diff --git a/init.lua b/init.lua index 1a06f91..69112bb 100644 --- a/init.lua +++ b/init.lua @@ -21,6 +21,9 @@ local function mchat(data) if data == nil then return end + if since == data.next_batch then + return + end -- lets just get this working if data["rooms"] == nil then return @@ -44,6 +47,7 @@ local function mchat(data) if event.type == "m.room.message" and event.sender ~= MATRIX_USERNAME_LONG then local message = event.sender .. ": " .. event.content.body + minetest.log("action", message) minetest.chat_send_all(message) end end @@ -69,14 +73,12 @@ local function msync(s) elseif res.code == 0 then minetest.log("info", "matrix_bridge - not found / timeout") elseif res.code == 404 then - minetest.log("error", "matrix_bridge - 404") - minetest.log("action", res.data) else local response = minetest.parse_json(res.data) if response ~= nil then + mchat(response) since = response.next_batch last_batch = response.prev_batch - mchat(response) end end end @@ -130,14 +132,14 @@ end -- end -- end) --- local GLOBAL_STEPS = 0 --- minetest.register_globalstep(function(dtine) --- -- print(GLOBAL_STEPS) +local GLOBAL_STEPS = 0 +minetest.register_globalstep(function(dtine) +-- print(GLOBAL_STEPS) -- if GLOBAL_STEPS == 4 then --- msync() + msync(since) -- end -- GLOBAL_STEPS = (GLOBAL_STEPS + 1) % 5 --- end) +end) minetest.register_chatcommand("msync", { privs = {