saved - look into timing later
This commit is contained in:
parent
e600d4a1e3
commit
45292083f2
21
init.lua
21
init.lua
@ -15,8 +15,8 @@ local token = nil
|
|||||||
local txid = 0
|
local txid = 0
|
||||||
-- used for msync()
|
-- used for msync()
|
||||||
local since = nil
|
local since = nil
|
||||||
|
local last_batch = nil
|
||||||
|
|
||||||
-- accepts list of events
|
|
||||||
local function mchat(data)
|
local function mchat(data)
|
||||||
if data == nil then
|
if data == nil then
|
||||||
return
|
return
|
||||||
@ -36,8 +36,10 @@ local function mchat(data)
|
|||||||
else
|
else
|
||||||
local events = data["rooms"]["join"][MATRIX_ROOM]["timeline"]["events"]
|
local events = data["rooms"]["join"][MATRIX_ROOM]["timeline"]["events"]
|
||||||
if events == nil then
|
if events == nil then
|
||||||
|
minetest.log("action", "matrix_bridge - found timeline but no events")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
minetest.log("action", "matrix_bridge - sync'd and found new messages")
|
||||||
for i, event in ipairs(events) do
|
for i, event in ipairs(events) do
|
||||||
if event.type == "m.room.message"
|
if event.type == "m.room.message"
|
||||||
and event.sender ~= MATRIX_USERNAME_LONG then
|
and event.sender ~= MATRIX_USERNAME_LONG then
|
||||||
@ -53,7 +55,8 @@ local function msync()
|
|||||||
-- local param1 = '&filter={\"room\":{\"timeline\":{\"limit\":1}}}'
|
-- local param1 = '&filter={\"room\":{\"timeline\":{\"limit\":1}}}'
|
||||||
local param1 = "?access_token=" .. token
|
local param1 = "?access_token=" .. token
|
||||||
local param2 = "&full_state=false"
|
local param2 = "&full_state=false"
|
||||||
local u = MATRIX_SERVER.."/_matrix/client/r0/sync" .. param1 .. param2
|
local param3 = "&timeout=30000"
|
||||||
|
local u = MATRIX_SERVER.."/_matrix/client/r0/sync" .. param1 .. param2 .. param3
|
||||||
if since == nil then -- first time sync
|
if since == nil then -- first time sync
|
||||||
-- do nothing for now
|
-- do nothing for now
|
||||||
else -- second time sync -> append since parameter
|
else -- second time sync -> append since parameter
|
||||||
@ -66,11 +69,12 @@ local function msync()
|
|||||||
elseif res.code == 0 then
|
elseif res.code == 0 then
|
||||||
minetest.log("info", "matrix_bridge - not found / timeout")
|
minetest.log("info", "matrix_bridge - not found / timeout")
|
||||||
elseif res.code == 404 then
|
elseif res.code == 404 then
|
||||||
minetest.log("info", "matrix_bridge - 404")
|
minetest.log("error", "matrix_bridge - 404")
|
||||||
else
|
else
|
||||||
local response = minetest.parse_json(res.data)
|
local response = minetest.parse_json(res.data)
|
||||||
if response ~= nil then
|
if response ~= nil then
|
||||||
since = response.next_batch
|
since = response.next_batch
|
||||||
|
last_batch = response.prev_batch
|
||||||
mchat(response)
|
mchat(response)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -125,8 +129,13 @@ end
|
|||||||
-- end
|
-- end
|
||||||
-- end)
|
-- end)
|
||||||
|
|
||||||
minetest.register_globalstep(function()
|
local GLOBAL_STEPS = 0
|
||||||
msync()
|
minetest.register_globalstep(function(dtine)
|
||||||
|
-- print(GLOBAL_STEPS)
|
||||||
|
if GLOBAL_STEPS == 4 then
|
||||||
|
msync()
|
||||||
|
end
|
||||||
|
GLOBAL_STEPS = (GLOBAL_STEPS + 1) % 5
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user