1 |
import { BanOptions, CommandInteraction, EmojiIdentifierResolvable, FileOptions, GuildMember, Interaction, Message, 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 SendCommand extends BaseCommand { |
14 |
supportsInteractions: boolean = true; |
15 |
|
16 |
constructor() { |
17 |
super('send', 'moderation', []); |
18 |
} |
19 |
|
20 |
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
21 |
if (!options.isInteraction && typeof options.args[1] === 'undefined') { |
22 |
await msg.reply({ |
23 |
embeds: [ |
24 |
new MessageEmbed() |
25 |
.setColor('#f14a60') |
26 |
.setDescription(`This command requires at least two arguments.`) |
27 |
] |
28 |
}); |
29 |
|
30 |
return; |
31 |
} |
32 |
|
33 |
let content: string; |
34 |
let member: GuildMember | undefined | null; |
35 |
|
36 |
if (options.isInteraction) { |
37 |
member = await <GuildMember> options.options.getMember('member'); |
38 |
content = await <string> options.options.getString('content'); |
39 |
} |
40 |
else { |
41 |
member = await getMember(msg as Message, options); |
42 |
|
43 |
if (!member) { |
44 |
await msg.reply({ |
45 |
embeds: [ |
46 |
new MessageEmbed() |
47 |
.setColor('#f14a60') |
48 |
.setDescription(`Invalid user given.`) |
49 |
] |
50 |
}); |
51 |
|
52 |
return; |
53 |
} |
54 |
|
55 |
options.args.shift(); |
56 |
content = await options.args.join(' '); |
57 |
} |
58 |
|
59 |
try { |
60 |
let { embeds, content: parsedContent } = parseEmbedsInString(content); |
61 |
|
62 |
await member.send({ |
63 |
content: parsedContent.trim() === '' ? undefined : parsedContent, |
64 |
embeds, |
65 |
files: msg instanceof CommandInteraction ? undefined : [...msg.attachments.map(a => ({ |
66 |
attachment: a.proxyURL, |
67 |
description: a.description, |
68 |
name: a.name |
69 |
} as FileOptions)).values()] |
70 |
}); |
71 |
|
72 |
if (options.isInteraction) { |
73 |
const emoji = await fetchEmoji('check'); |
74 |
|
75 |
console.log(emoji); |
76 |
|
77 |
await msg.reply({ |
78 |
content: emoji!.toString() + " Message sent!", |
79 |
ephemeral: true |
80 |
}); |
81 |
} |
82 |
else { |
83 |
await (msg as Message).react(await fetchEmoji('check') as EmojiIdentifierResolvable); |
84 |
} |
85 |
} |
86 |
catch (e) { |
87 |
console.log(e); |
88 |
|
89 |
await msg.reply({ |
90 |
embeds: [ |
91 |
new MessageEmbed() |
92 |
.setColor('#f14a60') |
93 |
.setDescription(`Failed to send message. Maybe invalid embed schema or the user has disabled DMs?`) |
94 |
], |
95 |
ephemeral: true |
96 |
}); |
97 |
|
98 |
return; |
99 |
} |
100 |
} |
101 |
} |