Updated files in classes directory to use new configs. Ensured usages are updated.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"""Contains various views to be used while voting for high council. Controls the logic when performing the vote."""
|
||||
|
||||
import nextcord
|
||||
from DakinySettings import DakinySettings
|
||||
from DakinySettings import settings
|
||||
from database_setup.sql_data_classes import (
|
||||
CouncilMembers,
|
||||
ElectionInformation,
|
||||
@@ -18,14 +18,13 @@ 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: DakinySettings, election_type: str) -> None:
|
||||
def __init__(self, options: list["SelectOption"], election_type: str) -> None:
|
||||
super().__init__(
|
||||
placeholder="Choose 1",
|
||||
min_values=1,
|
||||
max_values=1,
|
||||
options=options,
|
||||
)
|
||||
self.config = config
|
||||
self.election_type = election_type
|
||||
|
||||
async def callback(self, interaction: Interaction) -> None:
|
||||
@@ -38,7 +37,7 @@ class VoteSelect(nextcord.ui.StringSelect):
|
||||
Args:
|
||||
interaction (Interaction): Interaction with this callback.
|
||||
"""
|
||||
election_name: str = get_election_name(self.config)
|
||||
election_name: str = get_election_name(settings)
|
||||
with Session(engine) as session:
|
||||
stmt = select(ElectionInformation.HighCouncilVoteMsgId).where(
|
||||
ElectionInformation.ElectionName == election_name
|
||||
@@ -71,7 +70,7 @@ class VoteSelect(nextcord.ui.StringSelect):
|
||||
session.execute(stmt)
|
||||
session.commit()
|
||||
|
||||
vote_message_str = build_highcouncil_votes_str(self.config, interaction.guild)
|
||||
vote_message_str = build_highcouncil_votes_str(settings, interaction.guild)
|
||||
vote_msg: nextcord.Message = await interaction.channel.fetch_message(vote_msg_id)
|
||||
await vote_msg.edit(content=vote_message_str)
|
||||
|
||||
@@ -83,9 +82,8 @@ class VoteSelect(nextcord.ui.StringSelect):
|
||||
class VoteHighcouncilView(nextcord.ui.View):
|
||||
"""The button to press to start voting for HighCouncil."""
|
||||
|
||||
def __init__(self, config: DakinySettings, guild: nextcord.Guild):
|
||||
def __init__(self, guild: nextcord.Guild):
|
||||
super().__init__(timeout=None)
|
||||
self.config = config
|
||||
self.guild = guild
|
||||
|
||||
@nextcord.ui.button(
|
||||
@@ -106,14 +104,14 @@ class VoteHighcouncilView(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: str = get_election_name(self.config)
|
||||
election_name: str = get_election_name(settings)
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
@@ -152,7 +150,7 @@ class VoteHighcouncilView(nextcord.ui.View):
|
||||
)
|
||||
|
||||
view = nextcord.ui.View()
|
||||
view.add_item(VoteSelect(options=options, config=self.config, election_type=VoteType.CLANLEADER))
|
||||
view.add_item(VoteSelect(options=options, election_type=VoteType.CLANLEADER))
|
||||
|
||||
await interaction.response.send_message(
|
||||
content="Please vote for a Clan Leader!",
|
||||
@@ -178,14 +176,14 @@ class VoteHighcouncilView(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: str = get_election_name(self.config)
|
||||
election_name: str = get_election_name(settings)
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
@@ -227,7 +225,6 @@ class VoteHighcouncilView(nextcord.ui.View):
|
||||
view.add_item(
|
||||
VoteSelect(
|
||||
options=options,
|
||||
config=self.config,
|
||||
election_type=VoteType.DISCORDMANAGER,
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user