8
8
from discord .ext .commands import UserInputError , CommandError
9
9
10
10
from core .models import Bot , ThreadManagerABC , ThreadABC
11
- from core .utils import is_image_url , days , match_user_id , truncate
12
- from core .decorators import ignore
11
+ from core .utils import is_image_url , days , match_user_id , truncate , ignore
13
12
14
13
15
14
class Thread (ThreadABC ):
16
15
"""Represents a discord Modmail thread"""
17
16
18
17
def __init__ (self , manager : 'ThreadManager' ,
19
- recipient : typing .Union [discord .Member , discord .User ,
20
- int ],
18
+ recipient : typing .Union [discord .Member , discord .User , int ],
21
19
channel : typing .Union [discord .DMChannel ,
22
- discord .TextChannel ]= None ):
20
+ discord .TextChannel ] = None ):
23
21
self .manager = manager
24
22
self .bot = manager .bot
25
23
if isinstance (recipient , int ):
@@ -72,9 +70,9 @@ def ready(self, flag):
72
70
self ._ready_event .set ()
73
71
else :
74
72
self ._ready_event .clear ()
75
-
73
+
76
74
async def setup (self , * , creator = None , category = None ):
77
- """Create the thread channel and other io related initilisation tasks"""
75
+ """Create the thread channel and other io related initialisation tasks"""
78
76
79
77
recipient = self .recipient
80
78
@@ -105,8 +103,9 @@ async def setup(self, *, creator=None, category=None):
105
103
)
106
104
107
105
log_count = sum (1 for log in log_data if not log ['open' ])
108
- info_embed = self .manager ._format_info_embed (recipient , log_url , log_count ,
109
- discord .Color .green ())
106
+ info_embed = self .manager ._format_info_embed (recipient , log_url ,
107
+ log_count ,
108
+ discord .Color .green ())
110
109
111
110
topic = f'User ID: { recipient .id } '
112
111
if creator :
@@ -118,7 +117,7 @@ async def setup(self, *, creator=None, category=None):
118
117
channel .edit (topic = topic ),
119
118
channel .send (mention , embed = info_embed )
120
119
)
121
-
120
+
122
121
self .ready = True
123
122
124
123
# Once thread is ready, tell the recipient.
@@ -213,7 +212,7 @@ async def _close(self, closer, silent=False, delete_channel=True,
213
212
sneak_peak = 'No content'
214
213
215
214
desc = f"[`{ log_data ['key' ]} `]({ log_url } ): "
216
- desc += truncate (sneak_peak , max = 75 - 13 )
215
+ desc += truncate (sneak_peak , max = 75 - 13 )
217
216
else :
218
217
desc = "Could not resolve log url."
219
218
@@ -306,14 +305,14 @@ async def reply(self, message, anonymous=False):
306
305
description = 'Your message could not be delivered since'
307
306
'the recipient shares no servers with the bot'
308
307
))
309
-
308
+
310
309
tasks = []
311
-
310
+
312
311
try :
313
312
await self .send (message ,
314
- destination = self .recipient ,
315
- from_mod = True ,
316
- anonymous = anonymous )
313
+ destination = self .recipient ,
314
+ from_mod = True ,
315
+ anonymous = anonymous )
317
316
except Exception as e :
318
317
print (e )
319
318
tasks .append (message .channel .send (
@@ -329,16 +328,16 @@ async def reply(self, message, anonymous=False):
329
328
# Send the same thing in the thread channel.
330
329
tasks .append (
331
330
self .send (message ,
332
- destination = self .channel ,
333
- from_mod = True ,
334
- anonymous = anonymous )
335
- )
331
+ destination = self .channel ,
332
+ from_mod = True ,
333
+ anonymous = anonymous )
334
+ )
336
335
337
336
tasks .append (
338
337
self .bot .api .append_log (message ,
339
- self .channel .id ,
340
- type_ = 'anonymous' if anonymous else 'thread_message'
341
- ))
338
+ self .channel .id ,
339
+ type_ = 'anonymous' if anonymous else 'thread_message'
340
+ ))
342
341
343
342
if self .close_task is not None :
344
343
# cancel closing if a thread message is sent.
@@ -363,7 +362,7 @@ async def send(self, message, destination=None,
363
362
self .channel .send (embed = discord .Embed (
364
363
color = discord .Color .red (),
365
364
description = 'Scheduled close has been cancelled.'
366
- )))
365
+ )))
367
366
self .bot .loop .create_task (tasks )
368
367
369
368
if not from_mod and not note :
@@ -372,7 +371,7 @@ async def send(self, message, destination=None,
372
371
)
373
372
374
373
if not self .ready :
375
- self .wait_until_ready ()
374
+ await self .wait_until_ready ()
376
375
377
376
destination = destination or self .channel
378
377
@@ -433,7 +432,7 @@ async def send(self, message, destination=None,
433
432
for att in images : # TODO: Logic needs review
434
433
if not prioritize_uploads or (
435
434
is_image_url (* att ) and not
436
- embedded_image and
435
+ embedded_image and
437
436
att [1 ]
438
437
):
439
438
embed .set_image (url = att [0 ])
0 commit comments