MCPcopy Create free account
hub / github.com/codebymitch/TitanBot / validateRoleSafety

Function validateRoleSafety

src/services/reactionRoleService.js:62–101  ·  view source on GitHub ↗
(client, guildId, roleId)

Source from the content-addressed store, hash-verified

60}
61
62async function validateRoleSafety(client, guildId, roleId) {
63 const guild = client.guilds?.cache?.get(guildId) || await client.guilds?.fetch?.(guildId).catch(() => null);
64 if (!guild) {
65 throw createError(
66 `Guild not found for role validation: ${guildId}`,
67 ErrorTypes.VALIDATION,
68 'Server not found while validating reaction roles.',
69 { guildId, roleId }
70 );
71 }
72
73 const role = guild.roles.cache.get(roleId) || await guild.roles.fetch(roleId).catch(() => null);
74 if (!role) {
75 throw createError(
76 `Role not found: ${roleId}`,
77 ErrorTypes.VALIDATION,
78 'One or more selected roles no longer exist.',
79 { guildId, roleId }
80 );
81 }
82
83 if (hasDangerousPermissions(role)) {
84 throw createError(
85 `Dangerous role permission detected: ${roleId}`,
86 ErrorTypes.PERMISSION,
87 'For security reasons, high-privilege roles cannot be assigned through reaction roles.',
88 { guildId, roleId, roleName: role.name, dangerousPermissions: DANGEROUS_PERMISSIONS }
89 );
90 }
91
92 const botHighestRole = guild.members.me?.roles?.highest;
93 if (!botHighestRole || role.position >= botHighestRole.position) {
94 throw createError(
95 `Role above bot hierarchy: ${roleId}`,
96 ErrorTypes.PERMISSION,
97 'I cannot assign this role because it is equal to or above my highest role.',
98 { guildId, roleId, rolePosition: role.position, botRolePosition: botHighestRole?.position }
99 );
100 }
101}
102
103export async function getReactionRoleMessage(client, guildId, messageId) {
104 try {

Callers 2

addReactionRoleFunction · 0.85

Calls 3

createErrorFunction · 0.90
hasDangerousPermissionsFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected