Simplify CTCP code

master
ShadowNinja 2013-10-23 08:32:03 -04:00
parent d21f5b3403
commit 99c7c56733
2 changed files with 20 additions and 15 deletions

View File

@ -55,21 +55,23 @@ end
function mt_irc.hooks.ctcp(user, channel, message) function mt_irc.hooks.ctcp(user, channel, message)
if message:sub(2, 7):upper() == "ACTION" and message = message:sub(2, -2) -- Remove ^C
channel ~= mt_irc.conn.nick then local args = message:split(' ')
local action = message:sub(9, -2) local command = args[1]:upper()
local function reply(s)
mt_irc:queueMsg("NOTICE %s :\1%s %s\1", user.nick, command, s)
end
if command == "ACTION" and channel ~= mt_irc.conn.nick then
local action = message:sub(8, -1)
mt_irc:sendLocal(("* %s@IRC %s"):format(user.nick, action)) mt_irc:sendLocal(("* %s@IRC %s"):format(user.nick, action))
elseif message:sub(2, 8):upper() == "VERSION" then elseif command == "VERSION" then
mt_irc:queueMsg(mt_irc.msgs.notice(user.nick, reply("Minetest IRC mod "..mt_irc.version)
("\1VERSION Minetest IRC mod %s\1") elseif command == "PING" then
:format(mt_irc.version))) reply(args[2])
elseif message:sub(2, 5):upper() == "PING" then elseif command == "TIME" then
local ts = message:sub(7, -2) reply(os.date())
mt_irc:queueMsg(mt_irc.msgs.notice(user.nick,
("\1PING %s\1"):format(ts)))
elseif message:sub(2, 5):upper() == "TIME" then
mt_irc:queueMsg(mt_irc.msgs.notice(user.nick,
("\1TIME %s\1"):format(os.date())))
end end
end end

View File

@ -6,7 +6,10 @@ function mt_irc:sendLocal(message)
minetest.chat_send_all(message) minetest.chat_send_all(message)
end end
function mt_irc:queueMsg(message) function mt_irc:queueMsg(message, ...)
if select("#", ...) > 0 then
message = message:format(...)
end
table.insert(self.message_buffer, message) table.insert(self.message_buffer, message)
end end