/[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 393 - (hide annotations)
Mon Jul 29 17:29:59 2024 UTC (8 months, 3 weeks ago) by rakin
File MIME type: application/typescript
File size: 3179 byte(s)
style: add license comments (#77)

* style: add license commits

* fix: shebang errors
1 rakin 393 /**
2     * This file is part of SudoBot.
3     *
4     * Copyright (C) 2021-2022 OSN Inc.
5     *
6     * SudoBot is free software; you can redistribute it and/or modify it
7     * under the terms of the GNU Affero General Public License as published by
8     * the Free Software Foundation, either version 3 of the License, or
9     * (at your option) any later version.
10     *
11     * SudoBot is distributed in the hope that it will be useful, but
12     * WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU Affero General Public License for more details.
15     *
16     * You should have received a copy of the GNU Affero General Public License
17     * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18     */
19    
20 rakin 344 import { CommandInteraction, Message, User } from 'discord.js';
21 rakin 51 import BaseCommand from '../../utils/structures/BaseCommand';
22     import DiscordClient from '../../client/Client';
23     import CommandOptions from '../../types/CommandOptions';
24     import InteractionOptions from '../../types/InteractionOptions';
25     import MessageEmbed from '../../client/MessageEmbed';
26 rakin 86 import { fetchEmojiStr } from '../../utils/Emoji';
27     import Note from '../../models/Note';
28 rakin 5
29 rakin 51 export default class NotegetCommand extends BaseCommand {
30     supportsInteractions: boolean = true;
31    
32     constructor() {
33     super('noteget', 'moderation', []);
34     }
35    
36     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
37     if (!options.isInteraction && typeof options.args[0] === 'undefined') {
38 rakin 5 await msg.reply({
39     embeds: [
40     new MessageEmbed()
41     .setColor('#f14a60')
42     .setDescription(`This command requires at least one argument.`)
43     ]
44     });
45    
46     return;
47     }
48    
49 rakin 51 let id: string;
50    
51     if (options.isInteraction) {
52 rakin 334 id = await <string> options.options.getString('id');
53 rakin 51 }
54     else {
55 rakin 86 id = await options.args[0];
56 rakin 51 }
57    
58 rakin 86 const note = await Note.findOne({
59 rakin 334 guild_id: msg.guild!.id,
60     _id: id
61 rakin 86 });
62 rakin 5
63 rakin 86 if (!note) {
64     await msg.reply(`${await fetchEmojiStr('error')} Invalid note ID.`);
65     return;
66     }
67 rakin 5
68 rakin 86 let user;
69 rakin 5
70 rakin 86 try {
71 rakin 334 user = await client.users.fetch(note.user_id);
72 rakin 86 }
73     catch (e) {
74     console.log(e);
75     }
76 rakin 5
77 rakin 86 await msg.reply({
78     embeds: [
79     new MessageEmbed({
80     author: {
81 rakin 334 name: user?.tag ?? note.user_id,
82 rakin 86 iconURL: user instanceof User ? user.displayAvatarURL() : undefined,
83     },
84 rakin 334 description: note.content,
85 rakin 86 fields: [
86 rakin 5 {
87 rakin 86 name: 'Note taken by',
88 rakin 334 value: note.mod_tag
89 rakin 5 }
90 rakin 86 ],
91     footer: {
92 rakin 334 text: `ID: ${note.id}`
93 rakin 86 },
94 rakin 334 timestamp: note.createdAt
95 rakin 86 })
96     ]
97 rakin 5 });
98     }
99 rakin 51 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26