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'; |
9 |
import History from '../../automod/History'; |
import History from '../../automod/History'; |
10 |
import Punishment from '../../models/Punishment'; |
import Punishment from '../../models/Punishment'; |
11 |
import PunishmentType from '../../types/PunishmentType'; |
import PunishmentType from '../../types/PunishmentType'; |
12 |
|
import { hasPermission, shouldNotModerate } from '../../utils/util'; |
13 |
|
|
14 |
export default class KickCommand extends BaseCommand { |
export default class KickCommand extends BaseCommand { |
15 |
supportsInteractions: boolean = true; |
supportsInteractions: boolean = true; |
16 |
|
supportsContextMenu: boolean = true; |
17 |
|
|
18 |
constructor() { |
constructor() { |
19 |
super('kick', 'moderation', []); |
super('kick', 'moderation', ['Kick']); |
20 |
} |
} |
21 |
|
|
22 |
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
async run(client: DiscordClient, msg: Message | CommandInteraction | ContextMenuInteraction, options: CommandOptions | InteractionOptions) { |
23 |
if (!options.isInteraction && typeof options.args[0] === 'undefined') { |
if (!options.isInteraction && typeof options.args[0] === 'undefined') { |
24 |
await msg.reply({ |
await msg.reply({ |
25 |
embeds: [ |
embeds: [ |
36 |
let reason: string | undefined; |
let reason: string | undefined; |
37 |
|
|
38 |
if (options.isInteraction) { |
if (options.isInteraction) { |
39 |
user = await <GuildMember> options.options.getMember('member'); |
user = await <GuildMember> (msg instanceof ContextMenuInteraction ? options.options.getMember('user') : options.options.getMember('member')); |
40 |
|
|
41 |
if (!user) { |
if (!user) { |
42 |
await msg.reply({ |
await msg.reply({ |
86 |
} |
} |
87 |
|
|
88 |
try { |
try { |
89 |
if (!user.kickable) |
if (!(await hasPermissions(client, member, msg, null, "You don't have permission to kick this user."))) { |
90 |
|
return; |
91 |
|
} |
92 |
|
|
93 |
|
if (!user.kickable || shouldNotModerate(client, user)) |
94 |
throw new Error('User not kickable'); |
throw new Error('User not kickable'); |
95 |
|
|
96 |
await user.kick(reason); |
await user.kick(reason); |
104 |
reason |
reason |
105 |
}); |
}); |
106 |
|
|
107 |
await History.create(user.id, msg.guild!, 'kick', msg.member!.user.id, typeof reason === 'undefined' ? null : reason); |
// await History.create(user.id, msg.guild!, 'kick', msg.member!.user.id, typeof reason === 'undefined' ? null : reason); |
108 |
} |
} |
109 |
catch (e) { |
catch (e) { |
110 |
await msg.reply({ |
await msg.reply({ |
139 |
] |
] |
140 |
}); |
}); |
141 |
} |
} |
|
} |
|
142 |
|
} |