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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26