Files
dakiny-bot/classes/voting_views.py
T
imcompiling 5b1b4cfecb 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.
2023-11-02 19:52:20 -04:00

63 lines
1.9 KiB
Python

"""
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
from config import DakinyConfig
from database_setup.sql_data_classes import CouncilMembers, engine
from utils import get_election_cycle_name
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__(timeout=300)
self.add_item(VoteSelect())
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")],
)
async def callback(self, interaction: Interaction):
await interaction.edit(content=self.values[0], view=None)
class VoteView(nextcord.ui.View):
"""
The button to press to start your nomination.
"""
def __init__(self):
super().__init__(timeout=None)
@nextcord.ui.button(label="Vote", style=nextcord.ButtonStyle.primary, custom_id="vote")
async def vote(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None:
"""
TODO
Args:
button (nextcord.ui.Button): Unused. idk why its needed in the decorator
interaction (nextcord.Interaction): Interaction of user who pressed the button
"""
await interaction.response.send_message(
content="Please vote for a clan member!", view=VoteActionView(), ephemeral=True
)