Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
39 changes: 39 additions & 0 deletions core/discord_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
Loading