A tool for parsing traffic on the jetstream and applying a moderation workstream based on regexp based rules
accountModeration.ts#
This module provides a suite of functions for performing moderation actions specifically targeted at user accounts (as opposed to individual posts). These actions include applying labels, adding private comments for moderators, reporting the account, and removing labels.
All functions in this module are asynchronous and ensure that the agent is logged in (await isLoggedIn) before proceeding. They also wrap their core API calls in the limit function to respect rate limits.
Key Functions#
createAccountLabel(did: string, label: string, comment: string)#
- Purpose: Applies a moderation label to a user's account.
- De-duplication: Before applying a label, it performs two checks to prevent duplicates:
tryClaimAccountLabel(did, label): Atomically claims the label in Redis to prevent race conditions between multiple bot instances or threads.checkAccountLabels(did, label): Checks the Ozone API to see if the label has already been applied.
- Action: If the label is not a duplicate, it calls
agent.tools.ozone.moderation.emitEventwith amodEventLabelevent, adding thelabelto thecreateLabelValsarray. - Metrics: Increments
labelsAppliedCounteron success orlabelsCachedCounterif skipped.
createAccountComment(did: string, comment: string, atURI: string)#
- Purpose: Adds a private comment to a user's moderation record. This is visible to other moderators but not to the user.
- De-duplication: Uses
tryClaimAccountCommentin Redis to prevent duplicate comments for the same event. - Action: Calls
emitEventwith amodEventCommentevent.
createAccountReport(did: string, comment: string)#
- Purpose: Creates a formal report against a user's account.
- Action: Calls
emitEventwith amodEventReportevent. ThereportTypeis set tocom.atproto.moderation.defs#reasonOther.
negateAccountLabel(did: string, label: string, comment: string)#
- Purpose: Removes a previously applied label from an account. This is used when the criteria for a label are no longer met.
- Check: It first calls
checkAccountLabelsto ensure the label actually exists on the account before attempting to remove it. - Action: Calls
emitEventwith amodEventLabelevent, but this time adds thelabelto thenegateLabelValsarray. - Cache Invalidation: After successfully negating the label, it calls
deleteAccountLabelClaimto remove the claim from the Redis cache, allowing the label to be re-applied in the future if necessary. - Metrics: Increments
unlabelsRemovedCounter.
checkAccountLabels(did: string, label: string): Promise<boolean>#
- Purpose: Checks if a specific label already exists on an account.
- Action: Calls
agent.tools.ozone.moderation.getRepoto fetch the account's current moderation status and checks if thelabelsarray contains the specifiedlabel. - Returns:
trueif the label exists,falseotherwise.
getAllAccountLabels(did: string): Promise<string[]>#
- Purpose: Retrieves all labels currently applied to an account.
- Action: Calls
agent.tools.ozone.moderation.getRepoand maps the response to return an array of label strings. - Returns: An array of strings, where each string is a label value. Returns an empty array on failure.
- Note: Callers cannot distinguish between "account has no labels" and "API call failed" since both return an empty array.
Dependencies#
./redis.js: For de-duplication and caching logic (tryClaim...,deleteAccountLabelClaim)../agent.js: Provides the authenticatedagentfor all API calls../config.js: Provides theMOD_DIDfor proxying requests../limits.js: Provides thelimitfunction for rate limiting../logger.js: For logging../metrics.js: For incrementing Prometheus counters.