79 lines
1.9 KiB
Python
79 lines
1.9 KiB
Python
# main.py
|
|
import os
|
|
|
|
import discord
|
|
from discord import app_commands
|
|
from dotenv import load_dotenv
|
|
|
|
# Load environment variables
|
|
load_dotenv()
|
|
|
|
# Discord client setup
|
|
intents = discord.Intents.default()
|
|
intents.members = True
|
|
intents.presences = True
|
|
intents.guilds = True
|
|
intents.messages = True
|
|
intents.message_content = True
|
|
|
|
client = discord.Client(intents=intents)
|
|
tree = app_commands.CommandTree(client)
|
|
|
|
|
|
@client.event
|
|
async def on_ready():
|
|
global client, tree
|
|
"""Initialize bot state and sync commands."""
|
|
# Import initialization functions
|
|
from fouras import load_riddles, setup_commands
|
|
from rhymes import ensure_log_file, load_rhymes, setup_rhymes_commands
|
|
|
|
# Ensure directories exist
|
|
ensure_log_file()
|
|
|
|
# Load riddles and answers
|
|
load_riddles()
|
|
|
|
# register fouras commands
|
|
setup_commands(client, tree)
|
|
setup_rhymes_commands(client, tree)
|
|
|
|
# Load rhymes
|
|
success, msg = load_rhymes()
|
|
print(msg)
|
|
|
|
# Sync commands
|
|
async for guild in client.fetch_guilds():
|
|
tree.copy_global_to(guild=guild)
|
|
await tree.sync(guild=guild)
|
|
|
|
print(f"Logged in as {client.user} on {len(client.guilds)} servers!")
|
|
|
|
|
|
@client.event
|
|
async def on_message(message):
|
|
global client
|
|
"""Handle incoming messages."""
|
|
# Ignore bot's own messages
|
|
if message.author == client.user:
|
|
return
|
|
|
|
# Handle fouras module
|
|
from fouras import handle_message as handle_fouras
|
|
|
|
await handle_fouras(message, client)
|
|
|
|
# Handle rhymes module
|
|
from rhymes import handle_message as handle_rhymes
|
|
|
|
await handle_rhymes(message, client)
|
|
|
|
|
|
# Run the client
|
|
if __name__ == "__main__":
|
|
token = os.getenv("DISCORD_TOKEN")
|
|
if not token:
|
|
print("Error: DISCORD_TOKEN not found in environment variables")
|
|
exit(1)
|
|
client.run(token)
|