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