From 8507a9b80f188c2b44cc9b0d87ec4e8b93eddff7 Mon Sep 17 00:00:00 2001 From: flux Date: Thu, 25 Jul 2019 01:53:22 +0000 Subject: [PATCH] irc2 updates --- .gitmodules | 2 +- botcmds.lua | 52 ++++++++--------- callback.lua | 16 +++--- chatcmds.lua | 82 +++++++++++++-------------- config.lua | 32 ++++------- hooks.lua | 148 ++++++++++++++++++++++++------------------------ init.lua | 111 ++++++++++++++++++------------------ irc | 2 +- messages.lua | 10 ++-- mod.conf | 2 +- player_part.lua | 28 ++++----- 11 files changed, 238 insertions(+), 247 deletions(-) diff --git a/.gitmodules b/.gitmodules index e56fee3..a84cbd4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "src/LuaIRC"] path = irc - url = https://github.com/ShadowNinja/LuaIRC.git + url = https://github.com/BlockySurvival/LuaIRC2.git diff --git a/botcmds.lua b/botcmds.lua index 277e031..13165b1 100644 --- a/botcmds.lua +++ b/botcmds.lua @@ -1,5 +1,5 @@ -irc.bot_commands = {} +irc2.bot_commands = {} -- From RFC1459: -- "Because of IRC’s scandanavian origin, the characters {}| are @@ -15,9 +15,9 @@ local function nickequals(nick1, nick2) return irclower(nick1) == irclower(nick2) end -function irc.check_botcmd(msg) - local prefix = irc.config.command_prefix - local nick = irc.conn.nick +function irc2.check_botcmd(msg) + local prefix = irc2.config.command_prefix + local nick = irc2.conn.nick local text = msg.args[2] local nickpart = text:sub(1, #nick) local suffix = text:sub(#nick+1, #nick+2) @@ -25,18 +25,18 @@ function irc.check_botcmd(msg) -- First check for a nick prefix if nickequals(nickpart, nick) and (suffix == ": " or suffix == ", ") then - irc.bot_command(msg, text:sub(#nick + 3)) + irc2.bot_command(msg, text:sub(#nick + 3)) return true -- Then check for the configured prefix elseif prefix and text:sub(1, #prefix):lower() == prefix:lower() then - irc.bot_command(msg, text:sub(#prefix + 1)) + irc2.bot_command(msg, text:sub(#prefix + 1)) return true end return false end -function irc.bot_command(msg, text) +function irc2.bot_command(msg, text) -- Remove leading whitespace text = text:match("^%s*(.*)") if text:sub(1, 1) == "@" then @@ -44,15 +44,15 @@ function irc.bot_command(msg, text) if not player_to then return elseif not minetest.get_player_by_name(player_to) then - irc.reply("User '"..player_to.."' is not in the game.") + irc2.reply("User '"..player_to.."' is not in the game.") return - elseif not irc.joined_players[player_to] then - irc.reply("User '"..player_to.."' is not using IRC.") + elseif not irc2.joined_players[player_to] then + irc2.reply("User '"..player_to.."' is not using IRC.") return end minetest.chat_send_player(player_to, "PM from "..msg.user.nick.."@IRC: "..message, false) - irc.reply("Message sent!") + irc2.reply("Message sent!") return end local pos = text:find(" ", 1, true) @@ -65,36 +65,36 @@ function irc.bot_command(msg, text) args = "" end - if not irc.bot_commands[cmd] then - irc.reply("Unknown command '"..cmd.."'. Try 'help'." + if not irc2.bot_commands[cmd] then + irc2.reply("Unknown command '"..cmd.."'. Try 'help'." .." Or use @playername to send a private message") return end - local _, message = irc.bot_commands[cmd].func(msg.user, args) + local _, message = irc2.bot_commands[cmd].func(msg.user, args) if message then - irc.reply(message) + irc2.reply(message) end end -function irc.register_bot_command(name, def) +function irc2.register_bot_command(name, def) if (not def.func) or (type(def.func) ~= "function") then error("Erroneous bot command definition. def.func missing.", 2) elseif name:sub(1, 1) == "@" then error("Erroneous bot command name. Command name begins with '@'.", 2) end - irc.bot_commands[name] = def + irc2.bot_commands[name] = def end -irc.register_bot_command("help", { +irc2.register_bot_command("help", { params = "", description = "Get help about a command", func = function(_, args) if args == "" then local cmdlist = { } - for name in pairs(irc.bot_commands) do + for name in pairs(irc2.bot_commands) do cmdlist[#cmdlist+1] = name end return true, "Available commands: "..table.concat(cmdlist, ", ") @@ -102,13 +102,13 @@ irc.register_bot_command("help", { .." help about a specific command." end - local cmd = irc.bot_commands[args] + local cmd = irc2.bot_commands[args] if not cmd then return false, "Unknown command '"..args.."'." end return true, ("Usage: %s%s %s -- %s"):format( - irc.config.command_prefix or "", + irc2.config.command_prefix or "", args, cmd.params or "", cmd.description or "") @@ -116,7 +116,7 @@ irc.register_bot_command("help", { }) -irc.register_bot_command("list", { +irc2.register_bot_command("list", { params = "", description = "List available commands.", func = function() @@ -126,7 +126,7 @@ irc.register_bot_command("list", { }) -irc.register_bot_command("whereis", { +irc2.register_bot_command("whereis", { params = "", description = "Tell the location of ", func = function(_, args) @@ -137,7 +137,7 @@ irc.register_bot_command("whereis", { if not player then return false, "There is no player named '"..args.."'" end - local fmt = "Player %s is at [CENSORED]" + local fmt = "Player %s is at (%.2f,%.2f,%.2f)" local pos = player:getpos() return true, fmt:format(args, pos.x, pos.y, pos.z) end @@ -145,7 +145,7 @@ irc.register_bot_command("whereis", { local starttime = os.time() -irc.register_bot_command("uptime", { +irc2.register_bot_command("uptime", { description = "Tell how much time the server has been up", func = function() local cur_time = os.time() @@ -160,7 +160,7 @@ irc.register_bot_command("uptime", { }) -irc.register_bot_command("players", { +irc2.register_bot_command("players", { description = "List the players on the server", func = function() local players = minetest.get_connected_players() diff --git a/callback.lua b/callback.lua index 29667ba..63bb3bd 100644 --- a/callback.lua +++ b/callback.lua @@ -4,26 +4,26 @@ minetest.register_on_joinplayer(function(player) local name = player:get_player_name() - if irc.connected and irc.config.send_join_part then - irc.say("*** "..name.." joined the game") + if irc2.connected and irc2.config.send_join_part then + irc2.say("*** "..name.." joined the game") end end) minetest.register_on_leaveplayer(function(player, timed_out) local name = player:get_player_name() - if irc.connected and irc.config.send_join_part then - irc.say("*** "..name.." left the game".. + if irc2.connected and irc2.config.send_join_part then + irc2.say("*** "..name.." left the game".. (timed_out and " (Timed out)" or "")) end end) minetest.register_on_chat_message(function(name, message) - if not irc.connected + if not irc2.connected or message:sub(1, 1) == "/" or message:sub(1, 5) == "[off]" - or not irc.joined_players[name] + or not irc2.joined_players[name] or (not minetest.check_player_privs(name, {shout=true})) then return end @@ -31,11 +31,11 @@ minetest.register_on_chat_message(function(name, message) if nl then message = message:sub(1, nl - 1) end - irc.say(irc.playerMessage(name, core.strip_colors(message))) + irc2.say(irc2.playerMessage(name, core.strip_colors(message))) end) minetest.register_on_shutdown(function() - irc.disconnect("Game shutting down.") + irc2.disconnect("Game shutting down.") end) diff --git a/chatcmds.lua b/chatcmds.lua index 34283d7..2b6b997 100644 --- a/chatcmds.lua +++ b/chatcmds.lua @@ -5,22 +5,22 @@ -- Feature-specific commands (like /join) are in their own files. -minetest.register_chatcommand("irc_msg", { +minetest.register_chatcommand("irc2_msg", { params = " ", - description = "Send a private message to an IRC user", + description = "Send a private message to a freenode IRC user", privs = {shout=true}, func = function(name, param) - if not irc.connected then - return false, "Not connected to IRC. Use /irc_connect to connect." + if not irc2.connected then + return false, "Not connected to freenode IRC. Use /irc2_connect to connect." end local found, _, toname, message = param:find("^([^%s]+)%s(.+)") if not found then - return false, "Invalid usage, see /help irc_msg." + return false, "Invalid usage, see /help irc2_msg." end local toname_l = toname:lower() local validNick = false local hint = "They have to be in the channel" - for nick in pairs(irc.conn.channels[irc.config.channel].users) do + for nick in pairs(irc2.conn.channels[irc2.config.channel].users) do if nick:lower() == toname_l then validNick = true break @@ -33,80 +33,80 @@ minetest.register_chatcommand("irc_msg", { if not validNick then return false, "You can not message that user. ("..hint..")" end - irc.say(toname, irc.playerMessage(name, message)) + irc2.say(toname, irc2.playerMessage(name, message)) return true, "Message sent!" end }) -minetest.register_chatcommand("irc_names", { +minetest.register_chatcommand("irc2_names", { params = "", - description = "List the users in IRC.", + description = "List the users in freenode IRC.", func = function() - if not irc.connected then - return false, "Not connected to IRC. Use /irc_connect to connect." + if not irc2.connected then + return false, "Not connected to freenode IRC. Use /irc2_connect to connect." end local users = { } - for nick in pairs(irc.conn.channels[irc.config.channel].users) do + for nick in pairs(irc2.conn.channels[irc2.config.channel].users) do table.insert(users, nick) end - return true, "Users in IRC: "..table.concat(users, ", ") + return true, "Users in freenode IRC: "..table.concat(users, ", ") end }) -minetest.register_chatcommand("irc_connect", { - description = "Connect to the IRC server.", - privs = {irc_admin=true}, +minetest.register_chatcommand("irc2_connect", { + description = "Connect to the freenode IRC server.", + privs = {irc2_admin=true}, func = function(name) - if irc.connected then - return false, "You are already connected to IRC." + if irc2.connected then + return false, "You are already connected to freenode IRC." end minetest.chat_send_player(name, "IRC: Connecting...") - irc.connect() + irc2.connect() end }) -minetest.register_chatcommand("irc_disconnect", { +minetest.register_chatcommand("irc2_disconnect", { params = "[message]", - description = "Disconnect from the IRC server.", - privs = {irc_admin=true}, + description = "Disconnect from freenode IRC.", + privs = {irc2_admin=true}, func = function(name, param) - if not irc.connected then - return false, "Not connected to IRC. Use /irc_connect to connect." + if not irc2.connected then + return false, "Not connected to freenode IRC. Use /irc2_connect to connect." end if param == "" then param = "Manual disconnect by "..name end - irc.disconnect(param) + irc2.disconnect(param) end }) -minetest.register_chatcommand("irc_reconnect", { - description = "Reconnect to the IRC server.", - privs = {irc_admin=true}, +minetest.register_chatcommand("irc2_reconnect", { + description = "Reconnect to freenode IRC.", + privs = {irc2_admin=true}, func = function(name) - if not irc.connected then - return false, "Not connected to IRC. Use /irc_connect to connect." + if not irc2.connected then + return false, "Not connected to freenode IRC. Use /irc2_connect to connect." end minetest.chat_send_player(name, "IRC: Reconnecting...") - irc.disconnect("Reconnecting...") - irc.connect() + irc2.disconnect("Reconnecting...") + irc2.connect() end }) -minetest.register_chatcommand("irc_quote", { +minetest.register_chatcommand("irc2_quote", { params = "", - description = "Send a raw command to the IRC server.", - privs = {irc_admin=true}, + description = "Send a raw command freenode IRC.", + privs = {irc2_admin=true}, func = function(name, param) - if not irc.connected then - return false, "Not connected to IRC. Use /irc_connect to connect." + if not irc2.connected then + return false, "Not connected to freenode IRC. Use /irc2_connect to connect." end - irc.queue(param) + irc2.queue(param) minetest.chat_send_player(name, "Command sent!") end }) @@ -115,11 +115,11 @@ minetest.register_chatcommand("irc_quote", { local oldme = minetest.chatcommands["me"].func -- luacheck: ignore minetest.chatcommands["me"].func = function(name, param, ...) - irc.say(("* %s %s"):format(name, param)) + irc2.say(("* %s %s"):format(name, param)) return oldme(name, param, ...) end -if irc.config.send_kicks and minetest.chatcommands["kick"] then +if irc2.config.send_kicks and minetest.chatcommands["kick"] then local oldkick = minetest.chatcommands["kick"].func -- luacheck: ignore minetest.chatcommands["kick"].func = function(name, param, ...) @@ -127,7 +127,7 @@ if irc.config.send_kicks and minetest.chatcommands["kick"] then if not plname then return false, "Usage: /kick player [reason]" end - irc.say(("*** Kicked %s.%s"):format(name, + irc2.say(("*** Kicked %s.%s"):format(name, reason~="" and " Reason: "..reason or "")) return oldkick(name, param, ...) end diff --git a/config.lua b/config.lua index 1a5157e..970225f 100644 --- a/config.lua +++ b/config.lua @@ -2,37 +2,25 @@ -- See LICENSE.txt for details. -irc.config = {} +irc2.config = {} local function setting(stype, name, default, required) local value - if minetest.settings and minetest.settings.get and minetest.settings.get_bool then - -- The current methods for getting settings - if stype == "bool" then - value = minetest.settings:get_bool("irc."..name) - elseif stype == "string" then - value = minetest.settings:get("irc."..name) - elseif stype == "number" then - value = tonumber(minetest.settings:get("irc."..name)) - end - else - -- The old methods for getting settings for backward compatibility. Deprecated on 0.4.16+ - if stype == "bool" then - value = minetest.setting_getbool("irc."..name) - elseif stype == "string" then - value = minetest.setting_get("irc."..name) - elseif stype == "number" then - value = tonumber(minetest.setting_get("irc."..name)) - end + if stype == "bool" then + value = minetest.setting_getbool("irc2."..name) + elseif stype == "string" then + value = minetest.setting_get("irc2."..name) + elseif stype == "number" then + value = tonumber(minetest.setting_get("irc2."..name)) end if value == nil then if required then - error("Required configuration option irc.".. + error("Required configuration option irc2.".. name.." missing.") end value = default end - irc.config[name] = value + irc2.config[name] = value end ------------------------- @@ -43,7 +31,7 @@ setting("string", "nick", nil, true) -- Nickname setting("string", "server", nil, true) -- Server address to connect to setting("number", "port", 6667) -- Server port to connect to setting("string", "NSPass") -- NickServ password -setting("string", "sasl.user", irc.config.nick) -- SASL username +setting("string", "sasl.user", irc2.config.nick) -- SASL username setting("string", "username", "Minetest") -- Username/ident setting("string", "realname", "Minetest") -- Real name/GECOS setting("string", "sasl.pass") -- SASL password diff --git a/hooks.lua b/hooks.lua index d902ca6..71f5960 100644 --- a/hooks.lua +++ b/hooks.lua @@ -6,8 +6,8 @@ local ie = ... -- MIME is part of LuaSocket local b64e = ie.require("mime").b64 -irc.hooks = {} -irc.registered_hooks = {} +irc2.hooks = {} +irc2.registered_hooks = {} local stripped_chars = "[\2\31]" @@ -20,8 +20,8 @@ local function normalize(text) end -function irc.doHook(conn) - for name, hook in pairs(irc.registered_hooks) do +function irc2.doHook(conn) + for name, hook in pairs(irc2.registered_hooks) do for _, func in pairs(hook) do conn:hook(name, func) end @@ -29,39 +29,39 @@ function irc.doHook(conn) end -function irc.register_hook(name, func) - irc.registered_hooks[name] = irc.registered_hooks[name] or {} - table.insert(irc.registered_hooks[name], func) +function irc2.register_hook(name, func) + irc2.registered_hooks[name] = irc2.registered_hooks[name] or {} + table.insert(irc2.registered_hooks[name], func) end -function irc.hooks.raw(line) - if irc.config.debug then +function irc2.hooks.raw(line) + if irc2.config.debug then print("RECV: "..line) end end -function irc.hooks.send(line) - if irc.config.debug then +function irc2.hooks.send(line) + if irc2.config.debug then print("SEND: "..line) end end -function irc.hooks.chat(msg) +function irc2.hooks.chat(msg) local channel, text = msg.args[1], msg.args[2] if text:sub(1, 1) == string.char(1) then - irc.conn:invoke("OnCTCP", msg) + irc2.conn:invoke("OnCTCP", msg) return end - if channel == irc.conn.nick then - irc.last_from = msg.user.nick - irc.conn:invoke("PrivateMessage", msg) + if channel == irc2.conn.nick then + irc2.last_from = msg.user.nick + irc2.conn:invoke("PrivateMessage", msg) else - irc.last_from = channel - irc.conn:invoke("OnChannelChat", msg) + irc2.last_from = channel + irc2.conn:invoke("OnChannelChat", msg) end end @@ -74,22 +74,22 @@ local function get_core_version() end -function irc.hooks.ctcp(msg) +function irc2.hooks.ctcp(msg) local text = msg.args[2]:sub(2, -2) -- Remove ^C local args = text:split(' ') local command = args[1]:upper() local function reply(s) - irc.queue(irc.msgs.notice(msg.user.nick, + irc2.queue(irc2.msgs.notice(msg.user.nick, ("\1%s %s\1"):format(command, s))) end - if command == "ACTION" and msg.args[1] == irc.config.channel then + if command == "ACTION" and msg.args[1] == irc2.config.channel then local action = text:sub(8, -1) - irc.sendLocal(("* %s@xeroxIRC %s"):format(msg.user.nick, action)) + irc2.sendLocal(("* %s@freenode %s"):format(msg.user.nick, action)) elseif command == "VERSION" then reply(("Minetest version %s, IRC mod version %s.") - :format(get_core_version(), irc.version)) + :format(get_core_version(), irc2.version)) elseif command == "PING" then reply(args[2]) elseif command == "TIME" then @@ -98,15 +98,15 @@ function irc.hooks.ctcp(msg) end -function irc.hooks.channelChat(msg) +function irc2.hooks.channelChat(msg) local text = normalize(msg.args[2]) - irc.check_botcmd(msg) + irc2.check_botcmd(msg) -- Don't let a user impersonate someone else by using the nick "IRC" local fake = msg.user.nick:lower():match("^[il|]rc$") if fake then - irc.sendLocal("<"..msg.user.nick.."@xeroxIRC> "..text) + irc2.sendLocal("<"..msg.user.nick.."@freenode> "..text) return elseif msg.user.nick == "BlockyRelay" then return @@ -128,53 +128,53 @@ function irc.hooks.channelChat(msg) if text:sub(1, 5) == "[off]" then return elseif foundchat then - irc.sendLocal(("<%s@%s> %s") + irc2.sendLocal(("<%s@%s> %s") :format(chatnick, msg.user.nick, chatmessage)) elseif foundjoin then - irc.sendLocal(("*** %s joined %s") + irc2.sendLocal(("*** %s joined %s") :format(joinnick, msg.user.nick)) elseif foundleave then - irc.sendLocal(("*** %s left %s") + irc2.sendLocal(("*** %s left %s") :format(leavenick, msg.user.nick)) elseif foundaction then - irc.sendLocal(("* %s@%s %s") + irc2.sendLocal(("* %s@%s %s") :format(actionnick, msg.user.nick, actionmessage)) else - irc.sendLocal(("<%s@xeroxIRC> %s"):format(msg.user.nick, text)) + irc2.sendLocal(("<%s@freenode> %s"):format(msg.user.nick, text)) end end -function irc.hooks.pm(msg) +function irc2.hooks.pm(msg) -- Trim prefix if it is found local text = msg.args[2] - local prefix = irc.config.command_prefix + local prefix = irc2.config.command_prefix if prefix and text:sub(1, #prefix) == prefix then text = text:sub(#prefix + 1) end - irc.bot_command(msg, text) + irc2.bot_command(msg, text) end -function irc.hooks.kick(channel, target, prefix, reason) - if target == irc.conn.nick then - minetest.chat_send_all("IRC: kicked from "..channel.." (xeroxIRC) by "..prefix.nick..".") - irc.disconnect("Kicked") +function irc2.hooks.kick(channel, target, prefix, reason) + if target == irc2.conn.nick then + minetest.chat_send_all("IRC: kicked from "..channel.." (freenode) by "..prefix.nick..".") + irc2.disconnect("Kicked") else - irc.sendLocal(("-!- %s was kicked from %s (xeroxIRC) by %s [%s]") + irc2.sendLocal(("-!- %s was kicked from %s (freenode) by %s [%s]") :format(target, channel, prefix.nick, reason)) end end -function irc.hooks.notice(user, target, message) - if user.nick and target == irc.config.channel then - irc.sendLocal("-"..user.nick.."@xeroxIRC- "..message) +function irc2.hooks.notice(user, target, message) + if user.nick and target == irc2.config.channel then + irc2.sendLocal("-"..user.nick.."@freenode- "..message) end end -function irc.hooks.mode(user, target, modes, ...) +function irc2.hooks.mode(user, target, modes, ...) local by = "" if user.nick then by = " by "..user.nick @@ -189,37 +189,37 @@ function irc.hooks.mode(user, target, modes, ...) end -function irc.hooks.nick(user, newNick) - irc.sendLocal(("-!- %s is now known as %s") +function irc2.hooks.nick(user, newNick) + irc2.sendLocal(("-!- %s is now known as %s") :format(user.nick, newNick)) end -function irc.hooks.join(user, channel) - irc.sendLocal(("-!- %s joined %s (xeroxIRC)") +function irc2.hooks.join(user, channel) + irc2.sendLocal(("-!- %s joined %s (freenode)") :format(user.nick, channel)) end -function irc.hooks.part(user, channel, reason) +function irc2.hooks.part(user, channel, reason) reason = reason or "" - irc.sendLocal(("-!- %s has left %s (xeroxIRC) [%s]") + irc2.sendLocal(("-!- %s has left %s (freenode) [%s]") :format(user.nick, channel, reason)) end -function irc.hooks.quit(user, reason) - irc.sendLocal(("-!- %s has quit xeroxIRC [%s]") +function irc2.hooks.quit(user, reason) + irc2.sendLocal(("-!- %s has quit freenode [%s]") :format(user.nick, reason)) end -function irc.hooks.disconnect(_, isError) - irc.connected = false +function irc2.hooks.disconnect(_, isError) + irc2.connected = false if isError then minetest.log("error", "IRC: Error: Disconnected, reconnecting in one minute.") minetest.chat_send_all("IRC: Error: Disconnected, reconnecting in one minute.") - minetest.after(60, irc.connect, irc) + minetest.after(60, irc2.connect, irc2) else minetest.log("action", "IRC: Disconnected.") minetest.chat_send_all("IRC: Disconnected.") @@ -227,13 +227,13 @@ function irc.hooks.disconnect(_, isError) end -function irc.hooks.preregister(conn) - if not (irc.config["sasl.user"] and irc.config["sasl.pass"]) then return end +function irc2.hooks.preregister(conn) + if not (irc2.config["sasl.user"] and irc2.config["sasl.pass"]) then return end local authString = b64e( ("%s\x00%s\x00%s"):format( - irc.config["sasl.user"], - irc.config["sasl.user"], - irc.config["sasl.pass"]) + irc2.config["sasl.user"], + irc2.config["sasl.user"], + irc2.config["sasl.pass"]) ) conn:send("CAP REQ sasl") conn:send("AUTHENTICATE PLAIN") @@ -242,19 +242,19 @@ function irc.hooks.preregister(conn) end -irc.register_hook("PreRegister", irc.hooks.preregister) -irc.register_hook("OnRaw", irc.hooks.raw) -irc.register_hook("OnSend", irc.hooks.send) -irc.register_hook("DoPrivmsg", irc.hooks.chat) -irc.register_hook("OnPart", irc.hooks.part) -irc.register_hook("OnKick", irc.hooks.kick) -irc.register_hook("OnJoin", irc.hooks.join) -irc.register_hook("OnQuit", irc.hooks.quit) -irc.register_hook("NickChange", irc.hooks.nick) -irc.register_hook("OnCTCP", irc.hooks.ctcp) -irc.register_hook("PrivateMessage", irc.hooks.pm) -irc.register_hook("OnNotice", irc.hooks.notice) -irc.register_hook("OnChannelChat", irc.hooks.channelChat) -irc.register_hook("OnModeChange", irc.hooks.mode) -irc.register_hook("OnDisconnect", irc.hooks.disconnect) +irc2.register_hook("PreRegister", irc2.hooks.preregister) +irc2.register_hook("OnRaw", irc2.hooks.raw) +irc2.register_hook("OnSend", irc2.hooks.send) +irc2.register_hook("DoPrivmsg", irc2.hooks.chat) +irc2.register_hook("OnPart", irc2.hooks.part) +irc2.register_hook("OnKick", irc2.hooks.kick) +irc2.register_hook("OnJoin", irc2.hooks.join) +irc2.register_hook("OnQuit", irc2.hooks.quit) +irc2.register_hook("NickChange", irc2.hooks.nick) +irc2.register_hook("OnCTCP", irc2.hooks.ctcp) +irc2.register_hook("PrivateMessage", irc2.hooks.pm) +irc2.register_hook("OnNotice", irc2.hooks.notice) +irc2.register_hook("OnChannelChat", irc2.hooks.channelChat) +irc2.register_hook("OnModeChange", irc2.hooks.mode) +irc2.register_hook("OnDisconnect", irc2.hooks.disconnect) diff --git a/init.lua b/init.lua index 3923ca8..b6ef1ce 100644 --- a/init.lua +++ b/init.lua @@ -28,7 +28,6 @@ if not rawget(_G, "jit") and package.config:sub(1, 1) == "/" then ";/usr/share/lua/5.1/?/init.lua" ie.package.cpath = ie.package.cpath.. ";/usr/lib/lua/5.1/?.so" - ie.package.cpath = "/usr/lib/x86_64-linux-gnu/lua/5.1/?.so;"..ie.package.cpath end -- Temporarily set require so that LuaIRC can access it @@ -41,7 +40,7 @@ rawset(_G, "module", ie.module) local lib = ie.require("irc") -irc = { +irc2 = { version = "0.2.0", connected = false, cur_time = 0, @@ -53,7 +52,7 @@ irc = { } -- Compatibility -rawset(_G, "mt_irc", irc) +rawset(_G, "mt_irc2", irc2) local getinfo = debug.getinfo local warned = { } @@ -69,7 +68,7 @@ local function warn_deprecated(k) end -- This is a hack. -setmetatable(irc, { +setmetatable(irc2, { __newindex = function(t, k, v) if type(v) == "function" then local f = v @@ -97,33 +96,28 @@ dofile(modpath.."/botcmds.lua") require = old_require rawset(_G, "module", old_module) -if irc.config.enable_player_part then +if irc2.config.enable_player_part then dofile(modpath.."/player_part.lua") else - setmetatable(irc.joined_players, {__index = function() return true end}) + setmetatable(irc2.joined_players, {__index = function() return true end}) end -minetest.register_privilege("irc_admin", { - description = "Allow IRC administrative tasks to be performed.", - give_to_singleplayer = true -}) - local stepnum = 0 -minetest.register_globalstep(function(dtime) return irc.step(dtime) end) +minetest.register_globalstep(function(dtime) return irc2.step(dtime) end) -function irc.step() +function irc2.step() if stepnum == 3 then - if irc.config.auto_connect then - irc.connect() + if irc2.config.auto_connect then + irc2.connect() end end stepnum = stepnum + 1 - if not irc.connected then return end + if not irc2.connected then return end -- Hooks will manage incoming messages and errors - local good, err = xpcall(function() irc.conn:think() end, debug.traceback) + local good, err = xpcall(function() irc2.conn:think() end, debug.traceback) if not good then print(err) return @@ -131,17 +125,17 @@ function irc.step() end -function irc.connect() - if irc.connected then +function irc2.connect() + if irc2.connected then minetest.log("error", "IRC: Ignoring attempt to connect when already connected.") return end - irc.conn = irc.lib.new({ - nick = irc.config.nick, - username = irc.config.username, - realname = irc.config.realname, + irc2.conn = irc2.lib.new({ + nick = irc2.config.nick, + username = irc2.config.username, + realname = irc2.config.realname, }) - irc.doHook(irc.conn) + irc2.doHook(irc2.conn) -- We need to swap the `require` function again since -- LuaIRC `require`s `ssl` if `irc.secure` is true. @@ -149,13 +143,13 @@ function irc.connect() require = ie.require local good, message = pcall(function() - irc.conn:connect({ - host = irc.config.server, - port = irc.config.port, - password = irc.config.password, - timeout = irc.config.timeout, - reconnect = irc.config.reconnect, - secure = irc.config.secure + irc2.conn:connect({ + host = irc2.config.server, + port = irc2.config.port, + password = irc2.config.password, + timeout = irc2.config.timeout, + reconnect = irc2.config.reconnect, + secure = irc2.config.secure }) end) @@ -163,57 +157,66 @@ function irc.connect() if not good then minetest.log("error", ("IRC: Connection error: %s: %s -- Reconnecting in %d seconds...") - :format(irc.config.server, message, irc.config.reconnect)) - minetest.after(irc.config.reconnect, function() irc.connect() end) + :format(irc2.config.server, message, irc2.config.reconnect)) + minetest.after(irc2.config.reconnect, function() irc2.connect() end) return end - if irc.config.NSPass then - irc.conn:queue(irc.msgs.privmsg( - "NickServ", "IDENTIFY "..irc.config.NSPass)) + if irc2.config.NSPass then + irc2.conn:queue(irc2.msgs.privmsg( + "NickServ", "IDENTIFY "..irc2.config.NSPass)) end - irc.conn:join(irc.config.channel, irc.config.key) - irc.connected = true + irc2.conn:join(irc2.config.channel, irc2.config.key) + irc2.connected = true minetest.log("action", "IRC: Connected!") minetest.chat_send_all("IRC: Connected!") end -function irc.disconnect(message) - if irc.connected then +function irc2.disconnect(message) + if irc2.connected then --The OnDisconnect hook will clear irc.connected and print a disconnect message - irc.conn:disconnect(message) + irc2.conn:disconnect(message) end end -function irc.say(to, message) +function irc2.say(to, message) if not message then message = to - to = irc.config.channel + to = irc2.config.channel end - to = to or irc.config.channel + to = to or irc2.config.channel - irc.queue(irc.msgs.privmsg(to, message)) + irc2.queue(irc2.msgs.privmsg(to, message)) end -function irc.reply(message) - if not irc.last_from then +function irc2.reply(message) + if not irc2.last_from then return end message = message:gsub("[\r\n%z]", " \\n ") - irc.say(irc.last_from, message) + irc2.say(irc2.last_from, message) end -function irc.send(msg) - if not irc.connected then return end - irc.conn:send(msg) +function irc2.send(msg) + if not irc2.connected then return end + irc2.conn:send(msg) end -function irc.queue(msg) - if not irc.connected then return end - irc.conn:queue(msg) +function irc2.queue(msg) + if not irc2.connected then return end + irc2.conn:queue(msg) end +-- Cloaking fix +local irc_sendLocal = irc2.sendLocal + +function irc2.sendLocal(msg) + for _, player in ipairs(cloaking.get_cloaked_players()) do + minetest.chat_send_player(player, msg) + end + return irc_sendLocal(msg) +end diff --git a/irc b/irc index e49a52e..3baffb6 160000 --- a/irc +++ b/irc @@ -1 +1 @@ -Subproject commit e49a52ede1a58ddd94854657bc5098b0ac5d0677 +Subproject commit 3baffb6bd3821b3e45b74a78e3564a9e7063b931 diff --git a/messages.lua b/messages.lua index 83e4f7f..12e537b 100644 --- a/messages.lua +++ b/messages.lua @@ -1,17 +1,17 @@ -- This file is licensed under the terms of the BSD 2-clause license. -- See LICENSE.txt for details. -irc.msgs = irc.lib.msgs +irc2.msgs = irc2.lib.msgs -function irc.logChat(message) +function irc2.logChat(message) minetest.log("action", "IRC CHAT: "..message) end -function irc.sendLocal(message) +function irc2.sendLocal(message) minetest.chat_send_all(message) - irc.logChat(message) + irc2.logChat(message) end -function irc.playerMessage(name, message) +function irc2.playerMessage(name, message) return ("<%s> %s"):format(name, message) end diff --git a/mod.conf b/mod.conf index ba3caea..dcd075e 100644 --- a/mod.conf +++ b/mod.conf @@ -1 +1 @@ -name = irc +name = irc2 diff --git a/player_part.lua b/player_part.lua index e703316..80e4470 100644 --- a/player_part.lua +++ b/player_part.lua @@ -2,19 +2,19 @@ -- See LICENSE.txt for details. -function irc.player_part(name) - if not irc.joined_players[name] then +function irc2.player_part(name) + if not irc2.joined_players[name] then return false, "You are not in the channel" end - irc.joined_players[name] = nil + irc2.joined_players[name] = nil return true, "You left the channel" end -function irc.player_join(name) - if irc.joined_players[name] then +function irc2.player_join(name) + if irc2.joined_players[name] then return false, "You are already in the channel" end - irc.joined_players[name] = true + irc2.joined_players[name] = true return true, "You joined the channel" end @@ -23,7 +23,7 @@ minetest.register_chatcommand("join", { description = "Join the IRC channel", privs = {shout=true}, func = function(name) - return irc.player_join(name) + return irc2.player_join(name) end }) @@ -31,7 +31,7 @@ minetest.register_chatcommand("part", { description = "Part the IRC channel", privs = {shout=true}, func = function(name) - return irc.player_part(name) + return irc2.player_part(name) end }) @@ -40,7 +40,7 @@ minetest.register_chatcommand("who", { privs = {}, func = function() local out, n = { }, 0 - for plname in pairs(irc.joined_players) do + for plname in pairs(irc2.joined_players) do n = n + 1 out[n] = plname end @@ -52,18 +52,18 @@ minetest.register_chatcommand("who", { minetest.register_on_joinplayer(function(player) local name = player:get_player_name() - irc.joined_players[name] = irc.config.auto_join + irc2.joined_players[name] = irc2.config.auto_join end) minetest.register_on_leaveplayer(function(player) local name = player:get_player_name() - irc.joined_players[name] = nil + irc2.joined_players[name] = nil end) -function irc.sendLocal(message) - for name, _ in pairs(irc.joined_players) do +function irc2.sendLocal(message) + for name, _ in pairs(irc2.joined_players) do minetest.chat_send_player(name, message) end - irc.logChat(message) + irc2.logChat(message) end