/[sudobot]/branches/2.x/src/commands/automation/ScheduleCommand.ts
ViewVC logotype

Contents of /branches/2.x/src/commands/automation/ScheduleCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 3429 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 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 ms from 'ms';
8 import { timeSince } from '../../utils/util';
9 import { setTimeoutv2 } from '../../utils/setTimeout';
10
11 export default class ScheduleCommand extends BaseCommand {
12 supportsInteractions = true;
13
14 constructor() {
15 super('schedule', 'automation', []);
16 }
17
18 async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
19 if (!options.isInteraction && options.args[1] === undefined) {
20 await msg.reply({
21 embeds: [
22 new MessageEmbed()
23 .setColor('#f14a60')
24 .setDescription(`This command requires at least two arguments.`)
25 ]
26 });
27
28 return;
29 }
30
31 const time = ms(options.isInteraction ? <string> await options.options.getString('time') : options.args[0]);
32
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 let channel: TextChannel = <TextChannel> msg.channel;
46 let text: string;
47
48 if (options.isInteraction) {
49 if (options.options.getChannel('channel')) {
50 channel = <TextChannel> await options.options.getChannel('channel');
51 }
52
53 text = <string> await options.options.getString('content');
54 }
55 else if (msg instanceof Message) {
56 const args = [...options.args];
57 args.shift();
58
59 if (msg.mentions.channels.last()) {
60 channel = await <TextChannel> msg.mentions.channels.last();
61 args.pop();
62 }
63
64 text = args.join(' ');
65 }
66
67 if (!channel.send) {
68 await msg.reply({
69 content: 'Invalid text channel.',
70 ephemeral: true
71 });
72
73 return;
74 }
75
76 try {
77 const timeout = await setTimeoutv2('send', time, msg.guild!.id, `schedule ${time} ${text!} #${channel.name}`, text!, channel.id, msg.guild!.id);
78
79 await msg.reply({
80 embeds: [
81 new MessageEmbed()
82 .setDescription('A queue job has been added.')
83 .setFooter({
84 text: 'ID: ' + timeout.row.id
85 })
86 ],
87 ephemeral: true
88 });
89 }
90 catch(e) {
91 console.log(e);
92
93 await msg.reply({
94 embeds: [
95 new MessageEmbed()
96 .setColor('#f14a60')
97 .setDescription(`I don't have enough permission to send messages on this channel.`)
98 ]
99 });
100
101 return;
102 }
103
104 if (msg instanceof Message) {
105 await msg.react('⏰');
106 }
107 }
108 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26