Compare commits

...
Author SHA1 Message Date
imcompiling 45b304308b Merge branch '35-remove-nomination-views'
build_latest / build (push) Successful in 45s
build_release / build (push) Successful in 45s
2023-12-17 15:36:50 -05:00
imcompiling 43ef19fd82 Cover highcouncil edge case.
build_develop / build (push) Successful in 1m29s
2023-12-17 15:36:04 -05:00
imcompiling 757d2e5c19 Stored nomination message in wrong place. 2023-12-17 15:27:54 -05:00
imcompiling 8394cdd6fd Remove nomination views once they are done. 2023-12-17 15:06:19 -05:00
imcompiling a9c3719c29 Add two new fields to election information. 2023-12-17 14:44:32 -05:00
imcompiling 250de5baf8 Merge branch '18-highcouncil-election'
build_latest / build (push) Successful in 1m39s
build_develop / build (push) Successful in 48s
2023-12-17 14:36:57 -05:00
2 changed files with 52 additions and 21 deletions
+50 -21
View File
@@ -201,16 +201,9 @@ class ElectionCycle:
thread_msg: nextcord.Message = await parent.send(content=quarter_name)
# create new entry into database.
thread: nextcord.Thread = await parent.create_thread(
name=quarter_name, message=thread_msg
)
with Session(engine) as session:
new_cycle = ElectionInformation(
ElectionCycle=quarter_name, ThreadId=thread.id
)
session.add(new_cycle)
session.commit()
# post message announcing election
# election start message is returned as an array of string because it is too long. send each string
@@ -219,10 +212,22 @@ class ElectionCycle:
for index, message in enumerate(messages):
# if last item, add the nominate button
if index + 1 == len(messages):
await thread.send(message, view=NominateView(self.config, self.guild))
nominate_msg: nextcord.Message = await thread.send(
message, view=NominateView(self.config, self.guild)
)
else:
await thread.send(message)
# create new entry into database.
with Session(engine) as session:
new_cycle = ElectionInformation(
ElectionCycle=quarter_name,
ThreadId=thread.id,
CouncilNominationMsgId=nominate_msg.id,
)
session.add(new_cycle)
session.commit()
async def voting_start_action(self) -> None:
"""
Sends message informing members that voting has started.
@@ -246,6 +251,12 @@ class ElectionCycle:
info.CouncilVoteMsgId = vote_msg.id
session.commit()
thread: nextcord.Thread = self.guild.get_thread(info.ThreadId)
nominate_msg: nextcord.Message = await thread.fetch_message(
info.CouncilNominationMsgId
)
await nominate_msg.edit(view=None)
async def voting_end_action(self) -> None:
"""
Performs required actions for when voting time has ended.
@@ -259,18 +270,28 @@ class ElectionCycle:
self.get_election_info().ThreadId
)
# remove vote button from vote message
nominate_msg: nextcord.Message = await election_thread.send(
message, view=NominateHighCouncilView(self.config, self.guild)
)
election_name = get_election_cycle_name(self.config)
with Session(engine) as session:
stmt = select(ElectionInformation.CouncilVoteMsgId).where(
# remove vote button from vote message
stmt = select(ElectionInformation).where(
ElectionInformation.ElectionCycle == election_name
)
vote_msg_id = session.scalar(stmt)
vote_msg: nextcord.Message = await election_thread.fetch_message(vote_msg_id)
await vote_msg.edit(view=None)
info = session.scalar(stmt)
vote_msg: nextcord.Message = await election_thread.fetch_message(
info.CouncilVoteMsgId
)
await vote_msg.edit(view=None)
# add the highcouncil role to everyone with 3 or more votes. set elected to true in database
with Session(engine) as session:
# add the highcouncil nomination message to election information
info.HighCouncilNominationMsgId = nominate_msg.id
session.commit()
# add the highcouncil role to everyone with 3 or more votes. set elected to true in database
stmt = select(Votes.VotedForId).where(Votes.ElectionCycle == election_name)
vote_count = collections.Counter(session.scalars(stmt))
@@ -292,10 +313,6 @@ class ElectionCycle:
reason=f"{member.display_name} has won a nomination and become a Council Elect.",
)
await election_thread.send(
message, view=NominateHighCouncilView(self.config, self.guild)
)
async def highcouncil_election_start_action(self) -> None:
"""
Performs required actions for when the highcouncil is elected.
@@ -320,6 +337,12 @@ class ElectionCycle:
info.HighCouncilVoteMsgId = vote_msg.id
session.commit()
# remove highcouncil nomination view
nomination_msg: nextcord.Message = await election_thread.fetch_message(
info.HighCouncilNominationMsgId
)
await nomination_msg.edit(view=None)
async def term_start_action(self) -> None:
"""
Marks the election as over.
@@ -364,8 +387,14 @@ class ElectionCycle:
stmt = select(Votes.VotedForId).where(Votes.ElectionCycle == cl_election)
cl_votes = collections.Counter(session.scalars(stmt))
dm_winner = max(dm_votes, key=dm_votes.get)
cl_winner = max(cl_votes, key=cl_votes.get)
try:
dm_winner = max(dm_votes, key=dm_votes.get)
except ValueError:
dm_winner = "No winner"
try:
cl_winner = max(cl_votes, key=cl_votes.get)
except ValueError:
cl_winner = "No winner"
election_thread: nextcord.Thread = self.guild.get_thread(
self.get_election_info().ThreadId
+2
View File
@@ -3,6 +3,8 @@ CREATE TABLE ElectionInformation(
ThreadId bigint unsigned not null,
CouncilVoteMsgId bigint unsigned,
HighCouncilVoteMsgId bigint unsigned,
CouncilNominationMsgId bigint unsigned,
HighCouncilNominationMsgId bigint unsigned,
PRIMARY KEY (ElectionCycle)
);