irc2/chatcmds.lua

135 lines
3.8 KiB
Lua
Raw Permalink Normal View History

2013-04-29 15:07:44 -07:00
-- This file is licensed under the terms of the BSD 2-clause license.
-- See LICENSE.txt for details.
2012-12-21 19:16:28 -08:00
2013-04-29 15:07:44 -07: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 07:50:47 -08:00
2019-07-24 18:53:22 -07:00
minetest.register_chatcommand("irc2_msg", {
2013-04-29 15:07:44 -07:00
params = "<name> <message>",
2021-05-26 20:54:00 -07:00
description = "Send a private message to a Libera Chat (IRC) user",
2013-04-29 15:07:44 -07:00
privs = {shout=true},
func = function(name, param)
2019-07-24 18:53:22 -07:00
if not irc2.connected then
2021-05-26 20:54:00 -07:00
return false, "Not connected to Libera IRC. Use /irc2_connect to connect."
2013-04-25 14:00:44 -07:00
end
2013-04-29 15:07:44 -07:00
local found, _, toname, message = param:find("^([^%s]+)%s(.+)")
2013-04-25 14:00:44 -07:00
if not found then
2019-07-24 18:53:22 -07:00
return false, "Invalid usage, see /help irc2_msg."
2013-04-29 15:07:44 -07:00
end
local toname_l = toname:lower()
2013-04-29 15:07:44 -07:00
local validNick = false
local hint = "They have to be in the channel"
2019-07-24 18:53:22 -07:00
for nick in pairs(irc2.conn.channels[irc2.config.channel].users) do
if nick:lower() == toname_l then
2013-04-29 15:07:44 -07:00
validNick = true
break
end
2013-04-25 14:00:44 -07:00
end
if toname_l:find("serv$") or toname_l:find("bot$") then
hint = "it looks like a bot or service"
2013-04-29 15:07:44 -07:00
validNick = false
end
if not validNick then
return false, "You can not message that user. ("..hint..")"
2013-04-29 15:07:44 -07:00
end
2019-07-24 18:53:22 -07:00
irc2.say(toname, irc2.playerMessage(name, message))
return true, "Message sent!"
2013-04-29 15:07:44 -07:00
end
})
2012-12-21 19:16:28 -08:00
2019-07-24 18:53:22 -07:00
minetest.register_chatcommand("irc2_names", {
2013-10-22 20:20:27 -07:00
params = "",
2021-05-26 20:54:00 -07:00
description = "List the users in Libera IRC.",
func = function()
2019-07-24 18:53:22 -07:00
if not irc2.connected then
2021-05-26 20:54:00 -07:00
return false, "Not connected to Libera IRC. Use /irc2_connect to connect."
end
2013-10-22 20:20:27 -07:00
local users = { }
2019-07-24 18:53:22 -07:00
for nick in pairs(irc2.conn.channels[irc2.config.channel].users) do
table.insert(users, nick)
2013-10-22 20:20:27 -07:00
end
2021-05-26 20:54:00 -07:00
return true, "Users in Libera IRC: "..table.concat(users, ", ")
2013-10-22 20:20:27 -07:00
end
})
2019-07-24 18:53:22 -07:00
minetest.register_chatcommand("irc2_connect", {
2021-05-26 20:54:00 -07:00
description = "Connect to the Libera IRC server.",
2019-07-24 18:53:22 -07:00
privs = {irc2_admin=true},
func = function(name)
2019-07-24 18:53:22 -07:00
if irc2.connected then
2021-05-26 20:54:00 -07:00
return false, "You are already connected to Libera IRC."
2013-04-25 14:00:44 -07:00
end
2013-04-29 15:07:44 -07:00
minetest.chat_send_player(name, "IRC: Connecting...")
2019-07-24 18:53:22 -07:00
irc2.connect()
2013-04-29 15:07:44 -07:00
end
})
2012-12-21 19:16:28 -08:00
2019-07-24 18:53:22 -07:00
minetest.register_chatcommand("irc2_disconnect", {
2014-05-06 12:26:13 -07:00
params = "[message]",
2021-05-26 20:54:00 -07:00
description = "Disconnect from Libera IRC.",
2019-07-24 18:53:22 -07:00
privs = {irc2_admin=true},
2013-04-29 15:07:44 -07:00
func = function(name, param)
2019-07-24 18:53:22 -07:00
if not irc2.connected then
2021-05-26 20:54:00 -07:00
return false, "Not connected to Libera IRC. Use /irc2_connect to connect."
2013-04-25 14:00:44 -07:00
end
2017-02-15 21:36:04 -08:00
if param == "" then
param = "Manual disconnect by "..name
2014-05-06 12:26:13 -07:00
end
2019-07-24 18:53:22 -07:00
irc2.disconnect(param)
2013-04-29 15:07:44 -07:00
end
})
2019-07-24 18:53:22 -07:00
minetest.register_chatcommand("irc2_reconnect", {
2021-05-26 20:54:00 -07:00
description = "Reconnect to Libera IRC.",
2019-07-24 18:53:22 -07:00
privs = {irc2_admin=true},
func = function(name)
2019-07-24 18:53:22 -07:00
if not irc2.connected then
2021-05-26 20:54:00 -07:00
return false, "Not connected to Libera IRC. Use /irc2_connect to connect."
2013-04-25 14:00:44 -07:00
end
minetest.chat_send_player(name, "IRC: Reconnecting...")
2019-07-24 18:53:22 -07:00
irc2.disconnect("Reconnecting...")
irc2.connect()
2013-04-29 15:07:44 -07:00
end
})
2012-12-21 19:16:28 -08:00
2019-07-24 18:53:22 -07:00
minetest.register_chatcommand("irc2_quote", {
2013-04-29 15:07:44 -07:00
params = "<command>",
2021-05-26 20:54:00 -07:00
description = "Send a raw command Libera IRC.",
2019-07-24 18:53:22 -07:00
privs = {irc2_admin=true},
2012-12-21 19:16:28 -08:00
func = function(name, param)
2019-07-24 18:53:22 -07:00
if not irc2.connected then
2021-05-26 20:54:00 -07:00
return false, "Not connected to Libera IRC. Use /irc2_connect to connect."
2013-04-29 15:07:44 -07:00
end
2019-07-24 18:53:22 -07:00
irc2.queue(param)
2013-04-29 15:07:44 -07:00
minetest.chat_send_player(name, "Command sent!")
end
2012-12-21 19:16:28 -08:00
})
2012-12-26 17:29:22 -08:00
2013-04-29 15:07:44 -07:00
local oldme = minetest.chatcommands["me"].func
2017-02-15 21:36:04 -08:00
-- luacheck: ignore
2014-05-06 12:26:13 -07:00
minetest.chatcommands["me"].func = function(name, param, ...)
2019-07-24 18:53:22 -07:00
irc2.say(("* %s %s"):format(name, param))
return oldme(name, param, ...)
2013-04-29 15:07:44 -07:00
end
2019-07-24 18:53:22 -07:00
if irc2.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
2019-07-24 18:53:22 -07:00
irc2.say(("*** Kicked %s.%s"):format(name,
reason~="" and " Reason: "..reason or ""))
return oldkick(name, param, ...)
end
end