51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
import discord
|
|
import os
|
|
from modules.base import BaseModule
|
|
|
|
from client import client, MODULES, tree
|
|
from modules import gitea
|
|
|
|
token = os.getenv("DISCORD_TOKEN", "NO_TOKEN")
|
|
|
|
client.riddles = []
|
|
client.answers = []
|
|
client.rhyme_keys = {}
|
|
client.rhyme_strings = {}
|
|
client.cooldown = {}
|
|
client.ongoing_riddles = {}
|
|
client.modules: list[BaseModule] = []
|
|
|
|
|
|
@client.event
|
|
async def on_ready():
|
|
client.modules = [m(client) for m in MODULES]
|
|
for m in client.modules:
|
|
await m.load()
|
|
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):
|
|
# don't answer to self
|
|
if (
|
|
message.author == client.user and message.channel in client.ongoing_riddles
|
|
): # need to move a part of that block in FourasModule
|
|
current_riddle = client.ongoing_riddles[message.channel]
|
|
if "message" not in current_riddle:
|
|
current_riddle["message"] = message
|
|
return
|
|
|
|
if isinstance(
|
|
message.channel, (discord.DMChannel, discord.TextChannel, discord.Thread)
|
|
):
|
|
handled = False
|
|
for m in client.modules:
|
|
if not handled:
|
|
handled = await m.handle_message(message)
|
|
|
|
# Initialise le client
|
|
client.run(token)
|