@mostfeatured/dbi 0.0.66 → 0.0.68
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/DBI.d.ts +181 -180
- package/dist/DBI.d.ts.map +1 -1
- package/dist/DBI.js +369 -364
- package/dist/DBI.js.map +1 -1
- package/dist/Events.d.ts +13 -19
- package/dist/Events.d.ts.map +1 -1
- package/dist/Events.js.map +1 -1
- package/dist/index.d.ts +16 -16
- package/dist/index.js +29 -29
- package/dist/methods/hookEventListeners.js +97 -97
- package/dist/methods/hookInteractionListeners.js +129 -129
- package/dist/methods/publishInteractions.d.ts +8 -8
- package/dist/methods/publishInteractions.js +241 -241
- package/dist/methods/publishInteractions.js.map +1 -1
- package/dist/types/CustomEvent.js +19 -19
- package/dist/types/Event.d.ts +265 -265
- package/dist/types/Event.js +24 -24
- package/dist/types/Interaction.d.ts +49 -49
- package/dist/types/Interaction.js +26 -26
- package/dist/utils/recursiveImport.d.ts +5 -5
- package/dist/utils/recursiveImport.js +27 -27
- package/package.json +1 -1
- package/src/DBI.ts +7 -2
- package/src/Events.ts +6 -6
- package/src/methods/publishInteractions.ts +2 -2
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import Discord from "discord.js";
|
|
2
|
-
import { NamespaceEnums, NamespaceData } from "../../generated/namespaceData";
|
|
3
|
-
import { DBI } from "../DBI";
|
|
4
|
-
import { DBIButton } from "./Button";
|
|
5
|
-
import { DBIChatInput } from "./ChatInput/ChatInput";
|
|
6
|
-
import { DBILocale } from "./Locale";
|
|
7
|
-
import { DBIMessageContextMenu } from "./MessageContextMenu";
|
|
8
|
-
import { DBIModal } from "./Modal";
|
|
9
|
-
import { DBISelectMenu } from "./SelectMenu";
|
|
10
|
-
import { DBIUserContextMenu } from "./UserContextMenu";
|
|
11
|
-
export declare type TDBIInteractions<TNamespace extends NamespaceEnums> = DBIChatInput<TNamespace> | DBIButton<TNamespace> | DBISelectMenu<TNamespace> | DBIMessageContextMenu<TNamespace> | DBIUserContextMenu<TNamespace> | DBIModal<TNamespace>;
|
|
12
|
-
export interface IDBIBaseExecuteCtx<TNamespace extends NamespaceEnums> {
|
|
13
|
-
interaction: Discord.ChatInputCommandInteraction | Discord.UserContextMenuCommandInteraction | Discord.MessageContextMenuCommandInteraction | Discord.ModalSubmitInteraction | Discord.AutocompleteInteraction | Discord.SelectMenuInteraction | Discord.ButtonInteraction;
|
|
14
|
-
locale: {
|
|
15
|
-
user: DBILocale<TNamespace>;
|
|
16
|
-
guild?: DBILocale<TNamespace>;
|
|
17
|
-
};
|
|
18
|
-
dbi: DBI<TNamespace>;
|
|
19
|
-
dbiInteraction: TDBIInteractions<TNamespace>;
|
|
20
|
-
setRateLimit(type: TDBIRateLimitTypes, duration: number): Promise<any>;
|
|
21
|
-
other: Record<string, any>;
|
|
22
|
-
clientNamespace: NamespaceData[TNamespace]["clientNamespaces"];
|
|
23
|
-
}
|
|
24
|
-
export declare type TDBIReferencedData = ({
|
|
25
|
-
[key: string]: any;
|
|
26
|
-
$ref: string;
|
|
27
|
-
$unRef(): boolean;
|
|
28
|
-
} | string | number);
|
|
29
|
-
export declare type TDBIInteractionTypes = "ChatInput" | "UserContextMenu" | "MessageContextMenu" | "Modal" | "Autocomplete" | "SelectMenu" | "Button";
|
|
30
|
-
export declare type TDBIRateLimitTypes = "User" | "Channel" | "Guild" | "Member" | "Message";
|
|
31
|
-
export declare type DBIRateLimit = {
|
|
32
|
-
type: TDBIRateLimitTypes;
|
|
33
|
-
/**
|
|
34
|
-
* Duration in milliseconds.
|
|
35
|
-
*/
|
|
36
|
-
duration: number;
|
|
37
|
-
};
|
|
38
|
-
export declare class DBIBaseInteraction<TNamespace extends NamespaceEnums> {
|
|
39
|
-
constructor(dbi: DBI<TNamespace>, cfg: Omit<DBIBaseInteraction<TNamespace>, "dbi">);
|
|
40
|
-
publish?: NamespaceData[TNamespace]["clientNamespaces"];
|
|
41
|
-
dbi: DBI<TNamespace>;
|
|
42
|
-
name: string;
|
|
43
|
-
description: string;
|
|
44
|
-
readonly type: TDBIInteractionTypes;
|
|
45
|
-
options?: any | any[];
|
|
46
|
-
other?: Record<string, any>;
|
|
47
|
-
rateLimits?: DBIRateLimit[];
|
|
48
|
-
onExecute(ctx: IDBIBaseExecuteCtx<TNamespace>): Promise<void> | void;
|
|
49
|
-
}
|
|
1
|
+
import Discord from "discord.js";
|
|
2
|
+
import { NamespaceEnums, NamespaceData } from "../../generated/namespaceData";
|
|
3
|
+
import { DBI } from "../DBI";
|
|
4
|
+
import { DBIButton } from "./Button";
|
|
5
|
+
import { DBIChatInput } from "./ChatInput/ChatInput";
|
|
6
|
+
import { DBILocale } from "./Locale";
|
|
7
|
+
import { DBIMessageContextMenu } from "./MessageContextMenu";
|
|
8
|
+
import { DBIModal } from "./Modal";
|
|
9
|
+
import { DBISelectMenu } from "./SelectMenu";
|
|
10
|
+
import { DBIUserContextMenu } from "./UserContextMenu";
|
|
11
|
+
export declare type TDBIInteractions<TNamespace extends NamespaceEnums> = DBIChatInput<TNamespace> | DBIButton<TNamespace> | DBISelectMenu<TNamespace> | DBIMessageContextMenu<TNamespace> | DBIUserContextMenu<TNamespace> | DBIModal<TNamespace>;
|
|
12
|
+
export interface IDBIBaseExecuteCtx<TNamespace extends NamespaceEnums> {
|
|
13
|
+
interaction: Discord.ChatInputCommandInteraction | Discord.UserContextMenuCommandInteraction | Discord.MessageContextMenuCommandInteraction | Discord.ModalSubmitInteraction | Discord.AutocompleteInteraction | Discord.SelectMenuInteraction | Discord.ButtonInteraction;
|
|
14
|
+
locale: {
|
|
15
|
+
user: DBILocale<TNamespace>;
|
|
16
|
+
guild?: DBILocale<TNamespace>;
|
|
17
|
+
};
|
|
18
|
+
dbi: DBI<TNamespace>;
|
|
19
|
+
dbiInteraction: TDBIInteractions<TNamespace>;
|
|
20
|
+
setRateLimit(type: TDBIRateLimitTypes, duration: number): Promise<any>;
|
|
21
|
+
other: Record<string, any>;
|
|
22
|
+
clientNamespace: NamespaceData[TNamespace]["clientNamespaces"];
|
|
23
|
+
}
|
|
24
|
+
export declare type TDBIReferencedData = ({
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
$ref: string;
|
|
27
|
+
$unRef(): boolean;
|
|
28
|
+
} | string | number);
|
|
29
|
+
export declare type TDBIInteractionTypes = "ChatInput" | "UserContextMenu" | "MessageContextMenu" | "Modal" | "Autocomplete" | "SelectMenu" | "Button";
|
|
30
|
+
export declare type TDBIRateLimitTypes = "User" | "Channel" | "Guild" | "Member" | "Message";
|
|
31
|
+
export declare type DBIRateLimit = {
|
|
32
|
+
type: TDBIRateLimitTypes;
|
|
33
|
+
/**
|
|
34
|
+
* Duration in milliseconds.
|
|
35
|
+
*/
|
|
36
|
+
duration: number;
|
|
37
|
+
};
|
|
38
|
+
export declare class DBIBaseInteraction<TNamespace extends NamespaceEnums> {
|
|
39
|
+
constructor(dbi: DBI<TNamespace>, cfg: Omit<DBIBaseInteraction<TNamespace>, "dbi">);
|
|
40
|
+
publish?: NamespaceData[TNamespace]["clientNamespaces"];
|
|
41
|
+
dbi: DBI<TNamespace>;
|
|
42
|
+
name: string;
|
|
43
|
+
description: string;
|
|
44
|
+
readonly type: TDBIInteractionTypes;
|
|
45
|
+
options?: any | any[];
|
|
46
|
+
other?: Record<string, any>;
|
|
47
|
+
rateLimits?: DBIRateLimit[];
|
|
48
|
+
onExecute(ctx: IDBIBaseExecuteCtx<TNamespace>): Promise<void> | void;
|
|
49
|
+
}
|
|
50
50
|
//# sourceMappingURL=Interaction.d.ts.map
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DBIBaseInteraction = void 0;
|
|
4
|
-
class DBIBaseInteraction {
|
|
5
|
-
constructor(dbi, cfg) {
|
|
6
|
-
this.dbi = dbi;
|
|
7
|
-
this.name = cfg.name;
|
|
8
|
-
this.description = cfg.description;
|
|
9
|
-
this.onExecute = cfg.onExecute;
|
|
10
|
-
this.type = cfg.type;
|
|
11
|
-
this.options = cfg.options;
|
|
12
|
-
this.other = cfg.other;
|
|
13
|
-
this.publish = cfg.publish ?? dbi.data.clients.first()?.namespace;
|
|
14
|
-
}
|
|
15
|
-
publish;
|
|
16
|
-
dbi;
|
|
17
|
-
name;
|
|
18
|
-
description;
|
|
19
|
-
type;
|
|
20
|
-
options;
|
|
21
|
-
other;
|
|
22
|
-
rateLimits;
|
|
23
|
-
onExecute(ctx) {
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.DBIBaseInteraction = DBIBaseInteraction;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DBIBaseInteraction = void 0;
|
|
4
|
+
class DBIBaseInteraction {
|
|
5
|
+
constructor(dbi, cfg) {
|
|
6
|
+
this.dbi = dbi;
|
|
7
|
+
this.name = cfg.name;
|
|
8
|
+
this.description = cfg.description;
|
|
9
|
+
this.onExecute = cfg.onExecute;
|
|
10
|
+
this.type = cfg.type;
|
|
11
|
+
this.options = cfg.options;
|
|
12
|
+
this.other = cfg.other;
|
|
13
|
+
this.publish = cfg.publish ?? dbi.data.clients.first()?.namespace;
|
|
14
|
+
}
|
|
15
|
+
publish;
|
|
16
|
+
dbi;
|
|
17
|
+
name;
|
|
18
|
+
description;
|
|
19
|
+
type;
|
|
20
|
+
options;
|
|
21
|
+
other;
|
|
22
|
+
rateLimits;
|
|
23
|
+
onExecute(ctx) {
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.DBIBaseInteraction = DBIBaseInteraction;
|
|
27
27
|
//# sourceMappingURL=Interaction.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @example
|
|
3
|
-
* await recursiveImport("./src", [".js"], [".d.ts"])
|
|
4
|
-
*/
|
|
5
|
-
export declare function recursiveImport(folderPath: string, exts?: string[], ignore?: string[]): Promise<any>;
|
|
1
|
+
/**
|
|
2
|
+
* @example
|
|
3
|
+
* await recursiveImport("./src", [".js"], [".d.ts"])
|
|
4
|
+
*/
|
|
5
|
+
export declare function recursiveImport(folderPath: string, exts?: string[], ignore?: string[]): Promise<any>;
|
|
6
6
|
//# sourceMappingURL=recursiveImport.d.ts.map
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.recursiveImport = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
-
/**
|
|
8
|
-
* @example
|
|
9
|
-
* await recursiveImport("./src", [".js"], [".d.ts"])
|
|
10
|
-
*/
|
|
11
|
-
async function recursiveImport(folderPath, exts = [".js"], ignore = [".d.ts", ".js.map", ".d.ts.map"]) {
|
|
12
|
-
let files = await fs_1.default.promises.readdir(folderPath, { withFileTypes: true });
|
|
13
|
-
let dirName = __dirname;
|
|
14
|
-
for (const file of files) {
|
|
15
|
-
let filePath = path_1.default.resolve(folderPath, file.name);
|
|
16
|
-
let relative = path_1.default.relative(dirName, filePath);
|
|
17
|
-
if (!relative.includes(`${path_1.default.sep}-`)) {
|
|
18
|
-
if (file.isDirectory()) {
|
|
19
|
-
await recursiveImport(filePath, exts);
|
|
20
|
-
}
|
|
21
|
-
else if (exts.some(i => file.name.endsWith(i)) && !ignore.some(i => file.name.endsWith(i))) {
|
|
22
|
-
await Promise.resolve().then(() => tslib_1.__importStar(require(filePath)));
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.recursiveImport = recursiveImport;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.recursiveImport = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
+
/**
|
|
8
|
+
* @example
|
|
9
|
+
* await recursiveImport("./src", [".js"], [".d.ts"])
|
|
10
|
+
*/
|
|
11
|
+
async function recursiveImport(folderPath, exts = [".js"], ignore = [".d.ts", ".js.map", ".d.ts.map"]) {
|
|
12
|
+
let files = await fs_1.default.promises.readdir(folderPath, { withFileTypes: true });
|
|
13
|
+
let dirName = __dirname;
|
|
14
|
+
for (const file of files) {
|
|
15
|
+
let filePath = path_1.default.resolve(folderPath, file.name);
|
|
16
|
+
let relative = path_1.default.relative(dirName, filePath);
|
|
17
|
+
if (!relative.includes(`${path_1.default.sep}-`)) {
|
|
18
|
+
if (file.isDirectory()) {
|
|
19
|
+
await recursiveImport(filePath, exts);
|
|
20
|
+
}
|
|
21
|
+
else if (exts.some(i => file.name.endsWith(i)) && !ignore.some(i => file.name.endsWith(i))) {
|
|
22
|
+
await Promise.resolve().then(() => tslib_1.__importStar(require(filePath)));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.recursiveImport = recursiveImport;
|
|
28
28
|
//# sourceMappingURL=recursiveImport.js.map
|
package/package.json
CHANGED
package/src/DBI.ts
CHANGED
|
@@ -131,6 +131,7 @@ export class DBI<TNamespace extends NamespaceEnums, TOtherData = Record<string,
|
|
|
131
131
|
& {
|
|
132
132
|
next(key?: string): DBIClientData<TNamespace>,
|
|
133
133
|
random(): DBIClientData<TNamespace>,
|
|
134
|
+
random(size: number): DBIClientData<TNamespace>[],
|
|
134
135
|
first(): DBIClientData<TNamespace>,
|
|
135
136
|
get(namespace: NamespaceData[TNamespace]["clientNamespaces"]): DBIClientData<TNamespace>,
|
|
136
137
|
indexes: Record<string, number>
|
|
@@ -178,8 +179,12 @@ export class DBI<TNamespace extends NamespaceEnums, TOtherData = Record<string,
|
|
|
178
179
|
this.indexes[key] = (((this.indexes[key] ?? -1) + 1) % this.length);
|
|
179
180
|
return this[this.indexes[key]];
|
|
180
181
|
},
|
|
181
|
-
random() {
|
|
182
|
-
|
|
182
|
+
random(size?: number) {
|
|
183
|
+
if (typeof size === "number") {
|
|
184
|
+
return this.sort(() => Math.random() - 0.5).slice(0, size);
|
|
185
|
+
} else {
|
|
186
|
+
return this[Math.floor(Math.random() * this.length)];
|
|
187
|
+
}
|
|
183
188
|
},
|
|
184
189
|
first() {
|
|
185
190
|
return this[0];
|
package/src/Events.ts
CHANGED
|
@@ -6,6 +6,10 @@ import { DBILocale } from "./types/Locale";
|
|
|
6
6
|
|
|
7
7
|
export type TDBIEventNames = "beforeInteraction" | "afterInteraction" | "interactionRateLimit" | "beforeEvent" | "afterEvent" | "interactionError" | "eventError";
|
|
8
8
|
|
|
9
|
+
export type TDBIEventHandlerCtx<TNamespace extends NamespaceEnums> = {
|
|
10
|
+
[K in keyof (ClientEvents & NamespaceData[TNamespace]["customEvents"])]: { other: Record<string, any>, locale?: { guild: DBILocale<TNamespace> }, eventName: K } & (ClientEvents & NamespaceData[TNamespace]["customEvents"])[K]
|
|
11
|
+
}[keyof (ClientEvents & NamespaceData[TNamespace]["customEvents"])];
|
|
12
|
+
|
|
9
13
|
export class Events<TNamespace extends NamespaceEnums> {
|
|
10
14
|
DBI: DBI<TNamespace>;
|
|
11
15
|
handlers: Record<string, Array<(data: any) => boolean | Promise<boolean>>>;
|
|
@@ -49,17 +53,13 @@ export class Events<TNamespace extends NamespaceEnums> {
|
|
|
49
53
|
|
|
50
54
|
on(
|
|
51
55
|
eventName: "beforeEvent" | "afterEvent",
|
|
52
|
-
handler: (data:
|
|
53
|
-
[K in keyof (ClientEvents & NamespaceData[TNamespace]["customEvents"])]: { other: Record<string, any>, locale?: { guild: DBILocale<TNamespace> }, eventName: K } & (ClientEvents & NamespaceData[TNamespace]["customEvents"])[K]
|
|
54
|
-
}[keyof (ClientEvents & NamespaceData[TNamespace]["customEvents"])]) => Promise<boolean> | boolean,
|
|
56
|
+
handler: (data: TDBIEventHandlerCtx<TNamespace>) => Promise<boolean> | boolean,
|
|
55
57
|
options?: { once: boolean }
|
|
56
58
|
): (() => any);
|
|
57
59
|
|
|
58
60
|
on(
|
|
59
61
|
eventName: "eventError",
|
|
60
|
-
handler: (data: {
|
|
61
|
-
[K in keyof (ClientEvents & NamespaceData[TNamespace]["customEvents"])]: { other: Record<string, any>, locale?: { guild: DBILocale<TNamespace> }, eventName: K, error: any } & (ClientEvents & NamespaceData[TNamespace]["customEvents"])[K]
|
|
62
|
-
}[keyof (ClientEvents & NamespaceData[TNamespace]["customEvents"])]) => Promise<boolean> | boolean,
|
|
62
|
+
handler: (data: TDBIEventHandlerCtx<TNamespace> & { error: any }) => Promise<boolean> | boolean,
|
|
63
63
|
options?: { once: boolean }
|
|
64
64
|
): (() => any);
|
|
65
65
|
|
|
@@ -176,11 +176,11 @@ export async function publishInteractions(
|
|
|
176
176
|
|
|
177
177
|
switch (publishType) {
|
|
178
178
|
case "Guild": {
|
|
179
|
-
await rest.put(Routes.applicationGuildCommands(me.id, guildId), { body: body[client.namespace] });
|
|
179
|
+
await rest.put(Routes.applicationGuildCommands(me.id, guildId), { body: body[client.namespace] || [] });
|
|
180
180
|
break;
|
|
181
181
|
}
|
|
182
182
|
case "Global": {
|
|
183
|
-
await rest.put(Routes.applicationCommands(me.id), { body: body[client.namespace] });
|
|
183
|
+
await rest.put(Routes.applicationCommands(me.id), { body: body[client.namespace] || [] });
|
|
184
184
|
break;
|
|
185
185
|
}
|
|
186
186
|
}
|