Pass VoteType str instead of manual one in VoteSelect.
build_develop / build (push) Successful in 1m24s
build_develop / build (push) Successful in 1m24s
This commit is contained in:
@@ -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(
|
||||||
|
|||||||
Reference in New Issue
Block a user