forked from minetest-mods/irc
Simplify CTCP code
This commit is contained in:
parent
d21f5b3403
commit
99c7c56733
@ -55,21 +55,23 @@ end
|
||||
|
||||
|
||||
function mt_irc.hooks.ctcp(user, channel, message)
|
||||
if message:sub(2, 7):upper() == "ACTION" and
|
||||
channel ~= mt_irc.conn.nick then
|
||||
local action = message:sub(9, -2)
|
||||
message = message:sub(2, -2) -- Remove ^C
|
||||
local args = message:split(' ')
|
||||
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))
|
||||
elseif message:sub(2, 8):upper() == "VERSION" then
|
||||
mt_irc:queueMsg(mt_irc.msgs.notice(user.nick,
|
||||
("\1VERSION Minetest IRC mod %s\1")
|
||||
:format(mt_irc.version)))
|
||||
elseif message:sub(2, 5):upper() == "PING" then
|
||||
local ts = message:sub(7, -2)
|
||||
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())))
|
||||
elseif command == "VERSION" then
|
||||
reply("Minetest IRC mod "..mt_irc.version)
|
||||
elseif command == "PING" then
|
||||
reply(args[2])
|
||||
elseif command == "TIME" then
|
||||
reply(os.date())
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -6,7 +6,10 @@ function mt_irc:sendLocal(message)
|
||||
minetest.chat_send_all(message)
|
||||
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)
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user