24
24
25
25
__version__ = '2.11.0'
26
26
27
- import discord
28
- from discord .enums import ActivityType
29
- from discord .ext import commands
30
- from discord .ext .commands .view import StringView
31
-
32
27
from os import listdir
33
28
import asyncio
34
29
from textwrap import dedent
35
30
from datetime import datetime
36
31
from types import SimpleNamespace
37
32
33
+ import discord
34
+ from discord .enums import ActivityType
35
+ from discord .ext import commands
36
+ from discord .ext .commands .view import StringView
37
+
38
38
import uvloop
39
39
from aiohttp import ClientSession
40
40
from motor .motor_asyncio import AsyncIOMotorClient
48
48
from core .changelog import ChangeLog
49
49
from core .objects import Bot
50
50
51
-
52
51
colorama .init ()
53
52
54
- line = Fore .BLACK + Style .BRIGHT + '-------------------------' + \
53
+ LINE = Fore .BLACK + Style .BRIGHT + '-------------------------' + \
55
54
Style .RESET_ALL
56
55
57
56
@@ -117,13 +116,13 @@ def _load_extensions(self):
117
116
"""Adds commands automatically"""
118
117
self .remove_command ('help' )
119
118
120
- print (line + Fore .CYAN )
119
+ print (LINE + Fore .CYAN )
121
120
print ('┌┬┐┌─┐┌┬┐┌┬┐┌─┐┬┬' ,
122
121
'││││ │ │││││├─┤││' ,
123
122
'┴ ┴└─┘─┴┘┴ ┴┴ ┴┴┴─┘' , sep = '\n ' )
124
123
print (f'v{ __version__ } ' )
125
124
print ('Authors: kyb3r, fourjr, Taaku18' + Style .RESET_ALL )
126
- print (line + Fore .CYAN )
125
+ print (LINE + Fore .CYAN )
127
126
128
127
for file in listdir ('cogs' ):
129
128
if not file .endswith ('.py' ):
@@ -138,19 +137,18 @@ async def logout(self):
138
137
self .autoupdate_task .cancel ()
139
138
await super ().logout ()
140
139
141
- def run (self ):
140
+ def run (self , * args , ** kwargs ):
142
141
try :
143
- super ().run (self .token )
142
+ super ().run (self .token , * args , ** kwargs )
144
143
finally :
145
144
print (Fore .RED + ' - Shutting down bot' + Style .RESET_ALL )
146
-
145
+
147
146
@property
148
147
def log_channel (self ):
149
148
channel_id = self .config .get ('log_channel_id' )
150
149
if channel_id is not None :
151
150
return self .get_channel (int (channel_id ))
152
- else :
153
- return self .main_category .channels [0 ]
151
+ return self .main_category .channels [0 ]
154
152
155
153
@property
156
154
def snippets (self ):
@@ -185,9 +183,8 @@ def modmail_guild(self):
185
183
modmail_guild_id = self .config .get ('modmail_guild_id' )
186
184
if not modmail_guild_id :
187
185
return self .guild
188
- else :
189
- return discord .utils .get (self .guilds , id = int (modmail_guild_id ))
190
-
186
+ return discord .utils .get (self .guilds , id = int (modmail_guild_id ))
187
+
191
188
@property
192
189
def using_multiple_server_setup (self ):
193
190
return self .modmail_guild != self .guild
@@ -202,6 +199,7 @@ def main_category(self):
202
199
if self .modmail_guild :
203
200
return discord .utils .get (self .modmail_guild .categories ,
204
201
name = 'Modmail' )
202
+ return None
205
203
206
204
@property
207
205
def blocked_users (self ):
@@ -210,7 +208,7 @@ def blocked_users(self):
210
208
@property
211
209
def prefix (self ):
212
210
return self .config .get ('prefix' , '?' )
213
-
211
+
214
212
@property
215
213
def mod_color (self ):
216
214
color = self .config .get ('mod_color' )
@@ -238,19 +236,19 @@ def recipient_color(self):
238
236
return color
239
237
240
238
async def on_connect (self ):
241
- print (line )
239
+ print (LINE )
242
240
print (Fore .CYAN , end = '' )
243
241
if not self .self_hosted :
244
242
print ('MODE: Using the Modmail API' )
245
- print (line )
243
+ print (LINE )
246
244
await self .validate_api_token ()
247
- print (line )
245
+ print (LINE )
248
246
else :
249
247
print ('Mode: Self-hosting logs.' )
250
248
await self .validate_database_connection ()
251
- print (line )
249
+ print (LINE )
252
250
print (Fore .CYAN + 'Connected to gateway.' )
253
-
251
+
254
252
await self .config .refresh ()
255
253
256
254
activity_type = self .config .get ('activity_type' )
@@ -273,13 +271,13 @@ async def on_ready(self):
273
271
"""Bot startup, sets uptime."""
274
272
await self ._connected .wait ()
275
273
print (dedent (f"""
276
- { line }
274
+ { LINE }
277
275
{ Fore .CYAN } Client ready.
278
- { line }
276
+ { LINE }
279
277
{ Fore .CYAN } Logged in as: { self .user }
280
278
{ Fore .CYAN } User ID: { self .user .id }
281
279
{ Fore .CYAN } Guild ID: { self .guild .id if self .guild else 0 }
282
- { line } """ ).strip ())
280
+ { LINE } """ ).strip ())
283
281
284
282
if not self .guild :
285
283
print (f'{ Fore .RED } { Style .BRIGHT } WARNING - The GUILD_ID '
@@ -309,14 +307,12 @@ async def on_ready(self):
309
307
310
308
# TODO: Low priority,
311
309
# Retrieve messages/replies when bot is down, from history?
312
- self .loop .create_task (
313
- thread .close (
314
- closer = self .get_user (items ['closer_id' ]),
315
- after = after ,
316
- silent = items ['silent' ],
317
- delete_channel = items ['delete_channel' ],
318
- message = items ['message' ]
319
- )
310
+ await thread .close (
311
+ closer = self .get_user (items ['closer_id' ]),
312
+ after = after ,
313
+ silent = items ['silent' ],
314
+ delete_channel = items ['delete_channel' ],
315
+ message = items ['message' ]
320
316
)
321
317
322
318
async def process_modmail (self , message ):
@@ -390,8 +386,8 @@ async def get_context(self, message, *, cls=commands.Context):
390
386
alias = self .config .get ('aliases' , {}).get (invoker )
391
387
if alias is not None :
392
388
ctx ._alias_invoked = True
393
- _len = len (f'{ invoked_prefix } { invoker } ' )
394
- view = StringView (f'{ alias } { ctx .message .content [_len :]} ' )
389
+ len_ = len (f'{ invoked_prefix } { invoker } ' )
390
+ view = StringView (f'{ alias } { ctx .message .content [len_ :]} ' )
395
391
ctx .view = view
396
392
invoker = view .get_word ()
397
393
@@ -408,7 +404,7 @@ async def get_context(self, message, *, cls=commands.Context):
408
404
409
405
async def on_message (self , message ):
410
406
if message .type == discord .MessageType .pins_add and \
411
- message .author == self .user :
407
+ message .author == self .user :
412
408
await message .delete ()
413
409
414
410
if message .author .bot :
@@ -431,22 +427,22 @@ async def on_message(self, message):
431
427
thread = await self .threads .find (channel = ctx .channel )
432
428
if thread is not None :
433
429
await self .api .append_log (message , type_ = 'internal' )
434
-
430
+
435
431
async def on_guild_channel_delete (self , channel ):
436
432
if channel .guild != self .modmail_guild :
437
- return
433
+ return
438
434
439
435
audit_logs = self .modmail_guild .audit_logs ()
440
436
entry = await audit_logs .find (lambda e : e .target .id == channel .id )
441
437
mod = entry .user
442
438
443
439
if mod == self .user :
444
440
return
445
-
441
+
446
442
thread = await self .threads .find (channel = channel )
447
443
if not thread :
448
444
return
449
-
445
+
450
446
await thread .close (closer = mod , silent = True , delete_channel = False )
451
447
452
448
async def on_message_delete (self , message ):
@@ -577,14 +573,14 @@ async def autoupdate_loop(self):
577
573
578
574
if self .config .get ('disable_autoupdates' ):
579
575
print ('Autoupdates disabled.' )
580
- print (line )
581
- return
576
+ print (LINE )
577
+ return
582
578
583
579
if self .self_hosted and not self .config .get ('github_access_token' ):
584
580
print ('Github access token not found.' )
585
581
print ('Autoupdates disabled.' )
586
- print (line )
587
- return
582
+ print (LINE )
583
+ return
588
584
589
585
while True :
590
586
metadata = await self .api .get_metadata ()
@@ -614,7 +610,7 @@ async def autoupdate_loop(self):
614
610
short_sha = commit_data ['sha' ][:6 ]
615
611
embed .add_field (name = 'Merge Commit' ,
616
612
value = f"[`{ short_sha } `]({ html_url } ) "
617
- f"{ message } - { user ['username' ]} " )
613
+ f"{ message } - { user ['username' ]} " )
618
614
print ('Updating bot.' )
619
615
channel = self .log_channel
620
616
await channel .send (embed = embed )
@@ -625,7 +621,6 @@ async def get_latest_updates(self, limit=3):
625
621
latest_commits = ''
626
622
627
623
async for commit in Github (self ).get_latest_commits (limit = limit ):
628
-
629
624
short_sha = commit ['sha' ][:6 ]
630
625
html_url = commit ['html_url' ]
631
626
message = commit ['commit' ]['message' ].splitlines ()[0 ]
@@ -637,5 +632,5 @@ async def get_latest_updates(self, limit=3):
637
632
638
633
if __name__ == '__main__' :
639
634
uvloop .install ()
640
- bot = ModmailBot ()
635
+ bot = ModmailBot () # pylint: disable=invalid-name
641
636
bot .run ()
0 commit comments