Skip to content

Commit

Permalink
bazar
Browse files Browse the repository at this point in the history
  • Loading branch information
gylfirst committed Apr 5, 2024
1 parent 4661fd8 commit 6d35fc5
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ GUILD_ID=
POKE_CHANNEL=
POKE_ROLE=
POKEBALL_EMOJI=
# Birthdays notif
BIRTHDAY_CHANNEL=

# Hypixel API key
HYPIXEL_KEY=
Expand Down
43 changes: 43 additions & 0 deletions commands/birthdays.py
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)
2 changes: 1 addition & 1 deletion commands/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def is_msg(msg: discord.Message) -> bool:
return (message.id >> 22) <= (msg.id >> 22) <= (last_id >> 22)

del_msg = await message.channel.purge(bulk=True, reason="Admin used bulk delete", check=is_msg)
await interaction.followup.send(f"{len(del_msg)} messages supprimés !")
await interaction.followup.send(f"{len(del_msg)} messages supprimés !", delete_after=2)


# Make a bot information command
Expand Down
13 changes: 8 additions & 5 deletions commands_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import discord

from commands.admin import whisper
from commands.birthdays import add_birthday, remove_birthday
from commands.misc import cheh, delete, die_roll, info, latex, pin, ping
from commands.skyblock import Skyblock

Expand All @@ -13,14 +14,16 @@

# List the commands
COMMANDS_LIST: tuple = (
latex,
die_roll,
ping,
add_birthday,
cheh,
pin,
delete,
whisper,
die_roll,
info,
latex,
pin,
ping,
remove_birthday,
whisper,
)

SPACES = " " * 38
Expand Down
Empty file added data/birthdays.toml
Empty file.
1 change: 1 addition & 0 deletions docker-compose.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
- "8080:8080" # Exposed port:Inner port
volumes:
- /path/to/logs:/usr/src/chouettebot/logs # Path to logs
- /path/to/data:/usr/src/chouettebot/data # Path to data storage

restart: unless-stopped # Restart policy (here it will always restart unless you stopped it)
pull_policy: always # Pull the image before the application start
1 change: 1 addition & 0 deletions requirements.txt
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
13 changes: 13 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ async def poke_ping():
pokeball = client.get_emoji(int(client.config["POKEBALL_EMOJI"]))
msg_poke = f"{dresseurs.mention} C'est l'heure d'attraper des pokémons {pokeball}"
await client.get_channel(int(client.config["POKE_CHANNEL"])).send(msg_poke)

# Loop to check if it's 8:00 and send a message if it's someone's birthday
@tasks.loop(hours=24)
async def check_birthdays():
now = time.now()
if now.hour == 8 and now.minute == 0:
today = now.strftime('%d/%m')
for user_id, birthday in birthdays.items():
if birthday == today:
user = await bot.fetch_user(int(user_id))
msg_birthday = f":tada: {user.mention} is a year older now! Wish them a happy birthday! :tada:"
await client.get_channel(int(client.config["BIRTHDAY_CHANNEL"])).send(msg_birthday)

# Start loop
poke_ping.start()
check_birthdays.start()
18 changes: 18 additions & 0 deletions utils/birthdays.py
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)

0 comments on commit 6d35fc5

Please sign in to comment.