mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
automod: add add_roles and remove_roles actions
This commit is contained in:
parent
b0df86692f
commit
fd8a4598aa
1 changed files with 48 additions and 0 deletions
|
@ -254,6 +254,14 @@ const ChangeNicknameAction = t.type({
|
|||
|
||||
const LogAction = t.boolean;
|
||||
|
||||
const AddRolesAction = t.type({
|
||||
roles: t.array(t.string),
|
||||
});
|
||||
|
||||
const RemoveRolesAction = t.type({
|
||||
roles: t.array(t.string),
|
||||
});
|
||||
|
||||
/**
|
||||
* FULL CONFIG SCHEMA
|
||||
*/
|
||||
|
@ -288,6 +296,8 @@ const Rule = t.type({
|
|||
alert: tNullable(AlertAction),
|
||||
change_nickname: tNullable(ChangeNicknameAction),
|
||||
log: tNullable(LogAction),
|
||||
add_roles: tNullable(AddRolesAction),
|
||||
remove_roles: tNullable(RemoveRolesAction),
|
||||
}),
|
||||
cooldown: tNullable(t.string),
|
||||
});
|
||||
|
@ -1255,6 +1265,44 @@ export class AutomodPlugin extends ZeppelinPlugin<TConfigSchema> {
|
|||
actionsTaken.push("nickname");
|
||||
}
|
||||
|
||||
if (rule.actions.add_roles) {
|
||||
const userIdsToChange = matchResult.type === "raidspam" ? matchResult.userIds : [matchResult.userId];
|
||||
for (const userId of userIdsToChange) {
|
||||
const member = await this.getMember(userId);
|
||||
if (!member) continue;
|
||||
|
||||
const memberRoles = new Set(member.roles);
|
||||
for (const roleId of rule.actions.add_roles.roles) {
|
||||
memberRoles.add(roleId);
|
||||
}
|
||||
|
||||
const rolesArr = Array.from(memberRoles.values());
|
||||
await member.edit({
|
||||
roles: rolesArr,
|
||||
});
|
||||
member.roles = rolesArr; // Make sure we know of the new roles internally as well
|
||||
}
|
||||
}
|
||||
|
||||
if (rule.actions.remove_roles) {
|
||||
const userIdsToChange = matchResult.type === "raidspam" ? matchResult.userIds : [matchResult.userId];
|
||||
for (const userId of userIdsToChange) {
|
||||
const member = await this.getMember(userId);
|
||||
if (!member) continue;
|
||||
|
||||
const memberRoles = new Set(member.roles);
|
||||
for (const roleId of rule.actions.remove_roles.roles) {
|
||||
memberRoles.delete(roleId);
|
||||
}
|
||||
|
||||
const rolesArr = Array.from(memberRoles.values());
|
||||
await member.edit({
|
||||
roles: rolesArr,
|
||||
});
|
||||
member.roles = rolesArr; // Make sure we know of the new roles internally as well
|
||||
}
|
||||
}
|
||||
|
||||
// Don't wait for the rest before continuing to other automod items in the queue
|
||||
(async () => {
|
||||
const user = matchResult.type !== "raidspam" ? this.getUser(matchResult.userId) : new UnknownUser();
|
||||
|
|
Loading…
Add table
Reference in a new issue