Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c8e8c4d5a | ||
|
|
0b5423a62b | ||
|
|
dbbb7c1c62 |
@@ -224,7 +224,7 @@ class ElectionCycle:
|
|||||||
vote_count = collections.Counter(session.scalars(stmt))
|
vote_count = collections.Counter(session.scalars(stmt))
|
||||||
|
|
||||||
for user_id, votes in vote_count.items():
|
for user_id, votes in vote_count.items():
|
||||||
if votes >= 3:
|
if votes >= 2:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CouncilMembers)
|
select(CouncilMembers)
|
||||||
.where(CouncilMembers.ElectionCycle == election_name)
|
.where(CouncilMembers.ElectionCycle == election_name)
|
||||||
|
|||||||
+14
-41
@@ -7,16 +7,11 @@ from typing import List
|
|||||||
import nextcord
|
import nextcord
|
||||||
from nextcord import SelectOption
|
from nextcord import SelectOption
|
||||||
from nextcord.interactions import Interaction
|
from nextcord.interactions import Interaction
|
||||||
from sqlalchemy import exc, select, update
|
from sqlalchemy import exc, select
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from config import DakinyConfig
|
from config import DakinyConfig
|
||||||
from database_setup.sql_data_classes import (
|
from database_setup.sql_data_classes import CouncilMembers, ElectionInformation, Votes, engine
|
||||||
CouncilMembers,
|
|
||||||
ElectionInformation,
|
|
||||||
Votes,
|
|
||||||
engine,
|
|
||||||
)
|
|
||||||
from utils import build_votes_str, get_election_cycle_name
|
from utils import build_votes_str, get_election_cycle_name
|
||||||
|
|
||||||
|
|
||||||
@@ -43,11 +38,7 @@ class VoteSelect(nextcord.ui.StringSelect):
|
|||||||
else:
|
else:
|
||||||
voted_for = int(self.values[0])
|
voted_for = int(self.values[0])
|
||||||
|
|
||||||
new_vote = Votes(
|
new_vote = Votes(ElectionCycle=election_name, VoterId=interaction.user.id, VotedForId=voted_for)
|
||||||
ElectionCycle=election_name,
|
|
||||||
VoterId=interaction.user.id,
|
|
||||||
VotedForId=voted_for,
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
session.add(new_vote)
|
session.add(new_vote)
|
||||||
@@ -56,18 +47,16 @@ class VoteSelect(nextcord.ui.StringSelect):
|
|||||||
except exc.IntegrityError:
|
except exc.IntegrityError:
|
||||||
session.rollback()
|
session.rollback()
|
||||||
stmt = (
|
stmt = (
|
||||||
update(Votes)
|
select(Votes)
|
||||||
.where(Votes.ElectionCycle == election_name)
|
.where(Votes.ElectionCycle == election_name)
|
||||||
.where(Votes.VoterId == interaction.user.id)
|
.where(Votes.VoterId == interaction.user.id)
|
||||||
.values(VotedForId=voted_for)
|
|
||||||
)
|
)
|
||||||
session.execute(stmt)
|
vote = session.scalar(stmt)
|
||||||
|
vote.VotedForId = voted_for
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
vote_message_str = build_votes_str(self.config)
|
vote_message_str = build_votes_str(self.config)
|
||||||
vote_msg: nextcord.Message = await interaction.channel.fetch_message(
|
vote_msg: nextcord.Message = await interaction.channel.fetch_message(vote_msg_id)
|
||||||
vote_msg_id
|
|
||||||
)
|
|
||||||
await vote_msg.edit(content=vote_message_str)
|
await vote_msg.edit(content=vote_message_str)
|
||||||
|
|
||||||
if voted_for is not None:
|
if voted_for is not None:
|
||||||
@@ -88,15 +77,10 @@ class VoteView(nextcord.ui.View):
|
|||||||
self.config = config
|
self.config = config
|
||||||
self.guild = guild
|
self.guild = guild
|
||||||
|
|
||||||
@nextcord.ui.button(
|
@nextcord.ui.button(label="Vote", style=nextcord.ButtonStyle.primary, custom_id="vote")
|
||||||
label="Vote", style=nextcord.ButtonStyle.primary, custom_id="vote"
|
async def vote(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None:
|
||||||
)
|
|
||||||
async def vote(
|
|
||||||
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
|
||||||
) -> None:
|
|
||||||
"""
|
"""
|
||||||
Enforces only members vote. Gets election cycle, creates voting options (checking if user has voted already),
|
TODO
|
||||||
then sends the voting view.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
button (nextcord.ui.Button): Unused. idk why its needed in the decorator
|
button (nextcord.ui.Button): Unused. idk why its needed in the decorator
|
||||||
@@ -104,13 +88,9 @@ class VoteView(nextcord.ui.View):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# enforce members only
|
# enforce members only
|
||||||
if (
|
if self.guild.get_role(self.config.params.clan_member_role_id) not in interaction.user.roles:
|
||||||
self.guild.get_role(self.config.params.clan_member_role_id)
|
|
||||||
not in interaction.user.roles
|
|
||||||
):
|
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
f"You must have the <@&{self.config.params.clan_member_role_id}> role to vote.",
|
f"You must have the <@&{self.config.params.clan_member_role_id}> role to vote.", ephemeral=True
|
||||||
ephemeral=True,
|
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -124,9 +104,7 @@ class VoteView(nextcord.ui.View):
|
|||||||
)
|
)
|
||||||
voted_for = session.scalar(stmt)
|
voted_for = session.scalar(stmt)
|
||||||
|
|
||||||
stmt = select(CouncilMembers.MemberId).where(
|
stmt = select(CouncilMembers.MemberId).where(CouncilMembers.ElectionCycle == election)
|
||||||
CouncilMembers.ElectionCycle == election
|
|
||||||
)
|
|
||||||
|
|
||||||
options = [
|
options = [
|
||||||
SelectOption(
|
SelectOption(
|
||||||
@@ -137,12 +115,7 @@ class VoteView(nextcord.ui.View):
|
|||||||
)
|
)
|
||||||
for nominee in session.scalars(stmt)
|
for nominee in session.scalars(stmt)
|
||||||
]
|
]
|
||||||
options.append(
|
options.append(SelectOption(label="Abstain ☑️" if voted_for is None else "Abstain", value="Abstain"))
|
||||||
SelectOption(
|
|
||||||
label="Abstain ☑️" if voted_for is None else "Abstain",
|
|
||||||
value="Abstain",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
view = nextcord.ui.View()
|
view = nextcord.ui.View()
|
||||||
view.add_item(VoteSelect(options=options, config=self.config))
|
view.add_item(VoteSelect(options=options, config=self.config))
|
||||||
|
|||||||
Reference in New Issue
Block a user