Pass VoteType str instead of manual one in VoteSelect.
build_develop / build (push) Successful in 1m24s

This commit is contained in:
2024-05-19 11:29:04 -04:00
parent 426f009ca7
commit dbd2863aab
2 changed files with 11 additions and 15 deletions
+1 -1
View File
@@ -435,7 +435,7 @@ class ElectionCycle:
await vote_msg.edit(view=None) await vote_msg.edit(view=None)
highcouncil_msg: str = ( highcouncil_msg: str = (
f"Congratulations for our high council members!\n Clan Leader: <@{cl_winner}>\n" f"Congratulations for our high council members!\nClan Leader: <@{cl_winner}>\n"
) )
highcouncil_msg += f"Discord Manager: <@{dm_winner}>" highcouncil_msg += f"Discord Manager: <@{dm_winner}>"
await election_thread.send(highcouncil_msg) await election_thread.send(highcouncil_msg)
+10 -14
View File
@@ -34,16 +34,6 @@ class VoteSelect(nextcord.ui.StringSelect):
self.election_type = election_type self.election_type = election_type
async def callback(self, interaction: Interaction): async def callback(self, interaction: Interaction):
# decide on election type
match self.election_type:
case "cl":
election_type: str = VoteType.CLANLEADER
case "dm":
election_type: str = VoteType.DISCORDMANAGER
case _:
# should never happen
raise ValueError('election type was not "cl" or "dm"')
election_name: str = get_election_name(self.config) election_name: str = get_election_name(self.config)
with Session(engine) as session: with Session(engine) as session:
stmt = select(ElectionInformation.HighCouncilVoteMsgId).where( stmt = select(ElectionInformation.HighCouncilVoteMsgId).where(
@@ -60,7 +50,7 @@ class VoteSelect(nextcord.ui.StringSelect):
ElectionCycle=election_name, ElectionCycle=election_name,
VoterId=interaction.user.id, VoterId=interaction.user.id,
VotedForId=voted_for, VotedForId=voted_for,
Type=election_type, Type=self.election_type,
) )
try: try:
@@ -74,7 +64,7 @@ class VoteSelect(nextcord.ui.StringSelect):
update(Votes) update(Votes)
.where(Votes.ElectionCycle == election_name) .where(Votes.ElectionCycle == election_name)
.where(Votes.VoterId == interaction.user.id) .where(Votes.VoterId == interaction.user.id)
.where(Votes.Type == election_type) .where(Votes.Type == self.election_type)
.values(VotedForId=voted_for) .values(VotedForId=voted_for)
) )
session.execute(stmt) session.execute(stmt)
@@ -173,7 +163,9 @@ class VoteHighcouncilView(nextcord.ui.View):
view = nextcord.ui.View() view = nextcord.ui.View()
view.add_item( view.add_item(
VoteSelect(options=options, config=self.config, election_type="cl") VoteSelect(
options=options, config=self.config, election_type=VoteType.CLANLEADER
)
) )
await interaction.response.send_message( await interaction.response.send_message(
@@ -251,7 +243,11 @@ class VoteHighcouncilView(nextcord.ui.View):
view = nextcord.ui.View() view = nextcord.ui.View()
view.add_item( view.add_item(
VoteSelect(options=options, config=self.config, election_type="dm") VoteSelect(
options=options,
config=self.config,
election_type=VoteType.DISCORDMANAGER,
)
) )
await interaction.response.send_message( await interaction.response.send_message(