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

Annotation of /branches/2.x/src/commands/automation/ExpireCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (hide annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 3539 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 rakinar2 577 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 ExpireCommand extends BaseCommand {
12     supportsInteractions = true;
13    
14     constructor() {
15     super('expire', '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 message = await channel.send({
78     content: text!
79     });
80    
81     const timeout = await setTimeoutv2('expire', time, msg.guild!.id, `expire ${time} ${text!} #${channel.name}`, message.id, channel.id, msg.guild!.id);
82    
83     await msg.reply({
84     embeds: [
85     new MessageEmbed()
86     .setDescription('A queue job has been added.')
87     .setFooter({
88     text: 'ID: ' + timeout.row.id
89     })
90     ],
91     ephemeral: true
92     });
93     }
94     catch(e) {
95     console.log(e);
96    
97     await msg.reply({
98     embeds: [
99     new MessageEmbed()
100     .setColor('#f14a60')
101     .setDescription(`I don't have enough permission to send messages on this channel.`)
102     ]
103     });
104    
105     return;
106     }
107    
108     if (msg instanceof Message) {
109     await msg.react('⏰');
110     }
111     }
112     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26