UNPKG

detritus-client

Version:

A Typescript NodeJS library to interact with Discord's API, both Rest and Gateway.

52 lines (51 loc) 1.91 kB
import { Timers } from 'detritus-utils'; import { BaseCollection } from '../collections/basecollection'; import { CommandRatelimitTypes } from '../constants'; import { Command, Context } from '../command'; import { InteractionCommand, InteractionCommandOption, InteractionContext } from '../interaction'; export declare const KEY_SPLITTER = ":"; export declare type CommandRatelimitCustomType = (context: Context | InteractionContext) => string; /** * Command Ratelimit Options * @category Command Ratelimit Options */ export interface CommandRatelimitOptions { duration?: number; key?: string; limit?: number; type?: CommandRatelimitTypes | string | CommandRatelimitCustomType; } /** * Command Ratelimit Item * @category Command Ratelimit */ export interface CommandRatelimitItem { key: string; replied: boolean; start: number; timeout: Timers.Timeout; usages: number; } /** * Command Ratelimit Options and Cache * @category Command Ratelimit */ export declare class CommandRatelimit { command?: Command | InteractionCommand | InteractionCommandOption; duration: number; key?: string; limit: number; type: CommandRatelimitTypes | CommandRatelimitCustomType; constructor(options?: boolean | CommandRatelimitOptions | CommandRatelimit, command?: Command | InteractionCommand | InteractionCommandOption); get uniqueKey(): string; createKey(context: Context | InteractionContext): string; } export declare class CommandRatelimiter { readonly cache: BaseCollection<string, CommandRatelimitItem>; getExceeded(context: Context | InteractionContext, ratelimits: Array<CommandRatelimit>, now?: number): Array<{ item: CommandRatelimitItem; ratelimit: CommandRatelimit; remaining: number; }>; getOrCreate(context: Context | InteractionContext, ratelimit: CommandRatelimit): CommandRatelimitItem; }