Updated files in classes directory to use new configs. Ensured usages are updated.
This commit is contained in:
+9
-11
@@ -1,7 +1,7 @@
|
||||
"""Contains various views to be used while voting. 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_votes_str, get_election_name
|
||||
class VoteSelect(nextcord.ui.StringSelect):
|
||||
"""Vote view string select."""
|
||||
|
||||
def __init__(self, options: list["SelectOption"], config: DakinySettings) -> None:
|
||||
def __init__(self, options: list["SelectOption"]) -> None:
|
||||
super().__init__(
|
||||
placeholder="Choose 1",
|
||||
min_values=1,
|
||||
max_values=1,
|
||||
options=options,
|
||||
)
|
||||
self.config = config
|
||||
|
||||
async def callback(self, interaction: Interaction) -> None:
|
||||
"""
|
||||
@@ -37,7 +36,7 @@ class VoteSelect(nextcord.ui.StringSelect):
|
||||
Args:
|
||||
interaction (Interaction): Interaction with this callback.
|
||||
"""
|
||||
election_name = get_election_name(self.config)
|
||||
election_name = get_election_name(settings)
|
||||
with Session(engine) as session:
|
||||
stmt = select(ElectionInformation.CouncilVoteMsgId).where(ElectionInformation.ElectionName == election_name)
|
||||
vote_msg_id = session.scalar(stmt)
|
||||
@@ -67,7 +66,7 @@ class VoteSelect(nextcord.ui.StringSelect):
|
||||
session.execute(stmt)
|
||||
session.commit()
|
||||
|
||||
vote_message_str = build_votes_str(self.config, interaction.guild)
|
||||
vote_message_str = build_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)
|
||||
|
||||
@@ -79,9 +78,8 @@ class VoteSelect(nextcord.ui.StringSelect):
|
||||
class VoteView(nextcord.ui.View):
|
||||
"""The button to press to start your nomination."""
|
||||
|
||||
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(label="Vote", style=nextcord.ButtonStyle.primary, custom_id="vote")
|
||||
@@ -97,14 +95,14 @@ class VoteView(nextcord.ui.View):
|
||||
interaction (nextcord.Interaction): Interaction of user who pressed the button
|
||||
"""
|
||||
# enforce members only
|
||||
if self.guild.get_role(self.config.params.clan_member_role_id) not in interaction.user.roles:
|
||||
if self.guild.get_role(settings.role_ids.clan_member) not in interaction.user.roles:
|
||||
await interaction.response.send_message(
|
||||
f"You must have the <@&{self.config.params.clan_member_role_id}> role to vote.",
|
||||
f"You must have the <@&{settings.role_ids.clan_member}> 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 = (
|
||||
@@ -139,7 +137,7 @@ class VoteView(nextcord.ui.View):
|
||||
)
|
||||
|
||||
view = nextcord.ui.View()
|
||||
view.add_item(VoteSelect(options=options, config=self.config))
|
||||
view.add_item(VoteSelect(options))
|
||||
|
||||
await interaction.response.send_message(
|
||||
content="Please vote for a clan member!",
|
||||
|
||||
Reference in New Issue
Block a user