Allow certain or all roles to be removed upon mute and readded on unmute (#140)

This commit is contained in:
Nils 2021-02-13 19:04:40 +01:00 committed by GitHub
parent 8e812aab2f
commit a13b0b6fda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 135 additions and 27 deletions

View file

@ -2,6 +2,7 @@ import { GuildPluginData } from "knub";
import { MutesPluginType } from "../types";
import { LogType } from "../../../data/LogType";
import { resolveMember, stripObjectToScalars, UnknownUser } from "../../../utils";
import { MemberOptions } from "eris";
export async function clearExpiredMutes(pluginData: GuildPluginData<MutesPluginType>) {
const expiredMutes = await pluginData.state.mutes.getExpiredMutes();
@ -14,6 +15,14 @@ export async function clearExpiredMutes(pluginData: GuildPluginData<MutesPluginT
if (muteRole) {
await member.removeRole(muteRole);
}
if (mute.roles_to_restore) {
const memberOptions: MemberOptions = {};
const guildRoles = pluginData.guild.roles;
memberOptions.roles = Array.from(
new Set([...mute.roles_to_restore, ...member.roles.filter(x => x !== muteRole && guildRoles.has(x))]),
);
member.edit(memberOptions);
}
} catch (e) {
pluginData.state.serverLogs.log(LogType.BOT_ALERT, {
body: `Failed to remove mute role from {userMention(member)}`,