/[sudobot]/branches/2.x/src/commands/moderation/NoteCommand.ts
ViewVC logotype

Annotation of /branches/2.x/src/commands/moderation/NoteCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (hide annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 3302 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 rakinar2 577 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 { fetchEmoji } from '../../utils/Emoji';
12    
13     export async function note(user: GuildMember | User, content: string, msg: Message | CommandInteraction) {
14     const { default: Note } = await import('../../models/Note');
15    
16     return await Note.create({
17     content,
18     author: msg.member!.user.id,
19     mod_tag: (msg.member!.user as User).tag,
20     user_id: user.id,
21     guild_id: msg.guild!.id
22     });
23     }
24    
25     export default class NoteCommand extends BaseCommand {
26     supportsInteractions: boolean = true;
27    
28     constructor() {
29     super('note', 'moderation', []);
30     }
31    
32     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
33     if (!options.isInteraction && typeof options.args[1] === 'undefined') {
34     await msg.reply({
35     embeds: [
36     new MessageEmbed()
37     .setColor('#f14a60')
38     .setDescription(`This command requires at least two arguments.`)
39     ]
40     });
41    
42     return;
43     }
44    
45     let user: User;
46     let content: string | undefined;
47    
48     if (options.isInteraction) {
49     user = await <User> options.options.getUser('user');
50    
51     if (!user) {
52     await msg.reply({
53     embeds: [
54     new MessageEmbed()
55     .setColor('#f14a60')
56     .setDescription("Invalid user given.")
57     ]
58     });
59    
60     return;
61     }
62    
63     content = <string> options.options.getString('note');
64     }
65     else {
66     try {
67     const user2 = await getUser(client, (msg as Message), options);
68    
69     if (!user2) {
70     throw new Error('Invalid user');
71     }
72    
73     user = user2;
74     }
75     catch (e) {
76     await msg.reply({
77     embeds: [
78     new MessageEmbed()
79     .setColor('#f14a60')
80     .setDescription(`Invalid user given.`)
81     ]
82     });
83    
84     return;
85     }
86    
87     console.log(user);
88    
89     await options.args.shift();
90     content = options.args.join(' ');
91     }
92    
93     const n = await note(user, content as string, msg);
94    
95     await msg.reply({
96     embeds: [
97     new MessageEmbed()
98     .setDescription(`${(await fetchEmoji('check'))?.toString()} A note has been added for ${user.tag}`)
99     .setFooter({
100     text: `ID: ${n.get().id}`
101     })
102     ]
103     });
104     }
105     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26