/[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 336 - (show annotations)
Mon Jul 29 17:29:36 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 3547 byte(s)
refactor(moderation): use mongodb
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 createdAt: new Date()
87 });
88
89 await History.create(user.id, msg.guild!, 'unban', (msg.member!.user as User).id, null);
90 }
91 catch (e) {
92 console.log(e);
93 }
94
95 await msg.reply({
96 embeds: [
97 new MessageEmbed()
98 .setAuthor({
99 name: user.tag,
100 iconURL: user.displayAvatarURL(),
101 })
102 .setDescription(user.tag + " has been unbanned.")
103 .addFields([
104 {
105 name: "Unbanned by",
106 value: (msg.member!.user as User).tag
107 },
108 ])
109 ]
110 });
111 }
112 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26