/[sudobot]/trunk/src/commands/moderation/KickCommand.ts
ViewVC logotype

Contents of /trunk/src/commands/moderation/KickCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 153 - (show annotations)
Mon Jul 29 17:28:48 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 4674 byte(s)
Add Non-moderable role (#34)

* feat(utils): add shouldNotModerate() function

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26