@@ -100,15 +100,15 @@ def get_bucket(self, guild_id, rule_name, bucket_info):
100
100
async def on_message (self , message : Message ):
101
101
if message .author .id == self .bot .user .id or message .guild is None :
102
102
return # Don't track anti-spam for ourselves or DMs
103
- cfg = Configuration .get_var (message .guild .id , "ANTI_SPAM" )
103
+ cfg = await Configuration .get_var (message .guild .id , "ANTI_SPAM" )
104
104
if not cfg .get ("ENABLED" , False ) or message .id in self .processed :
105
105
return
106
106
self .processed .append (message .id )
107
107
await self .process_message (message )
108
108
109
109
async def process_message (self , message : Message ):
110
110
# print(f'{datetime.datetime.now().isoformat()} - Processing message')
111
- if message .webhook_id is not None or self .is_exempt (message .guild .id , message .author ):
111
+ if message .webhook_id is not None or await self .is_exempt (message .guild .id , message .author ):
112
112
return
113
113
114
114
# Use the discord's message timestamp to hopefully not trigger false positives
@@ -131,7 +131,7 @@ async def check_bucket(check, friendly_text, amount, b):
131
131
b , count )))
132
132
133
133
counters = dict ()
134
- buckets = Configuration .get_var (message .guild .id , "ANTI_SPAM" , "BUCKETS" , [])
134
+ buckets = await Configuration .get_var (message .guild .id , "ANTI_SPAM" , "BUCKETS" , [])
135
135
136
136
# so if someone does 20 levels of too many mentions for some stupid reason we don't end up running the same regex 20 times for nothing
137
137
cache = dict ()
@@ -235,7 +235,9 @@ async def mute_punishment(self, v: Violation, member):
235
235
duration = v .bucket ["PUNISHMENT" ]["DURATION" ]
236
236
until = time .time () + duration
237
237
reason = self .assemble_reason (v )
238
- role = AntiSpam ._get_mute_role (v .guild )
238
+ role = await AntiSpam ._get_mute_role (v .guild )
239
+ if role is None :
240
+ return
239
241
i = await Infraction .get_or_none (user_id = member .id , type = "Mute" , guild_id = member .guild .id , active = True )
240
242
if i is None :
241
243
i = await InfractionUtils .add_infraction (v .guild .id , member .id , self .bot .user .id , 'Mute' , reason ,
@@ -256,7 +258,7 @@ async def mute_punishment(self, v: Violation, member):
256
258
moderator_id = v .guild .me .id ,
257
259
duration = Utils .to_pretty_time (duration , v .guild .id ),
258
260
reason = reason , inf = i .id )
259
- if Configuration .get_var (v .guild .id , "INFRACTIONS" , "DM_ON_MUTE" ):
261
+ if await Configuration .get_var (v .guild .id , "INFRACTIONS" , "DM_ON_MUTE" ):
260
262
await Utils .send_infraction (self .bot , member , v .guild , 'MUTE' , 'mute' , reason , duration = Utils .to_pretty_time (duration , v .guild .id ))
261
263
else :
262
264
i .end += duration
@@ -282,7 +284,7 @@ async def kick_punishment(self, v: Violation, member):
282
284
active = False )
283
285
await self .bot .redis_pool .psetex (f"forced_exits:{ v .guild .id } -{ member .id } " , 8000 , "1" )
284
286
try :
285
- if Configuration .get_var (v .guild .id , "INFRACTIONS" , "DM_ON_KICK" ):
287
+ if await Configuration .get_var (v .guild .id , "INFRACTIONS" , "DM_ON_KICK" ):
286
288
asyncio .create_task (Utils .send_infraction (self .bot , member , v .guild , 'BOOT' , 'kick' , "Spam" ))
287
289
await v .guild .kick (member , reason = reason )
288
290
except Forbidden :
@@ -302,7 +304,7 @@ async def temp_ban_punishment(self, v: Violation, member):
302
304
await v .guild .ban (member , reason = reason , delete_message_days = 0 )
303
305
i = await InfractionUtils .add_infraction (v .guild .id , member .id , self .bot .user .id , 'Tempban' , reason ,
304
306
end = until )
305
- if Configuration .get_var (v .guild .id , "INFRACTIONS" , "DM_ON_TEMPBAN" ):
307
+ if await Configuration .get_var (v .guild .id , "INFRACTIONS" , "DM_ON_TEMPBAN" ):
306
308
dur = Utils .to_pretty_time (duration , None )
307
309
asyncio .create_task (Utils .send_infraction (self .bot , member , v .guild , 'BAN' , 'tempban' , "Spam" , duration = dur ))
308
310
GearbotLogging .log_key (v .guild .id , 'tempban_log' , user = Utils .clean_user (member ),
@@ -319,7 +321,7 @@ async def ban_punishment(self, v: Violation, member):
319
321
GearbotLogging .log_key (v .guild .id , 'ban_log' , user = Utils .clean_user (member ), user_id = member .id ,
320
322
moderator = Utils .clean_user (v .guild .me ), moderator_id = v .guild .me .id ,
321
323
reason = reason , inf = i .id )
322
- if Configuration .get_var (v .guild .id , "INFRACTIONS" , "DM_ON_BAN" ):
324
+ if await Configuration .get_var (v .guild .id , "INFRACTIONS" , "DM_ON_BAN" ):
323
325
asyncio .create_task (Utils .send_infraction (self .bot , member , v .guild , 'BAN' , 'ban' , "Spam" ))
324
326
325
327
@@ -335,10 +337,10 @@ async def censor_detector(self):
335
337
return
336
338
337
339
# make sure anti-spam is enabled
338
- cfg = Configuration .get_var (message .guild .id , "ANTI_SPAM" )
340
+ cfg = await Configuration .get_var (message .guild .id , "ANTI_SPAM" )
339
341
if not cfg .get ("ENABLED" , False ) or message .id in self .censor_processed :
340
342
continue
341
- buckets = Configuration .get_var (message .guild .id , "ANTI_SPAM" , "BUCKETS" , [])
343
+ buckets = await Configuration .get_var (message .guild .id , "ANTI_SPAM" , "BUCKETS" , [])
342
344
count = 0
343
345
for b in buckets :
344
346
t = b ["TYPE" ]
@@ -372,10 +374,10 @@ async def voice_spam_detector(self):
372
374
return
373
375
374
376
# make sure anti-spam is enabled
375
- cfg = Configuration .get_var (member .guild .id , "ANTI_SPAM" )
376
- if after .channel is None or before .channel == after .channel or member is None or not cfg .get ("ENABLED" , False ) or self .is_exempt (member .guild .id , member ):
377
+ cfg = await Configuration .get_var (member .guild .id , "ANTI_SPAM" )
378
+ if after .channel is None or before .channel == after .channel or member is None or not cfg .get ("ENABLED" , False ) or await self .is_exempt (member .guild .id , member ):
377
379
continue
378
- buckets = Configuration .get_var (member .guild .id , "ANTI_SPAM" , "BUCKETS" , [])
380
+ buckets = await Configuration .get_var (member .guild .id , "ANTI_SPAM" , "BUCKETS" , [])
379
381
count = 0
380
382
for b in buckets :
381
383
t = b ["TYPE" ]
@@ -405,15 +407,15 @@ async def on_raw_message_delete(self, data: RawMessageDeleteEvent):
405
407
member = await Utils .get_member (self .bot , self .bot .get_guild (data .guild_id ), message .author )
406
408
if member is None :
407
409
return # user no longer present, probably already actioned
408
- if self .is_exempt (data .guild_id , member ):
410
+ if await self .is_exempt (data .guild_id , member ):
409
411
return # don't action except users
410
412
411
- if data .message_id in self .bot .deleted_messages and not Configuration .get_var ("GENERAL" , "BOT_DELETED_STILL_GHOSTS" ):
413
+ if data .message_id in self .bot .deleted_messages and not await Configuration .get_var (data . guild_id , "GENERAL" , "BOT_DELETED_STILL_GHOSTS" ):
412
414
return
413
415
414
- ghost_message_threshold = Configuration .get_var (data .guild_id , "GENERAL" , "GHOST_MESSAGE_THRESHOLD" )
415
- ghost_ping_threshold = Configuration .get_var (data .guild_id , "GENERAL" , "GHOST_PING_THRESHOLD" )
416
- buckets = Configuration .get_var (data .guild_id , "ANTI_SPAM" , "BUCKETS" , [])
416
+ ghost_message_threshold = await Configuration .get_var (data .guild_id , "GENERAL" , "GHOST_MESSAGE_THRESHOLD" )
417
+ ghost_ping_threshold = await Configuration .get_var (data .guild_id , "GENERAL" , "GHOST_PING_THRESHOLD" )
418
+ buckets = await Configuration .get_var (data .guild_id , "ANTI_SPAM" , "BUCKETS" , [])
417
419
mentions = len (MENTION_MATCHER .findall (message .content ))
418
420
419
421
msg_time = int (snowflake_time (message .messageid ).timestamp ())
@@ -456,9 +458,9 @@ async def on_raw_message_delete(self, data: RawMessageDeleteEvent):
456
458
457
459
458
460
async def handle_failed_ping (self , message : disnake .Message , amount ):
459
- if self .is_exempt (message .guild .id , message .author ) or message .author .bot or message .webhook_id is not None :
461
+ if await self .is_exempt (message .guild .id , message .author ) or message .author .bot or message .webhook_id is not None :
460
462
return # don't action except users
461
- buckets = Configuration .get_var (message .guild .id , "ANTI_SPAM" , "BUCKETS" , [])
463
+ buckets = await Configuration .get_var (message .guild .id , "ANTI_SPAM" , "BUCKETS" , [])
462
464
msg_time = int (snowflake_time (message .id ).timestamp ())
463
465
for b in buckets :
464
466
t = b ["TYPE" ]
@@ -485,18 +487,18 @@ def assemble_reason(v):
485
487
friendly = v .friendly )
486
488
487
489
@staticmethod
488
- def is_exempt (guild_id , member : Member ):
490
+ async def is_exempt (guild_id , member : Member ):
489
491
if not hasattr (member , "roles" ):
490
492
return False
491
- config = Configuration .get_var (guild_id , "ANTI_SPAM" )
493
+ config = await Configuration .get_var (guild_id , "ANTI_SPAM" )
492
494
for role in member .roles :
493
495
if role .id in config ["EXEMPT_ROLES" ]:
494
496
return True
495
497
return member .id in config ["EXEMPT_USERS" ] or Permissioncheckers .is_mod (member )
496
498
497
499
@staticmethod
498
- def _get_mute_role (guild ):
499
- role_id = Configuration .get_var (guild .id , "ROLES" , "MUTE_ROLE" )
500
+ async def _get_mute_role (guild ):
501
+ role_id = await Configuration .get_var (guild .id , "ROLES" , "MUTE_ROLE" )
500
502
if role_id == 0 :
501
503
return None
502
504
role = guild .get_role (role_id )
0 commit comments