diff --git a/src/lib/command/CommandRegistry.ts b/src/lib/command/CommandRegistry.ts index f7091d1a..e6c3f560 100644 --- a/src/lib/command/CommandRegistry.ts +++ b/src/lib/command/CommandRegistry.ts @@ -18,6 +18,7 @@ type CommandFactory = SimpleMap<{ export interface CommandListOptions { includeSecret?: boolean; includeArchived?: boolean; + includeDeveloper?: boolean; includeOnlyDMCommands?: boolean; } @@ -101,6 +102,7 @@ export class CommandRegistry { list({ includeSecret, includeArchived, + includeDeveloper, includeOnlyDMCommands, }: CommandListOptions = {}): Command[] { return this.pool.filter( @@ -108,7 +110,8 @@ export class CommandRegistry { (c.parentName ? true : c.shouldBeIndexed) && (includeSecret || !c.secretCommand) && (includeArchived || !c.archived) && - (includeOnlyDMCommands ? !c.guildRequired : true) + (includeOnlyDMCommands ? !c.guildRequired : true) && + (includeDeveloper || !c.devCommand) ); } diff --git a/src/lib/command/interactions/ConvertedSlashCommand.ts b/src/lib/command/interactions/ConvertedSlashCommand.ts new file mode 100644 index 00000000..e6c72841 --- /dev/null +++ b/src/lib/command/interactions/ConvertedSlashCommand.ts @@ -0,0 +1,25 @@ +import { RESTPostAPIApplicationCommandsJSONBody } from "discord-api-types/v9"; +import { SlashCommandBuilder } from "../../context/arguments/argumentTypes/SlashCommandTypes"; + +export class ConvertedSlashCommand { + private isUserInstallable = false; + + constructor(private builder: SlashCommandBuilder) {} + + public toJSON(): RESTPostAPIApplicationCommandsJSONBody { + const json = this.builder.toJSON(); + + if (this.isUserInstallable) { + // Type is outdated + (json as any).integration_types = [0, 1]; + (json as any).contexts = [0, 1, 2]; + } + + return json; + } + + public setUserInstallable(toggle: boolean): this { + this.isUserInstallable = toggle; + return this; + } +} diff --git a/src/lib/command/interactions/InteractionRegister.ts b/src/lib/command/interactions/InteractionRegister.ts index 7e6e0572..4b74c2b6 100644 --- a/src/lib/command/interactions/InteractionRegister.ts +++ b/src/lib/command/interactions/InteractionRegister.ts @@ -1,22 +1,22 @@ -import { SlashCommandBuilder } from "@discordjs/builders"; import { REST } from "@discordjs/rest"; import { Routes } from "discord-api-types/v9"; import config from "../../../../config.json"; import { Command } from "../Command"; +import { ConvertedSlashCommand } from "./ConvertedSlashCommand"; import { SlashCommandConverter } from "./SlashCommandConverter"; export class InteractionRegister { private discord!: REST; private converter = new SlashCommandConverter(); - init() { + public init() { this.discord = new REST({ version: "9" }).setToken(config.discordToken); } constructor() {} async register(commands: Command[]) { - const convertedCommands = [] as SlashCommandBuilder[]; + const convertedCommands = [] as ConvertedSlashCommand[]; for (const command of commands) { try { @@ -29,7 +29,7 @@ export class InteractionRegister { await this.registerWithDiscord(convertedCommands); } - private async registerWithDiscord(commands: SlashCommandBuilder[]) { + private async registerWithDiscord(commands: ConvertedSlashCommand[]) { try { if (config.environment === "development") { await this.clearApplicationCommands(); diff --git a/src/lib/command/interactions/InteractionRegistry.ts b/src/lib/command/interactions/InteractionRegistry.ts index 56ff463d..faf124e2 100644 --- a/src/lib/command/interactions/InteractionRegistry.ts +++ b/src/lib/command/interactions/InteractionRegistry.ts @@ -58,7 +58,7 @@ export class InteractionRegistry { private getCommands(): Command[] { return this.commandRegistry - .list({ includeSecret: true }) + .list({ includeSecret: true, includeDeveloper: false }) .filter((c) => !!c.slashCommand) as Command[]; } diff --git a/src/lib/command/interactions/SlashCommandConverter.ts b/src/lib/command/interactions/SlashCommandConverter.ts index a31cc10a..2d3edbe0 100644 --- a/src/lib/command/interactions/SlashCommandConverter.ts +++ b/src/lib/command/interactions/SlashCommandConverter.ts @@ -1,20 +1,25 @@ -import { Command, Variation } from "../Command"; import { SlashCommandBuilder, SlashCommandSubcommandBuilder, } from "@discordjs/builders"; +import { PermissionFlagsBits } from "discord-api-types/v9"; import { ArgumentsMap } from "../../context/arguments/types"; -import { ParentCommand } from "../ParentCommand"; import { ChildCommand } from "../ChildCommand"; +import { Command, Variation } from "../Command"; +import { ParentCommand } from "../ParentCommand"; +import { ConvertedSlashCommand } from "./ConvertedSlashCommand"; export class SlashCommandConverter { - convert(command: Command, asVariation?: Variation): SlashCommandBuilder[] { + convert(command: Command, asVariation?: Variation): ConvertedSlashCommand[] { if (command instanceof ParentCommand) { return [this.convertParentCommand(command)]; } let slashCommand = new SlashCommandBuilder() - .setDefaultPermission(!(command.devCommand || command.adminCommand)) + .setDefaultMemberPermissions( + command.adminCommand ? PermissionFlagsBits.Administrator : undefined + ) + .setDMPermission(!command.guildRequired) .setName( ( asVariation?.name || @@ -33,12 +38,19 @@ export class SlashCommandConverter { const variations = this.getSeparateVariations(command); + const convertedSlashCommand = new ConvertedSlashCommand( + slashCommand + ).setUserInstallable(!command.guildRequired); + // Break the variation recursion if (variations.length && !asVariation) { - return [slashCommand, ...this.convertVariations(command, variations)]; + return [ + convertedSlashCommand, + ...this.convertVariations(command, variations), + ]; } - return [slashCommand]; + return [convertedSlashCommand]; } // The typing here is a disaster @@ -91,7 +103,7 @@ export class SlashCommandConverter { return newSlashCommand; } - private convertParentCommand(command: ParentCommand): SlashCommandBuilder { + private convertParentCommand(command: ParentCommand): ConvertedSlashCommand { let parentCommand = new SlashCommandBuilder() .setDefaultPermission(!(command.devCommand || command.adminCommand)) .setName(command.friendlyName) @@ -111,7 +123,7 @@ export class SlashCommandConverter { } } - return parentCommand; + return new ConvertedSlashCommand(parentCommand); } private getSeparateVariations(command: Command): Variation[] { @@ -121,8 +133,8 @@ export class SlashCommandConverter { private convertVariations( command: Command, variations: Variation[] - ): SlashCommandBuilder[] { - const slashCommands: SlashCommandBuilder[] = []; + ): ConvertedSlashCommand[] { + const slashCommands: ConvertedSlashCommand[] = []; for (const variation of variations) { slashCommands.push(...this.convert(command, variation)); diff --git a/src/lib/ui/embeds/AquariumEmbed.ts b/src/lib/ui/embeds/AquariumEmbed.ts index 3b02a78f..c591470e 100644 --- a/src/lib/ui/embeds/AquariumEmbed.ts +++ b/src/lib/ui/embeds/AquariumEmbed.ts @@ -50,13 +50,11 @@ export class AquariumEmbed extends View { const message = this.getAquariumMessage(fishies); return this.baseEmbed.setDescription(` - _${message}_ +_${message}_ - ${tank} +${tank} - There be **${displayNumber( - this.aquarium.size - )} total fishy** in your aquarium. +There be **${displayNumber(this.aquarium.size)} total fishy** in your aquarium. ${ this.aquarium.size === 0 ? ``