diff --git a/classes/voting_views.py b/classes/voting_views.py index 6444554..9c1097f 100644 --- a/classes/voting_views.py +++ b/classes/voting_views.py @@ -11,7 +11,12 @@ from sqlalchemy import exc, select from sqlalchemy.orm import Session from config import DakinyConfig -from database_setup.sql_data_classes import CouncilMembers, ElectionInformation, Votes, engine +from database_setup.sql_data_classes import ( + CouncilMembers, + ElectionInformation, + Votes, + engine, +) from utils import build_votes_str, get_election_cycle_name @@ -38,7 +43,11 @@ class VoteSelect(nextcord.ui.StringSelect): else: voted_for = int(self.values[0]) - new_vote = Votes(ElectionCycle=election_name, VoterId=interaction.user.id, VotedForId=voted_for) + new_vote = Votes( + ElectionCycle=election_name, + VoterId=interaction.user.id, + VotedForId=voted_for, + ) try: session.add(new_vote) @@ -56,7 +65,9 @@ class VoteSelect(nextcord.ui.StringSelect): session.commit() vote_message_str = build_votes_str(self.config) - vote_msg: nextcord.Message = await interaction.channel.fetch_message(vote_msg_id) + vote_msg: nextcord.Message = await interaction.channel.fetch_message( + vote_msg_id + ) await vote_msg.edit(content=vote_message_str) if voted_for is not None: @@ -77,10 +88,15 @@ class VoteView(nextcord.ui.View): self.config = config self.guild = guild - @nextcord.ui.button(label="Vote", style=nextcord.ButtonStyle.primary, custom_id="vote") - async def vote(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: + @nextcord.ui.button( + label="Vote", style=nextcord.ButtonStyle.primary, custom_id="vote" + ) + async def vote( + self, button: nextcord.ui.Button, interaction: nextcord.Interaction + ) -> None: """ - TODO + Enforces only members vote. Gets election cycle, creates voting options (checking if user has voted already), + then sends the voting view. Args: button (nextcord.ui.Button): Unused. idk why its needed in the decorator @@ -88,9 +104,13 @@ class VoteView(nextcord.ui.View): """ # enforce members only - if self.guild.get_role(self.config.params.clan_member_role_id) not in interaction.user.roles: + if ( + self.guild.get_role(self.config.params.clan_member_role_id) + not in interaction.user.roles + ): await interaction.response.send_message( - f"You must have the <@&{self.config.params.clan_member_role_id}> role to vote.", ephemeral=True + f"You must have the <@&{self.config.params.clan_member_role_id}> role to vote.", + ephemeral=True, ) return @@ -104,7 +124,9 @@ class VoteView(nextcord.ui.View): ) voted_for = session.scalar(stmt) - stmt = select(CouncilMembers.MemberId).where(CouncilMembers.ElectionCycle == election) + stmt = select(CouncilMembers.MemberId).where( + CouncilMembers.ElectionCycle == election + ) options = [ SelectOption( @@ -115,7 +137,12 @@ class VoteView(nextcord.ui.View): ) for nominee in session.scalars(stmt) ] - options.append(SelectOption(label="Abstain ☑️" if voted_for is None else "Abstain", value="Abstain")) + options.append( + SelectOption( + label="Abstain ☑️" if voted_for is None else "Abstain", + value="Abstain", + ) + ) view = nextcord.ui.View() view.add_item(VoteSelect(options=options, config=self.config))