|
|
@@ -3,6 +3,7 @@ from discord.ext import commands
|
|
3
|
3
|
from datetime import datetime, timedelta
|
|
4
|
4
|
import math
|
|
5
|
5
|
|
|
|
6
|
+from config import CONFIG
|
|
6
|
7
|
from rscollections import AgeBoundList, SizeBoundDict
|
|
7
|
8
|
from cogs.basecog import BaseCog
|
|
8
|
9
|
from storage import Storage
|
|
|
@@ -39,16 +40,20 @@ class CrossPostCog(BaseCog):
|
|
39
|
40
|
# Config
|
|
40
|
41
|
|
|
41
|
42
|
def __warn_count(self, guild: Guild) -> int:
|
|
42
|
|
- return Storage.get_config_value(guild, self.CONFIG_KEY_WARN_COUNT) or 3
|
|
|
43
|
+ return Storage.get_config_value(guild, self.CONFIG_KEY_WARN_COUNT) or \
|
|
|
44
|
+ self.get_cog_default('warn_message_count')
|
|
43
|
45
|
|
|
44
|
46
|
def __ban_count(self, guild: Guild) -> int:
|
|
45
|
|
- return Storage.get_config_value(guild, self.CONFIG_KEY_BAN_COUNT) or 9999
|
|
|
47
|
+ return Storage.get_config_value(guild, self.CONFIG_KEY_BAN_COUNT) or \
|
|
|
48
|
+ self.get_cog_default('ban_message_count')
|
|
46
|
49
|
|
|
47
|
50
|
def __min_message_length(self, guild: Guild) -> int:
|
|
48
|
|
- return Storage.get_config_value(guild, self.CONFIG_KEY_MIN_MESSAGE_LENGTH) or 0
|
|
|
51
|
+ return Storage.get_config_value(guild, self.CONFIG_KEY_MIN_MESSAGE_LENGTH) or \
|
|
|
52
|
+ self.get_cog_default('min_message_length')
|
|
49
|
53
|
|
|
50
|
54
|
def __message_age_seconds(self, guild: Guild) -> int:
|
|
51
|
|
- return Storage.get_config_value(guild, self.CONFIG_KEY_MESSAGE_AGE) or 120
|
|
|
55
|
+ return Storage.get_config_value(guild, self.CONFIG_KEY_MESSAGE_AGE) or \
|
|
|
56
|
+ self.get_cog_default('time_window_seconds')
|
|
52
|
57
|
|
|
53
|
58
|
async def __record_message(self, message: Message) -> None:
|
|
54
|
59
|
if message.author.permissions_in(message.channel).ban_members:
|
|
|
@@ -109,9 +114,9 @@ class CrossPostCog(BaseCog):
|
|
109
|
114
|
f'> {content}'
|
|
110
|
115
|
if context.warning_message:
|
|
111
|
116
|
await self.update_warn(context.warning_message, msg)
|
|
112
|
|
- await context.warning_message.clear_reaction('🗑')
|
|
113
|
|
- await context.warning_message.clear_reaction('👢')
|
|
114
|
|
- await context.warning_message.clear_reaction('🚫')
|
|
|
117
|
+ await context.warning_message.clear_reaction(CONFIG['trash_emoji'])
|
|
|
118
|
+ await context.warning_message.clear_reaction(CONFIG['kick_emoji'])
|
|
|
119
|
+ await context.warning_message.clear_reaction(CONFIG['ban_emoji'])
|
|
115
|
120
|
else:
|
|
116
|
121
|
context.warning_message = await self.warn(context.member.guild, msg)
|
|
117
|
122
|
elif len(context.messages) >= self.__warn_count(context.member.guild):
|
|
|
@@ -122,34 +127,34 @@ class CrossPostCog(BaseCog):
|
|
122
|
127
|
'\n'
|
|
123
|
128
|
can_delete = len(context.messages) > len(context.deleted_messages)
|
|
124
|
129
|
if can_delete:
|
|
125
|
|
- msg += '\n🗑 to delete messages'
|
|
|
130
|
+ msg += f'\n{CONFIG["trash_emoji"]} to delete messages'
|
|
126
|
131
|
else:
|
|
127
|
132
|
msg += '\nAll messages deleted'
|
|
128
|
133
|
if not context.is_kicked:
|
|
129
|
|
- msg += '\n👢 to kick user'
|
|
|
134
|
+ msg += f'\n{CONFIG["kick_emoji"]} to kick user'
|
|
130
|
135
|
elif not context.is_banned:
|
|
131
|
136
|
msg += '\nUser kicked'
|
|
132
|
137
|
if context.is_banned:
|
|
133
|
138
|
msg += '\nUser banned'
|
|
134
|
139
|
else:
|
|
135
|
|
- msg += '\n🚫 to ban user'
|
|
|
140
|
+ msg += '\n{CONFIG["ban_emoji"]} to ban user'
|
|
136
|
141
|
if context.warning_message:
|
|
137
|
142
|
await self.update_warn(context.warning_message, msg)
|
|
138
|
143
|
else:
|
|
139
|
144
|
context.warning_message = await self.warn(context.member.guild, msg)
|
|
140
|
145
|
self.listen_for_reactions_to(context.warning_message, context)
|
|
141
|
146
|
if can_delete:
|
|
142
|
|
- await context.warning_message.add_reaction('🗑')
|
|
|
147
|
+ await context.warning_message.add_reaction(CONFIG['trash_emoji'])
|
|
143
|
148
|
else:
|
|
144
|
|
- await context.warning_message.clear_reaction('🗑')
|
|
|
149
|
+ await context.warning_message.clear_reaction(CONFIG['trash_emoji'])
|
|
145
|
150
|
if not context.is_kicked:
|
|
146
|
|
- await context.warning_message.add_reaction('👢')
|
|
|
151
|
+ await context.warning_message.add_reaction(CONFIG['kick_emoji'])
|
|
147
|
152
|
else:
|
|
148
|
|
- await context.warning_message.clear_reaction('👢')
|
|
|
153
|
+ await context.warning_message.clear_reaction(CONFIG['kick_emoji'])
|
|
149
|
154
|
if not context.is_banned:
|
|
150
|
|
- await context.warning_message.add_reaction('🚫')
|
|
|
155
|
+ await context.warning_message.add_reaction(CONFIG['ban_emoji'])
|
|
151
|
156
|
else:
|
|
152
|
|
- await context.warning_message.clear_reaction('🚫')
|
|
|
157
|
+ await context.warning_message.clear_reaction(CONFIG['ban_emoji'])
|
|
153
|
158
|
|
|
154
|
159
|
async def __delete_messages(self, context: SpamContext) -> None:
|
|
155
|
160
|
for message in context.messages - context.deleted_messages:
|
|
|
@@ -173,11 +178,11 @@ class CrossPostCog(BaseCog):
|
|
173
|
178
|
if context is None:
|
|
174
|
179
|
return
|
|
175
|
180
|
|
|
176
|
|
- if emoji.name == '🗑':
|
|
|
181
|
+ if emoji.name == CONFIG['trash_emoji']:
|
|
177
|
182
|
await self.__delete_messages(context)
|
|
178
|
|
- elif emoji.name == '👢':
|
|
|
183
|
+ elif emoji.name == CONFIG['kick_emoji']:
|
|
179
|
184
|
await self.__kick(context)
|
|
180
|
|
- elif emoji.name == '🚫':
|
|
|
185
|
+ elif emoji.name == CONFIG['ban_emoji']:
|
|
181
|
186
|
await self.__ban(context)
|
|
182
|
187
|
|
|
183
|
188
|
@commands.Cog.listener()
|
|
|
@@ -210,8 +215,10 @@ class CrossPostCog(BaseCog):
|
|
210
|
215
|
allowed_types=(int, ), min_value=self.MIN_WARN_COUNT):
|
|
211
|
216
|
return
|
|
212
|
217
|
Storage.set_config_value(context.guild, self.CONFIG_KEY_WARN_COUNT, warn_count)
|
|
213
|
|
- await context.message.reply(f'✅ Mods will be warned if a user posts ' +
|
|
214
|
|
- f'the exact same message {warn_count} or more times within ' +
|
|
|
218
|
+ await context.message.reply(
|
|
|
219
|
+ CONFIG['success_emoji'] + ' ' +
|
|
|
220
|
+ 'Mods will be warned if a user posts the exact same message ' +
|
|
|
221
|
+ f'{warn_count} or more times within ' +
|
|
215
|
222
|
f'{self.__message_age_seconds(context.guild)} seconds.',
|
|
216
|
223
|
mention_author=False)
|
|
217
|
224
|
|
|
|
@@ -239,8 +246,10 @@ class CrossPostCog(BaseCog):
|
|
239
|
246
|
allowed_types=(int, ), min_value=self.MIN_BAN_COUNT):
|
|
240
|
247
|
return
|
|
241
|
248
|
Storage.set_config_value(context.guild, self.CONFIG_KEY_BAN_COUNT, ban_count)
|
|
242
|
|
- await context.message.reply(f'✅ Users will be banned if they post ' +
|
|
243
|
|
- f'the exact same message {ban_count} or more times within ' +
|
|
|
249
|
+ await context.message.reply(
|
|
|
250
|
+ CONFIG['success_emoji'] + ' ' +
|
|
|
251
|
+ 'Users will be banned if they post the exact same message ' +
|
|
|
252
|
+ f'{ban_count} or more times within ' +
|
|
244
|
253
|
f'{self.__message_age_seconds(context.guild)} seconds.',
|
|
245
|
254
|
mention_author=False)
|
|
246
|
255
|
|
|
|
@@ -249,9 +258,11 @@ class CrossPostCog(BaseCog):
|
|
249
|
258
|
brief='Returns the number of duplicate messages to trigger an automatic ban',
|
|
250
|
259
|
)
|
|
251
|
260
|
async def joinraid_getbancount(self, context: commands.Context):
|
|
252
|
|
- await context.message.reply(f'ℹ️ Users will be banned if they post ' +
|
|
253
|
|
- f'the exact same message {self.__ban_count(context.guild)} or more ' +
|
|
254
|
|
- f'times within {self.__message_age_seconds(context.guild)} seconds.',
|
|
|
261
|
+ await context.message.reply(
|
|
|
262
|
+ CONFIG['info_emoji'] + ' ' +
|
|
|
263
|
+ 'Users will be banned if they post the exact same message ' +
|
|
|
264
|
+ f'{self.__ban_count(context.guild)} or more times within ' +
|
|
|
265
|
+ f'{self.__message_age_seconds(context.guild)} seconds.',
|
|
255
|
266
|
mention_author=False)
|
|
256
|
267
|
|
|
257
|
268
|
@crosspost.command(
|
|
|
@@ -269,11 +280,15 @@ class CrossPostCog(BaseCog):
|
|
269
|
280
|
return
|
|
270
|
281
|
Storage.set_config_value(context.guild, self.CONFIG_KEY_MIN_MESSAGE_LENGTH, min_length)
|
|
271
|
282
|
if min_length == 0:
|
|
272
|
|
- await context.message.reply(f'✅ All messages will count against ' +
|
|
273
|
|
- 'spam counts, regardless of length.', mention_author=False)
|
|
|
283
|
+ await context.message.reply(
|
|
|
284
|
+ CONFIG['success_emoji'] + ' ' +
|
|
|
285
|
+ f'All messages will count against spam counts, regardless ' +
|
|
|
286
|
+ 'of length.', mention_author=False)
|
|
274
|
287
|
else:
|
|
275
|
|
- await context.message.reply(f'✅ Only messages {min_length} ' +
|
|
276
|
|
- f'characters or longer will count against spam counts.',
|
|
|
288
|
+ await context.message.reply(
|
|
|
289
|
+ CONFIG['success_emoji'] + ' ' +
|
|
|
290
|
+ f'Only messages {min_length} characters or longer will ' +
|
|
|
291
|
+ 'count against spam counts.',
|
|
277
|
292
|
mention_author=False)
|
|
278
|
293
|
|
|
279
|
294
|
@crosspost.command(
|
|
|
@@ -283,11 +298,15 @@ class CrossPostCog(BaseCog):
|
|
283
|
298
|
async def joinraid_getminlength(self, context: commands.Context):
|
|
284
|
299
|
min_length = self.__min_message_length(context.guild)
|
|
285
|
300
|
if min_length == 0:
|
|
286
|
|
- await context.message.reply(f'ℹ️ All messages will count against ' +
|
|
287
|
|
- 'spam counts, regardless of length.', mention_author=False)
|
|
|
301
|
+ await context.message.reply(
|
|
|
302
|
+ CONFIG['info_emoji'] + ' ' +
|
|
|
303
|
+ f'All messages will count against spam counts, regardless ' +
|
|
|
304
|
+ 'of length.', mention_author=False)
|
|
288
|
305
|
else:
|
|
289
|
|
- await context.message.reply(f'ℹ️ Only messages {min_length} ' +
|
|
290
|
|
- f'characters or longer will count against spam counts.',
|
|
|
306
|
+ await context.message.reply(
|
|
|
307
|
+ CONFIG['info_emoji'] + ' ' +
|
|
|
308
|
+ f'Only messages {min_length} characters or longer will ' +
|
|
|
309
|
+ 'count against spam counts.',
|
|
291
|
310
|
mention_author=False)
|
|
292
|
311
|
|
|
293
|
312
|
@crosspost.command(
|
|
|
@@ -304,8 +323,10 @@ class CrossPostCog(BaseCog):
|
|
304
|
323
|
allowed_types=(int, ), min_value=self.MIN_TIME_SPAN):
|
|
305
|
324
|
return
|
|
306
|
325
|
Storage.set_config_value(context.guild, self.CONFIG_KEY_MESSAGE_AGE, seconds)
|
|
307
|
|
- await context.message.reply(f'✅ Only messages in the past {seconds} ' +
|
|
308
|
|
- f'seconds will be checked for duplicates.',
|
|
|
326
|
+ await context.message.reply(
|
|
|
327
|
+ CONFIG['success_emoji'] + ' ' +
|
|
|
328
|
+ f'Only messages in the past {seconds} seconds will be checked ' +
|
|
|
329
|
+ 'for duplicates.',
|
|
309
|
330
|
mention_author=False)
|
|
310
|
331
|
|
|
311
|
332
|
@crosspost.command(
|
|
|
@@ -314,6 +335,8 @@ class CrossPostCog(BaseCog):
|
|
314
|
335
|
)
|
|
315
|
336
|
async def joinraid_gettimewindow(self, context: commands.Context):
|
|
316
|
337
|
seconds = self.__message_age_seconds(context.guild)
|
|
317
|
|
- await context.message.reply(f'ℹ️ Only messages in the past {seconds} ' +
|
|
318
|
|
- 'seconds will be checked for duplicates.',
|
|
|
338
|
+ await context.message.reply(
|
|
|
339
|
+ CONFIG['info_emoji'] + ' ' +
|
|
|
340
|
+ f'Only messages in the past {seconds} seconds will be checked ' +
|
|
|
341
|
+ 'for duplicates.',
|
|
319
|
342
|
mention_author=False)
|