/[sudobot]/trunk/src/commands/automation/AddQueueCommand.ts
ViewVC logotype

Annotation of /trunk/src/commands/automation/AddQueueCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 72 - (hide annotations)
Mon Jul 29 17:28:29 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 2994 byte(s)
Added proper help information
1 rakin 51 import { CommandInteraction, GuildMember, Interaction, Message } from 'discord.js';
2     import BaseCommand from '../../utils/structures/BaseCommand';
3     import DiscordClient from '../../client/Client';
4     import CommandOptions from '../../types/CommandOptions';
5     import InteractionOptions from '../../types/InteractionOptions';
6     import MessageEmbed from '../../client/MessageEmbed';
7     import ms from 'ms';
8     import { timeSince } from '../../utils/util';
9     import { setTimeoutv2 } from '../../utils/setTimeout';
10 rakin 46
11 rakin 51 export default class AddQueueCommand extends BaseCommand {
12     constructor() {
13     super('addqueue', 'automation', []);
14     }
15    
16     async run(client: DiscordClient, msg: Message, options: CommandOptions) {
17     if (options.args[1] === undefined) {
18 rakin 46 await msg.reply({
19     embeds: [
20     new MessageEmbed()
21     .setColor('#f14a60')
22     .setDescription(`This command requires at least two arguments.`)
23     ]
24     });
25    
26     return;
27     }
28    
29 rakin 51 const time = await ms(options.args[0]);
30     let cmd: string[];
31 rakin 46
32     if (!time) {
33     await msg.reply({
34     embeds: [
35     new MessageEmbed()
36     .setColor('#f14a60')
37     .setDescription(`Invalid time interval given.`)
38     ]
39     });
40    
41     return;
42     }
43    
44 rakin 51 cmd = [...options.args];
45     cmd.shift();
46 rakin 46
47 rakin 51 const cmdObj = client.commands.get(cmd[0]);
48    
49     if (!cmdObj) {
50 rakin 46 await msg.reply({
51     embeds: [
52     new MessageEmbed()
53     .setColor('#f14a60')
54     .setDescription(`Invalid command given.`)
55     ]
56     });
57    
58     return;
59     }
60    
61 rakin 51 if (!cmdObj.supportsLegacy) {
62     await msg.reply({
63     embeds: [
64     new MessageEmbed()
65     .setColor('#f14a60')
66     .setDescription(`This command conflicts with queued jobs.`)
67     ]
68     });
69 rakin 46
70 rakin 51 return;
71     }
72 rakin 46
73 rakin 51 const command = await cmd.join(' ');
74    
75 rakin 57 const queue = await setTimeoutv2('queue', time, msg.guild!.id, command, command, msg.id, msg.channel!.id, msg.guild!.id);
76 rakin 51
77 rakin 46 await msg.reply({
78     embeds: [
79     new MessageEmbed()
80     .setColor('#007bff')
81     .setDescription(`The queue has been added.`)
82     .setFields([
83     {
84     name: "ID",
85     value: queue.row.id + '',
86     },
87     {
88     name: "Command",
89     value: `\`${command}\``
90     },
91     {
92     name: "Time",
93     value: "After " + timeSince(Date.now() - time).replace(' ago', '')
94     }
95     ])
96     ]
97     });
98     }
99 rakin 51 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26