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
+10 -14
View File
@@ -34,16 +34,6 @@ class VoteSelect(nextcord.ui.StringSelect):
self.election_type = election_type
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)
with Session(engine) as session:
stmt = select(ElectionInformation.HighCouncilVoteMsgId).where(
@@ -60,7 +50,7 @@ class VoteSelect(nextcord.ui.StringSelect):
ElectionCycle=election_name,
VoterId=interaction.user.id,
VotedForId=voted_for,
Type=election_type,
Type=self.election_type,
)
try:
@@ -74,7 +64,7 @@ class VoteSelect(nextcord.ui.StringSelect):
update(Votes)
.where(Votes.ElectionCycle == election_name)
.where(Votes.VoterId == interaction.user.id)
.where(Votes.Type == election_type)
.where(Votes.Type == self.election_type)
.values(VotedForId=voted_for)
)
session.execute(stmt)
@@ -173,7 +163,9 @@ class VoteHighcouncilView(nextcord.ui.View):
view = nextcord.ui.View()
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(
@@ -251,7 +243,11 @@ class VoteHighcouncilView(nextcord.ui.View):
view = nextcord.ui.View()
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(