bakit 2.0.0-alpha.4 → 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.js +64 -22
- package/package.json +2 -4
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.
|
|
@@ -613,27 +614,6 @@ var BakitClient3 = class extends Client {
|
|
|
613
614
|
return `${this.constructor.name} {}`;
|
|
614
615
|
}
|
|
615
616
|
};
|
|
616
|
-
var Instance = class {
|
|
617
|
-
client;
|
|
618
|
-
async start() {
|
|
619
|
-
await loadConfig();
|
|
620
|
-
let config = getConfig();
|
|
621
|
-
this.client = new BakitClient3({
|
|
622
|
-
intents: []
|
|
623
|
-
}), await this.loadModules(), this.initIntents(), await this.client.login(config.token);
|
|
624
|
-
}
|
|
625
|
-
loadModules() {
|
|
626
|
-
let { managers } = this.client, { commands, listeners } = managers;
|
|
627
|
-
return Promise.all([commands.loadModules(), listeners.loadModules()]);
|
|
628
|
-
}
|
|
629
|
-
initIntents() {
|
|
630
|
-
let config = getConfig(), { options, managers } = this.client, { listeners } = managers, intents;
|
|
631
|
-
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;
|
|
632
|
-
}
|
|
633
|
-
};
|
|
634
|
-
function useApp() {
|
|
635
|
-
return new Instance();
|
|
636
|
-
}
|
|
637
617
|
|
|
638
618
|
// src/utils/string.ts
|
|
639
619
|
function tokenize(content) {
|
|
@@ -675,4 +655,66 @@ var Params = {
|
|
|
675
655
|
number: createFactory(NumberParam)
|
|
676
656
|
};
|
|
677
657
|
|
|
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
|
+
|
|
678
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
|
}
|