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

Annotation of /trunk/src/commands/moderation/NotedelCommand.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: 2511 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 } 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 Note from '../../models/Note';
27     import { fetchEmojiStr } from '../../utils/Emoji';
28 rakin 51
29     export default class NotedelCommand extends BaseCommand {
30     supportsInteractions: boolean = true;
31    
32     constructor() {
33     super('notedel', 'moderation', []);
34     }
35    
36     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
37     if (!options.isInteraction && typeof options.args[0] === 'undefined') {
38     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     let id: string;
50    
51     if (options.isInteraction) {
52 rakin 334 id = await <string> options.options.getString('id');
53 rakin 51 }
54     else {
55     id = await options.args[0];
56     }
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 51
63 rakin 86 if (!note) {
64     await msg.reply(`${await fetchEmojiStr('error')} Invalid note ID.`);
65     return;
66     }
67 rakin 51
68 rakin 334 await note.delete();
69 rakin 51
70 rakin 86 await msg.reply({
71     embeds: [
72     new MessageEmbed({
73     description: `${await fetchEmojiStr('check')} Note deleted.`
74     })
75     ]
76 rakin 51 });
77     }
78     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26