Skip to content

Commit 8d58d86

Browse files
committed
Add latest updates to the about command
1 parent 005a364 commit 8d58d86

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

bot.py

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

25-
__version__ = '1.4.3'
25+
__version__ = '1.4.4'
2626

2727
from contextlib import redirect_stdout
2828
from urllib.parse import urlparse
@@ -233,6 +233,22 @@ async def data_loop(self):
233233

234234
await asyncio.sleep(3600)
235235

236+
async def get_latest_updates(self, limit=3):
237+
latest_commits = ''
238+
239+
async for commit in Github(self).get_latest_commits(limit=limit):
240+
241+
short_sha = commit['sha'][:6]
242+
html_url = commit['html_url']
243+
message = commit['commit']['message']
244+
author_name = commit['author']['login']
245+
author_url = commit['author']['html_url']
246+
247+
latest_commits += f'[`{short_sha}`]({html_url}) {message} - {author_name}\n'
248+
249+
return latest_commits
250+
251+
236252
@property
237253
def uptime(self):
238254
now = datetime.datetime.utcnow()
@@ -271,6 +287,7 @@ async def about(self, ctx):
271287
'improved upon suggestions by the users! This bot serves as a means for members to '\
272288
'easily communicate with server leadership in an organised manner.'
273289

290+
274291
try:
275292
async with self.session.get('https://api.kybr.tk/modmail') as resp:
276293
meta = await resp.json()
@@ -282,8 +299,12 @@ async def about(self, ctx):
282299
em.add_field(name='Instances', value=meta['instances'])
283300
else:
284301
em.add_field(name='Latency', value=f'{self.latency*1000:.2f} ms')
302+
303+
285304
em.add_field(name='Version', value=f'[`{__version__}`](https://github.com/kyb3r/modmail/blob/master/bot.py#L25)')
286305
em.add_field(name='Author', value='[`kyb3r`](https://github.com/kyb3r)')
306+
307+
em.add_field(name='Latest Updates', value=await self.get_latest_updates())
287308

288309
footer = f'Bot ID: {self.user.id}'
289310

@@ -319,25 +340,14 @@ async def update(self, ctx):
319340
color=discord.Color.green()
320341
)
321342

343+
em.add_field(name='Latest Commit', value=await self.get_latest_updates(limit=1), inline=False)
344+
322345
access_token = self.config.get('GITHUB_ACCESS_TOKEN')
323346

324347
if data['latest_version'] == __version__:
325348
if access_token:
326349
user = await Github.login(self, access_token)
327350
em.set_author(name=user.username, icon_url=user.avatar_url, url=user.url)
328-
329-
latest_commits = ''
330-
331-
async for commit in Github(self).get_latest_commits():
332-
333-
short_sha = commit['sha'][:6]
334-
html_url = commit['html_url']
335-
message = commit['commit']['message']
336-
author_name = commit['author']['login']
337-
author_url = commit['author']['html_url']
338-
339-
latest_commits += f'[`{short_sha}`]({html_url}) {message} - [`{author_name}`]({author_url})\n'
340-
341351

342352
if data['latest_version'] != __version__:
343353
if not access_token:
@@ -350,6 +360,8 @@ async def update(self, ctx):
350360

351361
em.color = discord.Color.red()
352362
return await ctx.send(embed=em)
363+
364+
em.set_footer(text=f"Updating modmail v{__version__} -> v{data['latest_version']}")
353365

354366
user = await Github.login(self, access_token)
355367
data = await user.update_repository()
@@ -365,9 +377,7 @@ async def update(self, ctx):
365377
em.add_field(name='Merge Commit', value=f'[`{short_sha}`]({html_url}) {message} - [`{user.username}`]({user.url})')
366378
else:
367379
em.description = 'Already up to date with master repository.'
368-
369-
em.add_field(name='Latest Updates', value=latest_commits, inline=False)
370-
380+
371381
await ctx.send(embed=em)
372382

373383
@commands.command()

utils/github.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def __init__(self, bot, access_token=None, username=None):
1616

1717
async def get_latest_commits(self, limit=3):
1818
resp = await self.request(self.commit_url)
19-
print(resp)
2019
for index in range(limit):
2120
yield resp[index]
2221

0 commit comments

Comments
 (0)