Fix ruff smells in classes dir and config.py.
This commit is contained in:
+19
-26
@@ -1,9 +1,8 @@
|
||||
"""
|
||||
Contains the election cycle class
|
||||
"""
|
||||
"""Contains the election cycle class."""
|
||||
|
||||
import collections
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from pathlib import Path
|
||||
|
||||
import nextcord
|
||||
from classes.nominate_highcouncil_views import NominateHighCouncilView
|
||||
@@ -29,9 +28,13 @@ from utils import (
|
||||
get_election_name,
|
||||
)
|
||||
|
||||
REQUIRED_VOTES_TO_BE_ELECTED = 3
|
||||
|
||||
|
||||
class ElectionCycle:
|
||||
"""
|
||||
ElectionCycle class.
|
||||
|
||||
This class represents all the dates required for an election cycle along with all the functions needed to operate
|
||||
the cycle.
|
||||
"""
|
||||
@@ -67,7 +70,7 @@ class ElectionCycle:
|
||||
list[str]: A list of message contents in the correct order. Must be a string because the message is too
|
||||
long.
|
||||
"""
|
||||
with open(f"{TEMPLATES_DIR}/election_announcement.txt", encoding="utf8") as file:
|
||||
with Path(f"{TEMPLATES_DIR}/election_announcement.txt", encoding="utf8").open() as file:
|
||||
message = file.read()
|
||||
|
||||
next_election = get_datetime(
|
||||
@@ -95,7 +98,7 @@ class ElectionCycle:
|
||||
Returns:
|
||||
str: Message to send.
|
||||
"""
|
||||
with open(f"{TEMPLATES_DIR}/highcouncil_election.txt", encoding="utf8") as file:
|
||||
with Path(f"{TEMPLATES_DIR}/highcouncil_election.txt", encoding="utf8").open() as file:
|
||||
message = file.read()
|
||||
|
||||
return message.format(
|
||||
@@ -113,7 +116,7 @@ class ElectionCycle:
|
||||
Returns:
|
||||
str: Message to send.
|
||||
"""
|
||||
with open(f"{TEMPLATES_DIR}/highcouncil_vote.txt", encoding="utf8") as file:
|
||||
with Path(f"{TEMPLATES_DIR}/highcouncil_vote.txt", encoding="utf8").open() as file:
|
||||
message = file.read()
|
||||
|
||||
return message.format(
|
||||
@@ -128,7 +131,7 @@ class ElectionCycle:
|
||||
Returns:
|
||||
str: Message to send
|
||||
"""
|
||||
with open(f"{TEMPLATES_DIR}/vote_start.txt", encoding="utf8") as file:
|
||||
with Path(f"{TEMPLATES_DIR}/vote_start.txt", encoding="utf8").open() as file:
|
||||
message = file.read()
|
||||
vote_end: datetime = get_datetime(self.config.election_cycles[self.cycle].voting_end)
|
||||
|
||||
@@ -139,9 +142,7 @@ class ElectionCycle:
|
||||
)
|
||||
|
||||
async def check_date(self) -> None:
|
||||
"""
|
||||
Function checks current date to see if something needs to be run.
|
||||
"""
|
||||
"""Function checks current date to see if something needs to be run."""
|
||||
today = datetime.now(tz=UTC).date()
|
||||
|
||||
# check all dates if action is needed
|
||||
@@ -159,9 +160,7 @@ class ElectionCycle:
|
||||
await self.term_start_action()
|
||||
|
||||
async def election_start_action(self) -> None:
|
||||
"""
|
||||
Performs required actions for when the election cycle starts.
|
||||
"""
|
||||
"""Performs required actions for when the election cycle starts."""
|
||||
# create new channel for election
|
||||
parent: nextcord.TextChannel = self.guild.get_channel(self.config.params.voting_parent_id)
|
||||
quarter_name: str = get_election_name(self.config)
|
||||
@@ -193,6 +192,8 @@ class ElectionCycle:
|
||||
|
||||
async def voting_start_action(self) -> None:
|
||||
"""
|
||||
Actions performed when starting a vote.
|
||||
|
||||
Sends message informing members that voting has started.
|
||||
Removes write permission from the general clan member role.
|
||||
"""
|
||||
@@ -217,9 +218,7 @@ class ElectionCycle:
|
||||
await nominate_msg.edit(view=None)
|
||||
|
||||
async def voting_end_action(self) -> None:
|
||||
"""
|
||||
Performs required actions for when voting time has ended.
|
||||
"""
|
||||
"""Performs required actions for when voting time has ended."""
|
||||
message = self.build_highcouncil_election_announce()
|
||||
council_elect_role: nextcord.Role = self.guild.get_role(self.config.params.clan_council_elect_role_id)
|
||||
election_thread: nextcord.Thread = self.guild.get_thread(self.get_election_info().ThreadId)
|
||||
@@ -250,7 +249,7 @@ class ElectionCycle:
|
||||
vote_count = collections.Counter(session.scalars(stmt))
|
||||
|
||||
for user_id, votes in vote_count.items():
|
||||
if votes >= 3:
|
||||
if votes >= REQUIRED_VOTES_TO_BE_ELECTED:
|
||||
stmt = (
|
||||
select(CouncilMembers)
|
||||
.where(CouncilMembers.ElectionCycle == election_name)
|
||||
@@ -268,9 +267,7 @@ class ElectionCycle:
|
||||
)
|
||||
|
||||
async def highcouncil_election_start_action(self) -> None:
|
||||
"""
|
||||
Performs required actions for when the highcouncil is elected.
|
||||
"""
|
||||
"""Performs required actions for when the highcouncil is elected."""
|
||||
message = self.build_highcouncil_vote_start()
|
||||
election_thread: nextcord.Thread = self.guild.get_thread(self.get_election_info().ThreadId)
|
||||
await election_thread.send(message)
|
||||
@@ -292,9 +289,7 @@ class ElectionCycle:
|
||||
await nomination_msg.edit(view=None)
|
||||
|
||||
async def term_start_action(self) -> None:
|
||||
"""
|
||||
Marks the election as over.
|
||||
"""
|
||||
"""Marks the election as over."""
|
||||
self.election_over = True
|
||||
|
||||
elect_role: nextcord.Role = self.guild.get_role(self.config.params.clan_council_elect_role_id)
|
||||
@@ -394,9 +389,7 @@ class ElectionCycle:
|
||||
return session.scalar(stmt)
|
||||
|
||||
async def election_reminder(self) -> None:
|
||||
"""
|
||||
Sends a message to general chat reminder clan about election.
|
||||
"""
|
||||
"""Sends a message to general chat reminder clan about election."""
|
||||
general: nextcord.TextChannel = self.guild.get_channel(self.config.params.general_channel_id)
|
||||
|
||||
message = f"Reminder to <@&{self.config.params.clan_member_role_id}>! Clan elections are happening! Head over "
|
||||
|
||||
Reference in New Issue
Block a user