forked from minetest-mods/irc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatcmds.lua
134 lines (118 loc) · 3.68 KB
/
chatcmds.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
-- This file is licensed under the terms of the BSD 2-clause license.
-- See LICENSE.txt for details.
-- Note: This file does NOT conatin every chat command, only general ones.
-- Feature-specific commands (like /join) are in their own files.
minetest.register_chatcommand("irc_msg", {
params = "<name> <message>",
description = "Send a private message to an IRC user",
privs = {shout=true},
func = function(name, param)
if not irc.connected then
return false, "Not connected to IRC. Use /irc_connect to connect."
end
local found, _, toname, message = param:find("^([^%s]+)%s(.+)")
if not found then
return false, "Invalid usage, see /help irc_msg."
end
local toname_l = toname:lower()
local validNick = false
local hint = "They have to be in the channel"
for nick in pairs(irc.conn.channels[irc.config.channel].users) do
if nick:lower() == toname_l then
validNick = true
break
end
end
if toname_l:find("serv$") or toname_l:find("bot$") then
hint = "it looks like a bot or service"
validNick = false
end
if not validNick then
return false, "You can not message that user. ("..hint..")"
end
irc.say(toname, irc.playerMessage(name, message))
return true, "Message sent!"
end
})
minetest.register_chatcommand("irc_names", {
params = "",
description = "List the users in IRC.",
func = function()
if not irc.connected then
return false, "Not connected to IRC. Use /irc_connect to connect."
end
local users = { }
for nick in pairs(irc.conn.channels[irc.config.channel].users) do
table.insert(users, nick)
end
return true, "Users in IRC: "..table.concat(users, ", ")
end
})
minetest.register_chatcommand("irc_connect", {
description = "Connect to the IRC server.",
privs = {irc_admin=true},
func = function(name)
if irc.connected then
return false, "You are already connected to IRC."
end
minetest.chat_send_player(name, "IRC: Connecting...")
irc.connect()
end
})
minetest.register_chatcommand("irc_disconnect", {
params = "[message]",
description = "Disconnect from the IRC server.",
privs = {irc_admin=true},
func = function(name, param)
if not irc.connected then
return false, "Not connected to IRC. Use /irc_connect to connect."
end
if param == "" then
param = "Manual disconnect by "..name
end
irc.disconnect(param)
end
})
minetest.register_chatcommand("irc_reconnect", {
description = "Reconnect to the IRC server.",
privs = {irc_admin=true},
func = function(name)
if not irc.connected then
return false, "Not connected to IRC. Use /irc_connect to connect."
end
minetest.chat_send_player(name, "IRC: Reconnecting...")
irc.disconnect("Reconnecting...")
irc.connect()
end
})
minetest.register_chatcommand("irc_quote", {
params = "<command>",
description = "Send a raw command to the IRC server.",
privs = {irc_admin=true},
func = function(name, param)
if not irc.connected then
return false, "Not connected to IRC. Use /irc_connect to connect."
end
irc.queue(param)
minetest.chat_send_player(name, "Command sent!")
end
})
local oldme = minetest.chatcommands["me"].func
-- luacheck: ignore
minetest.chatcommands["me"].func = function(name, param, ...)
irc.say(("* %s %s"):format(name, param))
return oldme(name, param, ...)
end
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
irc.say(("*** Kicked %s.%s"):format(name,
reason~="" and " Reason: "..reason or ""))
return oldkick(name, param, ...)
end
end