From ae1de109bb8d254c9071f184c9f814a48175e572 Mon Sep 17 00:00:00 2001 From: FallMarsisus Date: Sat, 12 Oct 2024 11:50:04 +0200 Subject: [PATCH] first commit --- .gitignore | 2 + botdiscord.py | 70 +++++++++++++++++++++++++++ parse_colles.py | 124 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 196 insertions(+) create mode 100644 .gitignore create mode 100644 botdiscord.py create mode 100644 parse_colles.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..87eeb67 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/__pycache__ +/.env \ No newline at end of file diff --git a/botdiscord.py b/botdiscord.py new file mode 100644 index 0000000..f9fa1b5 --- /dev/null +++ b/botdiscord.py @@ -0,0 +1,70 @@ +from datetime import datetime +import discord +from discord import app_commands +from parse_colles import create_colloscope +import os +from dotenv import load_dotenv, dotenv_values + + +# Créer une instance du bot +intents = discord.Intents.default() +intents.message_content = True +bot = discord.Client( intents=intents) +tree = app_commands.CommandTree(bot) + + +load_dotenv() +# Événement lorsque le bot est prêt +@bot.event +async def on_ready(): + await tree.sync(guild=discord.Object(id=1292935532472565852)) + + print(f'Connecté en tant que {bot.user.name}') + +# réagir a un message +@bot.event +async def on_message(message): + if message.author == bot.user: + return + if "quoi" in message.content[-10:].lower(): + await message.channel.send(f"quoicoubeh {message.author.mention} !") + if "j'aime" in message.content.lower()[:6]: + await message.author.edit(nick=f'{message.content[6:]}') + + +# slash commands +@tree.command( + name="parse_colles", + description="Récupérer un fichier en .ics contenant vos colles du S1", + guild=discord.Object(id=1292935532472565852) +) +@app_commands.describe(group = "Votre Groupe de Colles. (1-16)") +@app_commands.describe(timezone = "Le fuseau Horaire (laisser vide si vous ne savez pas), par défaut: Europe/Paris, si il y a un décalage, essayer UTC") +async def recup_colles(interaction:discord.Interaction, group:str, timezone:str = "Europe/Paris"): + if 0 30 and date.month in [4, 6, 9, 11]: + new_days = new_days - 30; + new_month = date.month + 1; + elif new_days > 31 and date.month in [1, 3, 5, 7, 8, 10, 12]: + new_days = new_days - 31; + new_month = date.month + 1; + else : + new_month = date.month; + if (new_month <9): + combined_date = datetime(2025, new_month, new_days).date() + else: + combined_date = datetime(2024, new_month, new_days).date() + + + if professor == None: + continue; + + + start_time = datetime.strptime(hour.split('-')[0][:-1], "%H").time() + + + # Calculate the end time by adding 1 hour to the start time + end_time = (datetime.combine(date.today(), start_time) + timedelta(hours=1)).time() + + # Create a new datetime object with the combined date and start time + start_datetime = datetime.combine(combined_date, start_time) + + # Create a new datetime object with the combined date and end time + end_datetime = datetime.combine(combined_date, end_time) + + """ + print(f"Day: {day_sem}") + print(f"Date: {combined_date}") + print(f"Start time: {start_datetime}") + print(f"End time: {end_datetime}") + print(f"Subject: {matière}") + print(f"Professor: {professor}") + print(f"Room: {room}") + print("--------------------") + """ + + e = Event() + e.name = f"Colle {matière}" + + """if (start_datetime.month>9 and start_datetime.month<8): + time_ecart = offset - 2 + else: + time_ecart = offset""" + + e.begin = start_datetime.astimezone(pytz.timezone(timezone)) + e.duration = ({'hours': 1}); + e.location = f"{room} - Saint-Louis" + e.description = f"Professeur: {professor}\nSalle: {room}\nMatière : {matière}" + e.organizer = "Simon Lancelin" + e.alarms = [] + c.events.add(e) + + # Save the changes + workbook.save('colloscope.xlsx') + + + with open(f'output.ics', 'w') as my_file: + my_file.writelines(c) + + # Close the workbook + workbook.close() \ No newline at end of file