Allow certain or all roles to be removed upon mute and readded on unmute (#140)
This commit is contained in:
parent
8e812aab2f
commit
a13b0b6fda
12 changed files with 135 additions and 27 deletions
|
@ -7,7 +7,7 @@ import humanizeDuration from "humanize-duration";
|
|||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { WithRequiredProps } from "../../../utils/typeUtils";
|
||||
import { MemberOptions } from "eris";
|
||||
|
||||
export async function unmuteUser(
|
||||
pluginData: GuildPluginData<MutesPluginType>,
|
||||
|
@ -36,6 +36,14 @@ export async function unmuteUser(
|
|||
if (muteRole && member.roles.includes(muteRole)) {
|
||||
await member.removeRole(muteRole);
|
||||
}
|
||||
if (existingMute?.roles_to_restore) {
|
||||
const memberOptions: MemberOptions = {};
|
||||
const guildRoles = pluginData.guild.roles;
|
||||
memberOptions.roles = Array.from(
|
||||
new Set([...existingMute.roles_to_restore, ...member.roles.filter(x => x !== muteRole && guildRoles.has(x))]),
|
||||
);
|
||||
member.edit(memberOptions);
|
||||
}
|
||||
} else {
|
||||
console.warn(
|
||||
`Member ${userId} not found in guild ${pluginData.guild.name} (${pluginData.guild.id}) when attempting to unmute`,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue