From 610ed2be10fa1f27e01cd57d3aaef888792aaa65 Mon Sep 17 00:00:00 2001 From: Laura Demkowicz-Duffy Date: Tue, 24 Aug 2021 11:27:31 +0000 Subject: [PATCH] Add `version` command (#177) * Add version command * Fix various problems, ignore version file * Get version string from file in AdminCog constructor --- .gitignore | 1 + src/esportsbot/cogs/AdminCog.py | 13 +++++++++++++ src/esportsbot/user_strings.toml | 1 + 3 files changed, 15 insertions(+) diff --git a/.gitignore b/.gitignore index 1f96f6b5..b58135ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ **/__pycache__ test-file.py /src/cogs/TestCog.py +/src/esportsbot/version.txt .vscode .idea secrets.env diff --git a/src/esportsbot/cogs/AdminCog.py b/src/esportsbot/cogs/AdminCog.py index 01cd5d08..d8ea0525 100644 --- a/src/esportsbot/cogs/AdminCog.py +++ b/src/esportsbot/cogs/AdminCog.py @@ -10,6 +10,14 @@ def __init__(self, bot): self.bot = bot self.STRINGS = bot.STRINGS["admin"] + # Get bot version from text file + try: + version_file_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "version.txt") + with open(version_file_path, "rt") as version_file: + self.bot_version = "`" + version_file.readline().strip() + "`" + except FileNotFoundError: + self.bot_version = self.STRINGS['no_version'] + def is_dev(ctx): if not devs: return ctx.author.guild_permissions.administrator @@ -38,6 +46,11 @@ async def clear_messages(self, ctx, amount=5): } ) + @commands.check(is_dev) + @commands.command(name="version", help="Print the bot's version string") + async def print_version(self, ctx): + await ctx.channel.send(self.bot_version) + @commands.command( name="members", aliases=['Members'], diff --git a/src/esportsbot/user_strings.toml b/src/esportsbot/user_strings.toml index bd6839cb..9c4cb59a 100644 --- a/src/esportsbot/user_strings.toml +++ b/src/esportsbot/user_strings.toml @@ -15,6 +15,7 @@ channel_removed = "Log channel has been removed" [admin] channel_cleared = "{author_mention} has cleared {message_amount} messages from {author_mention}" members = "This server has {member_count} members including me" +no_version = "No version recorded" [default_role] default_role_missing = "Default role has not been set"