@@ -86,7 +86,9 @@ def __init__(self):
86
86
try :
87
87
self .db = AsyncIOMotorClient (mongo_uri ).modmail_bot
88
88
except ConfigurationError as e :
89
- logger .critical ("Your MONGO_URI is copied wrong, try re-copying from the source again." )
89
+ logger .critical (
90
+ "Your MONGO_URI is copied wrong, try re-copying from the source again."
91
+ )
90
92
logger .critical (str (e ))
91
93
sys .exit (0 )
92
94
@@ -213,7 +215,9 @@ def owner_ids(self):
213
215
owner_ids = set (map (int , str (owner_ids ).split ("," )))
214
216
if self .owner_id is not None :
215
217
owner_ids .add (self .owner_id )
216
- permissions = self .config ["level_permissions" ].get (PermissionLevel .OWNER .name , [])
218
+ permissions = self .config ["level_permissions" ].get (
219
+ PermissionLevel .OWNER .name , []
220
+ )
217
221
for perm in permissions :
218
222
owner_ids .add (int (perm ))
219
223
return owner_ids
@@ -230,13 +234,16 @@ def log_channel(self) -> typing.Optional[discord.TextChannel]:
230
234
channel = self .get_channel (int (channel_id ))
231
235
if channel is not None :
232
236
return channel
233
- logger .debug (' LOG_CHANNEL_ID was invalid, removed.' )
237
+ logger .debug (" LOG_CHANNEL_ID was invalid, removed." )
234
238
self .config .remove ("log_channel_id" )
235
239
if self .main_category is not None :
236
240
try :
237
241
channel = self .main_category .channels [0 ]
238
242
self .config ["log_channel_id" ] = channel .id
239
- logger .warning ("No log channel set, setting #%s to be the log channel." , channel .name )
243
+ logger .warning (
244
+ "No log channel set, setting #%s to be the log channel." ,
245
+ channel .name ,
246
+ )
240
247
return channel
241
248
except IndexError :
242
249
pass
@@ -268,7 +275,9 @@ def aliases(self) -> typing.Dict[str, str]:
268
275
def token (self ) -> str :
269
276
token = self .config ["token" ]
270
277
if token is None :
271
- logger .critical ("TOKEN must be set, set this as bot token found on the Discord Dev Portal." )
278
+ logger .critical (
279
+ "TOKEN must be set, set this as bot token found on the Discord Dev Portal."
280
+ )
272
281
sys .exit (0 )
273
282
return token
274
283
@@ -321,11 +330,13 @@ def main_category(self) -> typing.Optional[discord.CategoryChannel]:
321
330
if cat is not None :
322
331
return cat
323
332
self .config .remove ("main_category_id" )
324
- logger .debug (' MAIN_CATEGORY_ID was invalid, removed.' )
333
+ logger .debug (" MAIN_CATEGORY_ID was invalid, removed." )
325
334
cat = discord .utils .get (self .modmail_guild .categories , name = "Modmail" )
326
335
if cat is not None :
327
336
self .config ["main_category_id" ] = cat .id
328
- logger .debug ("No main category set explicitly, setting category \" Modmail\" as the main category." )
337
+ logger .debug (
338
+ 'No main category set explicitly, setting category "Modmail" as the main category.'
339
+ )
329
340
return cat
330
341
return None
331
342
@@ -404,7 +415,7 @@ async def setup_indexes(self):
404
415
("key" , "text" ),
405
416
]
406
417
)
407
- logger .debug (' Successfully set up database indexes.' )
418
+ logger .debug (" Successfully set up database indexes." )
408
419
409
420
async def on_ready (self ):
410
421
"""Bot startup, sets uptime."""
@@ -413,7 +424,7 @@ async def on_ready(self):
413
424
await self .wait_for_connected ()
414
425
415
426
if self .guild is None :
416
- logger .debug (' Logging out due to invalid GUILD_ID.' )
427
+ logger .debug (" Logging out due to invalid GUILD_ID." )
417
428
return await self .logout ()
418
429
419
430
logger .line ()
@@ -444,12 +455,12 @@ async def on_ready(self):
444
455
445
456
if not thread :
446
457
# If the channel is deleted
447
- logger .debug (' Failed to close thread for recipient %s.' , recipient_id )
458
+ logger .debug (" Failed to close thread for recipient %s." , recipient_id )
448
459
self .config ["closures" ].pop (recipient_id )
449
460
await self .config .update ()
450
461
continue
451
462
452
- logger .debug (' Closing thread for recipient %s.' , recipient_id )
463
+ logger .debug (" Closing thread for recipient %s." , recipient_id )
453
464
454
465
await thread .close (
455
466
closer = self .get_user (items ["closer_id" ]),
@@ -579,7 +590,7 @@ async def _process_blocked(self, message: discord.Message) -> bool:
579
590
reaction = blocked_emoji
580
591
changed = False
581
592
delta = human_timedelta (min_account_age )
582
- logger .debug (' Blocked due to account age, user %s.' , message .author .name )
593
+ logger .debug (" Blocked due to account age, user %s." , message .author .name )
583
594
584
595
if str (message .author .id ) not in self .blocked_users :
585
596
new_reason = (
@@ -603,7 +614,7 @@ async def _process_blocked(self, message: discord.Message) -> bool:
603
614
reaction = blocked_emoji
604
615
changed = False
605
616
delta = human_timedelta (min_guild_age )
606
- logger .debug (' Blocked due to guild age, user %s.' , message .author .name )
617
+ logger .debug (" Blocked due to guild age, user %s." , message .author .name )
607
618
608
619
if str (message .author .id ) not in self .blocked_users :
609
620
new_reason = (
@@ -628,13 +639,15 @@ async def _process_blocked(self, message: discord.Message) -> bool:
628
639
):
629
640
# Met the age limit already, otherwise it would've been caught by the previous if's
630
641
reaction = sent_emoji
631
- logger .debug ('No longer internally blocked, user %s.' , message .author .name )
642
+ logger .debug (
643
+ "No longer internally blocked, user %s." , message .author .name
644
+ )
632
645
self .blocked_users .pop (str (message .author .id ))
633
646
else :
634
647
reaction = blocked_emoji
635
648
end_time = re .search (r"%(.+?)%$" , reason )
636
649
if end_time is not None :
637
- logger .debug (' No longer blocked, user %s.' , message .author .name )
650
+ logger .debug (" No longer blocked, user %s." , message .author .name )
638
651
after = (
639
652
datetime .fromisoformat (end_time .group (1 )) - now
640
653
).total_seconds ()
@@ -643,7 +656,7 @@ async def _process_blocked(self, message: discord.Message) -> bool:
643
656
reaction = sent_emoji
644
657
self .blocked_users .pop (str (message .author .id ))
645
658
else :
646
- logger .debug (' User blocked, user %s.' , message .author .name )
659
+ logger .debug (" User blocked, user %s." , message .author .name )
647
660
else :
648
661
reaction = sent_emoji
649
662
@@ -652,7 +665,7 @@ async def _process_blocked(self, message: discord.Message) -> bool:
652
665
try :
653
666
await message .add_reaction (reaction )
654
667
except (discord .HTTPException , discord .InvalidArgument ):
655
- logger .warning (' Failed to add reaction %s.' , reaction , exc_info = True )
668
+ logger .warning (" Failed to add reaction %s." , reaction , exc_info = True )
656
669
return str (message .author .id ) in self .blocked_users
657
670
658
671
async def process_modmail (self , message : discord .Message ) -> None :
@@ -839,9 +852,13 @@ async def on_raw_reaction_add(self, payload):
839
852
if isinstance (channel , discord .DMChannel ):
840
853
if str (reaction ) == str (close_emoji ): # closing thread
841
854
try :
842
- recipient_thread_close = strtobool (self .config ["recipient_thread_close" ])
855
+ recipient_thread_close = strtobool (
856
+ self .config ["recipient_thread_close" ]
857
+ )
843
858
except ValueError :
844
- recipient_thread_close = self .config .remove ("recipient_thread_close" )
859
+ recipient_thread_close = self .config .remove (
860
+ "recipient_thread_close"
861
+ )
845
862
if not recipient_thread_close :
846
863
return
847
864
thread = await self .threads .find (recipient = user )
@@ -875,7 +892,7 @@ async def on_guild_channel_delete(self, channel):
875
892
876
893
if isinstance (channel , discord .CategoryChannel ):
877
894
if self .main_category .id == channel .id :
878
- logger .debug (' Main category was deleted.' )
895
+ logger .debug (" Main category was deleted." )
879
896
self .config .remove ("main_category_id" )
880
897
await self .config .update ()
881
898
return
@@ -884,14 +901,14 @@ async def on_guild_channel_delete(self, channel):
884
901
return
885
902
886
903
if self .log_channel is None or self .log_channel .id == channel .id :
887
- logger .info (' Log channel deleted.' )
904
+ logger .info (" Log channel deleted." )
888
905
self .config .remove ("log_channel_id" )
889
906
await self .config .update ()
890
907
return
891
908
892
909
thread = await self .threads .find (channel = channel )
893
910
if thread :
894
- logger .debug (' Manually closed channel %s.' , channel .name )
911
+ logger .debug (" Manually closed channel %s." , channel .name )
895
912
await thread .close (closer = mod , silent = True , delete_channel = False )
896
913
897
914
async def on_member_remove (self , member ):
@@ -1062,7 +1079,8 @@ async def after_post_metadata(self):
1062
1079
if __name__ == "__main__" :
1063
1080
try :
1064
1081
import uvloop
1065
- logger .debug ('Setting up with uvloop.' )
1082
+
1083
+ logger .debug ("Setting up with uvloop." )
1066
1084
uvloop .install ()
1067
1085
except ImportError :
1068
1086
pass
0 commit comments