From 5b1b4cfecbc6ac1eda3ed9a47b97b01ac9c1376f Mon Sep 17 00:00:00 2001 From: imcompiling Date: Thu, 2 Nov 2023 19:52:20 -0400 Subject: [PATCH] Change modal to a view. Still need to fill out functionality. Funtionality needed: put into database, check on view creation of the user has voted already. If so, then change the content to show they already voted and who they voted for. Alert that they can change their vote. --- classes/voting_views.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/classes/voting_views.py b/classes/voting_views.py index b76ee27..36c476d 100644 --- a/classes/voting_views.py +++ b/classes/voting_views.py @@ -2,8 +2,12 @@ Contains various views to be used while voting. Controls the logic when performing the vote. """ +from typing import List, Optional + import nextcord from nextcord import SelectOption +from nextcord.interactions import Interaction +from nextcord.utils import MISSING from sqlalchemy import select from sqlalchemy.orm import Session @@ -12,23 +16,27 @@ from database_setup.sql_data_classes import CouncilMembers, engine from utils import get_election_cycle_name -class VoteModal(nextcord.ui.Modal): +class VoteActionView(nextcord.ui.View): """ Modal for nominating oneself. User writes a speech and then the callback sends the speech into the correct channel. """ def __init__(self): - super().__init__( - "Nomination", - timeout=5 * 60, # 5 minutes - ) + super().__init__(timeout=300) + self.add_item(VoteSelect()) - self.list = nextcord.ui.StringSelect( + +class VoteSelect(nextcord.ui.StringSelect): + def __init__(self) -> None: + super().__init__( + placeholder="Choose 1", min_values=1, max_values=1, options=[SelectOption(label="one"), SelectOption(label="two"), SelectOption(label="three")], ) - self.add_item(self.list) + + async def callback(self, interaction: Interaction): + await interaction.edit(content=self.values[0], view=None) class VoteView(nextcord.ui.View): @@ -49,4 +57,6 @@ class VoteView(nextcord.ui.View): interaction (nextcord.Interaction): Interaction of user who pressed the button """ - await interaction.response.send_modal(VoteModal()) + await interaction.response.send_message( + content="Please vote for a clan member!", view=VoteActionView(), ephemeral=True + )