From 3ff398aece7f1b5eeb797873a6e8172f19453a74 Mon Sep 17 00:00:00 2001 From: joenas <jon@jonnev.se> Date: Wed, 21 Jun 2017 21:35:37 +0200 Subject: [PATCH] Fixed more indentations --- callback.lua | 45 +++++++++++++++++++------------------- config.lua | 42 +++++++++++++++++------------------ init.lua | 62 ++++++++++++++++++++++++++-------------------------- 3 files changed, 74 insertions(+), 75 deletions(-) diff --git a/callback.lua b/callback.lua index f0b9903..af25e39 100644 --- a/callback.lua +++ b/callback.lua @@ -2,37 +2,36 @@ -- See LICENSE.txt for details. minetest.register_on_joinplayer(function(player) - local name = player:get_player_name() - if matrix.connected then --and matrix.config.send_join_part then - matrix.say("*** "..name.." joined the game") - end + local name = player:get_player_name() + if matrix.connected then --and matrix.config.send_join_part then + matrix.say("*** "..name.." joined the game") + end end) minetest.register_on_leaveplayer(function(player, timed_out) - local name = player:get_player_name() - if matrix.connected then -- and matrix.config.send_join_part then - matrix.say("*** "..name.." left the game".. - (timed_out and " (Timed out)" or "")) - end + local name = player:get_player_name() + if matrix.connected then -- and matrix.config.send_join_part then + matrix.say("*** "..name.." left the game".. + (timed_out and " (Timed out)" or "")) + end end) minetest.register_on_chat_message(function(name, message) - if not matrix.connected - or message:sub(1, 1) == "/" - or message:sub(1, 5) == "[off]" - --or not matrix.joined_players[name] # TODO fix in player_part - or (not minetest.check_player_privs(name, {shout=true})) then - return - end - local nl = message:find("\n", 1, true) - if nl then - message = message:sub(1, nl - 1) - end - matrix.say("<"..name.."> "..message) + if not matrix.connected + or message:sub(1, 1) == "/" + or message:sub(1, 5) == "[off]" + --or not matrix.joined_players[name] # TODO fix in player_part + or (not minetest.check_player_privs(name, {shout=true})) then + return + end + local nl = message:find("\n", 1, true) + if nl then + message = message:sub(1, nl - 1) + end + matrix.say("<"..name.."> "..message) end) - minetest.register_on_shutdown(function() - matrix.disconnect("Game shutting down.") + matrix.disconnect("Game shutting down.") end) diff --git a/config.lua b/config.lua index 021a14a..82d6bf4 100644 --- a/config.lua +++ b/config.lua @@ -4,30 +4,30 @@ matrix.config = {} local function setting(stype, name, default, required) - local value - if stype == "bool" then - value = minetest.setting_getbool("matrix."..name) - elseif stype == "string" then - value = minetest.setting_get("matrix."..name) - elseif stype == "number" then - value = tonumber(minetest.setting_get("matrix."..name)) - end - if value == nil then - if required then - error("Required configuration option matrix.".. - name.." missing.") - end - value = default - end - matrix.config[name] = value + local value + if stype == "bool" then + value = minetest.setting_getbool("matrix."..name) + elseif stype == "string" then + value = minetest.setting_get("matrix."..name) + elseif stype == "number" then + value = tonumber(minetest.setting_get("matrix."..name)) + end + if value == nil then + if required then + error("Required configuration option matrix.".. + name.." missing.") + end + value = default + end + matrix.config[name] = value end ------------------------- -- BASIC USER SETTINGS -- ------------------------- -setting("string", "user", nil, true) -- User name, fe @digbot:matrix.org -setting("string", "server", nil, true) -- Server address 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", "password", nil, true) -- Server password +setting("string", "user", nil, true) -- User name, fe @digbot:matrix.org +setting("string", "server", nil, true) -- Server address 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", "password", nil, true) -- Server password diff --git a/init.lua b/init.lua index 8d27c95..48af83c 100644 --- a/init.lua +++ b/init.lua @@ -47,45 +47,45 @@ end):hook("logged-out", function (client) eprintf("Logged out... bye!\n") matrix.connected = false end):hook("left", function (client, room) - eprintf("Left room %s, active rooms:\n", room) - for room_id, room in pairs(client.rooms) do - assert(room_id == room.room_id) - eprintf(" - %s\n", room) - end + eprintf("Left room %s, active rooms:\n", room) + for room_id, room in pairs(client.rooms) do + assert(room_id == room.room_id) + eprintf(" - %s\n", room) + end end):hook("joined", function (client, room) - eprintf("Active rooms:\n") - for room_id, room in pairs(client.rooms) do - assert(room_id == room.room_id) - eprintf(" - %s\n", room) - end + eprintf("Active rooms:\n") + for room_id, room in pairs(client.rooms) do + assert(room_id == room.room_id) + eprintf(" - %s\n", room) + end --room:send_text("Type “!bot quit” to make the bot exit") room:hook("message", function (room, sender, message, event) - if event.origin_server_ts < start_ts then - eprintf("%s: (Skipping message sent before bot startup)\n", room) - return - end - if sender == room.client.user_id then - eprintf("%s: (Skipping message sent by ourselves)\n", room) - return - end - if message.msgtype ~= "m.text" then - eprintf("%s: (Message of type %s ignored)\n", room, message.msgtype) - return - end + if event.origin_server_ts < start_ts then + eprintf("%s: (Skipping message sent before bot startup)\n", room) + return + end + if sender == room.client.user_id then + eprintf("%s: (Skipping message sent by ourselves)\n", room) + return + end + if message.msgtype ~= "m.text" then + eprintf("%s: (Message of type %s ignored)\n", room, message.msgtype) + return + 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 - for _, room in pairs(client.rooms) do - 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) + if message.body == "!bot quit" then + for _, room in pairs(client.rooms) do + 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) end) -- GitLab