From 67d7e0495629b9868c6d239aa4f60178956f70fb Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sat, 17 Feb 2024 21:31:51 -0500 Subject: [PATCH 1/7] feat(aurora): updated all of the utils functions (and connected factory functions) to work with hybrid commands (UNTESTED) --- aurora/utilities/factory.py | 28 +++++++++++----------- aurora/utilities/utils.py | 48 ++++++++++++++++++------------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/aurora/utilities/factory.py b/aurora/utilities/factory.py index 18e5bd3..8c2965d 100644 --- a/aurora/utilities/factory.py +++ b/aurora/utilities/factory.py @@ -88,7 +88,7 @@ async def message_factory( async def log_factory( - interaction: Interaction, case_dict: dict, resolved: bool = False + ctx: commands.Context, case_dict: dict, resolved: bool = False ) -> Embed: """This function creates a log embed from set parameters, meant for moderation logging. @@ -99,20 +99,20 @@ async def log_factory( """ if resolved: if case_dict["target_type"] == "USER": - target_user = await fetch_user_dict(interaction.client, case_dict["target_id"]) + target_user = await fetch_user_dict(ctx.bot, case_dict["target_id"]) target_name = ( f"`{target_user['name']}`" if target_user["discriminator"] == "0" else f"`{target_user['name']}#{target_user['discriminator']}`" ) elif case_dict["target_type"] == "CHANNEL": - target_user = await fetch_channel_dict(interaction.guild, case_dict["target_id"]) + target_user = await fetch_channel_dict(ctx.guild, case_dict["target_id"]) if target_user["mention"]: target_name = f"{target_user['mention']}" else: target_name = f"`{target_user['name']}`" - moderator_user = await fetch_user_dict(interaction.client, case_dict["moderator_id"]) + moderator_user = await fetch_user_dict(ctx.bot, case_dict["moderator_id"]) moderator_name = ( f"`{moderator_user['name']}`" if moderator_user["discriminator"] == "0" @@ -121,7 +121,7 @@ async def log_factory( embed = Embed( title=f"📕 Case #{case_dict['moderation_id']:,} Resolved", - color=await interaction.client.get_embed_color(interaction.channel), + color=await ctx.client.get_embed_color(ctx.channel), ) embed.description = f"**Type:** {str.title(case_dict['moderation_type'])}\n**Target:** {target_name} ({target_user['id']})\n**Moderator:** {moderator_name} ({moderator_user['id']})\n**Timestamp:** | " @@ -148,7 +148,7 @@ async def log_factory( embed.add_field(name="Reason", value=box(case_dict["reason"]), inline=False) - resolved_user = await fetch_user_dict(interaction.client, case_dict["resolved_by"]) + resolved_user = await fetch_user_dict(ctx.bot, case_dict["resolved_by"]) resolved_name = ( resolved_user["name"] if resolved_user["discriminator"] == "0" @@ -162,20 +162,20 @@ async def log_factory( ) else: if case_dict["target_type"] == "USER": - target_user = await fetch_user_dict(interaction.client, case_dict["target_id"]) + target_user = await fetch_user_dict(ctx.bot, case_dict["target_id"]) target_name = ( f"`{target_user['name']}`" if target_user["discriminator"] == "0" else f"`{target_user['name']}#{target_user['discriminator']}`" ) elif case_dict["target_type"] == "CHANNEL": - target_user = await fetch_channel_dict(interaction.guild, case_dict["target_id"]) + target_user = await fetch_channel_dict(ctx.guild, case_dict["target_id"]) if target_user["mention"]: target_name = target_user["mention"] else: target_name = f"`{target_user['name']}`" - moderator_user = await fetch_user_dict(interaction.client, case_dict["moderator_id"]) + moderator_user = await fetch_user_dict(ctx.bot, case_dict["moderator_id"]) moderator_name = ( f"`{moderator_user['name']}`" if moderator_user["discriminator"] == "0" @@ -184,7 +184,7 @@ async def log_factory( embed = Embed( title=f"📕 Case #{case_dict['moderation_id']:,}", - color=await interaction.client.get_embed_color(interaction.channel), + color=await ctx.bot.get_embed_color(ctx.channel), ) embed.description = f"**Type:** {str.title(case_dict['moderation_type'])}\n**Target:** {target_name} ({target_user['id']})\n**Moderator:** {moderator_name} ({moderator_user['id']})\n**Timestamp:** | " @@ -344,7 +344,7 @@ async def changes_factory(interaction: Interaction, case_dict: dict) -> Embed: return embed -async def evidenceformat_factory(interaction: Interaction, case_dict: dict) -> str: +async def evidenceformat_factory(ctx: commands.Context, case_dict: dict) -> str: """This function creates a codeblock in evidence format from set parameters. Args: @@ -352,7 +352,7 @@ async def evidenceformat_factory(interaction: Interaction, case_dict: dict) -> s case_dict (dict): The case dictionary. """ if case_dict["target_type"] == "USER": - target_user = await fetch_user_dict(interaction.client, case_dict["target_id"]) + target_user = await fetch_user_dict(ctx.bot, case_dict["target_id"]) target_name = ( target_user["name"] if target_user["discriminator"] == "0" @@ -360,10 +360,10 @@ async def evidenceformat_factory(interaction: Interaction, case_dict: dict) -> s ) elif case_dict["target_type"] == "CHANNEL": - target_user = await fetch_channel_dict(interaction.guild, case_dict["target_id"]) + target_user = await fetch_channel_dict(ctx.guild, case_dict["target_id"]) target_name = target_user["name"] - moderator_user = await fetch_user_dict(interaction.client, case_dict["moderator_id"]) + moderator_user = await fetch_user_dict(ctx.bot, case_dict["moderator_id"]) moderator_name = ( moderator_user["name"] if moderator_user["discriminator"] == "0" diff --git a/aurora/utilities/utils.py b/aurora/utilities/utils.py index 24dbe34..47a8e46 100644 --- a/aurora/utilities/utils.py +++ b/aurora/utilities/utils.py @@ -39,11 +39,11 @@ def check_permissions( async def check_moddable( - target: Union[User, Member], interaction: Interaction, permissions: list + target: Union[User, Member], ctx: Union[commands.Context, Interaction], permissions: list ) -> bool: """Checks if a moderator can moderate a target.""" - if check_permissions(interaction.client.user, permissions, guild=interaction.guild): - await interaction.response.send_message( + if check_permissions(ctx.bot.user, permissions, guild=ctx.guild): + await ctx.send( error( f"I do not have the `{permissions}` permission, required for this action." ), @@ -51,9 +51,9 @@ async def check_moddable( ) return False - if await config.guild(interaction.guild).use_discord_permissions() is True: - if check_permissions(interaction.user, permissions, guild=interaction.guild): - await interaction.response.send_message( + if await config.guild(ctx.guild).use_discord_permissions() is True: + if check_permissions(ctx.author, permissions, guild=ctx.guild): + await ctx.send( error( f"You do not have the `{permissions}` permission, required for this action." ), @@ -61,21 +61,21 @@ async def check_moddable( ) return False - if interaction.user.id == target.id: - await interaction.response.send_message( + if ctx.author.id == target.id: + await ctx.send( content="You cannot moderate yourself!", ephemeral=True ) return False if target.bot: - await interaction.response.send_message( + await ctx.send( content="You cannot moderate bots!", ephemeral=True ) return False if isinstance(target, Member): - if interaction.user.top_role <= target.top_role: - await interaction.response.send_message( + if ctx.author.top_role <= target.top_role: + await ctx.send( content=error( "You cannot moderate members with a higher role than you!" ), @@ -84,10 +84,10 @@ async def check_moddable( return False if ( - interaction.guild.get_member(interaction.client.user.id).top_role + ctx.guild.get_member(ctx.bot.user.id).top_role <= target.top_role ): - await interaction.response.send_message( + await ctx.send( content=error( "You cannot moderate members with a role higher than the bot!" ), @@ -99,7 +99,7 @@ async def check_moddable( for role in target.roles: if role.id in immune_roles: - await interaction.response.send_message( + await ctx.send( content=error("You cannot moderate members with an immune role!"), ephemeral=True, ) @@ -202,19 +202,19 @@ async def fetch_role_dict(guild: Guild, role_id: int) -> dict: return role_dict -async def log(interaction: Interaction, moderation_id: int, resolved: bool = False) -> None: +async def log(ctx: Union[commands.Context, Interaction], moderation_id: int, resolved: bool = False) -> None: """This function sends a message to the guild's configured logging channel when an infraction takes place.""" from .database import fetch_case from .factory import log_factory - logging_channel_id = await config.guild(interaction.guild).log_channel() + logging_channel_id = await config.guild(ctx.guild).log_channel() if logging_channel_id != " ": - logging_channel = interaction.guild.get_channel(logging_channel_id) + logging_channel = ctx.guild.get_channel(logging_channel_id) - case = await fetch_case(moderation_id, interaction.guild.id) + case = await fetch_case(moderation_id, ctx.guild.id) if case: embed = await log_factory( - interaction=interaction, case_dict=case, resolved=resolved + ctx=ctx, case_dict=case, resolved=resolved ) try: await logging_channel.send(embed=embed) @@ -222,20 +222,20 @@ async def log(interaction: Interaction, moderation_id: int, resolved: bool = Fal return -async def send_evidenceformat(interaction: Interaction, case_dict: dict) -> None: +async def send_evidenceformat(ctx: commands.Context, case_dict: dict) -> None: """This function sends an ephemeral message to the moderator who took the moderation action, with a pre-made codeblock for use in the mod-evidence channel.""" from .factory import evidenceformat_factory send_evidence_bool = ( - await config.user(interaction.user).auto_evidenceformat() - or await config.guild(interaction.guild).auto_evidenceformat() + await config.user(ctx.author).auto_evidenceformat() + or await config.guild(ctx.guild).auto_evidenceformat() or False ) if send_evidence_bool is False: return - content = await evidenceformat_factory(interaction=interaction, case_dict=case_dict) - await interaction.followup.send(content=content, ephemeral=True) + content = await evidenceformat_factory(ctx=ctx, case_dict=case_dict) + await ctx.send(content=content, ephemeral=True) def convert_timedelta_to_str(timedelta: td) -> str: -- 2.45.2 From cfa95118aeae4b5836e41f542e34d264726bee70 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Sat, 17 Feb 2024 21:47:31 -0500 Subject: [PATCH 2/7] feat(aurora): factory functions now support hybrid commands (in theory, UNTESTED) --- aurora/utilities/factory.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/aurora/utilities/factory.py b/aurora/utilities/factory.py index 8c2965d..0aa4fe5 100644 --- a/aurora/utilities/factory.py +++ b/aurora/utilities/factory.py @@ -2,14 +2,13 @@ from datetime import datetime, timedelta from typing import Union import humanize -from discord import Color, Embed, Guild, Interaction, InteractionMessage, Member, Role, User +from discord import Color, Embed, Guild, Member, Message, Role, User from redbot.core import commands from redbot.core.utils.chat_formatting import bold, box, error, warning from aurora.utilities.config import config from aurora.utilities.utils import fetch_channel_dict, fetch_user_dict, get_bool_emoji, get_next_case_number, get_pagesize_str - async def message_factory( color: Color, guild: Guild, @@ -17,7 +16,7 @@ async def message_factory( moderation_type: str, moderator: Union[Member, User] = None, duration: timedelta = None, - response: InteractionMessage = None, + response: Message = None, role: Role = None, ) -> Embed: """This function creates a message from set parameters, meant for contacting the moderated user. @@ -29,10 +28,9 @@ async def message_factory( moderation_type (str): The type of moderation. moderator (Union[Member, User], optional): The moderator who performed the moderation. Defaults to None. duration (timedelta, optional): The duration of the moderation. Defaults to None. - response (InteractionMessage, optional): The response message. Defaults to None. + response (Message, optional): The response message. Defaults to None. role (Role, optional): The role that was added or removed. Defaults to None. - Returns: embed: The message embed. """ @@ -207,28 +205,28 @@ async def log_factory( return embed -async def case_factory(interaction: Interaction, case_dict: dict) -> Embed: +async def case_factory(ctx: commands.Context, case_dict: dict) -> Embed: """This function creates a case embed from set parameters. Args: - interaction (Interaction): The interaction object. + ctx (commands.Context): The context object. case_dict (dict): The case dictionary. """ if case_dict["target_type"] == "USER": - target_user = await fetch_user_dict(interaction.client, case_dict["target_id"]) + target_user = await fetch_user_dict(ctx.bot, case_dict["target_id"]) target_name = ( f"`{target_user['name']}`" if target_user["discriminator"] == "0" else f"`{target_user['name']}#{target_user['discriminator']}`" ) elif case_dict["target_type"] == "CHANNEL": - target_user = await fetch_channel_dict(interaction.guild, case_dict["target_id"]) + target_user = await fetch_channel_dict(ctx.guild, case_dict["target_id"]) if target_user["mention"]: target_name = f"{target_user['mention']}" else: target_name = f"`{target_user['name']}`" - moderator_user = await fetch_user_dict(interaction.client, case_dict["moderator_id"]) + moderator_user = await fetch_user_dict(ctx.bot, case_dict["moderator_id"]) moderator_name = ( f"`{moderator_user['name']}`" if moderator_user["discriminator"] == "0" @@ -237,7 +235,7 @@ async def case_factory(interaction: Interaction, case_dict: dict) -> Embed: embed = Embed( title=f"📕 Case #{case_dict['moderation_id']:,}", - color=await interaction.client.get_embed_color(interaction.channel), + color=await ctx.bot.get_embed_color(ctx.channel), ) embed.description = f"**Type:** {str.title(case_dict['moderation_type'])}\n**Target:** {target_name} ({target_user['id']})\n**Moderator:** {moderator_name} ({moderator_user['id']})\n**Resolved:** {bool(case_dict['resolved'])}\n**Timestamp:** | " @@ -272,7 +270,7 @@ async def case_factory(interaction: Interaction, case_dict: dict) -> Embed: embed.add_field(name="Reason", value=box(case_dict["reason"]), inline=False) if case_dict["resolved"] == 1: - resolved_user = await fetch_user_dict(interaction.client, case_dict["resolved_by"]) + resolved_user = await fetch_user_dict(ctx.bot, case_dict["resolved_by"]) resolved_name = ( f"`{resolved_user['name']}`" if resolved_user["discriminator"] == "0" @@ -287,16 +285,16 @@ async def case_factory(interaction: Interaction, case_dict: dict) -> Embed: return embed -async def changes_factory(interaction: Interaction, case_dict: dict) -> Embed: +async def changes_factory(ctx: commands.Context, case_dict: dict) -> Embed: """This function creates a changes embed from set parameters. Args: - interaction (Interaction): The interaction object. + ctx (commands.Context): The context object. case_dict (dict): The case dictionary. """ embed = Embed( title=f"📕 Case #{case_dict['moderation_id']:,} Changes", - color=await interaction.client.get_embed_color(interaction.channel), + color=await ctx.bot.get_embed_color(ctx.channel), ) memory_dict = {} @@ -305,7 +303,7 @@ async def changes_factory(interaction: Interaction, case_dict: dict) -> Embed: for change in case_dict["changes"]: if change["user_id"] not in memory_dict: memory_dict[str(change["user_id"])] = await fetch_user_dict( - interaction.client, change["user_id"] + ctx.bot, change["user_id"] ) user = memory_dict[str(change["user_id"])] -- 2.45.2 From 16a37691b5273fbe91777c50adc5360716a50de6 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Thu, 7 Mar 2024 15:03:55 -0500 Subject: [PATCH 3/7] feat(aurora): converted note to a hybrid command --- aurora/aurora.py | 33 +++++++++++++++++---------------- aurora/utilities/factory.py | 6 ++++-- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/aurora/aurora.py b/aurora/aurora.py index 1f946f4..465fb6a 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -48,7 +48,7 @@ class Aurora(commands.Cog): This cog stores all of its data in an SQLite database.""" __author__ = ["SeaswimmerTheFsh"] - __version__ = "2.0.6" + __version__ = "2.1.6" async def red_delete_data_for_user(self, *, requester, user_id: int): if requester == "discord_deleted_user": @@ -180,10 +180,11 @@ class Aurora(commands.Cog): ### COMMANDS ####################################################################################################################### - @app_commands.command(name="note") + @commands.hybrid_command(name="note") + @commands.mod_or_permissions(moderate_members=True) async def note( self, - interaction: discord.Interaction, + ctx: commands.Context, target: discord.User, reason: str, silent: bool = None, @@ -198,32 +199,32 @@ class Aurora(commands.Cog): Why are you noting this user? silent: bool Should the user be messaged?""" - if not await check_moddable(target, interaction, ["moderate_members"]): + if not await check_moddable(target, ctx, ["moderate_members"]): return - await interaction.response.send_message( + message = await ctx.send( content=f"{target.mention} has recieved a note!\n**Reason** - `{reason}`" ) if silent is None: - silent = not await config.guild(interaction.guild).dm_users() + silent = not await config.guild(ctx.guild).dm_users() if silent is False: try: embed = await message_factory( - await self.bot.get_embed_color(interaction.channel), - guild=interaction.guild, - moderator=interaction.user, + await self.bot.get_embed_color(ctx.channel), + guild=ctx.guild, + moderator=ctx.author, reason=reason, moderation_type="note", - response=await interaction.original_response(), + response=message, ) await target.send(embed=embed) except discord.errors.HTTPException: pass moderation_id = await mysql_log( - interaction.guild.id, - interaction.user.id, + ctx.guild.id, + ctx.author.id, "NOTE", "USER", target.id, @@ -231,13 +232,13 @@ class Aurora(commands.Cog): "NULL", reason, ) - await interaction.edit_original_response( + await message.edit( content=f"{target.mention} has received a note! (Case `#{moderation_id:,}`)\n**Reason** - `{reason}`" ) - await log(interaction, moderation_id) + await log(ctx, moderation_id) - case = await fetch_case(moderation_id, interaction.guild.id) - await send_evidenceformat(interaction, case) + case = await fetch_case(moderation_id, ctx.guild.id) + await send_evidenceformat(ctx, case) @app_commands.command(name="warn") async def warn( diff --git a/aurora/utilities/factory.py b/aurora/utilities/factory.py index 48de0ed..69d8cda 100644 --- a/aurora/utilities/factory.py +++ b/aurora/utilities/factory.py @@ -3,12 +3,14 @@ from datetime import datetime, timedelta from typing import Union import humanize -from discord import Color, Embed, Guild, Member, Role, User +from discord import Color, Embed, Guild, Member, Message, Role, User from redbot.core import commands from redbot.core.utils.chat_formatting import bold, box, error, warning from aurora.utilities.config import config -from aurora.utilities.utils import fetch_channel_dict, fetch_user_dict, get_bool_emoji, get_next_case_number, get_pagesize_str +from aurora.utilities.utils import (fetch_channel_dict, fetch_user_dict, + get_bool_emoji, get_next_case_number, + get_pagesize_str) async def message_factory( -- 2.45.2 From 918c058f5a7e24cbf9d4044d936eee88f159fee2 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Thu, 7 Mar 2024 15:11:26 -0500 Subject: [PATCH 4/7] feat(aurora): converted warn to a hybrid command --- aurora/aurora.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/aurora/aurora.py b/aurora/aurora.py index 465fb6a..9cff9d9 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -240,10 +240,11 @@ class Aurora(commands.Cog): case = await fetch_case(moderation_id, ctx.guild.id) await send_evidenceformat(ctx, case) - @app_commands.command(name="warn") + @commands.hybrid_command(name="warn") + @commands.mod_or_permissions(moderate_members=True) async def warn( self, - interaction: discord.Interaction, + ctx: commands.Context, target: discord.Member, reason: str, silent: bool = None, @@ -258,32 +259,32 @@ class Aurora(commands.Cog): Why are you warning this user? silent: bool Should the user be messaged?""" - if not await check_moddable(target, interaction, ["moderate_members"]): + if not await check_moddable(target, ctx, ["moderate_members"]): return - await interaction.response.send_message( + message = await ctx.send( content=f"{target.mention} has been warned!\n**Reason** - `{reason}`" ) if silent is None: - silent = not await config.guild(interaction.guild).dm_users() + silent = not await config.guild(ctx.guild).dm_users() if silent is False: try: embed = await message_factory( - await self.bot.get_embed_color(interaction.channel), - guild=interaction.guild, - moderator=interaction.user, + await self.bot.get_embed_color(ctx.channel), + guild=ctx.guild, + moderator=ctx.author, reason=reason, moderation_type="warned", - response=await interaction.original_response(), + response=message, ) await target.send(embed=embed) except discord.errors.HTTPException: pass moderation_id = await mysql_log( - interaction.guild.id, - interaction.user.id, + ctx.guild.id, + ctx.author.id, "WARN", "USER", target.id, @@ -291,13 +292,13 @@ class Aurora(commands.Cog): "NULL", reason, ) - await interaction.edit_original_response( + await message.edit( content=f"{target.mention} has been warned! (Case `#{moderation_id:,}`)\n**Reason** - `{reason}`" ) - await log(interaction, moderation_id) + await log(ctx, moderation_id) - case = await fetch_case(moderation_id, interaction.guild.id) - await send_evidenceformat(interaction, case) + case = await fetch_case(moderation_id, ctx.guild.id) + await send_evidenceformat(ctx, case) @app_commands.command(name="addrole") async def addrole( -- 2.45.2 From 246140da9bd0f8e083045c341c0c7b1cce04ec2f Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Thu, 7 Mar 2024 16:11:15 -0500 Subject: [PATCH 5/7] fix(aurora): fixed argument descriptions --- aurora/aurora.py | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/aurora/aurora.py b/aurora/aurora.py index 9cff9d9..629477c 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -182,6 +182,11 @@ class Aurora(commands.Cog): @commands.hybrid_command(name="note") @commands.mod_or_permissions(moderate_members=True) + @app_commands.describe( + target="Who are you noting?", + reason="Why are you noting this user?", + silent="Should the user be messaged?", + ) async def note( self, ctx: commands.Context, @@ -189,16 +194,7 @@ class Aurora(commands.Cog): reason: str, silent: bool = None, ): - """Add a note to a user. - - Parameters - ----------- - target: discord.User - Who are you noting? - reason: str - Why are you noting this user? - silent: bool - Should the user be messaged?""" + """Add a note to a user.""" if not await check_moddable(target, ctx, ["moderate_members"]): return @@ -242,6 +238,11 @@ class Aurora(commands.Cog): @commands.hybrid_command(name="warn") @commands.mod_or_permissions(moderate_members=True) + @app_commands.describe( + target="Who are you warning?", + reason="Why are you warning this user?", + silent="Should the user be messaged?", + ) async def warn( self, ctx: commands.Context, @@ -249,16 +250,7 @@ class Aurora(commands.Cog): reason: str, silent: bool = None, ): - """Warn a user. - - Parameters - ----------- - target: discord.Member - Who are you warning? - reason: str - Why are you warning this user? - silent: bool - Should the user be messaged?""" + """Warn a user.""" if not await check_moddable(target, ctx, ["moderate_members"]): return -- 2.45.2 From e2d2b7bdc19be44c29b3b941f4f2353bf8b123a8 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Thu, 7 Mar 2024 16:13:47 -0500 Subject: [PATCH 6/7] feat(aurora): converted mute to a hybrid command --- aurora/aurora.py | 58 ++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/aurora/aurora.py b/aurora/aurora.py index 629477c..cb996c9 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -401,32 +401,28 @@ class Aurora(commands.Cog): case = await fetch_case(moderation_id, interaction.guild.id) await send_evidenceformat(interaction, case) - @app_commands.command(name="mute") + @commands.hybrid_command(name="mute") + @commands.mod_or_permissions(moderate_members=True) + @app_commands.describe( + target="Who are you muting?", + duration="How long are you muting this user for?", + reason="Why are you muting this user?", + silent="Should the user be messaged?", + ) async def mute( self, - interaction: discord.Interaction, + ctx: commands.Context, target: discord.Member, duration: str, reason: str, silent: bool = None, ): - """Mute a user. - - Parameters - ----------- - target: discord.Member - Who are you unbanning? - duration: str - How long are you muting this user for? - reason: str - Why are you unbanning this user? - silent: bool - Should the user be messaged?""" - if not await check_moddable(target, interaction, ["moderate_members"]): + """Mute a user.""" + if not await check_moddable(target, ctx, ["moderate_members"]): return if target.is_timed_out() is True: - await interaction.response.send_message( + await ctx.send( error(f"{target.mention} is already muted!"), allowed_mentions=discord.AllowedMentions(users=False), ephemeral=True, @@ -436,36 +432,36 @@ class Aurora(commands.Cog): try: parsed_time = parse(sval=duration, as_timedelta=True, raise_exception=True) except ValueError: - await interaction.response.send_message( + await ctx.send( error("Please provide a valid duration!"), ephemeral=True ) return if parsed_time.total_seconds() / 1000 > 2419200000: - await interaction.response.send_message( + await ctx.send( error("Please provide a duration that is less than 28 days.") ) return await target.timeout( - parsed_time, reason=f"Muted by {interaction.user.id} for: {reason}" + parsed_time, reason=f"Muted by {ctx.author.id} for: {reason}" ) - await interaction.response.send_message( + message = await ctx.send( content=f"{target.mention} has been muted for {humanize.precisedelta(parsed_time)}!\n**Reason** - `{reason}`" ) if silent is None: - silent = not await config.guild(interaction.guild).dm_users() + silent = not await config.guild(ctx.guild).dm_users() if silent is False: try: embed = await message_factory( - await self.bot.get_embed_color(interaction.channel), - guild=interaction.guild, - moderator=interaction.user, + await ctx.embed_color(), + guild=ctx.guild, + moderator=ctx.author, reason=reason, moderation_type="muted", - response=await interaction.original_response(), + response=message, duration=parsed_time, ) await target.send(embed=embed) @@ -473,8 +469,8 @@ class Aurora(commands.Cog): pass moderation_id = await mysql_log( - interaction.guild.id, - interaction.user.id, + ctx.guild.id, + ctx.author.id, "MUTE", "USER", target.id, @@ -482,13 +478,13 @@ class Aurora(commands.Cog): parsed_time, reason, ) - await interaction.edit_original_response( + await message.edit( content=f"{target.mention} has been muted for {humanize.precisedelta(parsed_time)}! (Case `#{moderation_id:,}`)\n**Reason** - `{reason}`" ) - await log(interaction, moderation_id) + await log(ctx, moderation_id) - case = await fetch_case(moderation_id, interaction.guild.id) - await send_evidenceformat(interaction, case) + case = await fetch_case(moderation_id, ctx.guild.id) + await send_evidenceformat(ctx, case) @app_commands.command(name="unmute") async def unmute( -- 2.45.2 From 416d67bf65cf74bdb43d47f896cd3d01fcbf4773 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Thu, 7 Mar 2024 16:21:32 -0500 Subject: [PATCH 7/7] feat(aurora): converted unmute to a hybrid command --- aurora/aurora.py | 53 +++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/aurora/aurora.py b/aurora/aurora.py index cb996c9..7414b78 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -486,29 +486,26 @@ class Aurora(commands.Cog): case = await fetch_case(moderation_id, ctx.guild.id) await send_evidenceformat(ctx, case) - @app_commands.command(name="unmute") + @commands.hybrid_command(name="unmute") + @commands.mod_or_permissions(moderate_members=True) + @app_commands.describe( + target="Who are you unmuting?", + reason="Why are you unmuting this user?", + silent="Should the user be messaged?", + ) async def unmute( self, - interaction: discord.Interaction, + ctx: commands.Context, target: discord.Member, reason: str = None, silent: bool = None, ): - """Unmute a user. - - Parameters - ----------- - target: discord.user - Who are you unmuting? - reason: str - Why are you unmuting this user? - silent: bool - Should the user be messaged?""" - if not await check_moddable(target, interaction, ["moderate_members"]): + """Unmute a user.""" + if not await check_moddable(target, ctx, ["moderate_members"]): return if target.is_timed_out() is False: - await interaction.response.send_message( + await ctx.send( error(f"{target.mention} is not muted!"), allowed_mentions=discord.AllowedMentions(users=False), ephemeral=True, @@ -517,35 +514,35 @@ class Aurora(commands.Cog): if reason: await target.timeout( - None, reason=f"Unmuted by {interaction.user.id} for: {reason}" + None, reason=f"Unmuted by {ctx.author.id} for: {reason}" ) else: - await target.timeout(None, reason=f"Unbanned by {interaction.user.id}") + await target.timeout(None, reason=f"Unmuted by {ctx.author.id}") reason = "No reason given." - await interaction.response.send_message( + message = await ctx.send( content=f"{target.mention} has been unmuted!\n**Reason** - `{reason}`" ) if silent is None: - silent = not await config.guild(interaction.guild).dm_users() + silent = not await config.guild(ctx.guild).dm_users() if silent is False: try: embed = await message_factory( - await self.bot.get_embed_color(interaction.channel), - guild=interaction.guild, - moderator=interaction.user, + await ctx.embed_color(), + guild=ctx.guild, + moderator=ctx.author, reason=reason, moderation_type="unmuted", - response=await interaction.original_response(), + response=message, ) await target.send(embed=embed) except discord.errors.HTTPException: pass moderation_id = await mysql_log( - interaction.guild.id, - interaction.user.id, + ctx.guild.id, + ctx.author.id, "UNMUTE", "USER", target.id, @@ -553,13 +550,13 @@ class Aurora(commands.Cog): "NULL", reason, ) - await interaction.edit_original_response( + await message.edit( content=f"{target.mention} has been unmuted! (Case `#{moderation_id:,}`)\n**Reason** - `{reason}`" ) - await log(interaction, moderation_id) + await log(ctx, moderation_id) - case = await fetch_case(moderation_id, interaction.guild.id) - await send_evidenceformat(interaction, case) + case = await fetch_case(moderation_id, ctx.guild.id) + await send_evidenceformat(ctx, case) @app_commands.command(name="kick") async def kick( -- 2.45.2