async def update(self, ctx): '''Updates the bot, this only works with heroku users.''' client = ModmailApiClient(self) metadata = await client.get_metadata() em = discord.Embed( title='Already up to date', description= f'The latest version is [`{__version__}`](https://github.com/kyb3r/modmail/blob/master/bot.py#L25)', color=discord.Color.green()) if metadata['latest_version'] == __version__: data = await client.get_user_info() if not data['error']: user = data['user'] em.set_author(name=user['username'], icon_url=user['avatar_url'], url=user['url']) if metadata['latest_version'] != __version__: data = await client.update_repository() if data['error']: prefix = self.config.get('PREFIX', 'm.') em.title = 'Unauthorised' em.description = f"You haven't logged in with github yet. Type the command `{prefix}github login` to authorize this bot." em.color = discord.Color.red() return await ctx.send(embed=em) commit_data = data['data'] user = data['user'] em.title = 'Success' em.set_author(name=user['username'], icon_url=user['avatar_url'], url=user['url']) em.set_footer( text= f"Updating modmail v{__version__} -> v{metadata['latest_version']}" ) if commit_data: em.description = 'Bot successfully updated, the bot will restart momentarily' message = commit_data['commit']['message'] html_url = commit_data["html_url"] short_sha = commit_data['sha'][:6] em.add_field( name='Merge Commit', value= f"[`{short_sha}`]({html_url}) {message} - {user['username']}" ) else: em.description = 'Already up to date with master repository.' em.add_field(name='Latest Commit', value=await self.get_latest_updates(limit=1), inline=False) await ctx.send(embed=em)
async def github(self, ctx): if ctx.invoked_subcommand: return client = ModmailApiClient(self) data = await client.get_user_info() prefix = self.config.get('PREFIX', 'm.') em = discord.Embed( title='Github', color=discord.Color.red(), description= f'Not logged in, do `{prefix}github login` to login with GitHub.') em.add_field(name='Subcommands', value=f'`{prefix}github login`\n`{prefix}github logout`') if not data['error']: user = data['user'] em.color = discord.Color.green() em.description = f"Currently logged in." em.set_author(name=user['username'], icon_url=user['avatar_url'], url=user['url']) em.set_thumbnail(url=user['avatar_url']) await ctx.send(embed=em) else: await ctx.send(embed=em)
async def _login(self, ctx): client = ModmailApiClient(self) oauth_url = 'https://github.com/login/oauth/authorize?client_id' \ '=bcff71fd67581b703408&scope=public_repo&redirect_uri=' \ 'https://api.kybr.tk/modmail/github/callback' \ f'?token={client.token}' em = discord.Embed( color=discord.Color.green(), title='Login with GitHub', description='In order to use the update command, you need ' \ 'to have fork the [repo](https://github.com/kyb3r/modmail) and ' \ 'login with GitHub so that we can update your fork to ' \ 'match the main repository whenever there is an update.' \ 'Click the link below to be taken to log in with github to authorize Modmail.' ) em.set_thumbnail( url= 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png' ) em.add_field(name='Login', value=f'[Click Here]({oauth_url})', inline=False) em.add_field( name='Warning', value='Dont share this link as it contains sensitive information.') await ctx.send('Check your direct messages.') await ctx.author.send(embed=em)
async def _logout(self, ctx): client = ModmailApiClient(self) data = await client.logout() em = discord.Embed( color=discord.Color.green(), title='Logged out', description='Successfully logged out.' ) if data['error']: em.color = discord.Color.red() em.title = 'Error' em.description = 'You are not logged in already.' await ctx.send(embed=em)
async def _logout(self, ctx): client = ModmailApiClient(self) data = await client.logout() em = discord.Embed(color=discord.Color.green(), title='Logged out', description='No longer logged into ') if data['error']: em.color = discord.Color.red() em.title = 'Error' em.description = 'You are not logged in already.' else: user = data['user'] em.description += user['username'] em.set_author(name=user['username'], icon_url=user['avatar_url'], url=user['url']) em.set_thumbnail(url=user['avatar_url']) await ctx.send(embed=em)