This commit is contained in:
@@ -9,6 +9,7 @@ from sqlalchemy import select
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from classes.nominate_views import NominateView
|
from classes.nominate_views import NominateView
|
||||||
|
from classes.voting_views import VoteView
|
||||||
from config import DakinyConfig
|
from config import DakinyConfig
|
||||||
from database_setup.sql_data_classes import CouncilMembers, ElectionInformation, Votes, engine
|
from database_setup.sql_data_classes import CouncilMembers, ElectionInformation, Votes, engine
|
||||||
from utils import get_datetime, get_election_cycle_name
|
from utils import get_datetime, get_election_cycle_name
|
||||||
@@ -204,7 +205,7 @@ class ElectionCycle:
|
|||||||
message = self.build_vote_start()
|
message = self.build_vote_start()
|
||||||
clan_member_role: nextcord.Role = self.guild.get_role(self.config.params.clan_member_role_id)
|
clan_member_role: nextcord.Role = self.guild.get_role(self.config.params.clan_member_role_id)
|
||||||
election_channel: nextcord.TextChannel = self.guild.get_channel(self.get_election_info().ElectionChannel)
|
election_channel: nextcord.TextChannel = self.guild.get_channel(self.get_election_info().ElectionChannel)
|
||||||
await election_channel.send(message)
|
await election_channel.send(message, view=VoteView())
|
||||||
await election_channel.set_permissions(clan_member_role, send_messages=False)
|
await election_channel.set_permissions(clan_member_role, send_messages=False)
|
||||||
|
|
||||||
async def voting_end_action(self) -> None:
|
async def voting_end_action(self) -> None:
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
"""
|
||||||
|
Contains various views to be used while voting. Controls the logic when performing the vote.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import nextcord
|
||||||
|
from nextcord import SelectOption
|
||||||
|
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 VoteModal(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.list = nextcord.ui.StringSelect(
|
||||||
|
min_values=1,
|
||||||
|
max_values=1,
|
||||||
|
options=[SelectOption(label="one"), SelectOption(label="two"), SelectOption(label="three")],
|
||||||
|
)
|
||||||
|
self.add_item(self.list)
|
||||||
|
|
||||||
|
|
||||||
|
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_modal(VoteModal())
|
||||||
@@ -65,5 +65,6 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): _description_
|
interaction (nextcord.Interaction): _description_
|
||||||
"""
|
"""
|
||||||
cycle = ElectionCycle(0, self.bot)
|
config: DakinyConfig = self.bot.config
|
||||||
|
cycle = ElectionCycle(get_current_cycle(config), config, self.bot.get_guild(config.params.guild_id))
|
||||||
await cycle.voting_start_action()
|
await cycle.voting_start_action()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ 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 classes.nominate_views import NominateView
|
||||||
|
from classes.voting_views import VoteView
|
||||||
from config import DakinyConfig
|
from config import DakinyConfig
|
||||||
|
|
||||||
cs = ConfigStore.instance()
|
cs = ConfigStore.instance()
|
||||||
@@ -51,6 +52,7 @@ def main(cfg: DakinyConfig):
|
|||||||
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(cfg))
|
bot.add_view(NominateView(cfg))
|
||||||
|
bot.add_view(VoteView())
|
||||||
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