import { Dispatcher } from '../dispatcher.js'; import { StateService } from './service.js'; import { MtcuteError } from '@mtcute/core'; /** * Error thrown by `.rateLimit()` */ export declare class RateLimitError extends MtcuteError { readonly reset: number; constructor(reset: number); } /** * State of the current update. * * @template State Type that represents the state * @template SceneName Possible scene names */ export declare class UpdateState { private _key; private _localKey; private _storage; private _scene; private _scoped?; private _cached?; private _localStorage; private _localKeyBase; constructor(storage: StateService, key: string, scene: string | null, scoped?: boolean, customStorage?: StateService, customKey?: string); /** Name of the current scene */ get scene(): string | null; private _updateLocalKey; /** * Retrieve the state from the storage, falling back to default * if not found * * @param fallback Default state value * @param force Whether to ignore cached state (def. `false`) */ get(fallback: State | (() => State), force?: boolean): Promise; /** * Retrieve the state from the storage, falling back to default * if not found * * @param fallback Default state value * @param force Whether to ignore cached state (def. `false`) */ get(fallback?: State | (() => State), force?: boolean): Promise; /** * Retrieve the state from the storage * * @param force Whether to ignore cached state (def. `false`) */ get(force?: boolean): Promise; /** * Set new state to the storage * * @param state New state * @param ttl TTL for the new state (in seconds) */ set(state: State, ttl?: number): Promise; /** * Merge the given object to the current state. * * > **Note**: If the storage currently has no state, * > then `fallback` must be provided. * * Basically a shorthand to calling `.get()`, * modifying and then calling `.set()` * * @param state State to be merged * @param fallback Default state * @param ttl TTL for the new state (in seconds) * @param forceLoad Whether to force load the old state from storage */ merge(state: Partial, params?: { fallback?: State | (() => State); ttl?: number; forceLoad?: boolean; }): Promise; /** * Delete the state from the storage */ delete(): Promise; /** * Enter some scene */ enter>(scene: Scene, params?: { /** * Initial state for the scene * * Note that this will only work if the scene uses the same key delegate as this state. */ with?: SceneState; /** TTL for the scene (in seconds) */ ttl?: number; /** * If currently in a scoped scene, whether to reset the state * * @default true */ reset?: boolean; }): Promise; /** * Exit from current scene to the root * * @param reset * Whether to reset scene state (only applicable in case this is a scoped scene) */ exit(reset?: boolean): Promise; /** * Rate limit some handler. * * When the rate limit exceeds, {@link RateLimitError} is thrown. * * This is a simple rate-limiting solution that uses * the same key as the state. If you need something more * sophisticated and/or customizable, you'll have to implement * your own rate-limiter. * * > **Note**: `key` is used to prefix the local key * > derived using the given key delegate. * * @param key Key of the rate limit * @param limit Maximum number of requests in `window` * @param window Window size in seconds * @returns Tuple containing the number of remaining and * unix time in ms when the user can try again */ rateLimit(key: string, limit: number, window: number): Promise<[number, number]>; /** * Throttle some handler. * * When the rate limit exceeds, this function waits for it to reset. * * This is a simple wrapper over {@link rateLimit}, and follows the same logic. * * > **Note**: `key` is used to prefix the local key * > derived using the given key delegate. * * @param key Key of the rate limit * @param limit Maximum number of requests in `window` * @param window Window size in seconds * @returns Tuple containing the number of remaining and * unix time in ms when the user can try again */ throttle(key: string, limit: number, window: number): Promise<[number, number]>; /** * Reset the rate limit * * @param key Key of the rate limit */ resetRateLimit(key: string): Promise; }