Skip to content

Commit fda488e

Browse files
committed
resolve comment
1 parent 563b258 commit fda488e

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

bot.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -341,24 +341,37 @@ async def update(self, ctx):
341341
title='Already up to date',
342342
description=f'The latest version is [`{__version__}`](https://github.com/kyb3r/modmail/blob/master/bot.py#L25)',
343343
color=discord.Color.green()
344-
)
344+
)
345345

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}'
347347

348348
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'])
352366

353367
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:
355369
if resp.status == 403:
356370
em.title = 'Unauthorised'
357371
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.'
362375

363376
em.color = discord.Color.red()
364377
return await ctx.send(embed=em)

0 commit comments

Comments
 (0)