67 lines
2.2 KiB
Python
67 lines
2.2 KiB
Python
from typing import Optional, List
|
|
from io import BytesIO
|
|
from os import getenv
|
|
import discord
|
|
|
|
from discord import app_commands
|
|
from discord.app_commands import Choice
|
|
from dotenv import load_dotenv
|
|
|
|
from create_calendar import get_calendar, get_eleves, display
|
|
|
|
load_dotenv()
|
|
|
|
MY_GUILD = discord.Object(id=getenv("GUILD_ID")) # replace with your guild id
|
|
|
|
|
|
class MyClient(discord.Client):
|
|
def __init__(self):
|
|
super().__init__(intents=None)
|
|
self.tree = app_commands.CommandTree(self)
|
|
|
|
async def setup_hook(self):
|
|
self.tree.copy_global_to(guild=MY_GUILD)
|
|
await self.tree.sync(guild=MY_GUILD)
|
|
|
|
|
|
client = MyClient()
|
|
|
|
eleves = get_eleves()
|
|
|
|
|
|
|
|
@client.event
|
|
async def on_ready():
|
|
print(f'Logged in as {client.user} (ID: {client.user.id})')
|
|
print('------')
|
|
|
|
|
|
@client.tree.command()
|
|
@app_commands.choices(langues=[
|
|
Choice(name='Anglais LV1, Autre ou Pas de LV2', value="EN"),
|
|
Choice(name='Anglais LV1, Allemand LV2', value="EN-DE"),
|
|
Choice(name='Anglais LV1, Espagnol LV2', value="EN-ES"),
|
|
Choice(name='Allemand LV1, Anglais LV2', value="DE-EN"),
|
|
Choice(name='Espagnol LV1, Anglais LV2', value="ES-EN")
|
|
]
|
|
)
|
|
@app_commands.describe(groupe="Votre groupe de colle, groupe ∈ ⟦1, 15⟧")
|
|
@app_commands.describe(langues="Les options de langue que vous suivez. (Les langues suivies à H4 ne sont pas gérées, mettez 'Autres')")
|
|
async def edt(
|
|
interaction: discord.Interaction,
|
|
groupe: app_commands.Range[int, 1, 15],
|
|
langues: Choice[str]):
|
|
"""
|
|
Génère un emploi du temps prenant compte des colles, des langues et de la semaine.
|
|
"""
|
|
cal = get_calendar(str(groupe), langues.value)
|
|
calendrier = BytesIO(cal)
|
|
fichier = discord.File(fp=calendrier, filename=f"EDT-{groupe}-{langues.value}.ics")
|
|
|
|
await interaction.response.send_message(
|
|
f"Bonjour, votre emploi du temps pour le groupe {groupe} ({langues.name}) au format `.ics` a bien été généré ! \n\n Vous pouvez l'importer dans la plupart des messageries, je vous recommande cependant de créer un nouveau calendrier avec de l'importer, au cas où vous vouliez l'enlever. \n\n*Si vous avez des retours à faire (bug, erreur,..), contactez Joseph.*",
|
|
file=fichier)
|
|
|
|
|
|
client.run(getenv("TOKEN"))
|