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

Annotation of /trunk/src/commands/moderation/UnbanCommand.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: 3445 byte(s)
Updated the database system
1 rakin 51 import { BanOptions, CommandInteraction, Guild, 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 History from '../../automod/History';
9     import getMember from '../../utils/getMember';
10     import ms from 'ms';
11 rakin 86 import Punishment from '../../models/Punishment';
12     import PunishmentType from '../../types/PunishmentType';
13 rakin 51
14     export default class UnbanCommand extends BaseCommand {
15     supportsInteractions: boolean = true;
16    
17     constructor() {
18     super('unban', 'moderation', []);
19     }
20    
21     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
22     if (!options.isInteraction && typeof options.args[0] === 'undefined') {
23     await msg.reply({
24     embeds: [
25     new MessageEmbed()
26     .setColor('#f14a60')
27     .setDescription(`This command requires at least one argument.`)
28     ]
29     });
30    
31     return;
32     }
33    
34     let user: User;
35    
36     if (options.isInteraction) {
37     user = await <User> options.options.getUser('user');
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     else {
52     try {
53     const user2 = await getUser(client, (msg as Message), options);
54    
55     if (!user2) {
56     throw new Error('Invalid user');
57     }
58    
59     user = user2;
60     }
61     catch (e) {
62     await msg.reply({
63     embeds: [
64     new MessageEmbed()
65     .setColor('#f14a60')
66     .setDescription(`Invalid user given.`)
67     ]
68     });
69    
70     return;
71     }
72    
73     console.log(user);
74     }
75    
76     try {
77     await msg.guild?.bans.remove(user);
78 rakin 86
79     await Punishment.create({
80     type: PunishmentType.UNBAN,
81     user_id: user.id,
82     guild_id: msg.guild!.id,
83     mod_id: msg.member!.user.id,
84     mod_tag: (msg.member!.user as User).tag,
85     });
86    
87 rakin 51 await History.create(user.id, msg.guild!, 'unban', (msg.member!.user as User).id, null);
88     }
89     catch (e) {
90     console.log(e);
91     }
92    
93     await msg.reply({
94     embeds: [
95     new MessageEmbed()
96     .setAuthor({
97     name: user.tag,
98     iconURL: user.displayAvatarURL(),
99     })
100     .setDescription(user.tag + " has been unbanned.")
101     .addFields([
102     {
103     name: "Unbanned by",
104     value: (msg.member!.user as User).tag
105     },
106     ])
107     ]
108     });
109     }
110     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26