Merge branch 'changelog'

This commit is contained in:
Abigail Gold 2019-11-06 00:49:53 -05:00
commit d66cc63b5f
No known key found for this signature in database
GPG Key ID: 80A676456AB6B045
2 changed files with 63 additions and 0 deletions

View File

@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Rich lookup for QRZ, if a QRZ subscription is present
- Timestamp and requester username and avatar are now shown on embeds
- Current and 3-Day Forecast terrestrial weather conditions lookup commands
- Changelog command
### Changed
- Rewrote code to take advantage of discord.py's cogs
- Moved most bot responses into embeds

View File

@ -8,6 +8,8 @@ General Public License, version 2.
"""
from datetime import datetime
import re
from collections import OrderedDict
import discord
import discord.ext.commands as commands
@ -17,6 +19,7 @@ class BaseCog(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
self.gs = bot.get_cog("GlobalSettings")
self.changelog = parse_changelog()
@commands.command(name="info", aliases=["about"])
async def _info(self, ctx):
@ -43,6 +46,65 @@ class BaseCog(commands.Cog):
icon_url=str(ctx.author.avatar_url))
await ctx.send(embed=embed)
@commands.command(name="changelog", aliases=["clog"])
async def _changelog(self, ctx: commands.Context):
"""Show what has changed in recent bot versions."""
embed = discord.Embed(title="qrm Changelog",
description=("For a full listing, visit [Github](https://"
"github.com/classabbyamp/discord-qrm-bot/blob/master/CHANGELOG.md)."),
colour=self.gs.colours.neutral,
timestamp=datetime.utcnow())
embed.set_footer(text=ctx.author.name,
icon_url=str(ctx.author.avatar_url))
changelog = self.changelog
vers = 0
for ver, log in changelog.items():
if ver.lower() != 'unreleased':
if 'date' in log:
header = f'**{ver}** ({log["date"]})'
else:
header = f'**{ver}**'
embed.add_field(name=header, value=await format_changelog(log), inline=False)
vers += 1
if vers >= 2:
break
await ctx.send(embed=embed)
def parse_changelog():
changelog = OrderedDict()
ver = ''
heading = ''
with open('CHANGELOG.md') as changelog_file:
for line in changelog_file.readlines():
if line.strip() == '':
continue
if re.match(r'##[^#]', line):
ver_match = re.match(r'\[(.+)\](?: - )?(\d{4}-\d{2}-\d{2})?', line.lstrip('#').strip())
ver = ver_match.group(1)
changelog[ver] = dict()
if ver_match.group(2):
changelog[ver]['date'] = ver_match.group(2)
elif re.match(r'###[^#]', line):
heading = line.lstrip('#').strip()
changelog[ver][heading] = []
elif ver != '' and heading != '':
changelog[ver][heading].append(line.lstrip('-').strip())
return changelog
async def format_changelog(log: dict):
formatted = ''
for header, lines in log.items():
if header != 'date':
formatted += f'**{header}**\n'
for line in lines:
formatted += f'- {line}\n'
return formatted
def setup(bot: commands.Bot):
bot.add_cog(BaseCog(bot))