Skip to content

Commit

Permalink
Added version commit to /about embed (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nydauron authored Jun 13, 2024
1 parent b3a09f6 commit e2e768b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
Serves as the initial file to launch the bot. Loads all needed extensions and maintains
core functionality.
"""

from __future__ import annotations

import asyncio
import datetime
import logging
import logging.handlers
import re
import subprocess
import traceback
import uuid
from typing import TYPE_CHECKING, Any, ClassVar
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions src/discord/membercommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e2e768b

Please sign in to comment.