Compare commits
19
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8498f42ba0 | ||
|
|
be46edd4ea | ||
|
|
e34d847364 | ||
|
|
50d10f5168 | ||
|
|
a01503c2c3 | ||
|
|
4c40a4c0e5 | ||
|
|
c3f25b6b54 | ||
|
|
e36b2425aa | ||
|
|
d7a0480c2b | ||
|
|
8457c09b5b | ||
|
|
3c31d0ad33 | ||
|
|
70676a98dd | ||
|
|
512802def7 | ||
|
|
87b21782ce | ||
|
|
38ef2f4cb8 | ||
|
|
79706fbe34 | ||
|
|
83d39d0002 | ||
|
|
d81ff295dd | ||
|
|
9bfbafe15b |
+15
-11
@@ -23,6 +23,7 @@ class ChannelIds:
|
|||||||
class Election:
|
class Election:
|
||||||
"""Class defines relevant election dates."""
|
"""Class defines relevant election dates."""
|
||||||
|
|
||||||
|
active: bool
|
||||||
election_start: str
|
election_start: str
|
||||||
highcouncil_election_announce: str
|
highcouncil_election_announce: str
|
||||||
highcouncil_election_end: str
|
highcouncil_election_end: str
|
||||||
@@ -34,15 +35,6 @@ class Election:
|
|||||||
voting_start: str
|
voting_start: str
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class EventSettings:
|
|
||||||
"""Class defines settings editable by Clan Council."""
|
|
||||||
|
|
||||||
host_points: int
|
|
||||||
participate_points: int
|
|
||||||
weekly_limit: int
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Params:
|
class Params:
|
||||||
"""Class defines start parameters that shouldn't be changed."""
|
"""Class defines start parameters that shouldn't be changed."""
|
||||||
@@ -52,6 +44,19 @@ class Params:
|
|||||||
guild_id: int
|
guild_id: int
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class PointSettings:
|
||||||
|
"""Class defines point settings editable by Clan Council."""
|
||||||
|
|
||||||
|
clan_points: int
|
||||||
|
clan_points_weekly_limit: int
|
||||||
|
events_weekly_limit: int
|
||||||
|
host_points: int
|
||||||
|
participate_points: int
|
||||||
|
verify_clan_points: bool
|
||||||
|
verify_events: bool
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class RoleIds:
|
class RoleIds:
|
||||||
"""Class holds all role ids needed by bot."""
|
"""Class holds all role ids needed by bot."""
|
||||||
@@ -69,8 +74,8 @@ class DakinySettings(YAMLWizard):
|
|||||||
|
|
||||||
channel_ids: ChannelIds
|
channel_ids: ChannelIds
|
||||||
election_cycles: list[Election]
|
election_cycles: list[Election]
|
||||||
event_settings: EventSettings
|
|
||||||
params: Params
|
params: Params
|
||||||
|
point_settings: PointSettings
|
||||||
role_ids: RoleIds
|
role_ids: RoleIds
|
||||||
|
|
||||||
def save(self) -> None:
|
def save(self) -> None:
|
||||||
@@ -79,4 +84,3 @@ class DakinySettings(YAMLWizard):
|
|||||||
|
|
||||||
|
|
||||||
settings = DakinySettings.from_yaml_file(CONFIG_LOCATION)
|
settings = DakinySettings.from_yaml_file(CONFIG_LOCATION)
|
||||||
settings.save()
|
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class Election:
|
|||||||
"""
|
"""
|
||||||
self.cycle = cycle
|
self.cycle = cycle
|
||||||
self.election_cycle = settings.election_cycles[self.cycle]
|
self.election_cycle = settings.election_cycles[self.cycle]
|
||||||
|
self.active = self.election_cycle.active
|
||||||
self.election_start: datetime = get_datetime(self.election_cycle.election_start)
|
self.election_start: datetime = get_datetime(self.election_cycle.election_start)
|
||||||
self.term_start: datetime = get_datetime(self.election_cycle.term_start)
|
self.term_start: datetime = get_datetime(self.election_cycle.term_start)
|
||||||
self.term_end: datetime = get_datetime(self.election_cycle.term_end)
|
self.term_end: datetime = get_datetime(self.election_cycle.term_end)
|
||||||
|
|||||||
+91
-20
@@ -119,14 +119,14 @@ class RecordCog(commands.Cog, name="Record Commands"):
|
|||||||
elif recipient is not None: # noqa: RET505
|
elif recipient is not None: # noqa: RET505
|
||||||
record_event_points(
|
record_event_points(
|
||||||
[str(recipient.id)],
|
[str(recipient.id)],
|
||||||
settings.event_settings.participate_points,
|
settings.point_settings.participate_points,
|
||||||
is_member=True,
|
is_member=True,
|
||||||
)
|
)
|
||||||
recipient_str = f"<@{recipient.id}>"
|
recipient_str = f"<@{recipient.id}>"
|
||||||
elif non_discord_recipient is not None:
|
elif non_discord_recipient is not None:
|
||||||
record_event_points(
|
record_event_points(
|
||||||
[non_discord_recipient],
|
[non_discord_recipient],
|
||||||
settings.event_settings.participate_points,
|
settings.point_settings.participate_points,
|
||||||
is_member=False,
|
is_member=False,
|
||||||
)
|
)
|
||||||
recipient_str = f'"{non_discord_recipient}"'
|
recipient_str = f'"{non_discord_recipient}"'
|
||||||
@@ -180,33 +180,76 @@ class EventView(nextcord.ui.View):
|
|||||||
Removes view and embed from recording message.
|
Removes view and embed from recording message.
|
||||||
Sends point information to database.
|
Sends point information to database.
|
||||||
"""
|
"""
|
||||||
discord_users = self.event_participants.values.members # noqa: PD011 not a pandas object
|
if settings.point_settings.verify_events:
|
||||||
if discord_users:
|
verification_channel: nextcord.TextChannel = interaction.guild.get_channel(settings.channel_ids.admin)
|
||||||
discord_users_list: list[str] = [str(user.id) for user in discord_users if user.id is not self.host_id]
|
verification_view = EventVerification(
|
||||||
record_event_points(
|
self.event_participants.values.members, interaction.message.embeds[0].fields[1].value, self.host_id
|
||||||
discord_users_list,
|
|
||||||
settings.event_settings.participate_points,
|
|
||||||
is_member=True,
|
|
||||||
)
|
)
|
||||||
|
await verification_channel.send(
|
||||||
non_discord_users = interaction.message.embeds[0].fields[1].value
|
content="Event record request.", embed=interaction.message.embeds[0], view=verification_view
|
||||||
if non_discord_users:
|
)
|
||||||
non_discord_users_list: list[str] = non_discord_users.split("\n")
|
submission_response = "Event has been submitted to admins for approval."
|
||||||
record_event_points(
|
else:
|
||||||
non_discord_users_list,
|
process_event(
|
||||||
settings.event_settings.participate_points,
|
self.event_participants.values.members,
|
||||||
is_member=False,
|
interaction.message.embeds[0].fields[1].value,
|
||||||
|
self.host_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
record_event_points([self.host_id], settings.event_settings.host_points, is_member=True)
|
|
||||||
|
|
||||||
event_channel: nextcord.TextChannel = interaction.guild.get_channel(settings.channel_ids.event_post)
|
event_channel: nextcord.TextChannel = interaction.guild.get_channel(settings.channel_ids.event_post)
|
||||||
await event_channel.send(embed=interaction.message.embeds[0])
|
await event_channel.send(embed=interaction.message.embeds[0])
|
||||||
await interaction.response.edit_message(content="Event has been submitted.", view=None, embed=None)
|
submission_response = "Event has been submitted."
|
||||||
|
|
||||||
|
await interaction.response.edit_message(content=submission_response, view=None, embed=None)
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
|
|
||||||
|
class EventVerification(nextcord.ui.View):
|
||||||
|
"""Class contains code to approve/deny event submissions."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
discord_users: list[nextcord.Member],
|
||||||
|
non_discord_users: str,
|
||||||
|
host_id: int,
|
||||||
|
):
|
||||||
|
super().__init__(timeout=None, auto_defer=True)
|
||||||
|
self.discord_users: list[nextcord.Member] = discord_users
|
||||||
|
self.non_discord_users: str = non_discord_users
|
||||||
|
self.host_id: int = host_id
|
||||||
|
|
||||||
|
@nextcord.ui.button(label="Approve", style=nextcord.ButtonStyle.green)
|
||||||
|
async def approve(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
|
||||||
|
"""
|
||||||
|
Approve button for an event submission.
|
||||||
|
|
||||||
|
Calls the process event function. Records who approved the event.
|
||||||
|
Removes the view from the interaction message.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
button (nextcord.ui.Button): Unused.
|
||||||
|
interaction (nextcord.Interaction): The interaction of the user clicking the button.
|
||||||
|
"""
|
||||||
|
process_event(self.discord_users, self.non_discord_users, self.host_id)
|
||||||
|
event_channel: nextcord.TextChannel = interaction.guild.get_channel(settings.channel_ids.event_post)
|
||||||
|
await event_channel.send(embed=interaction.message.embeds[0])
|
||||||
|
|
||||||
|
content = f"\nApproved by <@{interaction.user.id}>."
|
||||||
|
await interaction.response.edit_message(content=content, view=None)
|
||||||
|
|
||||||
|
@nextcord.ui.button(label="Deny", style=nextcord.ButtonStyle.red)
|
||||||
|
async def deny(self, button: nextcord.ui.Button, interaction: nextcord.Interaction) -> None: # noqa: ARG002
|
||||||
|
"""
|
||||||
|
Deny button for an event submission. Just removes the view and logs who denied the request.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
button (nextcord.ui.Button): Unused.
|
||||||
|
interaction (nextcord.Interaction): The interaction of the user clicking the button.
|
||||||
|
"""
|
||||||
|
content = f"\nDenied by <@{interaction.user.id}>."
|
||||||
|
await interaction.response.edit_message(content=content, view=None)
|
||||||
|
|
||||||
|
|
||||||
class ParticipantModal(nextcord.ui.Modal):
|
class ParticipantModal(nextcord.ui.Modal):
|
||||||
"""
|
"""
|
||||||
This modal contains all the text edits for an event.
|
This modal contains all the text edits for an event.
|
||||||
@@ -281,3 +324,31 @@ class ParticipantSelect(nextcord.ui.UserSelect):
|
|||||||
participants: str = "\n".join([f"<@{participant.id}>" for participant in self.values.members])
|
participants: str = "\n".join([f"<@{participant.id}>" for participant in self.values.members])
|
||||||
embed.set_field_at(0, name="Participants", value=participants)
|
embed.set_field_at(0, name="Participants", value=participants)
|
||||||
await interaction.response.edit_message(embed=embed)
|
await interaction.response.edit_message(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
|
def process_event(discord_users: list[nextcord.Member], non_discord_users: str, host_id: int) -> None:
|
||||||
|
"""
|
||||||
|
Processes all points to give to participants and host for an event.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
discord_users (list[nextcord.Member]): List of discord members that participated in event.
|
||||||
|
non_discord_users (str): Newline separated list of non discord members that participated in event.
|
||||||
|
host_id (int): Discord ID of host.
|
||||||
|
"""
|
||||||
|
if discord_users:
|
||||||
|
discord_users_list: list[str] = [str(user.id) for user in discord_users if user.id is not host_id]
|
||||||
|
record_event_points(
|
||||||
|
discord_users_list,
|
||||||
|
settings.point_settings.participate_points,
|
||||||
|
is_member=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
if non_discord_users:
|
||||||
|
non_discord_users_list: list[str] = non_discord_users.split("\n")
|
||||||
|
record_event_points(
|
||||||
|
non_discord_users_list,
|
||||||
|
settings.point_settings.participate_points,
|
||||||
|
is_member=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
record_event_points([host_id], settings.point_settings.host_points, is_member=True)
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ class UsernameRequest(nextcord.ui.View):
|
|||||||
await interaction.followup.edit_message(interaction.message.id, content=content, view=None)
|
await interaction.followup.edit_message(interaction.message.id, content=content, view=None)
|
||||||
else:
|
else:
|
||||||
await interaction.response.edit_message(
|
await interaction.response.edit_message(
|
||||||
content="An error occured while changing the user's nickname.",
|
content="An error occurred while changing the user's nickname.",
|
||||||
view=None,
|
view=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+95
-17
@@ -144,10 +144,67 @@ class SettingsCog(commands.Cog, name="Settings Commands"):
|
|||||||
await interaction.response.send_message(f"Voting channel set to <#{channel_id}>.", ephemeral=True)
|
await interaction.response.send_message(f"Voting channel set to <#{channel_id}>.", ephemeral=True)
|
||||||
|
|
||||||
@settings.subcommand()
|
@settings.subcommand()
|
||||||
async def event_settings(self, interaction: nextcord.Interaction) -> None:
|
async def point_settings(self, interaction: nextcord.Interaction) -> None:
|
||||||
"""Subcommand parent. Never called."""
|
"""Subcommand parent. Never called."""
|
||||||
|
|
||||||
@event_settings.subcommand(description="Sets Event Host Points value.")
|
@point_settings.subcommand(description="Sets Points value.")
|
||||||
|
async def clan_points(
|
||||||
|
self,
|
||||||
|
interaction: nextcord.Interaction,
|
||||||
|
points: int = nextcord.SlashOption(
|
||||||
|
required=True, description="Number of Clan Points the recipient earns.", min_value=0
|
||||||
|
),
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Sets DakinySettings point_settings.clan_points to the given number of points.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Discord interaction of command.
|
||||||
|
points (int): Number of points to assign to PointSettings.points.
|
||||||
|
"""
|
||||||
|
settings.point_settings.clan_points = points
|
||||||
|
settings.save()
|
||||||
|
await interaction.response.send_message(f"Points set to {points}.", ephemeral=True)
|
||||||
|
|
||||||
|
@point_settings.subcommand(description="Sets Event Weekly Limit value for Clan Points.")
|
||||||
|
async def clan_points_weekly_limit(
|
||||||
|
self,
|
||||||
|
interaction: nextcord.Interaction,
|
||||||
|
points: int = nextcord.SlashOption(
|
||||||
|
required=True, description="Number of Clan Points a clan member can earn in a week.", min_value=0
|
||||||
|
),
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Sets DakinySettings point_settings.clan_points_weekly_limit to the given number of points.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Discord interaction of command.
|
||||||
|
points (int): Number of points to set.
|
||||||
|
"""
|
||||||
|
settings.point_settings.clan_points_weekly_limit = points
|
||||||
|
settings.save()
|
||||||
|
await interaction.response.send_message(f"Clan Points Weekly Limit set to {points}.", ephemeral=True)
|
||||||
|
|
||||||
|
@point_settings.subcommand(description="Sets Event Weekly Limit value.")
|
||||||
|
async def events_weekly_limit(
|
||||||
|
self,
|
||||||
|
interaction: nextcord.Interaction,
|
||||||
|
points: int = nextcord.SlashOption(
|
||||||
|
required=True, description="Number of Event Points a clan member can earn in a week.", min_value=0
|
||||||
|
),
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Sets DakinySettings point_settings.events_weekly_limit to the given number of points.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Discord interaction of command.
|
||||||
|
points (int): Number of points to set.
|
||||||
|
"""
|
||||||
|
settings.point_settings.events_weekly_limit = points
|
||||||
|
settings.save()
|
||||||
|
await interaction.response.send_message(f"Event Weekly Limit set to {points}.", ephemeral=True)
|
||||||
|
|
||||||
|
@point_settings.subcommand(description="Sets Event Host Points value.")
|
||||||
async def host_points(
|
async def host_points(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
@@ -156,17 +213,17 @@ class SettingsCog(commands.Cog, name="Settings Commands"):
|
|||||||
),
|
),
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Sets DakinySettings event_settings.host_points to the given number of points.
|
Sets DakinySettings point_settings.host_points to the given number of points.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Discord interaction of command.
|
interaction (nextcord.Interaction): Discord interaction of command.
|
||||||
points (nextcord.TextChannel): Number of points to set.
|
points (int): Number of points to set.
|
||||||
"""
|
"""
|
||||||
settings.event_settings.host_points = points
|
settings.point_settings.host_points = points
|
||||||
settings.save()
|
settings.save()
|
||||||
await interaction.response.send_message(f"Event Host Points set to {points}.", ephemeral=True)
|
await interaction.response.send_message(f"Event Host Points set to {points}.", ephemeral=True)
|
||||||
|
|
||||||
@event_settings.subcommand(description="Sets Event Participation Points value.")
|
@point_settings.subcommand(description="Sets Event Participation Points value.")
|
||||||
async def participate_points(
|
async def participate_points(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
@@ -177,34 +234,55 @@ class SettingsCog(commands.Cog, name="Settings Commands"):
|
|||||||
),
|
),
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Sets DakinySettings event_settings.participate_points to the given number of points.
|
Sets DakinySettings point_settings.participate_points to the given number of points.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Discord interaction of command.
|
interaction (nextcord.Interaction): Discord interaction of command.
|
||||||
points (nextcord.TextChannel): Number of points to set.
|
points (int): Number of points to set.
|
||||||
"""
|
"""
|
||||||
settings.event_settings.participate_points = points
|
settings.point_settings.participate_points = points
|
||||||
settings.save()
|
settings.save()
|
||||||
await interaction.response.send_message(f"Event Participation Points set to {points}.", ephemeral=True)
|
await interaction.response.send_message(f"Event Participation Points set to {points}.", ephemeral=True)
|
||||||
|
|
||||||
@event_settings.subcommand(description="Sets Event Weekly Limit value.")
|
@point_settings.subcommand(description="Sets whether to verify a clan point entry.")
|
||||||
async def weekly_limit(
|
async def verify_clan_points(
|
||||||
self,
|
self,
|
||||||
interaction: nextcord.Interaction,
|
interaction: nextcord.Interaction,
|
||||||
points: int = nextcord.SlashOption(
|
do_verification: bool = nextcord.SlashOption( # noqa: FBT001
|
||||||
required=True, description="Number of Event Points a clan member can earn in a week.", min_value=0
|
required=True,
|
||||||
|
description="Whether an event should be verified or not.",
|
||||||
),
|
),
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Sets DakinySettings event_settings.weekly_limit to the given number of points.
|
Sets DakinySettings point_settings.verify_clan_points to the given number of points.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
interaction (nextcord.Interaction): Discord interaction of command.
|
interaction (nextcord.Interaction): Discord interaction of command.
|
||||||
points (nextcord.TextChannel): Number of points to set.
|
do_verification (bool): If the bot should verify events.
|
||||||
"""
|
"""
|
||||||
settings.event_settings.weekly_limit = points
|
settings.point_settings.verify_clan_points = do_verification
|
||||||
settings.save()
|
settings.save()
|
||||||
await interaction.response.send_message(f"Event Weekly Limit set to {points}.", ephemeral=True)
|
await interaction.response.send_message(f"Event verification set to {do_verification}.", ephemeral=True)
|
||||||
|
|
||||||
|
@point_settings.subcommand(description="Sets whether an event.")
|
||||||
|
async def verify_events(
|
||||||
|
self,
|
||||||
|
interaction: nextcord.Interaction,
|
||||||
|
do_verification: bool = nextcord.SlashOption( # noqa: FBT001
|
||||||
|
required=True,
|
||||||
|
description="Whether an event should be verified or not.",
|
||||||
|
),
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Sets DakinySettings point_settings.verify_events to the given number of points.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interaction (nextcord.Interaction): Discord interaction of command.
|
||||||
|
do_verification (bool): If the bot should verify events.
|
||||||
|
"""
|
||||||
|
settings.point_settings.verify_events = do_verification
|
||||||
|
settings.save()
|
||||||
|
await interaction.response.send_message(f"Event verification set to {do_verification}.", ephemeral=True)
|
||||||
|
|
||||||
@settings.subcommand()
|
@settings.subcommand()
|
||||||
async def role_ids(self, interaction: nextcord.Interaction) -> None:
|
async def role_ids(self, interaction: nextcord.Interaction) -> None:
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from nextcord.ext import application_checks, commands
|
|||||||
|
|
||||||
from classes.election import Election
|
from classes.election import Election
|
||||||
from DakinySettings import settings
|
from DakinySettings import settings
|
||||||
from utils import GUILDS, get_current_election_cycle
|
from utils import GUILDS, get_active_election_cycle
|
||||||
|
|
||||||
ME = 206602713511886849
|
ME = 206602713511886849
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(),
|
get_active_election_cycle(),
|
||||||
self.bot.get_guild(settings.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.election_start_action()
|
await cycle.election_start_action()
|
||||||
@@ -56,7 +56,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(),
|
get_active_election_cycle(),
|
||||||
self.bot.get_guild(settings.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.voting_start_action()
|
await cycle.voting_start_action()
|
||||||
@@ -72,7 +72,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(),
|
get_active_election_cycle(),
|
||||||
self.bot.get_guild(settings.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.voting_end_action()
|
await cycle.voting_end_action()
|
||||||
@@ -88,7 +88,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(),
|
get_active_election_cycle(),
|
||||||
self.bot.get_guild(settings.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.highcouncil_election_start_action()
|
await cycle.highcouncil_election_start_action()
|
||||||
@@ -104,7 +104,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(),
|
get_active_election_cycle(),
|
||||||
self.bot.get_guild(settings.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.election_reminder()
|
await cycle.election_reminder()
|
||||||
@@ -120,7 +120,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(),
|
get_active_election_cycle(),
|
||||||
self.bot.get_guild(settings.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.check_date()
|
await cycle.check_date()
|
||||||
@@ -136,7 +136,7 @@ class TestCog(commands.Cog, name="Test commands."):
|
|||||||
interaction (nextcord.Interaction): Interaction with the message.
|
interaction (nextcord.Interaction): Interaction with the message.
|
||||||
"""
|
"""
|
||||||
cycle = Election(
|
cycle = Election(
|
||||||
get_current_election_cycle(),
|
get_active_election_cycle(),
|
||||||
self.bot.get_guild(settings.params.guild_id),
|
self.bot.get_guild(settings.params.guild_id),
|
||||||
)
|
)
|
||||||
await cycle.term_start_action()
|
await cycle.term_start_action()
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from classes.election import Election
|
|||||||
from DakinySettings import settings
|
from DakinySettings import settings
|
||||||
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_active_election_cycle
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
import nextcord
|
import nextcord
|
||||||
@@ -75,13 +75,15 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
|
|||||||
Returns:
|
Returns:
|
||||||
Election: Current election cycle, None if there is no election happening.
|
Election: Current election cycle, None if there is no election happening.
|
||||||
"""
|
"""
|
||||||
cycle = get_current_election_cycle()
|
cycle = get_active_election_cycle()
|
||||||
|
|
||||||
# prevent exception from using cycle as an Int in an array
|
# prevent exception from using cycle as an Int in an array
|
||||||
if cycle is None:
|
if cycle is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return Election(cycle, self.bot.get_guild(settings.params.guild_id))
|
election = Election(cycle, self.bot.get_guild(settings.params.guild_id))
|
||||||
|
|
||||||
|
return election if election.active else None
|
||||||
|
|
||||||
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."""
|
||||||
|
|||||||
@@ -60,3 +60,18 @@ CREATE TABLE EventPointsLimit (
|
|||||||
Week varchar(7) not null,
|
Week varchar(7) not null,
|
||||||
PRIMARY KEY (UserId, Week)
|
PRIMARY KEY (UserId, Week)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE ClanPoints (
|
||||||
|
QuarterName varchar(30) not null,
|
||||||
|
UserId varchar(32) not null,
|
||||||
|
DiscordMember boolean not null,
|
||||||
|
Points int unsigned DEFAULT 0,
|
||||||
|
PRIMARY KEY (QuarterName, UserId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE ClanPointsLimit (
|
||||||
|
UserId varchar(32) not null,
|
||||||
|
Points int unsigned DEFAULT 0,
|
||||||
|
Week varchar(7) not null,
|
||||||
|
PRIMARY KEY (UserId, Week)
|
||||||
|
);
|
||||||
@@ -10,11 +10,13 @@ Base = automap_base()
|
|||||||
Base.prepare(autoload_with=engine)
|
Base.prepare(autoload_with=engine)
|
||||||
|
|
||||||
# define the classes
|
# define the classes
|
||||||
|
ClanPoints = Base.classes.ClanPoints
|
||||||
|
ClanPointsLimit = Base.classes.ClanPointsLimit
|
||||||
CouncilMembers = Base.classes.CouncilMembers
|
CouncilMembers = Base.classes.CouncilMembers
|
||||||
ElectionInformation = Base.classes.ElectionInformation
|
ElectionInformation = Base.classes.ElectionInformation
|
||||||
|
EventPoints = Base.classes.EventPoints
|
||||||
EventPointsLimit = Base.classes.EventPointsLimit
|
EventPointsLimit = Base.classes.EventPointsLimit
|
||||||
Messages = Base.classes.Messages
|
Messages = Base.classes.Messages
|
||||||
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
|
||||||
|
|||||||
+2
-1
@@ -20,7 +20,7 @@ dataclass-wizard = "^0.22.3"
|
|||||||
|
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
[tool.poetry.group.dev.dependencies]
|
||||||
ruff = "^0.6.3"
|
ruff = "^0.6.9"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core"]
|
requires = ["poetry-core"]
|
||||||
@@ -85,6 +85,7 @@ ignore = [
|
|||||||
"E117",
|
"E117",
|
||||||
"ISC001",
|
"ISC001",
|
||||||
"ISC002",
|
"ISC002",
|
||||||
|
"PD011", # doesn't like me using '.values' on embeds....
|
||||||
"Q000",
|
"Q000",
|
||||||
"Q001",
|
"Q001",
|
||||||
"Q002",
|
"Q002",
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ def get_election_name() -> str:
|
|||||||
Returns:
|
Returns:
|
||||||
str: the name of the election cycle
|
str: the name of the election cycle
|
||||||
"""
|
"""
|
||||||
cycle = get_current_election_cycle()
|
cycle = get_active_election_cycle()
|
||||||
current_cycle = settings.election_cycles[cycle]
|
current_cycle = settings.election_cycles[cycle]
|
||||||
return f"vote-{get_datetime(current_cycle.term_start).year}-{current_cycle.name}"
|
return f"vote-{get_datetime(current_cycle.term_start).year}-{current_cycle.name}"
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ def get_quarter_name() -> str:
|
|||||||
return f"{get_datetime(current_cycle.term_start).year}-{current_cycle.name}"
|
return f"{get_datetime(current_cycle.term_start).year}-{current_cycle.name}"
|
||||||
|
|
||||||
|
|
||||||
def get_current_election_cycle() -> int:
|
def get_active_election_cycle() -> int:
|
||||||
"""
|
"""
|
||||||
Returns index for active election. An election is considered active between the election start and the term start.
|
Returns index for active election. An election is considered active between the election start and the term start.
|
||||||
|
|
||||||
@@ -104,7 +104,9 @@ def get_current_election_cycle() -> int:
|
|||||||
|
|
||||||
def get_quarter_cycle() -> int:
|
def get_quarter_cycle() -> int:
|
||||||
"""
|
"""
|
||||||
Returns the index for the current cycle/quarter. Defined as between term start and end. Shouldn't return none.
|
Returns the index for the current cycle/quarter. Defined as between term start and end.
|
||||||
|
|
||||||
|
Can return None if entire year isn't covered by cycles.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: cycle index for current cycle.
|
int: cycle index for current cycle.
|
||||||
@@ -307,7 +309,7 @@ def record_event_points(users: Sequence[str], add_points: int, *, is_member: boo
|
|||||||
|
|
||||||
points = session.scalar(stmt)
|
points = session.scalar(stmt)
|
||||||
if points is None:
|
if points is None:
|
||||||
add_points = get_allowed_points(session, settings.event_settings.weekly_limit, user, add_points)
|
add_points = get_allowed_points(session, settings.point_settings.events_weekly_limit, user, add_points)
|
||||||
new_points = EventPoints(
|
new_points = EventPoints(
|
||||||
QuarterName=quarter_name,
|
QuarterName=quarter_name,
|
||||||
UserId=user,
|
UserId=user,
|
||||||
@@ -316,7 +318,7 @@ def record_event_points(users: Sequence[str], add_points: int, *, is_member: boo
|
|||||||
)
|
)
|
||||||
session.add(new_points)
|
session.add(new_points)
|
||||||
else:
|
else:
|
||||||
add_points = get_allowed_points(session, settings.event_settings.weekly_limit, user, add_points)
|
add_points = get_allowed_points(session, settings.point_settings.events_weekly_limit, user, add_points)
|
||||||
points.Points += add_points
|
points.Points += add_points
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user