1 |
import { BanOptions, CommandInteraction, Guild, GuildMember, Interaction, Message, User } from 'discord.js'; |
import { CommandInteraction, GuildMember, Message, User } from 'discord.js'; |
2 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
import DiscordClient from '../../client/Client'; |
import DiscordClient from '../../client/Client'; |
4 |
import CommandOptions from '../../types/CommandOptions'; |
import CommandOptions from '../../types/CommandOptions'; |
5 |
import InteractionOptions from '../../types/InteractionOptions'; |
import InteractionOptions from '../../types/InteractionOptions'; |
6 |
import MessageEmbed from '../../client/MessageEmbed'; |
import MessageEmbed from '../../client/MessageEmbed'; |
7 |
import getUser from '../../utils/getUser'; |
import getUser from '../../utils/getUser'; |
8 |
import History from '../../automod/History'; |
import { fetchEmoji } from '../../utils/Emoji'; |
9 |
import getMember from '../../utils/getMember'; |
|
10 |
import ms from 'ms'; |
export async function note(user: GuildMember | User, content: string, msg: Message | CommandInteraction) { |
11 |
|
const { default: Note } = await import('../../models/Note'); |
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) => { |
return await Note.create({ |
14 |
if (err) { |
content, |
15 |
console.log(err); |
author: msg.member!.user.id, |
16 |
} |
mod_tag: (msg.member!.user as User).tag, |
17 |
|
user_id: user.id, |
18 |
|
guild_id: msg.guild!.id, |
19 |
|
createdAt: new Date(), |
20 |
}); |
}); |
21 |
} |
} |
22 |
|
|
40 |
return; |
return; |
41 |
} |
} |
42 |
|
|
43 |
let user: GuildMember; |
let user: User; |
44 |
let content: string | undefined; |
let content: string | undefined; |
45 |
|
|
46 |
if (options.isInteraction) { |
if (options.isInteraction) { |
47 |
user = await <GuildMember> options.options.getMember('member'); |
user = await <User> options.options.getUser('user'); |
48 |
|
|
49 |
if (!user) { |
if (!user) { |
50 |
await msg.reply({ |
await msg.reply({ |
62 |
} |
} |
63 |
else { |
else { |
64 |
try { |
try { |
65 |
const user2 = await getMember((msg as Message), options); |
const user2 = await getUser(client, (msg as Message), options); |
66 |
|
|
67 |
if (!user2) { |
if (!user2) { |
68 |
throw new Error('Invalid user'); |
throw new Error('Invalid user'); |
88 |
content = options.args.join(' '); |
content = options.args.join(' '); |
89 |
} |
} |
90 |
|
|
91 |
await History.create(user.id, msg.guild!, 'note', msg.member!.user.id, null, async (data2) => { |
const n = await note(user, content as string, msg); |
|
await note(client, user, content as string, msg); |
|
|
}); |
|
92 |
|
|
93 |
await msg.reply({ |
await msg.reply({ |
94 |
embeds: [ |
embeds: [ |
95 |
new MessageEmbed() |
new MessageEmbed() |
96 |
.setDescription(`A note has been added for ${user.user.tag}`) // TODO |
.setDescription(`${(await fetchEmoji('check'))?.toString()} A note has been added for ${user.tag}`) |
97 |
|
.setFooter({ |
98 |
|
text: `ID: ${n.id}` |
99 |
|
}) |
100 |
] |
] |
101 |
}); |
}); |
102 |
} |
} |