/[sudobot]/trunk/src/commands/automation/ExpireScheduleCommand.ts
ViewVC logotype

Contents of /trunk/src/commands/automation/ExpireScheduleCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26