Compare commits
30
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a55a90b922 | ||
|
|
7e0ff1da18 | ||
|
|
eb5102578d | ||
|
|
306e0d687a | ||
|
|
8fb59ba394 | ||
|
|
7b521893d3 | ||
|
|
19e654aed0 | ||
|
|
0d38bc82c4 | ||
|
|
b64e2471fa | ||
|
|
0b5330f7ca | ||
|
|
4e64eac176 | ||
|
|
c90ddf42c3 | ||
|
|
8eb2457ae9 | ||
|
|
2bdb7cb17b | ||
|
|
07906aaea1 | ||
|
|
9109ac53b3 | ||
|
|
47a33128be | ||
|
|
fdb04149aa | ||
|
|
4805f6cd5d | ||
|
|
ff85c8d485 | ||
|
|
ca0d27a929 | ||
|
|
8ebb689ee7 | ||
|
|
ecc81c5f35 | ||
|
|
96c1fcb17c | ||
|
|
840e17e03a | ||
|
|
f744d0d387 | ||
|
|
9c71d24fe3 | ||
|
|
cdc335936c | ||
|
|
303f0aa804 | ||
|
|
bc743cbb1a |
Vendored
+11
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"cSpell.words": [
|
||||||
|
"aiofiles",
|
||||||
|
"autofilled",
|
||||||
|
"blurple",
|
||||||
|
"CLANLEADER",
|
||||||
|
"Dakiny",
|
||||||
|
"DISCORDMANAGER",
|
||||||
|
"highcouncil"
|
||||||
|
]
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
FROM python:3.11.9-slim
|
FROM python:3.12.3-slim
|
||||||
|
|
||||||
# install dependencies
|
# install dependencies
|
||||||
RUN apt-get update && apt-get -y upgrade && apt-get -y install git sqlite3
|
RUN apt-get update && apt-get -y upgrade && apt-get -y install git sqlite3
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ from utils import (
|
|||||||
REQUIRED_VOTES_TO_BE_ELECTED = 3
|
REQUIRED_VOTES_TO_BE_ELECTED = 3
|
||||||
|
|
||||||
|
|
||||||
class ElectionCycle:
|
class Election:
|
||||||
"""
|
"""
|
||||||
ElectionCycle class.
|
Election class.
|
||||||
|
|
||||||
This class represents all the dates required for an election cycle along with all the functions needed to operate
|
This class represents all the dates required for an election cycle along with all the functions needed to operate
|
||||||
the cycle.
|
the cycle.
|
||||||
@@ -183,7 +183,7 @@ class ElectionCycle:
|
|||||||
# create new entry into database.
|
# create new entry into database.
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
new_cycle = ElectionInformation(
|
new_cycle = ElectionInformation(
|
||||||
ElectionCycle=quarter_name,
|
ElectionName=quarter_name,
|
||||||
ThreadId=thread.id,
|
ThreadId=thread.id,
|
||||||
CouncilNominationMsgId=nominate_msg.id,
|
CouncilNominationMsgId=nominate_msg.id,
|
||||||
)
|
)
|
||||||
@@ -206,9 +206,7 @@ class ElectionCycle:
|
|||||||
)
|
)
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(ElectionInformation).where(
|
stmt = select(ElectionInformation).where(ElectionInformation.ElectionName == get_election_name(self.config))
|
||||||
ElectionInformation.ElectionCycle == get_election_name(self.config)
|
|
||||||
)
|
|
||||||
info = session.scalar(stmt)
|
info = session.scalar(stmt)
|
||||||
info.CouncilVoteMsgId = vote_msg.id
|
info.CouncilVoteMsgId = vote_msg.id
|
||||||
session.commit()
|
session.commit()
|
||||||
@@ -231,7 +229,7 @@ class ElectionCycle:
|
|||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
# remove vote button from vote message
|
# remove vote button from vote message
|
||||||
stmt = select(ElectionInformation).where(ElectionInformation.ElectionCycle == election_name)
|
stmt = select(ElectionInformation).where(ElectionInformation.ElectionName == election_name)
|
||||||
info = session.scalar(stmt)
|
info = session.scalar(stmt)
|
||||||
vote_msg: nextcord.Message = await election_thread.fetch_message(info.CouncilVoteMsgId)
|
vote_msg: nextcord.Message = await election_thread.fetch_message(info.CouncilVoteMsgId)
|
||||||
await vote_msg.edit(view=None)
|
await vote_msg.edit(view=None)
|
||||||
@@ -243,7 +241,7 @@ class ElectionCycle:
|
|||||||
# add the highcouncil role to everyone with 3 or more votes. set elected to true in database
|
# add the highcouncil role to everyone with 3 or more votes. set elected to true in database
|
||||||
stmt = (
|
stmt = (
|
||||||
select(Votes.VotedForId)
|
select(Votes.VotedForId)
|
||||||
.where(Votes.ElectionCycle == election_name)
|
.where(Votes.ElectionName == election_name)
|
||||||
.where(Votes.Type == VoteType.COUNCIL)
|
.where(Votes.Type == VoteType.COUNCIL)
|
||||||
)
|
)
|
||||||
vote_count = collections.Counter(session.scalars(stmt))
|
vote_count = collections.Counter(session.scalars(stmt))
|
||||||
@@ -252,7 +250,7 @@ class ElectionCycle:
|
|||||||
if votes >= REQUIRED_VOTES_TO_BE_ELECTED:
|
if votes >= REQUIRED_VOTES_TO_BE_ELECTED:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CouncilMembers)
|
select(CouncilMembers)
|
||||||
.where(CouncilMembers.ElectionCycle == election_name)
|
.where(CouncilMembers.ElectionName == election_name)
|
||||||
.where(CouncilMembers.MemberId == user_id)
|
.where(CouncilMembers.MemberId == user_id)
|
||||||
)
|
)
|
||||||
council_member = session.scalar(stmt)
|
council_member = session.scalar(stmt)
|
||||||
@@ -277,9 +275,7 @@ class ElectionCycle:
|
|||||||
)
|
)
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(ElectionInformation).where(
|
stmt = select(ElectionInformation).where(ElectionInformation.ElectionName == get_election_name(self.config))
|
||||||
ElectionInformation.ElectionCycle == get_election_name(self.config)
|
|
||||||
)
|
|
||||||
info = session.scalar(stmt)
|
info = session.scalar(stmt)
|
||||||
info.HighCouncilVoteMsgId = vote_msg.id
|
info.HighCouncilVoteMsgId = vote_msg.id
|
||||||
session.commit()
|
session.commit()
|
||||||
@@ -295,13 +291,13 @@ class ElectionCycle:
|
|||||||
elect_role: nextcord.Role = self.guild.get_role(self.config.params.clan_council_elect_role_id)
|
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)
|
council_role: nextcord.Role = self.guild.get_role(self.config.params.clan_council_role_id)
|
||||||
|
|
||||||
election_cycle = get_election_name(self.config)
|
election_name = get_election_name(self.config)
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
# role management
|
# role management
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CouncilMembers.MemberId)
|
select(CouncilMembers.MemberId)
|
||||||
.where(CouncilMembers.ElectionCycle == election_cycle)
|
.where(CouncilMembers.ElectionName == election_name)
|
||||||
.where(CouncilMembers.Elected == true())
|
.where(CouncilMembers.Elected == true())
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -320,13 +316,13 @@ class ElectionCycle:
|
|||||||
# ties are undefined behavior.
|
# ties are undefined behavior.
|
||||||
stmt = (
|
stmt = (
|
||||||
select(Votes.VotedForId)
|
select(Votes.VotedForId)
|
||||||
.where(Votes.ElectionCycle == election_cycle)
|
.where(Votes.ElectionName == election_name)
|
||||||
.where(Votes.Type == VoteType.DISCORDMANAGER)
|
.where(Votes.Type == VoteType.DISCORDMANAGER)
|
||||||
)
|
)
|
||||||
dm_votes = collections.Counter(session.scalars(stmt))
|
dm_votes = collections.Counter(session.scalars(stmt))
|
||||||
stmt = (
|
stmt = (
|
||||||
select(Votes.VotedForId)
|
select(Votes.VotedForId)
|
||||||
.where(Votes.ElectionCycle == election_cycle)
|
.where(Votes.ElectionName == election_name)
|
||||||
.where(Votes.Type == VoteType.CLANLEADER)
|
.where(Votes.Type == VoteType.CLANLEADER)
|
||||||
)
|
)
|
||||||
cl_votes = collections.Counter(session.scalars(stmt))
|
cl_votes = collections.Counter(session.scalars(stmt))
|
||||||
@@ -335,7 +331,7 @@ class ElectionCycle:
|
|||||||
dm_winner = max(dm_votes, key=dm_votes.get)
|
dm_winner = max(dm_votes, key=dm_votes.get)
|
||||||
stmt = (
|
stmt = (
|
||||||
update(CouncilMembers)
|
update(CouncilMembers)
|
||||||
.where(CouncilMembers.ElectionCycle == election_cycle)
|
.where(CouncilMembers.ElectionName == election_name)
|
||||||
.where(CouncilMembers.MemberId == dm_winner)
|
.where(CouncilMembers.MemberId == dm_winner)
|
||||||
.values(DiscordManager=True)
|
.values(DiscordManager=True)
|
||||||
)
|
)
|
||||||
@@ -346,7 +342,7 @@ class ElectionCycle:
|
|||||||
cl_winner = max(cl_votes, key=cl_votes.get)
|
cl_winner = max(cl_votes, key=cl_votes.get)
|
||||||
stmt = (
|
stmt = (
|
||||||
update(CouncilMembers)
|
update(CouncilMembers)
|
||||||
.where(CouncilMembers.ElectionCycle == election_cycle)
|
.where(CouncilMembers.ElectionName == election_name)
|
||||||
.where(CouncilMembers.MemberId == cl_winner)
|
.where(CouncilMembers.MemberId == cl_winner)
|
||||||
.values(ClanLeader=True)
|
.values(ClanLeader=True)
|
||||||
)
|
)
|
||||||
@@ -360,7 +356,7 @@ class ElectionCycle:
|
|||||||
|
|
||||||
# clear view from vote message
|
# clear view from vote message
|
||||||
stmt = select(ElectionInformation.HighCouncilVoteMsgId).where(
|
stmt = select(ElectionInformation.HighCouncilVoteMsgId).where(
|
||||||
ElectionInformation.ElectionCycle == get_election_name(self.config)
|
ElectionInformation.ElectionName == get_election_name(self.config)
|
||||||
)
|
)
|
||||||
vote_msg_id = session.scalar(stmt)
|
vote_msg_id = session.scalar(stmt)
|
||||||
vote_msg: nextcord.Message = await election_thread.fetch_message(vote_msg_id)
|
vote_msg: nextcord.Message = await election_thread.fetch_message(vote_msg_id)
|
||||||
@@ -383,9 +379,7 @@ class ElectionCycle:
|
|||||||
ElectionInformation: The information from the database about the current election.
|
ElectionInformation: The information from the database about the current election.
|
||||||
"""
|
"""
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(ElectionInformation).where(
|
stmt = select(ElectionInformation).where(ElectionInformation.ElectionName == get_election_name(self.config))
|
||||||
ElectionInformation.ElectionCycle == get_election_name(self.config)
|
|
||||||
)
|
|
||||||
return session.scalar(stmt)
|
return session.scalar(stmt)
|
||||||
|
|
||||||
async def election_reminder(self) -> None:
|
async def election_reminder(self) -> None:
|
||||||
@@ -58,10 +58,10 @@ class NominateDMModal(nextcord.ui.Modal):
|
|||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
# user already in table
|
# user already in table
|
||||||
cycle = get_election_name(self.config)
|
election_name = get_election_name(self.config)
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CouncilMembers)
|
select(CouncilMembers)
|
||||||
.where(CouncilMembers.ElectionCycle == cycle)
|
.where(CouncilMembers.ElectionName == election_name)
|
||||||
.where(CouncilMembers.MemberId == self.usr_id)
|
.where(CouncilMembers.MemberId == self.usr_id)
|
||||||
)
|
)
|
||||||
council_elect = session.scalar(stmt)
|
council_elect = session.scalar(stmt)
|
||||||
@@ -120,10 +120,10 @@ class NominateCLModal(nextcord.ui.Modal):
|
|||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
# user already in table
|
# user already in table
|
||||||
cycle = get_election_name(self.config)
|
election_name = get_election_name(self.config)
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CouncilMembers)
|
select(CouncilMembers)
|
||||||
.where(CouncilMembers.ElectionCycle == cycle)
|
.where(CouncilMembers.ElectionName == election_name)
|
||||||
.where(CouncilMembers.MemberId == self.usr_id)
|
.where(CouncilMembers.MemberId == self.usr_id)
|
||||||
)
|
)
|
||||||
council_elect = session.scalar(stmt)
|
council_elect = session.scalar(stmt)
|
||||||
@@ -170,13 +170,13 @@ class NominateHighCouncilView(nextcord.ui.View):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
cycle = get_election_name(self.config)
|
election_name = get_election_name(self.config)
|
||||||
usr_nominated = False
|
usr_nominated = False
|
||||||
speech_content = ""
|
speech_content = ""
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CouncilMembers)
|
select(CouncilMembers)
|
||||||
.where(CouncilMembers.ElectionCycle == cycle)
|
.where(CouncilMembers.ElectionName == election_name)
|
||||||
.where(CouncilMembers.MemberId == interaction.user.id)
|
.where(CouncilMembers.MemberId == interaction.user.id)
|
||||||
)
|
)
|
||||||
obj = session.scalar(stmt)
|
obj = session.scalar(stmt)
|
||||||
@@ -215,13 +215,13 @@ class NominateHighCouncilView(nextcord.ui.View):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
cycle = get_election_name(self.config)
|
election_name = get_election_name(self.config)
|
||||||
usr_nominated = False
|
usr_nominated = False
|
||||||
speech_content = ""
|
speech_content = ""
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CouncilMembers)
|
select(CouncilMembers)
|
||||||
.where(CouncilMembers.ElectionCycle == cycle)
|
.where(CouncilMembers.ElectionName == election_name)
|
||||||
.where(CouncilMembers.MemberId == interaction.user.id)
|
.where(CouncilMembers.MemberId == interaction.user.id)
|
||||||
)
|
)
|
||||||
obj = session.scalar(stmt)
|
obj = session.scalar(stmt)
|
||||||
|
|||||||
@@ -50,13 +50,14 @@ class NominateModal(nextcord.ui.Modal):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
speech = decorate_nomination(interaction.user.id, self.speech.value)
|
speech = decorate_nomination(interaction.user.id, self.speech.value)
|
||||||
|
election_name = get_election_name(self.config)
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
if not self.usr_nominated:
|
if not self.usr_nominated:
|
||||||
msg = await interaction.channel.send(speech)
|
msg = await interaction.channel.send(speech)
|
||||||
|
|
||||||
council_member = CouncilMembers(
|
council_member = CouncilMembers(
|
||||||
ElectionCycle=get_election_name(self.config),
|
ElectionName=election_name,
|
||||||
MemberId=interaction.user.id,
|
MemberId=interaction.user.id,
|
||||||
SpeechMsgId=msg.id,
|
SpeechMsgId=msg.id,
|
||||||
)
|
)
|
||||||
@@ -64,10 +65,9 @@ class NominateModal(nextcord.ui.Modal):
|
|||||||
session.commit()
|
session.commit()
|
||||||
else:
|
else:
|
||||||
# user already nominated, just need to update the election speech
|
# user already nominated, just need to update the election speech
|
||||||
cycle = get_election_name(self.config)
|
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CouncilMembers)
|
select(CouncilMembers)
|
||||||
.where(CouncilMembers.ElectionCycle == cycle)
|
.where(CouncilMembers.ElectionName == election_name)
|
||||||
.where(CouncilMembers.MemberId == self.usr_id)
|
.where(CouncilMembers.MemberId == self.usr_id)
|
||||||
)
|
)
|
||||||
obj = session.scalar(stmt)
|
obj = session.scalar(stmt)
|
||||||
@@ -91,7 +91,7 @@ class NominateView(nextcord.ui.View):
|
|||||||
)
|
)
|
||||||
async def nominate(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
|
async def nominate(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
|
||||||
"""
|
"""
|
||||||
Button to nominate onself for Clan Council.
|
Button to nominate oneself for Clan Council.
|
||||||
|
|
||||||
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.
|
||||||
@@ -108,13 +108,13 @@ class NominateView(nextcord.ui.View):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
cycle = get_election_name(self.config)
|
election_name = get_election_name(self.config)
|
||||||
usr_nominated = False
|
usr_nominated = False
|
||||||
speech_content = ""
|
speech_content = ""
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CouncilMembers)
|
select(CouncilMembers)
|
||||||
.where(CouncilMembers.ElectionCycle == cycle)
|
.where(CouncilMembers.ElectionName == election_name)
|
||||||
.where(CouncilMembers.MemberId == interaction.user.id)
|
.where(CouncilMembers.MemberId == interaction.user.id)
|
||||||
)
|
)
|
||||||
obj = session.scalar(stmt)
|
obj = session.scalar(stmt)
|
||||||
|
|||||||
@@ -41,14 +41,14 @@ class VoteSelect(nextcord.ui.StringSelect):
|
|||||||
election_name: str = get_election_name(self.config)
|
election_name: str = get_election_name(self.config)
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(ElectionInformation.HighCouncilVoteMsgId).where(
|
stmt = select(ElectionInformation.HighCouncilVoteMsgId).where(
|
||||||
ElectionInformation.ElectionCycle == election_name
|
ElectionInformation.ElectionName == election_name
|
||||||
)
|
)
|
||||||
vote_msg_id = session.scalar(stmt)
|
vote_msg_id = session.scalar(stmt)
|
||||||
|
|
||||||
voted_for = None if self.values[0] == "Abstain" else int(self.values[0])
|
voted_for = None if self.values[0] == "Abstain" else int(self.values[0])
|
||||||
|
|
||||||
new_vote = Votes(
|
new_vote = Votes(
|
||||||
ElectionCycle=election_name,
|
ElectionName=election_name,
|
||||||
VoterId=interaction.user.id,
|
VoterId=interaction.user.id,
|
||||||
VotedForId=voted_for,
|
VotedForId=voted_for,
|
||||||
Type=self.election_type,
|
Type=self.election_type,
|
||||||
@@ -63,7 +63,7 @@ class VoteSelect(nextcord.ui.StringSelect):
|
|||||||
session.rollback()
|
session.rollback()
|
||||||
stmt = (
|
stmt = (
|
||||||
update(Votes)
|
update(Votes)
|
||||||
.where(Votes.ElectionCycle == election_name)
|
.where(Votes.ElectionName == election_name)
|
||||||
.where(Votes.VoterId == interaction.user.id)
|
.where(Votes.VoterId == interaction.user.id)
|
||||||
.where(Votes.Type == self.election_type)
|
.where(Votes.Type == self.election_type)
|
||||||
.values(VotedForId=voted_for)
|
.values(VotedForId=voted_for)
|
||||||
@@ -118,7 +118,7 @@ class VoteHighcouncilView(nextcord.ui.View):
|
|||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(Votes.VotedForId)
|
select(Votes.VotedForId)
|
||||||
.where(Votes.ElectionCycle == election_name)
|
.where(Votes.ElectionName == election_name)
|
||||||
.where(Votes.VoterId == interaction.user.id)
|
.where(Votes.VoterId == interaction.user.id)
|
||||||
.where(Votes.Type == VoteType.CLANLEADER)
|
.where(Votes.Type == VoteType.CLANLEADER)
|
||||||
)
|
)
|
||||||
@@ -126,7 +126,7 @@ class VoteHighcouncilView(nextcord.ui.View):
|
|||||||
|
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CouncilMembers.MemberId)
|
select(CouncilMembers.MemberId)
|
||||||
.where(CouncilMembers.ElectionCycle == election_name)
|
.where(CouncilMembers.ElectionName == election_name)
|
||||||
.filter(CouncilMembers.ClanLeaderSpeechId.is_not(None))
|
.filter(CouncilMembers.ClanLeaderSpeechId.is_not(None))
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ class VoteHighcouncilView(nextcord.ui.View):
|
|||||||
)
|
)
|
||||||
for nominee in sorted(
|
for nominee in sorted(
|
||||||
session.scalars(stmt),
|
session.scalars(stmt),
|
||||||
key=lambda nominee: self.guild.get_member(nominee).display_name,
|
key=lambda nominee: self.guild.get_member(nominee).display_name.lower(),
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
options.append(
|
options.append(
|
||||||
@@ -190,7 +190,7 @@ class VoteHighcouncilView(nextcord.ui.View):
|
|||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(Votes.VotedForId)
|
select(Votes.VotedForId)
|
||||||
.where(Votes.ElectionCycle == election_name)
|
.where(Votes.ElectionName == election_name)
|
||||||
.where(Votes.VoterId == interaction.user.id)
|
.where(Votes.VoterId == interaction.user.id)
|
||||||
.where(Votes.Type == VoteType.DISCORDMANAGER)
|
.where(Votes.Type == VoteType.DISCORDMANAGER)
|
||||||
)
|
)
|
||||||
@@ -198,7 +198,7 @@ class VoteHighcouncilView(nextcord.ui.View):
|
|||||||
|
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CouncilMembers.MemberId)
|
select(CouncilMembers.MemberId)
|
||||||
.where(CouncilMembers.ElectionCycle == election_name)
|
.where(CouncilMembers.ElectionName == election_name)
|
||||||
.filter(CouncilMembers.DiscordManagerSpeechId.is_not(None))
|
.filter(CouncilMembers.DiscordManagerSpeechId.is_not(None))
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -213,7 +213,7 @@ class VoteHighcouncilView(nextcord.ui.View):
|
|||||||
)
|
)
|
||||||
for nominee in sorted(
|
for nominee in sorted(
|
||||||
session.scalars(stmt),
|
session.scalars(stmt),
|
||||||
key=lambda nominee: self.guild.get_member(nominee).display_name,
|
key=lambda nominee: self.guild.get_member(nominee).display_name.lower(),
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
options.append(
|
options.append(
|
||||||
|
|||||||
@@ -39,15 +39,13 @@ class VoteSelect(nextcord.ui.StringSelect):
|
|||||||
"""
|
"""
|
||||||
election_name = get_election_name(self.config)
|
election_name = get_election_name(self.config)
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(ElectionInformation.CouncilVoteMsgId).where(
|
stmt = select(ElectionInformation.CouncilVoteMsgId).where(ElectionInformation.ElectionName == election_name)
|
||||||
ElectionInformation.ElectionCycle == election_name
|
|
||||||
)
|
|
||||||
vote_msg_id = session.scalar(stmt)
|
vote_msg_id = session.scalar(stmt)
|
||||||
|
|
||||||
voted_for = None if self.values[0] == "Abstain" else int(self.values[0])
|
voted_for = None if self.values[0] == "Abstain" else int(self.values[0])
|
||||||
|
|
||||||
new_vote = Votes(
|
new_vote = Votes(
|
||||||
ElectionCycle=election_name,
|
ElectionName=election_name,
|
||||||
VoterId=interaction.user.id,
|
VoterId=interaction.user.id,
|
||||||
VotedForId=voted_for,
|
VotedForId=voted_for,
|
||||||
Type=VoteType.COUNCIL,
|
Type=VoteType.COUNCIL,
|
||||||
@@ -61,7 +59,7 @@ class VoteSelect(nextcord.ui.StringSelect):
|
|||||||
session.rollback()
|
session.rollback()
|
||||||
stmt = (
|
stmt = (
|
||||||
update(Votes)
|
update(Votes)
|
||||||
.where(Votes.ElectionCycle == election_name)
|
.where(Votes.ElectionName == election_name)
|
||||||
.where(Votes.VoterId == interaction.user.id)
|
.where(Votes.VoterId == interaction.user.id)
|
||||||
.where(Votes.Type == VoteType.COUNCIL)
|
.where(Votes.Type == VoteType.COUNCIL)
|
||||||
.values(VotedForId=voted_for)
|
.values(VotedForId=voted_for)
|
||||||
@@ -106,18 +104,18 @@ class VoteView(nextcord.ui.View):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
election: str = get_election_name(self.config)
|
election_name: str = get_election_name(self.config)
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(Votes.VotedForId)
|
select(Votes.VotedForId)
|
||||||
.where(Votes.ElectionCycle == election)
|
.where(Votes.ElectionName == election_name)
|
||||||
.where(Votes.VoterId == interaction.user.id)
|
.where(Votes.VoterId == interaction.user.id)
|
||||||
.where(Votes.Type == VoteType.COUNCIL)
|
.where(Votes.Type == VoteType.COUNCIL)
|
||||||
)
|
)
|
||||||
voted_for = session.scalar(stmt)
|
voted_for = session.scalar(stmt)
|
||||||
|
|
||||||
stmt = select(CouncilMembers.MemberId).where(CouncilMembers.ElectionCycle == election)
|
stmt = select(CouncilMembers.MemberId).where(CouncilMembers.ElectionName == election_name)
|
||||||
|
|
||||||
options = [
|
options = [
|
||||||
SelectOption(
|
SelectOption(
|
||||||
@@ -130,7 +128,7 @@ class VoteView(nextcord.ui.View):
|
|||||||
)
|
)
|
||||||
for nominee in sorted(
|
for nominee in sorted(
|
||||||
session.scalars(stmt),
|
session.scalars(stmt),
|
||||||
key=lambda nominee: self.guild.get_member(nominee).display_name,
|
key=lambda nominee: self.guild.get_member(nominee).display_name.lower(),
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
options.append(
|
options.append(
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from cogs.commands.remove import RemoveCog
|
|||||||
from cogs.commands.request import RequestCog
|
from cogs.commands.request import RequestCog
|
||||||
from cogs.commands.set import SetCog
|
from cogs.commands.set import SetCog
|
||||||
from cogs.commands.test import TestCog
|
from cogs.commands.test import TestCog
|
||||||
|
from cogs.commands.time import TimeCog
|
||||||
from cogs.commands.view import ViewCog
|
from cogs.commands.view import ViewCog
|
||||||
|
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ def setup(bot: commands.Bot) -> None:
|
|||||||
bot.add_cog(RefreshCog(bot))
|
bot.add_cog(RefreshCog(bot))
|
||||||
bot.add_cog(RemoveCog())
|
bot.add_cog(RemoveCog())
|
||||||
bot.add_cog(RequestCog(bot))
|
bot.add_cog(RequestCog(bot))
|
||||||
bot.add_cog(TestCog(bot))
|
|
||||||
bot.add_cog(ViewCog())
|
|
||||||
bot.add_cog(SetCog())
|
bot.add_cog(SetCog())
|
||||||
|
bot.add_cog(TestCog(bot))
|
||||||
|
bot.add_cog(TimeCog())
|
||||||
|
bot.add_cog(ViewCog())
|
||||||
|
|||||||
+85
-3
@@ -5,7 +5,7 @@ from discord import TextInputStyle
|
|||||||
from nextcord.ext import commands
|
from nextcord.ext import commands
|
||||||
|
|
||||||
from config import DakinyConfig
|
from config import DakinyConfig
|
||||||
from utils import record_event_points
|
from utils import GUILDS, MAX_DISCORD_MESSAGE_LENGTH, record_event_points
|
||||||
|
|
||||||
|
|
||||||
class RecordCog(commands.Cog, name="Record Commands"):
|
class RecordCog(commands.Cog, name="Record Commands"):
|
||||||
@@ -16,7 +16,7 @@ class RecordCog(commands.Cog, name="Record Commands"):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.bot: commands.Bot = bot
|
self.bot: commands.Bot = bot
|
||||||
|
|
||||||
@nextcord.slash_command()
|
@nextcord.slash_command(guild_ids=GUILDS)
|
||||||
async def record(self, interaction: nextcord.Interaction) -> None:
|
async def record(self, interaction: nextcord.Interaction) -> None:
|
||||||
"""Parent slash command for record. Never called."""
|
"""Parent slash command for record. Never called."""
|
||||||
|
|
||||||
@@ -64,6 +64,88 @@ class RecordCog(commands.Cog, name="Record Commands"):
|
|||||||
embed=embed,
|
embed=embed,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@record.subcommand(description="Record a miscellaneous point for a clan member.")
|
||||||
|
async def point(
|
||||||
|
self,
|
||||||
|
interaction: nextcord.Interaction,
|
||||||
|
activity: str = nextcord.SlashOption(
|
||||||
|
description="The type of activity to receive points for.",
|
||||||
|
required=True,
|
||||||
|
choices=[
|
||||||
|
"Clan chat activity",
|
||||||
|
"Teaching or sharing in-game tips",
|
||||||
|
"Recruiting efforts",
|
||||||
|
"Successful recruitment",
|
||||||
|
],
|
||||||
|
),
|
||||||
|
justification: str = nextcord.SlashOption(
|
||||||
|
required=True,
|
||||||
|
description="Reason to give the recipient a point.",
|
||||||
|
max_length=int(MAX_DISCORD_MESSAGE_LENGTH / 2),
|
||||||
|
),
|
||||||
|
recipient: nextcord.Member = nextcord.SlashOption(
|
||||||
|
required=False,
|
||||||
|
description="Discord user to give point to.",
|
||||||
|
),
|
||||||
|
non_discord_recipient: str = nextcord.SlashOption(
|
||||||
|
required=False, description="Non Discord user to give point to.", max_length=32
|
||||||
|
),
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Gives a point to the provided recipient. Sends recording message to event participation channel.
|
||||||
|
|
||||||
|
Only one recipient should be given point/provided to the command. Fails if not exactly one recipient
|
||||||
|
is given.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): interaction with this command.
|
||||||
|
activity (str): Choice list of activities to give point for.
|
||||||
|
justification (str): Reason to give point.
|
||||||
|
recipient (nextcord.Member): Discord member to give point to.
|
||||||
|
non_discord_recipient (str): Non Discord member to give point to.
|
||||||
|
"""
|
||||||
|
# role check
|
||||||
|
if interaction.guild.get_role(self.bot.config.params.clan_member_role_id) not in interaction.user.roles:
|
||||||
|
await interaction.response.send_message(
|
||||||
|
f"You must have the <@&{self.bot.config.params.clan_member_role_id}> role to record points.",
|
||||||
|
ephemeral=True,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
# pylint or whatever seems to think that there are lines of unreachable code. That is false.
|
||||||
|
if recipient and non_discord_recipient:
|
||||||
|
await interaction.response.send_message("Please only provide 1 recipient.", ephemeral=True)
|
||||||
|
return
|
||||||
|
elif recipient is not None: # noqa: RET505
|
||||||
|
record_event_points(
|
||||||
|
self.bot.config,
|
||||||
|
[str(recipient.id)],
|
||||||
|
self.bot.config.params.event_participate_points,
|
||||||
|
is_member=True,
|
||||||
|
)
|
||||||
|
recipient_str = f"<@{recipient.id}>"
|
||||||
|
elif non_discord_recipient is not None:
|
||||||
|
record_event_points(
|
||||||
|
self.bot.config,
|
||||||
|
[non_discord_recipient],
|
||||||
|
self.bot.config.params.event_participate_points,
|
||||||
|
is_member=False,
|
||||||
|
)
|
||||||
|
recipient_str = f'"{non_discord_recipient}"'
|
||||||
|
else:
|
||||||
|
await interaction.response.send_message("You must provide a recipient.", ephemeral=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
event_channel: nextcord.TextChannel = interaction.guild.get_channel(
|
||||||
|
self.bot.config.params.event_post_channel_id
|
||||||
|
)
|
||||||
|
|
||||||
|
msg = f"<@{interaction.user.id}> has given {recipient_str} points for the {activity} activity. Justification: {justification}" # noqa: E501
|
||||||
|
if not msg.endswith("."):
|
||||||
|
msg += "."
|
||||||
|
await event_channel.send(msg)
|
||||||
|
await interaction.response.send_message("Point has been added.", ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
class EventView(nextcord.ui.View):
|
class EventView(nextcord.ui.View):
|
||||||
"""
|
"""
|
||||||
@@ -109,8 +191,8 @@ class EventView(nextcord.ui.View):
|
|||||||
record_event_points(
|
record_event_points(
|
||||||
self.config,
|
self.config,
|
||||||
discord_users_list,
|
discord_users_list,
|
||||||
True, # noqa: FBT003
|
|
||||||
self.config.params.event_participate_points,
|
self.config.params.event_participate_points,
|
||||||
|
is_member=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
non_discord_users = interaction.message.embeds[0].fields[1].value
|
non_discord_users = interaction.message.embeds[0].fields[1].value
|
||||||
|
|||||||
+9
-10
@@ -5,15 +5,14 @@ from typing import TYPE_CHECKING
|
|||||||
import nextcord
|
import nextcord
|
||||||
from nextcord.ext import application_checks, commands
|
from nextcord.ext import application_checks, commands
|
||||||
|
|
||||||
from classes.election_cycle import ElectionCycle
|
from classes.election import Election
|
||||||
from utils import get_current_election_cycle
|
from utils import GUILDS, get_current_election_cycle
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from config import DakinyConfig
|
from config import DakinyConfig
|
||||||
|
|
||||||
|
|
||||||
ME = 206602713511886849
|
ME = 206602713511886849
|
||||||
GUILDS = [1000247361639030804]
|
|
||||||
|
|
||||||
|
|
||||||
def is_me(): # noqa: ANN201
|
def is_me(): # noqa: ANN201
|
||||||
@@ -46,7 +45,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
config: DakinyConfig = self.bot.config
|
config: DakinyConfig = self.bot.config
|
||||||
cycle = ElectionCycle(
|
cycle = Election(
|
||||||
get_current_election_cycle(config),
|
get_current_election_cycle(config),
|
||||||
config,
|
config,
|
||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(config.params.guild_id),
|
||||||
@@ -64,7 +63,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
config: DakinyConfig = self.bot.config
|
config: DakinyConfig = self.bot.config
|
||||||
cycle = ElectionCycle(
|
cycle = Election(
|
||||||
get_current_election_cycle(config),
|
get_current_election_cycle(config),
|
||||||
config,
|
config,
|
||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(config.params.guild_id),
|
||||||
@@ -82,7 +81,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
config: DakinyConfig = self.bot.config
|
config: DakinyConfig = self.bot.config
|
||||||
cycle = ElectionCycle(
|
cycle = Election(
|
||||||
get_current_election_cycle(config),
|
get_current_election_cycle(config),
|
||||||
config,
|
config,
|
||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(config.params.guild_id),
|
||||||
@@ -100,7 +99,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
config: DakinyConfig = self.bot.config
|
config: DakinyConfig = self.bot.config
|
||||||
cycle = ElectionCycle(
|
cycle = Election(
|
||||||
get_current_election_cycle(config),
|
get_current_election_cycle(config),
|
||||||
config,
|
config,
|
||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(config.params.guild_id),
|
||||||
@@ -118,7 +117,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
config: DakinyConfig = self.bot.config
|
config: DakinyConfig = self.bot.config
|
||||||
cycle = ElectionCycle(
|
cycle = Election(
|
||||||
get_current_election_cycle(config),
|
get_current_election_cycle(config),
|
||||||
config,
|
config,
|
||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(config.params.guild_id),
|
||||||
@@ -136,7 +135,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
config: DakinyConfig = self.bot.config
|
config: DakinyConfig = self.bot.config
|
||||||
cycle = ElectionCycle(
|
cycle = Election(
|
||||||
get_current_election_cycle(config),
|
get_current_election_cycle(config),
|
||||||
config,
|
config,
|
||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(config.params.guild_id),
|
||||||
@@ -154,7 +153,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
config: DakinyConfig = self.bot.config
|
config: DakinyConfig = self.bot.config
|
||||||
cycle = ElectionCycle(
|
cycle = Election(
|
||||||
get_current_election_cycle(config),
|
get_current_election_cycle(config),
|
||||||
config,
|
config,
|
||||||
self.bot.get_guild(config.params.guild_id),
|
self.bot.get_guild(config.params.guild_id),
|
||||||
|
|||||||
@@ -0,0 +1,109 @@
|
|||||||
|
"""Contains commands for time commands."""
|
||||||
|
|
||||||
|
from datetime import MAXYEAR, MINYEAR, UTC, datetime
|
||||||
|
|
||||||
|
import nextcord
|
||||||
|
from nextcord.ext import commands
|
||||||
|
|
||||||
|
from utils import GUILDS
|
||||||
|
|
||||||
|
|
||||||
|
class TimeCog(commands.Cog, name="Time Commands"):
|
||||||
|
"""Class holds time commands."""
|
||||||
|
|
||||||
|
@nextcord.slash_command(guild_ids=GUILDS)
|
||||||
|
async def time(self, interaction: nextcord.Interaction) -> None:
|
||||||
|
"""Parent slash command. Never called."""
|
||||||
|
|
||||||
|
@time.subcommand(
|
||||||
|
description="Get a discord timestamp of the given game time. If date information is left blank, uses current day." # noqa: E501
|
||||||
|
)
|
||||||
|
async def at( # noqa: PLR0913
|
||||||
|
self,
|
||||||
|
interaction: nextcord.Interaction,
|
||||||
|
hour: int = nextcord.SlashOption(
|
||||||
|
description="The hour you want a timestamp of. Given in gametime/UTC.",
|
||||||
|
min_value=0,
|
||||||
|
max_value=23,
|
||||||
|
required=True,
|
||||||
|
),
|
||||||
|
minute: int = nextcord.SlashOption(
|
||||||
|
description="The minute you want a timestamp of. Given in gametime/UTC.",
|
||||||
|
min_value=0,
|
||||||
|
max_value=59,
|
||||||
|
required=True,
|
||||||
|
),
|
||||||
|
year: int = nextcord.SlashOption(
|
||||||
|
description="Year to make timestamp of.", required=False, min_value=MINYEAR, max_value=MAXYEAR
|
||||||
|
),
|
||||||
|
month: int = nextcord.SlashOption(
|
||||||
|
description="Month to make timestamp of.", required=False, min_value=1, max_value=12
|
||||||
|
),
|
||||||
|
day: int = nextcord.SlashOption(
|
||||||
|
description="Day to make timestamp of.", required=False, min_value=1, max_value=31
|
||||||
|
),
|
||||||
|
ephemeral: bool = nextcord.SlashOption( # noqa: FBT001
|
||||||
|
description="Whether the replying message will be public or not.", required=False, default=True
|
||||||
|
),
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Replies with a discord timestamp of given UTC time.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Interaction with the command.
|
||||||
|
hour (int): The hour in UTC to make the timestamp of..
|
||||||
|
minute (int): The minute in UTC to make the timestamp of..
|
||||||
|
year (int): The year to make the timestamp of.
|
||||||
|
month (int): The month to make the timestamp of.
|
||||||
|
day (int): The day to make the timestamp of.
|
||||||
|
ephemeral (bool): Whether the response is ephemeral or not.
|
||||||
|
"""
|
||||||
|
gametime_today: datetime = datetime.now(tz=UTC).replace(hour=hour, minute=minute)
|
||||||
|
|
||||||
|
if year is not None:
|
||||||
|
gametime_today = gametime_today.replace(year=year)
|
||||||
|
|
||||||
|
if month is not None and day is not None:
|
||||||
|
try:
|
||||||
|
gametime_today = gametime_today.replace(month=month, day=day)
|
||||||
|
except ValueError:
|
||||||
|
await interaction.response.send_message(f"Day {day} is out of range for month {month}.", ephemeral=True)
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
if month is not None:
|
||||||
|
try:
|
||||||
|
gametime_today = gametime_today.replace(month=month)
|
||||||
|
except ValueError:
|
||||||
|
await interaction.response.send_message(
|
||||||
|
f"Today ({gametime_today.day}) is out of range for month {month}.", ephemeral=True
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
if day is not None:
|
||||||
|
try:
|
||||||
|
gametime_today = gametime_today.replace(day=day)
|
||||||
|
except ValueError:
|
||||||
|
await interaction.response.send_message(
|
||||||
|
f"Day {day} is out of range for this month {gametime_today.month}.", ephemeral=True
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
await interaction.response.send_message(content=f"<t:{int(gametime_today.timestamp())}:t>", ephemeral=ephemeral)
|
||||||
|
|
||||||
|
@time.subcommand(description="Get the current time in game.")
|
||||||
|
async def gametime(
|
||||||
|
self,
|
||||||
|
interaction: nextcord.Interaction,
|
||||||
|
ephemeral: bool = nextcord.SlashOption( # noqa: FBT001
|
||||||
|
description="Whether the replying message will be public or not.", required=False, default=True
|
||||||
|
),
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Replies with the current time in game.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Interaction with the command.
|
||||||
|
ephemeral: (bool): Whether the response is ephemeral or not.
|
||||||
|
"""
|
||||||
|
gametime = datetime.now(tz=UTC)
|
||||||
|
await interaction.response.send_message(content=f"{gametime.hour}:{gametime.minute}", ephemeral=ephemeral)
|
||||||
+17
-15
@@ -7,7 +7,7 @@ from sqlalchemy import select
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from database_setup.sql_data_classes import (
|
from database_setup.sql_data_classes import (
|
||||||
ParticipationPoints,
|
EventPoints,
|
||||||
Presences,
|
Presences,
|
||||||
Votes,
|
Votes,
|
||||||
engine,
|
engine,
|
||||||
@@ -49,14 +49,12 @@ class ViewCog(commands.Cog, name="View Commands"):
|
|||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
if quarter_name:
|
if quarter_name:
|
||||||
ppdf = pd.read_sql_query(
|
ppdf = pd.read_sql_query(
|
||||||
sql=session.query(ParticipationPoints)
|
sql=session.query(EventPoints).where(EventPoints.QuarterName.startswith(quarter_name)).statement,
|
||||||
.where(ParticipationPoints.Cycle.startswith(quarter_name))
|
|
||||||
.statement,
|
|
||||||
con=engine,
|
con=engine,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
ppdf = pd.read_sql_query(
|
ppdf = pd.read_sql_query(
|
||||||
sql=session.query(ParticipationPoints).statement,
|
sql=session.query(EventPoints).statement,
|
||||||
con=engine,
|
con=engine,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -64,20 +62,24 @@ class ViewCog(commands.Cog, name="View Commands"):
|
|||||||
await interaction.followup.send(f'Quarter "{quarter_name}" is invalid.', ephemeral=True)
|
await interaction.followup.send(f'Quarter "{quarter_name}" is invalid.', ephemeral=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
cycles = ppdf.groupby("Cycle")
|
quarters = ppdf.groupby("QuarterName")
|
||||||
content = ""
|
content = ""
|
||||||
for cycle in cycles.groups:
|
for quarter in quarters.groups:
|
||||||
content += f"**{cycle}**\n"
|
content += f"**{quarter}**\n"
|
||||||
unsorted_all = cycles.get_group(cycle).groupby("DiscordMember")
|
unsorted_all = quarters.get_group(quarter).groupby("DiscordMember")
|
||||||
members = unsorted_all.get_group(name=True)
|
members = unsorted_all.get_group(name=True)
|
||||||
non_members = unsorted_all.get_group(name=False)
|
|
||||||
|
# there can be no non-discord members sometimes.
|
||||||
|
try:
|
||||||
|
sorted_non_members = unsorted_all.get_group(name=False).sort_values(by="UserId")
|
||||||
|
except KeyError:
|
||||||
|
sorted_non_members = None
|
||||||
sorted_members = members.sort_values(
|
sorted_members = members.sort_values(
|
||||||
by="UserId",
|
by="UserId",
|
||||||
key=lambda user_ids: (
|
key=lambda user_ids: (
|
||||||
[interaction.guild.get_member(int(user_id)).display_name for user_id in user_ids]
|
[interaction.guild.get_member(int(user_id)).display_name.lower() for user_id in user_ids]
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
sorted_non_members = non_members.sort_values(by="UserId")
|
|
||||||
sorted_all = pd.concat([sorted_members, sorted_non_members], ignore_index=True, sort=False)
|
sorted_all = pd.concat([sorted_members, sorted_non_members], ignore_index=True, sort=False)
|
||||||
for row in sorted_all.itertuples():
|
for row in sorted_all.itertuples():
|
||||||
userid = row.UserId
|
userid = row.UserId
|
||||||
@@ -147,7 +149,7 @@ class ViewCog(commands.Cog, name="View Commands"):
|
|||||||
election_name (str): Is SlashOption. The name of the election to view votes for.
|
election_name (str): Is SlashOption. The name of the election to view votes for.
|
||||||
election_type(str): Is SlashOption. The type of election to search for. Choice from StrEnum VoteType.
|
election_type(str): Is SlashOption. The type of election to search for. Choice from StrEnum VoteType.
|
||||||
"""
|
"""
|
||||||
stmt = select(Votes).where(Votes.ElectionCycle == election_name).where(Votes.Type == election_type)
|
stmt = select(Votes).where(Votes.ElectionName == election_name).where(Votes.Type == election_type)
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
# Check if election exists.
|
# Check if election exists.
|
||||||
@@ -176,7 +178,7 @@ class ViewCog(commands.Cog, name="View Commands"):
|
|||||||
election_name (str): String to run autocomplete on.
|
election_name (str): String to run autocomplete on.
|
||||||
"""
|
"""
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(Votes.ElectionCycle).distinct()
|
stmt = select(Votes.ElectionName).distinct()
|
||||||
elections = session.scalars(stmt)
|
elections = session.scalars(stmt)
|
||||||
|
|
||||||
# if empty compare string
|
# if empty compare string
|
||||||
@@ -199,7 +201,7 @@ class ViewCog(commands.Cog, name="View Commands"):
|
|||||||
quarter_name (str): String to run autocomplete on.
|
quarter_name (str): String to run autocomplete on.
|
||||||
"""
|
"""
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(ParticipationPoints.Cycle).distinct()
|
stmt = select(EventPoints.QuarterName).distinct()
|
||||||
quarters = session.scalars(stmt)
|
quarters = session.scalars(stmt)
|
||||||
|
|
||||||
# if empty compare string
|
# if empty compare string
|
||||||
|
|||||||
@@ -35,4 +35,4 @@ class BotPresence(commands.Cog, name="Bot Presence"):
|
|||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
presence = session.scalar(select(Presences.Presence).order_by(func.random()))
|
presence = session.scalar(select(Presences.Presence).order_by(func.random()))
|
||||||
|
|
||||||
await self.bot.change_presence(activity=nextcord.CustomActivity(name="Custom Status", state=presence))
|
await self.bot.change_presence(activity=nextcord.CustomActivity(presence))
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from pytz import timezone
|
|||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from classes.election_cycle import ElectionCycle
|
from classes.election import Election
|
||||||
from database_setup.sql_data_classes import UserBirthday, engine
|
from database_setup.sql_data_classes import UserBirthday, engine
|
||||||
from main import birthday_list
|
from main import birthday_list
|
||||||
from utils import get_current_election_cycle
|
from utils import get_current_election_cycle
|
||||||
@@ -43,7 +43,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
|||||||
election is over to delete the current election object.
|
election is over to delete the current election object.
|
||||||
"""
|
"""
|
||||||
if self.current_election is None:
|
if self.current_election is None:
|
||||||
self.current_election = self.get_election_cycle()
|
self.current_election = self.get_election()
|
||||||
|
|
||||||
if self.current_election is not None:
|
if self.current_election is not None:
|
||||||
await self.current_election.check_date()
|
await self.current_election.check_date()
|
||||||
@@ -65,16 +65,16 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
|||||||
await self.bot.wait_until_ready()
|
await self.bot.wait_until_ready()
|
||||||
|
|
||||||
# Bot needs to know guilds to get the current cycle.
|
# Bot needs to know guilds to get the current cycle.
|
||||||
self.current_election = self.get_election_cycle()
|
self.current_election = self.get_election()
|
||||||
|
|
||||||
def get_election_cycle(self) -> ElectionCycle:
|
def get_election(self) -> Election:
|
||||||
"""
|
"""
|
||||||
Creates an object for the current election cycle if one is active.
|
Creates an object for the current election cycle if one is active.
|
||||||
|
|
||||||
An election is considered active between the election start and the term start.
|
An election is considered active between the election start and the term start.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
ElectionCycle: Current election cycle, None if there is no election happening.
|
Election: Current election cycle, None if there is no election happening.
|
||||||
"""
|
"""
|
||||||
config: DakinyConfig = self.bot.config
|
config: DakinyConfig = self.bot.config
|
||||||
cycle = get_current_election_cycle(config)
|
cycle = get_current_election_cycle(config)
|
||||||
@@ -83,7 +83,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
|||||||
if cycle is None:
|
if cycle is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return ElectionCycle(cycle, config, self.bot.get_guild(config.params.guild_id))
|
return Election(cycle, config, self.bot.get_guild(config.params.guild_id))
|
||||||
|
|
||||||
def update_birthdays(self) -> None:
|
def update_birthdays(self) -> None:
|
||||||
"""Goes through database to collect all birthdays that are today. Adds user's id to birthday list."""
|
"""Goes through database to collect all birthdays that are today. Adds user's id to birthday list."""
|
||||||
@@ -91,7 +91,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
|||||||
|
|
||||||
# kandy's 1% chance
|
# kandy's 1% chance
|
||||||
if random.randint(0, 99) == 0: # noqa: S311 isn't cryptography related.
|
if random.randint(0, 99) == 0: # noqa: S311 isn't cryptography related.
|
||||||
birthday_list.append(239547993106284544)
|
birthday_list.append(KANDY)
|
||||||
|
|
||||||
today = datetime.now(tz=UTC).date()
|
today = datetime.now(tz=UTC).date()
|
||||||
birthday = f"{today.month}/{today.day}"
|
birthday = f"{today.month}/{today.day}"
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class Params:
|
|||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ElectionCycle:
|
class Election:
|
||||||
"""Class defines relevant election dates."""
|
"""Class defines relevant election dates."""
|
||||||
|
|
||||||
election_start: str
|
election_start: str
|
||||||
@@ -45,5 +45,5 @@ class ElectionCycle:
|
|||||||
class DakinyConfig:
|
class DakinyConfig:
|
||||||
"""Class defines all configs required for Dakiny Bot."""
|
"""Class defines all configs required for Dakiny Bot."""
|
||||||
|
|
||||||
election_cycles: list[ElectionCycle]
|
election_cycles: list[Election]
|
||||||
params: Params
|
params: Params
|
||||||
|
|||||||
+11
-11
@@ -1,15 +1,15 @@
|
|||||||
CREATE TABLE ElectionInformation(
|
CREATE TABLE ElectionInformation(
|
||||||
ElectionCycle varchar(30) not null unique,
|
ElectionName varchar(30) not null unique,
|
||||||
ThreadId bigint unsigned not null,
|
ThreadId bigint unsigned not null,
|
||||||
CouncilVoteMsgId bigint unsigned,
|
CouncilVoteMsgId bigint unsigned,
|
||||||
HighCouncilVoteMsgId bigint unsigned,
|
HighCouncilVoteMsgId bigint unsigned,
|
||||||
CouncilNominationMsgId bigint unsigned,
|
CouncilNominationMsgId bigint unsigned,
|
||||||
HighCouncilNominationMsgId bigint unsigned,
|
HighCouncilNominationMsgId bigint unsigned,
|
||||||
PRIMARY KEY (ElectionCycle)
|
PRIMARY KEY (ElectionName)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE CouncilMembers(
|
CREATE TABLE CouncilMembers(
|
||||||
ElectionCycle varchar(30) not null,
|
ElectionName varchar(30) not null,
|
||||||
MemberId bigint unsigned not null,
|
MemberId bigint unsigned not null,
|
||||||
SpeechMsgId bigint unsigned not null,
|
SpeechMsgId bigint unsigned not null,
|
||||||
Elected boolean DEFAULT false,
|
Elected boolean DEFAULT false,
|
||||||
@@ -17,17 +17,17 @@ CREATE TABLE CouncilMembers(
|
|||||||
ClanLeader boolean DEFAULT false,
|
ClanLeader boolean DEFAULT false,
|
||||||
DiscordManagerSpeechId bigint unsigned,
|
DiscordManagerSpeechId bigint unsigned,
|
||||||
ClanLeaderSpeechId bigint unsigned,
|
ClanLeaderSpeechId bigint unsigned,
|
||||||
FOREIGN KEY (ElectionCycle) REFERENCES ElectionInformation(ElectionCycle),
|
FOREIGN KEY (ElectionName) REFERENCES ElectionInformation(ElectionName),
|
||||||
PRIMARY KEY (ElectionCycle, MemberId)
|
PRIMARY KEY (ElectionName, MemberId)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE Votes(
|
CREATE TABLE Votes(
|
||||||
ElectionCycle varchar(30) not null,
|
ElectionName varchar(30) not null,
|
||||||
VoterId bigint unsigned not null,
|
VoterId bigint unsigned not null,
|
||||||
VotedForId bigint unsigned,
|
VotedForId bigint unsigned,
|
||||||
Type varchar(14) not null DEFAULT 'council' check("Type" in ('council', 'discordmanager', 'clanleader')),
|
Type varchar(14) not null DEFAULT 'council' check("Type" in ('council', 'discordmanager', 'clanleader')),
|
||||||
FOREIGN KEY (ElectionCycle) REFERENCES ElectionInformation(ElectionCycle),
|
FOREIGN KEY (ElectionName) REFERENCES ElectionInformation(ElectionName),
|
||||||
PRIMARY KEY (ElectionCycle, VoterId, Type)
|
PRIMARY KEY (ElectionName, VoterId, Type)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE UserBirthday (
|
CREATE TABLE UserBirthday (
|
||||||
@@ -41,12 +41,12 @@ CREATE TABLE Presences (
|
|||||||
Presence varchar(100) not null
|
Presence varchar(100) not null
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE ParticipationPoints (
|
CREATE TABLE EventPoints (
|
||||||
Cycle varchar(30) not null,
|
QuarterName varchar(30) not null,
|
||||||
UserId varchar(32) not null,
|
UserId varchar(32) not null,
|
||||||
DiscordMember boolean not null,
|
DiscordMember boolean not null,
|
||||||
Points int unsigned DEFAULT 0,
|
Points int unsigned DEFAULT 0,
|
||||||
PRIMARY KEY (Cycle, UserId)
|
PRIMARY KEY (QuarterName, UserId)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE Messages (
|
CREATE TABLE Messages (
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ CouncilMembers = Base.classes.CouncilMembers
|
|||||||
ElectionInformation = Base.classes.ElectionInformation
|
ElectionInformation = Base.classes.ElectionInformation
|
||||||
EventPointsLimit = Base.classes.EventPointsLimit
|
EventPointsLimit = Base.classes.EventPointsLimit
|
||||||
Messages = Base.classes.Messages
|
Messages = Base.classes.Messages
|
||||||
ParticipationPoints = Base.classes.ParticipationPoints
|
EventPoints = Base.classes.EventPoints
|
||||||
Presences = Base.classes.Presences
|
Presences = Base.classes.Presences
|
||||||
UserBirthday = Base.classes.UserBirthday
|
UserBirthday = Base.classes.UserBirthday
|
||||||
Votes = Base.classes.Votes
|
Votes = Base.classes.Votes
|
||||||
|
|||||||
+12
-11
@@ -7,20 +7,21 @@ readme = "README.md"
|
|||||||
package-mode = false
|
package-mode = false
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.11"
|
python = "^3.12"
|
||||||
gitpython = "3.1.43"
|
gitpython = "^3.1.43"
|
||||||
fastapi = "0.111.0"
|
fastapi = "^0.111.0"
|
||||||
hydra-core = "1.3.2"
|
hydra-core = "^1.3.2"
|
||||||
nextcord = "2.4.2"
|
nextcord = "^2.6.0"
|
||||||
pandas = "1.5.2"
|
pandas = "^2.2.2"
|
||||||
python-dotenv = "1.0.0"
|
python-dotenv = "^1.0.1"
|
||||||
pytz = "2022.7.1"
|
pytz = "^2024.1"
|
||||||
sqlalchemy = "1.4.46"
|
sqlalchemy = "^2.0.30"
|
||||||
aiofiles = "^23.2.1"
|
aiofiles = "^23.2.1"
|
||||||
|
setuptools = "^70.0.0"
|
||||||
|
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
[tool.poetry.group.dev.dependencies]
|
||||||
ruff = "^0.4.5"
|
ruff = "^0.6.3"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core"]
|
requires = ["poetry-core"]
|
||||||
@@ -63,7 +64,7 @@ line-length = 120
|
|||||||
indent-width = 4
|
indent-width = 4
|
||||||
|
|
||||||
# Assume Python 3.8
|
# Assume Python 3.8
|
||||||
target-version = "py311"
|
target-version = "py312"
|
||||||
|
|
||||||
[tool.ruff.lint]
|
[tool.ruff.lint]
|
||||||
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
|
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
python-3.10.4
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
"""File contains util functions."""
|
"""File contains util functions."""
|
||||||
|
|
||||||
|
import calendar
|
||||||
import os
|
import os
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from datetime import UTC, datetime
|
from datetime import UTC, datetime
|
||||||
@@ -14,9 +15,9 @@ from sqlalchemy.orm import Session
|
|||||||
from config import DakinyConfig
|
from config import DakinyConfig
|
||||||
from database_setup.sql_data_classes import (
|
from database_setup.sql_data_classes import (
|
||||||
CouncilMembers,
|
CouncilMembers,
|
||||||
|
EventPoints,
|
||||||
EventPointsLimit,
|
EventPointsLimit,
|
||||||
Messages,
|
Messages,
|
||||||
ParticipationPoints,
|
|
||||||
Votes,
|
Votes,
|
||||||
engine,
|
engine,
|
||||||
)
|
)
|
||||||
@@ -26,6 +27,7 @@ REPO_DIR = "./dakiny-messages"
|
|||||||
MESSAGES_DIR = f"{REPO_DIR}/messages"
|
MESSAGES_DIR = f"{REPO_DIR}/messages"
|
||||||
TEMPLATES_DIR = f"{REPO_DIR}/message_templates"
|
TEMPLATES_DIR = f"{REPO_DIR}/message_templates"
|
||||||
MAX_DISCORD_MESSAGE_LENGTH = 2000
|
MAX_DISCORD_MESSAGE_LENGTH = 2000
|
||||||
|
GUILDS = [1000247361639030804, 239758371358638080]
|
||||||
|
|
||||||
VoteType = StrEnum("VoteType", ["COUNCIL", "DISCORDMANAGER", "CLANLEADER"])
|
VoteType = StrEnum("VoteType", ["COUNCIL", "DISCORDMANAGER", "CLANLEADER"])
|
||||||
|
|
||||||
@@ -46,12 +48,10 @@ def get_datetime(day: str) -> datetime:
|
|||||||
day = int(day.split("/")[1])
|
day = int(day.split("/")[1])
|
||||||
|
|
||||||
# ensure that year rolls over if current month is December and the next month is less than 12.
|
# ensure that year rolls over if current month is December and the next month is less than 12.
|
||||||
# TODO(imcompiling): replace with Calendar.DECEMBER when updating to python 3.12
|
if today.month == calendar.DECEMBER and month < calendar.DECEMBER:
|
||||||
# https://gitea.cheezers.org/imcompiling/dakiny-bot/issues/52
|
|
||||||
if today.month == 12 and month < 12:
|
|
||||||
year += 1
|
year += 1
|
||||||
|
|
||||||
if today.month == 1 and month > 1:
|
if today.month == calendar.JANUARY and month > calendar.JANUARY:
|
||||||
year -= 1
|
year -= 1
|
||||||
|
|
||||||
return datetime(year, month, day, tzinfo=UTC)
|
return datetime(year, month, day, tzinfo=UTC)
|
||||||
@@ -137,7 +137,7 @@ def build_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str:
|
|||||||
Creates a string that contains all nominees and their votes to be sent as a discord message.
|
Creates a string that contains all nominees and their votes to be sent as a discord message.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
config (DakinyConfig): Daking config object
|
config (DakinyConfig): Dakiny config object
|
||||||
guild (nextcord.Guild): The guild object. Used to get display names for sorting.
|
guild (nextcord.Guild): The guild object. Used to get display names for sorting.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@@ -148,15 +148,15 @@ def build_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str:
|
|||||||
election_name = get_election_name(config)
|
election_name = get_election_name(config)
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = select(CouncilMembers).where(CouncilMembers.ElectionCycle == election_name)
|
stmt = select(CouncilMembers).where(CouncilMembers.ElectionName == election_name)
|
||||||
|
|
||||||
for nominee in sorted(
|
for nominee in sorted(
|
||||||
session.scalars(stmt),
|
session.scalars(stmt),
|
||||||
key=lambda nominee: guild.get_member(nominee.MemberId).display_name,
|
key=lambda nominee: guild.get_member(nominee.MemberId).display_name.lower(),
|
||||||
):
|
):
|
||||||
votes[nominee.MemberId] = 0
|
votes[nominee.MemberId] = 0
|
||||||
|
|
||||||
stmt = select(Votes).where(Votes.ElectionCycle == election_name).where(Votes.Type == VoteType.COUNCIL)
|
stmt = select(Votes).where(Votes.ElectionName == election_name).where(Votes.Type == VoteType.COUNCIL)
|
||||||
|
|
||||||
for vote in session.scalars(stmt):
|
for vote in session.scalars(stmt):
|
||||||
if vote.VotedForId is not None:
|
if vote.VotedForId is not None:
|
||||||
@@ -173,7 +173,7 @@ def build_highcouncil_votes_str(config: DakinyConfig, guild: nextcord.Guild) ->
|
|||||||
Creates a string that contains all high council nominees and their votes to be sent as a discord message.
|
Creates a string that contains all high council nominees and their votes to be sent as a discord message.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
config (DakinyConfig): Daking config object
|
config (DakinyConfig): Dakiny config object
|
||||||
guild (nextcord.Guild): The guild object. Used to get display names for sorting.
|
guild (nextcord.Guild): The guild object. Used to get display names for sorting.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@@ -187,17 +187,17 @@ def build_highcouncil_votes_str(config: DakinyConfig, guild: nextcord.Guild) ->
|
|||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CouncilMembers)
|
select(CouncilMembers)
|
||||||
.where(CouncilMembers.ElectionCycle == election_name)
|
.where(CouncilMembers.ElectionName == election_name)
|
||||||
.filter(CouncilMembers.ClanLeaderSpeechId.is_not(None))
|
.filter(CouncilMembers.ClanLeaderSpeechId.is_not(None))
|
||||||
)
|
)
|
||||||
|
|
||||||
for nominee in sorted(
|
for nominee in sorted(
|
||||||
session.scalars(stmt),
|
session.scalars(stmt),
|
||||||
key=lambda nominee: guild.get_member(nominee.MemberId).display_name,
|
key=lambda nominee: guild.get_member(nominee.MemberId).display_name.lower(),
|
||||||
):
|
):
|
||||||
cl_votes[nominee.MemberId] = 0
|
cl_votes[nominee.MemberId] = 0
|
||||||
|
|
||||||
stmt = select(Votes).where(Votes.ElectionCycle == election_name).where(Votes.Type == VoteType.CLANLEADER)
|
stmt = select(Votes).where(Votes.ElectionName == election_name).where(Votes.Type == VoteType.CLANLEADER)
|
||||||
|
|
||||||
for vote in session.scalars(stmt):
|
for vote in session.scalars(stmt):
|
||||||
if vote.VotedForId is not None:
|
if vote.VotedForId is not None:
|
||||||
@@ -205,17 +205,17 @@ def build_highcouncil_votes_str(config: DakinyConfig, guild: nextcord.Guild) ->
|
|||||||
|
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CouncilMembers)
|
select(CouncilMembers)
|
||||||
.where(CouncilMembers.ElectionCycle == election_name)
|
.where(CouncilMembers.ElectionName == election_name)
|
||||||
.filter(CouncilMembers.DiscordManagerSpeechId.is_not(None))
|
.filter(CouncilMembers.DiscordManagerSpeechId.is_not(None))
|
||||||
)
|
)
|
||||||
|
|
||||||
for nominee in sorted(
|
for nominee in sorted(
|
||||||
session.scalars(stmt),
|
session.scalars(stmt),
|
||||||
key=lambda nominee: guild.get_member(nominee.MemberId).display_name,
|
key=lambda nominee: guild.get_member(nominee.MemberId).display_name.lower(),
|
||||||
):
|
):
|
||||||
dm_votes[nominee.MemberId] = 0
|
dm_votes[nominee.MemberId] = 0
|
||||||
|
|
||||||
stmt = select(Votes).where(Votes.ElectionCycle == election_name).where(Votes.Type == VoteType.DISCORDMANAGER)
|
stmt = select(Votes).where(Votes.ElectionName == election_name).where(Votes.Type == VoteType.DISCORDMANAGER)
|
||||||
|
|
||||||
for vote in session.scalars(stmt):
|
for vote in session.scalars(stmt):
|
||||||
if vote.VotedForId is not None:
|
if vote.VotedForId is not None:
|
||||||
@@ -318,17 +318,13 @@ def record_event_points(config: DakinyConfig, users: Sequence[str], add_points:
|
|||||||
quarter_name = get_quarter_name(config)
|
quarter_name = get_quarter_name(config)
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
for user in users:
|
for user in users:
|
||||||
stmt = (
|
stmt = select(EventPoints).where(EventPoints.UserId == user).where(EventPoints.QuarterName == quarter_name)
|
||||||
select(ParticipationPoints)
|
|
||||||
.where(ParticipationPoints.UserId == user)
|
|
||||||
.where(ParticipationPoints.Cycle == quarter_name)
|
|
||||||
)
|
|
||||||
|
|
||||||
points = session.scalar(stmt)
|
points = session.scalar(stmt)
|
||||||
if points is None:
|
if points is None:
|
||||||
add_points = get_allowed_points(session, config.params.event_points_weekly_limit, user, add_points)
|
add_points = get_allowed_points(session, config.params.event_points_weekly_limit, user, add_points)
|
||||||
new_points = ParticipationPoints(
|
new_points = EventPoints(
|
||||||
Cycle=quarter_name,
|
QuarterName=quarter_name,
|
||||||
UserId=user,
|
UserId=user,
|
||||||
DiscordMember=is_member,
|
DiscordMember=is_member,
|
||||||
Points=add_points,
|
Points=add_points,
|
||||||
@@ -371,11 +367,7 @@ def get_allowed_points(session: Session, points_limit: int, user: str, points: i
|
|||||||
add_points = points
|
add_points = points
|
||||||
session.add(new_limit)
|
session.add(new_limit)
|
||||||
else:
|
else:
|
||||||
add_points = (
|
add_points = points if limit.Points + points <= points_limit else (max(0, points_limit - limit.Points))
|
||||||
points
|
|
||||||
if limit.Points + points <= points_limit
|
|
||||||
else (points_limit - limit.Points if points_limit - limit.Points > 0 else 0)
|
|
||||||
)
|
|
||||||
limit.Points += add_points
|
limit.Points += add_points
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
@@ -512,7 +504,7 @@ async def edit_clan_message(
|
|||||||
|
|
||||||
async def edit_clan_council_info(guild: nextcord.Guild, config: DakinyConfig) -> None:
|
async def edit_clan_council_info(guild: nextcord.Guild, config: DakinyConfig) -> None:
|
||||||
"""
|
"""
|
||||||
Gets the winners of the elections and updates the perminant message that states the current council.
|
Gets the winners of the elections and updates the permanent message that states the current council.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
guild (nextcord.Guild): Guild object that to use to get channel.
|
guild (nextcord.Guild): Guild object that to use to get channel.
|
||||||
@@ -520,28 +512,32 @@ async def edit_clan_council_info(guild: nextcord.Guild, config: DakinyConfig) ->
|
|||||||
"""
|
"""
|
||||||
clan_info_channel: nextcord.TextChannel = await guild.fetch_channel(config.params.clan_info_channel_id)
|
clan_info_channel: nextcord.TextChannel = await guild.fetch_channel(config.params.clan_info_channel_id)
|
||||||
|
|
||||||
election = get_election_name(config)
|
election_name = get_election_name(config)
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CouncilMembers.MemberId)
|
select(CouncilMembers.MemberId)
|
||||||
.where(CouncilMembers.ElectionCycle == election)
|
.where(CouncilMembers.ElectionName == election_name)
|
||||||
.where(CouncilMembers.DiscordManager == true())
|
.where(CouncilMembers.DiscordManager == true())
|
||||||
)
|
)
|
||||||
discord_manager = session.scalar(stmt)
|
discord_manager = session.scalar(stmt)
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CouncilMembers.MemberId)
|
select(CouncilMembers.MemberId)
|
||||||
.where(CouncilMembers.ElectionCycle == election)
|
.where(CouncilMembers.ElectionName == election_name)
|
||||||
.where(CouncilMembers.ClanLeader == true())
|
.where(CouncilMembers.ClanLeader == true())
|
||||||
)
|
)
|
||||||
clan_leader = session.scalar(stmt)
|
clan_leader = session.scalar(stmt)
|
||||||
stmt = (
|
stmt = (
|
||||||
select(CouncilMembers.MemberId)
|
select(CouncilMembers.MemberId)
|
||||||
.where(CouncilMembers.ElectionCycle == election)
|
.where(CouncilMembers.ElectionName == election_name)
|
||||||
.where(CouncilMembers.Elected == true())
|
.where(CouncilMembers.Elected == true())
|
||||||
)
|
)
|
||||||
|
|
||||||
|
council_member_ids = sorted(
|
||||||
|
session.scalars(stmt), key=lambda user_id: guild.get_member(user_id).display_name.lower()
|
||||||
|
)
|
||||||
|
|
||||||
council_members_strs = [
|
council_members_strs = [
|
||||||
f"<@{user_id}>" for user_id in session.scalars(stmt) if user_id not in (discord_manager, clan_leader)
|
f"<@{user_id}>" for user_id in council_member_ids if user_id not in (discord_manager, clan_leader)
|
||||||
]
|
]
|
||||||
|
|
||||||
quarter = get_quarter_name(config)
|
quarter = get_quarter_name(config)
|
||||||
|
|||||||
Reference in New Issue
Block a user