A tool for parsing traffic on the jetstream and applying a moderation workstream based on regexp based rules
starterPackThreshold.ts#
This module is responsible for checking if an account has created too many starter packs within a specific time window. When a threshold is met, it can trigger various moderation actions on the account, such as applying a label, adding a comment, or reporting the account. This is useful for detecting follow-farming behaviour and coordinated campaign activity.
Key Functions#
checkStarterPackThreshold(did: string, starterPackUri: string, timestamp: number): Promise<void>#
This is the main function of the module. It's called whenever a starter pack is created, and it checks if the creator has exceeded the configured threshold.
Parameters:
did: The DID of the account that created the starter pack.starterPackUri: The AT URI of the newly created starter pack.timestamp: The timestamp of the creation event.
Logic:
- Load Configurations: It retrieves the cached
STARTER_PACK_THRESHOLD_CONFIGS. - Check Allowlist: For each configuration, it first checks if the account is in the
allowlist. If so, the check is skipped for that configuration. - Track the Creation: It records the new starter pack creation for the account in Redis using
trackStarterPackForAccount. This function stores the URI with its timestamp in a sorted set. - Count Recent Creations: It then uses
getStarterPackCountInWindowto count how many starter packs the account has created within the defined rolling window (window+windowUnit). - Check Threshold: If the
countis greater than or equal to thethresholddefined in the configuration, it proceeds to take action. - Format Comment: A detailed comment is generated including the threshold count, window configuration, and the triggering starter pack URI.
- Apply Moderation Actions:
- It logs that the threshold has been met.
- It increments the
starterPackThresholdMetCountermetric. - Based on the booleans
toLabel(defaults to true),reportAcct, andcommentAcctin the configuration, it will:- Apply a label to the account (
createAccountLabel). - Report the account (
createAccountReport). - Add a comment to the account's moderation record (
createAccountComment).
- Apply a label to the account (
- It also increments the
starterPackLabelsThresholdAppliedCounterfor each action taken.
loadStarterPackThresholdConfigs(): StarterPackThresholdConfig[]#
This function returns the cached STARTER_PACK_THRESHOLD_CONFIGS. The configurations are loaded and validated once at module initialization to avoid re-reading and re-validating the configuration file on every call.
Supporting Functions#
validateAndLoadConfigs(): StarterPackThresholdConfig[]: This function is called once when the module is loaded. It iterates throughSTARTER_PACK_THRESHOLD_CONFIGS, validates that each configuration has the required properties (threshold > 0,window > 0), and then returns the valid configurations.
Dependencies#
../../rules/starterPackThreshold.js: Contains theSTARTER_PACK_THRESHOLD_CONFIGSarray, which defines the rules for when to take action on an account../accountModeration.js: Provides the functions (createAccountLabel,createAccountReport,createAccountComment) to perform moderation actions on an account../logger.js: Used for logging information, warnings, and errors../metrics.js: Provides Prometheus counters for monitoring the behavior of this module../redis.js: Provides the functions (trackStarterPackForAccount,getStarterPackCountInWindow) for interacting with Redis to store and retrieve data about starter pack creations../types.js: Defines theStarterPackThresholdConfigtype.