Fix lint errors in voting_views.

This commit is contained in:
2024-05-22 15:40:50 -04:00
parent af37ce6518
commit 02c313aee5
2 changed files with 31 additions and 23 deletions
+7
View File
@@ -0,0 +1,7 @@
[tool.ruff]
# Extend the `pyproject.toml` file in the parent directory...
extend = "../pyproject.toml"
[tool.ruff.lint]
# ignore implicit-namespace-package in this directory.
ignore = ["INP001"]
+24 -23
View File
@@ -1,14 +1,6 @@
"""
Contains various views to be used while voting. Controls the logic when performing the vote.
"""
"""Contains various views to be used while voting. Controls the logic when performing the vote."""
import nextcord
from nextcord import SelectOption
from nextcord.interactions import Interaction
from sqlalchemy import exc, select, update
from sqlalchemy.orm import Session
from config import DakinyConfig
from database_setup.sql_data_classes import (
CouncilMembers,
@@ -16,10 +8,16 @@ from database_setup.sql_data_classes import (
Votes,
engine,
)
from nextcord import SelectOption
from nextcord.interactions import Interaction
from sqlalchemy import exc, select, update
from sqlalchemy.orm import Session
from utils import VoteType, build_votes_str, get_election_name
class VoteSelect(nextcord.ui.StringSelect):
"""Vote view string select."""
def __init__(self, options: list["SelectOption"], config: DakinyConfig) -> None:
super().__init__(
placeholder="Choose 1",
@@ -29,7 +27,16 @@ class VoteSelect(nextcord.ui.StringSelect):
)
self.config = config
async def callback(self, interaction: Interaction):
async def callback(self, interaction: Interaction) -> None:
"""
Callback override for the StringSelect.
Submits the vote to database if a user is selected. Handles adding vs editing a vote. Returns message
informing user that vote has been recorded.
Args:
interaction (Interaction): Interaction with this callback.
"""
election_name = get_election_name(self.config)
with Session(engine) as session:
stmt = select(ElectionInformation.CouncilVoteMsgId).where(
@@ -37,10 +44,7 @@ class VoteSelect(nextcord.ui.StringSelect):
)
vote_msg_id = session.scalar(stmt)
if self.values[0] == "Abstain":
voted_for = None
else:
voted_for = int(self.values[0])
voted_for = None if self.values[0] == "Abstain" else int(self.values[0])
new_vote = Votes(
ElectionCycle=election_name,
@@ -69,18 +73,13 @@ class VoteSelect(nextcord.ui.StringSelect):
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:
msg = f"You have voted for <@{voted_for}>"
else:
msg = "You have abstained from voting."
msg = f"You have voted for <@{voted_for}>" if voted_for is not None else "You have abstained from voting."
await interaction.edit(content=msg, view=None)
class VoteView(nextcord.ui.View):
"""
The button to press to start your nomination.
"""
"""The button to press to start your nomination."""
def __init__(self, config: DakinyConfig, guild: nextcord.Guild):
super().__init__(timeout=None)
@@ -88,9 +87,11 @@ class VoteView(nextcord.ui.View):
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:
async def vote(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
"""
Enforces only members vote. Gets election cycle, creates voting options (checking if user has voted already),
Enforces only members vote.
Gets election cycle, creates voting options (checking if user has voted already),
then sends the voting view.
Args: