3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-18 15:45:03 +00:00

added role removal mute overrides to automod and spam plugins

This commit is contained in:
roflmaoqwerty 2020-06-21 11:33:14 +10:00
parent 8bf47ff418
commit fa7d5d0526
4 changed files with 48 additions and 17 deletions

View file

@ -1148,6 +1148,8 @@ export class AutomodPlugin extends ZeppelinPlugin<TConfigSchema, ICustomOverride
extraNotes: [caseExtraNote],
};
const contactMethods = this.readContactMethodsFromAction(rule.actions.mute);
const rolesToRemove = rule.actions.mute.remove_roles_on_mute;
const rolesToRestore = rule.actions.mute.restore_roles_on_mute;
let userIdsToMute = [];
if (
@ -1165,7 +1167,14 @@ export class AutomodPlugin extends ZeppelinPlugin<TConfigSchema, ICustomOverride
if (userIdsToMute.length) {
for (const userId of userIdsToMute) {
await this.getMutes().muteUser(userId, duration, reason, { contactMethods, caseArgs });
await this.getMutes().muteUser(
userId,
duration,
reason,
{ contactMethods, caseArgs },
rolesToRemove,
rolesToRestore,
);
}
actionsTaken.push("mute");

View file

@ -249,6 +249,8 @@ export const MuteAction = t.type({
duration: tNullable(tDelayString),
notify: tNullable(t.string),
notifyChannel: tNullable(t.string),
remove_roles_on_mute: tNullable(t.union([t.boolean, t.array(t.string)])),
restore_roles_on_mute: tNullable(t.union([t.boolean, t.array(t.string)])),
});
export const KickAction = t.type({

View file

@ -153,6 +153,8 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
muteTime: number = null,
reason: string = null,
muteOptions: MuteOptions = {},
removeRolesOnMuteOverride: boolean | string[] = null,
restoreRolesOnMuteOverride: boolean | string[] = null,
): Promise<MuteResult> {
const lock = await this.locks.acquire(`mute-${userId}`);
@ -178,26 +180,28 @@ export class MutesPlugin extends ZeppelinPlugin<TConfigSchema> {
// remove and store any roles to be removed/restored
const currentUserRoles = member.roles;
const memberOptions: MemberOptions = {};
const removeRoles = removeRolesOnMuteOverride ?? config.remove_roles_on_mute;
const restoreRoles = restoreRolesOnMuteOverride ?? config.restore_roles_on_mute;
let rolesToRestore = [];
// remove roles
if (!Array.isArray(config.remove_roles_on_mute)) {
if (config.remove_roles_on_mute) {
if (!Array.isArray(removeRoles)) {
if (removeRoles) {
memberOptions.roles = [];
await member.edit(memberOptions);
}
} else {
memberOptions.roles = currentUserRoles.filter(x => !(<string[]>config.remove_roles_on_mute).includes(x));
memberOptions.roles = currentUserRoles.filter(x => !(<string[]>removeRoles).includes(x));
await member.edit(memberOptions);
}
// set roles to be restored
if (!Array.isArray(config.restore_roles_on_mute)) {
if (config.restore_roles_on_mute) {
if (!Array.isArray(restoreRoles)) {
if (restoreRoles) {
rolesToRestore = currentUserRoles;
}
} else {
rolesToRestore = currentUserRoles.filter(x => (<string[]>config.restore_roles_on_mute).includes(x));
rolesToRestore = currentUserRoles.filter(x => (<string[]>restoreRoles).includes(x));
}
// Apply mute role if it's missing

View file

@ -29,6 +29,8 @@ const BaseSingleSpamConfig = t.type({
count: t.number,
mute: tNullable(t.boolean),
mute_time: tNullable(t.number),
remove_roles_on_mute: tNullable(t.union([t.boolean, t.array(t.string)])),
restore_roles_on_mute: tNullable(t.union([t.boolean, t.array(t.string)])),
clean: tNullable(t.boolean),
});
type TBaseSingleSpamConfig = t.TypeOf<typeof BaseSingleSpamConfig>;
@ -257,12 +259,19 @@ export class SpamPlugin extends ZeppelinPlugin<TConfigSchema> {
const muteTime = spamConfig.mute_time
? convertDelayStringToMS(spamConfig.mute_time.toString())
: 120 * 1000;
muteResult = await mutesPlugin.muteUser(member.id, muteTime, "Automatic spam detection", {
caseArgs: {
modId: this.bot.user.id,
postInCaseLogOverride: false,
muteResult = await mutesPlugin.muteUser(
member.id,
muteTime,
"Automatic spam detection",
{
caseArgs: {
modId: this.bot.user.id,
postInCaseLogOverride: false,
},
},
});
spamConfig.remove_roles_on_mute,
spamConfig.restore_roles_on_mute,
);
}
// Get the offending message IDs
@ -379,12 +388,19 @@ export class SpamPlugin extends ZeppelinPlugin<TConfigSchema> {
if (spamConfig.mute && member) {
const mutesPlugin = this.getPlugin<MutesPlugin>("mutes");
const muteTime = spamConfig.mute_time ? convertDelayStringToMS(spamConfig.mute_time.toString()) : 120 * 1000;
await mutesPlugin.muteUser(member.id, muteTime, "Automatic spam detection", {
caseArgs: {
modId: this.bot.user.id,
extraNotes: [`Details: ${details}`],
await mutesPlugin.muteUser(
member.id,
muteTime,
"Automatic spam detection",
{
caseArgs: {
modId: this.bot.user.id,
extraNotes: [`Details: ${details}`],
},
},
});
spamConfig.remove_roles_on_mute,
spamConfig.restore_roles_on_mute,
);
} else {
// If we're not muting the user, just add a note on them
const casesPlugin = this.getPlugin<CasesPlugin>("cases");