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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 257 - (hide annotations)
Mon Jul 29 17:29:14 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 3354 byte(s)
feat: echo and send command now supports attachments and embeds
1 rakin 51 import { BanOptions, CommandInteraction, EmojiIdentifierResolvable, 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 rakin 257 import { parseEmbedsInString } from '../../utils/util';
12 rakin 51
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 rakin 257 let { embeds, content: parsedContent } = parseEmbedsInString(content);
61    
62 rakin 51 await member.send({
63 rakin 257 content: parsedContent.trim() === '' ? undefined : parsedContent,
64     embeds,
65     attachments: msg instanceof CommandInteraction ? undefined : [...msg.attachments.values()]
66 rakin 51 });
67    
68     if (options.isInteraction) {
69     const emoji = await fetchEmoji('check');
70    
71     console.log(emoji);
72    
73     await msg.reply({
74     content: emoji!.toString() + " Message sent!",
75     ephemeral: true
76     });
77     }
78     else {
79     await (msg as Message).react(await fetchEmoji('check') as EmojiIdentifierResolvable);
80     }
81     }
82     catch (e) {
83     console.log(e);
84    
85     await msg.reply({
86     embeds: [
87     new MessageEmbed()
88     .setColor('#f14a60')
89 rakin 257 .setDescription(`Failed to send message. Maybe invalid embed schema or the user has disabled DMs?`)
90 rakin 51 ],
91     ephemeral: true
92     });
93    
94     return;
95     }
96     }
97     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26