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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26