This commit is contained in:
@@ -8,6 +8,7 @@ import nextcord
|
|||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from classes.nominate_views import NominateView
|
||||||
from config import DakinyConfig
|
from config import DakinyConfig
|
||||||
from database_setup.sql_data_classes import ElectionInformation, engine
|
from database_setup.sql_data_classes import ElectionInformation, engine
|
||||||
from utils import get_datetime
|
from utils import get_datetime
|
||||||
@@ -166,8 +167,12 @@ class ElectionCycle:
|
|||||||
# election start message is returned as an array of string because it is too long. send each string
|
# election start message is returned as an array of string because it is too long. send each string
|
||||||
# individually.
|
# individually.
|
||||||
messages = self.build_election_announcement()
|
messages = self.build_election_announcement()
|
||||||
for message in messages:
|
for index, message in enumerate(messages):
|
||||||
await election_channel.send(message)
|
# if last item, add the nominate button
|
||||||
|
if index + 1 == len(messages):
|
||||||
|
await election_channel.send(message, view=NominateView())
|
||||||
|
else:
|
||||||
|
await election_channel.send(message)
|
||||||
|
|
||||||
async def voting_start_action(self) -> None:
|
async def voting_start_action(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
"""
|
||||||
|
Contains various views to be used in the nomination process.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import nextcord
|
||||||
|
from nextcord.interactions import Interaction
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
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)
|
||||||
|
|
||||||
|
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,
|
||||||
|
# make the nomination message better
|
||||||
|
|
||||||
|
await interaction.channel.send(self.speech.value)
|
||||||
|
|
||||||
|
|
||||||
|
class NominateView(nextcord.ui.View):
|
||||||
|
"""
|
||||||
|
The button to press to start your nomination.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__(timeout=None)
|
||||||
|
|
||||||
|
@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())
|
||||||
@@ -6,6 +6,7 @@ import nextcord
|
|||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
from classes.election_cycle import ElectionCycle
|
from classes.election_cycle import ElectionCycle
|
||||||
|
from config import DakinyConfig
|
||||||
|
|
||||||
|
|
||||||
class TestCog(commands.Cog, name="Test commands."):
|
class TestCog(commands.Cog, name="Test commands."):
|
||||||
@@ -51,7 +52,8 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): _description_
|
interaction (nextcord.Interaction): _description_
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cycle = ElectionCycle(0, self.bot)
|
config: DakinyConfig = self.bot.config
|
||||||
|
cycle = ElectionCycle(4, config, self.bot.get_guild(config.params.guild_id))
|
||||||
await cycle.election_start_action()
|
await cycle.election_start_action()
|
||||||
|
|
||||||
@test.subcommand()
|
@test.subcommand()
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from hydra.core.config_store import ConfigStore
|
|||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
import database_setup.create_database as create_database
|
import database_setup.create_database as create_database
|
||||||
|
from classes.nominate_views import NominateView
|
||||||
from config import DakinyConfig
|
from config import DakinyConfig
|
||||||
|
|
||||||
cs = ConfigStore.instance()
|
cs = ConfigStore.instance()
|
||||||
@@ -49,6 +50,7 @@ def main(cfg: DakinyConfig):
|
|||||||
"""When Discord is connected"""
|
"""When Discord is connected"""
|
||||||
assert bot.user is not None
|
assert bot.user is not None
|
||||||
create_database # pylint: disable=pointless-statement
|
create_database # pylint: disable=pointless-statement
|
||||||
|
bot.add_view(NominateView())
|
||||||
print(f"{bot.user.name} has connected to Discord!")
|
print(f"{bot.user.name} has connected to Discord!")
|
||||||
|
|
||||||
# Run Discord bot
|
# Run Discord bot
|
||||||
|
|||||||
Reference in New Issue
Block a user