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'; |
5 |
import InteractionOptions from '../../types/InteractionOptions'; |
import InteractionOptions from '../../types/InteractionOptions'; |
6 |
import MessageEmbed from '../../client/MessageEmbed'; |
import MessageEmbed from '../../client/MessageEmbed'; |
|
import getUser from '../../utils/getUser'; |
|
|
import History from '../../automod/History'; |
|
7 |
import getMember from '../../utils/getMember'; |
import getMember from '../../utils/getMember'; |
|
import ms from 'ms'; |
|
8 |
|
|
9 |
import PunishmentType from '../../types/PunishmentType'; |
import PunishmentType from '../../types/PunishmentType'; |
10 |
|
|
11 |
export async function unmute(client: DiscordClient, user: GuildMember, d: User) { |
export async function unmute(client: DiscordClient, user: GuildMember, d: User) { |
12 |
try { |
try { |
|
await History.create(user.id, user.guild!, 'unmute', d.id, null); |
|
|
|
|
13 |
const role = await user.guild!.roles.fetch(client.config.props[user.guild.id].mute_role); |
const role = await user.guild!.roles.fetch(client.config.props[user.guild.id].mute_role); |
14 |
await user.roles.remove(role!, 'Unmuting user'); |
try { |
15 |
|
await user.roles.remove(role!, 'Unmuting user'); |
16 |
|
} |
17 |
|
catch (e) { |
18 |
|
console.log(e); |
19 |
|
} |
20 |
|
|
21 |
const { default: Punishment } = await import('../../models/Punishment'); |
const { default: Punishment } = await import('../../models/Punishment'); |
22 |
|
|
23 |
const { getTimeouts, clearTimeoutv2 } = await import('../../utils/setTimeout'); |
const { getTimeouts, clearTimeoutv2 } = await import('../../utils/setTimeout'); |
24 |
|
|
25 |
const { default: Hardmute } = await import("../../models/Hardmute"); |
const { default: Hardmute } = await import("../../models/Hardmute"); |
26 |
|
const { default: MuteRecord } = await import("../../models/MuteRecord"); |
27 |
|
|
28 |
const hardmute = await Hardmute.findOne({ |
const hardmute = await Hardmute.findOne({ |
29 |
where: { |
user_id: user.id, |
30 |
user_id: user.id, |
guild_id: user.guild.id |
|
guild_id: user.guild.id, |
|
|
}, |
|
|
order: [ |
|
|
['id', 'DESC'] |
|
|
] |
|
31 |
}); |
}); |
32 |
|
|
33 |
if (hardmute) { |
if (hardmute) { |
34 |
for await (const roleID of hardmute.get().roles) { |
for await (const roleID of hardmute.roles) { |
35 |
try { |
try { |
36 |
const role = await user.guild.roles.fetch(roleID); |
const role = await user.guild.roles.fetch(roleID); |
37 |
|
|
44 |
} |
} |
45 |
} |
} |
46 |
|
|
47 |
await hardmute.destroy(); |
await hardmute.delete(); |
48 |
} |
} |
49 |
|
|
50 |
const timeouts = getTimeouts(); |
const timeouts = getTimeouts(); |
72 |
guild_id: user.guild!.id, |
guild_id: user.guild!.id, |
73 |
mod_id: d.id, |
mod_id: d.id, |
74 |
mod_tag: d.tag, |
mod_tag: d.tag, |
75 |
|
createdAt: new Date() |
76 |
}); |
}); |
77 |
|
|
78 |
await user.send({ |
const muteRecord = await MuteRecord.findOne({ |
79 |
embeds: [ |
user_id: user.user.id, |
80 |
new MessageEmbed() |
guild_id: user.guild.id |
|
.setAuthor({ |
|
|
iconURL: <string> user.guild!.iconURL(), |
|
|
name: `\tYou have been unmuted in ${user.guild!.name}` |
|
|
}) |
|
|
] |
|
81 |
}); |
}); |
82 |
|
|
83 |
|
if (muteRecord) { |
84 |
|
await muteRecord.delete(); |
85 |
|
} |
86 |
|
|
87 |
|
try { |
88 |
|
await user.send({ |
89 |
|
embeds: [ |
90 |
|
new MessageEmbed() |
91 |
|
.setAuthor({ |
92 |
|
iconURL: <string> user.guild!.iconURL(), |
93 |
|
name: `\tYou have been unmuted in ${user.guild!.name}` |
94 |
|
}) |
95 |
|
] |
96 |
|
}); |
97 |
|
} |
98 |
|
catch (e) { |
99 |
|
console.log(e); |
100 |
|
} |
101 |
|
|
102 |
await client.logger.logUnmute(user, d); |
await client.logger.logUnmute(user, d); |
103 |
} |
} |
104 |
catch (e) { |
catch (e) { |
108 |
|
|
109 |
export default class UnmuteCommand extends BaseCommand { |
export default class UnmuteCommand extends BaseCommand { |
110 |
supportsInteractions: boolean = true; |
supportsInteractions: boolean = true; |
111 |
|
permissions = [Permissions.FLAGS.MODERATE_MEMBERS]; |
112 |
|
|
113 |
constructor() { |
constructor() { |
114 |
super('unmute', 'moderation', []); |
super('unmute', 'moderation', []); |
191 |
] |
] |
192 |
}); |
}); |
193 |
} |
} |
|
} |
|
194 |
|
} |