Compare commits

..
Author SHA1 Message Date
imcompiling 0eae8afa2a Fill out term_start_action 2023-07-25 15:25:35 -04:00
imcompiling d79c990558 Remove term end action. 2023-07-25 15:11:33 -04:00
imcompiling 3465698b85 Merge branch '14-high-council-election-action' 2023-07-25 14:52:57 -04:00
imcompiling 1731bd46a6 Fill out highcouncil_election_start_action
build_develop / build (push) Has been cancelled
2023-07-25 14:52:48 -04:00
imcompiling 1b4c5780df Refactor other function to use get_election_info. 2023-07-25 14:51:17 -04:00
imcompiling d67940aa26 Create new function for getting election information. 2023-07-25 14:50:44 -04:00
imcompiling 9867f91268 Add the highcouncil vote start message. 2023-07-25 14:41:16 -04:00
imcompiling 4763651e93 Merge branch '13-voting-end-action' 2023-07-25 14:38:50 -04:00
imcompiling 1c76e6806c Build and send announcement. Change permissions.
build_develop / build (push) Has been cancelled
2023-07-25 14:37:41 -04:00
imcompiling 5cb9be7e37 Fill out build_highcouncil_election_announce 2023-07-25 14:16:00 -04:00
imcompiling d573595114 Merge branch '12-voting-start-action' 2023-07-16 23:59:08 -04:00
imcompiling 7bded4aa57 Slight refactor, added voting start action. 2023-07-16 23:56:44 -04:00
imcompiling a6c6a80f8f Revert "Namespace clash."
This reverts commit a52979a847.
2023-07-16 23:52:02 -04:00
imcompiling a52979a847 Namespace clash. 2023-07-16 23:50:58 -04:00
imcompiling 8eae82536e Merge remote-tracking branch 'origin/3-sqlite-database' 2023-07-16 23:01:31 -04:00
6 changed files with 83 additions and 32 deletions
+1 -1
View File
@@ -10,4 +10,4 @@ From {highcouncil_election_announce} to {highcouncil_election_start}, you will b
Each member of the CCE can cast one for each category by using the emotes: <:Rank_Owner:479008325137072155> for Clan Leader and <:Rank_Deputy:479008295319896064> for Discord Server Manager.
If needed, the icon 🤷 can be used to abstain to vote in any or both categories and it should be apply to all candidates of that category.
Votes can be cast until the {highcouncil_election_end}, so we can announce and have everyone set up to start the term by {term_start}
Votes can be cast until the {highcouncil_election_end}, so we can announce and have everyone set up to start the term by {term_start}.
+1
View File
@@ -0,0 +1 @@
<@&{clan_council_elect_role_id}> it is now time to vote for the high council! You have until {term_start} to complete the vote.
+67 -30
View File
@@ -6,6 +6,7 @@ from datetime import datetime, timedelta
import nextcord
from nextcord.ext import commands
from sqlalchemy import select
from sqlalchemy.orm import Session
from config import DakinyConfig
@@ -19,7 +20,7 @@ class ElectionCycle:
the cycle.
"""
def __init__(self, cycle: int, bot) -> None:
def __init__(self, cycle: int, bot: commands.Bot) -> None:
"""
Generates all dates relevant to the election cycle from input election start, term start and end dates.
@@ -40,7 +41,7 @@ class ElectionCycle:
self.highcouncil_election_announce: datetime = self.voting_end + timedelta(days=1)
self.highcouncil_election_start: datetime = self.highcouncil_election_announce + timedelta(days=3)
self.highcouncil_election_end: datetime = self.term_start - timedelta(days=1)
self.bot: commands.Bot = bot
self.guild: nextcord.Guild = bot.get_guild(self.config.params.guild_id)
def build_election_announcement(self) -> list[str]:
"""
@@ -70,7 +71,7 @@ class ElectionCycle:
return message.split("---message_break---")
def build_highcouncil_election(self) -> str:
def build_highcouncil_election_announce(self) -> str:
"""
Builds message to announce highcouncil election start.
@@ -81,7 +82,29 @@ class ElectionCycle:
with open("bot_messages/highcouncil_election.txt", mode="r", encoding="utf8") as file:
message = file.read()
return message.format()
return message.format(
clan_council_elect_role_id=self.config.params.clan_council_elect_role_id,
highcouncil_election_announce=self.highcouncil_election_announce.strftime("%B %d"),
highcouncil_election_start=self.highcouncil_election_start.strftime("%B %d"),
highcouncil_election_end=self.highcouncil_election_end.strftime("%B %d"),
term_start_date=self.term_start.strftime("%B %d"),
)
def build_highcouncil_vote_start(self) -> str:
"""
Builds the message to announce that highcouncil voting has started.
Returns:
str: Message to send.
"""
with open("bot_messages/highcouncil_vote.txt", mode="r", encoding="utf8") as file:
message = file.read()
return message.format(
clan_council_elect_role_id=self.config.params.clan_council_elect_role_id,
term_start_date=self.term_start.strftime("%B %d"),
)
def build_vote_start(self) -> str:
"""
@@ -116,22 +139,20 @@ class ElectionCycle:
elif today.date() == self.voting_end.date():
await self.voting_end_action()
elif today.date() == self.highcouncil_election_start.date():
await self.highcouncil_election_action()
await self.highcouncil_election_start_action()
elif today.date() == self.term_start.date():
await self.term_start_action()
elif today.date() == self.term_end.date():
await self.term_end_action()
async def election_start_action(self) -> None:
"""
Performs required actions for when the election cycle starts.
"""
# create new channel for election
category: nextcord.CategoryChannel = self.bot.get_channel(self.config.params.active_category_id)
category: nextcord.CategoryChannel = self.guild.get_channel(self.config.params.active_category_id)
quarter_name: str = self.get_election_cycle_name()
# create new entry into database.
election_channel = await category.create_text_channel(quarter_name)
election_channel: nextcord.TextChannel = await category.create_text_channel(quarter_name)
with Session(engine) as session:
new_cycle = ElectionInformation(ElectionCycle=quarter_name, ElectionChannel=election_channel.id)
session.add(new_cycle)
@@ -146,41 +167,43 @@ class ElectionCycle:
async def voting_start_action(self) -> None:
"""
Performs required actions for when voting for candidates starts.
Sends message informing members that voting has started.
Removes write permission from the general clan member role.
Adds the voting emote to all messages not sent by the vote. (This is temporary until voting is managed.)
"""
print("Voting has started")
await self.message_me("Voting has started")
message = self.build_vote_start()
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)
await election_channel.send(message)
await election_channel.set_permissions(clan_member_role, send_messages=False)
async def voting_end_action(self) -> None:
"""
Performs required actions for when voting time has ended.
"""
print("voting has ended")
await self.message_me("voting has ended")
message = self.build_highcouncil_election_announce()
council_elect_role: nextcord.Role = self.guild.get_role(self.config.params.clan_council_elect_role_id)
election_channel: nextcord.TextChannel = self.guild.get_channel(self.get_election_info().ElectionChannel)
await election_channel.send(message)
await election_channel.set_permissions(council_elect_role, send_messages=True)
async def highcouncil_election_action(self) -> None:
async def highcouncil_election_start_action(self) -> None:
"""
Performs required actions for when the highcouncil is elected.
"""
print("Highcouncil election has started.")
await self.message_me("Highcouncil election has started.")
message = self.build_highcouncil_vote_start()
election_channel: nextcord.TextChannel = self.guild.get_channel(self.get_election_info().ElectionChannel)
await election_channel.send(message)
async def term_start_action(self) -> None:
msg: str = "the term has started"
print(msg)
self.message_me(msg)
async def term_end_action(self):
msg: str = "the term has ended"
print(msg)
self.message_me(msg)
async def message_me(self, msg: str):
"""
message a string to me
Moves the election channel into the archive category.
"""
imcompiling: nextcord.User = await self.bot.fetch_user(206602713511886849)
await imcompiling.send(msg)
election_channel: nextcord.TextChannel = self.guild.get_channel(self.get_election_info().ElectionChannel)
archive: nextcord.CategoryChannel = self.guild.get_channel(self.config.params.archive_channel_group_id)
await election_channel.move(beginning=True, category=archive)
def get_election_cycle_name(self) -> str:
"""
@@ -191,3 +214,17 @@ class ElectionCycle:
"""
return f"{self.election_start.year} {self.elecion_cycle.name} election"
def get_election_info(self) -> ElectionInformation:
"""
Gets information for current election.
Returns:
ElectionInformation: The information from the database about the current election.
"""
with Session(engine) as session:
stmt = select(ElectionInformation).where(
ElectionInformation.ElectionCycle == self.get_election_cycle_name()
)
return session.scalar(stmt)
+11
View File
@@ -53,3 +53,14 @@ class TestCog(commands.Cog, name="Test commands."):
cycle = ElectionCycle(0, self.bot)
await cycle.election_start_action()
@test.subcommand()
async def voting_start(self, interaction: nextcord.Interaction):
"""
tests the voting start action
Args:
interaction (nextcord.Interaction): _description_
"""
cycle = ElectionCycle(0, self.bot)
await cycle.voting_start_action()
+1
View File
@@ -18,6 +18,7 @@ class Params:
clan_info_channel_id: int
clan_member_role_id: int
discord_token: str
guild_id: int
high_council_role_id: int
voting_emote_id: str
+2 -1
View File
@@ -1,3 +1,4 @@
Discord permissions required for bot to operate:
manage channels
manage channels
manage roles