56 lines
1.4 KiB
Python
56 lines
1.4 KiB
Python
from dotenv import load_dotenv
|
|
import discord
|
|
|
|
from modules.base import BaseModule
|
|
from modules import FourasModule, RhymesModule
|
|
|
|
MODULES = FourasModule, RhymesModule
|
|
|
|
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)
|
|
load_dotenv()
|
|
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:
|
|
m.load()
|
|
print(f"Logged in as {client.user}")
|
|
|
|
|
|
@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)
|
|
):
|
|
for m in client.modules:
|
|
await m.handle_message(message)
|
|
|
|
|
|
# Initialise le client
|
|
client.run(token)
|