|
22 | 22 | SOFTWARE.
|
23 | 23 | '''
|
24 | 24 |
|
25 |
| -__version__ = '1.3.8' |
| 25 | +__version__ = '1.3.9' |
26 | 26 |
|
27 | 27 | from contextlib import redirect_stdout
|
28 | 28 | from urllib.parse import urlparse
|
|
39 | 39 | import re
|
40 | 40 | import io
|
41 | 41 |
|
42 |
| -import discord |
43 | 42 | from discord.ext import commands
|
44 |
| -from paginator import PaginatorSession |
| 43 | +import discord |
45 | 44 | import aiohttp
|
46 | 45 |
|
| 46 | +from utils.paginator import PaginatorSession |
| 47 | +from utils.github import Github |
47 | 48 |
|
48 |
| -class Github: |
49 |
| - head = 'https://api.github.com/repos/kyb3r/modmail/git/refs/heads/master' |
50 |
| - merge_url = 'https://api.github.com/repos/{username}/modmail/merges' |
51 |
| - |
52 |
| - def __init__(self, bot, access_token, username=None): |
53 |
| - self.bot = bot |
54 |
| - self.session = bot.session |
55 |
| - self.access_token = access_token |
56 |
| - self.username = username |
57 |
| - self.headers = {'Authorization': 'Bearer '+access_token} |
58 |
| - |
59 |
| - async def update_repository(self): |
60 |
| - sha = (await self.request(self.head))['object']['sha'] |
61 |
| - payload = { |
62 |
| - 'base': 'master', |
63 |
| - 'head': sha, |
64 |
| - 'commit_message': 'Updating bot' |
65 |
| - } |
66 |
| - merge_url = self.merge_url.format(username=self.username) |
67 |
| - |
68 |
| - r = await self.request(merge_url, method='POST', payload=payload) |
69 |
| - print(r) |
70 |
| - |
71 |
| - async def request(self, url, method='GET', payload=None): |
72 |
| - async with self.session.request(method, url, headers=self.headers, json=payload) as resp: |
73 |
| - try: |
74 |
| - return await resp.json() |
75 |
| - except: |
76 |
| - return await resp.text() |
77 |
| - |
78 |
| - @classmethod |
79 |
| - async def login(cls, bot, access_token): |
80 |
| - self = cls(bot, access_token) |
81 |
| - self.username = (await self.request('https://api.github.com/user'))['login'] |
82 |
| - return self |
83 | 49 |
|
84 | 50 |
|
85 | 51 | class Modmail(commands.Bot):
|
@@ -371,9 +337,15 @@ async def update(self, ctx):
|
371 | 337 | return await ctx.send(embed=em)
|
372 | 338 |
|
373 | 339 | user = await Github.login(self, access_token)
|
374 |
| - await user.update_repository() |
| 340 | + url = await user.update_repository() |
375 | 341 | em.title = 'Success'
|
376 |
| - em.description = 'Bot successfully updated, the bot will restart momentarily' |
| 342 | + |
| 343 | + if url: |
| 344 | + em.description = 'Bot successfully updated, the bot will restart momentarily' |
| 345 | + em.add_field(name='Commit', value=f'[Click Here]({url})') |
| 346 | + else: |
| 347 | + em.description = 'Already up to date with master repository.' |
| 348 | + |
377 | 349 | await ctx.send(embed=em)
|
378 | 350 |
|
379 | 351 | @commands.command()
|
|
0 commit comments