Updated files in classes directory to use new configs. Ensured usages are updated.
This commit is contained in:
+30
-33
@@ -9,7 +9,7 @@ from classes.nominate_highcouncil_views import NominateHighCouncilView
|
||||
from classes.nominate_views import NominateView
|
||||
from classes.voting_highcouncil_views import VoteHighcouncilView
|
||||
from classes.voting_views import VoteView
|
||||
from DakinySettings import DakinySettings
|
||||
from DakinySettings import settings
|
||||
from database_setup.sql_data_classes import (
|
||||
CouncilMembers,
|
||||
ElectionInformation,
|
||||
@@ -39,7 +39,7 @@ class Election:
|
||||
the cycle.
|
||||
"""
|
||||
|
||||
def __init__(self, cycle: int, config: DakinySettings, guild: nextcord.Guild) -> None:
|
||||
def __init__(self, cycle: int, guild: nextcord.Guild) -> None:
|
||||
"""
|
||||
Generates all dates relevant to the election cycle determined by the config and cycle.
|
||||
|
||||
@@ -48,9 +48,8 @@ class Election:
|
||||
config (DakinyConfig): The entire config object.
|
||||
guild (nextcord.Guild): The guild that this election is running in.
|
||||
"""
|
||||
self.config: DakinySettings = config
|
||||
self.cycle = cycle
|
||||
self.election_cycle = self.config.election_cycles[self.cycle]
|
||||
self.election_cycle = settings.election_cycles[self.cycle]
|
||||
self.election_start: datetime = get_datetime(self.election_cycle.election_start)
|
||||
self.term_start: datetime = get_datetime(self.election_cycle.term_start)
|
||||
self.term_end: datetime = get_datetime(self.election_cycle.term_end)
|
||||
@@ -74,12 +73,12 @@ class Election:
|
||||
message = file.read()
|
||||
|
||||
next_election = get_datetime(
|
||||
self.config.election_cycles[(self.cycle + 1) % len(self.config.election_cycles)].election_start
|
||||
settings.election_cycles[(self.cycle + 1) % len(settings.election_cycles)].election_start
|
||||
)
|
||||
|
||||
message = message.format(
|
||||
clan_council_id=self.config.params.clan_council_role_id,
|
||||
high_council_id=self.config.params.high_council_role_id,
|
||||
clan_council_id=settings.role_ids.clan_council,
|
||||
high_council_id=settings.role_ids.high_council,
|
||||
election_start=self.election_start.strftime("%B %d"),
|
||||
term_start=self.term_start.strftime("%B %d"),
|
||||
term_end=self.term_end.strftime("%B %d"),
|
||||
@@ -102,7 +101,7 @@ class Election:
|
||||
message = file.read()
|
||||
|
||||
return message.format(
|
||||
clan_council_elect_role_id=self.config.params.clan_council_elect_role_id,
|
||||
clan_council_elect_role_id=settings.role_ids.clan_council_elect,
|
||||
highcouncil_election_announce=self.highcouncil_election_announce.strftime("%B %d"),
|
||||
highcouncil_election_start=self.highcouncil_election_start.strftime("%B %d"),
|
||||
highcouncil_election_end=self.highcouncil_election_end.strftime("%B %d"),
|
||||
@@ -120,7 +119,7 @@ class Election:
|
||||
message = file.read()
|
||||
|
||||
return message.format(
|
||||
clan_council_elect_role_id=self.config.params.clan_council_elect_role_id,
|
||||
clan_council_elect_role_id=settings.role_ids.clan_council_elect,
|
||||
term_start=self.term_start.strftime("%B %d"),
|
||||
)
|
||||
|
||||
@@ -133,10 +132,10 @@ class Election:
|
||||
"""
|
||||
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)
|
||||
vote_end: datetime = get_datetime(settings.election_cycles[self.cycle].voting_end)
|
||||
|
||||
return message.format(
|
||||
clan_member_id=self.config.params.clan_member_role_id,
|
||||
clan_member_id=settings.role_ids.clan_member,
|
||||
voting_end=vote_end.strftime("%B %d"),
|
||||
voting_end_day=vote_end.strftime("%A"),
|
||||
)
|
||||
@@ -162,8 +161,8 @@ class Election:
|
||||
async def election_start_action(self) -> None:
|
||||
"""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)
|
||||
parent: nextcord.TextChannel = self.guild.get_channel(settings.channel_ids.voting_parent)
|
||||
quarter_name: str = get_election_name(settings)
|
||||
|
||||
thread_msg: nextcord.Message = await parent.send(content=quarter_name)
|
||||
|
||||
@@ -176,7 +175,7 @@ class Election:
|
||||
for index, message in enumerate(messages):
|
||||
# if last item, add the nominate button
|
||||
if index + 1 == len(messages):
|
||||
nominate_msg: nextcord.Message = await thread.send(message, view=NominateView(self.config, self.guild))
|
||||
nominate_msg: nextcord.Message = await thread.send(message, view=NominateView(self.guild))
|
||||
else:
|
||||
await thread.send(message)
|
||||
|
||||
@@ -201,12 +200,12 @@ class Election:
|
||||
election_thread: nextcord.Thread = self.guild.get_thread(self.get_election_info().ThreadId)
|
||||
await election_thread.send(message)
|
||||
vote_msg = await election_thread.send(
|
||||
build_votes_str(self.config, self.guild),
|
||||
view=VoteView(self.config, self.guild),
|
||||
build_votes_str(settings, self.guild),
|
||||
view=VoteView(self.guild),
|
||||
)
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = select(ElectionInformation).where(ElectionInformation.ElectionName == get_election_name(self.config))
|
||||
stmt = select(ElectionInformation).where(ElectionInformation.ElectionName == get_election_name(settings))
|
||||
info = session.scalar(stmt)
|
||||
info.CouncilVoteMsgId = vote_msg.id
|
||||
session.commit()
|
||||
@@ -218,14 +217,12 @@ class Election:
|
||||
async def voting_end_action(self) -> None:
|
||||
"""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)
|
||||
council_elect_role: nextcord.Role = self.guild.get_role(settings.role_ids.clan_council_elect)
|
||||
election_thread: nextcord.Thread = self.guild.get_thread(self.get_election_info().ThreadId)
|
||||
|
||||
nominate_msg: nextcord.Message = await election_thread.send(
|
||||
message, view=NominateHighCouncilView(self.config, self.guild)
|
||||
)
|
||||
nominate_msg: nextcord.Message = await election_thread.send(message, view=NominateHighCouncilView(self.guild))
|
||||
|
||||
election_name = get_election_name(self.config)
|
||||
election_name = get_election_name(settings)
|
||||
|
||||
with Session(engine) as session:
|
||||
# remove vote button from vote message
|
||||
@@ -270,12 +267,12 @@ class Election:
|
||||
election_thread: nextcord.Thread = self.guild.get_thread(self.get_election_info().ThreadId)
|
||||
await election_thread.send(message)
|
||||
vote_msg = await election_thread.send(
|
||||
build_highcouncil_votes_str(self.config, self.guild),
|
||||
view=VoteHighcouncilView(self.config, self.guild),
|
||||
build_highcouncil_votes_str(settings, self.guild),
|
||||
view=VoteHighcouncilView(self.guild),
|
||||
)
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = select(ElectionInformation).where(ElectionInformation.ElectionName == get_election_name(self.config))
|
||||
stmt = select(ElectionInformation).where(ElectionInformation.ElectionName == get_election_name(settings))
|
||||
info = session.scalar(stmt)
|
||||
info.HighCouncilVoteMsgId = vote_msg.id
|
||||
session.commit()
|
||||
@@ -288,10 +285,10 @@ class Election:
|
||||
"""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)
|
||||
council_role: nextcord.Role = self.guild.get_role(self.config.params.clan_council_role_id)
|
||||
elect_role: nextcord.Role = self.guild.get_role(settings.role_ids.clan_council_elect)
|
||||
council_role: nextcord.Role = self.guild.get_role(settings.role_ids.clan_council)
|
||||
|
||||
election_name = get_election_name(self.config)
|
||||
election_name = get_election_name(settings)
|
||||
|
||||
with Session(engine) as session:
|
||||
# role management
|
||||
@@ -356,7 +353,7 @@ class Election:
|
||||
|
||||
# clear view from vote message
|
||||
stmt = select(ElectionInformation.HighCouncilVoteMsgId).where(
|
||||
ElectionInformation.ElectionName == get_election_name(self.config)
|
||||
ElectionInformation.ElectionName == get_election_name(settings)
|
||||
)
|
||||
vote_msg_id = session.scalar(stmt)
|
||||
vote_msg: nextcord.Message = await election_thread.fetch_message(vote_msg_id)
|
||||
@@ -369,7 +366,7 @@ class Election:
|
||||
await election_thread.send("This election cycle is now over. Thank you everyone for participating!")
|
||||
|
||||
await election_thread.edit(archived=True, locked=True)
|
||||
await edit_clan_council_info(self.guild, self.config)
|
||||
await edit_clan_council_info(self.guild, settings)
|
||||
|
||||
def get_election_info(self) -> ElectionInformation:
|
||||
"""
|
||||
@@ -379,14 +376,14 @@ class Election:
|
||||
ElectionInformation: The information from the database about the current election.
|
||||
"""
|
||||
with Session(engine) as session:
|
||||
stmt = select(ElectionInformation).where(ElectionInformation.ElectionName == get_election_name(self.config))
|
||||
stmt = select(ElectionInformation).where(ElectionInformation.ElectionName == get_election_name(settings))
|
||||
return session.scalar(stmt)
|
||||
|
||||
async def election_reminder(self) -> None:
|
||||
"""Sends a message to general chat reminder clan about election."""
|
||||
general: nextcord.TextChannel = self.guild.get_channel(self.config.params.general_channel_id)
|
||||
general: nextcord.TextChannel = self.guild.get_channel(settings.channel_ids.general)
|
||||
|
||||
message = f"Reminder to <@&{self.config.params.clan_member_role_id}>! Clan elections are happening! Head over "
|
||||
message = f"Reminder to <@&{settings.role_ids.clan_member}>! Clan elections are happening! Head over "
|
||||
message += f"to <#{self.get_election_info().ThreadId}> to cast your vote!"
|
||||
|
||||
await general.send(content=message)
|
||||
|
||||
Reference in New Issue
Block a user