bakit 2.0.0-alpha.3 → 2.0.0-alpha.5
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/dist/index.d.ts +23 -1
- package/dist/index.js +86 -3
- package/package.json +2 -4
package/dist/index.d.ts
CHANGED
|
@@ -327,6 +327,28 @@ declare class BakitClient<Ready extends boolean = boolean> extends Client<Ready>
|
|
|
327
327
|
[inspect.custom](): string;
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
+
declare class Instance {
|
|
331
|
+
client: BakitClient;
|
|
332
|
+
start(): Promise<void>;
|
|
333
|
+
private loadModules;
|
|
334
|
+
private initIntents;
|
|
335
|
+
}
|
|
336
|
+
declare function useApp(): Instance;
|
|
337
|
+
|
|
338
|
+
declare const EVENT_INTENT_MAPPING: Record<string, number[]>;
|
|
339
|
+
|
|
340
|
+
declare function tokenize(content: string): string[];
|
|
341
|
+
|
|
342
|
+
declare class BakitError extends Error {
|
|
343
|
+
constructor(message: string);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
declare class ArgumentError extends BakitError {
|
|
347
|
+
target: string;
|
|
348
|
+
reason: string;
|
|
349
|
+
constructor(target: string, reason: string);
|
|
350
|
+
}
|
|
351
|
+
|
|
330
352
|
declare const Params: {
|
|
331
353
|
readonly string: <Required extends boolean = true>(options: string | {
|
|
332
354
|
name: string;
|
|
@@ -344,4 +366,4 @@ declare const Params: {
|
|
|
344
366
|
}) => NumberParam<Required>;
|
|
345
367
|
};
|
|
346
368
|
|
|
347
|
-
export { type AnyParam, BakitClient, type BakitClientEvents, BaseCommandContext, BaseParam, type BaseParamOptions, BaseParamSchema, ChatInputContext, type ChatInputContextSendOptions, Command, type CommandContext, CommandManager, type CommandOptions, type CommandOptionsInput, CommandOptionsSchema, type ContextSendOptions, type GetPrefixFunction, type InferParamTuple, type InferParamValue, Listener, ListenerManager, type ListenerOptions, ListenerOptionsSchema, MessageContext, type MessageContextSendOptions, type NumberOptions, NumberParam, NumberParamSchema, type ParamResolvedOutputType, ParamUserType, Params, type ProjectConfig, type ProjectConfigInput, ProjectConfigSchema, type StringOptions, StringParam, StringParamSchema, defineCommand, defineConfig, defineListener, getConfig, loadConfig };
|
|
369
|
+
export { type AnyParam, ArgumentError, BakitClient, type BakitClientEvents, BakitError, BaseClientManager, BaseCommandContext, BaseParam, type BaseParamOptions, BaseParamSchema, ChatInputContext, type ChatInputContextSendOptions, Command, type CommandContext, CommandManager, type CommandOptions, type CommandOptionsInput, CommandOptionsSchema, Context, type ContextSendOptions, EVENT_INTENT_MAPPING, type ErrorHookCallback, type GetPrefixFunction, HookOrder, HookState, type InferParamTuple, type InferParamValue, Instance, LifecycleManager, Listener, ListenerManager, type ListenerOptions, ListenerOptionsSchema, type MainHookCallback, MessageContext, type MessageContextSendOptions, type NumberOptions, NumberParam, NumberParamSchema, type ParamResolvedOutputType, ParamUserType, Params, type ProjectConfig, type ProjectConfigInput, ProjectConfigSchema, type StringOptions, StringParam, StringParamSchema, defineCommand, defineConfig, defineListener, getConfig, loadConfig, tokenize, useApp };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import 'dotenv/config';
|
|
1
2
|
import { GatewayIntentBits, Events, Client, IntentsBitField, Collection, ChatInputCommandInteraction, Message } from 'discord.js';
|
|
2
3
|
import z3, { z } from 'zod';
|
|
3
4
|
import { pathToFileURL } from 'url';
|
|
@@ -5,7 +6,7 @@ import glob from 'tiny-glob';
|
|
|
5
6
|
import { inspect } from 'util';
|
|
6
7
|
import { posix } from 'path';
|
|
7
8
|
|
|
8
|
-
// src/
|
|
9
|
+
// src/index.ts
|
|
9
10
|
var ProjectConfigSchema = z.object({
|
|
10
11
|
/**
|
|
11
12
|
* The gateway intents to use for the Discord client.
|
|
@@ -130,7 +131,7 @@ var BaseCommandContext = class extends Context {
|
|
|
130
131
|
return await channel.send(options);
|
|
131
132
|
}
|
|
132
133
|
};
|
|
133
|
-
var LifecycleManager = class {
|
|
134
|
+
var HookState = /* @__PURE__ */ ((HookState2) => (HookState2.Pre = "PRE", HookState2.Main = "MAIN", HookState2.Post = "POST", HookState2.Error = "ERROR", HookState2))(HookState || {}), HookOrder = /* @__PURE__ */ ((HookOrder2) => (HookOrder2[HookOrder2.First = 0] = "First", HookOrder2[HookOrder2.Last = 1] = "Last", HookOrder2))(HookOrder || {}), LifecycleManager = class {
|
|
134
135
|
constructor(id) {
|
|
135
136
|
this.id = id;
|
|
136
137
|
}
|
|
@@ -613,6 +614,26 @@ var BakitClient3 = class extends Client {
|
|
|
613
614
|
return `${this.constructor.name} {}`;
|
|
614
615
|
}
|
|
615
616
|
};
|
|
617
|
+
|
|
618
|
+
// src/utils/string.ts
|
|
619
|
+
function tokenize(content) {
|
|
620
|
+
let args = [], current = "", quoteChar = null, isEscaped = false;
|
|
621
|
+
for (let i = 0; i < content.length; i++) {
|
|
622
|
+
let char = content[i];
|
|
623
|
+
if (char === void 0)
|
|
624
|
+
break;
|
|
625
|
+
if (isEscaped) {
|
|
626
|
+
current += char, isEscaped = false;
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
if (char === "\\") {
|
|
630
|
+
isEscaped = true;
|
|
631
|
+
continue;
|
|
632
|
+
}
|
|
633
|
+
quoteChar ? char === quoteChar ? quoteChar = null : current += char : char === '"' ? quoteChar = char : /\s/.test(char) ? current.length > 0 && (args.push(current), current = "") : current += char;
|
|
634
|
+
}
|
|
635
|
+
return current.length > 0 && args.push(current), args;
|
|
636
|
+
}
|
|
616
637
|
var ParamUserType = /* @__PURE__ */ ((ParamUserType2) => (ParamUserType2.Bot = "bot", ParamUserType2.Normal = "normal", ParamUserType2.Any = "any", ParamUserType2))(ParamUserType || {}), BaseParamSchema = z.object({
|
|
617
638
|
name: z.string(),
|
|
618
639
|
description: z.string().optional(),
|
|
@@ -634,4 +655,66 @@ var Params = {
|
|
|
634
655
|
number: createFactory(NumberParam)
|
|
635
656
|
};
|
|
636
657
|
|
|
637
|
-
|
|
658
|
+
// src/defaults/command.ts
|
|
659
|
+
var messageCommandHandler = defineListener(Events.MessageCreate), chatInputCommandHandler = defineListener(Events.InteractionCreate);
|
|
660
|
+
messageCommandHandler.main(async (_, message) => {
|
|
661
|
+
let config = getConfig();
|
|
662
|
+
if (message.author.bot)
|
|
663
|
+
return;
|
|
664
|
+
let { content } = message, client = message.client, lowerContent = content.toLowerCase(), prefix = config.prefixes.find((p) => lowerContent.startsWith(p));
|
|
665
|
+
if (!prefix)
|
|
666
|
+
return;
|
|
667
|
+
let [name, ...args] = content.slice(prefix.length).trim().split(/\s+/g);
|
|
668
|
+
if (!name)
|
|
669
|
+
return;
|
|
670
|
+
let command = client.managers.commands.get(name);
|
|
671
|
+
if (!command)
|
|
672
|
+
return;
|
|
673
|
+
let context = new MessageContext(message), { params, quotes } = command.options, rawArgs = quotes ? tokenize(args.join(" ")) : args, resolvedArgs = [];
|
|
674
|
+
for (let i = 0; i < params.length; i++) {
|
|
675
|
+
let param = params[i], arg = rawArgs[i];
|
|
676
|
+
if (!param)
|
|
677
|
+
break;
|
|
678
|
+
let resolved = await param.resolve(context, arg);
|
|
679
|
+
resolvedArgs.push(resolved);
|
|
680
|
+
}
|
|
681
|
+
await command.execute(context, ...resolvedArgs);
|
|
682
|
+
});
|
|
683
|
+
chatInputCommandHandler.main(async (_, interaction) => {
|
|
684
|
+
if (!interaction.isChatInputCommand())
|
|
685
|
+
return;
|
|
686
|
+
let { commandName } = interaction, command = interaction.client.managers.commands.get(commandName);
|
|
687
|
+
if (!command)
|
|
688
|
+
return;
|
|
689
|
+
let context = new ChatInputContext(interaction), { params } = command.options, resolvedArgs = [];
|
|
690
|
+
for (let param of params) {
|
|
691
|
+
let resolved = await param.resolve(context);
|
|
692
|
+
resolvedArgs.push(resolved);
|
|
693
|
+
}
|
|
694
|
+
await command.execute(context, ...resolvedArgs);
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
// src/Instance.ts
|
|
698
|
+
var Instance = class {
|
|
699
|
+
client;
|
|
700
|
+
async start() {
|
|
701
|
+
await loadConfig();
|
|
702
|
+
let config = getConfig();
|
|
703
|
+
this.client = new BakitClient3({
|
|
704
|
+
intents: []
|
|
705
|
+
}), await this.loadModules(), this.initIntents(), await this.client.login(config.token);
|
|
706
|
+
}
|
|
707
|
+
loadModules() {
|
|
708
|
+
let { managers } = this.client, { commands, listeners } = managers;
|
|
709
|
+
return listeners.add(chatInputCommandHandler), listeners.add(messageCommandHandler), Promise.all([commands.loadModules(), listeners.loadModules()]);
|
|
710
|
+
}
|
|
711
|
+
initIntents() {
|
|
712
|
+
let config = getConfig(), { options, managers } = this.client, { listeners } = managers, intents;
|
|
713
|
+
config.intents === "auto" ? intents = listeners.getNeededIntents() : (intents = listeners.getBaseIntents(), typeof config.intents == "bigint" ? intents.bitfield = Number(config.intents) : intents.add(...config.intents)), options.intents = intents;
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
function useApp() {
|
|
717
|
+
return new Instance();
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
export { ArgumentError, BakitClient3 as BakitClient, BakitError, BaseClientManager, BaseCommandContext, BaseParam, BaseParamSchema, ChatInputContext, Command, CommandManager, CommandOptionsSchema, Context, EVENT_INTENT_MAPPING, HookOrder, HookState, Instance, LifecycleManager, Listener, ListenerManager, ListenerOptionsSchema, MessageContext, NumberParam, NumberParamSchema, ParamUserType, Params, ProjectConfigSchema, StringParam, StringParamSchema, defineCommand, defineConfig, defineListener, getConfig, loadConfig, tokenize, useApp };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bakit",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.5",
|
|
4
4
|
"description": "A framework for discord.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -34,11 +34,9 @@
|
|
|
34
34
|
"discord.js": "^14.0.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"dotenv": "^17.2.1",
|
|
37
38
|
"tiny-glob": "^0.2.9",
|
|
38
39
|
"type-fest": "^4.41.0",
|
|
39
40
|
"zod": "^4.1.12"
|
|
40
|
-
},
|
|
41
|
-
"devDependencies": {
|
|
42
|
-
"@swc/core": "^1.13.5"
|
|
43
41
|
}
|
|
44
42
|
}
|