@@ -341,24 +341,37 @@ async def update(self, ctx):
341
341
title = 'Already up to date' ,
342
342
description = f'The latest version is [`{ __version__ } `](https://github.com/kyb3r/modmail/blob/master/bot.py#L25)' ,
343
343
color = discord .Color .green ()
344
- )
344
+ )
345
345
346
- access_token = self .config . get ( 'GITHUB_ACCESS_TOKEN' )
346
+ oauth_url = f'https://github.com/login/oauth/authorize?client_id=e54e4ff0f234ee9f22aa&scope=public_repo&redirect_uri=http://api.kybr.tk/api/modmail/github/callback?user_id= { self .user . id } '
347
347
348
348
if data ['latest_version' ] == __version__ :
349
- if access_token :
350
- user = await Github .login (self , access_token )
351
- em .set_author (name = user .username , icon_url = user .avatar_url , url = user .url )
349
+ async with self .session .get (f'http://api.kybr.tk/api/modmail/github/user/{ self .user .id } ' ) as resp :
350
+ if resp .status == 403 :
351
+ em .title = 'Unauthorised'
352
+ em .description = 'You have not authorised modmail. ' \
353
+ 'Ask the user who setup modmail to go ' \
354
+ f'to [this]({ oauth_url } ) url to authorise the ' \
355
+ 'bot. Come back for the command later.'
356
+
357
+ em .color = discord .Color .red ()
358
+ return await ctx .send (embed = em )
359
+ elif resp .status == 200 :
360
+ # updated!
361
+ new_commit = await resp .json ()
362
+ commit_data = new_commit ['data' ]
363
+ else :
364
+ raise NotImplementedError (f'Server returned { resp .status } ' )
365
+ em .set_author (name = new_commit ['user' ]['username' ], icon_url = new_commit ['user' ]['avatar_url' ], url = new_commit ['user' ]['url' ])
352
366
353
367
if data ['latest_version' ] != __version__ :
354
- async with self .session .get (f'http://localhost:8000 /api/modmail/githubcheck/ { ctx . author .id } ' ) as resp :
368
+ async with self .session .get (f'http://api.kybr.tk /api/modmail/github/pull/ { self . user .id } ' ) as resp :
355
369
if resp .status == 403 :
356
370
em .title = 'Unauthorised'
357
371
em .description = 'You have not authorised modmail. ' \
358
- 'Go to [this]' \
359
- f'(https://github.com/login/oauth/authorize?client_id=e54e4ff0f234ee9f22aa&scope=public_repo&redirect_uri=http://localhost:8000/api/modmail/github?user_id={ ctx .author .id } )' \
360
- ' url to update the bot. In the future, ' \
361
- 'the command will work without the url.'
372
+ 'Ask the user who setup modmail to go ' \
373
+ f'to [this]({ oauth_url } ) url to authorise the ' \
374
+ 'bot. Come back for the command later.'
362
375
363
376
em .color = discord .Color .red ()
364
377
return await ctx .send (embed = em )
0 commit comments