From 0a910c3aecd6a74d27965f5b005925ca8111baf9 Mon Sep 17 00:00:00 2001 From: - <-> Date: Sat, 22 Jan 2022 21:19:10 -0800 Subject: [PATCH] Added chat command to debug syncing --- init.lua | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/init.lua b/init.lua index b93a4a5..51ed03d 100644 --- a/init.lua +++ b/init.lua @@ -50,17 +50,17 @@ local function mchat(data) end end -local function msync() +local function msync(s) -- optimization note: request more recent instead of unfiltered req -- local param1 = '&filter={\"room\":{\"timeline\":{\"limit\":1}}}' local param1 = "?access_token=" .. token local param2 = "&full_state=false" - local param3 = "&timeout=30000" + local param3 = "&timeout=5000" local u = MATRIX_SERVER.."/_matrix/client/r0/sync" .. param1 .. param2 .. param3 - if since == nil then -- first time sync + if s == nil then -- first time sync -- do nothing for now else -- second time sync -> append since parameter - u = u .. "&since="..since + u = u .. "&since="..s end http.fetch({url=u}, function (res) @@ -92,8 +92,8 @@ local function mlogin() minetest.log("action", res.data) local data = minetest.parse_json(res.data) token = data.access_token - minetest.log("action", "Matrix authenticated") msync() + minetest.log("action", "Matrix authenticated") else minetest.log("error", to_string(res)) end @@ -129,14 +129,27 @@ end -- end -- end) -local GLOBAL_STEPS = 0 -minetest.register_globalstep(function(dtine) --- print(GLOBAL_STEPS) - if GLOBAL_STEPS == 4 then - msync() - end - GLOBAL_STEPS = (GLOBAL_STEPS + 1) % 5 -end) +-- local GLOBAL_STEPS = 0 +-- minetest.register_globalstep(function(dtine) +-- -- print(GLOBAL_STEPS) +-- if GLOBAL_STEPS == 4 then +-- msync() +-- end +-- GLOBAL_STEPS = (GLOBAL_STEPS + 1) % 5 +-- end) + +minetest.register_chatcommand("msync", { + privs = { + interact = true + }, + func = function(name, param) + if param == "nil" then + msync() + else + msync(since) + end + return true, "[matrix_bridge] Fetching from matrix..." +end}) minetest.register_on_joinplayer(function(player) local name = player:get_player_name()