/[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 86 by rakin, Mon Jul 29 17:28:32 2024 UTC revision 206 by rakin, Mon Jul 29 17:29:01 2024 UTC
# Line 1  Line 1 
1  import { BanOptions, CommandInteraction, GuildMember, Interaction, Message, User } from 'discord.js';  import { BanOptions, CommandInteraction, ContextMenuInteraction, GuildMember, Interaction, 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';
# Line 9  import getMember from '../../utils/getMe Line 9  import getMember from '../../utils/getMe
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        permissions = [Permissions.FLAGS.KICK_MEMBERS];
19    
20      constructor() {      constructor() {
21          super('kick', 'moderation', []);          super('kick', 'moderation', ['Kick']);
22      }      }
23    
24      async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {      async run(client: DiscordClient, msg: Message | CommandInteraction | ContextMenuInteraction, options: CommandOptions | InteractionOptions) {
25          if (!options.isInteraction && typeof options.args[0] === 'undefined') {          if (!options.isInteraction && typeof options.args[0] === 'undefined') {
26              await msg.reply({              await msg.reply({
27                  embeds: [                  embeds: [
# Line 34  export default class KickCommand extends Line 38  export default class KickCommand extends
38          let reason: string | undefined;          let reason: string | undefined;
39    
40          if (options.isInteraction) {          if (options.isInteraction) {
41              user = await <GuildMember> options.options.getMember('member');              user = await <GuildMember> (msg instanceof ContextMenuInteraction ? options.options.getMember('user') : options.options.getMember('member'));
42    
43              if (!user) {              if (!user) {
44                  await msg.reply({                  await msg.reply({
# Line 84  export default class KickCommand extends Line 88  export default class KickCommand extends
88          }          }
89    
90          try {          try {
91              if (!user.kickable)              if (!(await hasPermission(client, user, msg, null, "You don't have permission to kick this user."))) {
92                    return;
93                }
94                
95                if (!user.kickable || shouldNotModerate(client, user))
96                  throw new Error('User not kickable');                  throw new Error('User not kickable');
97                            
98              await user.kick(reason);              await user.kick(reason);
# Line 98  export default class KickCommand extends Line 106  export default class KickCommand extends
106                  reason                  reason
107              });              });
108    
109              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);
110          }          }
111          catch (e) {          catch (e) {
112              await msg.reply({              await msg.reply({
# Line 133  export default class KickCommand extends Line 141  export default class KickCommand extends
141              ]              ]
142          });          });
143      }      }
 }  
144    }

Legend:
Removed from v.86  
changed lines
  Added in v.206

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26