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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26