/[sudobot]/trunk/src/commands/moderation/EchoCommand.ts
ViewVC logotype

Contents of /trunk/src/commands/moderation/EchoCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26