Compare commits
18
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62f53bde55 | ||
|
|
b15e99ca68 | ||
|
|
628152c22c | ||
|
|
f00b6502f6 | ||
|
|
a55a90b922 | ||
|
|
7e0ff1da18 | ||
|
|
eb5102578d | ||
|
|
306e0d687a | ||
|
|
8fb59ba394 | ||
|
|
7b521893d3 | ||
|
|
19e654aed0 | ||
|
|
0d38bc82c4 | ||
|
|
b64e2471fa | ||
|
|
0b5330f7ca | ||
|
|
4e64eac176 | ||
|
|
c90ddf42c3 | ||
|
|
8eb2457ae9 | ||
|
|
9109ac53b3 |
Vendored
+1
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"cSpell.words": [
|
||||
"aiofiles",
|
||||
"autofilled",
|
||||
"blurple",
|
||||
"CLANLEADER",
|
||||
"Dakiny",
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
"""File contains classes defining the Hydra configuraton structure."""
|
||||
"""File contains classes defining Dakiny settings structure."""
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from dataclass_wizard import YAMLWizard
|
||||
|
||||
CONFIG_LOCATION = "conf/config.yaml"
|
||||
|
||||
|
||||
@dataclass
|
||||
class Params:
|
||||
"""Class defines the various configuration parameters."""
|
||||
class Settings:
|
||||
"""Class defines settings editable by Clan Council."""
|
||||
|
||||
admin_channel_id: int # might want to rename this...
|
||||
announcement_category_id: int
|
||||
@@ -13,28 +17,34 @@ class Params:
|
||||
clan_council_role_id: int
|
||||
clan_info_channel_id: int
|
||||
clan_member_role_id: int
|
||||
discord_token: str
|
||||
event_host_points: int
|
||||
event_host_role_id: int
|
||||
event_participate_points: int
|
||||
event_points_weekly_limit: int
|
||||
event_post_channel_id: int
|
||||
general_channel_id: int
|
||||
git_branch: str
|
||||
guild_id: int
|
||||
high_council_role_id: int
|
||||
voting_parent_id: int
|
||||
|
||||
|
||||
@dataclass
|
||||
class ElectionCycle:
|
||||
class Params:
|
||||
"""Class defines start parameters that shouldn't be changed."""
|
||||
|
||||
discord_token: str
|
||||
git_branch: str
|
||||
guild_id: int
|
||||
|
||||
|
||||
@dataclass
|
||||
class Election:
|
||||
"""Class defines relevant election dates."""
|
||||
|
||||
name: str
|
||||
election_start: str
|
||||
highcouncil_election_announce: str
|
||||
highcouncil_election_end: str
|
||||
highcouncil_election_start: str
|
||||
name: str
|
||||
term_end: str
|
||||
term_start: str
|
||||
voting_end: str
|
||||
@@ -42,8 +52,16 @@ class ElectionCycle:
|
||||
|
||||
|
||||
@dataclass
|
||||
class DakinyConfig:
|
||||
class DakinySettings(YAMLWizard):
|
||||
"""Class defines all configs required for Dakiny Bot."""
|
||||
|
||||
election_cycles: list[ElectionCycle]
|
||||
election_cycles: list[Election]
|
||||
params: Params
|
||||
settings: Settings
|
||||
|
||||
def save(self) -> None:
|
||||
"""Saves settings to the yaml file."""
|
||||
self.to_yaml_file(CONFIG_LOCATION)
|
||||
|
||||
|
||||
settings = DakinySettings.from_yaml_file(CONFIG_LOCATION)
|
||||
@@ -9,7 +9,7 @@ from classes.nominate_highcouncil_views import NominateHighCouncilView
|
||||
from classes.nominate_views import NominateView
|
||||
from classes.voting_highcouncil_views import VoteHighcouncilView
|
||||
from classes.voting_views import VoteView
|
||||
from config import DakinyConfig
|
||||
from DakinySettings import DakinySettings
|
||||
from database_setup.sql_data_classes import (
|
||||
CouncilMembers,
|
||||
ElectionInformation,
|
||||
@@ -31,15 +31,15 @@ from utils import (
|
||||
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
|
||||
the cycle.
|
||||
"""
|
||||
|
||||
def __init__(self, cycle: int, config: DakinyConfig, guild: nextcord.Guild) -> None:
|
||||
def __init__(self, cycle: int, config: DakinySettings, guild: nextcord.Guild) -> None:
|
||||
"""
|
||||
Generates all dates relevant to the election cycle determined by the config and cycle.
|
||||
|
||||
@@ -48,7 +48,7 @@ class ElectionCycle:
|
||||
config (DakinyConfig): The entire config object.
|
||||
guild (nextcord.Guild): The guild that this election is running in.
|
||||
"""
|
||||
self.config: DakinyConfig = config
|
||||
self.config: DakinySettings = config
|
||||
self.cycle = cycle
|
||||
self.election_cycle = self.config.election_cycles[self.cycle]
|
||||
self.election_start: datetime = get_datetime(self.election_cycle.election_start)
|
||||
@@ -183,7 +183,7 @@ class ElectionCycle:
|
||||
# create new entry into database.
|
||||
with Session(engine) as session:
|
||||
new_cycle = ElectionInformation(
|
||||
ElectionCycle=quarter_name,
|
||||
ElectionName=quarter_name,
|
||||
ThreadId=thread.id,
|
||||
CouncilNominationMsgId=nominate_msg.id,
|
||||
)
|
||||
@@ -206,9 +206,7 @@ class ElectionCycle:
|
||||
)
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = select(ElectionInformation).where(
|
||||
ElectionInformation.ElectionCycle == get_election_name(self.config)
|
||||
)
|
||||
stmt = select(ElectionInformation).where(ElectionInformation.ElectionName == get_election_name(self.config))
|
||||
info = session.scalar(stmt)
|
||||
info.CouncilVoteMsgId = vote_msg.id
|
||||
session.commit()
|
||||
@@ -231,7 +229,7 @@ class ElectionCycle:
|
||||
|
||||
with Session(engine) as session:
|
||||
# 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)
|
||||
vote_msg: nextcord.Message = await election_thread.fetch_message(info.CouncilVoteMsgId)
|
||||
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
|
||||
stmt = (
|
||||
select(Votes.VotedForId)
|
||||
.where(Votes.ElectionCycle == election_name)
|
||||
.where(Votes.ElectionName == election_name)
|
||||
.where(Votes.Type == VoteType.COUNCIL)
|
||||
)
|
||||
vote_count = collections.Counter(session.scalars(stmt))
|
||||
@@ -252,7 +250,7 @@ class ElectionCycle:
|
||||
if votes >= REQUIRED_VOTES_TO_BE_ELECTED:
|
||||
stmt = (
|
||||
select(CouncilMembers)
|
||||
.where(CouncilMembers.ElectionCycle == election_name)
|
||||
.where(CouncilMembers.ElectionName == election_name)
|
||||
.where(CouncilMembers.MemberId == user_id)
|
||||
)
|
||||
council_member = session.scalar(stmt)
|
||||
@@ -277,9 +275,7 @@ class ElectionCycle:
|
||||
)
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = select(ElectionInformation).where(
|
||||
ElectionInformation.ElectionCycle == get_election_name(self.config)
|
||||
)
|
||||
stmt = select(ElectionInformation).where(ElectionInformation.ElectionName == get_election_name(self.config))
|
||||
info = session.scalar(stmt)
|
||||
info.HighCouncilVoteMsgId = vote_msg.id
|
||||
session.commit()
|
||||
@@ -295,13 +291,13 @@ class ElectionCycle:
|
||||
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)
|
||||
|
||||
election_cycle = get_election_name(self.config)
|
||||
election_name = get_election_name(self.config)
|
||||
|
||||
with Session(engine) as session:
|
||||
# role management
|
||||
stmt = (
|
||||
select(CouncilMembers.MemberId)
|
||||
.where(CouncilMembers.ElectionCycle == election_cycle)
|
||||
.where(CouncilMembers.ElectionName == election_name)
|
||||
.where(CouncilMembers.Elected == true())
|
||||
)
|
||||
|
||||
@@ -320,13 +316,13 @@ class ElectionCycle:
|
||||
# ties are undefined behavior.
|
||||
stmt = (
|
||||
select(Votes.VotedForId)
|
||||
.where(Votes.ElectionCycle == election_cycle)
|
||||
.where(Votes.ElectionName == election_name)
|
||||
.where(Votes.Type == VoteType.DISCORDMANAGER)
|
||||
)
|
||||
dm_votes = collections.Counter(session.scalars(stmt))
|
||||
stmt = (
|
||||
select(Votes.VotedForId)
|
||||
.where(Votes.ElectionCycle == election_cycle)
|
||||
.where(Votes.ElectionName == election_name)
|
||||
.where(Votes.Type == VoteType.CLANLEADER)
|
||||
)
|
||||
cl_votes = collections.Counter(session.scalars(stmt))
|
||||
@@ -335,7 +331,7 @@ class ElectionCycle:
|
||||
dm_winner = max(dm_votes, key=dm_votes.get)
|
||||
stmt = (
|
||||
update(CouncilMembers)
|
||||
.where(CouncilMembers.ElectionCycle == election_cycle)
|
||||
.where(CouncilMembers.ElectionName == election_name)
|
||||
.where(CouncilMembers.MemberId == dm_winner)
|
||||
.values(DiscordManager=True)
|
||||
)
|
||||
@@ -346,7 +342,7 @@ class ElectionCycle:
|
||||
cl_winner = max(cl_votes, key=cl_votes.get)
|
||||
stmt = (
|
||||
update(CouncilMembers)
|
||||
.where(CouncilMembers.ElectionCycle == election_cycle)
|
||||
.where(CouncilMembers.ElectionName == election_name)
|
||||
.where(CouncilMembers.MemberId == cl_winner)
|
||||
.values(ClanLeader=True)
|
||||
)
|
||||
@@ -360,7 +356,7 @@ class ElectionCycle:
|
||||
|
||||
# clear view from vote message
|
||||
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: 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.
|
||||
"""
|
||||
with Session(engine) as session:
|
||||
stmt = select(ElectionInformation).where(
|
||||
ElectionInformation.ElectionCycle == get_election_name(self.config)
|
||||
)
|
||||
stmt = select(ElectionInformation).where(ElectionInformation.ElectionName == get_election_name(self.config))
|
||||
return session.scalar(stmt)
|
||||
|
||||
async def election_reminder(self) -> None:
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Contains various views to be used in the high council nomination process."""
|
||||
|
||||
import nextcord
|
||||
from config import DakinyConfig
|
||||
from DakinySettings import DakinySettings
|
||||
from database_setup.sql_data_classes import CouncilMembers, engine
|
||||
from nextcord.interactions import Interaction
|
||||
from sqlalchemy import select
|
||||
@@ -23,7 +23,7 @@ class NominateDMModal(nextcord.ui.Modal):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config: DakinyConfig,
|
||||
config: DakinySettings,
|
||||
usr_id: int,
|
||||
usr_nominated: bool, # noqa: FBT001
|
||||
speech_content: str,
|
||||
@@ -33,7 +33,7 @@ class NominateDMModal(nextcord.ui.Modal):
|
||||
timeout=5 * 60, # 5 minutes
|
||||
)
|
||||
self.usr_id: int = usr_id
|
||||
self.config: DakinyConfig = config
|
||||
self.config: DakinySettings = config
|
||||
self.usr_nominated = usr_nominated
|
||||
|
||||
self.speech = nextcord.ui.TextInput(
|
||||
@@ -58,10 +58,10 @@ class NominateDMModal(nextcord.ui.Modal):
|
||||
|
||||
with Session(engine) as session:
|
||||
# user already in table
|
||||
cycle = get_election_name(self.config)
|
||||
election_name = get_election_name(self.config)
|
||||
stmt = (
|
||||
select(CouncilMembers)
|
||||
.where(CouncilMembers.ElectionCycle == cycle)
|
||||
.where(CouncilMembers.ElectionName == election_name)
|
||||
.where(CouncilMembers.MemberId == self.usr_id)
|
||||
)
|
||||
council_elect = session.scalar(stmt)
|
||||
@@ -85,7 +85,7 @@ class NominateCLModal(nextcord.ui.Modal):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config: DakinyConfig,
|
||||
config: DakinySettings,
|
||||
usr_id: int,
|
||||
usr_nominated: bool, # noqa: FBT001
|
||||
speech_content: str,
|
||||
@@ -95,7 +95,7 @@ class NominateCLModal(nextcord.ui.Modal):
|
||||
timeout=5 * 60, # 5 minutes
|
||||
)
|
||||
self.usr_id: int = usr_id
|
||||
self.config: DakinyConfig = config
|
||||
self.config: DakinySettings = config
|
||||
self.usr_nominated = usr_nominated
|
||||
|
||||
self.speech = nextcord.ui.TextInput(
|
||||
@@ -120,10 +120,10 @@ class NominateCLModal(nextcord.ui.Modal):
|
||||
|
||||
with Session(engine) as session:
|
||||
# user already in table
|
||||
cycle = get_election_name(self.config)
|
||||
election_name = get_election_name(self.config)
|
||||
stmt = (
|
||||
select(CouncilMembers)
|
||||
.where(CouncilMembers.ElectionCycle == cycle)
|
||||
.where(CouncilMembers.ElectionName == election_name)
|
||||
.where(CouncilMembers.MemberId == self.usr_id)
|
||||
)
|
||||
council_elect = session.scalar(stmt)
|
||||
@@ -141,9 +141,9 @@ class NominateCLModal(nextcord.ui.Modal):
|
||||
class NominateHighCouncilView(nextcord.ui.View):
|
||||
"""The buttons to press to start your High Council nomination."""
|
||||
|
||||
def __init__(self, config: DakinyConfig, guild: nextcord.Guild):
|
||||
def __init__(self, config: DakinySettings, guild: nextcord.Guild):
|
||||
super().__init__(timeout=None)
|
||||
self.config: DakinyConfig = config
|
||||
self.config: DakinySettings = config
|
||||
self.guild: nextcord.Guild = guild
|
||||
|
||||
@nextcord.ui.button(
|
||||
@@ -170,13 +170,13 @@ class NominateHighCouncilView(nextcord.ui.View):
|
||||
)
|
||||
return
|
||||
|
||||
cycle = get_election_name(self.config)
|
||||
election_name = get_election_name(self.config)
|
||||
usr_nominated = False
|
||||
speech_content = ""
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(CouncilMembers)
|
||||
.where(CouncilMembers.ElectionCycle == cycle)
|
||||
.where(CouncilMembers.ElectionName == election_name)
|
||||
.where(CouncilMembers.MemberId == interaction.user.id)
|
||||
)
|
||||
obj = session.scalar(stmt)
|
||||
@@ -215,13 +215,13 @@ class NominateHighCouncilView(nextcord.ui.View):
|
||||
)
|
||||
return
|
||||
|
||||
cycle = get_election_name(self.config)
|
||||
election_name = get_election_name(self.config)
|
||||
usr_nominated = False
|
||||
speech_content = ""
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(CouncilMembers)
|
||||
.where(CouncilMembers.ElectionCycle == cycle)
|
||||
.where(CouncilMembers.ElectionName == election_name)
|
||||
.where(CouncilMembers.MemberId == interaction.user.id)
|
||||
)
|
||||
obj = session.scalar(stmt)
|
||||
|
||||
+11
-11
@@ -1,7 +1,7 @@
|
||||
"""Contains various views to be used in the nomination process."""
|
||||
|
||||
import nextcord
|
||||
from config import DakinyConfig
|
||||
from DakinySettings import DakinySettings
|
||||
from database_setup.sql_data_classes import CouncilMembers, engine
|
||||
from nextcord.interactions import Interaction
|
||||
from sqlalchemy import select
|
||||
@@ -18,7 +18,7 @@ class NominateModal(nextcord.ui.Modal):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config: DakinyConfig,
|
||||
config: DakinySettings,
|
||||
usr_id: int,
|
||||
usr_nominated: bool, # noqa: FBT001
|
||||
speech_content: str,
|
||||
@@ -28,7 +28,7 @@ class NominateModal(nextcord.ui.Modal):
|
||||
timeout=5 * 60, # 5 minutes
|
||||
)
|
||||
self.usr_id: int = usr_id
|
||||
self.config: DakinyConfig = config
|
||||
self.config: DakinySettings = config
|
||||
self.usr_nominated = usr_nominated
|
||||
|
||||
self.speech = nextcord.ui.TextInput(
|
||||
@@ -50,13 +50,14 @@ class NominateModal(nextcord.ui.Modal):
|
||||
|
||||
"""
|
||||
speech = decorate_nomination(interaction.user.id, self.speech.value)
|
||||
election_name = get_election_name(self.config)
|
||||
|
||||
with Session(engine) as session:
|
||||
if not self.usr_nominated:
|
||||
msg = await interaction.channel.send(speech)
|
||||
|
||||
council_member = CouncilMembers(
|
||||
ElectionCycle=get_election_name(self.config),
|
||||
ElectionName=election_name,
|
||||
MemberId=interaction.user.id,
|
||||
SpeechMsgId=msg.id,
|
||||
)
|
||||
@@ -64,10 +65,9 @@ class NominateModal(nextcord.ui.Modal):
|
||||
session.commit()
|
||||
else:
|
||||
# user already nominated, just need to update the election speech
|
||||
cycle = get_election_name(self.config)
|
||||
stmt = (
|
||||
select(CouncilMembers)
|
||||
.where(CouncilMembers.ElectionCycle == cycle)
|
||||
.where(CouncilMembers.ElectionName == election_name)
|
||||
.where(CouncilMembers.MemberId == self.usr_id)
|
||||
)
|
||||
obj = session.scalar(stmt)
|
||||
@@ -79,9 +79,9 @@ class NominateModal(nextcord.ui.Modal):
|
||||
class NominateView(nextcord.ui.View):
|
||||
"""The button to press to start your nomination."""
|
||||
|
||||
def __init__(self, config: DakinyConfig, guild: nextcord.Guild):
|
||||
def __init__(self, config: DakinySettings, guild: nextcord.Guild):
|
||||
super().__init__(timeout=None)
|
||||
self.config: DakinyConfig = config
|
||||
self.config: DakinySettings = config
|
||||
self.guild: nextcord.Guild = guild
|
||||
|
||||
@nextcord.ui.button(
|
||||
@@ -91,7 +91,7 @@ class NominateView(nextcord.ui.View):
|
||||
)
|
||||
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
|
||||
the nomination modal to get their speech.
|
||||
@@ -108,13 +108,13 @@ class NominateView(nextcord.ui.View):
|
||||
)
|
||||
return
|
||||
|
||||
cycle = get_election_name(self.config)
|
||||
election_name = get_election_name(self.config)
|
||||
usr_nominated = False
|
||||
speech_content = ""
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(CouncilMembers)
|
||||
.where(CouncilMembers.ElectionCycle == cycle)
|
||||
.where(CouncilMembers.ElectionName == election_name)
|
||||
.where(CouncilMembers.MemberId == interaction.user.id)
|
||||
)
|
||||
obj = session.scalar(stmt)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Contains various views to be used while voting for high council. Controls the logic when performing the vote."""
|
||||
|
||||
import nextcord
|
||||
from config import DakinyConfig
|
||||
from DakinySettings import DakinySettings
|
||||
from database_setup.sql_data_classes import (
|
||||
CouncilMembers,
|
||||
ElectionInformation,
|
||||
@@ -18,7 +18,7 @@ from utils import VoteType, build_highcouncil_votes_str, get_election_name
|
||||
class VoteSelect(nextcord.ui.StringSelect):
|
||||
"""Vote view string select."""
|
||||
|
||||
def __init__(self, options: list["SelectOption"], config: DakinyConfig, election_type: str) -> None:
|
||||
def __init__(self, options: list["SelectOption"], config: DakinySettings, election_type: str) -> None:
|
||||
super().__init__(
|
||||
placeholder="Choose 1",
|
||||
min_values=1,
|
||||
@@ -41,14 +41,14 @@ class VoteSelect(nextcord.ui.StringSelect):
|
||||
election_name: str = get_election_name(self.config)
|
||||
with Session(engine) as session:
|
||||
stmt = select(ElectionInformation.HighCouncilVoteMsgId).where(
|
||||
ElectionInformation.ElectionCycle == election_name
|
||||
ElectionInformation.ElectionName == election_name
|
||||
)
|
||||
vote_msg_id = session.scalar(stmt)
|
||||
|
||||
voted_for = None if self.values[0] == "Abstain" else int(self.values[0])
|
||||
|
||||
new_vote = Votes(
|
||||
ElectionCycle=election_name,
|
||||
ElectionName=election_name,
|
||||
VoterId=interaction.user.id,
|
||||
VotedForId=voted_for,
|
||||
Type=self.election_type,
|
||||
@@ -63,7 +63,7 @@ class VoteSelect(nextcord.ui.StringSelect):
|
||||
session.rollback()
|
||||
stmt = (
|
||||
update(Votes)
|
||||
.where(Votes.ElectionCycle == election_name)
|
||||
.where(Votes.ElectionName == election_name)
|
||||
.where(Votes.VoterId == interaction.user.id)
|
||||
.where(Votes.Type == self.election_type)
|
||||
.values(VotedForId=voted_for)
|
||||
@@ -83,7 +83,7 @@ class VoteSelect(nextcord.ui.StringSelect):
|
||||
class VoteHighcouncilView(nextcord.ui.View):
|
||||
"""The button to press to start voting for HighCouncil."""
|
||||
|
||||
def __init__(self, config: DakinyConfig, guild: nextcord.Guild):
|
||||
def __init__(self, config: DakinySettings, guild: nextcord.Guild):
|
||||
super().__init__(timeout=None)
|
||||
self.config = config
|
||||
self.guild = guild
|
||||
@@ -118,7 +118,7 @@ class VoteHighcouncilView(nextcord.ui.View):
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(Votes.VotedForId)
|
||||
.where(Votes.ElectionCycle == election_name)
|
||||
.where(Votes.ElectionName == election_name)
|
||||
.where(Votes.VoterId == interaction.user.id)
|
||||
.where(Votes.Type == VoteType.CLANLEADER)
|
||||
)
|
||||
@@ -126,7 +126,7 @@ class VoteHighcouncilView(nextcord.ui.View):
|
||||
|
||||
stmt = (
|
||||
select(CouncilMembers.MemberId)
|
||||
.where(CouncilMembers.ElectionCycle == election_name)
|
||||
.where(CouncilMembers.ElectionName == election_name)
|
||||
.filter(CouncilMembers.ClanLeaderSpeechId.is_not(None))
|
||||
)
|
||||
|
||||
@@ -190,7 +190,7 @@ class VoteHighcouncilView(nextcord.ui.View):
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(Votes.VotedForId)
|
||||
.where(Votes.ElectionCycle == election_name)
|
||||
.where(Votes.ElectionName == election_name)
|
||||
.where(Votes.VoterId == interaction.user.id)
|
||||
.where(Votes.Type == VoteType.DISCORDMANAGER)
|
||||
)
|
||||
@@ -198,7 +198,7 @@ class VoteHighcouncilView(nextcord.ui.View):
|
||||
|
||||
stmt = (
|
||||
select(CouncilMembers.MemberId)
|
||||
.where(CouncilMembers.ElectionCycle == election_name)
|
||||
.where(CouncilMembers.ElectionName == election_name)
|
||||
.filter(CouncilMembers.DiscordManagerSpeechId.is_not(None))
|
||||
)
|
||||
|
||||
|
||||
+9
-11
@@ -1,7 +1,7 @@
|
||||
"""Contains various views to be used while voting. Controls the logic when performing the vote."""
|
||||
|
||||
import nextcord
|
||||
from config import DakinyConfig
|
||||
from DakinySettings import DakinySettings
|
||||
from database_setup.sql_data_classes import (
|
||||
CouncilMembers,
|
||||
ElectionInformation,
|
||||
@@ -18,7 +18,7 @@ from utils import VoteType, build_votes_str, get_election_name
|
||||
class VoteSelect(nextcord.ui.StringSelect):
|
||||
"""Vote view string select."""
|
||||
|
||||
def __init__(self, options: list["SelectOption"], config: DakinyConfig) -> None:
|
||||
def __init__(self, options: list["SelectOption"], config: DakinySettings) -> None:
|
||||
super().__init__(
|
||||
placeholder="Choose 1",
|
||||
min_values=1,
|
||||
@@ -39,15 +39,13 @@ class VoteSelect(nextcord.ui.StringSelect):
|
||||
"""
|
||||
election_name = get_election_name(self.config)
|
||||
with Session(engine) as session:
|
||||
stmt = select(ElectionInformation.CouncilVoteMsgId).where(
|
||||
ElectionInformation.ElectionCycle == election_name
|
||||
)
|
||||
stmt = select(ElectionInformation.CouncilVoteMsgId).where(ElectionInformation.ElectionName == election_name)
|
||||
vote_msg_id = session.scalar(stmt)
|
||||
|
||||
voted_for = None if self.values[0] == "Abstain" else int(self.values[0])
|
||||
|
||||
new_vote = Votes(
|
||||
ElectionCycle=election_name,
|
||||
ElectionName=election_name,
|
||||
VoterId=interaction.user.id,
|
||||
VotedForId=voted_for,
|
||||
Type=VoteType.COUNCIL,
|
||||
@@ -61,7 +59,7 @@ class VoteSelect(nextcord.ui.StringSelect):
|
||||
session.rollback()
|
||||
stmt = (
|
||||
update(Votes)
|
||||
.where(Votes.ElectionCycle == election_name)
|
||||
.where(Votes.ElectionName == election_name)
|
||||
.where(Votes.VoterId == interaction.user.id)
|
||||
.where(Votes.Type == VoteType.COUNCIL)
|
||||
.values(VotedForId=voted_for)
|
||||
@@ -81,7 +79,7 @@ class VoteSelect(nextcord.ui.StringSelect):
|
||||
class VoteView(nextcord.ui.View):
|
||||
"""The button to press to start your nomination."""
|
||||
|
||||
def __init__(self, config: DakinyConfig, guild: nextcord.Guild):
|
||||
def __init__(self, config: DakinySettings, guild: nextcord.Guild):
|
||||
super().__init__(timeout=None)
|
||||
self.config = config
|
||||
self.guild = guild
|
||||
@@ -106,18 +104,18 @@ class VoteView(nextcord.ui.View):
|
||||
)
|
||||
return
|
||||
|
||||
election: str = get_election_name(self.config)
|
||||
election_name: str = get_election_name(self.config)
|
||||
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(Votes.VotedForId)
|
||||
.where(Votes.ElectionCycle == election)
|
||||
.where(Votes.ElectionName == election_name)
|
||||
.where(Votes.VoterId == interaction.user.id)
|
||||
.where(Votes.Type == VoteType.COUNCIL)
|
||||
)
|
||||
voted_for = session.scalar(stmt)
|
||||
|
||||
stmt = select(CouncilMembers.MemberId).where(CouncilMembers.ElectionCycle == election)
|
||||
stmt = select(CouncilMembers.MemberId).where(CouncilMembers.ElectionName == election_name)
|
||||
|
||||
options = [
|
||||
SelectOption(
|
||||
|
||||
@@ -14,7 +14,7 @@ from utils import REPO_DIR, edit_clan_council_info, update_clan_messages
|
||||
if TYPE_CHECKING:
|
||||
import nextcord
|
||||
|
||||
from config import DakinyConfig
|
||||
from DakinySettings import DakinySettings
|
||||
|
||||
app = FastAPI()
|
||||
REPO_URL = "https://gitea.cheezers.org/imcompiling/dakiny-messages.git"
|
||||
@@ -30,7 +30,7 @@ class ClanMessages(commands.Cog, name="Clan Messages"):
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
self.config: DakinyConfig = self.bot.config
|
||||
self.config: DakinySettings = self.bot.config
|
||||
self.repo_setup()
|
||||
|
||||
@commands.Cog.listener()
|
||||
|
||||
@@ -4,7 +4,7 @@ import nextcord
|
||||
from discord import TextInputStyle
|
||||
from nextcord.ext import commands
|
||||
|
||||
from config import DakinyConfig
|
||||
from DakinySettings import DakinySettings
|
||||
from utils import GUILDS, MAX_DISCORD_MESSAGE_LENGTH, record_event_points
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ class RecordCog(commands.Cog, name="Record Commands"):
|
||||
)
|
||||
|
||||
@record.subcommand(description="Record a miscellaneous point for a clan member.")
|
||||
async def point( # noqa: PLR0913
|
||||
async def point(
|
||||
self,
|
||||
interaction: nextcord.Interaction,
|
||||
activity: str = nextcord.SlashOption(
|
||||
@@ -140,7 +140,9 @@ class RecordCog(commands.Cog, name="Record Commands"):
|
||||
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
|
||||
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)
|
||||
|
||||
@@ -153,11 +155,11 @@ class EventView(nextcord.ui.View):
|
||||
Also contains a UserSelect object to pick discord members.
|
||||
"""
|
||||
|
||||
def __init__(self, name: str, config: DakinyConfig, host_id: int):
|
||||
def __init__(self, name: str, config: DakinySettings, host_id: int):
|
||||
super().__init__()
|
||||
|
||||
self.name: str = name
|
||||
self.config: DakinyConfig = config
|
||||
self.config: DakinySettings = config
|
||||
self.host_id: int = host_id
|
||||
|
||||
self.event_participants = ParticipantSelect()
|
||||
|
||||
@@ -9,7 +9,7 @@ from sqlalchemy.orm import Session
|
||||
from database_setup.sql_data_classes import Presences, engine
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from config import DakinyConfig
|
||||
from DakinySettings import DakinySettings
|
||||
|
||||
|
||||
class RequestCog(commands.Cog, name="Request Commands"):
|
||||
@@ -41,7 +41,7 @@ class RequestCog(commands.Cog, name="Request Commands"):
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
presence (str): The presence to add.
|
||||
"""
|
||||
config: DakinyConfig = self.bot.config
|
||||
config: DakinySettings = self.bot.config
|
||||
content = f'<@{interaction.user.id}> would like to add presence "{presence}."'
|
||||
view = PresenceChange(presence)
|
||||
await self.bot.get_channel(config.params.admin_channel_id).send(content=content, view=view)
|
||||
@@ -65,7 +65,7 @@ class RequestCog(commands.Cog, name="Request Commands"):
|
||||
interaction (nextcord.Interaction): Interaction that invoked the command.
|
||||
new_nickname(str): The username to change to.
|
||||
"""
|
||||
config: DakinyConfig = self.bot.config
|
||||
config: DakinySettings = self.bot.config
|
||||
content = f'<@{interaction.user.id}> would like to change their username to "{new_nickname}."'
|
||||
view = UsernameRequest(interaction.user.id, new_nickname)
|
||||
await self.bot.get_channel(config.params.admin_channel_id).send(content=content, view=view)
|
||||
|
||||
+16
-16
@@ -5,11 +5,11 @@ from typing import TYPE_CHECKING
|
||||
import nextcord
|
||||
from nextcord.ext import application_checks, commands
|
||||
|
||||
from classes.election_cycle import ElectionCycle
|
||||
from classes.election import Election
|
||||
from utils import GUILDS, get_current_election_cycle
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from config import DakinyConfig
|
||||
from DakinySettings import DakinySettings
|
||||
|
||||
|
||||
ME = 206602713511886849
|
||||
@@ -44,8 +44,8 @@ class TestCog(commands.Cog, name="Test commands."):
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with the message.
|
||||
"""
|
||||
config: DakinyConfig = self.bot.config
|
||||
cycle = ElectionCycle(
|
||||
config: DakinySettings = self.bot.config
|
||||
cycle = Election(
|
||||
get_current_election_cycle(config),
|
||||
config,
|
||||
self.bot.get_guild(config.params.guild_id),
|
||||
@@ -62,8 +62,8 @@ class TestCog(commands.Cog, name="Test commands."):
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with the message.
|
||||
"""
|
||||
config: DakinyConfig = self.bot.config
|
||||
cycle = ElectionCycle(
|
||||
config: DakinySettings = self.bot.config
|
||||
cycle = Election(
|
||||
get_current_election_cycle(config),
|
||||
config,
|
||||
self.bot.get_guild(config.params.guild_id),
|
||||
@@ -80,8 +80,8 @@ class TestCog(commands.Cog, name="Test commands."):
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with the message.
|
||||
"""
|
||||
config: DakinyConfig = self.bot.config
|
||||
cycle = ElectionCycle(
|
||||
config: DakinySettings = self.bot.config
|
||||
cycle = Election(
|
||||
get_current_election_cycle(config),
|
||||
config,
|
||||
self.bot.get_guild(config.params.guild_id),
|
||||
@@ -98,8 +98,8 @@ class TestCog(commands.Cog, name="Test commands."):
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with the message.
|
||||
"""
|
||||
config: DakinyConfig = self.bot.config
|
||||
cycle = ElectionCycle(
|
||||
config: DakinySettings = self.bot.config
|
||||
cycle = Election(
|
||||
get_current_election_cycle(config),
|
||||
config,
|
||||
self.bot.get_guild(config.params.guild_id),
|
||||
@@ -116,8 +116,8 @@ class TestCog(commands.Cog, name="Test commands."):
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with the message.
|
||||
"""
|
||||
config: DakinyConfig = self.bot.config
|
||||
cycle = ElectionCycle(
|
||||
config: DakinySettings = self.bot.config
|
||||
cycle = Election(
|
||||
get_current_election_cycle(config),
|
||||
config,
|
||||
self.bot.get_guild(config.params.guild_id),
|
||||
@@ -134,8 +134,8 @@ class TestCog(commands.Cog, name="Test commands."):
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with the message.
|
||||
"""
|
||||
config: DakinyConfig = self.bot.config
|
||||
cycle = ElectionCycle(
|
||||
config: DakinySettings = self.bot.config
|
||||
cycle = Election(
|
||||
get_current_election_cycle(config),
|
||||
config,
|
||||
self.bot.get_guild(config.params.guild_id),
|
||||
@@ -152,8 +152,8 @@ class TestCog(commands.Cog, name="Test commands."):
|
||||
Args:
|
||||
interaction (nextcord.Interaction): Interaction with the message.
|
||||
"""
|
||||
config: DakinyConfig = self.bot.config
|
||||
cycle = ElectionCycle(
|
||||
config: DakinySettings = self.bot.config
|
||||
cycle = Election(
|
||||
get_current_election_cycle(config),
|
||||
config,
|
||||
self.bot.get_guild(config.params.guild_id),
|
||||
|
||||
+16
-14
@@ -7,7 +7,7 @@ from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from database_setup.sql_data_classes import (
|
||||
ParticipationPoints,
|
||||
EventPoints,
|
||||
Presences,
|
||||
Votes,
|
||||
engine,
|
||||
@@ -49,14 +49,12 @@ class ViewCog(commands.Cog, name="View Commands"):
|
||||
with Session(engine) as session:
|
||||
if quarter_name:
|
||||
ppdf = pd.read_sql_query(
|
||||
sql=session.query(ParticipationPoints)
|
||||
.where(ParticipationPoints.Cycle.startswith(quarter_name))
|
||||
.statement,
|
||||
sql=session.query(EventPoints).where(EventPoints.QuarterName.startswith(quarter_name)).statement,
|
||||
con=engine,
|
||||
)
|
||||
else:
|
||||
ppdf = pd.read_sql_query(
|
||||
sql=session.query(ParticipationPoints).statement,
|
||||
sql=session.query(EventPoints).statement,
|
||||
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)
|
||||
return
|
||||
|
||||
cycles = ppdf.groupby("Cycle")
|
||||
quarters = ppdf.groupby("QuarterName")
|
||||
content = ""
|
||||
for cycle in cycles.groups:
|
||||
content += f"**{cycle}**\n"
|
||||
unsorted_all = cycles.get_group(cycle).groupby("DiscordMember")
|
||||
for quarter in quarters.groups:
|
||||
content += f"**{quarter}**\n"
|
||||
unsorted_all = quarters.get_group(quarter).groupby("DiscordMember")
|
||||
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(
|
||||
by="UserId",
|
||||
key=lambda 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)
|
||||
for row in sorted_all.itertuples():
|
||||
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_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:
|
||||
# Check if election exists.
|
||||
@@ -176,7 +178,7 @@ class ViewCog(commands.Cog, name="View Commands"):
|
||||
election_name (str): String to run autocomplete on.
|
||||
"""
|
||||
with Session(engine) as session:
|
||||
stmt = select(Votes.ElectionCycle).distinct()
|
||||
stmt = select(Votes.ElectionName).distinct()
|
||||
elections = session.scalars(stmt)
|
||||
|
||||
# if empty compare string
|
||||
@@ -199,7 +201,7 @@ class ViewCog(commands.Cog, name="View Commands"):
|
||||
quarter_name (str): String to run autocomplete on.
|
||||
"""
|
||||
with Session(engine) as session:
|
||||
stmt = select(ParticipationPoints.Cycle).distinct()
|
||||
stmt = select(EventPoints.QuarterName).distinct()
|
||||
quarters = session.scalars(stmt)
|
||||
|
||||
# if empty compare string
|
||||
|
||||
@@ -9,7 +9,7 @@ from pytz import timezone
|
||||
from sqlalchemy import select
|
||||
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 main import birthday_list
|
||||
from utils import get_current_election_cycle
|
||||
@@ -17,7 +17,7 @@ from utils import get_current_election_cycle
|
||||
if TYPE_CHECKING:
|
||||
import nextcord
|
||||
|
||||
from config import DakinyConfig
|
||||
from DakinySettings import DakinySettings
|
||||
|
||||
KANDY = 239547993106284544
|
||||
|
||||
@@ -43,7 +43,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
||||
election is over to delete the current election object.
|
||||
"""
|
||||
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:
|
||||
await self.current_election.check_date()
|
||||
@@ -65,25 +65,25 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
||||
await self.bot.wait_until_ready()
|
||||
|
||||
# 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.
|
||||
|
||||
An election is considered active between the election start and the term start.
|
||||
|
||||
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: DakinySettings = self.bot.config
|
||||
cycle = get_current_election_cycle(config)
|
||||
|
||||
# prevent exception from using cycle as an Int in an array
|
||||
if cycle is 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:
|
||||
"""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
|
||||
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()
|
||||
birthday = f"{today.month}/{today.day}"
|
||||
|
||||
+11
-11
@@ -1,15 +1,15 @@
|
||||
CREATE TABLE ElectionInformation(
|
||||
ElectionCycle varchar(30) not null unique,
|
||||
ElectionName varchar(30) not null unique,
|
||||
ThreadId bigint unsigned not null,
|
||||
CouncilVoteMsgId bigint unsigned,
|
||||
HighCouncilVoteMsgId bigint unsigned,
|
||||
CouncilNominationMsgId bigint unsigned,
|
||||
HighCouncilNominationMsgId bigint unsigned,
|
||||
PRIMARY KEY (ElectionCycle)
|
||||
PRIMARY KEY (ElectionName)
|
||||
);
|
||||
|
||||
CREATE TABLE CouncilMembers(
|
||||
ElectionCycle varchar(30) not null,
|
||||
ElectionName varchar(30) not null,
|
||||
MemberId bigint unsigned not null,
|
||||
SpeechMsgId bigint unsigned not null,
|
||||
Elected boolean DEFAULT false,
|
||||
@@ -17,17 +17,17 @@ CREATE TABLE CouncilMembers(
|
||||
ClanLeader boolean DEFAULT false,
|
||||
DiscordManagerSpeechId bigint unsigned,
|
||||
ClanLeaderSpeechId bigint unsigned,
|
||||
FOREIGN KEY (ElectionCycle) REFERENCES ElectionInformation(ElectionCycle),
|
||||
PRIMARY KEY (ElectionCycle, MemberId)
|
||||
FOREIGN KEY (ElectionName) REFERENCES ElectionInformation(ElectionName),
|
||||
PRIMARY KEY (ElectionName, MemberId)
|
||||
);
|
||||
|
||||
CREATE TABLE Votes(
|
||||
ElectionCycle varchar(30) not null,
|
||||
ElectionName varchar(30) not null,
|
||||
VoterId bigint unsigned not null,
|
||||
VotedForId bigint unsigned,
|
||||
Type varchar(14) not null DEFAULT 'council' check("Type" in ('council', 'discordmanager', 'clanleader')),
|
||||
FOREIGN KEY (ElectionCycle) REFERENCES ElectionInformation(ElectionCycle),
|
||||
PRIMARY KEY (ElectionCycle, VoterId, Type)
|
||||
FOREIGN KEY (ElectionName) REFERENCES ElectionInformation(ElectionName),
|
||||
PRIMARY KEY (ElectionName, VoterId, Type)
|
||||
);
|
||||
|
||||
CREATE TABLE UserBirthday (
|
||||
@@ -41,12 +41,12 @@ CREATE TABLE Presences (
|
||||
Presence varchar(100) not null
|
||||
);
|
||||
|
||||
CREATE TABLE ParticipationPoints (
|
||||
Cycle varchar(30) not null,
|
||||
CREATE TABLE EventPoints (
|
||||
QuarterName varchar(30) not null,
|
||||
UserId varchar(32) not null,
|
||||
DiscordMember boolean not null,
|
||||
Points int unsigned DEFAULT 0,
|
||||
PRIMARY KEY (Cycle, UserId)
|
||||
PRIMARY KEY (QuarterName, UserId)
|
||||
);
|
||||
|
||||
CREATE TABLE Messages (
|
||||
|
||||
@@ -14,7 +14,7 @@ CouncilMembers = Base.classes.CouncilMembers
|
||||
ElectionInformation = Base.classes.ElectionInformation
|
||||
EventPointsLimit = Base.classes.EventPointsLimit
|
||||
Messages = Base.classes.Messages
|
||||
ParticipationPoints = Base.classes.ParticipationPoints
|
||||
EventPoints = Base.classes.EventPoints
|
||||
Presences = Base.classes.Presences
|
||||
UserBirthday = Base.classes.UserBirthday
|
||||
Votes = Base.classes.Votes
|
||||
|
||||
@@ -2,23 +2,17 @@
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
import hydra
|
||||
import nextcord
|
||||
from hydra.core.config_store import ConfigStore
|
||||
from nextcord.ext import commands
|
||||
|
||||
from classes.nominate_highcouncil_views import NominateHighCouncilView
|
||||
from classes.nominate_views import NominateView
|
||||
from classes.voting_highcouncil_views import VoteHighcouncilView
|
||||
from classes.voting_views import VoteView
|
||||
from config import DakinyConfig
|
||||
from DakinySettings import DakinySettings
|
||||
from database_setup import create_database
|
||||
|
||||
cs = ConfigStore.instance()
|
||||
cs.store(name="dakiny_config", node=DakinyConfig)
|
||||
|
||||
birthday_list: list[int] = []
|
||||
|
||||
logger = logging.getLogger("nextcord")
|
||||
@@ -28,26 +22,24 @@ handler.setFormatter(logging.Formatter("%(asctime)s:%(levelname)s:%(name)s: %(me
|
||||
logger.addHandler(handler)
|
||||
|
||||
|
||||
@hydra.main(config_path="conf", config_name="config")
|
||||
def main(cfg: DakinyConfig) -> None:
|
||||
def main() -> None:
|
||||
"""
|
||||
Builds and runs bot.
|
||||
|
||||
Args:
|
||||
cfg (DakinyConfig): Passed in hydra configuration.
|
||||
"""
|
||||
# Allows privledged intents for monitoring members joining, roles editing, and role assignments
|
||||
# Allows privileged intents for monitoring members joining, roles editing, and role assignments
|
||||
# These need to be enabled in the developer portal as well
|
||||
intents = nextcord.Intents.default()
|
||||
|
||||
# Required in order to read messages (eg. prefix commands)
|
||||
intents.message_content = True
|
||||
|
||||
# To enable the members priveleged intent:
|
||||
# To enable the members privileged intent:
|
||||
intents.members = True
|
||||
|
||||
bot = commands.Bot(intents=intents)
|
||||
bot.config = cfg
|
||||
|
||||
# Get the modules of all cogs whose directory structure is ./cogs/<module_name>
|
||||
for folder in os.listdir("cogs"):
|
||||
@@ -69,7 +61,4 @@ def main(cfg: DakinyConfig) -> None:
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.argv.append("hydra.job.chdir=False")
|
||||
sys.argv.append("hydra/job_logging=none")
|
||||
sys.argv.append("hydra/hydra_logging=none")
|
||||
main() # pylint: disable=no-value-for-parameter
|
||||
main()
|
||||
|
||||
+2
-3
@@ -10,18 +10,17 @@ package-mode = false
|
||||
python = "^3.12"
|
||||
gitpython = "^3.1.43"
|
||||
fastapi = "^0.111.0"
|
||||
hydra-core = "^1.3.2"
|
||||
nextcord = "^2.6.0"
|
||||
pandas = "^2.2.2"
|
||||
python-dotenv = "^1.0.1"
|
||||
pytz = "^2024.1"
|
||||
sqlalchemy = "^2.0.30"
|
||||
aiofiles = "^23.2.1"
|
||||
setuptools = "^70.0.0"
|
||||
dataclass-wizard = "^0.22.3"
|
||||
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
ruff = "^0.4.5"
|
||||
ruff = "^0.6.3"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
|
||||
@@ -12,12 +12,12 @@ import nextcord
|
||||
from sqlalchemy import select, true, update
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from config import DakinyConfig
|
||||
from DakinySettings import DakinySettings
|
||||
from database_setup.sql_data_classes import (
|
||||
CouncilMembers,
|
||||
EventPoints,
|
||||
EventPointsLimit,
|
||||
Messages,
|
||||
ParticipationPoints,
|
||||
Votes,
|
||||
engine,
|
||||
)
|
||||
@@ -57,7 +57,7 @@ def get_datetime(day: str) -> datetime:
|
||||
return datetime(year, month, day, tzinfo=UTC)
|
||||
|
||||
|
||||
def get_election_name(config: DakinyConfig) -> str:
|
||||
def get_election_name(config: DakinySettings) -> str:
|
||||
"""
|
||||
Builds the unique name of the current election cycle.
|
||||
|
||||
@@ -72,7 +72,7 @@ def get_election_name(config: DakinyConfig) -> str:
|
||||
return f"vote-{get_datetime(current_cycle.term_start).year}-{current_cycle.name}"
|
||||
|
||||
|
||||
def get_quarter_name(config: DakinyConfig) -> str:
|
||||
def get_quarter_name(config: DakinySettings) -> str:
|
||||
"""
|
||||
Builds the name of the current cycle/quarter.
|
||||
|
||||
@@ -88,7 +88,7 @@ def get_quarter_name(config: DakinyConfig) -> str:
|
||||
return f"{get_datetime(current_cycle.term_start).year}-{current_cycle.name}"
|
||||
|
||||
|
||||
def get_current_election_cycle(config: DakinyConfig) -> int:
|
||||
def get_current_election_cycle(config: DakinySettings) -> int:
|
||||
"""
|
||||
Returns index for active election. An election is considered active between the election start and the term start.
|
||||
|
||||
@@ -111,7 +111,7 @@ def get_current_election_cycle(config: DakinyConfig) -> int:
|
||||
return get_quarter_cycle(config)
|
||||
|
||||
|
||||
def get_quarter_cycle(config: DakinyConfig) -> int:
|
||||
def get_quarter_cycle(config: DakinySettings) -> int:
|
||||
"""
|
||||
Returns the index for the current cycle/quarter. Defined as between term start and end. Shouldn't return none.
|
||||
|
||||
@@ -132,7 +132,7 @@ def get_quarter_cycle(config: DakinyConfig) -> int:
|
||||
return None
|
||||
|
||||
|
||||
def build_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str:
|
||||
def build_votes_str(config: DakinySettings, guild: nextcord.Guild) -> str:
|
||||
"""
|
||||
Creates a string that contains all nominees and their votes to be sent as a discord message.
|
||||
|
||||
@@ -148,7 +148,7 @@ def build_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str:
|
||||
election_name = get_election_name(config)
|
||||
|
||||
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(
|
||||
session.scalars(stmt),
|
||||
@@ -156,7 +156,7 @@ def build_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str:
|
||||
):
|
||||
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):
|
||||
if vote.VotedForId is not None:
|
||||
@@ -168,7 +168,7 @@ def build_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str:
|
||||
return votes_str
|
||||
|
||||
|
||||
def build_highcouncil_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str:
|
||||
def build_highcouncil_votes_str(config: DakinySettings, guild: nextcord.Guild) -> str:
|
||||
"""
|
||||
Creates a string that contains all high council nominees and their votes to be sent as a discord message.
|
||||
|
||||
@@ -187,7 +187,7 @@ def build_highcouncil_votes_str(config: DakinyConfig, guild: nextcord.Guild) ->
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(CouncilMembers)
|
||||
.where(CouncilMembers.ElectionCycle == election_name)
|
||||
.where(CouncilMembers.ElectionName == election_name)
|
||||
.filter(CouncilMembers.ClanLeaderSpeechId.is_not(None))
|
||||
)
|
||||
|
||||
@@ -197,7 +197,7 @@ def build_highcouncil_votes_str(config: DakinyConfig, guild: nextcord.Guild) ->
|
||||
):
|
||||
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):
|
||||
if vote.VotedForId is not None:
|
||||
@@ -205,7 +205,7 @@ def build_highcouncil_votes_str(config: DakinyConfig, guild: nextcord.Guild) ->
|
||||
|
||||
stmt = (
|
||||
select(CouncilMembers)
|
||||
.where(CouncilMembers.ElectionCycle == election_name)
|
||||
.where(CouncilMembers.ElectionName == election_name)
|
||||
.filter(CouncilMembers.DiscordManagerSpeechId.is_not(None))
|
||||
)
|
||||
|
||||
@@ -215,7 +215,7 @@ def build_highcouncil_votes_str(config: DakinyConfig, guild: nextcord.Guild) ->
|
||||
):
|
||||
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):
|
||||
if vote.VotedForId is not None:
|
||||
@@ -302,7 +302,7 @@ def decorate_dm_nomination(user_id: int, speech: str) -> str:
|
||||
return msg
|
||||
|
||||
|
||||
def record_event_points(config: DakinyConfig, users: Sequence[str], add_points: int, *, is_member: bool) -> None:
|
||||
def record_event_points(config: DakinySettings, users: Sequence[str], add_points: int, *, is_member: bool) -> None:
|
||||
"""
|
||||
Adds event points to all users listed.
|
||||
|
||||
@@ -318,17 +318,13 @@ def record_event_points(config: DakinyConfig, users: Sequence[str], add_points:
|
||||
quarter_name = get_quarter_name(config)
|
||||
with Session(engine) as session:
|
||||
for user in users:
|
||||
stmt = (
|
||||
select(ParticipationPoints)
|
||||
.where(ParticipationPoints.UserId == user)
|
||||
.where(ParticipationPoints.Cycle == quarter_name)
|
||||
)
|
||||
stmt = select(EventPoints).where(EventPoints.UserId == user).where(EventPoints.QuarterName == quarter_name)
|
||||
|
||||
points = session.scalar(stmt)
|
||||
if points is None:
|
||||
add_points = get_allowed_points(session, config.params.event_points_weekly_limit, user, add_points)
|
||||
new_points = ParticipationPoints(
|
||||
Cycle=quarter_name,
|
||||
new_points = EventPoints(
|
||||
QuarterName=quarter_name,
|
||||
UserId=user,
|
||||
DiscordMember=is_member,
|
||||
Points=add_points,
|
||||
@@ -371,11 +367,7 @@ def get_allowed_points(session: Session, points_limit: int, user: str, points: i
|
||||
add_points = points
|
||||
session.add(new_limit)
|
||||
else:
|
||||
add_points = (
|
||||
points
|
||||
if limit.Points + points <= points_limit
|
||||
else (max(0, points_limit - limit.Points))
|
||||
)
|
||||
add_points = points if limit.Points + points <= points_limit else (max(0, points_limit - limit.Points))
|
||||
limit.Points += add_points
|
||||
|
||||
session.commit()
|
||||
@@ -510,7 +502,7 @@ async def edit_clan_message(
|
||||
session.commit()
|
||||
|
||||
|
||||
async def edit_clan_council_info(guild: nextcord.Guild, config: DakinyConfig) -> None:
|
||||
async def edit_clan_council_info(guild: nextcord.Guild, config: DakinySettings) -> None:
|
||||
"""
|
||||
Gets the winners of the elections and updates the permanent message that states the current council.
|
||||
|
||||
@@ -520,23 +512,23 @@ 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)
|
||||
|
||||
election = get_election_name(config)
|
||||
election_name = get_election_name(config)
|
||||
with Session(engine) as session:
|
||||
stmt = (
|
||||
select(CouncilMembers.MemberId)
|
||||
.where(CouncilMembers.ElectionCycle == election)
|
||||
.where(CouncilMembers.ElectionName == election_name)
|
||||
.where(CouncilMembers.DiscordManager == true())
|
||||
)
|
||||
discord_manager = session.scalar(stmt)
|
||||
stmt = (
|
||||
select(CouncilMembers.MemberId)
|
||||
.where(CouncilMembers.ElectionCycle == election)
|
||||
.where(CouncilMembers.ElectionName == election_name)
|
||||
.where(CouncilMembers.ClanLeader == true())
|
||||
)
|
||||
clan_leader = session.scalar(stmt)
|
||||
stmt = (
|
||||
select(CouncilMembers.MemberId)
|
||||
.where(CouncilMembers.ElectionCycle == election)
|
||||
.where(CouncilMembers.ElectionName == election_name)
|
||||
.where(CouncilMembers.Elected == true())
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user