67 lines
2.2 KiB
Python
67 lines
2.2 KiB
Python
"""
|
|
Contains commands and views for set commands.
|
|
"""
|
|
|
|
from datetime import datetime
|
|
|
|
import nextcord
|
|
from nextcord.ext import commands
|
|
from sqlalchemy import delete
|
|
from sqlalchemy.orm import Session
|
|
|
|
from dakiny_bot import birthday_list
|
|
from database_setup.sql_data_classes import UserBirthday, engine
|
|
|
|
|
|
class setCog(commands.Cog, name="Set Commands"):
|
|
"""
|
|
Class holds set commands.
|
|
"""
|
|
|
|
def __init__(self) -> None:
|
|
"""
|
|
Default constructor for SetCog class. Does nothing.
|
|
"""
|
|
|
|
@nextcord.slash_command()
|
|
async def set(self, interaction: nextcord.Interaction):
|
|
"""
|
|
Parent slash command for set. Never called.
|
|
"""
|
|
|
|
@set.subcommand(description="Sets your birth month and day for the Birthday Fun. Use 0/0 to remove yourself.")
|
|
async def birthday(
|
|
self,
|
|
interaction: nextcord.Interaction,
|
|
month: int = nextcord.SlashOption(required=True, min_value=0, max_value=12, description="Your birth month."),
|
|
day: int = nextcord.SlashOption(required=True, min_value=0, max_value=31, description="Your birth day."),
|
|
):
|
|
"""
|
|
Sets a user's birthday in the database. Removes on input 0/0. If birthday is today, adds to the birthday_list.
|
|
|
|
Args:
|
|
interaction (nextcord.Interaction): Interaction that invoked the command.
|
|
month (int, optional): The month a user was born. Is SlashOption.
|
|
day (int, optional): The day a user was born. Is SlashOption.
|
|
"""
|
|
|
|
if month == 0 and day == 0:
|
|
stmt = delete(UserBirthday).where(UserBirthday.UserId == interaction.user.id)
|
|
with Session(engine) as session:
|
|
session.scalar(stmt)
|
|
session.commit()
|
|
return
|
|
|
|
# check if valid day
|
|
today = datetime.today()
|
|
birthday = datetime(today.year, month, day)
|
|
|
|
# If the birthday is today, add to birthday_list
|
|
if today.date() == birthday.date():
|
|
birthday_list.append(interaction.user.id)
|
|
|
|
new_birthday = UserBirthday(interaction.user.id, f"{month}/{day}")
|
|
with Session(engine) as session:
|
|
session.add(new_birthday)
|
|
session.commit()
|