This commit is contained in:
+25
-9
@@ -10,8 +10,8 @@ from sqlalchemy import delete, select
|
|||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from dakiny_bot import birthday_list
|
|
||||||
from database_setup.sql_data_classes import UserBirthday, engine
|
from database_setup.sql_data_classes import UserBirthday, engine
|
||||||
|
from main import birthday_list
|
||||||
|
|
||||||
|
|
||||||
class setCog(commands.Cog, name="Set Commands"):
|
class setCog(commands.Cog, name="Set Commands"):
|
||||||
@@ -30,12 +30,18 @@ class setCog(commands.Cog, name="Set Commands"):
|
|||||||
Parent slash command for set. Never called.
|
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.")
|
@set.subcommand(
|
||||||
|
description="Sets your birth month and day for the Birthday Fun. Use 0/0 to remove yourself."
|
||||||
|
)
|
||||||
async def birthday(
|
async def birthday(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
month: int = nextcord.SlashOption(required=True, min_value=0, max_value=12, description="Your birth month."),
|
month: int = nextcord.SlashOption(
|
||||||
day: int = nextcord.SlashOption(required=True, min_value=0, max_value=31, description="Your birth day."),
|
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.
|
Sets a user's birthday in the database. Removes on input 0/0. If birthday is today, adds to the birthday_list.
|
||||||
@@ -50,7 +56,9 @@ class setCog(commands.Cog, name="Set Commands"):
|
|||||||
await interaction.response.defer(ephemeral=True)
|
await interaction.response.defer(ephemeral=True)
|
||||||
|
|
||||||
if month == 0 and day == 0:
|
if month == 0 and day == 0:
|
||||||
stmt = delete(UserBirthday).where(UserBirthday.UserId == interaction.user.id)
|
stmt = delete(UserBirthday).where(
|
||||||
|
UserBirthday.UserId == interaction.user.id
|
||||||
|
)
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
session.execute(stmt)
|
session.execute(stmt)
|
||||||
session.commit()
|
session.commit()
|
||||||
@@ -62,14 +70,18 @@ class setCog(commands.Cog, name="Set Commands"):
|
|||||||
try:
|
try:
|
||||||
birthday = datetime(today.year, month, day)
|
birthday = datetime(today.year, month, day)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
await interaction.followup.send(f"Invalid date: {month}/{day}.", ephemeral=True)
|
await interaction.followup.send(
|
||||||
|
f"Invalid date: {month}/{day}.", ephemeral=True
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
# If the birthday is today, add to birthday_list
|
# If the birthday is today, add to birthday_list
|
||||||
if today.date() == birthday.date():
|
if today.date() == birthday.date():
|
||||||
birthday_list.append(interaction.user.id)
|
birthday_list.append(interaction.user.id)
|
||||||
|
|
||||||
new_birthday = UserBirthday(UserId=interaction.user.id, Birthday=f"{month}/{day}")
|
new_birthday = UserBirthday(
|
||||||
|
UserId=interaction.user.id, Birthday=f"{month}/{day}"
|
||||||
|
)
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
try:
|
try:
|
||||||
session.add(new_birthday)
|
session.add(new_birthday)
|
||||||
@@ -77,9 +89,13 @@ class setCog(commands.Cog, name="Set Commands"):
|
|||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
# User already has birthday, change it instead.
|
# User already has birthday, change it instead.
|
||||||
session.rollback()
|
session.rollback()
|
||||||
stmt = select(UserBirthday).where(UserBirthday.UserId == interaction.user.id)
|
stmt = select(UserBirthday).where(
|
||||||
|
UserBirthday.UserId == interaction.user.id
|
||||||
|
)
|
||||||
new_birthday = session.scalar(stmt)
|
new_birthday = session.scalar(stmt)
|
||||||
new_birthday.Birthday = f"{month}/{day}"
|
new_birthday.Birthday = f"{month}/{day}"
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
await interaction.followup.send(f"Birthday set to {month}/{day}.", ephemeral=True)
|
await interaction.followup.send(
|
||||||
|
f"Birthday set to {month}/{day}.", ephemeral=True
|
||||||
|
)
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ from sqlalchemy.orm import Session
|
|||||||
|
|
||||||
from classes.election_cycle import ElectionCycle
|
from classes.election_cycle import ElectionCycle
|
||||||
from config import DakinyConfig
|
from config import DakinyConfig
|
||||||
from dakiny_bot import birthday_list
|
|
||||||
from database_setup.sql_data_classes import UserBirthday, engine
|
from database_setup.sql_data_classes import UserBirthday, engine
|
||||||
|
from main import birthday_list
|
||||||
from utils import get_current_election_cycle
|
from utils import get_current_election_cycle
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Defines cog for on message listener.
|
|||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
from dakiny_bot import birthday_list
|
from main import birthday_list
|
||||||
|
|
||||||
|
|
||||||
class SubmissionListener(commands.Cog, name="Message Listener"):
|
class SubmissionListener(commands.Cog, name="Message Listener"):
|
||||||
@@ -39,5 +39,7 @@ async def birthday_action(message: nextcord.Message) -> None:
|
|||||||
message (nextcord.Message): The message to check for a birthday person.
|
message (nextcord.Message): The message to check for a birthday person.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if message.author.id in birthday_list or bool(set(message.raw_mentions) & set(birthday_list)):
|
if message.author.id in birthday_list or bool(
|
||||||
|
set(message.raw_mentions) & set(birthday_list)
|
||||||
|
):
|
||||||
await message.add_reaction("🎂")
|
await message.add_reaction("🎂")
|
||||||
|
|||||||
Reference in New Issue
Block a user