Added chat command to debug syncing

This commit is contained in:
- 2022-01-22 21:19:10 -08:00
parent 45292083f2
commit 0a910c3aec
1 changed files with 26 additions and 13 deletions

View File

@ -50,17 +50,17 @@ local function mchat(data)
end end
end end
local function msync() local function msync(s)
-- optimization note: request more recent instead of unfiltered req -- optimization note: request more recent instead of unfiltered req
-- 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 param3 = "&timeout=30000" local param3 = "&timeout=5000"
local u = MATRIX_SERVER.."/_matrix/client/r0/sync" .. param1 .. param2 .. param3 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 -- do nothing for now
else -- second time sync -> append since parameter else -- second time sync -> append since parameter
u = u .. "&since="..since u = u .. "&since="..s
end end
http.fetch({url=u}, http.fetch({url=u},
function (res) function (res)
@ -92,8 +92,8 @@ local function mlogin()
minetest.log("action", res.data) minetest.log("action", res.data)
local data = minetest.parse_json(res.data) local data = minetest.parse_json(res.data)
token = data.access_token token = data.access_token
minetest.log("action", "Matrix authenticated")
msync() msync()
minetest.log("action", "Matrix authenticated")
else else
minetest.log("error", to_string(res)) minetest.log("error", to_string(res))
end end
@ -129,14 +129,27 @@ end
-- end -- end
-- end) -- end)
local GLOBAL_STEPS = 0 -- local GLOBAL_STEPS = 0
minetest.register_globalstep(function(dtine) -- minetest.register_globalstep(function(dtine)
-- print(GLOBAL_STEPS) -- -- print(GLOBAL_STEPS)
if GLOBAL_STEPS == 4 then -- if GLOBAL_STEPS == 4 then
msync() -- msync()
end -- end
GLOBAL_STEPS = (GLOBAL_STEPS + 1) % 5 -- GLOBAL_STEPS = (GLOBAL_STEPS + 1) % 5
end) -- 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) minetest.register_on_joinplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()