1 |
rakin |
51 |
import { BanOptions, CommandInteraction, 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 getMember from '../../utils/getMember'; |
9 |
|
|
import History from '../../automod/History'; |
10 |
|
|
|
11 |
|
|
export default class KickCommand extends BaseCommand { |
12 |
|
|
supportsInteractions: boolean = true; |
13 |
|
|
|
14 |
|
|
constructor() { |
15 |
|
|
super('kick', 'moderation', []); |
16 |
|
|
} |
17 |
|
|
|
18 |
|
|
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
19 |
|
|
if (!options.isInteraction && typeof options.args[0] === 'undefined') { |
20 |
|
|
await msg.reply({ |
21 |
|
|
embeds: [ |
22 |
|
|
new MessageEmbed() |
23 |
|
|
.setColor('#f14a60') |
24 |
|
|
.setDescription(`This command requires at least one argument.`) |
25 |
|
|
] |
26 |
|
|
}); |
27 |
|
|
|
28 |
|
|
return; |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
let user: GuildMember; |
32 |
|
|
let reason: string | undefined; |
33 |
|
|
|
34 |
|
|
if (options.isInteraction) { |
35 |
|
|
user = await <GuildMember> options.options.getMember('member'); |
36 |
|
|
|
37 |
|
|
if (!user) { |
38 |
|
|
await msg.reply({ |
39 |
|
|
embeds: [ |
40 |
|
|
new MessageEmbed() |
41 |
|
|
.setColor('#f14a60') |
42 |
|
|
.setDescription("Invalid user given.") |
43 |
|
|
] |
44 |
|
|
}); |
45 |
|
|
|
46 |
|
|
return; |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
if (options.options.getString('reason')) { |
50 |
|
|
reason = await <string> options.options.getString('reason'); |
51 |
|
|
} |
52 |
|
|
} |
53 |
|
|
else { |
54 |
|
|
try { |
55 |
|
|
const user2 = await getMember((msg as Message), options); |
56 |
|
|
|
57 |
|
|
if (!user2) { |
58 |
|
|
throw new Error('Invalid user'); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
user = user2; |
62 |
|
|
} |
63 |
|
|
catch (e) { |
64 |
|
|
await msg.reply({ |
65 |
|
|
embeds: [ |
66 |
|
|
new MessageEmbed() |
67 |
|
|
.setColor('#f14a60') |
68 |
|
|
.setDescription(`Invalid user given.`) |
69 |
|
|
] |
70 |
|
|
}); |
71 |
|
|
|
72 |
|
|
return; |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
console.log(user); |
76 |
|
|
|
77 |
|
|
if (options.args[1]) { |
78 |
|
|
const args = [...options.args]; |
79 |
|
|
args.shift(); |
80 |
|
|
reason = await args.join(' '); |
81 |
|
|
} |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
try { |
85 |
|
|
if (!user.kickable) |
86 |
|
|
throw new Error('User not kickable'); |
87 |
|
|
|
88 |
|
|
await user.kick(reason); |
89 |
|
|
await History.create(user.id, msg.guild!, 'kick', msg.member!.user.id, typeof reason === 'undefined' ? null : reason); |
90 |
|
|
} |
91 |
|
|
catch (e) { |
92 |
|
|
await msg.reply({ |
93 |
|
|
embeds: [ |
94 |
|
|
new MessageEmbed() |
95 |
|
|
.setColor('#f14a60') |
96 |
|
|
.setDescription("Failed to kick this user. Maybe missing permisions or I'm not allowed to kick this user?") |
97 |
|
|
] |
98 |
|
|
}); |
99 |
|
|
|
100 |
|
|
return; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
await msg.reply({ |
104 |
|
|
embeds: [ |
105 |
|
|
new MessageEmbed() |
106 |
|
|
.setAuthor({ |
107 |
|
|
name: user.user.tag, |
108 |
|
|
iconURL: user.user.displayAvatarURL(), |
109 |
|
|
}) |
110 |
|
|
.setDescription(user.user.tag + " has been kicked from this server.") |
111 |
|
|
.addFields([ |
112 |
|
|
{ |
113 |
|
|
name: "Kicked by", |
114 |
|
|
value: (msg.member!.user as User).tag |
115 |
|
|
}, |
116 |
|
|
{ |
117 |
|
|
name: "Reason", |
118 |
|
|
value: reason === undefined ? "*No reason provided*" : reason |
119 |
|
|
} |
120 |
|
|
]) |
121 |
|
|
] |
122 |
|
|
}); |
123 |
|
|
} |
124 |
|
|
} |