parent
c52a7d49da
commit
57c71c4406
26
init.lua
26
init.lua
|
@ -5,15 +5,13 @@ local function load(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Load HTTP privileges
|
-- Load HTTP privileges
|
||||||
local function get_api()
|
local http_api = minetest.request_http_api and minetest.request_http_api()
|
||||||
local http_api = minetest.request_http_api and minetest.request_http_api()
|
if http_api == nil then
|
||||||
if http_api == nil then
|
error(
|
||||||
error(
|
"This mod has no access to HTTP requests - which is crucial for it "..
|
||||||
"This mod has no access to HTTP requests - which is crucial for it "..
|
"to relay messages to Matrix. Please enable it at the "..
|
||||||
"to relay messages to Matrix. Please enable it at the "..
|
"`secure.http_mods` or the `secure.trusted_mods` settings!"
|
||||||
"`secure.http_mods` or the `secure.trusted_mods` settings!"
|
)
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Load standard configuration
|
-- Load standard configuration
|
||||||
|
@ -32,24 +30,24 @@ load("lua/send")
|
||||||
load("lua/sync")
|
load("lua/sync")
|
||||||
|
|
||||||
-- Mod Minetest server
|
-- Mod Minetest server
|
||||||
minetest.register_on_chat_message(matrix.say(get_api()))
|
minetest.register_on_chat_message(matrix.say(http_api))
|
||||||
minetest.register_on_joinplayer(function(ObjectRef, last_login)
|
minetest.register_on_joinplayer(function(ObjectRef, last_login)
|
||||||
local name = ObjectRef:get_player_name()
|
local name = ObjectRef:get_player_name()
|
||||||
matrix.send(get_api(), name .. " has joined the Minetest server")
|
matrix.send(http_api, name .. " has joined the Minetest server")
|
||||||
end)
|
end)
|
||||||
minetest.register_on_leaveplayer(function(ObjectRef, timed_out)
|
minetest.register_on_leaveplayer(function(ObjectRef, timed_out)
|
||||||
local name = ObjectRef:get_player_name()
|
local name = ObjectRef:get_player_name()
|
||||||
matrix.send(get_api(), name .. " has left the Minetest server")
|
matrix.send(http_api, name .. " has left the Minetest server")
|
||||||
end)
|
end)
|
||||||
minetest.register_on_dieplayer(function(ObjectRef, reason)
|
minetest.register_on_dieplayer(function(ObjectRef, reason)
|
||||||
local name = ObjectRef:get_player_name()
|
local name = ObjectRef:get_player_name()
|
||||||
matrix.send(get_api(), name .. " has died! Reason:", reason)
|
matrix.send(http_api, name .. " has died! Reason:", reason)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Start Matrix sync
|
-- Start Matrix sync
|
||||||
local names = {}
|
local names = {}
|
||||||
|
|
||||||
matrix.sync_forever(get_api(), function(event)
|
matrix.sync_forever(http_api, function(event)
|
||||||
local name = names[event.sender] or event.sender
|
local name = names[event.sender] or event.sender
|
||||||
|
|
||||||
if event.type == nil then
|
if event.type == nil then
|
||||||
|
|
Loading…
Reference in New Issue