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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 344 - (hide annotations)
Mon Jul 29 17:29:40 2024 UTC (8 months, 2 weeks ago) by rakin
File MIME type: application/typescript
File size: 2455 byte(s)
chore: eslint autofix
1 rakin 344 import { CommandInteraction, Message, User } from 'discord.js';
2 rakin 51 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 rakin 86 import { fetchEmojiStr } from '../../utils/Emoji';
8     import Note from '../../models/Note';
9 rakin 5
10 rakin 51 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 rakin 5 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 rakin 51 let id: string;
31    
32     if (options.isInteraction) {
33 rakin 334 id = await <string> options.options.getString('id');
34 rakin 51 }
35     else {
36 rakin 86 id = await options.args[0];
37 rakin 51 }
38    
39 rakin 86 const note = await Note.findOne({
40 rakin 334 guild_id: msg.guild!.id,
41     _id: id
42 rakin 86 });
43 rakin 5
44 rakin 86 if (!note) {
45     await msg.reply(`${await fetchEmojiStr('error')} Invalid note ID.`);
46     return;
47     }
48 rakin 5
49 rakin 86 let user;
50 rakin 5
51 rakin 86 try {
52 rakin 334 user = await client.users.fetch(note.user_id);
53 rakin 86 }
54     catch (e) {
55     console.log(e);
56     }
57 rakin 5
58 rakin 86 await msg.reply({
59     embeds: [
60     new MessageEmbed({
61     author: {
62 rakin 334 name: user?.tag ?? note.user_id,
63 rakin 86 iconURL: user instanceof User ? user.displayAvatarURL() : undefined,
64     },
65 rakin 334 description: note.content,
66 rakin 86 fields: [
67 rakin 5 {
68 rakin 86 name: 'Note taken by',
69 rakin 334 value: note.mod_tag
70 rakin 5 }
71 rakin 86 ],
72     footer: {
73 rakin 334 text: `ID: ${note.id}`
74 rakin 86 },
75 rakin 334 timestamp: note.createdAt
76 rakin 86 })
77     ]
78 rakin 5 });
79     }
80 rakin 51 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26