quickbotz 0.0.1 → 0.0.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.
- package/dist/index.d.mts +49 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +97 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +6 -4
- package/dist/index.js +0 -57502
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AutocompleteInteraction, ChatInputCommandInteraction, Client, ClientEvents, Collection, GatewayIntentBits, SlashCommandBuilder } from "discord.js";
|
|
2
|
+
|
|
3
|
+
//#region src/types/QuickBotzOptions.d.ts
|
|
4
|
+
interface MultiGuildConfig {
|
|
5
|
+
mode: "multi";
|
|
6
|
+
clientId: string;
|
|
7
|
+
token: string;
|
|
8
|
+
intents: GatewayIntentBits[];
|
|
9
|
+
}
|
|
10
|
+
interface SingleGuildConfig {
|
|
11
|
+
mode: "single";
|
|
12
|
+
clientId: string;
|
|
13
|
+
guildId: string;
|
|
14
|
+
token: string;
|
|
15
|
+
intents: GatewayIntentBits[];
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/types/Context.d.ts
|
|
19
|
+
interface Context {
|
|
20
|
+
client: Client;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/types/CommandOptions.d.ts
|
|
24
|
+
interface CommandOptions {
|
|
25
|
+
data: SlashCommandBuilder;
|
|
26
|
+
execute: (ctx: Context, interaction: ChatInputCommandInteraction) => void | Promise<void>;
|
|
27
|
+
autocomplete?: (ctx: Context, interaction: AutocompleteInteraction) => void | Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/QuickBotz.d.ts
|
|
31
|
+
declare class QuickBotz {
|
|
32
|
+
#private;
|
|
33
|
+
client: Client;
|
|
34
|
+
ctx: Context;
|
|
35
|
+
commands: Collection<string, any>;
|
|
36
|
+
private constructor();
|
|
37
|
+
static multi(config: Omit<MultiGuildConfig, "mode">): QuickBotz;
|
|
38
|
+
static single(config: Omit<SingleGuildConfig, "mode">): QuickBotz;
|
|
39
|
+
registerEvent: <K extends keyof ClientEvents>(event: K, once: boolean | undefined, callback: (ctx: Context, ...args: ClientEvents[K]) => void | Promise<void>) => void;
|
|
40
|
+
registerCommand({
|
|
41
|
+
data,
|
|
42
|
+
execute,
|
|
43
|
+
autocomplete
|
|
44
|
+
}: CommandOptions): void;
|
|
45
|
+
start: () => Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { type Context, QuickBotz };
|
|
49
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types/QuickBotzOptions.ts","../src/types/Context.ts","../src/types/CommandOptions.ts","../src/QuickBotz.ts"],"mappings":";;;UAEiB,gBAAA;EACf,IAAA;EACA,QAAA;EACA,KAAA;EACA,OAAA,EAAS,iBAAA;AAAA;AAAA,UAGM,iBAAA;EACf,IAAA;EACA,QAAA;EACA,OAAA;EACA,KAAA;EACA,OAAA,EAAS,iBAAA;AAAA;;;UCZM,OAAA;EACf,MAAA,EAAQ,MAAA;AAAA;;;UCAe,cAAA;EACrB,IAAA,EAAM,mBAAA;EACN,OAAA,GAAU,GAAA,EAAK,OAAA,EAAS,WAAA,EAAa,2BAAA,YAAuC,OAAA;EAC5E,YAAA,IAAgB,GAAA,EAAK,OAAA,EAAS,WAAA,EAAa,uBAAA,YAAmC,OAAA;AAAA;;;cCU5E,SAAA;EAAA;EACG,MAAA,EAAQ,MAAA;EACR,GAAA,EAAK,OAAA;EACL,QAAA,EAAU,UAAA;EAAA,QAGV,WAAA,CAAA;EAAA,OASA,KAAA,CAAM,MAAA,EAAQ,IAAA,CAAK,gBAAA,YAAyB,SAAA;EAAA,OAI5C,MAAA,CAAO,MAAA,EAAQ,IAAA,CAAK,iBAAA,YAA0B,SAAA;EAIrD,aAAA,mBAAiC,YAAA,EAC/B,KAAA,EAAO,CAAA,EACP,IAAA,uBACA,QAAA,GAAW,GAAA,EAAK,OAAA,KAAY,IAAA,EAAM,YAAA,CAAa,CAAA,aAAc,OAAA;EAW/D,eAAA,CAAA;IAAkB,IAAA;IAAM,OAAA;IAAS;EAAA,GAAgB,cAAA;EAiFjD,KAAA,QAAK,OAAA;AAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Client, Collection, Events, MessageFlags, REST, Routes } from "discord.js";
|
|
2
|
+
|
|
3
|
+
//#region src/QuickBotz.ts
|
|
4
|
+
var QuickBotz = class QuickBotz {
|
|
5
|
+
client;
|
|
6
|
+
ctx;
|
|
7
|
+
commands;
|
|
8
|
+
#config;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.#config = config;
|
|
11
|
+
this.client = new Client({ intents: config.intents });
|
|
12
|
+
this.commands = new Collection();
|
|
13
|
+
this.ctx = { client: this.client };
|
|
14
|
+
}
|
|
15
|
+
static multi(config) {
|
|
16
|
+
return new QuickBotz({
|
|
17
|
+
...config,
|
|
18
|
+
mode: "multi"
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
static single(config) {
|
|
22
|
+
return new QuickBotz({
|
|
23
|
+
...config,
|
|
24
|
+
mode: "single"
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
registerEvent = (event, once = false, callback) => {
|
|
28
|
+
once ? this.client.once(event, (...args) => {
|
|
29
|
+
return callback(this.ctx, ...args);
|
|
30
|
+
}) : this.client.on(event, (...args) => {
|
|
31
|
+
return callback(this.ctx, ...args);
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
registerCommand({ data, execute, autocomplete }) {
|
|
35
|
+
this.commands.set(data.name, {
|
|
36
|
+
data,
|
|
37
|
+
execute,
|
|
38
|
+
autocomplete
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
#setupInteractionHandler = () => {
|
|
42
|
+
this.client.on(Events.InteractionCreate, async (interaction) => {
|
|
43
|
+
if (interaction.isChatInputCommand()) {
|
|
44
|
+
const command = this.commands.get(interaction.commandName);
|
|
45
|
+
if (!command) return await interaction.reply({
|
|
46
|
+
content: `This command cannot be found.`,
|
|
47
|
+
flags: MessageFlags.Ephemeral
|
|
48
|
+
});
|
|
49
|
+
if (interaction.isAutocomplete() && command.autocomplete) {
|
|
50
|
+
try {
|
|
51
|
+
await command.autocomplete(this.ctx, interaction);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error(error);
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
await command.execute(this.ctx, interaction);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error(error);
|
|
61
|
+
const content = "There was an error while executing this command";
|
|
62
|
+
if (interaction.replied || interaction.deferred) return await interaction.followUp({
|
|
63
|
+
content,
|
|
64
|
+
flags: MessageFlags.Ephemeral
|
|
65
|
+
});
|
|
66
|
+
await interaction.reply({
|
|
67
|
+
content,
|
|
68
|
+
flags: MessageFlags.Ephemeral
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
#deployCommands = async () => {
|
|
75
|
+
const commandsToRegister = this.commands.map((cmd) => cmd.data.toJSON());
|
|
76
|
+
const rest = new REST().setToken(this.#config.token);
|
|
77
|
+
try {
|
|
78
|
+
console.log(`(ℹ) Started refreshing ${commandsToRegister.length} application (/) commands.`);
|
|
79
|
+
let data;
|
|
80
|
+
if (this.#config.mode === "multi") data = await rest.put(Routes.applicationCommands(this.#config.clientId), { body: commandsToRegister });
|
|
81
|
+
else data = await rest.put(Routes.applicationGuildCommands(this.#config.clientId, this.#config.guildId), { body: commandsToRegister });
|
|
82
|
+
console.log(`(✅) Successfully reloaded ${data.length} application (/) commands.`);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error(error);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
start = async () => {
|
|
88
|
+
await this.#deployCommands();
|
|
89
|
+
this.#setupInteractionHandler();
|
|
90
|
+
this.client.login(this.#config.token);
|
|
91
|
+
console.log(`(⚡) QuickBotz Initialized Successfully`);
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
export { QuickBotz };
|
|
97
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["#config","#deployCommands","#setupInteractionHandler"],"sources":["../src/QuickBotz.ts"],"sourcesContent":["import {\n Client,\n Collection,\n Events,\n MessageFlags,\n REST,\n Routes,\n type ClientEvents,\n type RESTPostAPIApplicationCommandsResult,\n} from \"discord.js\";\nimport type { CommandOptions, Context, QuickBotzOptions } from \"./types\";\nimport type {\n MultiGuildConfig,\n SingleGuildConfig,\n} from \"./types/QuickBotzOptions\";\n\nclass QuickBotz {\n public client: Client;\n public ctx: Context;\n public commands: Collection<string, any>;\n #config: QuickBotzOptions;\n\n private constructor(config: QuickBotzOptions) {\n this.#config = config;\n this.client = new Client({ intents: config.intents });\n this.commands = new Collection();\n this.ctx = {\n client: this.client,\n };\n }\n\n static multi(config: Omit<MultiGuildConfig, \"mode\">) {\n return new QuickBotz({ ...config, mode: \"multi\" });\n }\n\n static single(config: Omit<SingleGuildConfig, \"mode\">) {\n return new QuickBotz({ ...config, mode: \"single\" });\n }\n\n registerEvent = <K extends keyof ClientEvents>(\n event: K,\n once: boolean = false,\n callback: (ctx: Context, ...args: ClientEvents[K]) => void | Promise<void>,\n ) => {\n once\n ? this.client.once(event, (...args: ClientEvents[K]) => {\n return callback(this.ctx, ...args);\n })\n : this.client.on(event, (...args: ClientEvents[K]) => {\n return callback(this.ctx, ...args);\n });\n };\n\n registerCommand({ data, execute, autocomplete }: CommandOptions) {\n this.commands.set(data.name, { data, execute, autocomplete });\n }\n\n #setupInteractionHandler = () => {\n this.client.on(Events.InteractionCreate, async (interaction) => {\n if (interaction.isChatInputCommand()) {\n const command: CommandOptions = this.commands.get(\n interaction.commandName,\n );\n\n if (!command) {\n return await interaction.reply({\n content: `This command cannot be found.`,\n flags: MessageFlags.Ephemeral,\n });\n }\n\n if (interaction.isAutocomplete() && command.autocomplete) {\n try {\n await command.autocomplete(this.ctx, interaction);\n } catch (error) {\n console.error(error);\n }\n return;\n }\n\n try {\n await command.execute(this.ctx, interaction);\n } catch (error) {\n console.error(error);\n const content = \"There was an error while executing this command\";\n if (interaction.replied || interaction.deferred) {\n return await interaction.followUp({\n content,\n flags: MessageFlags.Ephemeral,\n });\n }\n\n await interaction.reply({\n content,\n flags: MessageFlags.Ephemeral,\n });\n }\n }\n });\n };\n\n #deployCommands = async () => {\n const commandsToRegister = this.commands.map((cmd) => cmd.data.toJSON());\n const rest = new REST().setToken(this.#config.token);\n\n try {\n console.log(\n `(ℹ) Started refreshing ${commandsToRegister.length} application (/) commands.`,\n );\n\n let data;\n if (this.#config.mode === \"multi\") {\n data = (await rest.put(\n Routes.applicationCommands(this.#config.clientId),\n { body: commandsToRegister },\n )) as RESTPostAPIApplicationCommandsResult[];\n } else {\n data = (await rest.put(\n Routes.applicationGuildCommands(\n this.#config.clientId,\n this.#config.guildId,\n ),\n { body: commandsToRegister },\n )) as RESTPostAPIApplicationCommandsResult[];\n }\n\n console.log(\n `(✅) Successfully reloaded ${data.length} application (/) commands.`,\n );\n } catch (error) {\n console.error(error);\n }\n };\n\n start = async () => {\n await this.#deployCommands();\n this.#setupInteractionHandler();\n this.client.login(this.#config.token);\n console.log(`(⚡) QuickBotz Initialized Successfully`);\n };\n}\n\nexport default QuickBotz;\n"],"mappings":";;;AAgBA,IAAM,YAAN,MAAM,UAAU;CACd,AAAO;CACP,AAAO;CACP,AAAO;CACP;CAEA,AAAQ,YAAY,QAA0B;AAC5C,QAAKA,SAAU;AACf,OAAK,SAAS,IAAI,OAAO,EAAE,SAAS,OAAO,S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Aa;MACrB,CAAC;;;IAGN;;CAGJ,kBAAkB,YAAY;EAC5B,MAAM,qBAAqB,KAAK,SAAS,KAAK,QAAQ,IAAI,KAAK,QAAQ,CAAC;EACxE,MAAM,OAAO,IAAI,MAAM,CAAC,SAAS,MAAKA,OAAQ,MAAM;AAEpD,MAAI;AACF,WAAQ,IACN,0BAA0B,mBAAmB,OAAO,4BACrD;GAED,IAAI;AACJ,OAAI,MAAKA,OAAQ,SAAS,QACxB,QAAQ,MAAM,KAAK,IACjB,OAAO,oBAAoB,MAAKA,OAAQ,SAAS,EACjD,EAAE,MAAM,oBAAoB,CAC7B;OAED,QAAQ,MAAM,KAAK,IACjB,OAAO,yBACL,MAAKA,OAAQ,UACb,MAAKA,OAAQ,QACd,EACD,EAAE,MAAM,oBAAoB,CAC7B;AAGH,WAAQ,IACN,6BAA6B,KAAK,OAAO,4BAC1C;WACM,OAAO;AACd,WAAQ,MAAM,MAAM;;;CAIxB,QAAQ,YAAY;AAClB,QAAM,MAAKC,gBAAiB;AAC5B,QAAKC,yBAA0B;AAC/B,OAAK,OAAO,MAAM,MAAKF,OAAQ,MAAM;AACrC,UAAQ,IAAI,yCAAyC"}
|
package/package.json
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quickbotz",
|
|
3
|
-
"
|
|
3
|
+
"main": "dist/index.mjs",
|
|
4
|
+
"types": "dist/index.d.mts",
|
|
5
|
+
"version": "0.0.4",
|
|
4
6
|
"files": [
|
|
5
7
|
"dist"
|
|
6
8
|
],
|
|
7
|
-
"main": "dist/index.js",
|
|
8
9
|
"scripts": {
|
|
9
|
-
"build": "
|
|
10
|
+
"build": "tsdown"
|
|
10
11
|
},
|
|
11
12
|
"description": "A simple yet powerful discord bot framework to build discord bots easier & faster",
|
|
12
13
|
"module": "src/index.ts",
|
|
13
14
|
"license": "MIT",
|
|
14
15
|
"type": "module",
|
|
15
16
|
"devDependencies": {
|
|
16
|
-
"@types/bun": "latest"
|
|
17
|
+
"@types/bun": "latest",
|
|
18
|
+
"tsdown": "^0.20.3"
|
|
17
19
|
},
|
|
18
20
|
"peerDependencies": {
|
|
19
21
|
"typescript": "^5"
|