Fixed more indentations

This commit is contained in:
joenas 2017-06-21 21:35:37 +02:00
parent e1d58c0aef
commit 3ff398aece
3 changed files with 74 additions and 75 deletions

View File

@ -2,37 +2,36 @@
-- See LICENSE.txt for details. -- See LICENSE.txt for details.
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
if matrix.connected then --and matrix.config.send_join_part then if matrix.connected then --and matrix.config.send_join_part then
matrix.say("*** "..name.." joined the game") matrix.say("*** "..name.." joined the game")
end end
end) end)
minetest.register_on_leaveplayer(function(player, timed_out) minetest.register_on_leaveplayer(function(player, timed_out)
local name = player:get_player_name() local name = player:get_player_name()
if matrix.connected then -- and matrix.config.send_join_part then if matrix.connected then -- and matrix.config.send_join_part then
matrix.say("*** "..name.." left the game".. matrix.say("*** "..name.." left the game"..
(timed_out and " (Timed out)" or "")) (timed_out and " (Timed out)" or ""))
end end
end) end)
minetest.register_on_chat_message(function(name, message) minetest.register_on_chat_message(function(name, message)
if not matrix.connected if not matrix.connected
or message:sub(1, 1) == "/" or message:sub(1, 1) == "/"
or message:sub(1, 5) == "[off]" or message:sub(1, 5) == "[off]"
--or not matrix.joined_players[name] # TODO fix in player_part --or not matrix.joined_players[name] # TODO fix in player_part
or (not minetest.check_player_privs(name, {shout=true})) then or (not minetest.check_player_privs(name, {shout=true})) then
return return
end end
local nl = message:find("\n", 1, true) local nl = message:find("\n", 1, true)
if nl then if nl then
message = message:sub(1, nl - 1) message = message:sub(1, nl - 1)
end end
matrix.say("<"..name.."> "..message) matrix.say("<"..name.."> "..message)
end) end)
minetest.register_on_shutdown(function() minetest.register_on_shutdown(function()
matrix.disconnect("Game shutting down.") matrix.disconnect("Game shutting down.")
end) end)

View File

@ -4,30 +4,30 @@
matrix.config = {} matrix.config = {}
local function setting(stype, name, default, required) local function setting(stype, name, default, required)
local value local value
if stype == "bool" then if stype == "bool" then
value = minetest.setting_getbool("matrix."..name) value = minetest.setting_getbool("matrix."..name)
elseif stype == "string" then elseif stype == "string" then
value = minetest.setting_get("matrix."..name) value = minetest.setting_get("matrix."..name)
elseif stype == "number" then elseif stype == "number" then
value = tonumber(minetest.setting_get("matrix."..name)) value = tonumber(minetest.setting_get("matrix."..name))
end end
if value == nil then if value == nil then
if required then if required then
error("Required configuration option matrix.".. error("Required configuration option matrix."..
name.." missing.") name.." missing.")
end end
value = default value = default
end end
matrix.config[name] = value matrix.config[name] = value
end end
------------------------- -------------------------
-- BASIC USER SETTINGS -- -- BASIC USER SETTINGS --
------------------------- -------------------------
setting("string", "user", nil, true) -- User name, fe @digbot:matrix.org setting("string", "user", nil, true) -- User name, fe @digbot:matrix.org
setting("string", "server", nil, true) -- Server address to connect to setting("string", "server", nil, true) -- Server address to connect to
setting("number", "port", 8448) -- Server port to connect to setting("number", "port", 8448) -- Server port to connect to
setting("string", "room_id", nil, true) -- Channel to join (not needed?) setting("string", "room_id", nil, true) -- Channel to join (not needed?)
setting("string", "password", nil, true) -- Server password setting("string", "password", nil, true) -- Server password

View File

@ -47,45 +47,45 @@ end):hook("logged-out", function (client)
eprintf("Logged out... bye!\n") eprintf("Logged out... bye!\n")
matrix.connected = false matrix.connected = false
end):hook("left", function (client, room) end):hook("left", function (client, room)
eprintf("Left room %s, active rooms:\n", room) eprintf("Left room %s, active rooms:\n", room)
for room_id, room in pairs(client.rooms) do for room_id, room in pairs(client.rooms) do
assert(room_id == room.room_id) assert(room_id == room.room_id)
eprintf(" - %s\n", room) eprintf(" - %s\n", room)
end end
end):hook("joined", function (client, room) end):hook("joined", function (client, room)
eprintf("Active rooms:\n") eprintf("Active rooms:\n")
for room_id, room in pairs(client.rooms) do for room_id, room in pairs(client.rooms) do
assert(room_id == room.room_id) assert(room_id == room.room_id)
eprintf(" - %s\n", room) eprintf(" - %s\n", room)
end end
--room:send_text("Type “!bot quit” to make the bot exit") --room:send_text("Type “!bot quit” to make the bot exit")
room:hook("message", function (room, sender, message, event) room:hook("message", function (room, sender, message, event)
if event.origin_server_ts < start_ts then if event.origin_server_ts < start_ts then
eprintf("%s: (Skipping message sent before bot startup)\n", room) eprintf("%s: (Skipping message sent before bot startup)\n", room)
return return
end end
if sender == room.client.user_id then if sender == room.client.user_id then
eprintf("%s: (Skipping message sent by ourselves)\n", room) eprintf("%s: (Skipping message sent by ourselves)\n", room)
return return
end end
if message.msgtype ~= "m.text" then if message.msgtype ~= "m.text" then
eprintf("%s: (Message of type %s ignored)\n", room, message.msgtype) eprintf("%s: (Message of type %s ignored)\n", room, message.msgtype)
return return
end end
eprintf("%s: <%s> %s\n", room, sender, message.body) eprintf("%s: <%s> %s\n", room, sender, message.body)
if message.body == "!bot quit" then if message.body == "!bot quit" then
for _, room in pairs(client.rooms) do for _, room in pairs(client.rooms) do
room:send_text("(gracefully shutting down)") room:send_text("(gracefully shutting down)")
end
client:logout()
matrix.connected = false
elseif room.room_id == matrix.config.room_id then
minetest.chat_send_all("<"..sender.."> "..message.body)
end end
client:logout()
matrix.connected = false
elseif room.room_id == matrix.config.room_id then
minetest.chat_send_all("<"..sender.."> "..message.body)
end
end) end)
end) end)