first commit
This commit is contained in:
commit
ae1de109bb
|
@ -0,0 +1,2 @@
|
|||
/__pycache__
|
||||
/.env
|
|
@ -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<int(group)<17:
|
||||
create_colloscope(int(group), timezone)
|
||||
await interaction.response.send_message(content=f"Voici le fichier de colles parsé pour le groupe {group} ! ", file=discord.File("output.ics", filename=f"groupe{group}.ics") )
|
||||
else:
|
||||
await interaction.response.send_message(content="Ce groupe n'existe pas banane !")
|
||||
|
||||
# Slash command to get help
|
||||
@tree.command(
|
||||
name="help",
|
||||
description="Afficher l'aide",
|
||||
guild=discord.Object(id=1292935532472565852)
|
||||
|
||||
)
|
||||
async def help(interaction:discord.Interaction):
|
||||
embed = discord.Embed(title="Le Bot des MP2I[3]",
|
||||
url="https://marsisus.me/staticky",
|
||||
description="Bienvenue sur la page d'aide du bot !",
|
||||
colour=0x00b0f4,
|
||||
timestamp=datetime.now())
|
||||
|
||||
embed.set_author(name="Staticky",
|
||||
url="https://marsisus.me/staticky")
|
||||
|
||||
await interaction.response.send_message(embed=embed, ephemeral=True)
|
||||
|
||||
# Lancer le bot
|
||||
bot.run(os.getenv('BOT_TOKEN'))
|
|
@ -0,0 +1,124 @@
|
|||
import openpyxl
|
||||
from datetime import datetime, timedelta, timezone
|
||||
import locale
|
||||
import calendar
|
||||
import pytz
|
||||
from ics import Calendar, Event
|
||||
|
||||
# Open the Excel file
|
||||
|
||||
def create_colloscope(groupe:int, timezone:str = "Europe/Paris"):
|
||||
try:
|
||||
pytz.timezone(timezone)
|
||||
except pytz.UnknownTimeZoneError:
|
||||
timezone = "Europe/Paris"
|
||||
c = Calendar()
|
||||
|
||||
workbook = openpyxl.load_workbook('colloscope.xlsx')
|
||||
|
||||
# Access a specific sheet
|
||||
sheet = workbook['Colloscope S1']
|
||||
|
||||
# Do something with the sheet, such as reading data or modifying it
|
||||
# Retrieve all coordinates where the cell value is 10
|
||||
coordinates = []
|
||||
for row in sheet.iter_rows():
|
||||
for cell in row:
|
||||
if cell.value == groupe:
|
||||
coordinates.append((cell.row, cell.column))
|
||||
|
||||
# Retrieve additional information for each coordinate
|
||||
for coordinate in coordinates:
|
||||
row = coordinate[0]
|
||||
column = coordinate[1]
|
||||
matière = sheet[f'A{row}'].value
|
||||
matière = matière.capitalize()
|
||||
professor = sheet[f'B{row}'].value
|
||||
hour = sheet[f'D{row}'].value
|
||||
room = sheet[f'E{row}'].value
|
||||
# Convert column number to letter
|
||||
column_letter = chr(ord('A') + column - 1)
|
||||
date_str = sheet[f'{column_letter}4'].value[3:8]
|
||||
try :
|
||||
date = datetime.strptime(date_str, "%d/%m").date()
|
||||
except ValueError:
|
||||
continue
|
||||
try:
|
||||
day_sem = sheet[f"C{row}"].value
|
||||
|
||||
except TypeError or day_sem == None:
|
||||
continue
|
||||
if day_sem == None:
|
||||
continue
|
||||
day_sem = str(day_sem).split(" ")[0]
|
||||
days = ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche']
|
||||
day_number_sem = days.index(day_sem)
|
||||
|
||||
# Combine day_number_sem with date
|
||||
new_days = day_number_sem + date.day;
|
||||
if new_days > 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()
|
Loading…
Reference in New Issue