quickbotz 0.0.1 → 0.0.3

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.
@@ -0,0 +1,17 @@
1
+ import { Client, Collection, type ClientEvents } from "discord.js";
2
+ import type { CommandOptions, Context } from "./types";
3
+ import type { MultiGuildConfig, SingleGuildConfig } from "./types/QuickBotzOptions";
4
+ declare class QuickBotz {
5
+ #private;
6
+ client: Client;
7
+ ctx: Context;
8
+ commands: Collection<string, any>;
9
+ private constructor();
10
+ static multi(config: Omit<MultiGuildConfig, "mode">): QuickBotz;
11
+ static single(config: Omit<SingleGuildConfig, "mode">): QuickBotz;
12
+ registerEvent: <K extends keyof ClientEvents>(event: K, once: boolean | undefined, callback: (ctx: Context, ...args: ClientEvents[K]) => void | Promise<void>) => void;
13
+ registerCommand({ data, execute, autocomplete }: CommandOptions): void;
14
+ start: () => Promise<void>;
15
+ }
16
+ export default QuickBotz;
17
+ //# sourceMappingURL=QuickBotz.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QuickBotz.d.ts","sourceRoot":"","sources":["../src/QuickBotz.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,UAAU,EAKV,KAAK,YAAY,EAElB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAoB,MAAM,SAAS,CAAC;AACzE,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,0BAA0B,CAAC;AAElC,cAAM,SAAS;;IACN,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAGzC,OAAO;IASP,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAInD,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC;IAIrD,aAAa,GAAI,CAAC,SAAS,MAAM,YAAY,EAC3C,OAAO,CAAC,EACR,MAAM,OAAO,YAAQ,EACrB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,UAS1E;IAEF,eAAe,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,cAAc;IAiF/D,KAAK,sBAKH;CACH;AAED,eAAe,SAAS,CAAC"}
@@ -0,0 +1,97 @@
1
+ import { Client, Collection, Events, MessageFlags, REST, Routes, } from "discord.js";
2
+ class QuickBotz {
3
+ client;
4
+ ctx;
5
+ commands;
6
+ #config;
7
+ constructor(config) {
8
+ this.#config = config;
9
+ this.client = new Client({ intents: config.intents });
10
+ this.commands = new Collection();
11
+ this.ctx = {
12
+ client: this.client,
13
+ };
14
+ }
15
+ static multi(config) {
16
+ return new QuickBotz({ ...config, mode: "multi" });
17
+ }
18
+ static single(config) {
19
+ return new QuickBotz({ ...config, mode: "single" });
20
+ }
21
+ registerEvent = (event, once = false, callback) => {
22
+ once
23
+ ? this.client.once(event, (...args) => {
24
+ return callback(this.ctx, ...args);
25
+ })
26
+ : this.client.on(event, (...args) => {
27
+ return callback(this.ctx, ...args);
28
+ });
29
+ };
30
+ registerCommand({ data, execute, autocomplete }) {
31
+ this.commands.set(data.name, { data, execute, autocomplete });
32
+ }
33
+ #setupInteractionHandler = () => {
34
+ this.client.on(Events.InteractionCreate, async (interaction) => {
35
+ if (interaction.isChatInputCommand()) {
36
+ const command = this.commands.get(interaction.commandName);
37
+ if (!command) {
38
+ return await interaction.reply({
39
+ content: `This command cannot be found.`,
40
+ flags: MessageFlags.Ephemeral,
41
+ });
42
+ }
43
+ if (interaction.isAutocomplete() && command.autocomplete) {
44
+ try {
45
+ await command.autocomplete(this.ctx, interaction);
46
+ }
47
+ catch (error) {
48
+ console.error(error);
49
+ }
50
+ return;
51
+ }
52
+ try {
53
+ await command.execute(this.ctx, interaction);
54
+ }
55
+ catch (error) {
56
+ console.error(error);
57
+ const content = "There was an error while executing this command";
58
+ if (interaction.replied || interaction.deferred) {
59
+ return await interaction.followUp({
60
+ content,
61
+ flags: MessageFlags.Ephemeral,
62
+ });
63
+ }
64
+ await interaction.reply({
65
+ content,
66
+ flags: MessageFlags.Ephemeral,
67
+ });
68
+ }
69
+ }
70
+ });
71
+ };
72
+ #deployCommands = async () => {
73
+ const commandsToRegister = this.commands.map((cmd) => cmd.data.toJSON());
74
+ const rest = new REST().setToken(this.#config.token);
75
+ try {
76
+ console.log(`(ℹ) Started refreshing ${commandsToRegister.length} application (/) commands.`);
77
+ let data;
78
+ if (this.#config.mode === "multi") {
79
+ data = (await rest.put(Routes.applicationCommands(this.#config.clientId), { body: commandsToRegister }));
80
+ }
81
+ else {
82
+ data = (await rest.put(Routes.applicationGuildCommands(this.#config.clientId, this.#config.guildId), { body: commandsToRegister }));
83
+ }
84
+ console.log(`(✅) Successfully reloaded ${data.length} application (/) commands.`);
85
+ }
86
+ catch (error) {
87
+ console.error(error);
88
+ }
89
+ };
90
+ start = async () => {
91
+ await this.#deployCommands();
92
+ this.#setupInteractionHandler();
93
+ this.client.login(this.#config.token);
94
+ console.log(`(⚡) QuickBotz Initialized Successfully`);
95
+ };
96
+ }
97
+ export default QuickBotz;
@@ -0,0 +1,4 @@
1
+ import QuickBotz from "./QuickBotz";
2
+ import type { Context } from "./types";
3
+ export { QuickBotz, type Context };
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,KAAK,OAAO,EAAE,CAAA"}