Advertisement
Guest User

Untitled

a guest
Mar 14th, 2024
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Subcommand } from '@sapphire/plugin-subcommands';
  2. import { ActionRowBuilder, ModalActionRowComponentBuilder, ModalBuilder, TextInputBuilder, TextInputStyle } from 'discord.js';
  3. import CustomEmbed, { CustomEmbedType } from '../lib/CustomEmbed.js';
  4.  
  5. /**
  6.  * Adds usable quotes.
  7.  */
  8. export class QuotesSubcommandGroup extends Subcommand {
  9.     /**
  10.      * The modals used within this command.
  11.      */
  12.     private static readonly _modals = {
  13.         add: new ModalBuilder() //
  14.             .setTitle('Adding new quotes.')
  15.             .setCustomId('add_quotes')
  16.             .setComponents([
  17.                 new ActionRowBuilder<ModalActionRowComponentBuilder>() //
  18.                     .setComponents([
  19.                         new TextInputBuilder() //
  20.                             .setLabel('A comma separated list of quotes to add.')
  21.                             .setRequired(true)
  22.                             .setStyle(TextInputStyle.Paragraph)
  23.                             .setMinLength(1)
  24.                             .setCustomId('quote')
  25.                     ])
  26.             ])
  27.     };
  28.  
  29.     public constructor(context: Subcommand.LoaderContext, options: Subcommand.Options) {
  30.         super(context, {
  31.             ...options,
  32.             name: 'quotes',
  33.             subcommands: [
  34.                 {
  35.                     name: 'add',
  36.                     chatInputRun: 'chatInputAdd'
  37.                 },
  38.                 {
  39.                     name: 'remove',
  40.                     chatInputRun: 'chatInputRemove'
  41.                 }
  42.             ]
  43.         });
  44.     }
  45.  
  46.     /**
  47.      * The modals used within this command.
  48.      */
  49.     public static get modals() {
  50.         return this._modals;
  51.     }
  52.  
  53.     /**
  54.      * Registers this slash command.
  55.      *
  56.      * @param registry - The {@link Command.Registry} instance associated with this command.
  57.      */
  58.     public override registerApplicationCommands(registry: Subcommand.Registry) {
  59.         registry.registerChatInputCommand(
  60.             (builder) =>
  61.                 builder
  62.                     .setName('quotes') //
  63.                     .setDescription('Manages the list of quotes.')
  64.                     .setDefaultMemberPermissions('0')
  65.                     .addSubcommand((subCommand) => {
  66.                         return subCommand //
  67.                             .setName('add')
  68.                             .setDescription('Add quotes to the list.');
  69.                     })
  70.                     .addSubcommand((subCommand) => {
  71.                         return subCommand //
  72.                             .setName('remove')
  73.                             .setDescription('Remove a quote from the list.')
  74.                             .addStringOption((option) => {
  75.                                 return option //
  76.                                     .setName('quote')
  77.                                     .setDescription('The quote to remove.')
  78.                                     .setMinLength(1)
  79.                                     .setRequired(true);
  80.                             });
  81.                     }),
  82.             {
  83.                 idHints: ['1217906420926644305'],
  84.                 guildIds: this.container.environment.GUILD_IDS.split(',')
  85.             }
  86.             /**
  87.              * Don't forget to add the command's id to `idHints` when the command is registered.
  88.              *
  89.              * ```
  90.              * {
  91.              *  idHints: [...]
  92.              * }
  93.              * ```
  94.              */
  95.         );
  96.     }
  97.  
  98.     /**
  99.      * Handles the `/quotes add` subcommand.
  100.      *
  101.      * @param interaction - The {@link Command.ChatInputCommandInteraction} object received.
  102.      */
  103.     public async chatInputAdd(interaction: Subcommand.ChatInputCommandInteraction) {
  104.         console.log(interaction.commandId);
  105.         await interaction.showModal(QuotesSubcommandGroup._modals.add);
  106.     }
  107.  
  108.     /**
  109.      * Handles the `/quotes remove <quote>` subcommand.
  110.      *
  111.      * @param interaction - The {@link Command.ChatInputCommandInteraction} object received.
  112.      */
  113.     public async chatInputRemove(interaction: Subcommand.ChatInputCommandInteraction) {
  114.         await interaction.deferReply({
  115.             ephemeral: true
  116.         });
  117.  
  118.         const quoteToRemove = interaction.options.getString('quote', true);
  119.         const removedQuote = await this.container.database.models.quotes.removeQuote(quoteToRemove);
  120.  
  121.         const embed = //
  122.             new CustomEmbed(removedQuote ? CustomEmbedType.Success : CustomEmbedType.Error) //
  123.                 .setDescription(removedQuote ? 'The specified quote was removed successfully.' : 'Could not find the specified quote.');
  124.  
  125.         await interaction.editReply({
  126.             embeds: [embed]
  127.         });
  128.     }
  129. }
  130.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement