1 |
import { BanOptions, CommandInteraction, EmojiIdentifierResolvable, GuildMember, Interaction, Message, Permissions, TextChannel, User } 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 getUser from '../../utils/getUser'; |
8 |
import getMember from '../../utils/getMember'; |
9 |
import History from '../../automod/History'; |
10 |
import { fetchEmoji } from '../../utils/Emoji'; |
11 |
import { parseEmbedsInString } from '../../utils/util'; |
12 |
|
13 |
export default class EchoCommand extends BaseCommand { |
14 |
supportsInteractions: boolean = true; |
15 |
|
16 |
constructor() { |
17 |
super('echo', 'moderation', []); |
18 |
} |
19 |
|
20 |
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
21 |
if (!options.isInteraction && typeof options.args[0] === 'undefined') { |
22 |
await msg.reply({ |
23 |
embeds: [ |
24 |
new MessageEmbed() |
25 |
.setColor('#f14a60') |
26 |
.setDescription(`This command requires at least one argument.`) |
27 |
] |
28 |
}); |
29 |
|
30 |
return; |
31 |
} |
32 |
|
33 |
let content: string; |
34 |
let channel: TextChannel = <TextChannel> msg.channel; |
35 |
|
36 |
if (options.isInteraction) { |
37 |
content = await <string> options.options.getString('content'); |
38 |
|
39 |
if (options.options.getChannel('channel')) { |
40 |
channel = await <TextChannel> options.options.getChannel('channel'); |
41 |
} |
42 |
} |
43 |
else { |
44 |
if ((msg as Message).mentions.channels.last()) { |
45 |
channel = await <TextChannel> (msg as Message).mentions.channels.last(); |
46 |
await options.args.pop(); |
47 |
} |
48 |
|
49 |
content = await options.args.join(' '); |
50 |
} |
51 |
|
52 |
if (!channel.send) { |
53 |
await msg.reply({ |
54 |
content: 'Invalid text channel.', |
55 |
ephemeral: true |
56 |
}); |
57 |
|
58 |
return; |
59 |
} |
60 |
|
61 |
try { |
62 |
let { embeds, content: parsedContent } = parseEmbedsInString(content); |
63 |
|
64 |
await channel.send({ |
65 |
content: parsedContent.trim() === '' ? undefined : parsedContent, |
66 |
embeds, |
67 |
attachments: msg instanceof CommandInteraction ? undefined : [...msg.attachments.values()] |
68 |
}); |
69 |
|
70 |
if (options.isInteraction) { |
71 |
const emoji = await fetchEmoji('check'); |
72 |
|
73 |
console.log(emoji); |
74 |
|
75 |
await msg.reply({ |
76 |
content: emoji!.toString() + " Message sent!", |
77 |
ephemeral: true |
78 |
}); |
79 |
} |
80 |
else { |
81 |
await (msg as Message).react(await fetchEmoji('check') as EmojiIdentifierResolvable); |
82 |
} |
83 |
} |
84 |
catch (e) { |
85 |
console.log(e); |
86 |
|
87 |
await msg.reply({ |
88 |
embeds: [ |
89 |
new MessageEmbed() |
90 |
.setColor('#f14a60') |
91 |
.setDescription(`Failed to send message. Maybe missing permissions or invalid embed schema?`) |
92 |
], |
93 |
ephemeral: true |
94 |
}); |
95 |
|
96 |
return; |
97 |
} |
98 |
} |
99 |
} |