Fix ruff smells in classes dir and config.py.

This commit is contained in:
2024-05-22 16:58:27 -04:00
parent e485c119f6
commit 6cd82dfcc4
6 changed files with 81 additions and 88 deletions
+26 -23
View File
@@ -1,14 +1,6 @@
"""
Contains various views to be used while voting for high council. Controls the logic when performing the vote.
"""
"""Contains various views to be used while voting for high council. 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_highcouncil_votes_str, get_election_name
class VoteSelect(nextcord.ui.StringSelect):
"""Vote view string select."""
def __init__(self, options: list["SelectOption"], config: DakinyConfig, election_type: str) -> None:
super().__init__(
placeholder="Choose 1",
@@ -30,7 +28,16 @@ class VoteSelect(nextcord.ui.StringSelect):
self.config = config
self.election_type = election_type
async def callback(self, interaction: Interaction):
async def callback(self, interaction: Interaction) -> None:
"""
Callback override for the StringSelect.
Submits the High Council 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: str = get_election_name(self.config)
with Session(engine) as session:
stmt = select(ElectionInformation.HighCouncilVoteMsgId).where(
@@ -38,10 +45,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,
@@ -71,18 +75,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 VoteHighcouncilView(nextcord.ui.View):
"""
The button to press to start voting for HighCouncil.
"""
"""The button to press to start voting for HighCouncil."""
def __init__(self, config: DakinyConfig, guild: nextcord.Guild):
super().__init__(timeout=None)
@@ -94,8 +93,10 @@ class VoteHighcouncilView(nextcord.ui.View):
style=nextcord.ButtonStyle.primary,
custom_id="vote-cl",
)
async def vote_cl(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None:
async def vote_cl(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
"""
Button to vote for Clan Leader.
Enforces only council elect vote. Gets election cycle, creates voting
options for clan leader (checking if user has voted already),
then sends the voting view.
@@ -164,8 +165,10 @@ class VoteHighcouncilView(nextcord.ui.View):
style=nextcord.ButtonStyle.primary,
custom_id="vote-dm",
)
async def vote_dm(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None:
async def vote_dm(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
"""
Button to vote for Discord Manager.
Enforces only council elect vote. Gets election cycle, creates voting
options for discord manager (checking if user has voted already),
then sends the voting view.