Compare commits

...
Author SHA1 Message Date
imcompiling a8697b0187 Bandaid fix so HC votes can be viewed.
build_latest / build (push) Successful in 1m39s
build_release / build (push) Successful in 48s
build_develop / build (push) Successful in 52s
2024-01-09 20:04:49 -05:00
imcompiling 8c8dc2c638 Merge branch '44-sort-candidates'
build_latest / build (push) Successful in 47s
build_release / build (push) Successful in 51s
2024-01-03 21:47:59 -05:00
imcompiling 54933b427e Sort nominees in voting views by display name.
build_develop / build (push) Successful in 1m27s
2024-01-03 21:46:54 -05:00
imcompiling 5d05006a23 Prevent unneeded exceptions.
build_latest / build (push) Successful in 1m23s
build_develop / build (push) Successful in 1m7s
2024-01-01 14:11:07 -05:00
imcompiling 2596b9fa7b Merge branch '47-incorrect-election-cycle'
build_latest / build (push) Successful in 44s
build_release / build (push) Successful in 45s
2024-01-01 13:32:41 -05:00
6 changed files with 46 additions and 21 deletions
+3 -2
View File
@@ -239,7 +239,8 @@ class ElectionCycle:
)
await election_thread.send(message)
vote_msg = await election_thread.send(
build_votes_str(self.config), view=VoteView(self.config, self.guild)
build_votes_str(self.config, self.guild),
view=VoteView(self.config, self.guild),
)
with Session(engine) as session:
@@ -324,7 +325,7 @@ class ElectionCycle:
)
await election_thread.send(message)
vote_msg = await election_thread.send(
build_highcouncil_votes_str(self.config),
build_highcouncil_votes_str(self.config, self.guild),
view=VoteHighcouncilView(self.config, self.guild),
)
+9 -3
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)
vote_message_str = build_highcouncil_votes_str(self.config, interaction.guild)
vote_msg: nextcord.Message = await interaction.channel.fetch_message(
vote_msg_id
)
@@ -159,7 +159,10 @@ class VoteHighcouncilView(nextcord.ui.View):
else f"{self.guild.get_member(nominee).display_name}",
value=str(nominee),
)
for nominee in session.scalars(stmt)
for nominee in sorted(
session.scalars(stmt),
key=lambda nominee: self.guild.get_member(nominee).display_name,
)
]
options.append(
SelectOption(
@@ -232,7 +235,10 @@ class VoteHighcouncilView(nextcord.ui.View):
else f"{self.guild.get_member(nominee).display_name}",
value=str(nominee),
)
for nominee in session.scalars(stmt)
for nominee in sorted(
session.scalars(stmt),
key=lambda nominee: self.guild.get_member(nominee).display_name,
)
]
options.append(
SelectOption(
+5 -2
View File
@@ -64,7 +64,7 @@ class VoteSelect(nextcord.ui.StringSelect):
session.execute(stmt)
session.commit()
vote_message_str = build_votes_str(self.config)
vote_message_str = build_votes_str(self.config, interaction.guild)
vote_msg: nextcord.Message = await interaction.channel.fetch_message(
vote_msg_id
)
@@ -135,7 +135,10 @@ class VoteView(nextcord.ui.View):
else f"{self.guild.get_member(nominee).display_name}",
value=str(nominee),
)
for nominee in session.scalars(stmt)
for nominee in sorted(
session.scalars(stmt),
key=lambda nominee: self.guild.get_member(nominee).display_name,
)
]
options.append(
SelectOption(
+2 -7
View File
@@ -7,12 +7,7 @@ from nextcord.ext import commands
from sqlalchemy import select
from sqlalchemy.orm import Session
from database_setup.sql_data_classes import (
ElectionInformation,
Presences,
Votes,
engine,
)
from database_setup.sql_data_classes import Presences, Votes, engine
class ViewCog(commands.Cog, name="View Commands"):
@@ -121,7 +116,7 @@ class ViewCog(commands.Cog, name="View Commands"):
"""
with Session(engine) as session:
stmt = select(ElectionInformation.ElectionCycle)
stmt = select(Votes.ElectionCycle).distinct()
elections = session.scalars(stmt)
# if empty compare string
+10 -2
View File
@@ -79,6 +79,10 @@ 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:
@@ -107,10 +111,14 @@ 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:
+17 -5
View File
@@ -4,6 +4,7 @@ File contains util functions.
from datetime import datetime
import nextcord
from sqlalchemy import select
from sqlalchemy.orm import Session
@@ -106,12 +107,13 @@ def get_current_cycle(config: DakinyConfig) -> int:
return None
def build_votes_str(config: DakinyConfig) -> str:
def build_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> 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.
@@ -124,7 +126,10 @@ def build_votes_str(config: DakinyConfig) -> str:
CouncilMembers.ElectionCycle == get_election_cycle_name(config)
)
for nominee in session.scalars(stmt):
for nominee in sorted(
session.scalars(stmt),
key=lambda nominee: guild.get_member(nominee.MemberId).display_name,
):
votes[nominee.MemberId] = 0
stmt = select(Votes).where(
@@ -141,7 +146,7 @@ def build_votes_str(config: DakinyConfig) -> str:
return votes_str
def build_highcouncil_votes_str(config: DakinyConfig) -> str:
def build_highcouncil_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str:
"""
Creates a string that contains all high council nominees and their votes to be sent as a discord message.
@@ -150,6 +155,7 @@ def build_highcouncil_votes_str(config: DakinyConfig) -> str:
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] = {}
@@ -162,7 +168,10 @@ def build_highcouncil_votes_str(config: DakinyConfig) -> str:
.filter(CouncilMembers.ClanLeaderSpeechId.is_not(None))
)
for nominee in session.scalars(stmt):
for nominee in sorted(
session.scalars(stmt),
key=lambda nominee: guild.get_member(nominee.MemberId).display_name,
):
cl_votes[nominee.MemberId] = 0
stmt = select(Votes).where(Votes.ElectionCycle == get_cl_election_name(config))
@@ -177,7 +186,10 @@ def build_highcouncil_votes_str(config: DakinyConfig) -> str:
.filter(CouncilMembers.DiscordManagerSpeechId.is_not(None))
)
for nominee in session.scalars(stmt):
for nominee in sorted(
session.scalars(stmt),
key=lambda nominee: guild.get_member(nominee.MemberId).display_name,
):
dm_votes[nominee.MemberId] = 0
stmt = select(Votes).where(Votes.ElectionCycle == get_dm_election_name(config))