Skip to content

Commit 6bf4e11

Browse files
committed
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.
1 parent 5f8850b commit 6bf4e11

9 files changed

+180
-149
lines changed

.luacheckrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
unused_args = false
32
allow_defined_top = true
43

54
read_globals = {
@@ -11,4 +10,5 @@ exclude_files = {
1110
}
1211

1312
globals = {
13+
"irc",
1414
}

API.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ to your mod's `depends.txt` file.
1313
Reference
1414
---------
1515

16-
irc:say([name,] message)
16+
irc.say([name,] message)
1717
Sends <message> to either the channel (if <name> is nil or not specified),
1818
or to the given user (if <name> is specified).
1919
Example:
20-
irc:say("Hello, Channel!")
21-
irc:say("john1234", "How are you?")
20+
irc.say("Hello, Channel!")
21+
irc.say("john1234", "How are you?")
2222

23-
irc:register_bot_command(name, cmdDef)
23+
irc.register_bot_command(name, cmdDef)
2424
Registers a new bot command named <name>.
2525
When an user sends a private message to the bot with the command name, the
2626
command's function is called.
@@ -38,7 +38,7 @@ irc:register_bot_command(name, cmdDef)
3838
end,
3939
};
4040
Example:
41-
irc:register_bot_command("hello", {
41+
irc.register_bot_command("hello", {
4242
params = "",
4343
description = "Greet user",
4444
func = function(user, param)
@@ -55,12 +55,12 @@ irc.joined_players[name]
5555
-- Joe is talking on IRC
5656
end
5757

58-
irc:register_hook(name, func)
58+
irc.register_hook(name, func)
5959
Registers a function to be called when an event happens. <name> is the name
6060
of the event, and <func> is the function to be called. See HOOKS below
6161
for more information
6262
Example:
63-
irc:register_hook("OnSend", function(line)
63+
irc.register_hook("OnSend", function(line)
6464
print("SEND: "..line)
6565
end)
6666

@@ -83,7 +83,7 @@ not modify these settings at runtime or you might crash the server!
8383
Hooks
8484
-----
8585

86-
The `irc:register_hook` function can register functions to be called
86+
The `irc.register_hook` function can register functions to be called
8787
when some events happen. The events supported are the same as the LuaIRC
8888
ones with a few added (mostly for internal use).
8989
See src/LuaIRC/doc/irc.luadoc for more information.

botcmds.lua

+24-24
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ local function nickequals(nick1, nick2)
1515
return irclower(nick1) == irclower(nick2)
1616
end
1717

18-
function irc:check_botcmd(msg)
18+
function irc.check_botcmd(msg)
1919
local prefix = irc.config.command_prefix
2020
local nick = irc.conn.nick
2121
local text = msg.args[2]
@@ -25,34 +25,34 @@ function irc:check_botcmd(msg)
2525
-- First check for a nick prefix
2626
if nickequals(nickpart, nick)
2727
and (suffix == ": " or suffix == ", ") then
28-
self:bot_command(msg, text:sub(#nick + 3))
28+
irc.bot_command(msg, text:sub(#nick + 3))
2929
return true
3030
-- Then check for the configured prefix
3131
elseif prefix and text:sub(1, #prefix):lower() == prefix:lower() then
32-
self:bot_command(msg, text:sub(#prefix + 1))
32+
irc.bot_command(msg, text:sub(#prefix + 1))
3333
return true
3434
end
3535
return false
3636
end
3737

3838

39-
function irc:bot_command(msg, text)
39+
function irc.bot_command(msg, text)
4040
-- Remove leading whitespace
4141
text = text:match("^%s*(.*)")
4242
if text:sub(1, 1) == "@" then
4343
local _, _, player_to, message = text:find("^.([^%s]+)%s(.+)$")
4444
if not player_to then
4545
return
4646
elseif not minetest.get_player_by_name(player_to) then
47-
irc:reply("User '"..player_to.."' is not in the game.")
47+
irc.reply("User '"..player_to.."' is not in the game.")
4848
return
4949
elseif not irc.joined_players[player_to] then
50-
irc:reply("User '"..player_to.."' is not using IRC.")
50+
irc.reply("User '"..player_to.."' is not using IRC.")
5151
return
5252
end
5353
minetest.chat_send_player(player_to,
5454
"PM from "..msg.user.nick.."@IRC: "..message, false)
55-
irc:reply("Message sent!")
55+
irc.reply("Message sent!")
5656
return
5757
end
5858
local pos = text:find(" ", 1, true)
@@ -65,36 +65,36 @@ function irc:bot_command(msg, text)
6565
args = ""
6666
end
6767

68-
if not self.bot_commands[cmd] then
69-
self:reply("Unknown command '"..cmd.."'. Try 'help'."
68+
if not irc.bot_commands[cmd] then
69+
irc.reply("Unknown command '"..cmd.."'. Try 'help'."
7070
.." Or use @playername <message> to send a private message")
7171
return
7272
end
7373

74-
local _, message = self.bot_commands[cmd].func(msg.user, args)
74+
local _, message = irc.bot_commands[cmd].func(msg.user, args)
7575
if message then
76-
self:reply(message)
76+
irc.reply(message)
7777
end
7878
end
7979

8080

81-
function irc:register_bot_command(name, def)
81+
function irc.register_bot_command(name, def)
8282
if (not def.func) or (type(def.func) ~= "function") then
8383
error("Erroneous bot command definition. def.func missing.", 2)
8484
elseif name:sub(1, 1) == "@" then
8585
error("Erroneous bot command name. Command name begins with '@'.", 2)
8686
end
87-
self.bot_commands[name] = def
87+
irc.bot_commands[name] = def
8888
end
8989

9090

91-
irc:register_bot_command("help", {
91+
irc.register_bot_command("help", {
9292
params = "<command>",
9393
description = "Get help about a command",
94-
func = function(user, args)
94+
func = function(_, args)
9595
if args == "" then
9696
local cmdlist = { }
97-
for name, cmd in pairs(irc.bot_commands) do
97+
for name in pairs(irc.bot_commands) do
9898
cmdlist[#cmdlist+1] = name
9999
end
100100
return true, "Available commands: "..table.concat(cmdlist, ", ")
@@ -116,20 +116,20 @@ irc:register_bot_command("help", {
116116
})
117117

118118

119-
irc:register_bot_command("list", {
119+
irc.register_bot_command("list", {
120120
params = "",
121121
description = "List available commands.",
122-
func = function(user, args)
122+
func = function()
123123
return false, "The `list` command has been merged into `help`."
124124
.." Use `help` with no arguments to get a list."
125125
end
126126
})
127127

128128

129-
irc:register_bot_command("whereis", {
129+
irc.register_bot_command("whereis", {
130130
params = "<player>",
131131
description = "Tell the location of <player>",
132-
func = function(user, args)
132+
func = function(_, args)
133133
if args == "" then
134134
return false, "Player name required."
135135
end
@@ -145,9 +145,9 @@ irc:register_bot_command("whereis", {
145145

146146

147147
local starttime = os.time()
148-
irc:register_bot_command("uptime", {
148+
irc.register_bot_command("uptime", {
149149
description = "Tell how much time the server has been up",
150-
func = function(user, args)
150+
func = function()
151151
local cur_time = os.time()
152152
local diff = os.difftime(cur_time, starttime)
153153
local fmt = "Server has been running for %d:%02d:%02d"
@@ -160,9 +160,9 @@ irc:register_bot_command("uptime", {
160160
})
161161

162162

163-
irc:register_bot_command("players", {
163+
irc.register_bot_command("players", {
164164
description = "List the players on the server",
165-
func = function(user, args)
165+
func = function()
166166
local players = minetest.get_connected_players()
167167
local names = {}
168168
for _, player in pairs(players) do

callback.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
minetest.register_on_joinplayer(function(player)
66
local name = player:get_player_name()
77
if irc.connected and irc.config.send_join_part then
8-
irc:say("*** "..name.." joined the game")
8+
irc.say("*** "..name.." joined the game")
99
end
1010
end)
1111

1212

1313
minetest.register_on_leaveplayer(function(player, timed_out)
1414
local name = player:get_player_name()
1515
if irc.connected and irc.config.send_join_part then
16-
irc:say("*** "..name.." left the game"..
16+
irc.say("*** "..name.." left the game"..
1717
(timed_out and " (Timed out)" or ""))
1818
end
1919
end)
@@ -31,11 +31,11 @@ minetest.register_on_chat_message(function(name, message)
3131
if nl then
3232
message = message:sub(1, nl - 1)
3333
end
34-
irc:say(irc:playerMessage(name, message))
34+
irc.say(irc.playerMessage(name, message))
3535
end)
3636

3737

3838
minetest.register_on_shutdown(function()
39-
irc:disconnect("Game shutting down.")
39+
irc.disconnect("Game shutting down.")
4040
end)
4141

chatcmds.lua

+14-14
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ minetest.register_chatcommand("irc_msg", {
2020
local toname_l = toname:lower()
2121
local validNick = false
2222
local hint = "They have to be in the channel"
23-
for nick, user in pairs(irc.conn.channels[irc.config.channel].users) do
23+
for nick in pairs(irc.conn.channels[irc.config.channel].users) do
2424
if nick:lower() == toname_l then
2525
validNick = true
2626
break
@@ -33,7 +33,7 @@ minetest.register_chatcommand("irc_msg", {
3333
if not validNick then
3434
return false, "You can not message that user. ("..hint..")"
3535
end
36-
irc:say(toname, irc:playerMessage(name, message))
36+
irc.say(toname, irc.playerMessage(name, message))
3737
return true, "Message sent!"
3838
end
3939
})
@@ -42,13 +42,13 @@ minetest.register_chatcommand("irc_msg", {
4242
minetest.register_chatcommand("irc_names", {
4343
params = "",
4444
description = "List the users in IRC.",
45-
func = function(name, params)
45+
func = function()
4646
if not irc.connected then
4747
return false, "Not connected to IRC. Use /irc_connect to connect."
4848
end
4949
local users = { }
50-
for k, v in pairs(irc.conn.channels[irc.config.channel].users) do
51-
table.insert(users, k)
50+
for nick in pairs(irc.conn.channels[irc.config.channel].users) do
51+
table.insert(users, nick)
5252
end
5353
return true, "Users in IRC: "..table.concat(users, ", ")
5454
end
@@ -58,12 +58,12 @@ minetest.register_chatcommand("irc_names", {
5858
minetest.register_chatcommand("irc_connect", {
5959
description = "Connect to the IRC server.",
6060
privs = {irc_admin=true},
61-
func = function(name, param)
61+
func = function(name)
6262
if irc.connected then
6363
return false, "You are already connected to IRC."
6464
end
6565
minetest.chat_send_player(name, "IRC: Connecting...")
66-
irc:connect()
66+
irc.connect()
6767
end
6868
})
6969

@@ -79,21 +79,21 @@ minetest.register_chatcommand("irc_disconnect", {
7979
if param == "" then
8080
param = "Manual disconnect by "..name
8181
end
82-
irc:disconnect(param)
82+
irc.disconnect(param)
8383
end
8484
})
8585

8686

8787
minetest.register_chatcommand("irc_reconnect", {
8888
description = "Reconnect to the IRC server.",
8989
privs = {irc_admin=true},
90-
func = function(name, param)
90+
func = function(name)
9191
if not irc.connected then
9292
return false, "Not connected to IRC. Use /irc_connect to connect."
9393
end
9494
minetest.chat_send_player(name, "IRC: Reconnecting...")
95-
irc:disconnect("Reconnecting...")
96-
irc:connect()
95+
irc.disconnect("Reconnecting...")
96+
irc.connect()
9797
end
9898
})
9999

@@ -106,7 +106,7 @@ minetest.register_chatcommand("irc_quote", {
106106
if not irc.connected then
107107
return false, "Not connected to IRC. Use /irc_connect to connect."
108108
end
109-
irc:queue(param)
109+
irc.queue(param)
110110
minetest.chat_send_player(name, "Command sent!")
111111
end
112112
})
@@ -115,7 +115,7 @@ minetest.register_chatcommand("irc_quote", {
115115
local oldme = minetest.chatcommands["me"].func
116116
-- luacheck: ignore
117117
minetest.chatcommands["me"].func = function(name, param, ...)
118-
irc:say(("* %s %s"):format(name, param))
118+
irc.say(("* %s %s"):format(name, param))
119119
return oldme(name, param, ...)
120120
end
121121

@@ -127,7 +127,7 @@ if irc.config.send_kicks and minetest.chatcommands["kick"] then
127127
if not plname then
128128
return false, "Usage: /kick player [reason]"
129129
end
130-
irc:say(("*** Kicked %s.%s"):format(name,
130+
irc.say(("*** Kicked %s.%s"):format(name,
131131
reason~="" and " Reason: "..reason or ""))
132132
return oldkick(name, param, ...)
133133
end

0 commit comments

Comments
 (0)