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 |
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 |
createdAt: new Date(), |
23 |
}); |
24 |
} |
25 |
|
26 |
export default class NoteCommand extends BaseCommand { |
27 |
supportsInteractions: boolean = true; |
28 |
|
29 |
constructor() { |
30 |
super('note', 'moderation', []); |
31 |
} |
32 |
|
33 |
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
34 |
if (!options.isInteraction && typeof options.args[1] === 'undefined') { |
35 |
await msg.reply({ |
36 |
embeds: [ |
37 |
new MessageEmbed() |
38 |
.setColor('#f14a60') |
39 |
.setDescription(`This command requires at least two arguments.`) |
40 |
] |
41 |
}); |
42 |
|
43 |
return; |
44 |
} |
45 |
|
46 |
let user: User; |
47 |
let content: string | undefined; |
48 |
|
49 |
if (options.isInteraction) { |
50 |
user = await <User> options.options.getUser('user'); |
51 |
|
52 |
if (!user) { |
53 |
await msg.reply({ |
54 |
embeds: [ |
55 |
new MessageEmbed() |
56 |
.setColor('#f14a60') |
57 |
.setDescription("Invalid user given.") |
58 |
] |
59 |
}); |
60 |
|
61 |
return; |
62 |
} |
63 |
|
64 |
content = <string> options.options.getString('note'); |
65 |
} |
66 |
else { |
67 |
try { |
68 |
const user2 = await getUser(client, (msg as Message), options); |
69 |
|
70 |
if (!user2) { |
71 |
throw new Error('Invalid user'); |
72 |
} |
73 |
|
74 |
user = user2; |
75 |
} |
76 |
catch (e) { |
77 |
await msg.reply({ |
78 |
embeds: [ |
79 |
new MessageEmbed() |
80 |
.setColor('#f14a60') |
81 |
.setDescription(`Invalid user given.`) |
82 |
] |
83 |
}); |
84 |
|
85 |
return; |
86 |
} |
87 |
|
88 |
console.log(user); |
89 |
|
90 |
await options.args.shift(); |
91 |
content = options.args.join(' '); |
92 |
} |
93 |
|
94 |
const n = await note(user, content as string, msg); |
95 |
|
96 |
await msg.reply({ |
97 |
embeds: [ |
98 |
new MessageEmbed() |
99 |
.setDescription(`${(await fetchEmoji('check'))?.toString()} A note has been added for ${user.tag}`) |
100 |
.setFooter({ |
101 |
text: `ID: ${n.id}` |
102 |
}) |
103 |
] |
104 |
}); |
105 |
} |
106 |
} |