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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 344 - (show annotations)
Mon Jul 29 17:29:40 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 3401 byte(s)
chore: eslint autofix
1 import { CommandInteraction, EmojiIdentifierResolvable, FileOptions, GuildMember, Message } 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 getMember from '../../utils/getMember';
8 import { fetchEmoji } from '../../utils/Emoji';
9 import { parseEmbedsInString } from '../../utils/util';
10
11 export default class SendCommand extends BaseCommand {
12 supportsInteractions: boolean = true;
13
14 constructor() {
15 super('send', 'moderation', []);
16 }
17
18 async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
19 if (!options.isInteraction && typeof 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 let content: string;
32 let member: GuildMember | undefined | null;
33
34 if (options.isInteraction) {
35 member = await <GuildMember> options.options.getMember('member');
36 content = await <string> options.options.getString('content');
37 }
38 else {
39 member = await getMember(msg as Message, options);
40
41 if (!member) {
42 await msg.reply({
43 embeds: [
44 new MessageEmbed()
45 .setColor('#f14a60')
46 .setDescription(`Invalid user given.`)
47 ]
48 });
49
50 return;
51 }
52
53 options.args.shift();
54 content = await options.args.join(' ');
55 }
56
57 try {
58 let { embeds, content: parsedContent } = parseEmbedsInString(content);
59
60 await member.send({
61 content: parsedContent.trim() === '' ? undefined : parsedContent,
62 embeds,
63 files: msg instanceof CommandInteraction ? undefined : [...msg.attachments.map(a => ({
64 attachment: a.proxyURL,
65 description: a.description,
66 name: a.name
67 } as FileOptions)).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 invalid embed schema or the user has disabled DMs?`)
92 ],
93 ephemeral: true
94 });
95
96 return;
97 }
98 }
99 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26