1 |
import { BanOptions, CommandInteraction, Guild, GuildMember, Interaction, Message, User } from 'discord.js'; |
import { BanOptions, CommandInteraction, Guild, GuildMember, Interaction, Message, Permissions, User } from 'discord.js'; |
2 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
import DiscordClient from '../../client/Client'; |
import DiscordClient from '../../client/Client'; |
4 |
import CommandOptions from '../../types/CommandOptions'; |
import CommandOptions from '../../types/CommandOptions'; |
11 |
|
|
12 |
import PunishmentType from '../../types/PunishmentType'; |
import PunishmentType from '../../types/PunishmentType'; |
13 |
|
|
14 |
export async function unmute(client: DiscordClient, user: GuildMember, msg: Message | CommandInteraction, d: User) { |
export async function unmute(client: DiscordClient, user: GuildMember, d: User) { |
15 |
try { |
try { |
16 |
await History.create(user.id, msg.guild!, 'unmute', msg.member!.user.id, null); |
await History.create(user.id, user.guild!, 'unmute', d.id, null); |
17 |
|
|
18 |
const role = await msg.guild!.roles.fetch(client.config.get('mute_role')); |
const role = await user.guild!.roles.fetch(client.config.props[user.guild.id].mute_role); |
19 |
await user.roles.remove(role!); |
try { |
20 |
|
await user.roles.remove(role!, 'Unmuting user'); |
21 |
|
} |
22 |
|
catch (e) { |
23 |
|
console.log(e); |
24 |
|
} |
25 |
|
|
26 |
const { default: Punishment } = await import('../../models/Punishment'); |
const { default: Punishment } = await import('../../models/Punishment'); |
27 |
|
|
28 |
|
const { getTimeouts, clearTimeoutv2 } = await import('../../utils/setTimeout'); |
29 |
|
|
30 |
|
const { default: Hardmute } = await import("../../models/Hardmute"); |
31 |
|
const { default: MuteRecord } = await import("../../models/MuteRecord"); |
32 |
|
|
33 |
|
const hardmute = await Hardmute.findOne({ |
34 |
|
where: { |
35 |
|
user_id: user.id, |
36 |
|
guild_id: user.guild.id, |
37 |
|
}, |
38 |
|
order: [ |
39 |
|
['id', 'DESC'] |
40 |
|
] |
41 |
|
}); |
42 |
|
|
43 |
|
if (hardmute) { |
44 |
|
for await (const roleID of hardmute.get().roles) { |
45 |
|
try { |
46 |
|
const role = await user.guild.roles.fetch(roleID); |
47 |
|
|
48 |
|
if (role) { |
49 |
|
await user.roles.add(role, 'Adding the roles which were removed due to hardmute'); |
50 |
|
} |
51 |
|
} |
52 |
|
catch (e) { |
53 |
|
console.log(e); |
54 |
|
} |
55 |
|
} |
56 |
|
|
57 |
|
await hardmute.destroy(); |
58 |
|
} |
59 |
|
|
60 |
|
const timeouts = getTimeouts(); |
61 |
|
|
62 |
|
for (const timeout of timeouts.values()) { |
63 |
|
if (timeout.row.params) { |
64 |
|
try { |
65 |
|
const json = JSON.parse(timeout.row.params); |
66 |
|
|
67 |
|
if (json) { |
68 |
|
if (json[1] === user.id && timeout.row.filePath.endsWith('unmute-job')) { |
69 |
|
await clearTimeoutv2(timeout); |
70 |
|
} |
71 |
|
} |
72 |
|
} |
73 |
|
catch (e) { |
74 |
|
console.log(e); |
75 |
|
} |
76 |
|
} |
77 |
|
} |
78 |
|
|
79 |
await Punishment.create({ |
await Punishment.create({ |
80 |
type: PunishmentType.UNMUTE, |
type: PunishmentType.UNMUTE, |
81 |
user_id: user.id, |
user_id: user.id, |
82 |
guild_id: msg.guild!.id, |
guild_id: user.guild!.id, |
83 |
mod_id: d.id, |
mod_id: d.id, |
84 |
mod_tag: d.tag, |
mod_tag: d.tag, |
85 |
}); |
}); |
86 |
|
|
87 |
await user.send({ |
const muteRecord = await MuteRecord.findOne({ |
88 |
embeds: [ |
where: { |
89 |
new MessageEmbed() |
user_id: user.user.id, |
90 |
.setAuthor({ |
guild_id: user.guild.id |
91 |
iconURL: <string> msg.guild!.iconURL(), |
} |
|
name: `\tYou have been unmuted in ${msg.guild!.name}` |
|
|
}) |
|
|
] |
|
92 |
}); |
}); |
93 |
|
|
94 |
|
if (muteRecord) { |
95 |
|
await muteRecord.destroy(); |
96 |
|
} |
97 |
|
|
98 |
|
try { |
99 |
|
await user.send({ |
100 |
|
embeds: [ |
101 |
|
new MessageEmbed() |
102 |
|
.setAuthor({ |
103 |
|
iconURL: <string> user.guild!.iconURL(), |
104 |
|
name: `\tYou have been unmuted in ${user.guild!.name}` |
105 |
|
}) |
106 |
|
] |
107 |
|
}); |
108 |
|
} |
109 |
|
catch (e) { |
110 |
|
console.log(e); |
111 |
|
} |
112 |
|
|
113 |
await client.logger.logUnmute(user, d); |
await client.logger.logUnmute(user, d); |
114 |
} |
} |
115 |
catch (e) { |
catch (e) { |
119 |
|
|
120 |
export default class UnmuteCommand extends BaseCommand { |
export default class UnmuteCommand extends BaseCommand { |
121 |
supportsInteractions: boolean = true; |
supportsInteractions: boolean = true; |
122 |
|
permissions = [Permissions.FLAGS.MODERATE_MEMBERS]; |
123 |
|
|
124 |
constructor() { |
constructor() { |
125 |
super('unmute', 'moderation', []); |
super('unmute', 'moderation', []); |
138 |
return; |
return; |
139 |
} |
} |
140 |
|
|
141 |
|
if (msg instanceof CommandInteraction) |
142 |
|
await msg.deferReply(); |
143 |
|
|
144 |
let user: GuildMember; |
let user: GuildMember; |
145 |
|
|
146 |
if (options.isInteraction) { |
if (options.isInteraction) { |
147 |
user = await <GuildMember> options.options.getMember('member'); |
user = await <GuildMember> options.options.getMember('member'); |
148 |
|
|
149 |
if (!user) { |
if (!user) { |
150 |
await msg.reply({ |
await this.deferReply(msg, { |
151 |
embeds: [ |
embeds: [ |
152 |
new MessageEmbed() |
new MessageEmbed() |
153 |
.setColor('#f14a60') |
.setColor('#f14a60') |
169 |
user = user2; |
user = user2; |
170 |
} |
} |
171 |
catch (e) { |
catch (e) { |
172 |
await msg.reply({ |
await this.deferReply(msg, { |
173 |
embeds: [ |
embeds: [ |
174 |
new MessageEmbed() |
new MessageEmbed() |
175 |
.setColor('#f14a60') |
.setColor('#f14a60') |
183 |
console.log(user); |
console.log(user); |
184 |
} |
} |
185 |
|
|
186 |
await unmute(client, user, msg, msg.member!.user as User); |
await unmute(client, user, msg.member!.user as User); |
187 |
|
|
188 |
await msg.reply({ |
await this.deferReply(msg, { |
189 |
embeds: [ |
embeds: [ |
190 |
new MessageEmbed() |
new MessageEmbed() |
191 |
.setAuthor({ |
.setAuthor({ |
202 |
] |
] |
203 |
}); |
}); |
204 |
} |
} |
|
} |
|
205 |
|
} |