3636from discord .ext .commands .view import StringView
3737from colorama import init , Fore , Style
3838
39- init ()
40-
4139from core .api import Github , ModmailApiClient
4240from core .thread import ThreadManager
4341from core .config import ConfigManager
4442
4543
44+ init ()
4645
4746line = Fore .BLACK + Style .BRIGHT + '-------------------------' + Style .RESET_ALL
4847
@@ -60,7 +59,7 @@ def __init__(self):
6059 self .data_task = self .loop .create_task (self .data_loop ())
6160 self .autoupdate_task = self .loop .create_task (self .autoupdate_loop ())
6261 self ._add_commands ()
63-
62+
6463 def _add_commands (self ):
6564 """Adds commands automatically"""
6665 self .remove_command ('help' )
@@ -151,7 +150,6 @@ async def on_connect(self):
151150 status = self .config .get ('status' )
152151 if status :
153152 await self .change_presence (activity = discord .Game (status ))
154-
155153
156154 async def on_ready (self ):
157155 """Bot startup, sets uptime."""
@@ -227,7 +225,7 @@ async def get_context(self, message, *, cls=commands.Context):
227225 return ctx
228226
229227 async def on_message (self , message ):
230- if message .type == discord .MessageType .pins_add and message .author == self .user :
228+ if message .type == discord .MessageType .pins_add and message .author == self .user :
231229 await message .delete ()
232230 if message .author .bot :
233231 return
@@ -246,7 +244,7 @@ async def on_message(self, message):
246244 async def on_message_delete (self , message ):
247245 """Support for deleting linked messages"""
248246 if message .embeds and not isinstance (message .channel , discord .DMChannel ):
249- matches = re . findall ( r'\d+' , str (message .embeds [0 ].author .url ))
247+ matches = int ( str (message .embeds [0 ].author .url ). split ( '/' )[ - 1 ] )
250248 if matches :
251249 thread = await self .threads .find (channel = message .channel )
252250
@@ -256,7 +254,7 @@ async def on_message_delete(self, message):
256254 async for msg in channel .history ():
257255 if msg .embeds and msg .embeds [0 ].author :
258256 url = msg .embeds [0 ].author .url
259- if message_id == re . findall ( r'\d+' , url )[ 0 ]:
257+ if message_id == url . split ( '/' )[ - 1 ]:
260258 return await msg .delete ()
261259
262260 async def on_message_edit (self , before , after ):
@@ -267,8 +265,8 @@ async def on_message_edit(self, before, after):
267265 async for msg in thread .channel .history ():
268266 if msg .embeds :
269267 embed = msg .embeds [0 ]
270- matches = re . findall ( r'\d+' , str ( embed .author .url ) )
271- if matches and int (matches [0 ]) == before .id :
268+ matches = embed .author .url . split ( '/' )
269+ if matches and int (matches [- 1 ]) == before .id :
272270 if ' - (Edited)' not in embed .footer .text :
273271 embed .set_footer (text = embed .footer .text + ' - (Edited)' )
274272 embed .description = after .content
@@ -295,9 +293,9 @@ def overwrites(self, ctx):
295293 return overwrites
296294
297295 async def validate_api_token (self ):
298- valid = True
296+ valid = True
299297 try :
300- token = self .config .modmail_api_token
298+ self .config .modmail_api_token
301299 except KeyError :
302300 print ('MODMAIL_API_TOKEN not found.' )
303301 print ('Set a config variable called MODMAIL_API_TOKEN with a token from https://dashboard.modmail.tk' )
@@ -311,7 +309,7 @@ async def validate_api_token(self):
311309 await self .logout ()
312310 else :
313311 print (Style .RESET_ALL + Fore .CYAN + 'Validated API token.' + Style .RESET_ALL )
314-
312+
315313 async def data_loop (self ):
316314 await self .wait_until_ready ()
317315
0 commit comments