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

Contents of /trunk/src/commands/moderation/NotesCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 51 - (show annotations)
Mon Jul 29 17:28:23 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 3449 byte(s)
Release version 2.0
1 import { BanOptions, CommandInteraction, 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 getMember from '../../utils/getMember';
9 import History from '../../automod/History';
10
11 export default class NotesCommand extends BaseCommand {
12 supportsInteractions: boolean = true;
13
14 constructor() {
15 super('notes', 'moderation', []);
16 }
17
18 async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
19 if (!options.isInteraction && typeof options.args[0] === 'undefined') {
20 await msg.reply({
21 embeds: [
22 new MessageEmbed()
23 .setColor('#f14a60')
24 .setDescription(`This command requires at least one argument.`)
25 ]
26 });
27
28 return;
29 }
30
31 let user: GuildMember;
32
33 if (options.isInteraction) {
34 user = await <GuildMember> options.options.getMember('member');
35
36 if (!user) {
37 await msg.reply({
38 embeds: [
39 new MessageEmbed()
40 .setColor('#f14a60')
41 .setDescription("Invalid user given.")
42 ]
43 });
44
45 return;
46 }
47 }
48 else {
49 try {
50 const user2 = await getMember((msg as Message), options);
51
52 if (!user2) {
53 throw new Error('Invalid user');
54 }
55
56 user = user2;
57 }
58 catch (e) {
59 await msg.reply({
60 embeds: [
61 new MessageEmbed()
62 .setColor('#f14a60')
63 .setDescription(`Invalid user given.`)
64 ]
65 });
66
67 return;
68 }
69
70 console.log(user);
71 }
72
73 await client.db.all("SELECT * FROM notes WHERE user_id = ? AND guild_id = ?", [user.id, msg.guild!.id], async (err: any, data: any) => {
74 if (err) {
75 console.log(err);
76 }
77
78 if (data === undefined || data.length < 1) {
79 await msg.reply({
80 embeds: [
81 new MessageEmbed()
82 .setColor('#f14a60')
83 .setDescription('No notes found for user ' + user.user.tag)
84 ]
85 });
86
87 return;
88 }
89
90 let desc = '';
91
92 for (let row of data) {
93 desc += `\n\n**Note #${row.id}**\n${row.content}\nDate: ${new Date(row.date).toUTCString()}`;
94 }
95
96 desc = desc.substring(1);
97
98 await msg.reply({
99 embeds: [
100 new MessageEmbed()
101 .setAuthor({
102 iconURL: user.displayAvatarURL(),
103 name: user.user.tag
104 })
105 .setDescription(desc)
106 ]
107 });
108 });
109 }
110 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26