1 |
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 |
|
12 |
export default class UnbanCommand extends BaseCommand { |
13 |
supportsInteractions: boolean = true; |
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 |
await History.create(user.id, msg.guild!, 'unban', (msg.member!.user as User).id, null); |
77 |
} |
78 |
catch (e) { |
79 |
console.log(e); |
80 |
} |
81 |
|
82 |
await msg.reply({ |
83 |
embeds: [ |
84 |
new MessageEmbed() |
85 |
.setAuthor({ |
86 |
name: user.tag, |
87 |
iconURL: user.displayAvatarURL(), |
88 |
}) |
89 |
.setDescription(user.tag + " has been unbanned.") |
90 |
.addFields([ |
91 |
{ |
92 |
name: "Unbanned by", |
93 |
value: (msg.member!.user as User).tag |
94 |
}, |
95 |
]) |
96 |
] |
97 |
}); |
98 |
} |
99 |
} |