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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26