-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
87 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from __future__ import annotations | ||
|
||
from datetime import datetime, timezone | ||
from typing import TYPE_CHECKING | ||
|
||
import discord | ||
from discord import app_commands | ||
|
||
from utils.birthdays import load_birthdays, save_birthdays | ||
|
||
if TYPE_CHECKING: | ||
from bot import ChouetteBot | ||
|
||
|
||
# Commande pour ajouter un anniversaire | ||
@app_commands.command( | ||
name="add_birthday", | ||
description="Permit the user to register his birthday", | ||
) | ||
async def add_birthday(interaction: discord.Interaction[ChouetteBot]): | ||
date = datetime.now(tz=timezone.utc) | ||
user_id = str(interaction.user.id) | ||
birthdays = load_birthdays() | ||
birthdays.table[user_id] | ||
birthdays[user_id][interaction.user.name] = date | ||
save_birthdays(birthdays) | ||
await interaction.response.send_message("Anniversaire enregistré !", ephemeral=True) | ||
|
||
|
||
# Commande pour supprimer un anniversaire | ||
@app_commands.command( | ||
name="remove_birthday", | ||
description="Permit the user to delte his birthday", | ||
) | ||
async def remove_birthday(interaction: discord.Interaction[ChouetteBot]): | ||
user_id = str(interaction.user.id) | ||
birthdays = load_birthdays() | ||
if user_id in birthdays: | ||
del birthdays[user_id] | ||
save_birthdays(birthdays) | ||
await interaction.response.send_message("Anniversaire supprimé !") | ||
else: | ||
await interaction.response.send_message("Vous n'avez pas d'anniversaire enregistré.", ephemeral=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
aiohttp ~= 3.9.3 | ||
discord.py[speed] ~= 2.3.2 | ||
python-dotenv ~= 1.0.1 | ||
tomlkit ~= 0.12.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import tomlkit | ||
|
||
birthday_file_path = "data/birthdays.toml" | ||
|
||
|
||
# Charge les anniversaires depuis un fichier TOML | ||
def load_birthdays(): | ||
try: | ||
with open(birthday_file_path) as f: | ||
return tomlkit.load(f) | ||
except FileNotFoundError: | ||
return {} | ||
|
||
|
||
# Enregistre les anniversaires dans le fichier TOML | ||
def save_birthdays(birthdays): | ||
with open(birthday_file_path, "w") as f: | ||
tomlkit.dump(birthdays, f) |