Pass config along so that nominate can add to database with election cycle name.
This commit is contained in:
@@ -170,7 +170,7 @@ class ElectionCycle:
|
|||||||
for index, message in enumerate(messages):
|
for index, message in enumerate(messages):
|
||||||
# if last item, add the nominate button
|
# if last item, add the nominate button
|
||||||
if index + 1 == len(messages):
|
if index + 1 == len(messages):
|
||||||
await election_channel.send(message, view=NominateView())
|
await election_channel.send(message, view=NominateView(self.config))
|
||||||
else:
|
else:
|
||||||
await election_channel.send(message)
|
await election_channel.send(message)
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import nextcord
|
|||||||
from nextcord.interactions import Interaction
|
from nextcord.interactions import Interaction
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from config import DakinyConfig
|
||||||
from database_setup.sql_data_classes import CouncilMembers, engine
|
from database_setup.sql_data_classes import CouncilMembers, engine
|
||||||
from utils import get_election_cycle_name
|
from utils import get_election_cycle_name
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ class NominateModal(nextcord.ui.Modal):
|
|||||||
Modal for nominating oneself. User writes a speech and then the callback sends the speech into the correct channel.
|
Modal for nominating oneself. User writes a speech and then the callback sends the speech into the correct channel.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, config):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
"Nomination",
|
"Nomination",
|
||||||
timeout=5 * 60, # 5 minutes
|
timeout=5 * 60, # 5 minutes
|
||||||
@@ -29,6 +30,7 @@ class NominateModal(nextcord.ui.Modal):
|
|||||||
max_length=1500,
|
max_length=1500,
|
||||||
)
|
)
|
||||||
self.add_item(self.speech)
|
self.add_item(self.speech)
|
||||||
|
self.config: DakinyConfig = config
|
||||||
|
|
||||||
async def callback(self, interaction: Interaction) -> None:
|
async def callback(self, interaction: Interaction) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -48,9 +50,10 @@ class NominateModal(nextcord.ui.Modal):
|
|||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
council_member = CouncilMembers(
|
council_member = CouncilMembers(
|
||||||
ElectionCycle=get_election_cycle_name(self.bot.config), MemberId=interaction.user.id
|
ElectionCycle=get_election_cycle_name(self.config), MemberId=interaction.user.id
|
||||||
)
|
)
|
||||||
session.add(council_member)
|
session.add(council_member)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
class NominateView(nextcord.ui.View):
|
class NominateView(nextcord.ui.View):
|
||||||
@@ -58,9 +61,10 @@ class NominateView(nextcord.ui.View):
|
|||||||
The button to press to start your nomination.
|
The button to press to start your nomination.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, config):
|
||||||
super().__init__(timeout=None)
|
super().__init__(timeout=None)
|
||||||
|
self.config: DakinyConfig = config
|
||||||
|
|
||||||
@nextcord.ui.button(label="Nominate Yourself", style=nextcord.ButtonStyle.primary, custom_id="nominate")
|
@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:
|
async def nominate(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None:
|
||||||
await interaction.response.send_modal(NominateModal())
|
await interaction.response.send_modal(NominateModal(self.config))
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from nextcord.ext import commands
|
|||||||
|
|
||||||
from classes.election_cycle import ElectionCycle
|
from classes.election_cycle import ElectionCycle
|
||||||
from config import DakinyConfig
|
from config import DakinyConfig
|
||||||
|
from utils import get_current_cycle
|
||||||
|
|
||||||
|
|
||||||
class TestCog(commands.Cog, name="Test commands."):
|
class TestCog(commands.Cog, name="Test commands."):
|
||||||
@@ -53,7 +54,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
config: DakinyConfig = self.bot.config
|
config: DakinyConfig = self.bot.config
|
||||||
cycle = ElectionCycle(4, config, self.bot.get_guild(config.params.guild_id))
|
cycle = ElectionCycle(get_current_cycle(config), config, self.bot.get_guild(config.params.guild_id))
|
||||||
await cycle.election_start_action()
|
await cycle.election_start_action()
|
||||||
|
|
||||||
@test.subcommand()
|
@test.subcommand()
|
||||||
|
|||||||
+1
-1
@@ -50,7 +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())
|
bot.add_view(NominateView(cfg))
|
||||||
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