Condense slash commands
This commit is contained in:
parent
9a23a1adfc
commit
008da0df03
7 changed files with 77 additions and 89 deletions
|
@ -8,6 +8,7 @@ from jarvis_core.util.ansi import RESET, Fore, Format, fmt
|
||||||
from naff import listen
|
from naff import listen
|
||||||
from naff.models.discord.channel import DMChannel
|
from naff.models.discord.channel import DMChannel
|
||||||
from naff.models.discord.embed import EmbedField
|
from naff.models.discord.embed import EmbedField
|
||||||
|
from naff.models.naff.application_commands import ContextMenu
|
||||||
from naff.models.naff.context import Context, InteractionContext, PrefixedContext
|
from naff.models.naff.context import Context, InteractionContext, PrefixedContext
|
||||||
|
|
||||||
from jarvis import const
|
from jarvis import const
|
||||||
|
@ -61,6 +62,35 @@ class EventMixin(MemberEventMixin, MessageEventMixin, ComponentEventMixin):
|
||||||
"{}&permissions=8&scope=bot%20applications.commands".format(self.user.id)
|
"{}&permissions=8&scope=bot%20applications.commands".format(self.user.id)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
global_base_commands = {}
|
||||||
|
guild_base_commands = {}
|
||||||
|
global_context_menus = []
|
||||||
|
guild_context_menus = []
|
||||||
|
for cid in self.interactions:
|
||||||
|
commands = self.interactions[cid]
|
||||||
|
to_update = global_base_commands if cid == 0 else guild_base_commands
|
||||||
|
for command in commands:
|
||||||
|
if isinstance(commands[command], ContextMenu):
|
||||||
|
if cid == 0:
|
||||||
|
global_context_menus.append(command)
|
||||||
|
else:
|
||||||
|
guild_context_menus.append(command)
|
||||||
|
continue
|
||||||
|
full = command.split(" ")
|
||||||
|
base = full[0]
|
||||||
|
if base not in to_update:
|
||||||
|
to_update[base] = {}
|
||||||
|
if len(full) == 3:
|
||||||
|
to_update[base][full[1]] = full[2]
|
||||||
|
elif len(full) == 2:
|
||||||
|
to_update[base][full[1]] = None
|
||||||
|
|
||||||
|
self.logger.info(
|
||||||
|
"Loaded {:>2} global base slash commands".format(len(global_base_commands))
|
||||||
|
)
|
||||||
|
self.logger.info("Loaded {:>2} global context menus".format(len(global_context_menus)))
|
||||||
|
self.logger.info("Loaded {:>2} guild base slash commands".format(len(guild_base_commands)))
|
||||||
|
self.logger.info("Loaded {:>2} guild context menus".format(len(guild_context_menus)))
|
||||||
self.logger.debug("Hitting Reminders for faster loads")
|
self.logger.debug("Hitting Reminders for faster loads")
|
||||||
_ = await Reminder.find().to_list(None)
|
_ = await Reminder.find().to_list(None)
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,8 @@ from naff.models.discord.file import File
|
||||||
from naff.models.discord.message import Attachment
|
from naff.models.discord.message import Attachment
|
||||||
from naff.models.naff.application_commands import (
|
from naff.models.naff.application_commands import (
|
||||||
OptionTypes,
|
OptionTypes,
|
||||||
|
SlashCommand,
|
||||||
SlashCommandChoice,
|
SlashCommandChoice,
|
||||||
slash_command,
|
|
||||||
slash_option,
|
slash_option,
|
||||||
)
|
)
|
||||||
from naff.models.naff.command import cooldown
|
from naff.models.naff.command import cooldown
|
||||||
|
@ -60,7 +60,9 @@ class DevCog(Extension):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@slash_command(name="hash", description="Hash some data")
|
dev = SlashCommand(name="dev", description="Developer utilities")
|
||||||
|
|
||||||
|
@dev.subcommand(sub_cmd_name="hash", sub_cmd_description="Hash some data")
|
||||||
@slash_option(
|
@slash_option(
|
||||||
name="method",
|
name="method",
|
||||||
description="Hash method",
|
description="Hash method",
|
||||||
|
@ -126,7 +128,7 @@ class DevCog(Extension):
|
||||||
)
|
)
|
||||||
await ctx.send(embeds=embed, components=components)
|
await ctx.send(embeds=embed, components=components)
|
||||||
|
|
||||||
@slash_command(name="uuid", description="Generate a UUID")
|
@dev.subcommand(sub_cmd_name="uuid", sub_cmd_description="Generate a UUID")
|
||||||
@slash_option(
|
@slash_option(
|
||||||
name="version",
|
name="version",
|
||||||
description="UUID version",
|
description="UUID version",
|
||||||
|
@ -159,25 +161,25 @@ class DevCog(Extension):
|
||||||
to_send = UUID_GET[version](uuidpy.NAMESPACE_DNS, data)
|
to_send = UUID_GET[version](uuidpy.NAMESPACE_DNS, data)
|
||||||
await ctx.send(f"UUID{version}: `{to_send}`")
|
await ctx.send(f"UUID{version}: `{to_send}`")
|
||||||
|
|
||||||
@slash_command(
|
@dev.subcommand(
|
||||||
name="objectid",
|
sub_cmd_name="objectid",
|
||||||
description="Generate an ObjectID",
|
sub_cmd_description="Generate an ObjectID",
|
||||||
)
|
)
|
||||||
@cooldown(bucket=Buckets.USER, rate=1, interval=2)
|
@cooldown(bucket=Buckets.USER, rate=1, interval=2)
|
||||||
async def _objectid(self, ctx: InteractionContext) -> None:
|
async def _objectid(self, ctx: InteractionContext) -> None:
|
||||||
await ctx.send(f"ObjectId: `{str(ObjectId())}`")
|
await ctx.send(f"ObjectId: `{str(ObjectId())}`")
|
||||||
|
|
||||||
@slash_command(
|
@dev.subcommand(
|
||||||
name="ulid",
|
sub_cmd_name="ulid",
|
||||||
description="Generate a ULID",
|
sub_cmd_description="Generate a ULID",
|
||||||
)
|
)
|
||||||
@cooldown(bucket=Buckets.USER, rate=1, interval=2)
|
@cooldown(bucket=Buckets.USER, rate=1, interval=2)
|
||||||
async def _ulid(self, ctx: InteractionContext) -> None:
|
async def _ulid(self, ctx: InteractionContext) -> None:
|
||||||
await ctx.send(f"ULID: `{ulidpy.new().str}`")
|
await ctx.send(f"ULID: `{ulidpy.new().str}`")
|
||||||
|
|
||||||
@slash_command(
|
@dev.subcommand(
|
||||||
name="uuid2ulid",
|
sub_cmd_name="uuid2ulid",
|
||||||
description="Convert a UUID to a ULID",
|
sub_cmd_description="Convert a UUID to a ULID",
|
||||||
)
|
)
|
||||||
@slash_option(
|
@slash_option(
|
||||||
name="uuid", description="UUID to convert", opt_type=OptionTypes.STRING, required=True
|
name="uuid", description="UUID to convert", opt_type=OptionTypes.STRING, required=True
|
||||||
|
@ -190,9 +192,9 @@ class DevCog(Extension):
|
||||||
else:
|
else:
|
||||||
await ctx.send("Invalid UUID")
|
await ctx.send("Invalid UUID")
|
||||||
|
|
||||||
@slash_command(
|
@dev.subcommand(
|
||||||
name="ulid2uuid",
|
sub_cmd_name="ulid2uuid",
|
||||||
description="Convert a ULID to a UUID",
|
sub_cmd_description="Convert a ULID to a UUID",
|
||||||
)
|
)
|
||||||
@slash_option(
|
@slash_option(
|
||||||
name="ulid", description="ULID to convert", opt_type=OptionTypes.STRING, required=True
|
name="ulid", description="ULID to convert", opt_type=OptionTypes.STRING, required=True
|
||||||
|
@ -207,7 +209,7 @@ class DevCog(Extension):
|
||||||
|
|
||||||
base64_methods = ["b64", "b16", "b32", "a85", "b85"]
|
base64_methods = ["b64", "b16", "b32", "a85", "b85"]
|
||||||
|
|
||||||
@slash_command(name="encode", description="Encode some data")
|
@dev.subcommand(sub_cmd_name="encode", sub_cmd_description="Encode some data")
|
||||||
@slash_option(
|
@slash_option(
|
||||||
name="method",
|
name="method",
|
||||||
description="Encode method",
|
description="Encode method",
|
||||||
|
@ -245,7 +247,7 @@ class DevCog(Extension):
|
||||||
)
|
)
|
||||||
await ctx.send(embeds=embed, components=components)
|
await ctx.send(embeds=embed, components=components)
|
||||||
|
|
||||||
@slash_command(name="decode", description="Decode some data")
|
@dev.subcommand(sub_cmd_name="decode", sub_cmd_description="Decode some data")
|
||||||
@slash_option(
|
@slash_option(
|
||||||
name="method",
|
name="method",
|
||||||
description="Decode method",
|
description="Decode method",
|
||||||
|
@ -283,7 +285,7 @@ class DevCog(Extension):
|
||||||
)
|
)
|
||||||
await ctx.send(embeds=embed, components=components)
|
await ctx.send(embeds=embed, components=components)
|
||||||
|
|
||||||
@slash_command(name="cloc", description="Get JARVIS lines of code")
|
@dev.subcommand(sub_cmd_name="cloc", sub_cmd_description="Get JARVIS lines of code")
|
||||||
@cooldown(bucket=Buckets.CHANNEL, rate=1, interval=30)
|
@cooldown(bucket=Buckets.CHANNEL, rate=1, interval=30)
|
||||||
async def _cloc(self, ctx: InteractionContext) -> None:
|
async def _cloc(self, ctx: InteractionContext) -> None:
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
|
|
|
@ -15,7 +15,7 @@ from naff.models.discord.file import File
|
||||||
from naff.models.discord.message import Attachment
|
from naff.models.discord.message import Attachment
|
||||||
from naff.models.naff.application_commands import (
|
from naff.models.naff.application_commands import (
|
||||||
OptionTypes,
|
OptionTypes,
|
||||||
slash_command,
|
SlashCommand,
|
||||||
slash_option,
|
slash_option,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -40,7 +40,9 @@ class ImageCog(Extension):
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self._session.close()
|
self._session.close()
|
||||||
|
|
||||||
@slash_command(name="resize", description="Resize an image")
|
image = SlashCommand(name="image", description="Manipulate images")
|
||||||
|
|
||||||
|
@image.subcommand(sub_cmd_name="shrink", sub_cmd_description="Shrink an image")
|
||||||
@slash_option(
|
@slash_option(
|
||||||
name="target",
|
name="target",
|
||||||
description="Target size, i.e. 200KB",
|
description="Target size, i.e. 200KB",
|
||||||
|
|
|
@ -18,7 +18,6 @@ from naff.models.discord.modal import InputText, Modal, TextStyles
|
||||||
from naff.models.naff.application_commands import (
|
from naff.models.naff.application_commands import (
|
||||||
OptionTypes,
|
OptionTypes,
|
||||||
SlashCommand,
|
SlashCommand,
|
||||||
slash_command,
|
|
||||||
slash_option,
|
slash_option,
|
||||||
)
|
)
|
||||||
from thefuzz import process
|
from thefuzz import process
|
||||||
|
@ -40,7 +39,9 @@ class RemindmeCog(Extension):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@slash_command(name="remindme", description="Set a reminder")
|
reminders = SlashCommand(name="reminders", description="Manage reminders")
|
||||||
|
|
||||||
|
@reminders.subcommand(sub_cmd_name="set", sub_cmd_description="Set a reminder")
|
||||||
@slash_option(
|
@slash_option(
|
||||||
name="private",
|
name="private",
|
||||||
description="Send as DM?",
|
description="Send as DM?",
|
||||||
|
@ -210,8 +211,6 @@ class RemindmeCog(Extension):
|
||||||
|
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
reminders = SlashCommand(name="reminders", description="Manage reminders")
|
|
||||||
|
|
||||||
@reminders.subcommand(sub_cmd_name="list", sub_cmd_description="List reminders")
|
@reminders.subcommand(sub_cmd_name="list", sub_cmd_description="List reminders")
|
||||||
async def _list(self, ctx: InteractionContext) -> None:
|
async def _list(self, ctx: InteractionContext) -> None:
|
||||||
reminders = await Reminder.find(q(user=ctx.author.id, active=True)).to_list(None)
|
reminders = await Reminder.find(q(user=ctx.author.id, active=True)).to_list(None)
|
||||||
|
|
|
@ -218,9 +218,7 @@ class RolegiverCog(Extension):
|
||||||
)
|
)
|
||||||
await ctx.send(embeds=embed, components=components)
|
await ctx.send(embeds=embed, components=components)
|
||||||
|
|
||||||
role = SlashCommand(name="role", description="Get/Remove Rolegiver roles")
|
@rolegiver.subcommand(sub_cmd_name="get", sub_cmd_description="Get a role")
|
||||||
|
|
||||||
@role.subcommand(sub_cmd_name="get", sub_cmd_description="Get a role")
|
|
||||||
@cooldown(bucket=Buckets.USER, rate=1, interval=10)
|
@cooldown(bucket=Buckets.USER, rate=1, interval=10)
|
||||||
async def _role_get(self, ctx: InteractionContext) -> None:
|
async def _role_get(self, ctx: InteractionContext) -> None:
|
||||||
setting = await Rolegiver.find_one(q(guild=ctx.guild.id))
|
setting = await Rolegiver.find_one(q(guild=ctx.guild.id))
|
||||||
|
@ -296,7 +294,7 @@ class RolegiverCog(Extension):
|
||||||
component.disabled = True
|
component.disabled = True
|
||||||
await message.edit(components=components)
|
await message.edit(components=components)
|
||||||
|
|
||||||
@role.subcommand(sub_cmd_name="remove", sub_cmd_description="Remove a role")
|
@rolegiver.subcommand(sub_cmd_name="forfeit", sub_cmd_description="Forfeit a role")
|
||||||
@cooldown(bucket=Buckets.USER, rate=1, interval=10)
|
@cooldown(bucket=Buckets.USER, rate=1, interval=10)
|
||||||
async def _role_remove(self, ctx: InteractionContext) -> None:
|
async def _role_remove(self, ctx: InteractionContext) -> None:
|
||||||
user_roles = ctx.author.roles
|
user_roles = ctx.author.roles
|
||||||
|
|
|
@ -265,56 +265,6 @@ class StarboardCog(Extension):
|
||||||
description="Manage stars",
|
description="Manage stars",
|
||||||
)
|
)
|
||||||
|
|
||||||
@star.subcommand(sub_cmd_name="delete", sub_cmd_description="Delete a starred message")
|
|
||||||
@slash_option(
|
|
||||||
name="id", description="Star ID to delete", opt_type=OptionTypes.INTEGER, required=True
|
|
||||||
)
|
|
||||||
@slash_option(
|
|
||||||
name="starboard",
|
|
||||||
description="Starboard to delete star from",
|
|
||||||
opt_type=OptionTypes.CHANNEL,
|
|
||||||
required=True,
|
|
||||||
)
|
|
||||||
@check(admin_or_permissions(Permissions.MANAGE_GUILD))
|
|
||||||
async def _star_delete(
|
|
||||||
self,
|
|
||||||
ctx: InteractionContext,
|
|
||||||
id: int,
|
|
||||||
starboard: GuildText,
|
|
||||||
) -> None:
|
|
||||||
if not isinstance(starboard, GuildText):
|
|
||||||
await ctx.send("Channel must be a GuildText channel", ephemeral=True)
|
|
||||||
return
|
|
||||||
|
|
||||||
exists = await Starboard.find_one(q(channel=starboard.id, guild=ctx.guild.id))
|
|
||||||
if not exists:
|
|
||||||
# TODO: automagically create starboard
|
|
||||||
await ctx.send(
|
|
||||||
f"Starboard does not exist in {starboard.mention}. Please create it first",
|
|
||||||
ephemeral=True,
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
star = await Star.find_one(
|
|
||||||
q(
|
|
||||||
starboard=starboard.id,
|
|
||||||
index=id,
|
|
||||||
guild=ctx.guild.id,
|
|
||||||
active=True,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if not star:
|
|
||||||
await ctx.send(f"No star exists with id {id}", ephemeral=True)
|
|
||||||
return
|
|
||||||
|
|
||||||
message = await starboard.fetch_message(star.star)
|
|
||||||
if message:
|
|
||||||
await message.delete()
|
|
||||||
|
|
||||||
await star.delete()
|
|
||||||
|
|
||||||
await ctx.send(f"Star {id} deleted from {starboard.mention}")
|
|
||||||
|
|
||||||
|
|
||||||
def setup(bot: Client) -> None:
|
def setup(bot: Client) -> None:
|
||||||
"""Add StarboardCog to JARVIS"""
|
"""Add StarboardCog to JARVIS"""
|
||||||
|
|
|
@ -20,6 +20,7 @@ from naff.models.discord.user import User
|
||||||
from naff.models.naff.application_commands import (
|
from naff.models.naff.application_commands import (
|
||||||
CommandTypes,
|
CommandTypes,
|
||||||
OptionTypes,
|
OptionTypes,
|
||||||
|
SlashCommand,
|
||||||
SlashCommandChoice,
|
SlashCommandChoice,
|
||||||
context_menu,
|
context_menu,
|
||||||
slash_command,
|
slash_command,
|
||||||
|
@ -49,7 +50,9 @@ class UtilCog(Extension):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@slash_command(name="status", description="Retrieve JARVIS status")
|
bot = SlashCommand(name="bot", description="Bot commands")
|
||||||
|
|
||||||
|
@bot.subcommand(sub_cmd_name="status", sub_cmd_description="Retrieve JARVIS status")
|
||||||
@cooldown(bucket=Buckets.CHANNEL, rate=1, interval=30)
|
@cooldown(bucket=Buckets.CHANNEL, rate=1, interval=30)
|
||||||
async def _status(self, ctx: InteractionContext) -> None:
|
async def _status(self, ctx: InteractionContext) -> None:
|
||||||
title = "JARVIS Status"
|
title = "JARVIS Status"
|
||||||
|
@ -74,9 +77,9 @@ class UtilCog(Extension):
|
||||||
)
|
)
|
||||||
await ctx.send(embeds=embed, components=components)
|
await ctx.send(embeds=embed, components=components)
|
||||||
|
|
||||||
@slash_command(
|
@bot.subcommand(
|
||||||
name="logo",
|
sub_cmd_name="logo",
|
||||||
description="Get the current logo",
|
sub_cmd_description="Get the current logo",
|
||||||
)
|
)
|
||||||
@cooldown(bucket=Buckets.CHANNEL, rate=1, interval=30)
|
@cooldown(bucket=Buckets.CHANNEL, rate=1, interval=30)
|
||||||
async def _logo(self, ctx: InteractionContext) -> None:
|
async def _logo(self, ctx: InteractionContext) -> None:
|
||||||
|
@ -89,13 +92,15 @@ class UtilCog(Extension):
|
||||||
)
|
)
|
||||||
await ctx.send(file=logo, components=components)
|
await ctx.send(file=logo, components=components)
|
||||||
|
|
||||||
@slash_command(name="rchk", description="Robot Camo HK416")
|
rc = SlashCommand(name="rc", description="Robot Camo emoji commands")
|
||||||
|
|
||||||
|
@rc.subcommand(sub_cmd_name="hk", sub_cmd_description="Robot Camo HK416")
|
||||||
async def _rchk(self, ctx: InteractionContext) -> None:
|
async def _rchk(self, ctx: InteractionContext) -> None:
|
||||||
await ctx.send(content=hk, ephemeral=True)
|
await ctx.send(content=hk, ephemeral=True)
|
||||||
|
|
||||||
@slash_command(
|
@rc.subcommand(
|
||||||
name="rcauto",
|
sub_cmd_name="auto",
|
||||||
description="Automates robot camo letters",
|
sub_cmd_description="Automates robot camo letters",
|
||||||
)
|
)
|
||||||
@slash_option(
|
@slash_option(
|
||||||
name="text",
|
name="text",
|
||||||
|
@ -176,7 +181,7 @@ class UtilCog(Extension):
|
||||||
embed.set_thumbnail(url="attachment://color_show.png")
|
embed.set_thumbnail(url="attachment://color_show.png")
|
||||||
|
|
||||||
data = np.array(JARVIS_LOGO)
|
data = np.array(JARVIS_LOGO)
|
||||||
r, g, b, a = data.T
|
*_, a = data.T
|
||||||
|
|
||||||
fill = a > 0
|
fill = a > 0
|
||||||
|
|
||||||
|
@ -397,7 +402,7 @@ class UtilCog(Extension):
|
||||||
)
|
)
|
||||||
await ctx.send(embeds=embed, ephemeral=private, components=components)
|
await ctx.send(embeds=embed, ephemeral=private, components=components)
|
||||||
|
|
||||||
@slash_command(name="support", description="Got issues?")
|
@bot.subcommand(sub_cmd_name="support", sub_cmd_description="Got issues?")
|
||||||
async def _support(self, ctx: InteractionContext) -> None:
|
async def _support(self, ctx: InteractionContext) -> None:
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
f"""
|
f"""
|
||||||
|
@ -409,7 +414,9 @@ We'll help as best we can with whatever issues you encounter.
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
@slash_command(name="privacy_terms", description="View Privacy and Terms of Use")
|
@bot.subcommand(
|
||||||
|
sub_cmd_name="privacy_terms", sub_cmd_description="View Privacy and Terms of Use"
|
||||||
|
)
|
||||||
async def _privacy_terms(self, ctx: InteractionContext) -> None:
|
async def _privacy_terms(self, ctx: InteractionContext) -> None:
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Reference in a new issue