-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
285 lines (249 loc) · 7.05 KB
/
init.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
--ANTI SPAM
local spam_warnings = 3 -- warn this many times before taking action
local msg_count = {}
local first_msg = {}
local spam_warn = {}
clam_antispam = {}
clam_antispam.muted = {}
clam_antispam.ignore = {}
--This is a statistic generated from historic clamity chat. the key is the amount of messages and the value is the shortest time anyone has taken to say that many messages ( this list was provided by anon5 )
local msg_cap = {
[1]=0,
[2]=0,
[3]=6,
[4]=10,
[5]=14,
[6]=18,
[7]=36,
[8]=39,
[9]=60,
[10]=86,
[11]=124,
[12]=137,
[13]=150,
[14]=156,
[15]=171,
[16]=177,
[17]=192,
[18]=207,
[19]=233,
[20]=244,
[21]=270,
[22]=303,
[23]=318,
[24]=342,
[25]=355,
[26]=402,
[27]=412,
[28]=450,
[29]=492,
[30]=540,
[31]=555,
[32]=588,
[33]=592
}
--[[] debug
msg_cap = {
[1]=0,
[2]=0,
[3]=6,
[4]=6,
[5]=6,
[6]=6,
[7]=6,
[8]=6,
[9]=10
}--]]
local function send_all_ignore(name,msg)
if discord then discord.send(('<%s>: %s'):format(name, msg)) end
for _,p in ipairs(minetest.get_connected_players()) do
local pn=p:get_player_name()
if not clam_antispam.ignore[pn][name] then
minetest.chat_send_player(pn,msg)
end
end
end
local function send_ply_ignore(name,msg,recv)
if not clam_antispam.ignore[recv][name] then
minetest.chat_send_player(recv,msg)
end
end
local function player_online(name)
for _,p in ipairs(minetest.get_connected_players()) do
if p:get_player_name() == name then return true end
end
end
local function process_msg(name,message,bycmd,recv)
if not core.get_player_by_name(name) then return end
if badges and badges.get_badge(name) then
if bycmd then
if not recv then
if discord then discord.send(('<%s>: %s'):format(name, msg)) end
return minetest.chat_send_all(message)
else
return minetest.chat_send_player(recv,message)
end
end
if discord then discord.send(msg) end
return badges.chat_send(name, message)
end
if msg_count[name] == nil then msg_count[name] = 0 end
if msg_count[name] <= 1 then first_msg[name] = os.time() end
local et=os.time() - first_msg[name] --elapsed time
msg_count[name] = msg_count[name] + 1
--restart the "loop" when the time hits the largest value from the list
if et > msg_cap[#msg_cap] then
msg_count[name] = 1
spam_warn[name] = 1
end
--kick the player when they said more messages than on the list within the max time
if msg_cap[msg_count[name]] == nil then
if msg_count[name] > #msg_cap then minetest.kick_player(name, "You talk too much") end
msg_count[name] = math.random(3,msg_cap[#msg_cap]) --set the counter to a random position to make it less predictable
return true
end
if et < msg_cap[msg_count[name]] then --spam detected
if not spam_warn[name] then spam_warn[name]=1 end
--if the player has been warned sufficiently, only display their spam to them.
if spam_warn[name] and spam_warn[name] >= spam_warnings then
clam_antispam.muted[name] = true
else --otherwise print a warning
spam_warn[name] = spam_warn[name] + 1
minetest.chat_send_player(name,"Don't spam >:( you have been warned (" .. spam_warn[name] .. ").")
end
else
clam_antispam.muted[name] = nil
spam_warn[name] = 1
end
if not clam_antispam.muted[name] then
if recv and player_online(recv) then
send_ply_ignore(name,message,recv)
else
message=('<%s>: %s'):format(name, message)
send_all_ignore(name,message)
end
else
send_ply_ignore(name,message,name)
end
return true
end
minetest.unregister_chatcommand("me")
minetest.unregister_chatcommand("msg")
minetest.unregister_chatcommand("greentext")
minetest.register_chatcommand("me", {
params = "<action>",
description = "Show chat action (e.g., '/me orders a pizza' displays '<player name> orders a pizza')",
privs = {shout = true},
func = function(name, param)
if param:find("<") or param:find(">") then
param = minetest.strip_colors(param)
end
return process_msg(name," " .. minetest.colorize("#B0B0B0", name .. " " .. param),true)
end,
})
minetest.register_chatcommand("greentext", {
params = "<action>",
description = "Sends a message in greentext",
privs = {shout = true},
func = function(name, param)
return process_msg(name,minetest.colorize("#789922", " <" .. name .. ">: >" .. param),true)
end,
})
minetest.register_chatcommand("msg", {
params = "<name> <message>",
description = "Send a direct message to a player",
privs = {shout=true},
func = function(name, param)
local sendto, message = param:match("^(%S+)%s(.+)$")
if not sendto then
return false, "Invalid usage, see /help msg."
end
if not core.get_player_by_name(sendto) then
return false, "The player " .. sendto
.. " is not online."
end
core.log("action", "DM from " .. name .. " to " .. sendto
.. ": " .. message)
process_msg(name, "DM from " .. name .. ": ".. message,true,sendto)
return true, "DM to "..sendto..": "..message
end,
})
minetest.register_on_chat_message(process_msg)
minetest.register_on_leaveplayer(function(lp, timed_out)
local name=lp:get_player_name()
msg_count[name] = nil
spam_warn[name] = nil
first_msg[name] = nil
clam_antispam.muted[name] = nil
end)
-- IGNORE
minetest.register_on_joinplayer(function(lp, timed_out)
local name=lp:get_player_name()
clam_antispam.ignore[name] = {}
end)
minetest.register_on_leaveplayer(function(lp, timed_out)
local name=lp:get_player_name()
clam_antispam.ignore[name] = nil
end)
local function ignore_player(name,igname)
if player_online(igname) then
clam_antispam.ignore[name][igname] = true
return true
end
end
local function unignore_player(name,igname)
if clam_antispam.ignore[name][igname] then
clam_antispam.ignore[name][igname] = nil
return true
end
end
local function get_ignores(name)
local r={}
for k,v in pairs(clam_antispam.ignore[name]) do
if v then table.insert(r,k) end
end
return r
end
local function get_ignorers(name)
local r={}
for p,l in pairs(clam_antispam.ignore) do
for pp,st in pairs(l) do
if name == pp then
table.insert(r,p)
end
end
end
return r
end
local function print_ignores(name)
return "Ignored players: "..table.concat(get_ignores(name),',')..". These players are ignoring you: "..table.concat(get_ignorers(name))
end
minetest.register_chatcommand("unignore", {
params = "<playername>",
description = "Unignore a player",
privs = {shout = true},
func = function(name, param)
param=tostring(param)
if unignore_player(name,param) then
return true, "Player "..param.." unignored. "..print_ignores(name)
end
return false,"Player "..param.." not on ignorelist. "..print_ignores(name)
end,
})
minetest.register_chatcommand("ignore", {
params = "<playername>",
description = "Ignore a player",
privs = {shout = true},
func = function(name, param)
param=tostring(param)
if ignore_player(name,param) then
return true, "Player "..param.." ignored. "..print_ignores(name)
end
return false,"Player "..param.." not online. "..print_ignores(name)
end,
})
minetest.register_chatcommand("ignorestats", {
description = "Show who you ignore and who ignores you.",
privs = {shout = true},
func = function(name) return true,print_ignores(name) end,
})