From 853dbdb80b62d629fde25f637b9b21a2fd4a4cc8 Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Tue, 3 May 2022 15:59:18 -0600 Subject: [PATCH] Add more case commands --- jarvis/client.py | 3 +- jarvis/cogs/admin/modcase.py | 73 +++++++++++++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/jarvis/client.py b/jarvis/client.py index 297314a..69bc0f9 100644 --- a/jarvis/client.py +++ b/jarvis/client.py @@ -651,7 +651,8 @@ class Jarvis(Client): async def on_button(self, event: Button) -> None: """Process button events.""" context = event.context - await context.defer(ephemeral=True) + if not context.deferred and not context.responded: + await context.defer(ephemeral=True) if not context.custom_id.startswith("modcase|"): return await super().on_button(event) diff --git a/jarvis/cogs/admin/modcase.py b/jarvis/cogs/admin/modcase.py index 2f076cc..a45ead9 100644 --- a/jarvis/cogs/admin/modcase.py +++ b/jarvis/cogs/admin/modcase.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING, List, Optional from jarvis_core.db import q -from jarvis_core.db.models import Modlog, actions +from jarvis_core.db.models import Modlog, Note, actions from naff import Cog, InteractionContext, Permissions from naff.ext.paginators import Paginator from naff.models.discord.embed import Embed, EmbedField @@ -254,3 +254,74 @@ class CaseCog(Cog): embed = await self.get_summary_embed(case, ctx.guild) await ctx.send(embed=embed) + + @case.subcommand(sub_cmd_name="repoen", sub_cmd_description="Reopen a specific case") + @slash_option(name="cid", description="Case ID", opt_type=OptionTypes.STRING, required=True) + @check(admin_or_permissions(Permissions.BAN_MEMBERS)) + async def _case_reopen(self, ctx: InteractionContext, cid: str) -> None: + case = await Modlog.find_one(q(guild=ctx.guild.id, nanoid=cid)) + if not case: + await ctx.send(f"Could not find case with ID {cid}", ephemeral=True) + return + + case.open = True + await case.commit() + + embed = await self.get_summary_embed(case, ctx.guild) + await ctx.send(embed=embed) + + @case.subcommand(sub_cmd_name="note", sub_cmd_description="Add a note to a specific case") + @slash_option(name="cid", description="Case ID", opt_type=OptionTypes.STRING, required=True) + @slash_option( + name="note", description="Note to add", opt_type=OptionTypes.STRING, required=True + ) + @check(admin_or_permissions(Permissions.BAN_MEMBERS)) + async def _case_note(self, ctx: InteractionContext, cid: str, note: str) -> None: + case = await Modlog.find_one(q(guild=ctx.guild.id, nanoid=cid)) + if not case: + await ctx.send(f"Could not find case with ID {cid}", ephemeral=True) + return + + if not case.open: + await ctx.send("Case is closed, please re-open to add a new comment", ephemeral=True) + return + + if len(note) > 50: + await ctx.send("Note must be <= 50 characters", ephemeral=True) + return + + note = Note(admin=ctx.author.id, content=note) + + case.notes.append(note) + await case.commit() + + embed = await self.get_summary_embed(case, ctx.guild) + await ctx.send(embed=embed) + + @case.subcommand(sub_cmd_name="new", sub_cmd_description="Open a new case") + @slash_option(name="user", description="Target user", opt_type=OptionTypes.USER, required=True) + @slash_option( + name="note", description="Note to add", opt_type=OptionTypes.STRING, required=True + ) + @check(admin_or_permissions(Permissions.BAN_MEMBERS)) + async def _case_new(self, ctx: InteractionContext, user: Member, note: str) -> None: + case = await Modlog.find_one(q(guild=ctx.guild.id, user=user.id, open=True)) + if not case: + await ctx.send(f"Case already exists with ID {case.nanoid}", ephemeral=True) + return + + if not isinstance(user, Member): + await ctx.send("User must be in this guild", ephemeral=True) + return + + if len(note) > 50: + await ctx.send("Note must be <= 50 characters", ephemeral=True) + return + + note = Note(admin=ctx.author.id, content=note) + + case = Modlog(user=user.id, guild=ctx.guild.id, admin=ctx.author.id, notes=[note]) + await case.commit() + + embed = await self.get_summary_embed(case, ctx.guild) + await ctx.send(embed=embed)