A tool for parsing traffic on the jetstream and applying a moderation workstream based on regexp based rules
moderation.ts#
This module provides functions for performing moderation actions on individual posts (records). It is the counterpart to accountModeration.ts, which handles account-level actions.
All functions in this module ensure the agent is logged in (await isLoggedIn) and wrap their API calls in the limit function to manage concurrency and rate limiting.
Key Functions#
createPostLabel(uri: string, cid: string, label: string, comment: string, duration: number | undefined, did?: string, time?: number)#
- Purpose: Applies a moderation label to a specific post.
- Parameters:
uri,cid: The strong reference to the post.label: The label value to apply (e.g., "spam").comment: The private moderation comment.duration: An optional duration in hours for temporary labels.did,time: Optional author DID and event time, passed through to trigger an account threshold check.
- De-duplication:
tryClaimPostLabel(uri, label): Atomically claims the label for the post in Redis to prevent race conditions.checkRecordLabels(uri, label): Checks the Ozone API to see if the label already exists on the post.
- Action: If the label is not a duplicate, it calls
agent.tools.ozone.moderation.emitEventwith amodEventLabelevent. - Threshold Check: After successfully applying a label, if the author's
didand the eventtimewere provided, it dynamically imports and callscheckAccountThreshold. This is a crucial step that connects post-level moderation to account-level moderation, escalating actions against repeat offenders. The dynamic import is used to break a circular dependency between themoderationandaccountThresholdmodules. - Metrics: Increments
labelsAppliedCounteron success orlabelsCachedCounterif skipped.
createPostReport(uri: string, cid: string, comment: string)#
- Purpose: Creates a formal report against a specific post.
- Action: Calls
emitEventwith amodEventReportevent. ThereportTypeis hardcoded tocom.atproto.moderation.defs#reasonOther.
checkRecordLabels(uri: string, label: string): Promise<boolean>#
- Purpose: Checks if a specific label already exists on a post.
- Action: Calls
agent.tools.ozone.moderation.getRecordto fetch the post's current moderation status. - Returns:
trueif the label exists,falseotherwise. It relies on the helperdoesLabelExistto parse the response.
Helper Functions#
doesLabelExist(labels: { val: string }[] | undefined, labelVal: string): boolean#
- A simple, private utility function that safely checks if a
labelsarray from an API response contains a specificlabelVal.
Dependencies#
../automod/redis.js: ProvidestryClaimPostLabelfor de-duplication../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.../automod/accountThreshold.js: Dynamically imported to trigger account threshold checks.