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:
48
botcmds.lua
48
botcmds.lua
@ -15,7 +15,7 @@ local function nickequals(nick1, nick2)
|
||||
return irclower(nick1) == irclower(nick2)
|
||||
end
|
||||
|
||||
function irc:check_botcmd(msg)
|
||||
function irc.check_botcmd(msg)
|
||||
local prefix = irc.config.command_prefix
|
||||
local nick = irc.conn.nick
|
||||
local text = msg.args[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
|
||||
self:bot_command(msg, text:sub(#nick + 3))
|
||||
irc.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
|
||||
self:bot_command(msg, text:sub(#prefix + 1))
|
||||
irc.bot_command(msg, text:sub(#prefix + 1))
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
function irc:bot_command(msg, text)
|
||||
function irc.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.")
|
||||
irc.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.")
|
||||
irc.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!")
|
||||
irc.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 self.bot_commands[cmd] then
|
||||
self:reply("Unknown command '"..cmd.."'. Try 'help'."
|
||||
if not irc.bot_commands[cmd] then
|
||||
irc.reply("Unknown command '"..cmd.."'. Try 'help'."
|
||||
.." Or use @playername <message> to send a private message")
|
||||
return
|
||||
end
|
||||
|
||||
local _, message = self.bot_commands[cmd].func(msg.user, args)
|
||||
local _, message = irc.bot_commands[cmd].func(msg.user, args)
|
||||
if message then
|
||||
self:reply(message)
|
||||
irc.reply(message)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function irc:register_bot_command(name, def)
|
||||
function irc.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
|
||||
self.bot_commands[name] = def
|
||||
irc.bot_commands[name] = def
|
||||
end
|
||||
|
||||
|
||||
irc:register_bot_command("help", {
|
||||
irc.register_bot_command("help", {
|
||||
params = "<command>",
|
||||
description = "Get help about a command",
|
||||
func = function(user, args)
|
||||
func = function(_, args)
|
||||
if args == "" then
|
||||
local cmdlist = { }
|
||||
for name, cmd in pairs(irc.bot_commands) do
|
||||
for name in pairs(irc.bot_commands) do
|
||||
cmdlist[#cmdlist+1] = name
|
||||
end
|
||||
return true, "Available commands: "..table.concat(cmdlist, ", ")
|
||||
@ -116,20 +116,20 @@ irc:register_bot_command("help", {
|
||||
})
|
||||
|
||||
|
||||
irc:register_bot_command("list", {
|
||||
irc.register_bot_command("list", {
|
||||
params = "",
|
||||
description = "List available commands.",
|
||||
func = function(user, args)
|
||||
func = function()
|
||||
return false, "The `list` command has been merged into `help`."
|
||||
.." Use `help` with no arguments to get a list."
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
irc:register_bot_command("whereis", {
|
||||
irc.register_bot_command("whereis", {
|
||||
params = "<player>",
|
||||
description = "Tell the location of <player>",
|
||||
func = function(user, args)
|
||||
func = function(_, args)
|
||||
if args == "" then
|
||||
return false, "Player name required."
|
||||
end
|
||||
@ -145,9 +145,9 @@ irc:register_bot_command("whereis", {
|
||||
|
||||
|
||||
local starttime = os.time()
|
||||
irc:register_bot_command("uptime", {
|
||||
irc.register_bot_command("uptime", {
|
||||
description = "Tell how much time the server has been up",
|
||||
func = function(user, args)
|
||||
func = function()
|
||||
local cur_time = os.time()
|
||||
local diff = os.difftime(cur_time, starttime)
|
||||
local fmt = "Server has been running for %d:%02d:%02d"
|
||||
@ -160,9 +160,9 @@ irc:register_bot_command("uptime", {
|
||||
})
|
||||
|
||||
|
||||
irc:register_bot_command("players", {
|
||||
irc.register_bot_command("players", {
|
||||
description = "List the players on the server",
|
||||
func = function(user, args)
|
||||
func = function()
|
||||
local players = minetest.get_connected_players()
|
||||
local names = {}
|
||||
for _, player in pairs(players) do
|
||||
|
Reference in New Issue
Block a user