-
Notifications
You must be signed in to change notification settings - Fork 2
fix: protect admins/mods/owner from moderation actions (#174) #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f968a62
a50d66f
ce85feb
c20ea73
4b922de
7fc24c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,21 +141,24 @@ export async function sendModerationLog(client, classification, snapshot, channe | |
| // Skip moderation log if any flagged user is a protected role (admin/mod/owner) | ||
| const guild = logChannel.guild; | ||
| if (guild && targets.length > 0) { | ||
| const seenUserIds = new Set(); | ||
| for (const t of targets) { | ||
| if (seenUserIds.has(t.userId)) continue; | ||
| seenUserIds.add(t.userId); | ||
| try { | ||
| const member = await guild.members.fetch(t.userId); | ||
| if (isProtectedTarget(member, guild, config)) { | ||
| warn('Triage skipped moderation log: target is a protected role', { | ||
| userId: t.userId, | ||
| channelId, | ||
| }); | ||
| return; | ||
| // Skip the expensive member-fetch loop when protection is explicitly disabled. | ||
| if (config.moderation?.protectRoles?.enabled !== false) { | ||
| const seenUserIds = new Set(); | ||
| for (const t of targets) { | ||
| if (seenUserIds.has(t.userId)) continue; | ||
| seenUserIds.add(t.userId); | ||
| try { | ||
| const member = await guild.members.fetch(t.userId); | ||
| if (isProtectedTarget(member, guild)) { | ||
| warn('Triage skipped moderation log: target is a protected role', { | ||
| userId: t.userId, | ||
| channelId, | ||
| }); | ||
| return; | ||
| } | ||
| } catch { | ||
| // Member not in guild or fetch failed — proceed with logging | ||
| } | ||
| } catch { | ||
| // Member not in guild or fetch failed — proceed with logging | ||
| } | ||
| } | ||
|
Comment on lines
+141
to
+163
|
||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+141
to
+164
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove stale JSDoc param from
isProtectedTarget.Line 449 documents a
configparameter that no longer exists in the function signature, which is misleading.♻️ Suggested doc fix
/** * Check if a target member is protected from moderation actions. * Protected members include the server owner, admins, moderators, and any custom role IDs * configured under `moderation.protectRoles`. * `@param` {import('discord.js').GuildMember} target - Target member to check * `@param` {import('discord.js').Guild} guild - Discord guild - * `@param` {Object} config - Bot configuration * `@returns` {boolean} True if the target should not be moderated */🤖 Prompt for AI Agents