bakit 1.0.0-beta.2 → 1.0.0-beta.4
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.
|
@@ -33,13 +33,13 @@ type Context<Cached extends boolean = boolean, InGuild extends boolean = boolean
|
|
|
33
33
|
type CommandConstructor = new (...args: unknown[]) => object;
|
|
34
34
|
declare function use(command: RootCommandEntry): (target: CommandConstructor) => void;
|
|
35
35
|
declare function getRoot(constructor: CommandConstructor): RootCommandEntry | undefined;
|
|
36
|
-
declare function CommandFactory(options:
|
|
36
|
+
declare function CommandFactory(options: CreateCommandOptions<BaseCommandEntryOptions> | string): RootCommandEntry;
|
|
37
37
|
declare const Command: typeof CommandFactory & {
|
|
38
38
|
use: typeof use;
|
|
39
39
|
getRoot: typeof getRoot;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
declare enum
|
|
42
|
+
declare enum CommandHookExecutionState {
|
|
43
43
|
Main = "main",
|
|
44
44
|
Pre = "pre",
|
|
45
45
|
Post = "post",
|
|
@@ -47,7 +47,7 @@ declare enum HookExecutionState {
|
|
|
47
47
|
}
|
|
48
48
|
type CommandHookMethod = (ctx: Context, ...args: any[]) => Awaitable<void>;
|
|
49
49
|
interface CommandHook {
|
|
50
|
-
state:
|
|
50
|
+
state: CommandHookExecutionState;
|
|
51
51
|
method: CommandHookMethod;
|
|
52
52
|
entry: CommandEntry;
|
|
53
53
|
}
|
|
@@ -56,7 +56,7 @@ interface BaseCommandEntryOptions {
|
|
|
56
56
|
description: string;
|
|
57
57
|
nsfw?: boolean;
|
|
58
58
|
}
|
|
59
|
-
type
|
|
59
|
+
type CreateCommandOptions<T extends BaseCommandEntryOptions> = SetOptional<T, "description"> | string;
|
|
60
60
|
declare const HOOKS_KEY: unique symbol;
|
|
61
61
|
declare abstract class BaseCommandEntry {
|
|
62
62
|
options: BaseCommandEntryOptions;
|
|
@@ -74,7 +74,7 @@ declare abstract class BaseCommandEntry {
|
|
|
74
74
|
}
|
|
75
75
|
declare abstract class BaseCommandGroupEntry extends BaseCommandEntry {
|
|
76
76
|
children: Collection<string, CommandGroupEntry | SubcommandEntry>;
|
|
77
|
-
subcommand(options:
|
|
77
|
+
subcommand(options: CreateCommandOptions<BaseCommandEntryOptions>): SubcommandEntry;
|
|
78
78
|
}
|
|
79
79
|
declare class CommandGroupEntry extends BaseCommandGroupEntry {
|
|
80
80
|
options: BaseCommandEntryOptions;
|
|
@@ -85,7 +85,7 @@ declare class CommandGroupEntry extends BaseCommandGroupEntry {
|
|
|
85
85
|
declare class RootCommandEntry extends BaseCommandGroupEntry {
|
|
86
86
|
options: BaseCommandEntryOptions;
|
|
87
87
|
constructor(options: BaseCommandEntryOptions);
|
|
88
|
-
group(options:
|
|
88
|
+
group(options: CreateCommandOptions<BaseCommandEntryOptions>): CommandGroupEntry;
|
|
89
89
|
}
|
|
90
90
|
declare class SubcommandEntry extends BaseCommandEntry {
|
|
91
91
|
options: BaseCommandEntryOptions;
|
|
@@ -201,4 +201,4 @@ declare class BakitClient<Ready extends boolean = boolean> extends Client<Ready>
|
|
|
201
201
|
private createHookRecord;
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
export { Arg as A,
|
|
204
|
+
export { Arg as A, BakitClient as B, CommandHookExecutionState as C, CommandSyntaxError as D, type GetSyntaxErrorMessageFunction as G, HOOKS_KEY as H, type IntegerArgumentOptions as I, type MemberArgumentOptions as M, type NumberArgumentOptions as N, RootCommandEntry as R, type StringArgumentOptions as S, type UserArgumentOptions as U, type BakitClientOptions as a, ArgumentType as b, type BaseArgumentOptions as c, type ArgumentOptions as d, type CommandHookMethod as e, type CommandHook as f, type BaseCommandEntryOptions as g, type CreateCommandOptions as h, BaseCommandEntry as i, BaseCommandGroupEntry as j, CommandGroupEntry as k, SubcommandEntry as l, type CommandEntry as m, type CommandConstructor as n, CommandFactory as o, Command as p, CommandRegistry as q, type ChatInputContextSendOptions as r, type MessageContextSendOptions as s, type ContextSendOptions as t, BaseContext as u, ChatInputContext as v, MessageContext as w, type Context as x, CommandSyntaxErrorType as y, type CommandSyntaxErrorOptions as z };
|
package/dist/command/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { A as Arg, d as ArgumentOptions, b as ArgumentType, c as BaseArgumentOptions, i as BaseCommandEntry,
|
|
1
|
+
export { A as Arg, d as ArgumentOptions, b as ArgumentType, c as BaseArgumentOptions, i as BaseCommandEntry, g as BaseCommandEntryOptions, j as BaseCommandGroupEntry, u as BaseContext, v as ChatInputContext, r as ChatInputContextSendOptions, p as Command, n as CommandConstructor, m as CommandEntry, o as CommandFactory, k as CommandGroupEntry, f as CommandHook, C as CommandHookExecutionState, e as CommandHookMethod, q as CommandRegistry, x as Context, t as ContextSendOptions, h as CreateCommandOptions, H as HOOKS_KEY, I as IntegerArgumentOptions, M as MemberArgumentOptions, w as MessageContext, s as MessageContextSendOptions, N as NumberArgumentOptions, R as RootCommandEntry, S as StringArgumentOptions, l as SubcommandEntry, U as UserArgumentOptions } from '../BakitClient-CgtDS6Hr.js';
|
|
2
2
|
import 'discord.js';
|
|
3
3
|
import 'type-fest';
|
package/dist/command/index.js
CHANGED
|
@@ -106,13 +106,13 @@ var Arg = {
|
|
|
106
106
|
|
|
107
107
|
// src/command/CommandEntry.ts
|
|
108
108
|
import { Collection } from "discord.js";
|
|
109
|
-
var
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return
|
|
115
|
-
})(
|
|
109
|
+
var CommandHookExecutionState = /* @__PURE__ */ ((CommandHookExecutionState2) => {
|
|
110
|
+
CommandHookExecutionState2["Main"] = "main";
|
|
111
|
+
CommandHookExecutionState2["Pre"] = "pre";
|
|
112
|
+
CommandHookExecutionState2["Post"] = "post";
|
|
113
|
+
CommandHookExecutionState2["Error"] = "error";
|
|
114
|
+
return CommandHookExecutionState2;
|
|
115
|
+
})(CommandHookExecutionState || {});
|
|
116
116
|
var HOOKS_KEY = Symbol("hooks");
|
|
117
117
|
var BaseCommandEntry = class _BaseCommandEntry {
|
|
118
118
|
constructor(options) {
|
|
@@ -467,12 +467,10 @@ export {
|
|
|
467
467
|
Command,
|
|
468
468
|
CommandFactory,
|
|
469
469
|
CommandGroupEntry,
|
|
470
|
+
CommandHookExecutionState,
|
|
470
471
|
CommandRegistry,
|
|
471
472
|
HOOKS_KEY,
|
|
472
|
-
HookExecutionState,
|
|
473
473
|
MessageContext,
|
|
474
474
|
RootCommandEntry,
|
|
475
|
-
SubcommandEntry
|
|
476
|
-
getRoot,
|
|
477
|
-
use
|
|
475
|
+
SubcommandEntry
|
|
478
476
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { B as BakitClient } from './BakitClient-CgtDS6Hr.js';
|
|
2
|
+
export { A as Arg, d as ArgumentOptions, b as ArgumentType, a as BakitClientOptions, c as BaseArgumentOptions, i as BaseCommandEntry, g as BaseCommandEntryOptions, j as BaseCommandGroupEntry, u as BaseContext, v as ChatInputContext, r as ChatInputContextSendOptions, p as Command, n as CommandConstructor, m as CommandEntry, o as CommandFactory, k as CommandGroupEntry, f as CommandHook, C as CommandHookExecutionState, e as CommandHookMethod, q as CommandRegistry, D as CommandSyntaxError, z as CommandSyntaxErrorOptions, y as CommandSyntaxErrorType, x as Context, t as ContextSendOptions, h as CreateCommandOptions, G as GetSyntaxErrorMessageFunction, H as HOOKS_KEY, I as IntegerArgumentOptions, M as MemberArgumentOptions, w as MessageContext, s as MessageContextSendOptions, N as NumberArgumentOptions, R as RootCommandEntry, S as StringArgumentOptions, l as SubcommandEntry, U as UserArgumentOptions } from './BakitClient-CgtDS6Hr.js';
|
|
2
3
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
-
import '
|
|
4
|
-
import '
|
|
4
|
+
import { SetOptional } from 'type-fest';
|
|
5
|
+
import { Awaitable, ClientEvents } from 'discord.js';
|
|
6
|
+
import EventEmitter from 'node:events';
|
|
5
7
|
|
|
6
8
|
declare function extractId(value: string): string | null;
|
|
7
9
|
|
|
@@ -15,4 +17,69 @@ declare class StateBox {
|
|
|
15
17
|
static use<T extends object>(defaultValue?: unknown): (target: T, key: keyof T) => void;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
type EventsLike = Record<keyof unknown, unknown[]>;
|
|
21
|
+
type EventKey<E extends EventsLike> = keyof E;
|
|
22
|
+
declare enum ListenerHookExecutionState {
|
|
23
|
+
Main = "main",
|
|
24
|
+
Pre = "pre",
|
|
25
|
+
Post = "post",
|
|
26
|
+
Error = "error"
|
|
27
|
+
}
|
|
28
|
+
type MainListenerHookMethod<E extends EventsLike, K extends EventKey<E>> = (...args: E[K] & unknown[]) => Awaitable<void>;
|
|
29
|
+
type ErrorListenerHookMethod<E extends EventsLike, K extends EventKey<E>> = (error: unknown, ...args: E[K] & unknown[]) => Awaitable<void>;
|
|
30
|
+
interface MainListenerHook<E extends EventsLike, K extends EventKey<E>> {
|
|
31
|
+
state: ListenerHookExecutionState.Main | ListenerHookExecutionState.Post | ListenerHookExecutionState.Pre;
|
|
32
|
+
method: MainListenerHookMethod<E, K>;
|
|
33
|
+
entry: ListenerEntry<E, K>;
|
|
34
|
+
}
|
|
35
|
+
interface ErrorListenerHook<E extends EventsLike, K extends EventKey<E>> {
|
|
36
|
+
state: ListenerHookExecutionState.Error;
|
|
37
|
+
method: ErrorListenerHookMethod<E, K>;
|
|
38
|
+
entry: ListenerEntry<E, K>;
|
|
39
|
+
}
|
|
40
|
+
type ListenerHook<E extends EventsLike, K extends EventKey<E>> = MainListenerHook<E, K> | ErrorListenerHook<E, K>;
|
|
41
|
+
interface ListenerEntryOptions<E extends EventsLike, K extends EventKey<E>> {
|
|
42
|
+
name: K;
|
|
43
|
+
once: boolean;
|
|
44
|
+
emitter?: EventEmitter;
|
|
45
|
+
}
|
|
46
|
+
declare class ListenerEntry<E extends EventsLike, K extends EventKey<E>> {
|
|
47
|
+
options: ListenerEntryOptions<E, K>;
|
|
48
|
+
static hooksKey: symbol;
|
|
49
|
+
private static cache;
|
|
50
|
+
main: <T extends MainListenerHookMethod<E, K>>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
|
|
51
|
+
pre: <T extends MainListenerHookMethod<E, K>>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
|
|
52
|
+
post: <T extends MainListenerHookMethod<E, K>>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
|
|
53
|
+
error: <T extends ErrorListenerHookMethod<E, K>>(target: object, _key: string, descriptor: TypedPropertyDescriptor<T>) => void;
|
|
54
|
+
constructor(options: ListenerEntryOptions<E, K>);
|
|
55
|
+
static getHooks<E extends EventsLike, K extends EventKey<E>>(constructor: ListenerConstructor): readonly ListenerHook<E, K>[];
|
|
56
|
+
static getHooks<E extends EventsLike, K extends EventKey<E>>(constructor: ListenerConstructor, init: true): ListenerHook<E, K>[];
|
|
57
|
+
private static createMainHookDecorator;
|
|
58
|
+
private static createErrorHookDecorator;
|
|
59
|
+
private static addHook;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type ListenerConstructor = new (...args: unknown[]) => object;
|
|
63
|
+
type CreateListenerOptions<E extends EventsLike, K extends EventKey<E>> = SetOptional<ListenerEntryOptions<E, K>, "once"> | K;
|
|
64
|
+
declare function ListenerFactory<E extends EventsLike = ClientEvents, K extends EventKey<E> = EventKey<E>>(options: CreateListenerOptions<E, K>): ListenerEntry<E, K>;
|
|
65
|
+
declare function use(listener: ListenerEntry<never, never>): (target: ListenerConstructor) => void;
|
|
66
|
+
declare function getEntry(constructor: ListenerConstructor): ListenerEntry<never, never> | undefined;
|
|
67
|
+
declare const Listener: typeof ListenerFactory & {
|
|
68
|
+
use: typeof use;
|
|
69
|
+
getEntry: typeof getEntry;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
declare function add(constructor: ListenerConstructor): void;
|
|
73
|
+
declare function remove(constructor: ListenerConstructor): void;
|
|
74
|
+
declare function removeAll(): void;
|
|
75
|
+
declare function setClient(newClient: BakitClient): void;
|
|
76
|
+
declare const ListenerRegistry: {
|
|
77
|
+
constructors: Set<ListenerConstructor>;
|
|
78
|
+
instances: WeakMap<ListenerConstructor, object>;
|
|
79
|
+
add: typeof add;
|
|
80
|
+
setClient: typeof setClient;
|
|
81
|
+
remove: typeof remove;
|
|
82
|
+
removeAll: typeof removeAll;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export { BakitClient, type CreateListenerOptions, type ErrorListenerHook, type ErrorListenerHookMethod, type EventKey, type EventsLike, Listener, type ListenerConstructor, ListenerEntry, type ListenerEntryOptions, ListenerFactory, type ListenerHook, ListenerHookExecutionState, ListenerRegistry, type MainListenerHook, type MainListenerHookMethod, StateBox, type States, extractId };
|
package/dist/index.js
CHANGED
|
@@ -122,13 +122,13 @@ var Arg = {
|
|
|
122
122
|
};
|
|
123
123
|
|
|
124
124
|
// src/command/CommandEntry.ts
|
|
125
|
-
var
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return
|
|
131
|
-
})(
|
|
125
|
+
var CommandHookExecutionState = /* @__PURE__ */ ((CommandHookExecutionState2) => {
|
|
126
|
+
CommandHookExecutionState2["Main"] = "main";
|
|
127
|
+
CommandHookExecutionState2["Pre"] = "pre";
|
|
128
|
+
CommandHookExecutionState2["Post"] = "post";
|
|
129
|
+
CommandHookExecutionState2["Error"] = "error";
|
|
130
|
+
return CommandHookExecutionState2;
|
|
131
|
+
})(CommandHookExecutionState || {});
|
|
132
132
|
var HOOKS_KEY = Symbol("hooks");
|
|
133
133
|
var BaseCommandEntry = class _BaseCommandEntry {
|
|
134
134
|
constructor(options) {
|
|
@@ -564,13 +564,13 @@ var ArgumentResolver = class _ArgumentResolver {
|
|
|
564
564
|
return this.options.message.client;
|
|
565
565
|
}
|
|
566
566
|
static create(message) {
|
|
567
|
-
const
|
|
568
|
-
const { enableMentionPrefix } =
|
|
567
|
+
const client2 = message.client;
|
|
568
|
+
const { enableMentionPrefix } = client2.options;
|
|
569
569
|
const prefixes = [
|
|
570
570
|
// Custom prefixes specified in options
|
|
571
|
-
...
|
|
571
|
+
...client2.options.prefixes ?? [],
|
|
572
572
|
// Use bot mention as prefix if enabled
|
|
573
|
-
...enableMentionPrefix ? [
|
|
573
|
+
...enableMentionPrefix ? [client2.user.toString()] : []
|
|
574
574
|
];
|
|
575
575
|
const prefix = prefixes.find((p) => message.content.startsWith(p)) ?? null;
|
|
576
576
|
if (!prefix) {
|
|
@@ -812,6 +812,140 @@ var StateBox = class _StateBox {
|
|
|
812
812
|
}
|
|
813
813
|
};
|
|
814
814
|
|
|
815
|
+
// src/listener/ListenerEntry.ts
|
|
816
|
+
var ListenerHookExecutionState = /* @__PURE__ */ ((ListenerHookExecutionState2) => {
|
|
817
|
+
ListenerHookExecutionState2["Main"] = "main";
|
|
818
|
+
ListenerHookExecutionState2["Pre"] = "pre";
|
|
819
|
+
ListenerHookExecutionState2["Post"] = "post";
|
|
820
|
+
ListenerHookExecutionState2["Error"] = "error";
|
|
821
|
+
return ListenerHookExecutionState2;
|
|
822
|
+
})(ListenerHookExecutionState || {});
|
|
823
|
+
var ListenerEntry = class _ListenerEntry {
|
|
824
|
+
constructor(options) {
|
|
825
|
+
this.options = options;
|
|
826
|
+
}
|
|
827
|
+
static hooksKey = Symbol("hooks");
|
|
828
|
+
static cache = /* @__PURE__ */ new WeakMap();
|
|
829
|
+
main = _ListenerEntry.createMainHookDecorator("main" /* Main */, this);
|
|
830
|
+
pre = _ListenerEntry.createMainHookDecorator("pre" /* Pre */, this);
|
|
831
|
+
post = _ListenerEntry.createMainHookDecorator("post" /* Post */, this);
|
|
832
|
+
error = _ListenerEntry.createErrorHookDecorator("error" /* Error */, this);
|
|
833
|
+
static getHooks(constructor, init = false) {
|
|
834
|
+
let hooks = this.cache.get(constructor) ?? Reflect.getMetadata(this.hooksKey, constructor);
|
|
835
|
+
if (!hooks) {
|
|
836
|
+
hooks = [];
|
|
837
|
+
if (init) {
|
|
838
|
+
Reflect.defineMetadata(this.hooksKey, hooks, constructor);
|
|
839
|
+
this.cache.set(constructor, hooks);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
return init ? hooks : Object.freeze([...hooks]);
|
|
843
|
+
}
|
|
844
|
+
static createMainHookDecorator(state, entry) {
|
|
845
|
+
return (target, _key, descriptor) => {
|
|
846
|
+
this.addHook(target, state, descriptor.value, entry);
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
static createErrorHookDecorator(state, entry) {
|
|
850
|
+
return (target, _key, descriptor) => {
|
|
851
|
+
this.addHook(target, state, descriptor.value, entry);
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
static addHook(target, state, method, entry) {
|
|
855
|
+
const { constructor } = target;
|
|
856
|
+
const hooks = this.getHooks(constructor, true);
|
|
857
|
+
if (typeof method !== "function") {
|
|
858
|
+
throw new Error("CommandEntry decorator must be used with a class method.");
|
|
859
|
+
}
|
|
860
|
+
if (hooks.some((hook2) => hook2.state === state && hook2.entry === entry)) {
|
|
861
|
+
throw new Error(
|
|
862
|
+
`Hook "${state}" is already defined for entry "${String(entry.options.name)}".`
|
|
863
|
+
);
|
|
864
|
+
}
|
|
865
|
+
const hook = {
|
|
866
|
+
state,
|
|
867
|
+
entry,
|
|
868
|
+
method
|
|
869
|
+
};
|
|
870
|
+
hooks.push(hook);
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
// src/listener/Listener.ts
|
|
875
|
+
function ListenerFactory(options) {
|
|
876
|
+
if (typeof options !== "object") {
|
|
877
|
+
options = {
|
|
878
|
+
name: options,
|
|
879
|
+
once: false
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
options.once = Boolean(options.once);
|
|
883
|
+
return new ListenerEntry(options);
|
|
884
|
+
}
|
|
885
|
+
var ENTRY_KEY = Symbol("entry");
|
|
886
|
+
function use2(listener) {
|
|
887
|
+
return (target) => {
|
|
888
|
+
Reflect.defineMetadata(ENTRY_KEY, listener, target);
|
|
889
|
+
};
|
|
890
|
+
}
|
|
891
|
+
function getEntry(constructor) {
|
|
892
|
+
return Reflect.getMetadata(ENTRY_KEY, constructor);
|
|
893
|
+
}
|
|
894
|
+
var Listener = Object.assign(ListenerFactory, {
|
|
895
|
+
use: use2,
|
|
896
|
+
getEntry
|
|
897
|
+
});
|
|
898
|
+
|
|
899
|
+
// src/listener/ListenerRegistry.ts
|
|
900
|
+
var client;
|
|
901
|
+
var constructors = /* @__PURE__ */ new Set();
|
|
902
|
+
var instances = /* @__PURE__ */ new WeakMap();
|
|
903
|
+
function add(constructor) {
|
|
904
|
+
const entry = Listener.getEntry(constructor);
|
|
905
|
+
if (!entry) {
|
|
906
|
+
throw new Error(`No entry found for "${constructor.name}"`);
|
|
907
|
+
}
|
|
908
|
+
const { options } = entry;
|
|
909
|
+
if (!options.emitter) {
|
|
910
|
+
if (!client) {
|
|
911
|
+
throw new Error("Client is not ready.");
|
|
912
|
+
}
|
|
913
|
+
options.emitter = client;
|
|
914
|
+
}
|
|
915
|
+
constructors.add(constructor);
|
|
916
|
+
instances.set(constructor, new constructor());
|
|
917
|
+
}
|
|
918
|
+
function remove(constructor) {
|
|
919
|
+
const entry = Listener.getEntry(constructor);
|
|
920
|
+
if (!entry) {
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
constructors.delete(constructor);
|
|
924
|
+
instances.delete(constructor);
|
|
925
|
+
const hook = ListenerEntry.getHooks(constructor).find((hook2) => hook2.entry === entry);
|
|
926
|
+
if (!hook) {
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
const { name, emitter } = entry.options;
|
|
930
|
+
emitter?.removeListener(name, hook.method);
|
|
931
|
+
}
|
|
932
|
+
function removeAll() {
|
|
933
|
+
for (const constructor of constructors) {
|
|
934
|
+
remove(constructor);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
function setClient(newClient) {
|
|
938
|
+
client = newClient;
|
|
939
|
+
}
|
|
940
|
+
var ListenerRegistry = {
|
|
941
|
+
constructors,
|
|
942
|
+
instances,
|
|
943
|
+
add,
|
|
944
|
+
setClient,
|
|
945
|
+
remove,
|
|
946
|
+
removeAll
|
|
947
|
+
};
|
|
948
|
+
|
|
815
949
|
// src/BakitClient.ts
|
|
816
950
|
var BakitClient = class _BakitClient extends Client {
|
|
817
951
|
constructor(options) {
|
|
@@ -819,9 +953,10 @@ var BakitClient = class _BakitClient extends Client {
|
|
|
819
953
|
options.getSyntaxErrorMessage = _BakitClient.getSyntaxErrorMessage;
|
|
820
954
|
}
|
|
821
955
|
super(options);
|
|
956
|
+
ListenerRegistry.setClient(this);
|
|
822
957
|
this.once(
|
|
823
958
|
Events.ClientReady,
|
|
824
|
-
(
|
|
959
|
+
(client2) => void this.registerApplicationCommands(client2)
|
|
825
960
|
);
|
|
826
961
|
this.on(Events.InteractionCreate, (interaction) => void this.handleInteraction(interaction));
|
|
827
962
|
this.on(Events.MessageCreate, (message) => void this.handleMessage(message));
|
|
@@ -841,9 +976,9 @@ var BakitClient = class _BakitClient extends Client {
|
|
|
841
976
|
content
|
|
842
977
|
};
|
|
843
978
|
};
|
|
844
|
-
async registerApplicationCommands(
|
|
979
|
+
async registerApplicationCommands(client2) {
|
|
845
980
|
const commands = CommandRegistry.constructors.map((c) => CommandRegistry.buildSlashCommand(c));
|
|
846
|
-
await
|
|
981
|
+
await client2.application.commands.set(commands);
|
|
847
982
|
}
|
|
848
983
|
async handleMessage(message) {
|
|
849
984
|
if (message.author.bot) {
|
|
@@ -999,7 +1134,7 @@ var BakitClient = class _BakitClient extends Client {
|
|
|
999
1134
|
return { root, group, subcommand: sub };
|
|
1000
1135
|
}
|
|
1001
1136
|
createHookRecord(hooks) {
|
|
1002
|
-
return Object.values(
|
|
1137
|
+
return Object.values(CommandHookExecutionState).reduce(
|
|
1003
1138
|
(acc, state) => {
|
|
1004
1139
|
acc[state] = hooks.find((h) => h.state === state);
|
|
1005
1140
|
return acc;
|
|
@@ -1019,16 +1154,19 @@ export {
|
|
|
1019
1154
|
Command,
|
|
1020
1155
|
CommandFactory,
|
|
1021
1156
|
CommandGroupEntry,
|
|
1157
|
+
CommandHookExecutionState,
|
|
1022
1158
|
CommandRegistry,
|
|
1023
1159
|
CommandSyntaxError,
|
|
1024
1160
|
CommandSyntaxErrorType,
|
|
1025
1161
|
HOOKS_KEY,
|
|
1026
|
-
|
|
1162
|
+
Listener,
|
|
1163
|
+
ListenerEntry,
|
|
1164
|
+
ListenerFactory,
|
|
1165
|
+
ListenerHookExecutionState,
|
|
1166
|
+
ListenerRegistry,
|
|
1027
1167
|
MessageContext,
|
|
1028
1168
|
RootCommandEntry,
|
|
1029
1169
|
StateBox,
|
|
1030
1170
|
SubcommandEntry,
|
|
1031
|
-
extractId
|
|
1032
|
-
getRoot,
|
|
1033
|
-
use
|
|
1171
|
+
extractId
|
|
1034
1172
|
};
|