71 lines
2.4 KiB
Python
71 lines
2.4 KiB
Python
"""
|
|
Contains various views to be used in the nomination process.
|
|
"""
|
|
|
|
import nextcord
|
|
from nextcord.interactions import Interaction
|
|
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 NominateModal(nextcord.ui.Modal):
|
|
"""
|
|
Modal for nominating oneself. User writes a speech and then the callback sends the speech into the correct channel.
|
|
"""
|
|
|
|
def __init__(self, config):
|
|
super().__init__(
|
|
"Nomination",
|
|
timeout=5 * 60, # 5 minutes
|
|
)
|
|
|
|
self.speech = nextcord.ui.TextInput(
|
|
label="Nomination Speech",
|
|
style=nextcord.TextInputStyle.paragraph,
|
|
placeholder="Please write your speech here.",
|
|
required=True,
|
|
max_length=1500,
|
|
)
|
|
self.add_item(self.speech)
|
|
self.config: DakinyConfig = config
|
|
|
|
async def callback(self, interaction: Interaction) -> None:
|
|
"""
|
|
Sends the nomination speech into the voting channel and enters the user into the voting database.
|
|
|
|
Args:
|
|
interaction (Interaction): Interaction with user.
|
|
|
|
"""
|
|
# TODO add nominee to database, make sure user hasn't nominated themself before,
|
|
|
|
nomination_message = f"**Clan Council Nominee: <@{interaction.user.id}>**\n"
|
|
nomination_message += "========================================================\n\n"
|
|
nomination_message += self.speech.value
|
|
|
|
msg = await interaction.channel.send(nomination_message)
|
|
|
|
with Session(engine) as session:
|
|
council_member = CouncilMembers(
|
|
ElectionCycle=get_election_cycle_name(self.config), MemberId=interaction.user.id, SpeechMsgId=msg.id
|
|
)
|
|
session.add(council_member)
|
|
session.commit()
|
|
|
|
|
|
class NominateView(nextcord.ui.View):
|
|
"""
|
|
The button to press to start your nomination.
|
|
"""
|
|
|
|
def __init__(self, config):
|
|
super().__init__(timeout=None)
|
|
self.config: DakinyConfig = config
|
|
|
|
@nextcord.ui.button(label="Nominate Yourself", style=nextcord.ButtonStyle.primary, custom_id="nominate")
|
|
async def nominate(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None:
|
|
await interaction.response.send_modal(NominateModal(self.config))
|