Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | 49x 49x 21x 21x 21x 13x 13x 13x 12x 9x 9x 5x 5x 5x 5x 4x 4x 27x 27x 17x 10x 10x 5x 5x 5x 8x 8x 8x 8x 1x 1x 7x 7x 7x 7x 1x 1x 6x 6x 6x 1x 1x 5x 3x 1x 1x 2x 1x 2x 2x 1x 1x 1x 1x 2x 1x 1x 6x 6x 1x 5x 5x 2x 3x 2x 1x 10x | /** * ModeratorProcessor - Processes moderator-related proposals (add/remove moderator roles) * * Handles the democratic process for changing server moderation staff through community proposals. * When moderator proposals pass community voting, this processor executes the role changes. * * Design rationale: * - Democratic moderator selection ensures community input on server leadership * - Automatic role assignment prevents manual errors and ensures timely changes * - Validation prevents invalid users from being assigned moderator privileges * - Comprehensive logging provides audit trail for moderator changes */ class ModeratorProcessor { constructor(bot, proposalConfig) { this.bot = bot; this.proposalConfig = proposalConfig; } /** * Parse moderator proposal to extract target user and action type * Format: **Add Moderator**: @user or **Remove Moderator**: @user * * This parsing ensures only properly formatted proposals can affect moderator status, * preventing accidental or malformed role changes. */ parseModeratorProposal(content) { console.log(`Parsing moderator proposal: ${content}`); // Check for add moderator format const addMatch = content.match(/^\*\*Add Moderator\*\*:\s*(.+)$/i); if (addMatch) { const targetText = addMatch[1].trim(); const userId = this.extractUserId(targetText); if (userId) { return { action: 'add', userId: userId, targetText: targetText }; } } // Check for remove moderator format const removeMatch = content.match(/^\*\*Remove Moderator\*\*:\s*(.+)$/i); if (removeMatch) { const targetText = removeMatch[1].trim(); const userId = this.extractUserId(targetText); Eif (userId) { return { action: 'remove', userId: userId, targetText: targetText }; } } console.log('No valid moderator action found in proposal'); return null; } // Extract user ID from various mention formats // Supports: @username, <@123456>, <@!123456>, or raw user ID extractUserId(text) { // Discord mention format: <@123456> or <@!123456> const mentionMatch = text.match(/<@!?(\d{17,19})>/); if (mentionMatch) { return mentionMatch[1]; } // Raw user ID (17-19 digits) const idMatch = text.match(/^\d{17,19}$/); if (idMatch) { return text; } console.log(`Could not extract user ID from: ${text}`); return null; } // Process passed moderator proposal by applying role change // Adds or removes moderator role as specified in the proposal async processModeratorAction(proposal, guild) { try { console.log(`Processing moderator action for proposal: ${proposal.message_id}`); const moderatorAction = this.parseModeratorProposal(proposal.content); if (!moderatorAction) { console.error('Could not parse moderator action from proposal content'); return false; } const { action, userId, targetText } = moderatorAction; console.log(`Moderator action: ${action} for user ${userId}`); // Get guild member const targetMember = await guild.members.fetch(userId).catch(() => null); if (!targetMember) { console.error(`Could not find member with ID ${userId} in guild`); return false; } // Get moderator role const moderatorRoleId = this.bot.getModeratorRoleId(); const moderatorRole = guild.roles.cache.get(moderatorRoleId); if (!moderatorRole) { console.error(`Could not find moderator role with ID ${moderatorRoleId}`); return false; } // Apply role change if (action === 'add') { if (targetMember.roles.cache.has(moderatorRoleId)) { console.log(`User ${targetMember.displayName} already has moderator role`); return true; // Not an error, just already has role } await targetMember.roles.add(moderatorRole); console.log(`✅ Added moderator role to ${targetMember.displayName}`); } else Eif (action === 'remove') { if (!targetMember.roles.cache.has(moderatorRoleId)) { console.log(`User ${targetMember.displayName} does not have moderator role`); return true; // Not an error, just doesn't have role } await targetMember.roles.remove(moderatorRole); console.log(`✅ Removed moderator role from ${targetMember.displayName}`); } return true; } catch (error) { console.error('Error processing moderator action:', error); return false; } } // Generate human-readable summary of moderator action // Used for vote messages and resolution displays getActionSummary(content) { const moderatorAction = this.parseModeratorProposal(content); if (!moderatorAction) { return 'Unknown moderator action'; } const { action, targetText } = moderatorAction; if (action === 'add') { return `Add ${targetText} as moderator`; } else if (action === 'remove') { return `Remove ${targetText} from moderator role`; } return 'Unknown moderator action'; } } module.exports = ModeratorProcessor; |