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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26