mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import * as t from "io-ts";
|
|
import { automodAction } from "../helpers";
|
|
import { LogType } from "../../../data/LogType";
|
|
import { asyncMap, resolveMember, tNullable, unique } from "../../../utils";
|
|
import { resolveActionContactMethods } from "../functions/resolveActionContactMethods";
|
|
import { ModActionsPlugin } from "../../ModActions/ModActionsPlugin";
|
|
|
|
export const AddRolesAction = automodAction({
|
|
configType: t.array(t.string),
|
|
defaultConfig: [],
|
|
|
|
async apply({ pluginData, contexts, actionConfig }) {
|
|
const members = unique(contexts.map(c => c.member).filter(Boolean));
|
|
|
|
await Promise.all(
|
|
members.map(async member => {
|
|
const memberRoles = new Set(member.roles);
|
|
for (const roleId of actionConfig) {
|
|
memberRoles.add(roleId);
|
|
}
|
|
|
|
if (memberRoles.size === member.roles.length) {
|
|
// No role changes
|
|
return;
|
|
}
|
|
|
|
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
|
|
}),
|
|
);
|
|
},
|
|
});
|