4
4
5
5
import discord
6
6
from dateutil import parser
7
- from natural .date import duration
8
7
from discord .ext import commands
8
+ from natural .date import duration
9
9
10
- from core import checks
11
-
10
+ from core import checks
12
11
from core .decorators import trigger_typing
13
12
from core .models import Bot
14
13
from core .paginator import PaginatorSession
15
14
from core .time import UserFriendlyTime , human_timedelta
16
- from core .utils import truncate , format_preview , User
15
+ from core .utils import format_preview , User
17
16
18
17
19
18
class Modmail :
@@ -366,25 +365,37 @@ def format_log_embeds(self, logs, avatar_url, title='Previous Logs'):
366
365
created_at = parser .parse (entry ['created_at' ])
367
366
368
367
log_url = (
369
- f"https://logs.modmail.tk/{ key } "
370
- if not self .bot .self_hosted else
368
+ f"https://logs.modmail.tk/{ key } "
369
+ if not self .bot .self_hosted else
371
370
self .bot .config .log_url .strip ('/' ) + f'/logs/{ key } '
372
- )
373
-
374
- username = entry ['recipient' ]['name' ] + '#' + entry ['recipient' ]['discriminator' ]
375
-
376
- em = discord .Embed (color = discord .Color .blurple (), timestamp = created_at )
377
- em .set_author (name = f'{ title } ({ index } ) - { username } ' , icon_url = avatar_url , url = log_url )
378
- em .url = log_url
379
- em .add_field (name = 'Created' , value = duration (created_at , now = datetime .utcnow ()))
380
- em .add_field (name = 'Closed By' , value = f"<@{ entry ['closer' ]['id' ]} >" )
371
+ )
372
+
373
+ username = entry ['recipient' ]['name' ] + '#'
374
+ username += entry ['recipient' ]['discriminator' ]
375
+
376
+ embed = discord .Embed (color = discord .Color .blurple (),
377
+ timestamp = created_at )
378
+ embed .set_author (name = f'{ title } ({ index } ) - { username } ' ,
379
+ icon_url = avatar_url ,
380
+ url = log_url )
381
+ embed .url = log_url
382
+ embed .add_field (name = 'Created' ,
383
+ value = duration (created_at , now = datetime .utcnow ()))
384
+ embed .add_field (name = 'Closed By' ,
385
+ value = f"<@{ entry ['closer' ]['id' ]} >" )
386
+
381
387
if entry ['recipient' ]['id' ] != entry ['creator' ]['id' ]:
382
- em .add_field (name = 'Created by' , value = f"<@{ entry ['creator' ]['id' ]} >" )
383
- em .add_field (name = 'Preview' , value = format_preview (entry ['messages' ]), inline = False )
384
- em .add_field (name = 'Link' , value = log_url )
385
- em .set_footer (text = 'Recipient ID: ' + str (entry ['recipient' ]['id' ]))
386
-
387
- embeds .append (em )
388
+ embed .add_field (name = 'Created by' ,
389
+ value = f"<@{ entry ['creator' ]['id' ]} >" )
390
+
391
+ embed .add_field (name = 'Preview' ,
392
+ value = format_preview (entry ['messages' ]),
393
+ inline = False )
394
+ embed .add_field (name = 'Link' , value = log_url )
395
+ embed .set_footer (
396
+ text = 'Recipient ID: ' + str (entry ['recipient' ]['id' ])
397
+ )
398
+ embeds .append (embed )
388
399
return embeds
389
400
390
401
@commands .group (invoke_without_command = True )
@@ -393,7 +404,7 @@ async def logs(self, ctx, *, member: User = None):
393
404
"""Shows a list of previous Modmail thread logs of a member."""
394
405
395
406
await ctx .trigger_typing ()
396
-
407
+
397
408
if not member :
398
409
thread = ctx .thread
399
410
if not thread :
@@ -419,14 +430,15 @@ async def logs(self, ctx, *, member: User = None):
419
430
420
431
session = PaginatorSession (ctx , * embeds )
421
432
await session .run ()
422
-
433
+
423
434
@logs .command (name = 'closed-by' )
424
- async def closed_by (self , ctx , * , user : User = None ):
435
+ async def closed_by (self , ctx , * , user : User = None ):
425
436
"""Returns all logs closed by a user."""
426
437
if not self .bot .self_hosted :
427
438
embed = discord .Embed (
428
439
color = discord .Color .red (),
429
- description = 'This command only works if you are self-hosting your logs.'
440
+ description = 'This command only works if '
441
+ 'you are self-hosting your logs.'
430
442
)
431
443
return await ctx .send (embed = embed )
432
444
@@ -444,7 +456,9 @@ async def closed_by(self, ctx, *, user: User=None):
444
456
445
457
entries = await self .bot .db .logs .find (query , projection ).to_list (None )
446
458
447
- embeds = self .format_log_embeds (entries , avatar_url = self .bot .guild .icon_url , title = 'Search Results' )
459
+ embeds = self .format_log_embeds (entries ,
460
+ avatar_url = self .bot .guild .icon_url ,
461
+ title = 'Search Results' )
448
462
449
463
if not embeds :
450
464
embed = discord .Embed (
@@ -455,17 +469,18 @@ async def closed_by(self, ctx, *, user: User=None):
455
469
456
470
session = PaginatorSession (ctx , * embeds )
457
471
await session .run ()
458
-
472
+
459
473
@logs .command (name = 'search' )
460
- async def search (self , ctx , limit : Optional [int ]= None , * , query ):
461
- ''' Searches all logs for a message that contains your query.'''
474
+ async def search (self , ctx , limit : Optional [int ] = None , * , query ):
475
+ """ Searches all logs for a message that contains your query."""
462
476
463
477
await ctx .trigger_typing ()
464
478
465
479
if not self .bot .self_hosted :
466
480
embed = discord .Embed (
467
481
color = discord .Color .red (),
468
- description = 'This command only works if you are self-hosting your logs.'
482
+ description = 'This command only works if you '
483
+ 'are self-hosting your logs.'
469
484
)
470
485
return await ctx .send (embed = embed )
471
486
@@ -483,7 +498,9 @@ async def search(self, ctx, limit: Optional[int]=None, *, query):
483
498
484
499
entries = await self .bot .db .logs .find (query , projection ).to_list (limit )
485
500
486
- embeds = self .format_log_embeds (entries , avatar_url = self .bot .guild .icon_url , title = 'Search Results' )
501
+ embeds = self .format_log_embeds (entries ,
502
+ avatar_url = self .bot .guild .icon_url ,
503
+ title = 'Search Results' )
487
504
488
505
if not embeds :
489
506
embed = discord .Embed (
@@ -494,7 +511,7 @@ async def search(self, ctx, limit: Optional[int]=None, *, query):
494
511
495
512
session = PaginatorSession (ctx , * embeds )
496
513
await session .run ()
497
-
514
+
498
515
@commands .command ()
499
516
@checks .thread_only ()
500
517
async def reply (self , ctx , * , msg = '' ):
@@ -510,8 +527,8 @@ async def reply(self, ctx, *, msg=''):
510
527
@commands .command ()
511
528
@checks .thread_only ()
512
529
async def anonreply (self , ctx , * , msg = '' ):
513
- """Reply to a thread anonymously.
514
-
530
+ """Reply to a thread anonymously.
531
+
515
532
You can edit the anonymous user's name,
516
533
avatar and tag using the config command.
517
534
@@ -570,7 +587,7 @@ async def edit(self, ctx, message_id: Optional[int] = None,
570
587
thread .edit_message (linked_message_id , new_message ),
571
588
self .bot .api .edit_message (linked_message_id , new_message )
572
589
)
573
-
590
+
574
591
await ctx .message .add_reaction ('✅' )
575
592
576
593
@commands .command ()
0 commit comments