mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 04:25:01 +00:00
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { Snowflake } from "discord.js";
|
|
import z from "zod";
|
|
import { zSnowflake } from "../../../utils";
|
|
import { consumeIgnoredRoleChange } from "../functions/ignoredRoleChanges";
|
|
import { automodTrigger } from "../helpers";
|
|
|
|
interface RoleAddedMatchResult {
|
|
matchedRoleId: string;
|
|
}
|
|
|
|
const configSchema = z.union([zSnowflake, z.array(zSnowflake).max(255)]).default([]);
|
|
|
|
export const RoleAddedTrigger = automodTrigger<RoleAddedMatchResult>()({
|
|
configSchema,
|
|
|
|
async match({ triggerConfig, context, pluginData }) {
|
|
if (!context.member || !context.rolesChanged || context.rolesChanged.added!.length === 0) {
|
|
return;
|
|
}
|
|
|
|
const triggerRoles = Array.isArray(triggerConfig) ? triggerConfig : [triggerConfig];
|
|
for (const roleId of triggerRoles) {
|
|
if (context.rolesChanged.added!.includes(roleId)) {
|
|
if (consumeIgnoredRoleChange(pluginData, context.member.id, roleId)) {
|
|
continue;
|
|
}
|
|
|
|
return {
|
|
extra: {
|
|
matchedRoleId: roleId,
|
|
},
|
|
};
|
|
}
|
|
}
|
|
},
|
|
|
|
renderMatchInformation({ matchResult, pluginData, contexts }) {
|
|
const role = pluginData.guild.roles.cache.get(matchResult.extra.matchedRoleId as Snowflake);
|
|
const roleName = role?.name || "Unknown";
|
|
const member = contexts[0].member!;
|
|
const memberName = `**${renderUsername(member)}** (\`${member.id}\`)`;
|
|
return `Role ${roleName} (\`${matchResult.extra.matchedRoleId}\`) was added to ${memberName}`;
|
|
},
|
|
});
|