Sweepers
classe · Source
A container for all cache sweeping intervals and their associated sweep methods.
Properties
options
The options the sweepers were instantiated with Source
intervals
A record of interval timeout that is used to sweep the indicated items, or null if not being swept Source
Methods
sweepApplicationCommands
Sweeps all guild and global application commands and removes the ones which are indicated by the filter. Parameters
| Name | Type | Description |
|---|---|---|
filter | function | The function used to determine which commands will be removed from the caches. |
Returns: number — Amount of commands that were removed from the caches Source
sweepAutoModerationRules
Sweeps all auto moderation rules and removes the ones which are indicated by the filter. Parameters
| Name | Type | Description |
|---|---|---|
filter | function | The function used to determine which auto moderation rules will be removed from the caches |
Returns: number — Amount of auto moderation rules that were removed from the caches Source
sweepBans
Sweeps all guild bans and removes the ones which are indicated by the filter. Parameters
| Name | Type | Description |
|---|---|---|
filter | function | The function used to determine which bans will be removed from the caches. |
Returns: number — Amount of bans that were removed from the caches Source
sweepEmojis
Sweeps all guild emojis and removes the ones which are indicated by the filter. Parameters
| Name | Type | Description |
|---|---|---|
filter | function | The function used to determine which emojis will be removed from the caches. |
Returns: number — Amount of emojis that were removed from the caches Source
sweepInvites
Sweeps all guild invites and removes the ones which are indicated by the filter. Parameters
| Name | Type | Description |
|---|---|---|
filter | function | The function used to determine which invites will be removed from the caches. |
Returns: number — Amount of invites that were removed from the caches Source
sweepGuildMembers
Sweeps all guild members and removes the ones which are indicated by the filter. It is highly recommended to keep the client guild member cached Parameters
| Name | Type | Description |
|---|---|---|
filter | function | The function used to determine which guild members will be removed from the caches. |
Returns: number — Amount of guild members that were removed from the caches Source
sweepMessages
Sweeps all text-based channels' messages and removes the ones which are indicated by the filter. Parameters
| Name | Type | Description |
|---|---|---|
filter | function | The function used to determine which messages will be removed from the caches. |
Returns: number — Amount of messages that were removed from the caches
// Remove all messages older than 1800 seconds from the messages cache
const amount = sweepers.sweepMessages(
Sweepers.filterByLifetime({
lifetime: 1800,
getComparisonTimestamp: m => m.editedTimestamp ?? m.createdTimestamp,
})(),
);
console.log(`Successfully removed ${amount} messages from the cache.`);sweepPresences
Sweeps all presences and removes the ones which are indicated by the filter. Parameters
| Name | Type | Description |
|---|---|---|
filter | function | The function used to determine which presences will be removed from the caches. |
Returns: number — Amount of presences that were removed from the caches Source
sweepReactions
Sweeps all message reactions and removes the ones which are indicated by the filter. Parameters
| Name | Type | Description |
|---|---|---|
filter | function | The function used to determine which reactions will be removed from the caches. |
Returns: number — Amount of reactions that were removed from the caches Source
sweepStageInstances
Sweeps all guild stage instances and removes the ones which are indicated by the filter. Parameters
| Name | Type | Description |
|---|---|---|
filter | function | The function used to determine which stage instances will be removed from the caches. |
Returns: number — Amount of stage instances that were removed from the caches Source
sweepStickers
Sweeps all guild stickers and removes the ones which are indicated by the filter. Parameters
| Name | Type | Description |
|---|---|---|
filter | function | The function used to determine which stickers will be removed from the caches. |
Returns: number — Amount of stickers that were removed from the caches Source
sweepThreadMembers
Sweeps all thread members and removes the ones which are indicated by the filter. It is highly recommended to keep the client thread member cached Parameters
| Name | Type | Description |
|---|---|---|
filter | function | The function used to determine which thread members will be removed from the caches. |
Returns: number — Amount of thread members that were removed from the caches Source
sweepThreads
Sweeps all threads and removes the ones which are indicated by the filter. Parameters
| Name | Type | Description |
|---|---|---|
filter | function | The function used to determine which threads will be removed from the caches. |
Returns: number — filter Amount of threads that were removed from the caches
// Remove all threads archived greater than 1 day ago from all the channel caches
const amount = sweepers.sweepThreads(
Sweepers.filterByLifetime({
getComparisonTimestamp: t => t.archivedTimestamp,
excludeFromSweep: t => !t.archived,
})(),
);
console.log(`Successfully removed ${amount} threads from the cache.`);sweepUsers
Sweeps all users and removes the ones which are indicated by the filter. Parameters
| Name | Type | Description |
|---|---|---|
filter | function | The function used to determine which users will be removed from the caches. |
Returns: number — Amount of users that were removed from the caches Source
sweepVoiceStates
Sweeps all guild voice states and removes the ones which are indicated by the filter. Parameters
| Name | Type | Description |
|---|---|---|
filter | function | The function used to determine which voice states will be removed from the caches. |
Returns: number — Amount of voice states that were removed from the caches Source
destroy
Cancels all sweeping intervals Returns: voidSource
_sweepGuildDirectProp
Sweep a direct sub property of all guilds Parameters
| Name | Type | Description |
|---|---|---|
key | string | The name of the property |
filter | function | Filter function passed to sweep |
eventOptions? | SweepEventOptions | Options for the Client event emitted here Default: {}. |
Returns: Object — Object containing the number of guilds swept and the number of items swept Source
_validateProperties
Validates a set of properties Parameters
| Name | Type | Description |
|---|---|---|
key | string | Key of the options object to check |
| Source |
_initInterval
Initialize an interval for sweeping Parameters
| Name | Type | Description |
|---|---|---|
intervalKey | string | The name of the property that stores the interval for this sweeper |
sweepKey | string | The name of the function that sweeps the desired caches |
opts | Object | Validated options for a sweep |
| Source |
filterByLifetime
Create a sweepFilter function that uses a lifetime to determine sweepability. Parameters
| Name | Type | Description |
|---|---|---|
options? | LifetimeFilterOptions | The options used to generate the filter function Default: {}. |
Returns: GlobalSweepFilterSource
archivedThreadSweepFilter
Creates a sweep filter that sweeps archived threads Parameters
| Name | Type | Description |
|---|---|---|
lifetime? | number | How long a thread has to be archived to be valid for sweeping Default: 14400. |
Returns: GlobalSweepFilterSource
expiredInviteSweepFilter
Creates a sweep filter that sweeps expired invites Parameters
| Name | Type | Description |
|---|---|---|
lifetime? | number | How long ago an invite has to have expired to be valid for sweeping Default: 14400. |
Returns: GlobalSweepFilterSource
outdatedMessageSweepFilter
Creates a sweep filter that sweeps outdated messages (edits taken into account) Parameters
| Name | Type | Description |
|---|---|---|
lifetime? | number | How long ago a message has to have been sent or edited to be valid for sweeping Default: 3600. |
Returns: GlobalSweepFilterSource