mirror of
https://github.com/minetest-mods/irc.git
synced 2025-06-30 07:00:33 +02:00
Major cleanup.
- Use `irc.foo` notation instead of `irc:foo`. It still supports the `irc:foo` usage, but will helpfully issue a warning with the location of the offending code. - Remove unused arguments from functions.
This commit is contained in:
74
hooks.lua
74
hooks.lua
@ -20,8 +20,8 @@ local function normalize(text)
|
||||
end
|
||||
|
||||
|
||||
function irc:doHook(conn)
|
||||
for name, hook in pairs(self.registered_hooks) do
|
||||
function irc.doHook(conn)
|
||||
for name, hook in pairs(irc.registered_hooks) do
|
||||
for _, func in pairs(hook) do
|
||||
conn:hook(name, func)
|
||||
end
|
||||
@ -29,9 +29,9 @@ function irc:doHook(conn)
|
||||
end
|
||||
|
||||
|
||||
function irc:register_hook(name, func)
|
||||
self.registered_hooks[name] = self.registered_hooks[name] or {}
|
||||
table.insert(self.registered_hooks[name], func)
|
||||
function irc.register_hook(name, func)
|
||||
irc.registered_hooks[name] = irc.registered_hooks[name] or {}
|
||||
table.insert(irc.registered_hooks[name], func)
|
||||
end
|
||||
|
||||
|
||||
@ -80,13 +80,13 @@ function irc.hooks.ctcp(msg)
|
||||
local command = args[1]:upper()
|
||||
|
||||
local function reply(s)
|
||||
irc:queue(irc.msgs.notice(msg.user.nick,
|
||||
irc.queue(irc.msgs.notice(msg.user.nick,
|
||||
("\1%s %s\1"):format(command, s)))
|
||||
end
|
||||
|
||||
if command == "ACTION" and msg.args[1] == irc.config.channel then
|
||||
local action = text:sub(8, -1)
|
||||
irc:sendLocal(("* %s@IRC %s"):format(msg.user.nick, action))
|
||||
irc.sendLocal(("* %s@IRC %s"):format(msg.user.nick, action))
|
||||
elseif command == "VERSION" then
|
||||
reply(("Minetest version %s, IRC mod version %s.")
|
||||
:format(get_core_version(), irc.version))
|
||||
@ -105,7 +105,7 @@ function irc.hooks.channelChat(msg)
|
||||
|
||||
-- Don't let a user impersonate someone else by using the nick "IRC"
|
||||
if msg.user.nick == "IRC" then
|
||||
irc:sendLocal("<IRC@IRC> "..text)
|
||||
irc.sendLocal("<IRC@IRC> "..text)
|
||||
return
|
||||
end
|
||||
|
||||
@ -125,19 +125,19 @@ function irc.hooks.channelChat(msg)
|
||||
if text:sub(1, 5) == "[off]" then
|
||||
return
|
||||
elseif foundchat then
|
||||
irc:sendLocal(("<%s@%s> %s")
|
||||
irc.sendLocal(("<%s@%s> %s")
|
||||
:format(chatnick, msg.user.nick, chatmessage))
|
||||
elseif foundjoin then
|
||||
irc:sendLocal(("*** %s joined %s")
|
||||
irc.sendLocal(("*** %s joined %s")
|
||||
:format(joinnick, msg.user.nick))
|
||||
elseif foundleave then
|
||||
irc:sendLocal(("*** %s left %s")
|
||||
irc.sendLocal(("*** %s left %s")
|
||||
:format(leavenick, msg.user.nick))
|
||||
elseif foundaction then
|
||||
irc:sendLocal(("* %s@%s %s")
|
||||
irc.sendLocal(("* %s@%s %s")
|
||||
:format(actionnick, msg.user.nick, actionmessage))
|
||||
else
|
||||
irc:sendLocal(("<%s@IRC> %s"):format(msg.user.nick, text))
|
||||
irc.sendLocal(("<%s@IRC> %s"):format(msg.user.nick, text))
|
||||
end
|
||||
end
|
||||
|
||||
@ -149,16 +149,16 @@ function irc.hooks.pm(msg)
|
||||
if prefix and text:sub(1, #prefix) == prefix then
|
||||
text = text:sub(#prefix + 1)
|
||||
end
|
||||
irc:bot_command(msg, text)
|
||||
irc.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.." by "..prefix.nick..".")
|
||||
irc:disconnect("Kicked")
|
||||
irc.disconnect("Kicked")
|
||||
else
|
||||
irc:sendLocal(("-!- %s was kicked from %s by %s [%s]")
|
||||
irc.sendLocal(("-!- %s was kicked from %s by %s [%s]")
|
||||
:format(target, channel, prefix.nick, reason))
|
||||
end
|
||||
end
|
||||
@ -166,7 +166,7 @@ end
|
||||
|
||||
function irc.hooks.notice(user, target, message)
|
||||
if user.nick and target == irc.config.channel then
|
||||
irc:sendLocal("-"..user.nick.."@IRC- "..message)
|
||||
irc.sendLocal("-"..user.nick.."@IRC- "..message)
|
||||
end
|
||||
end
|
||||
|
||||
@ -187,31 +187,31 @@ end
|
||||
|
||||
|
||||
function irc.hooks.nick(user, newNick)
|
||||
irc:sendLocal(("-!- %s is now known as %s")
|
||||
irc.sendLocal(("-!- %s is now known as %s")
|
||||
:format(user.nick, newNick))
|
||||
end
|
||||
|
||||
|
||||
function irc.hooks.join(user, channel)
|
||||
irc:sendLocal(("-!- %s joined %s")
|
||||
irc.sendLocal(("-!- %s joined %s")
|
||||
:format(user.nick, channel))
|
||||
end
|
||||
|
||||
|
||||
function irc.hooks.part(user, channel, reason)
|
||||
reason = reason or ""
|
||||
irc:sendLocal(("-!- %s has left %s [%s]")
|
||||
irc.sendLocal(("-!- %s has left %s [%s]")
|
||||
:format(user.nick, channel, reason))
|
||||
end
|
||||
|
||||
|
||||
function irc.hooks.quit(user, reason)
|
||||
irc:sendLocal(("-!- %s has quit [%s]")
|
||||
irc.sendLocal(("-!- %s has quit [%s]")
|
||||
:format(user.nick, reason))
|
||||
end
|
||||
|
||||
|
||||
function irc.hooks.disconnect(message, isError)
|
||||
function irc.hooks.disconnect(_, isError)
|
||||
irc.connected = false
|
||||
if isError then
|
||||
minetest.log("error", "IRC: Error: Disconnected, reconnecting in one minute.")
|
||||
@ -239,19 +239,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)
|
||||
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)
|
||||
|
||||
|
Reference in New Issue
Block a user