[Owner] Rich embed for [p]version

This commit is contained in:
Twentysix 2016-11-17 19:14:37 +01:00
parent 7fe0126a79
commit d11d2a5867

View File

@ -631,7 +631,11 @@ class Owner:
"""Shows Red's current version"""
response = self.bot.loop.run_in_executor(None, self._get_version)
result = await asyncio.wait_for(response, timeout=10)
await self.bot.say(result)
try:
await self.bot.say(embed=result)
except:
await self.bot.say("I need the `Embed links` permission "
"to send this")
def _load_cog(self, cogname):
if not self._does_cogfile_exist(cogname):
@ -686,12 +690,27 @@ class Owner:
self.setowner_lock = False
def _get_version(self):
getversion = os.popen(r'git show -s HEAD --format="%cr|%s|%h"')
getversion = getversion.read()
version = getversion.split('|')
return 'Last updated: ``{}``\nCommit: ``{}``\nHash: ``{}``'.format(
*version)
url = os.popen(r'git config --get remote.origin.url')
url = url.read().strip()[:-4]
repo_name = url.split("/")[-1]
commits = os.popen(r'git show -s -n 3 HEAD --format="%cr|%s|%H"')
ncommits = os.popen(r'git rev-list --count HEAD').read()
lines = commits.read().split('\n')
embed = discord.Embed(title="Updates of " + repo_name,
description="Last three updates",
colour=discord.Colour.red(),
url=url)
for line in lines:
if not line:
continue
when, commit, chash = line.split("|")
commit_url = url + "/commit/" + chash
content = "[{}]({}) - {} ".format(chash[:6], commit_url, commit)
embed.add_field(name=when, value=content, inline=False)
embed.set_footer(text="Total commits: " + ncommits)
return embed
def check_files():
if not os.path.isfile("data/red/disabled_commands.json"):