Compare commits

..
Author SHA1 Message Date
imcompiling 4c1f41c4c8 Correct date being used for getting the election cycle name.
build_develop / build (push) Successful in 1m39s
2023-12-28 19:28:30 -05:00
6 changed files with 24 additions and 54 deletions
+2 -3
View File
@@ -239,8 +239,7 @@ class ElectionCycle:
)
await election_thread.send(message)
vote_msg = await election_thread.send(
build_votes_str(self.config, self.guild),
view=VoteView(self.config, self.guild),
build_votes_str(self.config), view=VoteView(self.config, self.guild)
)
with Session(engine) as session:
@@ -325,7 +324,7 @@ class ElectionCycle:
)
await election_thread.send(message)
vote_msg = await election_thread.send(
build_highcouncil_votes_str(self.config, self.guild),
build_highcouncil_votes_str(self.config),
view=VoteHighcouncilView(self.config, self.guild),
)
+3 -9
View File
@@ -82,7 +82,7 @@ class VoteSelect(nextcord.ui.StringSelect):
session.execute(stmt)
session.commit()
vote_message_str = build_highcouncil_votes_str(self.config, interaction.guild)
vote_message_str = build_highcouncil_votes_str(self.config)
vote_msg: nextcord.Message = await interaction.channel.fetch_message(
vote_msg_id
)
@@ -159,10 +159,7 @@ class VoteHighcouncilView(nextcord.ui.View):
else f"{self.guild.get_member(nominee).display_name}",
value=str(nominee),
)
for nominee in sorted(
session.scalars(stmt),
key=lambda nominee: self.guild.get_member(nominee).display_name,
)
for nominee in session.scalars(stmt)
]
options.append(
SelectOption(
@@ -235,10 +232,7 @@ class VoteHighcouncilView(nextcord.ui.View):
else f"{self.guild.get_member(nominee).display_name}",
value=str(nominee),
)
for nominee in sorted(
session.scalars(stmt),
key=lambda nominee: self.guild.get_member(nominee).display_name,
)
for nominee in session.scalars(stmt)
]
options.append(
SelectOption(
+2 -5
View File
@@ -64,7 +64,7 @@ class VoteSelect(nextcord.ui.StringSelect):
session.execute(stmt)
session.commit()
vote_message_str = build_votes_str(self.config, interaction.guild)
vote_message_str = build_votes_str(self.config)
vote_msg: nextcord.Message = await interaction.channel.fetch_message(
vote_msg_id
)
@@ -135,10 +135,7 @@ class VoteView(nextcord.ui.View):
else f"{self.guild.get_member(nominee).display_name}",
value=str(nominee),
)
for nominee in sorted(
session.scalars(stmt),
key=lambda nominee: self.guild.get_member(nominee).display_name,
)
for nominee in session.scalars(stmt)
]
options.append(
SelectOption(
+7 -2
View File
@@ -7,7 +7,12 @@ from nextcord.ext import commands
from sqlalchemy import select
from sqlalchemy.orm import Session
from database_setup.sql_data_classes import Presences, Votes, engine
from database_setup.sql_data_classes import (
ElectionInformation,
Presences,
Votes,
engine,
)
class ViewCog(commands.Cog, name="View Commands"):
@@ -116,7 +121,7 @@ class ViewCog(commands.Cog, name="View Commands"):
"""
with Session(engine) as session:
stmt = select(Votes.ElectionCycle).distinct()
stmt = select(ElectionInformation.ElectionCycle)
elections = session.scalars(stmt)
# if empty compare string
+2 -10
View File
@@ -79,10 +79,6 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
config: DakinyConfig = self.bot.config
cycle = get_current_cycle(config)
# prevent exception from using cycle as an Int in an array
if cycle is None:
return None
return ElectionCycle(cycle, config, self.bot.get_guild(config.params.guild_id))
def update_birthdays(self) -> None:
@@ -111,14 +107,10 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
today = datetime.today()
guild: nextcord.Guild = self.bot.get_guild(self.bot.config.params.guild_id)
announce_channel: nextcord.TextChannel = guild.get_channel(
self.bot.config.params.general_channel_id
)
announce_channel: nextcord.TextChannel = guild.get_channel(self.bot.config.params.general_channel_id)
cakedays: list[nextcord.Member] = [
human
for human in guild.humans
if human.joined_at.month == today.month and human.joined_at.day == today.day
human for human in guild.humans if human.joined_at.month == today.month and human.joined_at.day == today.day
]
for member in cakedays:
+8 -25
View File
@@ -4,7 +4,6 @@ File contains util functions.
from datetime import datetime
import nextcord
from sqlalchemy import select
from sqlalchemy.orm import Session
@@ -32,9 +31,6 @@ def get_datetime(day: str) -> datetime:
if datetime.today().month == 12 and month < 12:
year += 1
if datetime.today().month == 1 and month > 1:
year -= 1
return datetime(year, month, day)
@@ -51,9 +47,7 @@ def get_election_cycle_name(config: DakinyConfig) -> str:
cycle = get_current_cycle(config)
current_cycle = config.election_cycles[cycle]
return (
f"vote-{get_datetime(current_cycle.election_start).year}-{current_cycle.name}"
)
return f"vote-{get_datetime(current_cycle.term_start).year}-{current_cycle.name}"
def get_dm_election_name(config: DakinyConfig) -> str:
@@ -92,7 +86,7 @@ def get_current_cycle(config: DakinyConfig) -> int:
config (DakinyConfig): Config object to use
Returns:
int: cycle index for active election. None for no active cycle
int: cycle index for active election. -1 for no active cycle
"""
today = datetime.today()
@@ -104,16 +98,15 @@ def get_current_cycle(config: DakinyConfig) -> int:
):
return cycle
return None
return -1
def build_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str:
def build_votes_str(config: DakinyConfig) -> str:
"""
Creates a string that contains all nominees and their votes to be sent as a discord message.
Args:
config (DakinyConfig): Daking config object
guild (nextcord.Guild): The guild object. Used to get display names for sorting.
Returns:
str: String that contains all nominees and their votes.
@@ -126,10 +119,7 @@ def build_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str:
CouncilMembers.ElectionCycle == get_election_cycle_name(config)
)
for nominee in sorted(
session.scalars(stmt),
key=lambda nominee: guild.get_member(nominee.MemberId).display_name,
):
for nominee in session.scalars(stmt):
votes[nominee.MemberId] = 0
stmt = select(Votes).where(
@@ -146,7 +136,7 @@ def build_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str:
return votes_str
def build_highcouncil_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str:
def build_highcouncil_votes_str(config: DakinyConfig) -> str:
"""
Creates a string that contains all high council nominees and their votes to be sent as a discord message.
@@ -155,7 +145,6 @@ def build_highcouncil_votes_str(config: DakinyConfig, guild: nextcord.Guild) ->
Returns:
str: String that contains all nominees and their votes.
guild (nextcord.Guild): The guild object. Used to get display names for sorting.
"""
cl_votes: dict[int, int] = {}
@@ -168,10 +157,7 @@ def build_highcouncil_votes_str(config: DakinyConfig, guild: nextcord.Guild) ->
.filter(CouncilMembers.ClanLeaderSpeechId.is_not(None))
)
for nominee in sorted(
session.scalars(stmt),
key=lambda nominee: guild.get_member(nominee.MemberId).display_name,
):
for nominee in session.scalars(stmt):
cl_votes[nominee.MemberId] = 0
stmt = select(Votes).where(Votes.ElectionCycle == get_cl_election_name(config))
@@ -186,10 +172,7 @@ def build_highcouncil_votes_str(config: DakinyConfig, guild: nextcord.Guild) ->
.filter(CouncilMembers.DiscordManagerSpeechId.is_not(None))
)
for nominee in sorted(
session.scalars(stmt),
key=lambda nominee: guild.get_member(nominee.MemberId).display_name,
):
for nominee in session.scalars(stmt):
dm_votes[nominee.MemberId] = 0
stmt = select(Votes).where(Votes.ElectionCycle == get_dm_election_name(config))