2013-04-30 00:07:44 +02:00
|
|
|
-- This file is licensed under the terms of the BSD 2-clause license.
|
|
|
|
-- See LICENSE.txt for details.
|
2012-12-22 04:16:28 +01:00
|
|
|
|
2013-04-30 00:07:44 +02:00
|
|
|
-- Note: This file does NOT conatin every chat command, only general ones.
|
|
|
|
-- Feature-specific commands (like /join) are in their own files.
|
2013-01-08 16:50:47 +01:00
|
|
|
|
|
|
|
|
2013-04-20 20:45:11 +02:00
|
|
|
minetest.register_chatcommand("irc_msg", {
|
2013-04-30 00:07:44 +02:00
|
|
|
params = "<name> <message>",
|
|
|
|
description = "Send a private message to an IRC user",
|
|
|
|
privs = {shout=true},
|
|
|
|
func = function(name, param)
|
2014-05-26 04:52:24 +02:00
|
|
|
if not irc.connected then
|
2016-11-28 06:02:40 +01:00
|
|
|
return false, "Not connected to IRC. Use /irc_connect to connect."
|
2013-04-25 23:00:44 +02:00
|
|
|
end
|
2013-04-30 00:07:44 +02:00
|
|
|
local found, _, toname, message = param:find("^([^%s]+)%s(.+)")
|
2013-04-25 23:00:44 +02:00
|
|
|
if not found then
|
2016-11-28 06:02:40 +01:00
|
|
|
return false, "Invalid usage, see /help irc_msg."
|
2013-04-30 00:07:44 +02:00
|
|
|
end
|
2013-10-23 05:23:02 +02:00
|
|
|
local toname_l = toname:lower()
|
2013-04-30 00:07:44 +02:00
|
|
|
local validNick = false
|
2016-11-28 06:02:40 +01:00
|
|
|
local hint = "They have to be in the channel"
|
2017-03-16 01:33:47 +01:00
|
|
|
for nick in pairs(irc.conn.channels[irc.config.channel].users) do
|
2013-10-23 05:23:02 +02:00
|
|
|
if nick:lower() == toname_l then
|
2013-04-30 00:07:44 +02:00
|
|
|
validNick = true
|
|
|
|
break
|
|
|
|
end
|
2013-04-25 23:00:44 +02:00
|
|
|
end
|
2013-10-23 05:23:02 +02:00
|
|
|
if toname_l:find("serv$") or toname_l:find("bot$") then
|
2016-11-28 06:02:40 +01:00
|
|
|
hint = "it looks like a bot or service"
|
2013-04-30 00:07:44 +02:00
|
|
|
validNick = false
|
|
|
|
end
|
|
|
|
if not validNick then
|
2016-11-28 06:02:40 +01:00
|
|
|
return false, "You can not message that user. ("..hint..")"
|
2013-04-30 00:07:44 +02:00
|
|
|
end
|
2017-03-16 01:33:47 +01:00
|
|
|
irc.say(toname, irc.playerMessage(name, message))
|
2016-11-28 06:02:40 +01:00
|
|
|
return true, "Message sent!"
|
2013-04-30 00:07:44 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2012-12-22 04:16:28 +01:00
|
|
|
|
2013-10-23 05:20:27 +02:00
|
|
|
minetest.register_chatcommand("irc_names", {
|
|
|
|
params = "",
|
|
|
|
description = "List the users in IRC.",
|
2017-03-16 01:33:47 +01:00
|
|
|
func = function()
|
2015-01-18 02:41:24 +01:00
|
|
|
if not irc.connected then
|
2016-11-28 06:02:40 +01:00
|
|
|
return false, "Not connected to IRC. Use /irc_connect to connect."
|
2015-01-18 02:41:24 +01:00
|
|
|
end
|
2013-10-23 05:20:27 +02:00
|
|
|
local users = { }
|
2017-03-16 01:33:47 +01:00
|
|
|
for nick in pairs(irc.conn.channels[irc.config.channel].users) do
|
|
|
|
table.insert(users, nick)
|
2013-10-23 05:20:27 +02:00
|
|
|
end
|
2016-11-28 06:02:40 +01:00
|
|
|
return true, "Users in IRC: "..table.concat(users, ", ")
|
2013-10-23 05:20:27 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2012-12-22 04:16:28 +01:00
|
|
|
minetest.register_chatcommand("irc_connect", {
|
2013-04-30 00:07:44 +02:00
|
|
|
description = "Connect to the IRC server.",
|
|
|
|
privs = {irc_admin=true},
|
2017-03-16 01:33:47 +01:00
|
|
|
func = function(name)
|
2014-05-26 04:52:24 +02:00
|
|
|
if irc.connected then
|
2016-11-28 06:02:40 +01:00
|
|
|
return false, "You are already connected to IRC."
|
2013-04-25 23:00:44 +02:00
|
|
|
end
|
2013-04-30 00:07:44 +02:00
|
|
|
minetest.chat_send_player(name, "IRC: Connecting...")
|
2017-03-16 01:33:47 +01:00
|
|
|
irc.connect()
|
2013-04-30 00:07:44 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2012-12-22 04:16:28 +01:00
|
|
|
|
2012-12-31 16:53:01 +01:00
|
|
|
minetest.register_chatcommand("irc_disconnect", {
|
2014-05-06 21:26:13 +02:00
|
|
|
params = "[message]",
|
2013-04-30 00:07:44 +02:00
|
|
|
description = "Disconnect from the IRC server.",
|
|
|
|
privs = {irc_admin=true},
|
|
|
|
func = function(name, param)
|
2014-05-26 04:52:24 +02:00
|
|
|
if not irc.connected then
|
2016-11-28 06:02:40 +01:00
|
|
|
return false, "Not connected to IRC. Use /irc_connect to connect."
|
2013-04-25 23:00:44 +02:00
|
|
|
end
|
2017-02-16 06:36:04 +01:00
|
|
|
if param == "" then
|
|
|
|
param = "Manual disconnect by "..name
|
2014-05-06 21:26:13 +02:00
|
|
|
end
|
2017-03-16 01:33:47 +01:00
|
|
|
irc.disconnect(param)
|
2013-04-30 00:07:44 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2012-12-31 16:53:01 +01:00
|
|
|
|
|
|
|
minetest.register_chatcommand("irc_reconnect", {
|
2013-04-30 00:07:44 +02:00
|
|
|
description = "Reconnect to the IRC server.",
|
|
|
|
privs = {irc_admin=true},
|
2017-03-16 01:33:47 +01:00
|
|
|
func = function(name)
|
2014-05-26 04:52:24 +02:00
|
|
|
if not irc.connected then
|
2016-11-28 06:02:40 +01:00
|
|
|
return false, "Not connected to IRC. Use /irc_connect to connect."
|
2013-04-25 23:00:44 +02:00
|
|
|
end
|
2016-11-28 06:02:40 +01:00
|
|
|
minetest.chat_send_player(name, "IRC: Reconnecting...")
|
2017-03-16 01:33:47 +01:00
|
|
|
irc.disconnect("Reconnecting...")
|
|
|
|
irc.connect()
|
2013-04-30 00:07:44 +02:00
|
|
|
end
|
|
|
|
})
|
2012-12-22 04:16:28 +01:00
|
|
|
|
|
|
|
|
2013-04-30 00:07:44 +02:00
|
|
|
minetest.register_chatcommand("irc_quote", {
|
|
|
|
params = "<command>",
|
|
|
|
description = "Send a raw command to the IRC server.",
|
|
|
|
privs = {irc_admin=true},
|
2012-12-22 04:16:28 +01:00
|
|
|
func = function(name, param)
|
2014-05-26 04:52:24 +02:00
|
|
|
if not irc.connected then
|
2016-11-28 06:02:40 +01:00
|
|
|
return false, "Not connected to IRC. Use /irc_connect to connect."
|
2013-04-30 00:07:44 +02:00
|
|
|
end
|
2017-03-16 01:33:47 +01:00
|
|
|
irc.queue(param)
|
2013-04-30 00:07:44 +02:00
|
|
|
minetest.chat_send_player(name, "Command sent!")
|
|
|
|
end
|
2012-12-22 04:16:28 +01:00
|
|
|
})
|
2012-12-27 02:29:22 +01:00
|
|
|
|
2013-04-30 00:07:44 +02:00
|
|
|
|
|
|
|
local oldme = minetest.chatcommands["me"].func
|
2017-02-16 06:36:04 +01:00
|
|
|
-- luacheck: ignore
|
2014-05-06 21:26:13 +02:00
|
|
|
minetest.chatcommands["me"].func = function(name, param, ...)
|
2017-03-16 01:33:47 +01:00
|
|
|
irc.say(("* %s %s"):format(name, param))
|
2016-11-28 06:02:40 +01:00
|
|
|
return oldme(name, param, ...)
|
2013-04-30 00:07:44 +02:00
|
|
|
end
|
|
|
|
|
2017-02-21 06:07:36 +01:00
|
|
|
if irc.config.send_kicks and minetest.chatcommands["kick"] then
|
|
|
|
local oldkick = minetest.chatcommands["kick"].func
|
|
|
|
-- luacheck: ignore
|
|
|
|
minetest.chatcommands["kick"].func = function(name, param, ...)
|
|
|
|
local plname, reason = param:match("^(%S+)%s*(.*)$")
|
|
|
|
if not plname then
|
|
|
|
return false, "Usage: /kick player [reason]"
|
|
|
|
end
|
2017-03-16 01:33:47 +01:00
|
|
|
irc.say(("*** Kicked %s.%s"):format(name,
|
2017-02-21 06:07:36 +01:00
|
|
|
reason~="" and " Reason: "..reason or ""))
|
|
|
|
return oldkick(name, param, ...)
|
|
|
|
end
|
|
|
|
end
|