diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 34ba3dc..d2cee1c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,6 +53,7 @@ jobs: platforms: ${{ matrix.platform }} build-args: | GIT_SHA=${{ github.sha }} + GIT_BRANCH=${{ github.ref_name }} labels: ${{ steps.meta.outputs.labels }} tags: ${{ env.REGISTRY_IMAGE }} outputs: type=image,push-by-digest=true,name-canonical=true,push=true diff --git a/Dockerfile b/Dockerfile index 44a0590..5f67e93 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,11 @@ FROM nikolaik/python-nodejs:python3.13-nodejs25 -# Store git commit hash + +# Store git commit hash and branch ARG GIT_SHA +ARG GIT_BRANCH=main ENV GIT_SHA=$GIT_SHA +ENV GIT_BRANCH=$GIT_BRANCH # Set the working directory in the container WORKDIR /Bot diff --git a/core/discord_bot.py b/core/discord_bot.py index 4c16a18..5765fcf 100644 --- a/core/discord_bot.py +++ b/core/discord_bot.py @@ -35,6 +35,30 @@ def emoji_repl(match): def slash_mention_repl(match): return f"/{match.group(1)}" +async def get_latest_commit_sha() -> str: + """Fetch the latest commit SHA from GitHub using the API""" + try: + current_branch = os.getenv("GIT_BRANCH", "main") + async with aiohttp.ClientSession() as sesh: + # Use GitHub API to get latest commit + url = f"https://api.github.com/repos/SkyKings-Network/GuildBridgeBot/commits/{current_branch}" + async with sesh.get(url, headers={'Accept': 'application/vnd.github.v3+json'}) as resp: + data = await resp.json() + return data['sha'] + except Exception as e: + print(f"{Color.CYAN}Discord{Color.RESET} > Failed to get latest git SHA: {e}") + return "unknown" + +async def is_outdated() -> bool: + print(f"{Color.CYAN}Discord{Color.RESET} > Checking for updates...") + current_sha = os.getenv("GIT_SHA", "unknown") + latest_sha = await get_latest_commit_sha() + print(f"{Color.CYAN}Discord{Color.RESET} > Current SHA: {current_sha}") + print(f"{Color.CYAN}Discord{Color.RESET} > Latest SHA: {latest_sha}") + if current_sha == "unknown" or latest_sha == "unknown": + return False + return current_sha != latest_sha + class DiscordBridgeBot(commands.Bot): def __init__(self): @@ -229,6 +253,21 @@ async def _send_message(self, *args, **kwargs) -> Union[discord.Message, discord ) return None + is_bot_outdated = await is_outdated() + # Add a footer to the embed if the bot is outdated + if is_bot_outdated: + footer_text = "📩 Bridge Update available!" + if 'embed' in kwargs: + embed = kwargs['embed'] + if isinstance(embed, discord.Embed): + if embed.footer.text: + embed.set_footer(text=embed.footer.text + " | " + footer_text) + else: + embed.set_footer(text=footer_text) + else: + kwargs['embed'] = discord.Embed(description=" ", colour=0xFF6347) + kwargs['embed'].set_footer(text=footer_text) + is_officer = kwargs.pop("officer", False) officer_maybe = kwargs.pop("officer_maybe", False) if officer_maybe: