From fa2c7d5b9c2fc50aa866a5321fedfd31f77168c4 Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Thu, 14 Dec 2023 17:23:25 -0500 Subject: [PATCH] feat(moderation): added default setting configuration for the history command --- moderation/moderation.py | 107 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 5 deletions(-) diff --git a/moderation/moderation.py b/moderation/moderation.py index 7f57dc9..8acfa7a 100644 --- a/moderation/moderation.py +++ b/moderation/moderation.py @@ -28,7 +28,17 @@ class Moderation(commands.Cog): self.config.register_guild( ignore_other_bots = True, dm_users = True, - log_channel = " " + log_channel = " ", + history_ephemeral = False, + history_inline = False, + history_pagesize = 5, + history_inline_pagesize = 6 + ) + self.config.register_user( + history_ephemeral = None, + history_inline = None, + history_pagesize = None, + history_inline_pagesize = None ) disable_dateutil() self.handle_expiry.start() # pylint: disable=no-member @@ -822,7 +832,7 @@ class Moderation(commands.Cog): await self.log(interaction, moderation_id) @app_commands.command(name="history") - async def history(self, interaction: discord.Interaction, target: discord.User = None, moderator: discord.User = None, pagesize: app_commands.Range[int, 1, 25] = None, page: int = 1, ephemeral: bool = False, inline: bool = False, export: bool = False): + async def history(self, interaction: discord.Interaction, target: discord.User = None, moderator: discord.User = None, pagesize: app_commands.Range[int, 1, 25] = None, page: int = 1, ephemeral: bool = None, inline: bool = None, export: bool = False): """List previous infractions. Parameters @@ -853,9 +863,23 @@ class Moderation(commands.Cog): if pagesize is None: if inline is True: - pagesize = 6 + pagesize = (await self.config.user(interaction.user).history_inline_pagesize() + or await self.config.guild(interaction.guild).history_inline_pagesize() + or 6) else: - pagesize = 5 + pagesize = (await self.config.user(interaction.user).history_pagesize() + or await self.config.guild(interaction.guild).history_pagesize() + or 6) + + if inline is None: + inline = (await self.config.user(interaction.user).history_inline() + or await self.config.guild(interaction.guild).history_inline() + or False) + + if ephemeral is None: + ephemeral = (await self.config.user(interaction.user).history_ephemeral() + or await self.config.guild(interaction.guild).history_ephemeral() + or False) if target: query = """SELECT * @@ -1115,10 +1139,83 @@ class Moderation(commands.Cog): database.close() @commands.group(autohelp=True) - @checks.admin() async def moderationset(self, ctx: commands.Context): """Manage moderation commands.""" + @commands.group(autohelp=True) + async def moderationset_history(self, ctx: commands.Context): + """Manage configuration for the `/history` command.""" + + @commands.group(autohelp=True) + async def moderationset_history_user(self, ctx: commands.Context): + """Manage configuration for the `/history` command, per user.""" + + @moderationset_history_user.command(name='ephemeral', aliases=['hidden', 'hide']) + async def moderationset_history_user_ephemeral(self, ctx: commands.Context): + """Toggle if the `/history` command should be ephemeral.""" + await self.config.user(ctx.author).history_ephemeral.set(not await self.config.user(ctx.author).ephemeral()) + await ctx.send(f"Ephemeral setting set to {await self.config.user(ctx.author).ephemeral()}") + + @moderationset_history_user.command(name='pagesize') + async def moderationset_history_user_pagesize(self, ctx: commands.Context, pagesize: int): + """Set the amount of cases to display per page.""" + await self.config.user(ctx.author).history_pagesize.set(pagesize) + await ctx.send(f"Pagesize set to {await self.config.user(ctx.author).history_pagesize()}") + + @moderationset_history_user.group(name='inline') + async def moderationset_history_user_inline(self, ctx: commands.Context): + """Manage configuration for the `/history` command's inline argument.""" + + @moderationset_history_user_inline.command(name='toggle') + async def moderationset_history_user_inline_toggle(self, ctx: commands.Context): + """Enable the `/history` command's inline argument by default.""" + await self.config.user(ctx.author).history_inline.set(not await self.config.user(ctx.author).history_inline()) + await ctx.send(f"Inline setting set to {await self.config.user(ctx.author).history_inline()}") + + @moderationset_history_user_inline.command(name='pagesize') + async def moderationset_history_user_inline_pagesize(self, ctx: commands.Context, pagesize: int): + """Set the amount of cases to display per page.""" + await self.config.user(ctx.author).history_inline_pagesize.set(pagesize) + await ctx.send(f"Inline pagesize set to {await self.config.user(ctx.author).history_inline_pagesize()}") + + @commands.group(autohelp=True) + @checks.admin() + async def moderationset_history_guild(self, ctx: commands.Context): + """Manage configuration for the `/history` command, per guild.""" + + @moderationset_history_guild.command(name='ephemeral', aliases=['hidden', 'hide']) + @checks.admin() + async def moderationset_history_guild_ephemeral(self, ctx: commands.Context): + """Toggle if the `/history` command should be ephemeral.""" + await self.config.guild(ctx.guild).history_ephemeral.set(not await self.config.guild(ctx.guild).ephemeral()) + await ctx.send(f"Ephemeral setting set to {await self.config.guild(ctx.guild).ephemeral()}") + + @moderationset_history_guild.command(name='pagesize') + @checks.admin() + async def moderationset_history_guild_pagesize(self, ctx: commands.Context, pagesize: int): + """Set the amount of cases to display per page.""" + await self.config.guild(ctx.guild).history_pagesize.set(pagesize) + await ctx.send(f"Pagesize set to {await self.config.guild(ctx.guild).history_pagesize()}") + + @moderationset_history_guild.group(name='inline') + @checks.admin() + async def moderationset_history_guild_inline(self, ctx: commands.Context): + """Manage configuration for the `/history` command's inline argument.""" + + @moderationset_history_guild_inline.command(name='toggle') + @checks.admin() + async def moderationset_history_guild_inline_toggle(self, ctx: commands.Context): + """Enable the `/history` command's inline argument by default.""" + await self.config.guild(ctx.guild).history_inline.set(not await self.config.guild(ctx.guild).history_inline()) + await ctx.send(f"Inline setting set to {await self.config.guild(ctx.guild).history_inline()}") + + @moderationset_history_guild_inline.command(name='pagesize') + @checks.admin() + async def moderationset_history_guild_inline_pagesize(self, ctx: commands.Context, pagesize: int): + """Set the amount of cases to display per page.""" + await self.config.guild(ctx.guild).history_inline_pagesize.set(pagesize) + await ctx.send(f"Inline pagesize set to {await self.config.guild(ctx.guild).history_inline_pagesize()}") + @moderationset.command(name="ignorebots") @checks.admin() async def moderationset_ignorebots(self, ctx: commands.Context):