From 07906aaea137adf3b3477fa773fbeaad520e5b7f Mon Sep 17 00:00:00 2001 From: imcompiling Date: Thu, 1 Aug 2024 21:46:16 -0400 Subject: [PATCH 1/2] Spell check and ruff fixes. --- .vscode/settings.json | 10 ++++++++++ utils.py | 8 ++++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f1b7934 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,10 @@ +{ + "cSpell.words": [ + "aiofiles", + "blurple", + "CLANLEADER", + "Dakiny", + "DISCORDMANAGER", + "highcouncil" + ] +} \ No newline at end of file diff --git a/utils.py b/utils.py index e02ada8..ce4ddd9 100644 --- a/utils.py +++ b/utils.py @@ -137,7 +137,7 @@ def build_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> str: Creates a string that contains all nominees and their votes to be sent as a discord message. Args: - config (DakinyConfig): Daking config object + config (DakinyConfig): Dakiny config object guild (nextcord.Guild): The guild object. Used to get display names for sorting. Returns: @@ -173,7 +173,7 @@ def build_highcouncil_votes_str(config: DakinyConfig, guild: nextcord.Guild) -> Creates a string that contains all high council nominees and their votes to be sent as a discord message. Args: - config (DakinyConfig): Daking config object + config (DakinyConfig): Dakiny config object guild (nextcord.Guild): The guild object. Used to get display names for sorting. Returns: @@ -374,7 +374,7 @@ def get_allowed_points(session: Session, points_limit: int, user: str, points: i add_points = ( points if limit.Points + points <= points_limit - else (points_limit - limit.Points if points_limit - limit.Points > 0 else 0) + else (max(0, points_limit - limit.Points)) ) limit.Points += add_points @@ -512,7 +512,7 @@ async def edit_clan_message( async def edit_clan_council_info(guild: nextcord.Guild, config: DakinyConfig) -> None: """ - Gets the winners of the elections and updates the perminant message that states the current council. + Gets the winners of the elections and updates the permanent message that states the current council. Args: guild (nextcord.Guild): Guild object that to use to get channel. From 2bdb7cb17b44a80286d5bbf689b1f2e5a88dcda0 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Thu, 1 Aug 2024 21:48:33 -0400 Subject: [PATCH 2/2] Add the record point command. --- cogs/commands/record.py | 84 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/cogs/commands/record.py b/cogs/commands/record.py index 9fb7810..cd2f1a3 100644 --- a/cogs/commands/record.py +++ b/cogs/commands/record.py @@ -5,7 +5,7 @@ from discord import TextInputStyle from nextcord.ext import commands from config import DakinyConfig -from utils import record_event_points +from utils import GUILDS, MAX_DISCORD_MESSAGE_LENGTH, record_event_points class RecordCog(commands.Cog, name="Record Commands"): @@ -16,7 +16,7 @@ class RecordCog(commands.Cog, name="Record Commands"): super().__init__() self.bot: commands.Bot = bot - @nextcord.slash_command() + @nextcord.slash_command(guild_ids=GUILDS) async def record(self, interaction: nextcord.Interaction) -> None: """Parent slash command for record. Never called.""" @@ -64,6 +64,86 @@ class RecordCog(commands.Cog, name="Record Commands"): embed=embed, ) + @record.subcommand(description="Record a miscellaneous point for a clan member.") + async def point( # noqa: PLR0913 + self, + interaction: nextcord.Interaction, + activity: str = nextcord.SlashOption( + description="The type of activity to receive points for.", + required=True, + choices=[ + "Clan chat activity", + "Teaching or sharing in-game tips", + "Recruiting efforts", + "Successful recruitment", + ], + ), + justification: str = nextcord.SlashOption( + required=True, + description="Reason to give the recipient a point.", + max_length=int(MAX_DISCORD_MESSAGE_LENGTH / 2), + ), + recipient: nextcord.Member = nextcord.SlashOption( + required=False, + description="Discord user to give point to.", + ), + non_discord_recipient: str = nextcord.SlashOption( + required=False, description="Non Discord user to give point to.", max_length=32 + ), + ) -> None: + """ + Gives a point to the provided recipient. Sends recording message to event participation channel. + + Only one recipient should be given point/provided to the command. Fails if not exactly one recipient + is given. + + Args: + interaction (nextcord.Interaction): interaction with this command. + activity (str): Choice list of activities to give point for. + justification (str): Reason to give point. + recipient (nextcord.Member): Discord member to give point to. + non_discord_recipient (str): Non Discord member to give point to. + """ + # role check + if interaction.guild.get_role(self.bot.config.params.clan_member_role_id) not in interaction.user.roles: + await interaction.response.send_message( + f"You must have the <@&{self.bot.config.params.clan_member_role_id}> role to record points.", + ephemeral=True, + ) + return + + # pylint or whatever seems to think that there are lines of unreachable code. That is false. + if recipient and non_discord_recipient: + await interaction.response.send_message("Please only provide 1 recipient.", ephemeral=True) + return + elif recipient is not None: # noqa: RET505 + record_event_points( + self.bot.config, + [str(recipient.id)], + self.bot.config.params.event_participate_points, + is_member=True, + ) + recipient_str = f"<@{recipient.id}>" + elif non_discord_recipient is not None: + record_event_points( + self.bot.config, + [non_discord_recipient], + self.bot.config.params.event_participate_points, + is_member=False, + ) + recipient_str = f'"{non_discord_recipient}"' + else: + await interaction.response.send_message("You must provide a recipient.", ephemeral=True) + return + + event_channel: nextcord.TextChannel = interaction.guild.get_channel( + self.bot.config.params.event_post_channel_id + ) + + msg = f"<@{interaction.user.id}> has given {recipient_str} points for the {activity} activity. Justification: {justification}." # noqa: E501 + await event_channel.send(msg) + await interaction.response.send_message("Point has been added.", ephemeral=True) + class EventView(nextcord.ui.View): """