44
55import discord
66from dateutil import parser
7- from natural .date import duration
87from discord .ext import commands
8+ from natural .date import duration
99
10- from core import checks
11-
10+ from core import checks
1211from core .decorators import trigger_typing
1312from core .models import Bot
1413from core .paginator import PaginatorSession
1514from core .time import UserFriendlyTime , human_timedelta
16- from core .utils import truncate , format_preview , User
15+ from core .utils import format_preview , User
1716
1817
1918class Modmail :
@@ -366,25 +365,37 @@ def format_log_embeds(self, logs, avatar_url, title='Previous Logs'):
366365 created_at = parser .parse (entry ['created_at' ])
367366
368367 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
371370 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+
381387 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 )
388399 return embeds
389400
390401 @commands .group (invoke_without_command = True )
@@ -393,7 +404,7 @@ async def logs(self, ctx, *, member: User = None):
393404 """Shows a list of previous Modmail thread logs of a member."""
394405
395406 await ctx .trigger_typing ()
396-
407+
397408 if not member :
398409 thread = ctx .thread
399410 if not thread :
@@ -419,14 +430,15 @@ async def logs(self, ctx, *, member: User = None):
419430
420431 session = PaginatorSession (ctx , * embeds )
421432 await session .run ()
422-
433+
423434 @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 ):
425436 """Returns all logs closed by a user."""
426437 if not self .bot .self_hosted :
427438 embed = discord .Embed (
428439 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.'
430442 )
431443 return await ctx .send (embed = embed )
432444
@@ -444,7 +456,9 @@ async def closed_by(self, ctx, *, user: User=None):
444456
445457 entries = await self .bot .db .logs .find (query , projection ).to_list (None )
446458
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' )
448462
449463 if not embeds :
450464 embed = discord .Embed (
@@ -455,17 +469,18 @@ async def closed_by(self, ctx, *, user: User=None):
455469
456470 session = PaginatorSession (ctx , * embeds )
457471 await session .run ()
458-
472+
459473 @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."""
462476
463477 await ctx .trigger_typing ()
464478
465479 if not self .bot .self_hosted :
466480 embed = discord .Embed (
467481 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.'
469484 )
470485 return await ctx .send (embed = embed )
471486
@@ -483,7 +498,9 @@ async def search(self, ctx, limit: Optional[int]=None, *, query):
483498
484499 entries = await self .bot .db .logs .find (query , projection ).to_list (limit )
485500
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' )
487504
488505 if not embeds :
489506 embed = discord .Embed (
@@ -494,7 +511,7 @@ async def search(self, ctx, limit: Optional[int]=None, *, query):
494511
495512 session = PaginatorSession (ctx , * embeds )
496513 await session .run ()
497-
514+
498515 @commands .command ()
499516 @checks .thread_only ()
500517 async def reply (self , ctx , * , msg = '' ):
@@ -510,8 +527,8 @@ async def reply(self, ctx, *, msg=''):
510527 @commands .command ()
511528 @checks .thread_only ()
512529 async def anonreply (self , ctx , * , msg = '' ):
513- """Reply to a thread anonymously.
514-
530+ """Reply to a thread anonymously.
531+
515532 You can edit the anonymous user's name,
516533 avatar and tag using the config command.
517534
@@ -570,7 +587,7 @@ async def edit(self, ctx, message_id: Optional[int] = None,
570587 thread .edit_message (linked_message_id , new_message ),
571588 self .bot .api .edit_message (linked_message_id , new_message )
572589 )
573-
590+
574591 await ctx .message .add_reaction ('✅' )
575592
576593 @commands .command ()
0 commit comments