Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f9da9fe7ef | ||
|
|
b5ea709c3a | ||
|
|
9980c49764 | ||
|
|
8d02e28271 | ||
|
|
3a5add3c60 | ||
|
|
dd1c304522 | ||
|
|
619ae92d03 |
@@ -6,7 +6,7 @@ import collections
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
import nextcord
|
import nextcord
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select, true
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from classes.nominate_views import NominateView
|
from classes.nominate_views import NominateView
|
||||||
@@ -210,7 +210,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 thread.send(message, view=NominateView(self.config))
|
await thread.send(message, view=NominateView(self.config, self.guild))
|
||||||
else:
|
else:
|
||||||
await thread.send(message)
|
await thread.send(message)
|
||||||
|
|
||||||
@@ -276,9 +276,12 @@ class ElectionCycle:
|
|||||||
council_member.Elected = True
|
council_member.Elected = True
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
user: nextcord.Member = self.guild.get_member(user_id)
|
member: nextcord.Member = self.guild.get_member(user_id)
|
||||||
|
|
||||||
await user.add_roles(council_elect_role)
|
await member.add_roles(
|
||||||
|
council_elect_role,
|
||||||
|
reason=f"{member.display_name} has won a nomination and become a Council Elect.",
|
||||||
|
)
|
||||||
|
|
||||||
await election_thread.send(message)
|
await election_thread.send(message)
|
||||||
|
|
||||||
@@ -300,6 +303,34 @@ class ElectionCycle:
|
|||||||
|
|
||||||
self.election_over = True
|
self.election_over = True
|
||||||
|
|
||||||
|
elect_role: nextcord.Role = self.guild.get_role(
|
||||||
|
self.config.params.clan_council_elect_role_id
|
||||||
|
)
|
||||||
|
council_role: nextcord.Role = self.guild.get_role(
|
||||||
|
self.config.params.clan_council_role_id
|
||||||
|
)
|
||||||
|
|
||||||
|
# role management
|
||||||
|
with Session(engine) as session:
|
||||||
|
stmt = (
|
||||||
|
select(CouncilMembers.MemberId)
|
||||||
|
.where(
|
||||||
|
CouncilMembers.ElectionCycle == get_election_cycle_name(self.config)
|
||||||
|
)
|
||||||
|
.where(CouncilMembers.Elected == true())
|
||||||
|
)
|
||||||
|
|
||||||
|
for member_id in session.scalars(stmt):
|
||||||
|
member = self.guild.get_member(member_id)
|
||||||
|
await member.remove_roles(
|
||||||
|
elect_role,
|
||||||
|
reason=f"{member.display_name} no longer needs the elect role.",
|
||||||
|
)
|
||||||
|
await member.add_roles(
|
||||||
|
council_role,
|
||||||
|
reason=f"{member.display_name} has been elected to council.",
|
||||||
|
)
|
||||||
|
|
||||||
election_thread: nextcord.Thread = self.guild.get_thread(
|
election_thread: nextcord.Thread = self.guild.get_thread(
|
||||||
self.get_election_info().ThreadId
|
self.get_election_info().ThreadId
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -19,7 +19,13 @@ 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, config: DakinyConfig, usr_id: int, usr_nominated: bool, speech_content: str):
|
def __init__(
|
||||||
|
self,
|
||||||
|
config: DakinyConfig,
|
||||||
|
usr_id: int,
|
||||||
|
usr_nominated: bool,
|
||||||
|
speech_content: str,
|
||||||
|
):
|
||||||
super().__init__(
|
super().__init__(
|
||||||
"Nomination",
|
"Nomination",
|
||||||
timeout=5 * 60, # 5 minutes
|
timeout=5 * 60, # 5 minutes
|
||||||
@@ -70,8 +76,12 @@ class NominateModal(nextcord.ui.Modal):
|
|||||||
)
|
)
|
||||||
obj = session.scalar(stmt)
|
obj = session.scalar(stmt)
|
||||||
|
|
||||||
msg: nextcord.Message = await interaction.channel.fetch_message(obj.SpeechMsgId)
|
msg: nextcord.Message = await interaction.channel.fetch_message(
|
||||||
await msg.edit(content=decorate_nomination(interaction.user.id, self.speech.value))
|
obj.SpeechMsgId
|
||||||
|
)
|
||||||
|
await msg.edit(
|
||||||
|
content=decorate_nomination(interaction.user.id, self.speech.value)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class NominateView(nextcord.ui.View):
|
class NominateView(nextcord.ui.View):
|
||||||
@@ -79,12 +89,19 @@ class NominateView(nextcord.ui.View):
|
|||||||
The button to press to start your nomination.
|
The button to press to start your nomination.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config: DakinyConfig, guild: nextcord.Guild):
|
||||||
super().__init__(timeout=None)
|
super().__init__(timeout=None)
|
||||||
self.config: DakinyConfig = config
|
self.config: DakinyConfig = config
|
||||||
|
self.guild: nextcord.Guild = guild
|
||||||
|
|
||||||
@nextcord.ui.button(label="Nominate Yourself", style=nextcord.ButtonStyle.primary, custom_id="nominate")
|
@nextcord.ui.button(
|
||||||
async def nominate(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None:
|
label="Nominate Yourself",
|
||||||
|
style=nextcord.ButtonStyle.primary,
|
||||||
|
custom_id="nominate",
|
||||||
|
)
|
||||||
|
async def nominate(
|
||||||
|
self, button: nextcord.ui.Button, interaction: nextcord.Interaction
|
||||||
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Gathers previous information about the user if they have already nominated themselves, then launches
|
Gathers previous information about the user if they have already nominated themselves, then launches
|
||||||
the nomination modal to get their speech.
|
the nomination modal to get their speech.
|
||||||
@@ -94,6 +111,17 @@ class NominateView(nextcord.ui.View):
|
|||||||
interaction (nextcord.Interaction): Interaction of user who pressed the button
|
interaction (nextcord.Interaction): Interaction of user who pressed the button
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# enforce members only
|
||||||
|
if (
|
||||||
|
self.guild.get_role(self.config.params.clan_member_role_id)
|
||||||
|
not in interaction.user.roles
|
||||||
|
):
|
||||||
|
await interaction.response.send_message(
|
||||||
|
f"You must have the <@&{self.config.params.clan_member_role_id}> role to vote.",
|
||||||
|
ephemeral=True,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
cycle = get_election_cycle_name(self.config)
|
cycle = get_election_cycle_name(self.config)
|
||||||
usr_nominated = False
|
usr_nominated = False
|
||||||
speech_content = ""
|
speech_content = ""
|
||||||
@@ -110,7 +138,9 @@ class NominateView(nextcord.ui.View):
|
|||||||
speech_content = msg.content.split(NOMINEE_SPLITTER)[1]
|
speech_content = msg.content.split(NOMINEE_SPLITTER)[1]
|
||||||
|
|
||||||
await interaction.response.send_modal(
|
await interaction.response.send_modal(
|
||||||
NominateModal(self.config, interaction.user.id, usr_nominated, speech_content)
|
NominateModal(
|
||||||
|
self.config, interaction.user.id, usr_nominated, speech_content
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -130,9 +130,9 @@ class VoteView(nextcord.ui.View):
|
|||||||
|
|
||||||
options = [
|
options = [
|
||||||
SelectOption(
|
SelectOption(
|
||||||
label=f"{self.guild.get_member(nominee).nick} ☑️"
|
label=f"{self.guild.get_member(nominee).display_name} ☑️"
|
||||||
if voted_for == nominee
|
if voted_for == nominee
|
||||||
else f"{self.guild.get_member(nominee).nick}",
|
else f"{self.guild.get_member(nominee).display_name}",
|
||||||
value=str(nominee),
|
value=str(nominee),
|
||||||
)
|
)
|
||||||
for nominee in session.scalars(stmt)
|
for nominee in session.scalars(stmt)
|
||||||
|
|||||||
+11
-25
@@ -10,6 +10,17 @@ from config import DakinyConfig
|
|||||||
from utils import get_current_cycle
|
from utils import get_current_cycle
|
||||||
|
|
||||||
|
|
||||||
|
def is_me():
|
||||||
|
"""
|
||||||
|
predicate that makes sure only I can run the test commands.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def predicate(interaction: nextcord.Interaction):
|
||||||
|
return interaction.user.id == 206602713511886849
|
||||||
|
|
||||||
|
return application_checks.check(predicate)
|
||||||
|
|
||||||
|
|
||||||
class TestCog(commands.Cog, name="Test commands."):
|
class TestCog(commands.Cog, name="Test commands."):
|
||||||
"""
|
"""
|
||||||
Class holds commands for testing.
|
Class holds commands for testing.
|
||||||
@@ -21,37 +32,12 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
"""
|
"""
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
def is_me():
|
|
||||||
def predicate(interaction: nextcord.Interaction):
|
|
||||||
return interaction.user.id == 206602713511886849
|
|
||||||
|
|
||||||
return application_checks.check(predicate)
|
|
||||||
|
|
||||||
@nextcord.slash_command()
|
@nextcord.slash_command()
|
||||||
@is_me()
|
|
||||||
async def test(self, interaction: nextcord.Interaction):
|
async def test(self, interaction: nextcord.Interaction):
|
||||||
"""
|
"""
|
||||||
Parent slash command for help. Never called.
|
Parent slash command for help. Never called.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@test.subcommand()
|
|
||||||
@is_me()
|
|
||||||
async def msg_builder(self, interaction: nextcord.Interaction):
|
|
||||||
"""
|
|
||||||
Tests the message builder.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
|
||||||
"""
|
|
||||||
|
|
||||||
cycle = ElectionCycle(0, self.bot)
|
|
||||||
|
|
||||||
message = cycle.build_election_announcement()
|
|
||||||
|
|
||||||
# doesn't tell discord that the message was responded to. Is a test command so I don't really care atm.
|
|
||||||
for m in message:
|
|
||||||
await interaction.channel.send(content=m)
|
|
||||||
|
|
||||||
@test.subcommand()
|
@test.subcommand()
|
||||||
@is_me()
|
@is_me()
|
||||||
async def election_start(self, interaction: nextcord.Interaction):
|
async def election_start(self, interaction: nextcord.Interaction):
|
||||||
|
|||||||
@@ -10,10 +10,8 @@ class Params:
|
|||||||
Class defines the various configuration parameters.
|
Class defines the various configuration parameters.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
active_category_id: int
|
|
||||||
admin_channel_id: int # might want to rename this...
|
admin_channel_id: int # might want to rename this...
|
||||||
announcement_category_id: int
|
announcement_category_id: int
|
||||||
archive_channel_group_id: int
|
|
||||||
clan_council_elect_role_id: int
|
clan_council_elect_role_id: int
|
||||||
clan_council_role_id: int
|
clan_council_role_id: int
|
||||||
clan_info_channel_id: int
|
clan_info_channel_id: int
|
||||||
|
|||||||
+4
-2
@@ -20,7 +20,9 @@ birthday_list: list[int] = []
|
|||||||
logger = logging.getLogger("nextcord")
|
logger = logging.getLogger("nextcord")
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8", mode="w")
|
handler = logging.FileHandler(filename="nextcord.log", encoding="utf-8", mode="w")
|
||||||
handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s"))
|
handler.setFormatter(
|
||||||
|
logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(message)s")
|
||||||
|
)
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
|
|
||||||
|
|
||||||
@@ -51,7 +53,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(cfg))
|
bot.add_view(NominateView(cfg, bot.get_guild(cfg.params.guild_id)))
|
||||||
bot.add_view(VoteView(cfg, bot.get_guild(cfg.params.guild_id)))
|
bot.add_view(VoteView(cfg, bot.get_guild(cfg.params.guild_id)))
|
||||||
print(f"{bot.user.name} has connected to Discord!")
|
print(f"{bot.user.name} has connected to Discord!")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user