2025-01-19 22:29:16 -05:00
|
|
|
import os
|
|
|
|
import logging
|
2025-01-18 21:45:25 -05:00
|
|
|
import discord
|
2025-01-28 09:22:02 -05:00
|
|
|
import subprocess
|
2025-01-18 21:45:25 -05:00
|
|
|
from dotenv import load_dotenv
|
2025-01-19 22:29:16 -05:00
|
|
|
from commands import setup_commands
|
2025-01-18 21:45:25 -05:00
|
|
|
|
2025-01-19 22:29:16 -05:00
|
|
|
# Load environment variables
|
2025-01-18 21:45:25 -05:00
|
|
|
load_dotenv()
|
|
|
|
|
2025-01-19 22:29:16 -05:00
|
|
|
TOKEN = os.getenv("DISCORD_TOKEN")
|
|
|
|
GUILD_ID = os.getenv("GUILD_ID")
|
2025-01-28 09:22:02 -05:00
|
|
|
DEFAULT_OWNER_ID = os.getenv("DEFAULT_OWNER_ID")
|
2025-01-19 22:29:16 -05:00
|
|
|
|
|
|
|
# Validate Guild ID
|
|
|
|
if GUILD_ID:
|
|
|
|
try:
|
|
|
|
GUILD_ID = int(GUILD_ID)
|
|
|
|
except ValueError:
|
|
|
|
logging.error("Invalid GUILD_ID in .env file. It must be a numeric value.")
|
|
|
|
GUILD_ID = None
|
|
|
|
|
2025-01-18 21:45:25 -05:00
|
|
|
intents = discord.Intents.default()
|
|
|
|
intents.messages = True
|
|
|
|
intents.message_content = True
|
|
|
|
intents.guilds = True
|
|
|
|
intents.voice_states = True
|
|
|
|
|
|
|
|
|
|
|
|
class AmberClient(discord.Client):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__(intents=intents)
|
|
|
|
self.tree = discord.app_commands.CommandTree(self)
|
|
|
|
|
|
|
|
async def on_ready(self):
|
2025-01-28 09:22:02 -05:00
|
|
|
try:
|
|
|
|
app_info = await client.application_info()
|
|
|
|
if hasattr(app_info, "team") and app_info.team: # Check if the bot is part of a team
|
|
|
|
team_owner_id = app_info.team.owner_id
|
|
|
|
owner = await client.fetch_user(team_owner_id)
|
|
|
|
print(f"✅ Team owner fetched successfully: {owner} ({team_owner_id})")
|
|
|
|
else:
|
|
|
|
owner = app_info.owner or await client.fetch_user(DEFAULT_OWNER_ID)
|
|
|
|
print(f"✅ Individual owner fetched successfully: {owner} ({owner.id})")
|
|
|
|
|
|
|
|
# Send startup notification
|
|
|
|
try:
|
|
|
|
commit_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("utf-8").strip()
|
|
|
|
startup_message = (
|
|
|
|
f"🚀 **Quartessa is online!**\n"
|
|
|
|
f"Version: `{commit_hash}`\n\n"
|
|
|
|
"Use `/check_update` to check for updates or `/update` to apply updates."
|
|
|
|
)
|
|
|
|
await owner.send(startup_message)
|
|
|
|
except discord.Forbidden:
|
|
|
|
print("⚠️ Unable to send startup notification to the owner. Check privacy settings.")
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
print(f"⚠️ Error fetching owner information: {e}")
|
2025-01-18 21:45:25 -05:00
|
|
|
|
2025-01-19 22:29:16 -05:00
|
|
|
# Sync commands after the bot is fully ready
|
|
|
|
if GUILD_ID:
|
|
|
|
logging.info(f"Setting up commands for guild: {GUILD_ID}")
|
|
|
|
else:
|
|
|
|
logging.info("Setting up global commands (no guild ID specified).")
|
2025-01-18 21:45:25 -05:00
|
|
|
|
2025-01-19 22:29:16 -05:00
|
|
|
try:
|
|
|
|
await setup_commands(self, guild_id=GUILD_ID)
|
|
|
|
except Exception as e:
|
|
|
|
logging.error(f"Failed to setup commands: {e}")
|
2025-01-18 21:45:25 -05:00
|
|
|
|
2025-01-28 09:22:02 -05:00
|
|
|
print(f"✅ Quartessa is online as {client.user}. Done.")
|
|
|
|
|
2025-01-18 21:45:25 -05:00
|
|
|
|
2025-01-19 22:29:16 -05:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
client = AmberClient()
|
|
|
|
|
|
|
|
if TOKEN:
|
|
|
|
client.run(TOKEN)
|
|
|
|
else:
|
|
|
|
logging.error("Bot token not found. Check your .env file.")
|