1 |
import { BanOptions, CommandInteraction, GuildMember, Interaction, Message, User } from 'discord.js'; |
import { BanOptions, CommandInteraction, ContextMenuInteraction, GuildMember, Interaction, 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'; |
7 |
import getUser from '../../utils/getUser'; |
import getUser from '../../utils/getUser'; |
8 |
import getMember from '../../utils/getMember'; |
import getMember from '../../utils/getMember'; |
9 |
import History from '../../automod/History'; |
import History from '../../automod/History'; |
10 |
|
import Punishment from '../../models/Punishment'; |
11 |
|
import PunishmentType from '../../types/PunishmentType'; |
12 |
|
|
13 |
export default class BeanCommand extends BaseCommand { |
export default class BeanCommand extends BaseCommand { |
14 |
supportsInteractions: boolean = true; |
supportsInteractions: boolean = true; |
15 |
|
supportsContextMenu: boolean = true; |
16 |
|
|
17 |
constructor() { |
constructor() { |
18 |
super('bean', 'moderation', []); |
super('bean', 'moderation', ['Bean']); |
19 |
} |
} |
20 |
|
|
21 |
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
async run(client: DiscordClient, msg: Message | CommandInteraction | ContextMenuInteraction, options: CommandOptions | InteractionOptions) { |
22 |
if (!options.isInteraction && typeof options.args[0] === 'undefined') { |
if (!options.isInteraction && typeof options.args[0] === 'undefined') { |
23 |
await msg.reply({ |
await msg.reply({ |
24 |
embeds: [ |
embeds: [ |
35 |
let reason: string | undefined; |
let reason: string | undefined; |
36 |
|
|
37 |
if (options.isInteraction) { |
if (options.isInteraction) { |
38 |
user = await <GuildMember> options.options.getMember('member'); |
user = await <GuildMember> (msg instanceof ContextMenuInteraction ? options.options.getMember('user') : options.options.getMember('member')); |
39 |
|
|
40 |
if (!user) { |
if (!user) { |
41 |
await msg.reply({ |
await msg.reply({ |
42 |
embeds: [ |
embeds: [ |
43 |
new MessageEmbed() |
new MessageEmbed() |
44 |
.setColor('#f14a60') |
.setColor('#f14a60') |
45 |
.setDescription("Invalid user given.") |
.setDescription("Invalid member given.") |
46 |
] |
] |
47 |
}); |
}); |
48 |
|
|
85 |
} |
} |
86 |
|
|
87 |
try { |
try { |
88 |
|
await Punishment.create({ |
89 |
|
type: PunishmentType.BEAN, |
90 |
|
user_id: user.id, |
91 |
|
guild_id: msg.guild!.id, |
92 |
|
mod_id: msg.member!.user.id, |
93 |
|
mod_tag: (msg.member!.user as User).tag, |
94 |
|
reason |
95 |
|
}); |
96 |
|
|
97 |
await History.create(user.id, msg.guild!, 'bean', msg.member!.user.id, typeof reason === 'undefined' ? null : reason); |
await History.create(user.id, msg.guild!, 'bean', msg.member!.user.id, typeof reason === 'undefined' ? null : reason); |
98 |
|
|
99 |
await user.send({ |
await user.send({ |