Migrate admin/purge, ref #91
This commit is contained in:
parent
d4e3d17393
commit
716f16946d
1 changed files with 63 additions and 73 deletions
|
@ -1,33 +1,31 @@
|
|||
"""J.A.R.V.I.S. PurgeCog."""
|
||||
from discord import TextChannel
|
||||
from discord.ext import commands
|
||||
from discord_slash import SlashContext, cog_ext
|
||||
from discord_slash.utils.manage_commands import create_option
|
||||
from dis_snek import InteractionContext, Permissions, Scale, Snek
|
||||
from dis_snek.models.discord.channel import TextChannel
|
||||
from dis_snek.models.snek.application_commands import (
|
||||
OptionTypes,
|
||||
slash_command,
|
||||
slash_option,
|
||||
)
|
||||
|
||||
from jarvis.db.models import Autopurge, Purge
|
||||
from jarvis.utils.permissions import admin_or_permissions
|
||||
|
||||
|
||||
class PurgeCog(commands.Cog):
|
||||
class PurgeCog(Scale):
|
||||
"""J.A.R.V.I.S. PurgeCog."""
|
||||
|
||||
def __init__(self, bot: commands.Bot):
|
||||
def __init__(self, bot: Snek):
|
||||
self.bot = bot
|
||||
|
||||
@cog_ext.cog_slash(
|
||||
name="purge",
|
||||
description="Purge messages from channel",
|
||||
options=[
|
||||
create_option(
|
||||
@slash_command(name="purge", description="Purge messages from channel")
|
||||
@slash_option(
|
||||
name="amount",
|
||||
description="Amount of messages to purge",
|
||||
description="Amount of messages to purge, default 10",
|
||||
option_type=OptionTypes.INTEGER,
|
||||
required=False,
|
||||
option_type=4,
|
||||
)
|
||||
],
|
||||
)
|
||||
@admin_or_permissions(manage_messages=True)
|
||||
async def _purge(self, ctx: SlashContext, amount: int = 10) -> None:
|
||||
@admin_or_permissions(Permissions.MANAGE_MESSAGES)
|
||||
async def _purge(self, ctx: InteractionContext, amount: int = 10) -> None:
|
||||
if amount < 1:
|
||||
await ctx.send("Amount must be >= 1", hidden=True)
|
||||
return
|
||||
|
@ -44,28 +42,24 @@ class PurgeCog(commands.Cog):
|
|||
count=amount,
|
||||
).save()
|
||||
|
||||
@cog_ext.cog_subcommand(
|
||||
base="autopurge",
|
||||
name="add",
|
||||
description="Automatically purge messages after x seconds",
|
||||
options=[
|
||||
create_option(
|
||||
@slash_command(
|
||||
name="autopurge", sub_cmd_name="add", sub_cmd_description="Automatically purge messages"
|
||||
)
|
||||
@slash_option(
|
||||
name="channel",
|
||||
description="Channel to autopurge",
|
||||
option_type=7,
|
||||
option_type=OptionTypes.CHANNEL,
|
||||
required=True,
|
||||
),
|
||||
create_option(
|
||||
)
|
||||
@slash_option(
|
||||
name="delay",
|
||||
description="Seconds to keep message before purge, default 30",
|
||||
option_type=4,
|
||||
option_type=OptionTypes.INTEGER,
|
||||
required=False,
|
||||
),
|
||||
],
|
||||
)
|
||||
@admin_or_permissions(manage_messages=True)
|
||||
@admin_or_permissions(Permissions.MANAGE_MESSAGES)
|
||||
async def _autopurge_add(
|
||||
self, ctx: SlashContext, channel: TextChannel, delay: int = 30
|
||||
self, ctx: InteractionContext, channel: TextChannel, delay: int = 30
|
||||
) -> None:
|
||||
if not isinstance(channel, TextChannel):
|
||||
await ctx.send("Channel must be a TextChannel", hidden=True)
|
||||
|
@ -88,21 +82,17 @@ class PurgeCog(commands.Cog):
|
|||
).save()
|
||||
await ctx.send(f"Autopurge set up on {channel.mention}, delay is {delay} seconds")
|
||||
|
||||
@cog_ext.cog_subcommand(
|
||||
base="autopurge",
|
||||
name="remove",
|
||||
description="Remove an autopurge",
|
||||
options=[
|
||||
create_option(
|
||||
@slash_command(
|
||||
name="autopurge", sub_cmd_name="remove", sub_cmd_description="Remove an autopurge"
|
||||
)
|
||||
@slash_option(
|
||||
name="channel",
|
||||
description="Channel to remove from autopurge",
|
||||
option_type=7,
|
||||
option_type=OptionTypes.CHANNEL,
|
||||
required=True,
|
||||
),
|
||||
],
|
||||
)
|
||||
@admin_or_permissions(manage_messages=True)
|
||||
async def _autopurge_remove(self, ctx: SlashContext, channel: TextChannel) -> None:
|
||||
@admin_or_permissions(Permissions.MANAGE_MESSAGES)
|
||||
async def _autopurge_remove(self, ctx: InteractionContext, channel: TextChannel) -> None:
|
||||
autopurge = Autopurge.objects(guild=ctx.guild.id, channel=channel.id)
|
||||
if not autopurge:
|
||||
await ctx.send("Autopurge does not exist.", hidden=True)
|
||||
|
@ -110,27 +100,27 @@ class PurgeCog(commands.Cog):
|
|||
autopurge.delete()
|
||||
await ctx.send(f"Autopurge removed from {channel.mention}.")
|
||||
|
||||
@cog_ext.cog_subcommand(
|
||||
base="autopurge",
|
||||
name="update",
|
||||
description="Update autopurge on a channel",
|
||||
options=[
|
||||
create_option(
|
||||
@slash_command(
|
||||
name="autopurge",
|
||||
sub_cmd_name="update",
|
||||
sub_cmd_description="Update autopurge on a channel",
|
||||
)
|
||||
@slash_option(
|
||||
name="channel",
|
||||
description="Channel to update",
|
||||
option_type=7,
|
||||
option_type=OptionTypes.CHANNEL,
|
||||
required=True,
|
||||
),
|
||||
create_option(
|
||||
)
|
||||
@slash_option(
|
||||
name="delay",
|
||||
description="New time to save",
|
||||
option_type=4,
|
||||
option_type=OptionTypes.INTEGER,
|
||||
required=True,
|
||||
),
|
||||
],
|
||||
)
|
||||
@admin_or_permissions(manage_messages=True)
|
||||
async def _autopurge_update(self, ctx: SlashContext, channel: TextChannel, delay: int) -> None:
|
||||
@admin_or_permissions(Permissions.MANAGE_MESSAGES)
|
||||
async def _autopurge_update(
|
||||
self, ctx: InteractionContext, channel: TextChannel, delay: int
|
||||
) -> None:
|
||||
autopurge = Autopurge.objects(guild=ctx.guild.id, channel=channel.id)
|
||||
if not autopurge:
|
||||
await ctx.send("Autopurge does not exist.", hidden=True)
|
||||
|
|
Loading…
Add table
Reference in a new issue