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

Contents of /trunk/src/commands/moderation/NotegetCommand.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: 2455 byte(s)
chore: eslint autofix
1 import { CommandInteraction, Message, 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 { fetchEmojiStr } from '../../utils/Emoji';
8 import Note from '../../models/Note';
9
10 export default class NotegetCommand extends BaseCommand {
11 supportsInteractions: boolean = true;
12
13 constructor() {
14 super('noteget', '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 id: string;
31
32 if (options.isInteraction) {
33 id = await <string> options.options.getString('id');
34 }
35 else {
36 id = await options.args[0];
37 }
38
39 const note = await Note.findOne({
40 guild_id: msg.guild!.id,
41 _id: id
42 });
43
44 if (!note) {
45 await msg.reply(`${await fetchEmojiStr('error')} Invalid note ID.`);
46 return;
47 }
48
49 let user;
50
51 try {
52 user = await client.users.fetch(note.user_id);
53 }
54 catch (e) {
55 console.log(e);
56 }
57
58 await msg.reply({
59 embeds: [
60 new MessageEmbed({
61 author: {
62 name: user?.tag ?? note.user_id,
63 iconURL: user instanceof User ? user.displayAvatarURL() : undefined,
64 },
65 description: note.content,
66 fields: [
67 {
68 name: 'Note taken by',
69 value: note.mod_tag
70 }
71 ],
72 footer: {
73 text: `ID: ${note.id}`
74 },
75 timestamp: note.createdAt
76 })
77 ]
78 });
79 }
80 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26