1 |
rakin |
51 |
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 |
rakin |
86 |
import PunishmentType from '../../types/PunishmentType'; |
13 |
|
|
|
14 |
rakin |
102 |
export async function unmute(client: DiscordClient, user: GuildMember, d: User) { |
15 |
rakin |
51 |
try { |
16 |
rakin |
102 |
await History.create(user.id, user.guild!, 'unmute', d.id, null); |
17 |
rakin |
51 |
|
18 |
rakin |
102 |
const role = await user.guild!.roles.fetch(client.config.get('mute_role')); |
19 |
rakin |
51 |
await user.roles.remove(role!); |
20 |
|
|
|
21 |
rakin |
86 |
const { default: Punishment } = await import('../../models/Punishment'); |
22 |
|
|
|
23 |
rakin |
102 |
const { getTimeouts, clearTimeoutv2 } = await import('../../utils/setTimeout'); |
24 |
|
|
|
25 |
|
|
const timeouts = getTimeouts(); |
26 |
|
|
|
27 |
|
|
for (const timeout of timeouts.values()) { |
28 |
|
|
if (timeout.row.params) { |
29 |
|
|
try { |
30 |
|
|
const json = JSON.parse(timeout.row.params); |
31 |
|
|
|
32 |
|
|
if (json) { |
33 |
|
|
if (json[1] === user.id) { |
34 |
|
|
await clearTimeoutv2(timeout); |
35 |
|
|
} |
36 |
|
|
} |
37 |
|
|
} |
38 |
|
|
catch (e) { |
39 |
|
|
console.log(e); |
40 |
|
|
} |
41 |
|
|
} |
42 |
|
|
} |
43 |
|
|
|
44 |
rakin |
86 |
await Punishment.create({ |
45 |
|
|
type: PunishmentType.UNMUTE, |
46 |
|
|
user_id: user.id, |
47 |
rakin |
102 |
guild_id: user.guild!.id, |
48 |
rakin |
86 |
mod_id: d.id, |
49 |
|
|
mod_tag: d.tag, |
50 |
|
|
}); |
51 |
|
|
|
52 |
rakin |
51 |
await user.send({ |
53 |
|
|
embeds: [ |
54 |
|
|
new MessageEmbed() |
55 |
|
|
.setAuthor({ |
56 |
rakin |
102 |
iconURL: <string> user.guild!.iconURL(), |
57 |
|
|
name: `\tYou have been unmuted in ${user.guild!.name}` |
58 |
rakin |
51 |
}) |
59 |
|
|
] |
60 |
|
|
}); |
61 |
|
|
|
62 |
|
|
await client.logger.logUnmute(user, d); |
63 |
|
|
} |
64 |
|
|
catch (e) { |
65 |
|
|
console.log(e); |
66 |
|
|
} |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
export default class UnmuteCommand extends BaseCommand { |
70 |
|
|
supportsInteractions: boolean = true; |
71 |
|
|
|
72 |
|
|
constructor() { |
73 |
|
|
super('unmute', 'moderation', []); |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
77 |
|
|
if (!options.isInteraction && typeof options.args[0] === 'undefined') { |
78 |
|
|
await msg.reply({ |
79 |
|
|
embeds: [ |
80 |
|
|
new MessageEmbed() |
81 |
|
|
.setColor('#f14a60') |
82 |
|
|
.setDescription(`This command requires at least one argument.`) |
83 |
|
|
] |
84 |
|
|
}); |
85 |
|
|
|
86 |
|
|
return; |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
let user: GuildMember; |
90 |
|
|
|
91 |
|
|
if (options.isInteraction) { |
92 |
|
|
user = await <GuildMember> options.options.getMember('member'); |
93 |
|
|
|
94 |
|
|
if (!user) { |
95 |
|
|
await msg.reply({ |
96 |
|
|
embeds: [ |
97 |
|
|
new MessageEmbed() |
98 |
|
|
.setColor('#f14a60') |
99 |
|
|
.setDescription("Invalid user given.") |
100 |
|
|
] |
101 |
|
|
}); |
102 |
|
|
|
103 |
|
|
return; |
104 |
|
|
} |
105 |
|
|
} |
106 |
|
|
else { |
107 |
|
|
try { |
108 |
|
|
const user2 = await getMember((msg as Message), options); |
109 |
|
|
|
110 |
|
|
if (!user2) { |
111 |
|
|
throw new Error('Invalid user'); |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
user = user2; |
115 |
|
|
} |
116 |
|
|
catch (e) { |
117 |
|
|
await msg.reply({ |
118 |
|
|
embeds: [ |
119 |
|
|
new MessageEmbed() |
120 |
|
|
.setColor('#f14a60') |
121 |
|
|
.setDescription(`Invalid user given.`) |
122 |
|
|
] |
123 |
|
|
}); |
124 |
|
|
|
125 |
|
|
return; |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
console.log(user); |
129 |
|
|
} |
130 |
|
|
|
131 |
rakin |
102 |
await unmute(client, user, msg.member!.user as User); |
132 |
rakin |
51 |
|
133 |
|
|
await msg.reply({ |
134 |
|
|
embeds: [ |
135 |
|
|
new MessageEmbed() |
136 |
|
|
.setAuthor({ |
137 |
|
|
name: user.user.tag, |
138 |
|
|
iconURL: user.user.displayAvatarURL(), |
139 |
|
|
}) |
140 |
|
|
.setDescription(user.user.tag + " has been unmuted.") |
141 |
|
|
.addFields([ |
142 |
|
|
{ |
143 |
|
|
name: "Unmuted by", |
144 |
|
|
value: (msg.member!.user as User).tag |
145 |
|
|
}, |
146 |
|
|
]) |
147 |
|
|
] |
148 |
|
|
}); |
149 |
|
|
} |
150 |
|
|
} |