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
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ SOCKET_AUTH_TOKEN=your_socket_auth_token
SOCKET_SERVER_PORT=8080

# Health Server Configuration
HEALTH_HOST=your_health_check_host
HEALTH_PORT=your_health_check_port
HOST=your_health_check_host
PORT=your_health_check_port

# Database/API Configuration (if applicable)
# Add any database URLs or API keys here
Expand Down
45 changes: 30 additions & 15 deletions bot/bot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys
import logging
import asyncio
Expand All @@ -11,8 +12,8 @@
import aiohttp.client_exceptions

from bot.api_client import TortoiseAPI
from bot.constants import error_log_channel_id, bot_log_channel_id
from bot.utils.embed_handler import info
from bot.constants import error_log_channel_id, bot_log_channel_id, system_log_channel_id
from bot.utils.embed_handler import info, simple_embed


logger = logging.getLogger(__name__)
Expand All @@ -23,7 +24,7 @@ class Bot(commands.Bot):
# If not empty then only these will be loaded. Good for local debugging. If empty all found are loaded.
allowed_extensions = ("tortoise_dm", "health")
banned_extensions = ("advent_of_code",)
build_version = "Mystery Build"
build_version = "mystery-build"

def __init__(self, prefix="t.", *args, **kwargs):
kwargs.setdefault("activity", discord.Game(name="DM to Contact Staff"))
Expand All @@ -44,23 +45,37 @@ async def on_ready(self):
f"d.py version: {discord.__version__} \t"
"Further logging output will go to log file.."
)
await self.send_restart_message()

async def send_restart_message(self: commands.Bot):
try:
commit_hash = subprocess.check_output(
["git", "rev-parse", "--short", "HEAD"],
stderr=subprocess.DEVNULL,
).decode().strip()
except Exception:
commit_hash = os.getenv("BOT_BUILD_VERSION", "mystery-build")

channel = self.get_channel(system_log_channel_id)
self.build_version = commit_hash

if channel is None:
return

try:
embed = simple_embed(message=f"Build version: `{commit_hash}`", title="", color=discord.Color.dark_orange())
embed.set_footer(text=f"🔄 Bot Restarted")
await channel.send(
embed=embed,
)
except discord.Forbidden:
pass

async def setup_hook(self):
self.api_client: TortoiseAPI = TortoiseAPI()
await self.load_extensions()
# await self.reload_tortoise_meta_cache()
try:
version = (
subprocess.check_output(["git", "describe", "--always"])
.strip()
.decode("utf-8")
)
bot_log_channel = self.get_channel(bot_log_channel_id)
await bot_log_channel.send(
embed=info(f"Bot restarted. Build version `{version}`", self.user, "")
)
except Exception as e:
logger.exception("Git image version not found", exc_info=True)


async def reload_tortoise_meta_cache(self):
try:
Expand Down
4 changes: 2 additions & 2 deletions bot/cogs/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ async def health_error(self, interaction: discord.Interaction, error):


async def setup(bot: commands.Bot):
host = os.getenv("HEALTH_HOST", "0.0.0.0")
port = os.getenv("HEALTH_PORT", "8080")
host = os.getenv("HOST", "0.0.0.0")
port = os.getenv("PORT", "8080")

await bot.add_cog(HealthCheck(bot, host=host, port=port))
2 changes: 1 addition & 1 deletion bot/cogs/tortoise_dm.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ async def create_mod_mail(self, user: discord.User):
if user.id in self.pending_mod_mails:
await user.send(embed=failure("You already have a pending mod mail, please be patient."))
return
submission_embed = authored_sm(f"{user.name}` submitted for mod mail.", author=user)
submission_embed = authored_sm(f"{user.name} submitted for mod mail.", author=user)
view = ModMailAcceptView(self, user.id)

await self.staff_channel.send("@here", delete_after=30)
Expand Down
Loading