/[sudobot]/branches/2.x/src/commands/moderation/UnbanCommand.ts
ViewVC logotype

Contents of /branches/2.x/src/commands/moderation/UnbanCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26