- Update edt cog (command removed from main)
- Update main - Add a parent class for cogs - Fixes
This commit is contained in:
parent
74ff357853
commit
19b1f0eeea
|
@ -158,5 +158,5 @@ cython_debug/
|
||||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
.idea/
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
from discord.ext import commands
|
||||||
|
import discord
|
||||||
|
|
||||||
|
|
||||||
|
class MyCog(commands.Cog):
|
||||||
|
def __init__(self, bot: commands.Bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
async def cog_load(self):
|
||||||
|
print(f"{self.__class__.__name__} loaded!")
|
||||||
|
|
||||||
|
async def cog_unload(self):
|
||||||
|
print(f"{self.__class__.__name__} unloaded!")
|
||||||
|
|
||||||
|
|
||||||
|
async def setup(bot):
|
||||||
|
await bot.add_cog(EDT(bot))
|
|
@ -1,11 +1,64 @@
|
||||||
|
import discord
|
||||||
|
from discord import app_commands
|
||||||
|
from discord.app_commands import Choice
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
|
|
||||||
class EDT:
|
from classes.my_cog import MyCog
|
||||||
|
from create_calendar import get_calendar, get_eleves, display
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
|
|
||||||
|
class EDT(MyCog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
|
super().__init__(bot)
|
||||||
|
self.eleves = get_eleves()
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
print("EDT loaded")
|
|
||||||
|
@app_commands.command(name="edt")
|
||||||
|
@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')")
|
||||||
|
@app_commands.describe(split="Créer deux fichiers différentes, un pour les colles et un pour le rest de l'EDT.")
|
||||||
|
async def edt(
|
||||||
|
self,
|
||||||
|
interaction: discord.Interaction,
|
||||||
|
groupe: app_commands.Range[int, 1, 15],
|
||||||
|
langues: Choice[str],
|
||||||
|
split: bool = False):
|
||||||
|
"""
|
||||||
|
Génère un emploi du temps prenant compte des colles, des langues et de la semaine.
|
||||||
|
"""
|
||||||
|
cal_list = get_calendar(str(groupe), langues.value, split)
|
||||||
|
fichiers = []
|
||||||
|
|
||||||
|
if split:
|
||||||
|
fichiers.append(discord.File(fp=BytesIO(cal_list[0]), filename=f"EDT-{groupe}-{langues.value}-WO.ics"))
|
||||||
|
fichiers.append(discord.File(fp=BytesIO(cal_list[1]), filename=f"Colles-{groupe}.ics"))
|
||||||
|
|
||||||
|
message = f"""
|
||||||
|
\nVotre emploi du temps (`EDT-{groupe}-{langues.value}-WO.ics`) pour le groupe `{groupe}`, `{langues.name}` au format `.ics` a bien été généré, **sans les colles**
|
||||||
|
\n\nLes colles ont été généré séparemment pour le groupe `{groupe}` : `Colles-{groupe}.ics`
|
||||||
|
\n\nVous pouvez importer ces fichiers dans la plupart des calendriers, mais il est recommandé de créer un nouveau sous-calendrier pour facilement pouvoir le changer.
|
||||||
|
"""
|
||||||
|
|
||||||
|
else:
|
||||||
|
fichiers.append(discord.File(fp=BytesIO(cal_list[0]), filename=f"EDT-{groupe}-{langues.value}.ics"))
|
||||||
|
message = f"""
|
||||||
|
\nVotre emploi du temps (`EDT-{groupe}-{langues.value}.ics`) pour le groupe `{groupe}`, `{langues.name}` au format `.ics` a bien été généré, **avec les colles**
|
||||||
|
\n\nVous pouvez importer ces fichiers dans la plupart des calendriers, mais il est recommandé de créer un nouveau sous-calendrier pour facilement pouvoir le changer.
|
||||||
|
"""
|
||||||
|
|
||||||
|
await interaction.response.send_message(message, files=fichiers)
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
async def setup(bot):
|
||||||
bot.add_cog(EDT(bot))
|
await bot.add_cog(EDT(bot))
|
||||||
|
|
79
main.py
79
main.py
|
@ -1,89 +1,38 @@
|
||||||
from typing import Optional, List
|
from typing import Optional, List
|
||||||
from io import BytesIO
|
from os import getenv, listdir
|
||||||
from os import getenv
|
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
from discord.app_commands import Choice
|
from discord.app_commands import Choice
|
||||||
|
from discord.ext import commands
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
from create_calendar import get_calendar, get_eleves, display
|
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
MY_GUILD = discord.Object(id=getenv("GUILD_ID")) # replace with your guild id
|
|
||||||
|
|
||||||
|
class MyClient(commands.Bot):
|
||||||
class MyClient(discord.Client):
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(intents=discord.Intents.none())
|
super().__init__(intents=discord.Intents.none(), command_prefix="!")
|
||||||
self.tree = app_commands.CommandTree(self)
|
|
||||||
|
|
||||||
self.initial_extensions = ["cogs." + f[:-3] for f in os.listdir("./cogs") if f.endswith(".py") and f.name != "__init__.py"]
|
self.MY_GUILD = discord.Object(id=getenv("GUILD_ID"))
|
||||||
|
|
||||||
|
self.initial_extensions = ["cogs." + f[:-3] for f in listdir("./cogs") if
|
||||||
|
f.endswith(".py") and f.__str__() != "__init__.py"]
|
||||||
|
|
||||||
async def setup_hook(self):
|
async def setup_hook(self):
|
||||||
|
|
||||||
# cogs
|
# cogs
|
||||||
for extension in self.initial_extensions:
|
for extension in self.initial_extensions:
|
||||||
await self.load_extension(extension)
|
await self.load_extension(extension)
|
||||||
|
|
||||||
self.tree.copy_global_to(guild=MY_GUILD)
|
self.tree.copy_global_to(guild=self.MY_GUILD)
|
||||||
await self.tree.sync(guild=MY_GUILD)
|
await self.tree.sync(guild=self.MY_GUILD)
|
||||||
|
|
||||||
|
async def on_ready(self):
|
||||||
client = MyClient()
|
print(f'Logged in as {self.user} (ID: {self.user.id})')
|
||||||
|
|
||||||
eleves = get_eleves()
|
|
||||||
|
|
||||||
|
|
||||||
@client.event
|
|
||||||
async def on_ready():
|
|
||||||
print(f'Logged in as {client.user} (ID: {client.user.id})')
|
|
||||||
print('------')
|
print('------')
|
||||||
|
|
||||||
|
|
||||||
@client.tree.command()
|
if __name__ == "__main__":
|
||||||
@app_commands.choices(langues=[
|
client = MyClient()
|
||||||
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')")
|
|
||||||
@app_commands.describe(split="Créer deux fichiers différentes, un pour les colles et un pour le rest de l'EDT.")
|
|
||||||
async def edt(
|
|
||||||
interaction: discord.Interaction,
|
|
||||||
groupe: app_commands.Range[int, 1, 15],
|
|
||||||
langues: Choice[str],
|
|
||||||
split: bool = False):
|
|
||||||
"""
|
|
||||||
Génère un emploi du temps prenant compte des colles, des langues et de la semaine.
|
|
||||||
"""
|
|
||||||
cal_list = get_calendar(str(groupe), langues.value, split)
|
|
||||||
fichiers = []
|
|
||||||
|
|
||||||
if split:
|
|
||||||
fichiers.append(discord.File(fp=BytesIO(cal_list[0]), filename=f"EDT-{groupe}-{langues.value}-WO.ics"))
|
|
||||||
fichiers.append(discord.File(fp=BytesIO(cal_list[1]), filename=f"Colles-{groupe}.ics"))
|
|
||||||
|
|
||||||
message = f"""
|
|
||||||
\nVotre emploi du temps (`EDT-{groupe}-{langues.value}-WO.ics`) pour le groupe `{groupe}`, `{langues.name}` au format `.ics` a bien été généré, **sans les colles**
|
|
||||||
\n\nLes colles ont été généré séparemment pour le groupe `{groupe}` : `Colles-{groupe}.ics`
|
|
||||||
\n\nVous pouvez importer ces fichiers dans la plupart des calendriers, mais il est recommandé de créer un nouveau sous-calendrier pour facilement pouvoir le changer.
|
|
||||||
"""
|
|
||||||
|
|
||||||
else:
|
|
||||||
fichiers.append(discord.File(fp=BytesIO(cal_list[0]), filename=f"EDT-{groupe}-{langues.value}.ics"))
|
|
||||||
message = f"""
|
|
||||||
\nVotre emploi du temps (`EDT-{groupe}-{langues.value}.ics`) pour le groupe `{groupe}`, `{langues.name}` au format `.ics` a bien été généré, **avec les colles**
|
|
||||||
\n\nVous pouvez importer ces fichiers dans la plupart des calendriers, mais il est recommandé de créer un nouveau sous-calendrier pour facilement pouvoir le changer.
|
|
||||||
"""
|
|
||||||
|
|
||||||
await interaction.response.send_message(message, files=fichiers)
|
|
||||||
|
|
||||||
|
|
||||||
client.run(getenv("TOKEN"))
|
client.run(getenv("TOKEN"))
|
||||||
|
|
Loading…
Reference in New Issue