@whanext/core 0.8.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -0
- package/README.md +198 -44
- package/dist/index.d.ts +316 -85
- package/dist/index.js +955 -160
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -147,33 +147,6 @@ interface StickerContent {
|
|
|
147
147
|
}
|
|
148
148
|
type MessageContent = TextContent | ImageContent | VideoContent | AudioContent | StickerContent;
|
|
149
149
|
|
|
150
|
-
interface CommandDefinition {
|
|
151
|
-
name: string;
|
|
152
|
-
description: string;
|
|
153
|
-
aliases?: readonly string[];
|
|
154
|
-
onlyGroup?: boolean;
|
|
155
|
-
onlyPrivate?: boolean;
|
|
156
|
-
onlyAdmin?: boolean;
|
|
157
|
-
botMustBeAdmin?: boolean;
|
|
158
|
-
execute(message: Message, args: ArgsParser): void | Promise<void>;
|
|
159
|
-
}
|
|
160
|
-
declare function defineCommand<const Command extends CommandDefinition>(command: Command): Command;
|
|
161
|
-
declare function defineCommands<const Commands extends readonly CommandDefinition[]>(...commands: Commands): Commands;
|
|
162
|
-
|
|
163
|
-
type WhaNextErrorCode = 'AUTH_INVALID_PHONE' | 'AUTH_EXPIRED' | 'CONNECTION_CLOSED' | 'CONNECTION_FAILED' | 'GROUP_NOT_FOUND' | 'MEMBER_NOT_FOUND' | 'BOT_NOT_ADMIN' | 'MESSAGE_NOT_FOUND' | 'MEDIA_NOT_AVAILABLE' | 'MUTE_DISABLED' | 'STORAGE_ERROR' | 'ARGUMENT_MISSING' | 'ARGUMENT_INVALID' | 'COMMAND_NOT_ALLOWED' | 'COMMAND_LOAD_FAILED' | 'PROVIDER_ERROR' | 'UNKNOWN_ERROR';
|
|
164
|
-
interface WhaNextErrorOptions {
|
|
165
|
-
cause?: unknown;
|
|
166
|
-
context?: Readonly<Record<string, unknown>>;
|
|
167
|
-
recoverable?: boolean;
|
|
168
|
-
}
|
|
169
|
-
declare class WhaNextError extends Error {
|
|
170
|
-
readonly code: WhaNextErrorCode;
|
|
171
|
-
readonly context: Readonly<Record<string, unknown>>;
|
|
172
|
-
readonly recoverable: boolean;
|
|
173
|
-
constructor(code: WhaNextErrorCode, message: string, options?: WhaNextErrorOptions);
|
|
174
|
-
}
|
|
175
|
-
declare function toWhaNextError(error: unknown, context?: Readonly<Record<string, unknown>>): WhaNextError;
|
|
176
|
-
|
|
177
150
|
type GroupAccess = 'open' | 'closed';
|
|
178
151
|
type GroupRole = 'member' | 'admin' | 'owner';
|
|
179
152
|
type GroupAddressingMode = 'lid' | 'pn';
|
|
@@ -286,47 +259,75 @@ declare class GroupService {
|
|
|
286
259
|
invalidate(groupId: string): Promise<void>;
|
|
287
260
|
}
|
|
288
261
|
|
|
289
|
-
|
|
290
|
-
prefix?: string;
|
|
291
|
-
onError?: (error: WhaNextError, message: Message) => void | Promise<void>;
|
|
292
|
-
}
|
|
293
|
-
declare class CommandRouter {
|
|
262
|
+
declare class UserService {
|
|
294
263
|
#private;
|
|
295
|
-
constructor(group: GroupService
|
|
296
|
-
|
|
297
|
-
|
|
264
|
+
constructor(group: GroupService);
|
|
265
|
+
resolve(message: Message, args: ArgsParser): Promise<User>;
|
|
266
|
+
from(identity: string): User;
|
|
298
267
|
}
|
|
299
268
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
timestamp: string;
|
|
305
|
-
level: Exclude<LogLevel, 'silent'>;
|
|
306
|
-
scope: string;
|
|
307
|
-
message: string;
|
|
308
|
-
context: LogContext;
|
|
269
|
+
interface BaseOption<TKind extends string> {
|
|
270
|
+
kind: TKind;
|
|
271
|
+
description: string;
|
|
272
|
+
required?: boolean;
|
|
309
273
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
writer?: LogWriter;
|
|
315
|
-
scope?: string;
|
|
316
|
-
redact?: readonly string[];
|
|
274
|
+
interface StringOption extends BaseOption<'string'> {
|
|
275
|
+
rest?: boolean;
|
|
276
|
+
minLength?: number;
|
|
277
|
+
maxLength?: number;
|
|
317
278
|
}
|
|
318
|
-
|
|
319
|
-
|
|
279
|
+
interface NumberOption extends BaseOption<'number'> {
|
|
280
|
+
min?: number;
|
|
281
|
+
max?: number;
|
|
282
|
+
}
|
|
283
|
+
interface BooleanOption extends BaseOption<'boolean'> {
|
|
284
|
+
}
|
|
285
|
+
interface UserOption extends BaseOption<'user'> {
|
|
286
|
+
}
|
|
287
|
+
interface DurationOption extends BaseOption<'duration'> {
|
|
288
|
+
}
|
|
289
|
+
interface EnumOption<Values extends readonly string[] = readonly string[]> extends BaseOption<'enum'> {
|
|
290
|
+
values: Values;
|
|
291
|
+
}
|
|
292
|
+
type CommandOptionDefinition = StringOption | NumberOption | BooleanOption | UserOption | DurationOption | EnumOption;
|
|
293
|
+
type CommandOptionSchema = Readonly<Record<string, CommandOptionDefinition>>;
|
|
294
|
+
type RawOptionValue<Definition extends CommandOptionDefinition> = Definition extends StringOption ? string : Definition extends NumberOption ? number : Definition extends BooleanOption ? boolean : Definition extends UserOption ? User : Definition extends DurationOption ? number | undefined : Definition extends EnumOption<infer Values> ? Values[number] : never;
|
|
295
|
+
type CommandOptionValue<Definition extends CommandOptionDefinition> = Definition['required'] extends true ? RawOptionValue<Definition> : RawOptionValue<Definition> | undefined;
|
|
296
|
+
type CommandOptionValues<Schema extends CommandOptionSchema> = {
|
|
297
|
+
readonly [Name in keyof Schema]: CommandOptionValue<Schema[Name]>;
|
|
298
|
+
};
|
|
299
|
+
declare const option: {
|
|
300
|
+
string<const Definition extends Omit<StringOption, "kind">>(definition: Definition): {
|
|
301
|
+
kind: "string";
|
|
302
|
+
} & Definition;
|
|
303
|
+
number<const Definition extends Omit<NumberOption, "kind">>(definition: Definition): {
|
|
304
|
+
kind: "number";
|
|
305
|
+
} & Definition;
|
|
306
|
+
boolean<const Definition extends Omit<BooleanOption, "kind">>(definition: Definition): {
|
|
307
|
+
kind: "boolean";
|
|
308
|
+
} & Definition;
|
|
309
|
+
user<const Definition extends Omit<UserOption, "kind">>(definition: Definition): {
|
|
310
|
+
kind: "user";
|
|
311
|
+
} & Definition;
|
|
312
|
+
duration<const Definition extends Omit<DurationOption, "kind">>(definition: Definition): {
|
|
313
|
+
kind: "duration";
|
|
314
|
+
} & Definition;
|
|
315
|
+
enum<const Values extends readonly string[], const Definition extends Omit<EnumOption<Values>, "kind" | "values">>(values: Values, definition: Definition): {
|
|
316
|
+
kind: "enum";
|
|
317
|
+
values: Values;
|
|
318
|
+
} & Definition;
|
|
319
|
+
};
|
|
320
|
+
declare class ParsedCommandOptions<Schema extends CommandOptionSchema = CommandOptionSchema> {
|
|
320
321
|
#private;
|
|
321
|
-
constructor(
|
|
322
|
-
get
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
322
|
+
constructor(values: CommandOptionValues<Schema>);
|
|
323
|
+
get<Name extends keyof Schema>(name: Name): CommandOptionValue<Schema[Name]>;
|
|
324
|
+
string<Name extends keyof Schema>(name: Name): CommandOptionValue<Schema[Name]>;
|
|
325
|
+
number<Name extends keyof Schema>(name: Name): CommandOptionValue<Schema[Name]>;
|
|
326
|
+
boolean<Name extends keyof Schema>(name: Name): CommandOptionValue<Schema[Name]>;
|
|
327
|
+
user<Name extends keyof Schema>(name: Name): CommandOptionValue<Schema[Name]>;
|
|
328
|
+
duration<Name extends keyof Schema>(name: Name): CommandOptionValue<Schema[Name]>;
|
|
329
|
+
enum<Name extends keyof Schema>(name: Name): CommandOptionValue<Schema[Name]>;
|
|
330
|
+
toJSON(): CommandOptionValues<Schema>;
|
|
330
331
|
}
|
|
331
332
|
|
|
332
333
|
interface StoredMute {
|
|
@@ -437,11 +438,247 @@ declare class MessageService {
|
|
|
437
438
|
text(chatId: string, text: string, mentions?: MentionTarget[]): Promise<SentMessage>;
|
|
438
439
|
}
|
|
439
440
|
|
|
440
|
-
|
|
441
|
+
interface CommandCatalogView {
|
|
442
|
+
readonly prefix: string;
|
|
443
|
+
readonly size: number;
|
|
444
|
+
catalog(options?: {
|
|
445
|
+
category?: string;
|
|
446
|
+
includeHidden?: boolean;
|
|
447
|
+
}): readonly RegisteredCommand[];
|
|
448
|
+
categories(): readonly string[];
|
|
449
|
+
has(path: string): boolean;
|
|
450
|
+
find(path: string): RegisteredCommand | undefined;
|
|
451
|
+
}
|
|
452
|
+
interface CommandRuntimeServices {
|
|
453
|
+
messages: MessageService;
|
|
454
|
+
media: MediaService;
|
|
455
|
+
groups: GroupService;
|
|
456
|
+
members: MemberService;
|
|
457
|
+
chats: ChatService;
|
|
458
|
+
users: UserService;
|
|
459
|
+
mute: MuteService;
|
|
460
|
+
}
|
|
461
|
+
interface CommandChatContext {
|
|
462
|
+
id: string;
|
|
463
|
+
isGroup: boolean;
|
|
464
|
+
}
|
|
465
|
+
interface CommandGroupContext {
|
|
466
|
+
id: string;
|
|
467
|
+
metadata(refresh?: boolean): ReturnType<GroupService['metadata']>;
|
|
468
|
+
isUserAdmin(): Promise<boolean>;
|
|
469
|
+
isBotAdmin(): Promise<boolean>;
|
|
470
|
+
}
|
|
471
|
+
interface ReplyOptions {
|
|
472
|
+
deleteAfterMs?: number;
|
|
473
|
+
}
|
|
474
|
+
interface CommandContext<Schema extends CommandOptionSchema = CommandOptionSchema> extends Message {
|
|
475
|
+
readonly message: Message;
|
|
476
|
+
readonly user: User;
|
|
477
|
+
readonly chat: CommandChatContext;
|
|
478
|
+
readonly group: CommandGroupContext | undefined;
|
|
479
|
+
readonly command: RegisteredCommand;
|
|
480
|
+
readonly commands: CommandCatalogView;
|
|
481
|
+
readonly prefix: string;
|
|
482
|
+
readonly options: ParsedCommandOptions<Schema>;
|
|
483
|
+
readonly args: ArgsParser;
|
|
484
|
+
readonly locale: string | undefined;
|
|
485
|
+
readonly signal: AbortSignal;
|
|
486
|
+
readonly client: CommandRuntimeServices;
|
|
487
|
+
readonly messages: MessageService;
|
|
488
|
+
readonly mediaService: MediaService;
|
|
489
|
+
readonly groups: GroupService;
|
|
490
|
+
readonly members: MemberService;
|
|
491
|
+
readonly chats: ChatService;
|
|
492
|
+
readonly users: UserService;
|
|
493
|
+
readonly muteService: MuteService;
|
|
494
|
+
reply(content: string | MessageContent, options?: ReplyOptions): Promise<SentMessage>;
|
|
495
|
+
defer(content?: string | MessageContent): Promise<DeferredReply>;
|
|
496
|
+
edit(content: string): Promise<SentMessage>;
|
|
497
|
+
react(emoji: string): Promise<SentMessage>;
|
|
498
|
+
unreact(): Promise<SentMessage>;
|
|
499
|
+
delete(): Promise<void>;
|
|
500
|
+
deleteReply(options?: ReplyOptions): Promise<void>;
|
|
501
|
+
}
|
|
502
|
+
declare class DeferredReply {
|
|
441
503
|
#private;
|
|
442
|
-
constructor(
|
|
443
|
-
|
|
444
|
-
|
|
504
|
+
constructor(messages: MessageService, message: SentMessage, onEdit: (message: SentMessage) => void);
|
|
505
|
+
edit(content: string): Promise<SentMessage>;
|
|
506
|
+
delete(): Promise<void>;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
type WhaNextErrorCode = 'AUTH_INVALID_PHONE' | 'AUTH_EXPIRED' | 'CONNECTION_CLOSED' | 'CONNECTION_FAILED' | 'GROUP_NOT_FOUND' | 'MEMBER_NOT_FOUND' | 'BOT_NOT_ADMIN' | 'MESSAGE_NOT_FOUND' | 'MEDIA_NOT_AVAILABLE' | 'MUTE_DISABLED' | 'STORAGE_ERROR' | 'ARGUMENT_MISSING' | 'ARGUMENT_INVALID' | 'COMMAND_NOT_ALLOWED' | 'COMMAND_COOLDOWN' | 'COMMAND_BUSY' | 'COMMAND_LOAD_FAILED' | 'PROVIDER_ERROR' | 'UNKNOWN_ERROR';
|
|
510
|
+
interface WhaNextErrorOptions {
|
|
511
|
+
cause?: unknown;
|
|
512
|
+
context?: Readonly<Record<string, unknown>>;
|
|
513
|
+
recoverable?: boolean;
|
|
514
|
+
}
|
|
515
|
+
declare class WhaNextError extends Error {
|
|
516
|
+
readonly code: WhaNextErrorCode;
|
|
517
|
+
readonly context: Readonly<Record<string, unknown>>;
|
|
518
|
+
readonly recoverable: boolean;
|
|
519
|
+
constructor(code: WhaNextErrorCode, message: string, options?: WhaNextErrorOptions);
|
|
520
|
+
}
|
|
521
|
+
declare function toWhaNextError(error: unknown, context?: Readonly<Record<string, unknown>>): WhaNextError;
|
|
522
|
+
|
|
523
|
+
interface GuardResult {
|
|
524
|
+
allowed: boolean;
|
|
525
|
+
code?: WhaNextErrorCode;
|
|
526
|
+
message?: string;
|
|
527
|
+
}
|
|
528
|
+
type CommandGuard = (context: CommandContext) => boolean | void | GuardResult | Promise<boolean | void | GuardResult>;
|
|
529
|
+
declare const guards: {
|
|
530
|
+
group(): CommandGuard;
|
|
531
|
+
private(): CommandGuard;
|
|
532
|
+
userAdmin(): CommandGuard;
|
|
533
|
+
botAdmin(): CommandGuard;
|
|
534
|
+
botEnabled(check: (context: CommandContext) => boolean | Promise<boolean>): CommandGuard;
|
|
535
|
+
custom(guard: CommandGuard): CommandGuard;
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
type CommandScope = 'global' | 'user' | 'chat' | 'user-chat' | 'user-group';
|
|
539
|
+
type ConcurrencyStrategy = 'parallel' | 'reject' | 'queue' | 'replace';
|
|
540
|
+
interface CommandCooldown {
|
|
541
|
+
durationMs: number;
|
|
542
|
+
scope?: CommandScope;
|
|
543
|
+
}
|
|
544
|
+
interface CommandConcurrency {
|
|
545
|
+
max?: number;
|
|
546
|
+
scope?: CommandScope;
|
|
547
|
+
strategy?: ConcurrencyStrategy;
|
|
548
|
+
}
|
|
549
|
+
interface CommandLocalization {
|
|
550
|
+
name?: string;
|
|
551
|
+
aliases?: readonly string[];
|
|
552
|
+
description?: string;
|
|
553
|
+
}
|
|
554
|
+
type CommandMiddleware = (context: CommandContext, next: () => Promise<void>) => void | Promise<void>;
|
|
555
|
+
interface CommandHooks {
|
|
556
|
+
beforeExecute?: (context: CommandContext) => void | Promise<void>;
|
|
557
|
+
afterExecute?: (context: CommandContext) => void | Promise<void>;
|
|
558
|
+
onError?: (context: CommandContext, error: Error) => void | Promise<void>;
|
|
559
|
+
}
|
|
560
|
+
interface CommandMetadata {
|
|
561
|
+
name: string;
|
|
562
|
+
description: string;
|
|
563
|
+
aliases?: readonly string[];
|
|
564
|
+
category?: string;
|
|
565
|
+
usage?: string;
|
|
566
|
+
examples?: readonly string[];
|
|
567
|
+
hidden?: boolean;
|
|
568
|
+
localizations?: Readonly<Record<string, CommandLocalization>>;
|
|
569
|
+
guards?: readonly CommandGuard[];
|
|
570
|
+
middleware?: readonly CommandMiddleware[];
|
|
571
|
+
cooldown?: CommandCooldown;
|
|
572
|
+
concurrency?: CommandConcurrency;
|
|
573
|
+
hooks?: CommandHooks;
|
|
574
|
+
onlyGroup?: boolean;
|
|
575
|
+
onlyPrivate?: boolean;
|
|
576
|
+
onlyAdmin?: boolean;
|
|
577
|
+
botMustBeAdmin?: boolean;
|
|
578
|
+
}
|
|
579
|
+
interface ExecutableCommandDefinition<Schema extends CommandOptionSchema = CommandOptionSchema> extends CommandMetadata {
|
|
580
|
+
options?: Schema;
|
|
581
|
+
execute(context: CommandContext<Schema>, args: ArgsParser): void | Promise<void>;
|
|
582
|
+
}
|
|
583
|
+
interface CommandGroupDefinition extends CommandMetadata {
|
|
584
|
+
subcommands: readonly CommandDefinition[];
|
|
585
|
+
}
|
|
586
|
+
type CommandDefinition<Schema extends CommandOptionSchema = CommandOptionSchema> = ExecutableCommandDefinition<Schema> | CommandGroupDefinition;
|
|
587
|
+
interface RegisteredCommand {
|
|
588
|
+
definition: ExecutableCommandDefinition;
|
|
589
|
+
root: CommandDefinition;
|
|
590
|
+
path: readonly string[];
|
|
591
|
+
aliases: readonly string[];
|
|
592
|
+
category: string;
|
|
593
|
+
}
|
|
594
|
+
declare function defineCommand<const Schema extends CommandOptionSchema = CommandOptionSchema>(command: ExecutableCommandDefinition<Schema>): ExecutableCommandDefinition<Schema>;
|
|
595
|
+
declare function defineSubcommand<const Schema extends CommandOptionSchema = CommandOptionSchema>(command: ExecutableCommandDefinition<Schema>): ExecutableCommandDefinition<Schema>;
|
|
596
|
+
declare function defineCommandGroup<const Group extends CommandGroupDefinition>(group: Group): Group;
|
|
597
|
+
declare function defineCommands<const Commands extends readonly CommandDefinition[]>(...commands: Commands): Commands;
|
|
598
|
+
declare function isCommandGroup(definition: CommandDefinition): definition is CommandGroupDefinition;
|
|
599
|
+
|
|
600
|
+
interface CommandRegistrar {
|
|
601
|
+
command(definition: CommandDefinition): unknown;
|
|
602
|
+
}
|
|
603
|
+
interface LoadCommandsOptions {
|
|
604
|
+
extensions?: readonly string[];
|
|
605
|
+
recursive?: boolean;
|
|
606
|
+
}
|
|
607
|
+
interface LoadCommandsResult {
|
|
608
|
+
loaded: readonly string[];
|
|
609
|
+
skipped: readonly string[];
|
|
610
|
+
commands: readonly LoadedCommand[];
|
|
611
|
+
}
|
|
612
|
+
interface LoadedCommand {
|
|
613
|
+
name: string;
|
|
614
|
+
filePath: string;
|
|
615
|
+
}
|
|
616
|
+
declare function loadCommands(registrar: CommandRegistrar, dirPath: string | URL, options?: LoadCommandsOptions): Promise<LoadCommandsResult>;
|
|
617
|
+
|
|
618
|
+
interface RouterOptions {
|
|
619
|
+
prefix?: string;
|
|
620
|
+
onError?: (error: WhaNextError, message: Message) => void | Promise<void>;
|
|
621
|
+
onCommandError?: CommandErrorHandler;
|
|
622
|
+
beforeExecute?: (context: CommandContext) => void | Promise<void>;
|
|
623
|
+
afterExecute?: (context: CommandContext) => void | Promise<void>;
|
|
624
|
+
}
|
|
625
|
+
interface CommandCatalogOptions {
|
|
626
|
+
category?: string;
|
|
627
|
+
includeHidden?: boolean;
|
|
628
|
+
}
|
|
629
|
+
interface CommandHelpOptions extends CommandCatalogOptions {
|
|
630
|
+
title?: string;
|
|
631
|
+
}
|
|
632
|
+
type CommandErrorHandler = (context: CommandContext, error: WhaNextError) => void | Promise<void>;
|
|
633
|
+
declare class CommandRouter {
|
|
634
|
+
#private;
|
|
635
|
+
constructor(services: CommandRuntimeServices, options?: RouterOptions);
|
|
636
|
+
constructor(group: GroupService, options?: RouterOptions);
|
|
637
|
+
get prefix(): string;
|
|
638
|
+
get size(): number;
|
|
639
|
+
command(definition: CommandDefinition): this;
|
|
640
|
+
load(dirPath: string | URL, options?: LoadCommandsOptions): Promise<LoadCommandsResult>;
|
|
641
|
+
use(middleware: CommandMiddleware): this;
|
|
642
|
+
onError(handler: CommandErrorHandler): () => void;
|
|
643
|
+
catalog(options?: CommandCatalogOptions): readonly RegisteredCommand[];
|
|
644
|
+
categories(): readonly string[];
|
|
645
|
+
has(path: string): boolean;
|
|
646
|
+
values(): readonly RegisteredCommand[];
|
|
647
|
+
find(path: string): RegisteredCommand | undefined;
|
|
648
|
+
help(context: CommandContext, options?: CommandHelpOptions): Promise<SentMessage>;
|
|
649
|
+
dispatch(message: Message): Promise<boolean>;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
653
|
+
type LogFormat = 'pretty' | 'json';
|
|
654
|
+
type LogContext = Readonly<Record<string, unknown>>;
|
|
655
|
+
interface LogEntry {
|
|
656
|
+
timestamp: string;
|
|
657
|
+
level: Exclude<LogLevel, 'silent'>;
|
|
658
|
+
scope: string;
|
|
659
|
+
message: string;
|
|
660
|
+
context: LogContext;
|
|
661
|
+
}
|
|
662
|
+
type LogWriter = (entry: LogEntry) => unknown;
|
|
663
|
+
interface LoggerOptions {
|
|
664
|
+
level?: LogLevel;
|
|
665
|
+
format?: LogFormat;
|
|
666
|
+
writer?: LogWriter;
|
|
667
|
+
scope?: string;
|
|
668
|
+
redact?: readonly string[];
|
|
669
|
+
}
|
|
670
|
+
type LoggerConfig = LogLevel | LoggerOptions;
|
|
671
|
+
declare class Logger {
|
|
672
|
+
#private;
|
|
673
|
+
constructor(config?: LoggerConfig);
|
|
674
|
+
get level(): LogLevel;
|
|
675
|
+
setLevel(level: LogLevel): this;
|
|
676
|
+
isEnabled(level: Exclude<LogLevel, 'silent'>): boolean;
|
|
677
|
+
child(scope: string): Logger;
|
|
678
|
+
debug(message: string, context?: LogContext): void;
|
|
679
|
+
info(message: string, context?: LogContext): void;
|
|
680
|
+
warn(message: string, context?: LogContext): void;
|
|
681
|
+
error(message: string, context?: LogContext): void;
|
|
445
682
|
}
|
|
446
683
|
|
|
447
684
|
interface AppEvents {
|
|
@@ -484,6 +721,7 @@ declare class WhaNextApp {
|
|
|
484
721
|
readonly user: UserService;
|
|
485
722
|
readonly mute: MuteService;
|
|
486
723
|
readonly logger: Logger;
|
|
724
|
+
readonly commands: CommandRouter;
|
|
487
725
|
constructor(provider: WhatsAppProvider, options?: WhaNextAppOptions, logger?: Logger);
|
|
488
726
|
get state(): ConnectionUpdate['state'];
|
|
489
727
|
get isReady(): boolean;
|
|
@@ -521,6 +759,15 @@ interface CreateOptions {
|
|
|
521
759
|
}
|
|
522
760
|
declare function create(options?: CreateOptions): Promise<WhaNextApp>;
|
|
523
761
|
|
|
762
|
+
interface MemoryCacheStats {
|
|
763
|
+
size: number;
|
|
764
|
+
maxEntries: number;
|
|
765
|
+
hits: number;
|
|
766
|
+
misses: number;
|
|
767
|
+
sets: number;
|
|
768
|
+
evictions: number;
|
|
769
|
+
expirations: number;
|
|
770
|
+
}
|
|
524
771
|
declare class MemoryCache implements CacheStore {
|
|
525
772
|
#private;
|
|
526
773
|
constructor(options?: {
|
|
@@ -530,26 +777,10 @@ declare class MemoryCache implements CacheStore {
|
|
|
530
777
|
set<T>(key: string, value: T, ttlMs?: number): Promise<void>;
|
|
531
778
|
delete(key: string): Promise<void>;
|
|
532
779
|
clear(): Promise<void>;
|
|
780
|
+
prune(now?: number): number;
|
|
781
|
+
stats(): Readonly<MemoryCacheStats>;
|
|
533
782
|
}
|
|
534
783
|
|
|
535
|
-
interface CommandRegistrar {
|
|
536
|
-
command(definition: CommandDefinition): unknown;
|
|
537
|
-
}
|
|
538
|
-
interface LoadCommandsOptions {
|
|
539
|
-
extensions?: readonly string[];
|
|
540
|
-
recursive?: boolean;
|
|
541
|
-
}
|
|
542
|
-
interface LoadCommandsResult {
|
|
543
|
-
loaded: readonly string[];
|
|
544
|
-
skipped: readonly string[];
|
|
545
|
-
commands: readonly LoadedCommand[];
|
|
546
|
-
}
|
|
547
|
-
interface LoadedCommand {
|
|
548
|
-
name: string;
|
|
549
|
-
filePath: string;
|
|
550
|
-
}
|
|
551
|
-
declare function loadCommands(registrar: CommandRegistrar, dirPath: string, options?: LoadCommandsOptions): Promise<LoadCommandsResult>;
|
|
552
|
-
|
|
553
784
|
declare class SqliteMuteStore implements MuteStore {
|
|
554
785
|
#private;
|
|
555
786
|
constructor(path?: string);
|
|
@@ -560,4 +791,4 @@ declare class SqliteMuteStore implements MuteStore {
|
|
|
560
791
|
close(): void;
|
|
561
792
|
}
|
|
562
793
|
|
|
563
|
-
export { type AddMuteOptions, type AddMuteResult, type AppEvents, type AppHealth, type AppHealthStatus, ArgsParser, type AudioContent, Browser, type CacheOptions, type CacheStore, type CallEvent, type CallStatus, type ChangeResult, type CommandDefinition, type CommandRegistrar, CommandRouter, type ConnectionState, type ConnectionUpdate, type CreateOptions, type DownloadedMedia, type GroupAccess, type GroupAddressingMode, type GroupParticipant, type GroupParticipantAction, type GroupParticipantsChanged, type GroupRole, type GroupSnapshot, type ImageContent, type InviteResult, type LoadCommandsOptions, type LoadCommandsResult, type LoadedCommand, type LogContext, type LogEntry, type LogFormat, type LogLevel, type LogWriter, Logger, type LoggerConfig, type LoggerOptions, type LoginOptions, type MediaKind, type MediaSource, type MemberActionState, MemoryCache, type MentionTarget, type Message, type MessageContent, type MessageKey, type MessageMedia, type MuteChangeResult, type MuteEnforcement, type MuteOptions, type MuteRecord, MuteService, type MuteStore, type ParticipantUpdateResult, type PresenceState, type QuotedMessage, type ReconnectOptions, type RemoveMuteResult, type RouterOptions, type SentMessage, SqliteMuteStore, type StickerContent, type StoredMute, type TextContent, User, type UserData, type VideoContent, WhaNextApp, WhaNextError, type WhaNextErrorCode, type WhatsAppProvider, create, defineCommand, defineCommands, loadCommands, toWhaNextError };
|
|
794
|
+
export { type AddMuteOptions, type AddMuteResult, type AppEvents, type AppHealth, type AppHealthStatus, ArgsParser, type AudioContent, type BooleanOption, Browser, type CacheOptions, type CacheStore, type CallEvent, type CallStatus, type ChangeResult, type CommandCatalogOptions, type CommandCatalogView, type CommandChatContext, type CommandConcurrency, type CommandContext, type CommandCooldown, type CommandDefinition, type CommandErrorHandler, type CommandGroupContext, type CommandGroupDefinition, type CommandGuard, type CommandHelpOptions, type CommandHooks, type CommandLocalization, type CommandMetadata, type CommandMiddleware, type CommandOptionDefinition, type CommandOptionSchema, type CommandOptionValue, type CommandOptionValues, type CommandRegistrar, CommandRouter, type CommandRuntimeServices, type CommandScope, type ConcurrencyStrategy, type ConnectionState, type ConnectionUpdate, type CreateOptions, DeferredReply, type DownloadedMedia, type DurationOption, type EnumOption, type ExecutableCommandDefinition, type GroupAccess, type GroupAddressingMode, type GroupParticipant, type GroupParticipantAction, type GroupParticipantsChanged, type GroupRole, type GroupSnapshot, type GuardResult, type ImageContent, type InviteResult, type LoadCommandsOptions, type LoadCommandsResult, type LoadedCommand, type LogContext, type LogEntry, type LogFormat, type LogLevel, type LogWriter, Logger, type LoggerConfig, type LoggerOptions, type LoginOptions, type MediaKind, type MediaSource, type MemberActionState, MemoryCache, type MemoryCacheStats, type MentionTarget, type Message, type MessageContent, type MessageKey, type MessageMedia, type MuteChangeResult, type MuteEnforcement, type MuteOptions, type MuteRecord, MuteService, type MuteStore, type NumberOption, ParsedCommandOptions, type ParticipantUpdateResult, type PresenceState, type QuotedMessage, type ReconnectOptions, type RegisteredCommand, type RemoveMuteResult, type ReplyOptions, type RouterOptions, type SentMessage, SqliteMuteStore, type StickerContent, type StoredMute, type StringOption, type TextContent, User, type UserData, type UserOption, type VideoContent, WhaNextApp, WhaNextError, type WhaNextErrorCode, type WhatsAppProvider, create, defineCommand, defineCommandGroup, defineCommands, defineSubcommand, guards, isCommandGroup, loadCommands, option, toWhaNextError };
|