1 |
import { 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 MessageEmbed from '../../client/MessageEmbed'; |
6 |
import ms from 'ms'; |
7 |
import { timeSince } from '../../utils/util'; |
8 |
import { setTimeoutv2 } from '../../utils/setTimeout'; |
9 |
|
10 |
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 |
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 |
const time = await ms(options.args[0]); |
29 |
let cmd: string[]; |
30 |
|
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 |
cmd = [...options.args]; |
44 |
cmd.shift(); |
45 |
|
46 |
const cmdObj = client.commands.get(cmd[0]); |
47 |
|
48 |
if (!cmdObj) { |
49 |
await msg.reply({ |
50 |
embeds: [ |
51 |
new MessageEmbed() |
52 |
.setColor('#f14a60') |
53 |
.setDescription(`Invalid command given.`) |
54 |
] |
55 |
}); |
56 |
|
57 |
return; |
58 |
} |
59 |
|
60 |
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 |
|
69 |
return; |
70 |
} |
71 |
|
72 |
const command = await cmd.join(' '); |
73 |
|
74 |
const queue = await setTimeoutv2('queue', time, msg.guild!.id, command, command, msg.id, msg.channel!.id, msg.guild!.id); |
75 |
|
76 |
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 |
} |