Compare commits

..
1 Commits
Author SHA1 Message Date
imcompiling 09041f69db Merge branch '21-edit-configs-from-discord'
build_release / build (push) Has been cancelled
build_latest / build (push) Successful in 15s
2024-09-03 19:51:49 -04:00
10 changed files with 50 additions and 463 deletions
+14 -15
View File
@@ -12,39 +12,28 @@ class ChannelIds:
"""Class holds all channel ids needed by bot.""" """Class holds all channel ids needed by bot."""
admin: int # might want to rename this... admin: int # might want to rename this...
announcement: int announcement_category: int
clan_info: int clan_info: int
event_post: int event_post: int
general: int general: int
voting: int voting_parent: int
@dataclass @dataclass
class Election: class Election:
"""Class defines relevant election dates.""" """Class defines relevant election dates."""
active: bool name: str
election_start: str election_start: str
highcouncil_election_announce: str highcouncil_election_announce: str
highcouncil_election_end: str highcouncil_election_end: str
highcouncil_election_start: str highcouncil_election_start: str
name: str
term_end: str term_end: str
term_start: str term_start: str
voting_end: str voting_end: str
voting_start: str voting_start: str
@dataclass
class EventSettings:
"""Class defines settings editable by Clan Council."""
host_points: int
participate_points: int
verify: bool
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."""
@@ -58,13 +47,22 @@ class Params:
class RoleIds: class RoleIds:
"""Class holds all role ids needed by bot.""" """Class holds all role ids needed by bot."""
clan_council: int
clan_council_elect: int clan_council_elect: int
clan_council: int
clan_member: int clan_member: int
event_host: int event_host: int
high_council: int high_council: int
@dataclass
class EventSettings:
"""Class defines settings editable by Clan Council."""
host_points: int
participate_points: int
weekly_limit: int
@dataclass @dataclass
class DakinySettings(YAMLWizard): class DakinySettings(YAMLWizard):
"""Class defines all configs required for Dakiny Bot.""" """Class defines all configs required for Dakiny Bot."""
@@ -81,3 +79,4 @@ class DakinySettings(YAMLWizard):
settings = DakinySettings.from_yaml_file(CONFIG_LOCATION) settings = DakinySettings.from_yaml_file(CONFIG_LOCATION)
settings.save()
+1 -2
View File
@@ -49,7 +49,6 @@ 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)
@@ -161,7 +160,7 @@ class Election:
async def election_start_action(self) -> None: async def election_start_action(self) -> None:
"""Performs required actions for when the election cycle starts.""" """Performs required actions for when the election cycle starts."""
# create new channel for election # create new channel for election
parent: nextcord.TextChannel = self.guild.get_channel(settings.channel_ids.voting) parent: nextcord.TextChannel = self.guild.get_channel(settings.channel_ids.voting_parent)
quarter_name: str = get_election_name() quarter_name: str = get_election_name()
thread_msg: nextcord.Message = await parent.send(content=quarter_name) thread_msg: nextcord.Message = await parent.send(content=quarter_name)
-2
View File
@@ -7,7 +7,6 @@ from cogs.commands.refresh import RefreshCog
from cogs.commands.remove import RemoveCog 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.settings import SettingsCog
from cogs.commands.test import TestCog from cogs.commands.test import TestCog
from cogs.commands.time import TimeCog from cogs.commands.time import TimeCog
from cogs.commands.view import ViewCog from cogs.commands.view import ViewCog
@@ -22,7 +21,6 @@ def setup(bot: commands.Bot) -> None:
bot.add_cog(RemoveCog()) bot.add_cog(RemoveCog())
bot.add_cog(RequestCog(bot)) bot.add_cog(RequestCog(bot))
bot.add_cog(SetCog()) bot.add_cog(SetCog())
bot.add_cog(SettingsCog())
bot.add_cog(TestCog(bot)) bot.add_cog(TestCog(bot))
bot.add_cog(TimeCog()) bot.add_cog(TimeCog())
bot.add_cog(ViewCog()) bot.add_cog(ViewCog())
+18 -89
View File
@@ -180,76 +180,33 @@ 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.
""" """
if settings.event_settings.verify: discord_users = self.event_participants.values.members # noqa: PD011 not a pandas object
verification_channel: nextcord.TextChannel = interaction.guild.get_channel(settings.channel_ids.admin) if discord_users:
verification_view = EventVerification( discord_users_list: list[str] = [str(user.id) for user in discord_users if user.id is not self.host_id]
self.event_participants.values.members, interaction.message.embeds[0].fields[1].value, self.host_id record_event_points(
discord_users_list,
settings.event_settings.participate_points,
is_member=True,
) )
await verification_channel.send(
content="Event record request.", embed=interaction.message.embeds[0], view=verification_view non_discord_users = interaction.message.embeds[0].fields[1].value
) if non_discord_users:
submission_response = "Event has been submitted to admins for approval." non_discord_users_list: list[str] = non_discord_users.split("\n")
else: record_event_points(
process_event( non_discord_users_list,
self.event_participants.values.members, settings.event_settings.participate_points,
interaction.message.embeds[0].fields[1].value, is_member=False,
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])
submission_response = "Event has been submitted." await interaction.response.edit_message(content="Event has been submitted.", view=None, embed=None)
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.
@@ -324,31 +281,3 @@ 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.event_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.event_settings.participate_points,
is_member=False,
)
record_event_points([host_id], settings.event_settings.host_points, is_member=True)
+1 -1
View File
@@ -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 occurred while changing the user's nickname.", content="An error occured while changing the user's nickname.",
view=None, view=None,
) )
-321
View File
@@ -1,321 +0,0 @@
"""Contains commands and views for settings commands."""
import nextcord
from nextcord.ext import commands
from DakinySettings import settings
from utils import GUILDS
class SettingsCog(commands.Cog, name="Settings Commands"):
"""Class holds settings commands."""
def __init__(self) -> None:
"""Default constructor for SettingsCog class. Does nothing."""
@nextcord.slash_command(guild_ids=GUILDS, default_member_permissions=nextcord.Permissions(administrator=True))
async def settings(self, interaction: nextcord.Interaction) -> None:
"""Parent slash command for settings. Never called."""
@settings.subcommand()
async def channel_ids(self, interaction: nextcord.Interaction) -> None:
"""Subcommand parent. Never called."""
@channel_ids.subcommand(description="Sets channel that bot sends verification requests to admins.")
async def admin(
self,
interaction: nextcord.Interaction,
channel: nextcord.TextChannel = nextcord.SlashOption(
required=False, description="Channel to set to. If left blank, uses current channel."
),
) -> None:
"""
Sets DakinySettings channel_ids.admin value to given channel id or current channel id.
Args:
interaction (nextcord.Interaction): Discord interaction of command.
channel (nextcord.TextChannel, optional): Channel to set in settings.
"""
channel_id = interaction.channel_id if channel is None else channel.id
settings.channel_ids.admin = channel_id
settings.save()
await interaction.response.send_message(f"Admin verification channel set to <#{channel_id}>.", ephemeral=True)
@channel_ids.subcommand(description="Sets announcement channel.")
async def announcement(
self,
interaction: nextcord.Interaction,
channel: nextcord.TextChannel = nextcord.SlashOption(
required=False, description="Channel to set to. If left blank, uses current channel."
),
) -> None:
"""
Sets DakinySettings channel_ids.announcement value to given channel id or current channel id.
Args:
interaction (nextcord.Interaction): Discord interaction of command.
channel (nextcord.TextChannel, optional): Channel to set in settings.
"""
channel_id = interaction.channel_id if channel is None else channel.id
settings.channel_ids.announcement = channel_id
settings.save()
await interaction.response.send_message(f"Announcement channel set to <#{channel_id}>.", ephemeral=True)
@channel_ids.subcommand(description="Sets clan info channel. Channel used for tracking current council.")
async def clan_info(
self,
interaction: nextcord.Interaction,
channel: nextcord.TextChannel = nextcord.SlashOption(
required=False, description="Channel to set to. If left blank, uses current channel."
),
) -> None:
"""
Sets DakinySettings channel_ids.clan_info value to given channel id or current channel id.
Args:
interaction (nextcord.Interaction): Discord interaction of command.
channel (nextcord.TextChannel, optional): Channel to set in settings.
"""
channel_id = interaction.channel_id if channel is None else channel.id
settings.channel_ids.clan_info = channel_id
settings.save()
await interaction.response.send_message(f"Clan information channel set to <#{channel_id}>.", ephemeral=True)
@channel_ids.subcommand(
description="Sets event post channel. Channel is where event tracking information is posted."
)
async def event_post(
self,
interaction: nextcord.Interaction,
channel: nextcord.TextChannel = nextcord.SlashOption(
required=False, description="Channel to set to. If left blank, uses current channel."
),
) -> None:
"""
Sets DakinySettings channel_ids.event_post value to given channel id or current channel id.
Args:
interaction (nextcord.Interaction): Discord interaction of command.
channel (nextcord.TextChannel, optional): Channel to set in settings.
"""
channel_id = interaction.channel_id if channel is None else channel.id
settings.channel_ids.event_post = channel_id
settings.save()
await interaction.response.send_message(f"Event posting channel set to <#{channel_id}>.", ephemeral=True)
@channel_ids.subcommand(description="Sets general channel.")
async def general(
self,
interaction: nextcord.Interaction,
channel: nextcord.TextChannel = nextcord.SlashOption(
required=False, description="Channel to set to. If left blank, uses current channel."
),
) -> None:
"""
Sets DakinySettings channel_ids.general value to given channel id or current channel id.
Args:
interaction (nextcord.Interaction): Discord interaction of command.
channel (nextcord.TextChannel, optional): Channel to set in settings.
"""
channel_id = interaction.channel_id if channel is None else channel.id
settings.channel_ids.general = channel_id
settings.save()
await interaction.response.send_message(f"General channel set to <#{channel_id}>.", ephemeral=True)
@channel_ids.subcommand(description="Sets voting channel. Channel used as parent for voting threads.")
async def voting(
self,
interaction: nextcord.Interaction,
channel: nextcord.TextChannel = nextcord.SlashOption(
required=False, description="Channel to set to. If left blank, uses current channel."
),
) -> None:
"""
Sets DakinySettings channel_ids.voting value to given channel id or current channel id.
Args:
interaction (nextcord.Interaction): Discord interaction of command.
channel (nextcord.TextChannel, optional): Channel to set in settings.
"""
channel_id = interaction.channel_id if channel is None else channel.id
settings.channel_ids.voting = channel_id
settings.save()
await interaction.response.send_message(f"Voting channel set to <#{channel_id}>.", ephemeral=True)
@settings.subcommand()
async def event_settings(self, interaction: nextcord.Interaction) -> None:
"""Subcommand parent. Never called."""
@event_settings.subcommand(description="Sets Event Host Points value.")
async def host_points(
self,
interaction: nextcord.Interaction,
points: int = nextcord.SlashOption(
required=True, description="Number of Event Points a host earns when hosting event.", min_value=0
),
) -> None:
"""
Sets DakinySettings event_settings.host_points to the given number of points.
Args:
interaction (nextcord.Interaction): Discord interaction of command.
points (int): Number of points to set.
"""
settings.event_settings.host_points = points
settings.save()
await interaction.response.send_message(f"Event Host Points set to {points}.", ephemeral=True)
@event_settings.subcommand(description="Sets Event Participation Points value.")
async def participate_points(
self,
interaction: nextcord.Interaction,
points: int = nextcord.SlashOption(
required=True,
description="Number of Event Points a participant earns when attending an event.",
min_value=0,
),
) -> None:
"""
Sets DakinySettings event_settings.participate_points to the given number of points.
Args:
interaction (nextcord.Interaction): Discord interaction of command.
points (int): Number of points to set.
"""
settings.event_settings.participate_points = points
settings.save()
await interaction.response.send_message(f"Event Participation Points set to {points}.", ephemeral=True)
@event_settings.subcommand(description="Sets Event Participation Points value.")
async def verify(
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 event_settings.verify to the given number of points.
Args:
interaction (nextcord.Interaction): Discord interaction of command.
do_verification (bool): If the bot should verify events.
"""
settings.event_settings.verify = do_verification
settings.save()
await interaction.response.send_message(f"Event verification set to {do_verification}.", ephemeral=True)
@event_settings.subcommand(description="Sets Event Weekly Limit value.")
async def 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 event_settings.weekly_limit to the given number of points.
Args:
interaction (nextcord.Interaction): Discord interaction of command.
points (int): Number of points to set.
"""
settings.event_settings.weekly_limit = points
settings.save()
await interaction.response.send_message(f"Event Weekly Limit set to {points}.", ephemeral=True)
@settings.subcommand()
async def role_ids(self, interaction: nextcord.Interaction) -> None:
"""Subcommand parent. Never called."""
@role_ids.subcommand(description="Sets Clan Council role id.")
async def clan_council(
self,
interaction: nextcord.Interaction,
role: nextcord.Role = nextcord.SlashOption(required=True, description="Role to set."),
) -> None:
"""
Sets DakinySettings role_ids.clan_council to the given role id.
Args:
interaction (nextcord.Interaction): Discord interaction of command.
role (nextcord.TextChannel): Role to set in settings.
"""
role_id = role.id
settings.role_ids.clan_council = role_id
settings.save()
await interaction.response.send_message(f"Clan Council role set to <@&{role_id}>.", ephemeral=True)
@role_ids.subcommand(description="Sets Clan Council Elect role id.")
async def clan_council_elect(
self,
interaction: nextcord.Interaction,
role: nextcord.Role = nextcord.SlashOption(required=True, description="Role to set."),
) -> None:
"""
Sets DakinySettings role_ids.clan_council_elect to the given role id.
Args:
interaction (nextcord.Interaction): Discord interaction of command.
role (nextcord.TextChannel): Role to set in settings.
"""
role_id = role.id
settings.role_ids.clan_council_elect = role_id
settings.save()
await interaction.response.send_message(f"Clan Council Elect role set to <@&{role_id}>.", ephemeral=True)
@role_ids.subcommand(description="Sets Clan Member role id.")
async def clan_member(
self,
interaction: nextcord.Interaction,
role: nextcord.Role = nextcord.SlashOption(required=True, description="Role to set."),
) -> None:
"""
Sets DakinySettings role_ids.clan_member to the given role id.
Args:
interaction (nextcord.Interaction): Discord interaction of command.
role (nextcord.TextChannel): Role to set in settings.
"""
role_id = role.id
settings.role_ids.clan_member = role_id
settings.save()
await interaction.response.send_message(f"Clan Member role set to <@&{role_id}>.", ephemeral=True)
@role_ids.subcommand(description="Sets Event Host role id.")
async def event_host(
self,
interaction: nextcord.Interaction,
role: nextcord.Role = nextcord.SlashOption(required=True, description="Role to set."),
) -> None:
"""
Sets DakinySettings role_ids.event_host to the given role id.
Args:
interaction (nextcord.Interaction): Discord interaction of command.
role (nextcord.TextChannel): Role to set in settings.
"""
role_id = role.id
settings.role_ids.event_host = role_id
settings.save()
await interaction.response.send_message(f"Event Host role set to <@&{role_id}>.", ephemeral=True)
@role_ids.subcommand(description="Sets High Council role id.")
async def high_council(
self,
interaction: nextcord.Interaction,
role: nextcord.Role = nextcord.SlashOption(required=True, description="Role to set."),
) -> None:
"""
Sets DakinySettings role_ids.high_council to the given role id.
Args:
interaction (nextcord.Interaction): Discord interaction of command.
role (nextcord.TextChannel): Role to set in settings.
"""
role_id = role.id
settings.role_ids.high_council = role_id
settings.save()
await interaction.response.send_message(f"High Council role set to <@&{role_id}>.", ephemeral=True)
+8 -20
View File
@@ -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_active_election_cycle, get_quarter_name from utils import GUILDS, get_current_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_active_election_cycle(), get_current_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_active_election_cycle(), get_current_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_active_election_cycle(), get_current_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_active_election_cycle(), get_current_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_active_election_cycle(), get_current_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_active_election_cycle(), get_current_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,20 +136,8 @@ 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_active_election_cycle(), get_current_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()
await interaction.send("Test command sent.", ephemeral=True) await interaction.send("Test command sent.", ephemeral=True)
@test.subcommand()
@is_me()
async def get_quarter_name(self, interaction: nextcord.Interaction) -> None:
"""
Tests getting the quarter name.
Args:
interaction (nextcord.Interaction): Interaction with the message.
"""
name = get_quarter_name()
await interaction.send(name)
+3 -5
View File
@@ -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_active_election_cycle from utils import get_current_election_cycle
if TYPE_CHECKING: if TYPE_CHECKING:
import nextcord import nextcord
@@ -75,15 +75,13 @@ 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_active_election_cycle() cycle = get_current_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
election = Election(cycle, self.bot.get_guild(settings.params.guild_id)) return 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."""
-1
View File
@@ -85,7 +85,6 @@ ignore = [
"E117", "E117",
"ISC001", "ISC001",
"ISC002", "ISC002",
"PD011", # doesn't like me using '.values' on embeds....
"Q000", "Q000",
"Q001", "Q001",
"Q002", "Q002",
+5 -7
View File
@@ -48,10 +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.
if today.month == calendar.DECEMBER and month < calendar.OCTOBER: if today.month == calendar.DECEMBER and month < calendar.DECEMBER:
year += 1 year += 1
if today.month == calendar.JANUARY and month > calendar.MARCH: 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)
@@ -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_active_election_cycle() cycle = get_current_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_active_election_cycle() -> int: def get_current_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,9 +104,7 @@ def get_active_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. Returns the index for the current cycle/quarter. Defined as between term start and end. Shouldn't return none.
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.