/[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 86 - (hide annotations)
Mon Jul 29 17:28:32 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 2742 byte(s)
Updated the database system
1 rakin 51 import { BanOptions, CommandInteraction, Guild, GuildMember, Interaction, 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 getUser from '../../utils/getUser';
8     import History from '../../automod/History';
9     import getMember from '../../utils/getMember';
10     import ms from 'ms';
11 rakin 86 import { fetchEmojiStr } from '../../utils/Emoji';
12     import Note from '../../models/Note';
13 rakin 5
14 rakin 51 export default class NotegetCommand extends BaseCommand {
15     supportsInteractions: boolean = true;
16    
17     constructor() {
18     super('noteget', 'moderation', []);
19     }
20    
21     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
22     if (!options.isInteraction && typeof options.args[0] === 'undefined') {
23 rakin 5 await msg.reply({
24     embeds: [
25     new MessageEmbed()
26     .setColor('#f14a60')
27     .setDescription(`This command requires at least one argument.`)
28     ]
29     });
30    
31     return;
32     }
33    
34 rakin 51 let id: string;
35    
36     if (options.isInteraction) {
37 rakin 86 id = await <string> options.options.getNumber('id')?.toString();
38 rakin 51 }
39     else {
40 rakin 86 id = await options.args[0];
41 rakin 51 }
42    
43 rakin 86 const note = await Note.findOne({
44     where: {
45     guild_id: msg.guild!.id,
46     id
47 rakin 5 }
48 rakin 86 });
49 rakin 5
50 rakin 86 if (!note) {
51     await msg.reply(`${await fetchEmojiStr('error')} Invalid note ID.`);
52     return;
53     }
54 rakin 5
55 rakin 86 let user;
56 rakin 5
57 rakin 86 try {
58     user = await client.users.fetch(note.get().user_id);
59     }
60     catch (e) {
61     console.log(e);
62     }
63 rakin 5
64 rakin 86 await msg.reply({
65     embeds: [
66     new MessageEmbed({
67     author: {
68     name: user?.tag ?? note.get().user_id,
69     iconURL: user instanceof User ? user.displayAvatarURL() : undefined,
70     },
71     description: note.get().content,
72     fields: [
73 rakin 5 {
74 rakin 86 name: 'Note taken by',
75     value: note.get().mod_tag
76 rakin 5 }
77 rakin 86 ],
78     footer: {
79     text: `ID: ${note.get().id}`
80     },
81     timestamp: note.get().createdAt
82     })
83     ]
84 rakin 5 });
85     }
86 rakin 51 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26