Add more case commands
This commit is contained in:
parent
be1618c782
commit
853dbdb80b
2 changed files with 74 additions and 2 deletions
|
@ -651,6 +651,7 @@ class Jarvis(Client):
|
||||||
async def on_button(self, event: Button) -> None:
|
async def on_button(self, event: Button) -> None:
|
||||||
"""Process button events."""
|
"""Process button events."""
|
||||||
context = event.context
|
context = event.context
|
||||||
|
if not context.deferred and not context.responded:
|
||||||
await context.defer(ephemeral=True)
|
await context.defer(ephemeral=True)
|
||||||
if not context.custom_id.startswith("modcase|"):
|
if not context.custom_id.startswith("modcase|"):
|
||||||
return await super().on_button(event)
|
return await super().on_button(event)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
from typing import TYPE_CHECKING, List, Optional
|
from typing import TYPE_CHECKING, List, Optional
|
||||||
|
|
||||||
from jarvis_core.db import q
|
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 import Cog, InteractionContext, Permissions
|
||||||
from naff.ext.paginators import Paginator
|
from naff.ext.paginators import Paginator
|
||||||
from naff.models.discord.embed import Embed, EmbedField
|
from naff.models.discord.embed import Embed, EmbedField
|
||||||
|
@ -254,3 +254,74 @@ class CaseCog(Cog):
|
||||||
|
|
||||||
embed = await self.get_summary_embed(case, ctx.guild)
|
embed = await self.get_summary_embed(case, ctx.guild)
|
||||||
await ctx.send(embed=embed)
|
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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue