From 67b33a2eb8e120daa0bb6222a142b3dd564b4a31 Mon Sep 17 00:00:00 2001 From: Seaswimmer Date: Fri, 24 May 2024 03:46:20 -0400 Subject: [PATCH] feat(aurora): added a slowmode command --- aurora/aurora.py | 53 +++++++++++++++++++++++++++++++------ aurora/models/moderation.py | 2 +- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/aurora/aurora.py b/aurora/aurora.py index 01655a9..5d4e983 100644 --- a/aurora/aurora.py +++ b/aurora/aurora.py @@ -20,8 +20,7 @@ from redbot.core import app_commands, commands, data_manager from redbot.core.app_commands import Choice from redbot.core.bot import Red from redbot.core.commands.converter import parse_relativedelta, parse_timedelta -from redbot.core.utils.chat_formatting import (box, error, humanize_list, - humanize_timedelta, warning) +from redbot.core.utils.chat_formatting import box, error, humanize_list, humanize_timedelta, warning from .importers.aurora import ImportAuroraView from .importers.galacticbot import ImportGalacticBotView @@ -33,14 +32,10 @@ from .models.change import Change from .models.moderation import Moderation from .utilities.config import config, register_config from .utilities.database import connect, create_guild_table -from .utilities.factory import (addrole_embed, case_factory, changes_factory, - evidenceformat_factory, guild_embed, - immune_embed, message_factory, overrides_embed) +from .utilities.factory import addrole_embed, case_factory, changes_factory, evidenceformat_factory, guild_embed, immune_embed, message_factory, overrides_embed from .utilities.json import dump from .utilities.logger import logger -from .utilities.utils import (check_moddable, check_permissions, - get_footer_image, log, send_evidenceformat, - timedelta_from_relativedelta) +from .utilities.utils import check_moddable, check_permissions, get_footer_image, log, send_evidenceformat, timedelta_from_relativedelta class Aurora(commands.Cog): @@ -970,6 +965,48 @@ class Aurora(commands.Cog): await log(interaction, moderation.id) await send_evidenceformat(interaction, moderation.id) + @app_commands.command(name="slowmode") + async def slowmode( + self, + interaction: discord.Interaction, + interval: int, + channel: discord.TextChannel | None = None, + reason: str | None = None, + ): + """Set the slowmode of a channel. + + Parameters + ----------- + interval: int + The slowmode interval in seconds + channel: discord.TextChannel + The channel to set the slowmode in + reason: str + Why are you setting the slowmode?""" + if channel is None: + channel = interaction.channel + + if not await check_moddable(channel, interaction, ["manage_channels"]): + return + + await channel.edit(slowmode_delay=interval) + await interaction.response.send_message(f"Slowmode in {channel.mention} has been set to {interval} seconds!\n**Reason** - `{reason}`") + + moderation = Moderation.log( + interaction.client, + interaction.guild.id, + interaction.user.id, + "SLOWMODE", + "CHANNEL", + channel.id, + None, + None, + reason, + ) + await interaction.edit_original_response(content=f"Slowmode in {channel.mention} has been set to {interval} seconds! (Case `#{moderation.id:,}`)\n**Reason** - `{reason}`") + await log(interaction, moderation.id) + await send_evidenceformat(interaction, moderation.id) + @app_commands.command(name="history") async def history( self, diff --git a/aurora/models/moderation.py b/aurora/models/moderation.py index c216218..9ebb733 100644 --- a/aurora/models/moderation.py +++ b/aurora/models/moderation.py @@ -222,7 +222,7 @@ class Moderation(AuroraGuildModel): moderation_type: str, target_type: str, target_id: int, - role_id: int, + role_id: int | None = None, duration: timedelta | None = None, reason: str | None = None, database: sqlite3.Connection | None = None,