@@ -61,7 +61,7 @@ def __init__(self):
6161 self .data_task = self .loop .create_task (self .data_loop ())
6262 self .autoupdate_task = self .loop .create_task (self .autoupdate_loop ())
6363 self ._add_commands ()
64-
64+
6565 def _add_commands (self ):
6666 """Adds commands automatically"""
6767 self .remove_command ('help' )
@@ -91,7 +91,7 @@ def run(self):
9191 try :
9292 super ().run (self .token )
9393 finally :
94- print (Fore .CYAN + ' Shutting down bot' + Style .RESET_ALL )
94+ print (Fore .RED + ' - Shutting down bot' + Style .RESET_ALL )
9595
9696 @property
9797 def snippets (self ):
@@ -142,12 +142,15 @@ async def get_pre(bot, message):
142142 return [bot .prefix , f'<@{ bot .user .id } > ' , f'<@!{ bot .user .id } > ' ]
143143
144144 async def on_connect (self ):
145+ print (line + Fore .RED + Style .BRIGHT )
146+ await self .validate_api_token ()
145147 print (line )
146148 print (Fore .CYAN + 'Connected to gateway.' )
147149 await self .config .refresh ()
148150 status = self .config .get ('status' )
149151 if status :
150152 await self .change_presence (activity = discord .Game (status ))
153+
151154
152155 async def on_ready (self ):
153156 """Bot startup, sets uptime."""
@@ -290,6 +293,24 @@ def overwrites(self, ctx):
290293
291294 return overwrites
292295
296+ async def validate_api_token (self ):
297+ valid = True
298+ try :
299+ token = self .config .modmail_api_token
300+ except KeyError :
301+ print ('MODMAIL_API_TOKEN not found.' )
302+ print ('Set a config variable called MODMAIL_API_TOKEN with a token from https://dashboard.modmail.tk' )
303+ valid = False
304+ else :
305+ valid = await self .modmail_api .validate_token ()
306+ if not valid :
307+ print ('Invalid MODMAIL_API_TOKEN - get one from https://dashboard.modmail.tk' )
308+ finally :
309+ if not valid :
310+ await self .logout ()
311+ else :
312+ print (Style .RESET_ALL + Fore .CYAN + 'Validated API token.' + Style .RESET_ALL )
313+
293314 async def data_loop (self ):
294315 await self .wait_until_ready ()
295316
0 commit comments