Skip to content

Commit 8a5e136

Browse files
committed
Restructure folders
1 parent 9e95e32 commit 8a5e136

File tree

5 files changed

+48
-128
lines changed

5 files changed

+48
-128
lines changed

bot.py

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
SOFTWARE.
2323
'''
2424

25-
__version__ = '1.3.8'
25+
__version__ = '1.3.9'
2626

2727
from contextlib import redirect_stdout
2828
from urllib.parse import urlparse
@@ -39,47 +39,13 @@
3939
import re
4040
import io
4141

42-
import discord
4342
from discord.ext import commands
44-
from paginator import PaginatorSession
43+
import discord
4544
import aiohttp
4645

46+
from utils.paginator import PaginatorSession
47+
from utils.github import Github
4748

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
8349

8450

8551
class Modmail(commands.Bot):
@@ -371,9 +337,15 @@ async def update(self, ctx):
371337
return await ctx.send(embed=em)
372338

373339
user = await Github.login(self, access_token)
374-
await user.update_repository()
340+
url = await user.update_repository()
375341
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+
377349
await ctx.send(embed=em)
378350

379351
@commands.command()

docs/favicon.ico

-1.37 KB
Binary file not shown.

docs/index.html

Lines changed: 0 additions & 88 deletions
This file was deleted.

utils/github.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
class Github:
2+
head = 'https://api.github.com/repos/kyb3r/modmail/git/refs/heads/master'
3+
merge_url = 'https://api.github.com/repos/{username}/modmail/merges'
4+
5+
def __init__(self, bot, access_token, username=None):
6+
self.bot = bot
7+
self.session = bot.session
8+
self.access_token = access_token
9+
self.username = username
10+
self.headers = {'Authorization': 'Bearer '+access_token}
11+
12+
async def update_repository(self):
13+
sha = (await self.request(self.head))['object']['sha']
14+
payload = {
15+
'base': 'master',
16+
'head': sha,
17+
'commit_message': 'Updating bot'
18+
}
19+
merge_url = self.merge_url.format(username=self.username)
20+
21+
r = await self.request(merge_url, method='POST', payload=payload)
22+
if isinstance(r, dict):
23+
return r['html_url']
24+
25+
async def request(self, url, method='GET', payload=None):
26+
async with self.session.request(method, url, headers=self.headers, json=payload) as resp:
27+
try:
28+
return await resp.json()
29+
except:
30+
return await resp.text()
31+
32+
@classmethod
33+
async def login(cls, bot, access_token):
34+
self = cls(bot, access_token)
35+
self.username = (await self.request('https://api.github.com/user'))['login']
36+
return self
File renamed without changes.

0 commit comments

Comments
 (0)