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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 51 by rakin, Mon Jul 29 17:28:23 2024 UTC revision 344 by rakin, Mon Jul 29 17:29:40 2024 UTC
# Line 1  Line 1 
1  import { BanOptions, CommandInteraction, GuildMember, Interaction, Message, User } from 'discord.js';  import { CommandInteraction, ContextMenuInteraction, GuildMember, Message, Permissions, 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';
5  import InteractionOptions from '../../types/InteractionOptions';  import InteractionOptions from '../../types/InteractionOptions';
6  import MessageEmbed from '../../client/MessageEmbed';  import MessageEmbed from '../../client/MessageEmbed';
 import getUser from '../../utils/getUser';  
7  import getMember from '../../utils/getMember';  import getMember from '../../utils/getMember';
8  import History from '../../automod/History';  import Punishment from '../../models/Punishment';
9    import PunishmentType from '../../types/PunishmentType';
10    import { hasPermission, shouldNotModerate } from '../../utils/util';
11    
12  export default class KickCommand extends BaseCommand {  export default class KickCommand extends BaseCommand {
13      supportsInteractions: boolean = true;      supportsInteractions: boolean = true;
14        supportsContextMenu: boolean = true;
15        
16        permissions = [Permissions.FLAGS.KICK_MEMBERS];
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: [
# Line 32  export default class KickCommand extends Line 36  export default class KickCommand extends
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({
# Line 82  export default class KickCommand extends Line 86  export default class KickCommand extends
86          }          }
87    
88          try {          try {
89              if (!user.kickable)              if (!(await hasPermission(client, user, 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);
97              await History.create(user.id, msg.guild!, 'kick', msg.member!.user.id, typeof reason === 'undefined' ? null : reason);  
98                await Punishment.create({
99                    type: PunishmentType.KICK,
100                    user_id: user.id,
101                    guild_id: msg.guild!.id,
102                    mod_id: msg.member!.user.id,
103                    mod_tag: (msg.member!.user as User).tag,
104                    reason,
105                    createdAt: new Date()
106                });
107    
108                // await History.create(user.id, msg.guild!, 'kick', msg.member!.user.id, typeof reason === 'undefined' ? null : reason);
109          }          }
110          catch (e) {          catch (e) {
111              await msg.reply({              await msg.reply({
# Line 121  export default class KickCommand extends Line 140  export default class KickCommand extends
140              ]              ]
141          });          });
142      }      }
 }  
143    }

Legend:
Removed from v.51  
changed lines
  Added in v.344

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26