@@ -61,7 +61,7 @@ def __init__(self):
61
61
self .data_task = self .loop .create_task (self .data_loop ())
62
62
self .autoupdate_task = self .loop .create_task (self .autoupdate_loop ())
63
63
self ._add_commands ()
64
-
64
+
65
65
def _add_commands (self ):
66
66
"""Adds commands automatically"""
67
67
self .remove_command ('help' )
@@ -91,7 +91,7 @@ def run(self):
91
91
try :
92
92
super ().run (self .token )
93
93
finally :
94
- print (Fore .CYAN + ' Shutting down bot' + Style .RESET_ALL )
94
+ print (Fore .RED + ' - Shutting down bot' + Style .RESET_ALL )
95
95
96
96
@property
97
97
def snippets (self ):
@@ -142,12 +142,15 @@ async def get_pre(bot, message):
142
142
return [bot .prefix , f'<@{ bot .user .id } > ' , f'<@!{ bot .user .id } > ' ]
143
143
144
144
async def on_connect (self ):
145
+ print (line + Fore .RED + Style .BRIGHT )
146
+ await self .validate_api_token ()
145
147
print (line )
146
148
print (Fore .CYAN + 'Connected to gateway.' )
147
149
await self .config .refresh ()
148
150
status = self .config .get ('status' )
149
151
if status :
150
152
await self .change_presence (activity = discord .Game (status ))
153
+
151
154
152
155
async def on_ready (self ):
153
156
"""Bot startup, sets uptime."""
@@ -290,6 +293,24 @@ def overwrites(self, ctx):
290
293
291
294
return overwrites
292
295
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
+
293
314
async def data_loop (self ):
294
315
await self .wait_until_ready ()
295
316
0 commit comments