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 |
|
12 |
export async function note(client: DiscordClient, user: GuildMember | User, content: string, msg: Message | CommandInteraction) { |
13 |
await client.db.get("INSERT INTO notes(user_id, guild_id, content, date) VALUES(?, ?, ?, ?)", [user.id, msg.guild!.id, content, (new Date().toISOString())], async (err: any) => { |
14 |
if (err) { |
15 |
console.log(err); |
16 |
} |
17 |
}); |
18 |
} |
19 |
|
20 |
export default class NoteCommand extends BaseCommand { |
21 |
supportsInteractions: boolean = true; |
22 |
|
23 |
constructor() { |
24 |
super('note', 'moderation', []); |
25 |
} |
26 |
|
27 |
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
28 |
if (!options.isInteraction && typeof options.args[1] === 'undefined') { |
29 |
await msg.reply({ |
30 |
embeds: [ |
31 |
new MessageEmbed() |
32 |
.setColor('#f14a60') |
33 |
.setDescription(`This command requires at least two arguments.`) |
34 |
] |
35 |
}); |
36 |
|
37 |
return; |
38 |
} |
39 |
|
40 |
let user: GuildMember; |
41 |
let content: string | undefined; |
42 |
|
43 |
if (options.isInteraction) { |
44 |
user = await <GuildMember> options.options.getMember('member'); |
45 |
|
46 |
if (!user) { |
47 |
await msg.reply({ |
48 |
embeds: [ |
49 |
new MessageEmbed() |
50 |
.setColor('#f14a60') |
51 |
.setDescription("Invalid user given.") |
52 |
] |
53 |
}); |
54 |
|
55 |
return; |
56 |
} |
57 |
|
58 |
content = <string> options.options.getString('note'); |
59 |
} |
60 |
else { |
61 |
try { |
62 |
const user2 = await getMember((msg as Message), options); |
63 |
|
64 |
if (!user2) { |
65 |
throw new Error('Invalid user'); |
66 |
} |
67 |
|
68 |
user = user2; |
69 |
} |
70 |
catch (e) { |
71 |
await msg.reply({ |
72 |
embeds: [ |
73 |
new MessageEmbed() |
74 |
.setColor('#f14a60') |
75 |
.setDescription(`Invalid user given.`) |
76 |
] |
77 |
}); |
78 |
|
79 |
return; |
80 |
} |
81 |
|
82 |
console.log(user); |
83 |
|
84 |
await options.args.shift(); |
85 |
content = options.args.join(' '); |
86 |
} |
87 |
|
88 |
await History.create(user.id, msg.guild!, 'note', msg.member!.user.id, null, async (data2) => { |
89 |
await note(client, user, content as string, msg); |
90 |
}); |
91 |
|
92 |
await msg.reply({ |
93 |
embeds: [ |
94 |
new MessageEmbed() |
95 |
.setDescription(`A note has been added for ${user.user.tag}`) // TODO |
96 |
] |
97 |
}); |
98 |
} |
99 |
} |