/[sudobot]/branches/6.x/src/commands/automation/QueueCommand.ts
ViewVC logotype

Annotation of /branches/6.x/src/commands/automation/QueueCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (hide annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 3809 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 rakinar2 577 /**
2     * This file is part of SudoBot.
3     *
4     * Copyright (C) 2021-2023 OSN Developers.
5     *
6     * SudoBot is free software; you can redistribute it and/or modify it
7     * under the terms of the GNU Affero General Public License as published by
8     * the Free Software Foundation, either version 3 of the License, or
9     * (at your option) any later version.
10     *
11     * SudoBot is distributed in the hope that it will be useful, but
12     * WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU Affero General Public License for more details.
15     *
16     * You should have received a copy of the GNU Affero General Public License
17     * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18     */
19    
20     import { PermissionsBitField, SlashCommandBuilder } from "discord.js";
21     import Command, { ArgumentType, BasicCommandContext, CommandMessage, CommandReturn, ValidationRule } from "../../core/Command";
22    
23     export default class QueueCommand extends Command {
24     public readonly subcommands = ["add", "cancel", "list", "show"];
25     public readonly name = "queue";
26     public readonly subCommandCheck = true;
27     public readonly validationRules: ValidationRule[] = [
28     {
29     types: [ArgumentType.String],
30     errors: {
31     required: `Please provide a valid subcommand! The valid commands are: \`${this.subcommands.join(
32     "`, `"
33     )}\`, \`remove\`, \`view\``,
34     "type:invalid": "Please provide a valid subcommand!",
35     },
36     name: "subcommand"
37     }
38     ];
39     public readonly permissions = [PermissionsBitField.Flags.ManageMessages];
40     public readonly description = "Manage the queued jobs";
41     public readonly since = "5.57.0";
42     public readonly slashCommandBuilder = new SlashCommandBuilder()
43     .addSubcommand(subcommand =>
44     subcommand
45     .setName("add")
46     .setDescription("Creates a new command queue")
47     .addStringOption(option =>
48     option
49     .setName("run_after")
50     .setDescription("Specify after how much time the queued job will run")
51     .setRequired(true)
52     )
53     .addStringOption(option =>
54     option
55     .setName("command")
56     .setDescription("Specify what command to run (include everything just without the prefix)")
57     .setRequired(true)
58     )
59     )
60     .addSubcommand(subcommand =>
61     subcommand
62     .setName("cancel")
63     .setDescription("Cancels a previously added queue")
64     .addIntegerOption(option => option.setName("id").setDescription("The queue ID").setRequired(true))
65     )
66     .addSubcommand(subcommand =>
67     subcommand
68     .setName("show")
69     .setDescription("Shows information about a previously added queue")
70     .addIntegerOption(option => option.setName("id").setDescription("The queue ID").setRequired(true))
71     )
72     .addSubcommand(subcommand => subcommand.setName("list").setDescription("List all queued jobs"));
73    
74     async execute(message: CommandMessage, context: BasicCommandContext): Promise<CommandReturn> {
75     const subcommand = context.isLegacy ? context.parsedNamedArgs.subcommand : context.options.getSubcommand(true);
76     const command = this.client.commands.get(`queue__${subcommand}`);
77    
78     if (!command) {
79     await this.error(message, this.validationRules[0].errors!.required!);
80     return;
81     }
82    
83     if (context.isLegacy) context.args.shift();
84    
85     return await command.execute(message, context);
86     }
87     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26