mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
feat(Client): add global sweepers (#6825)
Co-authored-by: Antonio Román <kyradiscord@gmail.com> Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com> Co-authored-by: Rodry <38259440+ImRodry@users.noreply.github.com> Co-authored-by: Almeida <almeidx@pm.me>
This commit is contained in:
118
typings/index.d.ts
vendored
118
typings/index.d.ts
vendored
@@ -545,6 +545,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
|
||||
public options: ClientOptions;
|
||||
public readyAt: If<Ready, Date>;
|
||||
public readonly readyTimestamp: If<Ready, number>;
|
||||
public sweepers: Sweepers;
|
||||
public shard: ShardClientUtil | null;
|
||||
public token: If<Ready, string, string | null>;
|
||||
public uptime: If<Ready, number>;
|
||||
@@ -564,6 +565,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
|
||||
public generateInvite(options?: InviteGenerationOptions): string;
|
||||
public login(token?: string): Promise<string>;
|
||||
public isReady(): this is Client<true>;
|
||||
/** @deprecated Use {@link Sweepers#sweepMessages} instead */
|
||||
public sweepMessages(lifetime?: number): number;
|
||||
public toJSON(): unknown;
|
||||
|
||||
@@ -629,6 +631,7 @@ export class ClientUser extends User {
|
||||
export class Options extends null {
|
||||
private constructor();
|
||||
public static defaultMakeCacheSettings: CacheWithLimitsOptions;
|
||||
public static defaultSweeperSettings: SweeperOptions;
|
||||
public static createDefault(): ClientOptions;
|
||||
public static cacheWithLimits(settings?: CacheWithLimitsOptions): CacheFactory;
|
||||
public static cacheEverything(): CacheFactory;
|
||||
@@ -1365,9 +1368,12 @@ export class LimitedCollection<K, V> extends Collection<K, V> {
|
||||
public constructor(options?: LimitedCollectionOptions<K, V>, iterable?: Iterable<readonly [K, V]>);
|
||||
public maxSize: number;
|
||||
public keepOverLimit: ((value: V, key: K, collection: this) => boolean) | null;
|
||||
/** @deprecated Use Global Sweepers instead */
|
||||
public interval: NodeJS.Timeout | null;
|
||||
/** @deprecated Use Global Sweepers instead */
|
||||
public sweepFilter: SweepFilter<K, V> | null;
|
||||
|
||||
/** @deprecated Use `Sweepers.filterByLifetime` instead */
|
||||
public static filterByLifetime<K, V>(options?: LifetimeFilterOptions<K, V>): SweepFilter<K, V>;
|
||||
}
|
||||
|
||||
@@ -2112,6 +2118,68 @@ export class StoreChannel extends GuildChannel {
|
||||
public type: 'GUILD_STORE';
|
||||
}
|
||||
|
||||
export class Sweepers {
|
||||
public constructor(client: Client, options: SweeperOptions);
|
||||
public readonly client: Client;
|
||||
public intervals: Record<SweeperKey, NodeJS.Timeout | null>;
|
||||
public options: SweeperOptions;
|
||||
|
||||
public sweepApplicationCommands(
|
||||
filter: CollectionSweepFilter<
|
||||
SweeperDefinitions['applicationCommands'][0],
|
||||
SweeperDefinitions['applicationCommands'][1]
|
||||
>,
|
||||
): number;
|
||||
public sweepBans(filter: CollectionSweepFilter<SweeperDefinitions['bans'][0], SweeperDefinitions['bans'][1]>): number;
|
||||
public sweepEmojis(
|
||||
filter: CollectionSweepFilter<SweeperDefinitions['emojis'][0], SweeperDefinitions['emojis'][1]>,
|
||||
): number;
|
||||
public sweepInvites(
|
||||
filter: CollectionSweepFilter<SweeperDefinitions['invites'][0], SweeperDefinitions['invites'][1]>,
|
||||
): number;
|
||||
public sweepGuildMembers(
|
||||
filter: CollectionSweepFilter<SweeperDefinitions['guildMembers'][0], SweeperDefinitions['guildMembers'][1]>,
|
||||
): number;
|
||||
public sweepMessages(
|
||||
filter: CollectionSweepFilter<SweeperDefinitions['messages'][0], SweeperDefinitions['messages'][1]>,
|
||||
): number;
|
||||
public sweepPresences(
|
||||
filter: CollectionSweepFilter<SweeperDefinitions['presences'][0], SweeperDefinitions['presences'][1]>,
|
||||
): number;
|
||||
public sweepReactions(
|
||||
filter: CollectionSweepFilter<SweeperDefinitions['reactions'][0], SweeperDefinitions['reactions'][1]>,
|
||||
): number;
|
||||
public sweepStageInstnaces(
|
||||
filter: CollectionSweepFilter<SweeperDefinitions['stageInstances'][0], SweeperDefinitions['stageInstances'][1]>,
|
||||
): number;
|
||||
public sweepStickers(
|
||||
filter: CollectionSweepFilter<SweeperDefinitions['stickers'][0], SweeperDefinitions['stickers'][1]>,
|
||||
): number;
|
||||
public sweepThreadMembers(
|
||||
filter: CollectionSweepFilter<SweeperDefinitions['threadMembers'][0], SweeperDefinitions['threadMembers'][1]>,
|
||||
): number;
|
||||
public sweepThreads(
|
||||
filter: CollectionSweepFilter<SweeperDefinitions['threads'][0], SweeperDefinitions['threads'][1]>,
|
||||
): number;
|
||||
public sweepUsers(
|
||||
filter: CollectionSweepFilter<SweeperDefinitions['users'][0], SweeperDefinitions['users'][1]>,
|
||||
): number;
|
||||
public sweepVoiceStates(
|
||||
filter: CollectionSweepFilter<SweeperDefinitions['voiceStates'][0], SweeperDefinitions['voiceStates'][1]>,
|
||||
): number;
|
||||
|
||||
public static archivedThreadSweepFilter(
|
||||
lifetime?: number,
|
||||
): GlobalSweepFilter<SweeperDefinitions['threads'][0], SweeperDefinitions['threads'][1]>;
|
||||
public static expiredInviteSweepFilter(
|
||||
lifetime?: number,
|
||||
): GlobalSweepFilter<SweeperDefinitions['invites'][0], SweeperDefinitions['invites'][1]>;
|
||||
public static filterByLifetime<K, V>(options?: LifetimeFilterOptions<K, V>): GlobalSweepFilter<K, V>;
|
||||
public static outdatedMessageSweepFilter(
|
||||
lifetime?: number,
|
||||
): GlobalSweepFilter<SweeperDefinitions['messages'][0], SweeperDefinitions['messages'][1]>;
|
||||
}
|
||||
|
||||
export class SystemChannelFlags extends BitField<SystemChannelFlagsString> {
|
||||
public static FLAGS: Record<SystemChannelFlagsString, number>;
|
||||
public static resolve(bit?: BitFieldResolvable<SystemChannelFlagsString, number>): number;
|
||||
@@ -2280,6 +2348,7 @@ export class UserFlags extends BitField<UserFlagsString> {
|
||||
|
||||
export class Util extends null {
|
||||
private constructor();
|
||||
/** @deprecated When not using with `makeCache` use `Sweepers.archivedThreadSweepFilter` instead */
|
||||
public static archivedThreadSweepFilter<K, V>(lifetime?: number): SweepFilter<K, V>;
|
||||
public static basename(path: string, ext?: string): string;
|
||||
public static cleanContent(str: string, channel: TextBasedChannels): string;
|
||||
@@ -3742,6 +3811,7 @@ export interface ClientEvents extends BaseClientEvents {
|
||||
applicationCommandDelete: [command: ApplicationCommand];
|
||||
/** @deprecated See [this issue](https://github.com/discord/discord-api-docs/issues/3690) for more information. */
|
||||
applicationCommandUpdate: [oldCommand: ApplicationCommand | null, newCommand: ApplicationCommand];
|
||||
cacheSweep: [message: string];
|
||||
channelCreate: [channel: GuildChannel];
|
||||
channelDelete: [channel: DMChannel | GuildChannel];
|
||||
channelPinsUpdate: [channel: TextBasedChannels, date: Date];
|
||||
@@ -3821,9 +3891,9 @@ export interface ClientOptions {
|
||||
shards?: number | number[] | 'auto';
|
||||
shardCount?: number;
|
||||
makeCache?: CacheFactory;
|
||||
/** @deprecated Use `makeCache` with a `LimitedCollection` for `MessageManager` instead. */
|
||||
/** @deprecated Pass the value of this property as `lifetime` to `sweepers.messages` instead. */
|
||||
messageCacheLifetime?: number;
|
||||
/** @deprecated Use `makeCache` with a `LimitedCollection` for `MessageManager` instead. */
|
||||
/** @deprecated Pass the value of this property as `interval` to `sweepers.messages` instead. */
|
||||
messageSweepInterval?: number;
|
||||
allowedMentions?: MessageMentionOptions;
|
||||
invalidRequestWarningInterval?: number;
|
||||
@@ -3838,6 +3908,7 @@ export interface ClientOptions {
|
||||
userAgentSuffix?: string[];
|
||||
presence?: PresenceData;
|
||||
intents: BitFieldResolvable<IntentsString, number>;
|
||||
sweepers?: SweeperOptions;
|
||||
ws?: WebSocketOptions;
|
||||
http?: HTTPOptions;
|
||||
rejectOnRateLimit?: string[] | ((data: RateLimitData) => boolean | Promise<boolean>);
|
||||
@@ -4033,6 +4104,7 @@ export interface ConstantsEvents {
|
||||
ERROR: 'error';
|
||||
WARN: 'warn';
|
||||
DEBUG: 'debug';
|
||||
CACHE_SWEEP: 'cacheSweep';
|
||||
SHARD_DISCONNECT: 'shardDisconnect';
|
||||
SHARD_ERROR: 'shardError';
|
||||
SHARD_RECONNECTING: 'shardReconnecting';
|
||||
@@ -4237,6 +4309,8 @@ export interface FileOptions {
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export type GlobalSweepFilter<K, V> = () => ((value: V, key: K, collection: Collection<K, V>) => boolean) | null;
|
||||
|
||||
export interface GuildApplicationCommandPermissionData {
|
||||
id: Snowflake;
|
||||
permissions: ApplicationCommandPermissionData[];
|
||||
@@ -5234,14 +5308,54 @@ export interface StageInstanceEditOptions {
|
||||
privacyLevel?: PrivacyLevel | number;
|
||||
}
|
||||
|
||||
export type SweeperKey = keyof SweeperDefinitions;
|
||||
|
||||
export type CollectionSweepFilter<K, V> = (value: V, key: K, collection: Collection<K, V>) => boolean;
|
||||
|
||||
export type SweepFilter<K, V> = (
|
||||
collection: LimitedCollection<K, V>,
|
||||
) => ((value: V, key: K, collection: LimitedCollection<K, V>) => boolean) | null;
|
||||
|
||||
export interface SweepOptions<K, V> {
|
||||
interval: number;
|
||||
filter: GlobalSweepFilter<K, V>;
|
||||
}
|
||||
|
||||
export interface LifetimeSweepOptions {
|
||||
interval: number;
|
||||
lifetime: number;
|
||||
filter?: never;
|
||||
}
|
||||
|
||||
export interface SweeperDefinitions {
|
||||
applicationCommands: [Snowflake, ApplicationCommand];
|
||||
bans: [Snowflake, GuildBan];
|
||||
emojis: [Snowflake, GuildEmoji];
|
||||
invites: [string, Invite, true];
|
||||
guildMembers: [Snowflake, GuildMember];
|
||||
messages: [Snowflake, Message, true];
|
||||
presences: [Snowflake, Presence];
|
||||
reactions: [string | Snowflake, MessageReaction];
|
||||
stageInstances: [Snowflake, StageInstance];
|
||||
stickers: [Snowflake, Sticker];
|
||||
threadMembers: [Snowflake, ThreadMember];
|
||||
threads: [Snowflake, ThreadChannel, true];
|
||||
users: [Snowflake, User];
|
||||
voiceStates: [Snowflake, VoiceState];
|
||||
}
|
||||
|
||||
export type SweeperOptions = {
|
||||
[K in keyof SweeperDefinitions]?: SweeperDefinitions[K][2] extends true
|
||||
? SweepOptions<SweeperDefinitions[K][0], SweeperDefinitions[K][1]> | LifetimeSweepOptions
|
||||
: SweepOptions<SweeperDefinitions[K][0], SweeperDefinitions[K][1]>;
|
||||
};
|
||||
|
||||
export interface LimitedCollectionOptions<K, V> {
|
||||
maxSize?: number;
|
||||
keepOverLimit?: (value: V, key: K, collection: LimitedCollection<K, V>) => boolean;
|
||||
/** @deprecated Use Global Sweepers instead */
|
||||
sweepFilter?: SweepFilter<K, V>;
|
||||
/** @deprecated Use Global Sweepers instead */
|
||||
sweepInterval?: number;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user