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