Remove nomination views once they are done.
This commit is contained in:
+42
-19
@@ -201,16 +201,9 @@ class ElectionCycle:
|
|||||||
|
|
||||||
thread_msg: nextcord.Message = await parent.send(content=quarter_name)
|
thread_msg: nextcord.Message = await parent.send(content=quarter_name)
|
||||||
|
|
||||||
# create new entry into database.
|
|
||||||
thread: nextcord.Thread = await parent.create_thread(
|
thread: nextcord.Thread = await parent.create_thread(
|
||||||
name=quarter_name, message=thread_msg
|
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
|
# post message announcing election
|
||||||
# election start message is returned as an array of string because it is too long. send each string
|
# 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):
|
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, self.guild))
|
nominate_msg: nextcord.Message = await thread.send(
|
||||||
|
message, view=NominateView(self.config, self.guild)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
await thread.send(message)
|
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:
|
async def voting_start_action(self) -> None:
|
||||||
"""
|
"""
|
||||||
Sends message informing members that voting has started.
|
Sends message informing members that voting has started.
|
||||||
@@ -246,6 +251,12 @@ class ElectionCycle:
|
|||||||
info.CouncilVoteMsgId = vote_msg.id
|
info.CouncilVoteMsgId = vote_msg.id
|
||||||
session.commit()
|
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:
|
async def voting_end_action(self) -> None:
|
||||||
"""
|
"""
|
||||||
Performs required actions for when voting time has ended.
|
Performs required actions for when voting time has ended.
|
||||||
@@ -259,18 +270,28 @@ class ElectionCycle:
|
|||||||
self.get_election_info().ThreadId
|
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)
|
election_name = get_election_cycle_name(self.config)
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(ElectionInformation.CouncilVoteMsgId).where(
|
# remove vote button from vote message
|
||||||
|
stmt = select(ElectionInformation).where(
|
||||||
ElectionInformation.ElectionCycle == election_name
|
ElectionInformation.ElectionCycle == election_name
|
||||||
)
|
)
|
||||||
vote_msg_id = session.scalar(stmt)
|
info = session.scalar(stmt)
|
||||||
vote_msg: nextcord.Message = await election_thread.fetch_message(vote_msg_id)
|
vote_msg: nextcord.Message = await election_thread.fetch_message(
|
||||||
await vote_msg.edit(view=None)
|
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
|
# add the highcouncil nomination message to election information
|
||||||
with Session(engine) as session:
|
info.HighCouncilVoteMsgId = 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)
|
stmt = select(Votes.VotedForId).where(Votes.ElectionCycle == election_name)
|
||||||
vote_count = collections.Counter(session.scalars(stmt))
|
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.",
|
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:
|
async def highcouncil_election_start_action(self) -> None:
|
||||||
"""
|
"""
|
||||||
Performs required actions for when the highcouncil is elected.
|
Performs required actions for when the highcouncil is elected.
|
||||||
@@ -320,6 +337,12 @@ class ElectionCycle:
|
|||||||
info.HighCouncilVoteMsgId = vote_msg.id
|
info.HighCouncilVoteMsgId = vote_msg.id
|
||||||
session.commit()
|
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:
|
async def term_start_action(self) -> None:
|
||||||
"""
|
"""
|
||||||
Marks the election as over.
|
Marks the election as over.
|
||||||
|
|||||||
Reference in New Issue
Block a user