Compare commits

..
4 Commits
Author SHA1 Message Date
imcompiling 094a22f5e7 Update README.md
build_latest / build (push) Successful in 23s
2024-05-15 17:13:45 -04:00
imcompiling 592819e028 Update dockerfile to use main.
build_latest / build (push) Successful in 1m2s
2024-05-15 14:31:26 -04:00
imcompiling 967d41b8ef Rename dakiny_bot.py to main.py.
build_latest / build (push) Failing after 16s
2024-05-14 11:18:55 -04:00
imcompiling 01687ae8e8 Reduce duplicate code when getting cycle name.
build_develop / build (push) Successful in 48s
2024-05-13 21:32:19 -04:00
7 changed files with 38 additions and 18 deletions
+2 -2
View File
@@ -10,7 +10,7 @@ WORKDIR /home
COPY requirements.txt requirements.txt COPY requirements.txt requirements.txt
COPY config.py config.py COPY config.py config.py
COPY dakiny_bot.py dakiny_bot.py COPY main.py main.py
COPY utils.py utils.py COPY utils.py utils.py
COPY bot_messages bot_messages/ COPY bot_messages bot_messages/
@@ -23,4 +23,4 @@ RUN pip install -r requirements.txt
# remove build deps that aren't needed to run # remove build deps that aren't needed to run
# RUN apt-get -y remove python3-dev build-essential && apt-get -y autoremove # RUN apt-get -y remove python3-dev build-essential && apt-get -y autoremove
CMD ["python3", "-u", "./dakiny_bot.py"] CMD ["python3", "-u", "./main.py"]
+5 -1
View File
@@ -1,5 +1,9 @@
# Dakiny Bot # Dakiny Bot
Bot assumes that it always did the step before it. If the step before an action didn't happen, behavior is undefined. Dakiny clan's own discord bot!
### Assumptions
- For Elections: Bot assumes that it always did the step before it. If the step before an action didn't happen, behavior is undefined.
Object creation in the middle of a cycle is only there for restarting the bot. All relevant information should already Object creation in the middle of a cycle is only there for restarting the bot. All relevant information should already
exist in the database. exist in the database.
+25 -9
View File
@@ -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
)
+1 -1
View File
@@ -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
+4 -2
View File
@@ -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("🎂")
View File
+1 -3
View File
@@ -53,10 +53,8 @@ def get_election_cycle_name(config: DakinyConfig) -> str:
Returns: Returns:
str: the name of the election cycle str: the name of the election cycle
""" """
cycle = get_current_election_cycle(config)
current_cycle = config.election_cycles[cycle]
return f"vote-{get_datetime(current_cycle.term_start).year}-{current_cycle.name}" return f"vote-{get_cycle_name(config)}"
def get_cycle_name(config: DakinyConfig) -> str: def get_cycle_name(config: DakinyConfig) -> str: