Change ElectionCycle class to Election. Change ElectionCycle column in database to ElectionName. Update some variables for clarification.

This commit is contained in:
2024-09-03 11:24:28 -04:00
parent 306e0d687a
commit eb5102578d
10 changed files with 71 additions and 79 deletions
+8 -8
View File
@@ -5,7 +5,7 @@ from typing import TYPE_CHECKING
import nextcord
from nextcord.ext import application_checks, commands
from classes.election_cycle import ElectionCycle
from classes.election import Election
from utils import GUILDS, get_current_election_cycle
if TYPE_CHECKING:
@@ -45,7 +45,7 @@ class TestCog(commands.Cog, name="Test commands."):
interaction (nextcord.Interaction): Interaction with the message.
"""
config: DakinyConfig = self.bot.config
cycle = ElectionCycle(
cycle = Election(
get_current_election_cycle(config),
config,
self.bot.get_guild(config.params.guild_id),
@@ -63,7 +63,7 @@ class TestCog(commands.Cog, name="Test commands."):
interaction (nextcord.Interaction): Interaction with the message.
"""
config: DakinyConfig = self.bot.config
cycle = ElectionCycle(
cycle = Election(
get_current_election_cycle(config),
config,
self.bot.get_guild(config.params.guild_id),
@@ -81,7 +81,7 @@ class TestCog(commands.Cog, name="Test commands."):
interaction (nextcord.Interaction): Interaction with the message.
"""
config: DakinyConfig = self.bot.config
cycle = ElectionCycle(
cycle = Election(
get_current_election_cycle(config),
config,
self.bot.get_guild(config.params.guild_id),
@@ -99,7 +99,7 @@ class TestCog(commands.Cog, name="Test commands."):
interaction (nextcord.Interaction): Interaction with the message.
"""
config: DakinyConfig = self.bot.config
cycle = ElectionCycle(
cycle = Election(
get_current_election_cycle(config),
config,
self.bot.get_guild(config.params.guild_id),
@@ -117,7 +117,7 @@ class TestCog(commands.Cog, name="Test commands."):
interaction (nextcord.Interaction): Interaction with the message.
"""
config: DakinyConfig = self.bot.config
cycle = ElectionCycle(
cycle = Election(
get_current_election_cycle(config),
config,
self.bot.get_guild(config.params.guild_id),
@@ -135,7 +135,7 @@ class TestCog(commands.Cog, name="Test commands."):
interaction (nextcord.Interaction): Interaction with the message.
"""
config: DakinyConfig = self.bot.config
cycle = ElectionCycle(
cycle = Election(
get_current_election_cycle(config),
config,
self.bot.get_guild(config.params.guild_id),
@@ -153,7 +153,7 @@ class TestCog(commands.Cog, name="Test commands."):
interaction (nextcord.Interaction): Interaction with the message.
"""
config: DakinyConfig = self.bot.config
cycle = ElectionCycle(
cycle = Election(
get_current_election_cycle(config),
config,
self.bot.get_guild(config.params.guild_id),
+2 -2
View File
@@ -149,7 +149,7 @@ class ViewCog(commands.Cog, name="View Commands"):
election_name (str): Is SlashOption. The name of the election to view votes for.
election_type(str): Is SlashOption. The type of election to search for. Choice from StrEnum VoteType.
"""
stmt = select(Votes).where(Votes.ElectionCycle == election_name).where(Votes.Type == election_type)
stmt = select(Votes).where(Votes.ElectionName == election_name).where(Votes.Type == election_type)
with Session(engine) as session:
# Check if election exists.
@@ -178,7 +178,7 @@ class ViewCog(commands.Cog, name="View Commands"):
election_name (str): String to run autocomplete on.
"""
with Session(engine) as session:
stmt = select(Votes.ElectionCycle).distinct()
stmt = select(Votes.ElectionName).distinct()
elections = session.scalars(stmt)
# if empty compare string
+6 -6
View File
@@ -9,7 +9,7 @@ from pytz import timezone
from sqlalchemy import select
from sqlalchemy.orm import Session
from classes.election_cycle import ElectionCycle
from classes.election import Election
from database_setup.sql_data_classes import UserBirthday, engine
from main import birthday_list
from utils import get_current_election_cycle
@@ -43,7 +43,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
election is over to delete the current election object.
"""
if self.current_election is None:
self.current_election = self.get_election_cycle()
self.current_election = self.get_election()
if self.current_election is not None:
await self.current_election.check_date()
@@ -65,16 +65,16 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
await self.bot.wait_until_ready()
# Bot needs to know guilds to get the current cycle.
self.current_election = self.get_election_cycle()
self.current_election = self.get_election()
def get_election_cycle(self) -> ElectionCycle:
def get_election(self) -> Election:
"""
Creates an object for the current election cycle if one is active.
An election is considered active between the election start and the term start.
Returns:
ElectionCycle: Current election cycle, None if there is no election happening.
Election: Current election cycle, None if there is no election happening.
"""
config: DakinyConfig = self.bot.config
cycle = get_current_election_cycle(config)
@@ -83,7 +83,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
if cycle is None:
return None
return ElectionCycle(cycle, config, self.bot.get_guild(config.params.guild_id))
return Election(cycle, config, self.bot.get_guild(config.params.guild_id))
def update_birthdays(self) -> None:
"""Goes through database to collect all birthdays that are today. Adds user's id to birthday list."""