/[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 428 - (hide annotations)
Mon Jul 29 17:30:11 2024 UTC (8 months, 2 weeks ago) by rakin
File MIME type: application/typescript
File size: 4339 byte(s)
refactor: use new queue handler
1 rakin 393 /**
2     * This file is part of SudoBot.
3     *
4     * Copyright (C) 2021-2022 OSN Inc.
5     *
6     * SudoBot is free software; you can redistribute it and/or modify it
7     * under the terms of the GNU Affero General Public License as published by
8     * the Free Software Foundation, either version 3 of the License, or
9     * (at your option) any later version.
10     *
11     * SudoBot is distributed in the hope that it will be useful, but
12     * WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU Affero General Public License for more details.
15     *
16     * You should have received a copy of the GNU Affero General Public License
17     * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18     */
19    
20 rakin 344 import { CommandInteraction, Message, User, Permissions } from 'discord.js';
21 rakin 51 import BaseCommand from '../../utils/structures/BaseCommand';
22     import DiscordClient from '../../client/Client';
23     import CommandOptions from '../../types/CommandOptions';
24     import InteractionOptions from '../../types/InteractionOptions';
25     import MessageEmbed from '../../client/MessageEmbed';
26     import getUser from '../../utils/getUser';
27 rakin 86 import Punishment from '../../models/Punishment';
28     import PunishmentType from '../../types/PunishmentType';
29 rakin 428 import UnbanQueue from '../../queues/UnbanQueue';
30 rakin 51
31     export default class UnbanCommand extends BaseCommand {
32     supportsInteractions: boolean = true;
33 rakin 204 permissions = [Permissions.FLAGS.BAN_MEMBERS];
34 rakin 51
35     constructor() {
36     super('unban', 'moderation', []);
37     }
38    
39     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
40     if (!options.isInteraction && typeof options.args[0] === 'undefined') {
41     await msg.reply({
42     embeds: [
43     new MessageEmbed()
44     .setColor('#f14a60')
45     .setDescription(`This command requires at least one argument.`)
46     ]
47     });
48    
49     return;
50     }
51    
52     let user: User;
53    
54     if (options.isInteraction) {
55     user = await <User> options.options.getUser('user');
56    
57     if (!user) {
58     await msg.reply({
59     embeds: [
60     new MessageEmbed()
61     .setColor('#f14a60')
62     .setDescription("Invalid user given.")
63     ]
64     });
65    
66     return;
67     }
68     }
69     else {
70     try {
71     const user2 = await getUser(client, (msg as Message), options);
72    
73     if (!user2) {
74     throw new Error('Invalid user');
75     }
76    
77     user = user2;
78     }
79     catch (e) {
80     await msg.reply({
81     embeds: [
82     new MessageEmbed()
83     .setColor('#f14a60')
84     .setDescription(`Invalid user given.`)
85     ]
86     });
87    
88     return;
89     }
90    
91     console.log(user);
92     }
93    
94     try {
95 rakin 428 for await (const queue of client.queueManager.queues.values()) {
96     if (queue instanceof UnbanQueue && queue.data!.userID === user.id && queue.data!.guildID === msg.guild!.id) {
97     await queue.cancel();
98     }
99     }
100    
101 rakin 51 await msg.guild?.bans.remove(user);
102 rakin 86
103     await Punishment.create({
104     type: PunishmentType.UNBAN,
105     user_id: user.id,
106     guild_id: msg.guild!.id,
107     mod_id: msg.member!.user.id,
108     mod_tag: (msg.member!.user as User).tag,
109 rakin 336 createdAt: new Date()
110 rakin 86 });
111 rakin 51 }
112     catch (e) {
113     console.log(e);
114     }
115    
116     await msg.reply({
117     embeds: [
118     new MessageEmbed()
119     .setAuthor({
120     name: user.tag,
121     iconURL: user.displayAvatarURL(),
122     })
123     .setDescription(user.tag + " has been unbanned.")
124     .addFields([
125     {
126     name: "Unbanned by",
127     value: (msg.member!.user as User).tag
128     },
129     ])
130     ]
131     });
132     }
133     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26