diff --git a/bot.py b/bot.py index 79b3305..8ffb1b3 100644 --- a/bot.py +++ b/bot.py @@ -2,6 +2,7 @@ Serves as the initial file to launch the bot. Loads all needed extensions and maintains core functionality. """ + from __future__ import annotations import asyncio @@ -9,6 +10,7 @@ import logging import logging.handlers import re +import subprocess import traceback import uuid from typing import TYPE_CHECKING, Any, ClassVar @@ -152,9 +154,20 @@ def __init__(self): dict[str, Any], ] = {} # name differentiation between internal _listeners attribute self.__version__ = "v5.1.0" + self.__commit__ = self.get_commit() self.session = None self.mongo_database = MongoDatabase(self) + def get_commit(self) -> str | None: + with subprocess.Popen( + ["git", "rev-parse", "--short", "HEAD"], + stdout=subprocess.PIPE, + ) as proc: + if proc.stdout: + hash = proc.stdout.read() + return hash.decode("utf-8") + return None + async def setup_hook(self) -> None: """ Called when the bot is being setup. Currently sets up a connection to the @@ -279,6 +292,9 @@ async def on_message(self, message: discord.Message) -> None: await reply_message.delete(delay=10) async def start(self, token: str, *, reconnect: bool = True) -> None: + if self.__commit__ is None: + # Logging is set up at this point so we can now prompt a warning message for a missing commit hash + logging.warning("Version commit could not be found") self.session = aiohttp.ClientSession() await super().start(token=token, reconnect=reconnect) diff --git a/src/discord/membercommands.py b/src/discord/membercommands.py index 7de7d3c..b166808 100644 --- a/src/discord/membercommands.py +++ b/src/discord/membercommands.py @@ -685,6 +685,7 @@ async def about(self, interaction: discord.Interaction): embed.add_field(name="Code Repository", value=repo, inline=False) embed.add_field(name="Wiki Page", value=wiki_link, inline=False) embed.add_field(name="Forums Page", value=forums_link, inline=False) + embed.set_footer(text=f"Version Commit: {self.bot.__commit__ or 'Unknown'}") embed.set_thumbnail(url=avatar_url) await interaction.response.send_message(embed=embed)