1 |
rakin |
51 |
import { CommandInteraction, GuildMember, Interaction, Message, TextChannel } 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 |
|
|
|
12 |
|
|
export default class ScheduleCommand extends BaseCommand { |
13 |
|
|
supportsInteractions = true; |
14 |
|
|
|
15 |
|
|
constructor() { |
16 |
|
|
super('schedule', 'automation', []); |
17 |
|
|
} |
18 |
|
|
|
19 |
|
|
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
20 |
|
|
if (!options.isInteraction && options.args[1] === undefined) { |
21 |
|
|
await msg.reply({ |
22 |
|
|
embeds: [ |
23 |
|
|
new MessageEmbed() |
24 |
|
|
.setColor('#f14a60') |
25 |
|
|
.setDescription(`This command requires at least two arguments.`) |
26 |
|
|
] |
27 |
|
|
}); |
28 |
|
|
|
29 |
|
|
return; |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
const time = ms(options.isInteraction ? <string> await options.options.getString('time') : options.args[0]); |
33 |
|
|
|
34 |
|
|
if (!time) { |
35 |
|
|
await msg.reply({ |
36 |
|
|
embeds: [ |
37 |
|
|
new MessageEmbed() |
38 |
|
|
.setColor('#f14a60') |
39 |
|
|
.setDescription(`Invalid time interval given.`) |
40 |
|
|
] |
41 |
|
|
}); |
42 |
|
|
|
43 |
|
|
return; |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
let channel: TextChannel = <TextChannel> msg.channel; |
47 |
|
|
let text: string; |
48 |
|
|
|
49 |
|
|
if (options.isInteraction) { |
50 |
|
|
if (options.options.getChannel('channel')) { |
51 |
|
|
channel = <TextChannel> await options.options.getChannel('channel'); |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
text = <string> await options.options.getString('content'); |
55 |
|
|
} |
56 |
|
|
else if (msg instanceof Message) { |
57 |
|
|
const args = [...options.args]; |
58 |
|
|
args.shift(); |
59 |
|
|
|
60 |
|
|
if (msg.mentions.channels.last()) { |
61 |
|
|
channel = await <TextChannel> msg.mentions.channels.last(); |
62 |
|
|
args.pop(); |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
text = args.join(' '); |
66 |
|
|
} |
67 |
rakin |
55 |
|
68 |
|
|
if (!channel.send) { |
69 |
|
|
await msg.reply({ |
70 |
|
|
content: 'Invalid text channel.', |
71 |
|
|
ephemeral: true |
72 |
|
|
}); |
73 |
rakin |
51 |
|
74 |
rakin |
55 |
return; |
75 |
|
|
} |
76 |
|
|
|
77 |
rakin |
51 |
try { |
78 |
rakin |
57 |
const timeout = await setTimeoutv2('send', time, msg.guild!.id, `schedule ${time} ${text!} #${channel.name}`, text!, channel.id, msg.guild!.id); |
79 |
rakin |
51 |
|
80 |
|
|
await msg.reply({ |
81 |
|
|
embeds: [ |
82 |
|
|
new MessageEmbed() |
83 |
|
|
.setDescription('A queue job has been added.') |
84 |
|
|
.setFooter({ |
85 |
|
|
text: 'ID: ' + timeout.row.id |
86 |
|
|
}) |
87 |
|
|
], |
88 |
|
|
ephemeral: true |
89 |
|
|
}); |
90 |
|
|
} |
91 |
|
|
catch(e) { |
92 |
|
|
console.log(e); |
93 |
|
|
|
94 |
|
|
await msg.reply({ |
95 |
|
|
embeds: [ |
96 |
|
|
new MessageEmbed() |
97 |
|
|
.setColor('#f14a60') |
98 |
|
|
.setDescription(`I don't have enough permission to send messages on this channel.`) |
99 |
|
|
] |
100 |
|
|
}); |
101 |
|
|
|
102 |
|
|
return; |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
if (msg instanceof Message) { |
106 |
|
|
await msg.react('⏰'); |
107 |
|
|
} |
108 |
|
|
} |
109 |
|
|
} |