Skip to content

Commit

Permalink
create triggerbirthday command
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulMarisOUMary committed Dec 20, 2023
1 parent 2e143c0 commit 0667506
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cogs/birthday.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Optional, Union

from classes.discordbot import DiscordBot
from classes.utilities import bot_has_permissions

@app_commands.guild_only()
class Birthday(commands.GroupCog, name="birthday", group_name="birthday", group_description="Commands related to birthday."):
Expand Down Expand Up @@ -44,6 +45,9 @@ async def daily_birthday(self) -> None:
if not datetime.now().hour == 9:
return

await self.trigger_global_birthday()

async def trigger_global_birthday(self, specify_guild: Optional[int] = None):
response: tuple[tuple[int, date]] = await self.bot.database.select(self.subconfig_data["table"], "*", condition="DAY(`user_birth`) = DAY(CURRENT_DATE()) AND MONTH(`user_birth`) = MONTH(CURRENT_DATE())")
if not response:
self.bot.log(message = "No birthday today", name = "discord.cogs.birthday.daily_birthday")
Expand All @@ -54,6 +58,8 @@ async def daily_birthday(self) -> None:
for guild in self.bot.guilds:
if not guild.id in response_guilds:
continue
if specify_guild and guild.id != specify_guild:
continue
for channel in guild.text_channels:
if channel.type == discord.ChannelType.forum:
continue
Expand Down Expand Up @@ -120,6 +126,21 @@ async def show_birthday_message(self, interaction: discord.Interaction, user: Un
else:
await interaction.response.send_message(":birthday: Nothing was found. Set the birthday and retry.")

@bot_has_permissions(view_channel=True)
@commands.command(name="triggerbirthday")
@commands.has_permissions(administrator=True)
@commands.cooldown(1, 25, commands.BucketType.guild)
@commands.guild_only()
async def config_invite_logs(self, ctx: commands.Context, guild_id: Optional[int] = None) -> None:
"""Trigger manually the birthday."""
if guild_id and not guild_id in [guild.id for guild in self.bot.guilds]:
await ctx.send(f"Invalid Guild id `{guild_id}`.")
return

await self.trigger_global_birthday(guild_id)
await ctx.send(f"Manually trigger birthday for `{guild_id if guild_id else 'all guilds'}`.")




async def setup(bot: DiscordBot) -> None:
Expand Down

0 comments on commit 0667506

Please sign in to comment.