Updated files in classes directory to use new configs. Ensured usages are updated.

This commit is contained in:
2024-09-03 15:57:50 -04:00
parent 2244765d87
commit 3b289e74c8
8 changed files with 78 additions and 109 deletions
+12 -21
View File
@@ -1,7 +1,7 @@
"""Contains various views to be used in the high council nomination process."""
import nextcord
from DakinySettings import DakinySettings
from DakinySettings import settings
from database_setup.sql_data_classes import CouncilMembers, engine
from nextcord.interactions import Interaction
from sqlalchemy import select
@@ -23,7 +23,6 @@ class NominateDMModal(nextcord.ui.Modal):
def __init__(
self,
config: DakinySettings,
usr_id: int,
usr_nominated: bool, # noqa: FBT001
speech_content: str,
@@ -33,7 +32,6 @@ class NominateDMModal(nextcord.ui.Modal):
timeout=5 * 60, # 5 minutes
)
self.usr_id: int = usr_id
self.config: DakinySettings = config
self.usr_nominated = usr_nominated
self.speech = nextcord.ui.TextInput(
@@ -58,7 +56,7 @@ class NominateDMModal(nextcord.ui.Modal):
with Session(engine) as session:
# user already in table
election_name = get_election_name(self.config)
election_name = get_election_name(settings)
stmt = (
select(CouncilMembers)
.where(CouncilMembers.ElectionName == election_name)
@@ -85,7 +83,6 @@ class NominateCLModal(nextcord.ui.Modal):
def __init__(
self,
config: DakinySettings,
usr_id: int,
usr_nominated: bool, # noqa: FBT001
speech_content: str,
@@ -95,7 +92,6 @@ class NominateCLModal(nextcord.ui.Modal):
timeout=5 * 60, # 5 minutes
)
self.usr_id: int = usr_id
self.config: DakinySettings = config
self.usr_nominated = usr_nominated
self.speech = nextcord.ui.TextInput(
@@ -120,7 +116,7 @@ class NominateCLModal(nextcord.ui.Modal):
with Session(engine) as session:
# user already in table
election_name = get_election_name(self.config)
election_name = get_election_name(settings)
stmt = (
select(CouncilMembers)
.where(CouncilMembers.ElectionName == election_name)
@@ -141,9 +137,8 @@ class NominateCLModal(nextcord.ui.Modal):
class NominateHighCouncilView(nextcord.ui.View):
"""The buttons to press to start your High Council nomination."""
def __init__(self, config: DakinySettings, guild: nextcord.Guild):
def __init__(self, guild: nextcord.Guild):
super().__init__(timeout=None)
self.config: DakinySettings = config
self.guild: nextcord.Guild = guild
@nextcord.ui.button(
@@ -163,14 +158,14 @@ class NominateHighCouncilView(nextcord.ui.View):
interaction (nextcord.Interaction): Interaction of user who pressed the button
"""
# enforce council elect only
if self.guild.get_role(self.config.params.clan_council_elect_role_id) not in interaction.user.roles:
if self.guild.get_role(settings.role_ids.clan_council_elect) not in interaction.user.roles:
await interaction.response.send_message(
f"You must have the <@&{self.config.params.clan_council_elect_role_id}> role to vote.",
f"You must have the <@&{settings.role_ids.clan_council_elect}> role to vote.",
ephemeral=True,
)
return
election_name = get_election_name(self.config)
election_name = get_election_name(settings)
usr_nominated = False
speech_content = ""
with Session(engine) as session:
@@ -187,9 +182,7 @@ class NominateHighCouncilView(nextcord.ui.View):
msg = await interaction.channel.fetch_message(obj.DiscordManagerSpeechId)
speech_content = msg.content.split(NOMINEE_SPLITTER)[1]
await interaction.response.send_modal(
NominateDMModal(self.config, interaction.user.id, usr_nominated, speech_content)
)
await interaction.response.send_modal(NominateDMModal(interaction.user.id, usr_nominated, speech_content))
@nextcord.ui.button(
label="Nominate for Clan Leader",
@@ -208,14 +201,14 @@ class NominateHighCouncilView(nextcord.ui.View):
interaction (nextcord.Interaction): Interaction of user who pressed the button
"""
# enforce council elect only
if self.guild.get_role(self.config.params.clan_council_elect_role_id) not in interaction.user.roles:
if self.guild.get_role(settings.role_ids.clan_council_elect) not in interaction.user.roles:
await interaction.response.send_message(
f"You must have the <@&{self.config.params.clan_council_elect_role_id}> role to vote.",
f"You must have the <@&{settings.role_ids.clan_council_elect}> role to vote.",
ephemeral=True,
)
return
election_name = get_election_name(self.config)
election_name = get_election_name(settings)
usr_nominated = False
speech_content = ""
with Session(engine) as session:
@@ -232,6 +225,4 @@ class NominateHighCouncilView(nextcord.ui.View):
msg = await interaction.channel.fetch_message(obj.ClanLeaderSpeechId)
speech_content = msg.content.split(NOMINEE_SPLITTER)[1]
await interaction.response.send_modal(
NominateCLModal(self.config, interaction.user.id, usr_nominated, speech_content)
)
await interaction.response.send_modal(NominateCLModal(interaction.user.id, usr_nominated, speech_content))