19
19
from aiohttp import ClientSession
20
20
from emoji import UNICODE_EMOJI
21
21
from motor .motor_asyncio import AsyncIOMotorClient
22
- from pkg_resources import parse_version
23
22
from pymongo .errors import ConfigurationError
24
23
24
+ from pkg_resources import parse_version
25
+
25
26
try :
26
27
# noinspection PyUnresolvedReferences
27
28
from colorama import init
@@ -171,9 +172,7 @@ def run(self, *args, **kwargs):
171
172
for task in asyncio .all_tasks (self .loop ):
172
173
task .cancel ()
173
174
try :
174
- self .loop .run_until_complete (
175
- asyncio .gather (* asyncio .all_tasks (self .loop ))
176
- )
175
+ self .loop .run_until_complete (asyncio .gather (* asyncio .all_tasks (self .loop )))
177
176
except asyncio .CancelledError :
178
177
logger .debug ("All pending tasks has been cancelled." )
179
178
finally :
@@ -187,9 +186,7 @@ def owner_ids(self):
187
186
owner_ids = set (map (int , str (owner_ids ).split ("," )))
188
187
if self .owner_id is not None :
189
188
owner_ids .add (self .owner_id )
190
- permissions = self .config ["level_permissions" ].get (
191
- PermissionLevel .OWNER .name , []
192
- )
189
+ permissions = self .config ["level_permissions" ].get (PermissionLevel .OWNER .name , [])
193
190
for perm in permissions :
194
191
owner_ids .add (int (perm ))
195
192
return owner_ids
@@ -216,8 +213,7 @@ def log_channel(self) -> typing.Optional[discord.TextChannel]:
216
213
channel = self .main_category .channels [0 ]
217
214
self .config ["log_channel_id" ] = channel .id
218
215
logger .warning (
219
- "No log channel set, setting #%s to be the log channel." ,
220
- channel .name ,
216
+ "No log channel set, setting #%s to be the log channel." , channel .name
221
217
)
222
218
return channel
223
219
except IndexError :
@@ -302,9 +298,7 @@ def main_category(self) -> typing.Optional[discord.CategoryChannel]:
302
298
category_id = self .config ["main_category_id" ]
303
299
if category_id is not None :
304
300
try :
305
- cat = discord .utils .get (
306
- self .modmail_guild .categories , id = int (category_id )
307
- )
301
+ cat = discord .utils .get (self .modmail_guild .categories , id = int (category_id ))
308
302
if cat is not None :
309
303
return cat
310
304
except ValueError :
@@ -354,9 +348,7 @@ def command_perm(self, command_name: str) -> PermissionLevel:
354
348
try :
355
349
return PermissionLevel [level .upper ()]
356
350
except KeyError :
357
- logger .warning (
358
- "Invalid override_command_level for command %s." , command_name
359
- )
351
+ logger .warning ("Invalid override_command_level for command %s." , command_name )
360
352
self .config ["override_command_level" ].pop (command_name )
361
353
362
354
command = self .get_command (command_name )
@@ -405,11 +397,7 @@ async def setup_indexes(self):
405
397
logger .info ('Creating "text" index for logs collection.' )
406
398
logger .info ("Name: %s" , index_name )
407
399
await coll .create_index (
408
- [
409
- ("messages.content" , "text" ),
410
- ("messages.author.name" , "text" ),
411
- ("key" , "text" ),
412
- ]
400
+ [("messages.content" , "text" ), ("messages.author.name" , "text" ), ("key" , "text" )]
413
401
)
414
402
logger .debug ("Successfully configured and verified database indexes." )
415
403
@@ -428,8 +416,7 @@ async def on_ready(self):
428
416
logger .info ("Logged in as: %s" , self .user )
429
417
logger .info ("Bot ID: %s" , self .user .id )
430
418
owners = ", " .join (
431
- getattr (self .get_user (owner_id ), "name" , str (owner_id ))
432
- for owner_id in self .owner_ids
419
+ getattr (self .get_user (owner_id ), "name" , str (owner_id )) for owner_id in self .owner_ids
433
420
)
434
421
logger .info ("Owners: %s" , owners )
435
422
logger .info ("Prefix: %s" , self .prefix )
@@ -447,9 +434,7 @@ async def on_ready(self):
447
434
logger .line ()
448
435
449
436
for recipient_id , items in tuple (closures .items ()):
450
- after = (
451
- datetime .fromisoformat (items ["time" ]) - datetime .utcnow ()
452
- ).total_seconds ()
437
+ after = (datetime .fromisoformat (items ["time" ]) - datetime .utcnow ()).total_seconds ()
453
438
if after < 0 :
454
439
after = 0
455
440
@@ -475,9 +460,7 @@ async def on_ready(self):
475
460
476
461
for log in await self .api .get_open_logs ():
477
462
if self .get_channel (int (log ["channel_id" ])) is None :
478
- logger .debug (
479
- "Unable to resolve thread with channel %s." , log ["channel_id" ]
480
- )
463
+ logger .debug ("Unable to resolve thread with channel %s." , log ["channel_id" ])
481
464
log_data = await self .api .post_log (
482
465
log ["channel_id" ],
483
466
{
@@ -494,13 +477,10 @@ async def on_ready(self):
494
477
},
495
478
)
496
479
if log_data :
497
- logger .debug (
498
- "Successfully closed thread with channel %s." , log ["channel_id" ]
499
- )
480
+ logger .debug ("Successfully closed thread with channel %s." , log ["channel_id" ])
500
481
else :
501
482
logger .debug (
502
- "Failed to close thread with channel %s, skipping." ,
503
- log ["channel_id" ],
483
+ "Failed to close thread with channel %s, skipping." , log ["channel_id" ]
504
484
)
505
485
506
486
self .metadata_loop = tasks .Loop (
@@ -550,9 +530,7 @@ async def retrieve_emoji(self) -> typing.Tuple[str, str]:
550
530
551
531
return sent_emoji , blocked_emoji
552
532
553
- async def _process_blocked (
554
- self , message : discord .Message
555
- ) -> typing .Tuple [bool , str ]:
533
+ async def _process_blocked (self , message : discord .Message ) -> typing .Tuple [bool , str ]:
556
534
sent_emoji , blocked_emoji = await self .retrieve_emoji ()
557
535
558
536
if str (message .author .id ) in self .blocked_whitelisted_users :
@@ -597,18 +575,15 @@ async def _process_blocked(
597
575
logger .debug ("Blocked due to account age, user %s." , message .author .name )
598
576
599
577
if str (message .author .id ) not in self .blocked_users :
600
- new_reason = (
601
- f"System Message: New Account. Required to wait for { delta } ."
602
- )
578
+ new_reason = f"System Message: New Account. Required to wait for { delta } ."
603
579
self .blocked_users [str (message .author .id )] = new_reason
604
580
changed = True
605
581
606
582
if reason .startswith ("System Message: New Account." ) or changed :
607
583
await message .channel .send (
608
584
embed = discord .Embed (
609
585
title = "Message not sent!" ,
610
- description = f"Your must wait for { delta } "
611
- f"before you can contact me." ,
586
+ description = f"Your must wait for { delta } before you can contact me." ,
612
587
color = self .error_color ,
613
588
)
614
589
)
@@ -621,18 +596,15 @@ async def _process_blocked(
621
596
logger .debug ("Blocked due to guild age, user %s." , message .author .name )
622
597
623
598
if str (message .author .id ) not in self .blocked_users :
624
- new_reason = (
625
- f"System Message: Recently Joined. Required to wait for { delta } ."
626
- )
599
+ new_reason = f"System Message: Recently Joined. Required to wait for { delta } ."
627
600
self .blocked_users [str (message .author .id )] = new_reason
628
601
changed = True
629
602
630
603
if reason .startswith ("System Message: Recently Joined." ) or changed :
631
604
await message .channel .send (
632
605
embed = discord .Embed (
633
606
title = "Message not sent!" ,
634
- description = f"Your must wait for { delta } "
635
- f"before you can contact me." ,
607
+ description = f"Your must wait for { delta } before you can contact me." ,
636
608
color = self .error_color ,
637
609
)
638
610
)
@@ -643,9 +615,7 @@ async def _process_blocked(
643
615
):
644
616
# Met the age limit already, otherwise it would've been caught by the previous if's
645
617
reaction = sent_emoji
646
- logger .debug (
647
- "No longer internally blocked, user %s." , message .author .name
648
- )
618
+ logger .debug ("No longer internally blocked, user %s." , message .author .name )
649
619
self .blocked_users .pop (str (message .author .id ))
650
620
else :
651
621
reaction = blocked_emoji
@@ -661,9 +631,7 @@ async def _process_blocked(
661
631
)
662
632
663
633
if end_time is not None :
664
- after = (
665
- datetime .fromisoformat (end_time .group (1 )) - now
666
- ).total_seconds ()
634
+ after = (datetime .fromisoformat (end_time .group (1 )) - now ).total_seconds ()
667
635
if after <= 0 :
668
636
# No longer blocked
669
637
reaction = sent_emoji
@@ -701,12 +669,10 @@ async def process_dm_modmail(self, message: discord.Message) -> None:
701
669
description = self .config ["disabled_new_thread_response" ],
702
670
)
703
671
embed .set_footer (
704
- text = self .config ["disabled_new_thread_footer" ],
705
- icon_url = self .guild .icon_url ,
672
+ text = self .config ["disabled_new_thread_footer" ], icon_url = self .guild .icon_url
706
673
)
707
674
logger .info (
708
- "A new thread was blocked from %s due to disabled Modmail." ,
709
- message .author ,
675
+ "A new thread was blocked from %s due to disabled Modmail." , message .author
710
676
)
711
677
_ , blocked_emoji = await self .retrieve_emoji ()
712
678
await self .add_reaction (message , blocked_emoji )
@@ -724,8 +690,7 @@ async def process_dm_modmail(self, message: discord.Message) -> None:
724
690
icon_url = self .guild .icon_url ,
725
691
)
726
692
logger .info (
727
- "A message was blocked from %s due to disabled Modmail." ,
728
- message .author ,
693
+ "A message was blocked from %s due to disabled Modmail." , message .author
729
694
)
730
695
_ , blocked_emoji = await self .retrieve_emoji ()
731
696
await self .add_reaction (message , blocked_emoji )
@@ -866,9 +831,7 @@ async def process_commands(self, message):
866
831
for ctx in ctxs :
867
832
if ctx .command :
868
833
if not any (
869
- 1
870
- for check in ctx .command .checks
871
- if hasattr (check , "permission_level" )
834
+ 1 for check in ctx .command .checks if hasattr (check , "permission_level" )
872
835
):
873
836
logger .debug (
874
837
"Command %s has no permissions check, adding invalid level." ,
@@ -1064,9 +1027,7 @@ async def on_command_error(self, context, exception):
1064
1027
[c .__name__ for c in exception .converters ]
1065
1028
)
1066
1029
await context .trigger_typing ()
1067
- await context .send (
1068
- embed = discord .Embed (color = self .error_color , description = msg )
1069
- )
1030
+ await context .send (embed = discord .Embed (color = self .error_color , description = msg ))
1070
1031
1071
1032
elif isinstance (exception , commands .BadArgument ):
1072
1033
await context .trigger_typing ()
@@ -1082,9 +1043,7 @@ async def on_command_error(self, context, exception):
1082
1043
if not await check (context ):
1083
1044
if hasattr (check , "fail_msg" ):
1084
1045
await context .send (
1085
- embed = discord .Embed (
1086
- color = self .error_color , description = check .fail_msg
1087
- )
1046
+ embed = discord .Embed (color = self .error_color , description = check .fail_msg )
1088
1047
)
1089
1048
if hasattr (check , "permission_level" ):
1090
1049
corrected_permission_level = self .command_perm (
0 commit comments