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

Contents of /trunk/src/commands/moderation/UnbanCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 341 - (show annotations)
Mon Jul 29 17:29:38 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 3332 byte(s)
refactor: removing using the old history manager
1 import { BanOptions, CommandInteraction, Guild, GuildMember, Interaction, Message, User, Permissions } 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 Punishment from '../../models/Punishment';
9 import PunishmentType from '../../types/PunishmentType';
10
11 export default class UnbanCommand extends BaseCommand {
12 supportsInteractions: boolean = true;
13 permissions = [Permissions.FLAGS.BAN_MEMBERS];
14
15 constructor() {
16 super('unban', 'moderation', []);
17 }
18
19 async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
20 if (!options.isInteraction && typeof options.args[0] === 'undefined') {
21 await msg.reply({
22 embeds: [
23 new MessageEmbed()
24 .setColor('#f14a60')
25 .setDescription(`This command requires at least one argument.`)
26 ]
27 });
28
29 return;
30 }
31
32 let user: User;
33
34 if (options.isInteraction) {
35 user = await <User> options.options.getUser('user');
36
37 if (!user) {
38 await msg.reply({
39 embeds: [
40 new MessageEmbed()
41 .setColor('#f14a60')
42 .setDescription("Invalid user given.")
43 ]
44 });
45
46 return;
47 }
48 }
49 else {
50 try {
51 const user2 = await getUser(client, (msg as Message), options);
52
53 if (!user2) {
54 throw new Error('Invalid user');
55 }
56
57 user = user2;
58 }
59 catch (e) {
60 await msg.reply({
61 embeds: [
62 new MessageEmbed()
63 .setColor('#f14a60')
64 .setDescription(`Invalid user given.`)
65 ]
66 });
67
68 return;
69 }
70
71 console.log(user);
72 }
73
74 try {
75 await msg.guild?.bans.remove(user);
76
77 await Punishment.create({
78 type: PunishmentType.UNBAN,
79 user_id: user.id,
80 guild_id: msg.guild!.id,
81 mod_id: msg.member!.user.id,
82 mod_tag: (msg.member!.user as User).tag,
83 createdAt: new Date()
84 });
85 }
86 catch (e) {
87 console.log(e);
88 }
89
90 await msg.reply({
91 embeds: [
92 new MessageEmbed()
93 .setAuthor({
94 name: user.tag,
95 iconURL: user.displayAvatarURL(),
96 })
97 .setDescription(user.tag + " has been unbanned.")
98 .addFields([
99 {
100 name: "Unbanned by",
101 value: (msg.member!.user as User).tag
102 },
103 ])
104 ]
105 });
106 }
107 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26