(moderator, target, action)
| 50 | } |
| 51 | |
| 52 | static validateHierarchy(moderator, target, action) { |
| 53 | if (!moderator || !target) { |
| 54 | return { valid: false, error: 'Invalid moderator or target' }; |
| 55 | } |
| 56 | |
| 57 | if (moderator.guild?.ownerId === moderator.id) { |
| 58 | return { valid: true }; |
| 59 | } |
| 60 | |
| 61 | const modRole = getHighestRole(moderator); |
| 62 | const targetRole = getHighestRole(target); |
| 63 | |
| 64 | if (!modRole || !targetRole) { |
| 65 | return { |
| 66 | valid: false, |
| 67 | error: 'Could not resolve role hierarchy. Try mentioning the user or use the slash command.', |
| 68 | }; |
| 69 | } |
| 70 | |
| 71 | if (modRole.position <= targetRole.position) { |
| 72 | return { |
| 73 | valid: false, |
| 74 | error: this.buildHierarchyMessage({ |
| 75 | actor: 'moderator', |
| 76 | actorRole: modRole, |
| 77 | targetRole, |
| 78 | targetLabel: getTargetLabel(target), |
| 79 | action, |
| 80 | }), |
| 81 | }; |
| 82 | } |
| 83 | |
| 84 | return { valid: true }; |
| 85 | } |
| 86 | |
| 87 | static validateBotHierarchy(target, action) { |
| 88 | if (!target) { |
no test coverage detected