/** * API 速率限制器 * 防止触发平台的速率限制 */ export interface RateLimiterOptions { /** 时间窗口内允许的最大请求数 */ maxRequests: number; /** 时间窗口大小(毫秒) */ windowMs: number; /** 请求之间的最小间隔(毫秒) */ minInterval?: number; /** 超出限制时是否排队等待 */ queueExcess?: boolean; /** 队列最大长度 */ maxQueueSize?: number; /** 队列中请求的最大等待时间(毫秒),默认 30000 */ requestTimeout?: number; } /** * 令牌桶速率限制器 */ export declare class RateLimiter { private tokens; private lastRefill; private queue; private processing; private lastRequest; private readonly maxRequests; private readonly windowMs; private readonly minInterval; private readonly queueExcess; private readonly maxQueueSize; private readonly requestTimeout; constructor(options: RateLimiterOptions); /** * 补充令牌 */ private refillTokens; /** * 尝试获取令牌 */ private tryAcquire; /** * 计算需要等待的时间 */ private getWaitTime; /** * 执行受限函数 */ execute(fn: () => Promise): Promise; /** * 处理队列 */ private processQueue; /** * 获取当前状态 */ getStatus(): { availableTokens: number; queueLength: number; isProcessing: boolean; }; /** * 清空队列 */ clearQueue(): void; private sleep; } /** * 速率限制错误 */ export declare class RateLimitError extends Error { constructor(message: string); } /** * 平台速率限制预设 */ export declare const RateLimitPresets: { /** Discord - 50 请求/秒 */ discord: RateLimiterOptions; /** Telegram - 30 消息/秒(群组 20/分钟) */ telegram: RateLimiterOptions; /** QQ - 5 消息/秒 */ qq: RateLimiterOptions; /** 通用 - 10 请求/秒 */ default: RateLimiterOptions; }; /** * 创建带速率限制的函数包装器 */ export declare function withRateLimit Promise>(fn: T, limiter: RateLimiter): T;