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