@mostfeatured/dbi 0.0.67 → 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 -181
- package/dist/DBI.js +369 -369
- package/dist/Events.d.ts +47 -47
- 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/methods/publishInteractions.ts +2 -2
package/dist/Events.d.ts
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { NamespaceEnums, NamespaceData } from "../generated/namespaceData";
|
|
2
|
-
import { DBI } from "./DBI";
|
|
3
|
-
import { ClientEvents } from "./types/Event";
|
|
4
|
-
import { IDBIBaseExecuteCtx, TDBIRateLimitTypes } from "./types/Interaction";
|
|
5
|
-
import { DBILocale } from "./types/Locale";
|
|
6
|
-
export declare type TDBIEventNames = "beforeInteraction" | "afterInteraction" | "interactionRateLimit" | "beforeEvent" | "afterEvent" | "interactionError" | "eventError";
|
|
7
|
-
export declare type TDBIEventHandlerCtx<TNamespace extends NamespaceEnums> = {
|
|
8
|
-
[K in keyof (ClientEvents & NamespaceData[TNamespace]["customEvents"])]: {
|
|
9
|
-
other: Record<string, any>;
|
|
10
|
-
locale?: {
|
|
11
|
-
guild: DBILocale<TNamespace>;
|
|
12
|
-
};
|
|
13
|
-
eventName: K;
|
|
14
|
-
} & (ClientEvents & NamespaceData[TNamespace]["customEvents"])[K];
|
|
15
|
-
}[keyof (ClientEvents & NamespaceData[TNamespace]["customEvents"])];
|
|
16
|
-
export declare class Events<TNamespace extends NamespaceEnums> {
|
|
17
|
-
DBI: DBI<TNamespace>;
|
|
18
|
-
handlers: Record<string, Array<(data: any) => boolean | Promise<boolean>>>;
|
|
19
|
-
constructor(DBI: DBI<TNamespace>);
|
|
20
|
-
trigger(name: TDBIEventNames, data: any): Promise<boolean>;
|
|
21
|
-
on(eventName: "beforeInteraction" | "afterInteraction", handler: (data: IDBIBaseExecuteCtx<TNamespace>) => Promise<boolean> | boolean, options?: {
|
|
22
|
-
once: boolean;
|
|
23
|
-
}): (() => any);
|
|
24
|
-
on(eventName: "interactionError", handler: (data: IDBIBaseExecuteCtx<TNamespace> & {
|
|
25
|
-
error: any;
|
|
26
|
-
}) => Promise<boolean> | boolean, options?: {
|
|
27
|
-
once: boolean;
|
|
28
|
-
}): (() => any);
|
|
29
|
-
on(eventName: "beforeEvent" | "afterEvent", handler: (data: TDBIEventHandlerCtx<TNamespace>) => Promise<boolean> | boolean, options?: {
|
|
30
|
-
once: boolean;
|
|
31
|
-
}): (() => any);
|
|
32
|
-
on(eventName: "eventError", handler: (data: TDBIEventHandlerCtx<TNamespace> & {
|
|
33
|
-
error: any;
|
|
34
|
-
}) => Promise<boolean> | boolean, options?: {
|
|
35
|
-
once: boolean;
|
|
36
|
-
}): (() => any);
|
|
37
|
-
on(eventName: "interactionRateLimit", handler: (data: Omit<IDBIBaseExecuteCtx<TNamespace>, "other" | "setRateLimit"> & {
|
|
38
|
-
rateLimit: {
|
|
39
|
-
type: TDBIRateLimitTypes;
|
|
40
|
-
duration: number;
|
|
41
|
-
at: number;
|
|
42
|
-
};
|
|
43
|
-
}) => Promise<boolean> | boolean, options?: {
|
|
44
|
-
once: boolean;
|
|
45
|
-
}): (() => any);
|
|
46
|
-
off(eventName: TDBIEventNames, handler: (data: any) => Promise<boolean> | boolean): ((data: any) => boolean | Promise<boolean>)[];
|
|
47
|
-
}
|
|
1
|
+
import { NamespaceEnums, NamespaceData } from "../generated/namespaceData";
|
|
2
|
+
import { DBI } from "./DBI";
|
|
3
|
+
import { ClientEvents } from "./types/Event";
|
|
4
|
+
import { IDBIBaseExecuteCtx, TDBIRateLimitTypes } from "./types/Interaction";
|
|
5
|
+
import { DBILocale } from "./types/Locale";
|
|
6
|
+
export declare type TDBIEventNames = "beforeInteraction" | "afterInteraction" | "interactionRateLimit" | "beforeEvent" | "afterEvent" | "interactionError" | "eventError";
|
|
7
|
+
export declare type TDBIEventHandlerCtx<TNamespace extends NamespaceEnums> = {
|
|
8
|
+
[K in keyof (ClientEvents & NamespaceData[TNamespace]["customEvents"])]: {
|
|
9
|
+
other: Record<string, any>;
|
|
10
|
+
locale?: {
|
|
11
|
+
guild: DBILocale<TNamespace>;
|
|
12
|
+
};
|
|
13
|
+
eventName: K;
|
|
14
|
+
} & (ClientEvents & NamespaceData[TNamespace]["customEvents"])[K];
|
|
15
|
+
}[keyof (ClientEvents & NamespaceData[TNamespace]["customEvents"])];
|
|
16
|
+
export declare class Events<TNamespace extends NamespaceEnums> {
|
|
17
|
+
DBI: DBI<TNamespace>;
|
|
18
|
+
handlers: Record<string, Array<(data: any) => boolean | Promise<boolean>>>;
|
|
19
|
+
constructor(DBI: DBI<TNamespace>);
|
|
20
|
+
trigger(name: TDBIEventNames, data: any): Promise<boolean>;
|
|
21
|
+
on(eventName: "beforeInteraction" | "afterInteraction", handler: (data: IDBIBaseExecuteCtx<TNamespace>) => Promise<boolean> | boolean, options?: {
|
|
22
|
+
once: boolean;
|
|
23
|
+
}): (() => any);
|
|
24
|
+
on(eventName: "interactionError", handler: (data: IDBIBaseExecuteCtx<TNamespace> & {
|
|
25
|
+
error: any;
|
|
26
|
+
}) => Promise<boolean> | boolean, options?: {
|
|
27
|
+
once: boolean;
|
|
28
|
+
}): (() => any);
|
|
29
|
+
on(eventName: "beforeEvent" | "afterEvent", handler: (data: TDBIEventHandlerCtx<TNamespace>) => Promise<boolean> | boolean, options?: {
|
|
30
|
+
once: boolean;
|
|
31
|
+
}): (() => any);
|
|
32
|
+
on(eventName: "eventError", handler: (data: TDBIEventHandlerCtx<TNamespace> & {
|
|
33
|
+
error: any;
|
|
34
|
+
}) => Promise<boolean> | boolean, options?: {
|
|
35
|
+
once: boolean;
|
|
36
|
+
}): (() => any);
|
|
37
|
+
on(eventName: "interactionRateLimit", handler: (data: Omit<IDBIBaseExecuteCtx<TNamespace>, "other" | "setRateLimit"> & {
|
|
38
|
+
rateLimit: {
|
|
39
|
+
type: TDBIRateLimitTypes;
|
|
40
|
+
duration: number;
|
|
41
|
+
at: number;
|
|
42
|
+
};
|
|
43
|
+
}) => Promise<boolean> | boolean, options?: {
|
|
44
|
+
once: boolean;
|
|
45
|
+
}): (() => any);
|
|
46
|
+
off(eventName: TDBIEventNames, handler: (data: any) => Promise<boolean> | boolean): ((data: any) => boolean | Promise<boolean>)[];
|
|
47
|
+
}
|
|
48
48
|
//# sourceMappingURL=Events.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { NamespaceEnums } from "../generated/namespaceData";
|
|
2
|
-
import { DBI, DBIConfigConstructor } from "./DBI";
|
|
3
|
-
import { recursiveImport as _recursiveImport } from "./utils/recursiveImport";
|
|
4
|
-
export { MemoryStore } from "./utils/MemoryStore";
|
|
5
|
-
import { parseCustomId, buildCustomId } from "./utils/customId";
|
|
6
|
-
export declare const generatedPath: string;
|
|
7
|
-
export declare function createDBI<TNamespace extends NamespaceEnums, TOtherType = Record<string, any>>(namespace: TNamespace, cfg: DBIConfigConstructor): DBI<TNamespace, TOtherType>;
|
|
8
|
-
export declare const Utils: {
|
|
9
|
-
parseCustomId: typeof parseCustomId;
|
|
10
|
-
buildCustomId: typeof buildCustomId;
|
|
11
|
-
recursiveImport: typeof _recursiveImport;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated
|
|
15
|
-
*/
|
|
16
|
-
export declare function recursiveImport(...args: any[]): Promise<any>;
|
|
1
|
+
import { NamespaceEnums } from "../generated/namespaceData";
|
|
2
|
+
import { DBI, DBIConfigConstructor } from "./DBI";
|
|
3
|
+
import { recursiveImport as _recursiveImport } from "./utils/recursiveImport";
|
|
4
|
+
export { MemoryStore } from "./utils/MemoryStore";
|
|
5
|
+
import { parseCustomId, buildCustomId } from "./utils/customId";
|
|
6
|
+
export declare const generatedPath: string;
|
|
7
|
+
export declare function createDBI<TNamespace extends NamespaceEnums, TOtherType = Record<string, any>>(namespace: TNamespace, cfg: DBIConfigConstructor): DBI<TNamespace, TOtherType>;
|
|
8
|
+
export declare const Utils: {
|
|
9
|
+
parseCustomId: typeof parseCustomId;
|
|
10
|
+
buildCustomId: typeof buildCustomId;
|
|
11
|
+
recursiveImport: typeof _recursiveImport;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated
|
|
15
|
+
*/
|
|
16
|
+
export declare function recursiveImport(...args: any[]): Promise<any>;
|
|
17
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.recursiveImport = exports.Utils = exports.createDBI = exports.generatedPath = exports.MemoryStore = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const DBI_1 = require("./DBI");
|
|
6
|
-
const recursiveImport_1 = require("./utils/recursiveImport");
|
|
7
|
-
var MemoryStore_1 = require("./utils/MemoryStore");
|
|
8
|
-
Object.defineProperty(exports, "MemoryStore", { enumerable: true, get: function () { return MemoryStore_1.MemoryStore; } });
|
|
9
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
10
|
-
const customId_1 = require("./utils/customId");
|
|
11
|
-
exports.generatedPath = path_1.default.resolve(__dirname, "../generated");
|
|
12
|
-
function createDBI(namespace, cfg) {
|
|
13
|
-
return new DBI_1.DBI(namespace, cfg);
|
|
14
|
-
}
|
|
15
|
-
exports.createDBI = createDBI;
|
|
16
|
-
;
|
|
17
|
-
exports.Utils = {
|
|
18
|
-
parseCustomId: customId_1.parseCustomId,
|
|
19
|
-
buildCustomId: customId_1.buildCustomId,
|
|
20
|
-
recursiveImport: recursiveImport_1.recursiveImport
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* @deprecated
|
|
24
|
-
*/
|
|
25
|
-
async function recursiveImport(...args) {
|
|
26
|
-
console.log("[DEPRECTED] recursiveImport is a deprected api. Please use Utils.recursiveImport instead.", Error().stack);
|
|
27
|
-
return await recursiveImport_1.recursiveImport.call(this, ...args);
|
|
28
|
-
}
|
|
29
|
-
exports.recursiveImport = recursiveImport;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.recursiveImport = exports.Utils = exports.createDBI = exports.generatedPath = exports.MemoryStore = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const DBI_1 = require("./DBI");
|
|
6
|
+
const recursiveImport_1 = require("./utils/recursiveImport");
|
|
7
|
+
var MemoryStore_1 = require("./utils/MemoryStore");
|
|
8
|
+
Object.defineProperty(exports, "MemoryStore", { enumerable: true, get: function () { return MemoryStore_1.MemoryStore; } });
|
|
9
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
10
|
+
const customId_1 = require("./utils/customId");
|
|
11
|
+
exports.generatedPath = path_1.default.resolve(__dirname, "../generated");
|
|
12
|
+
function createDBI(namespace, cfg) {
|
|
13
|
+
return new DBI_1.DBI(namespace, cfg);
|
|
14
|
+
}
|
|
15
|
+
exports.createDBI = createDBI;
|
|
16
|
+
;
|
|
17
|
+
exports.Utils = {
|
|
18
|
+
parseCustomId: customId_1.parseCustomId,
|
|
19
|
+
buildCustomId: customId_1.buildCustomId,
|
|
20
|
+
recursiveImport: recursiveImport_1.recursiveImport
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated
|
|
24
|
+
*/
|
|
25
|
+
async function recursiveImport(...args) {
|
|
26
|
+
console.log("[DEPRECTED] recursiveImport is a deprected api. Please use Utils.recursiveImport instead.", Error().stack);
|
|
27
|
+
return await recursiveImport_1.recursiveImport.call(this, ...args);
|
|
28
|
+
}
|
|
29
|
+
exports.recursiveImport = recursiveImport;
|
|
30
30
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hookEventListeners = void 0;
|
|
4
|
-
const discord_js_1 = require("discord.js");
|
|
5
|
-
function hookEventListeners(dbi) {
|
|
6
|
-
function getClientByEvent(value) {
|
|
7
|
-
return value.triggerType == "OneByOne"
|
|
8
|
-
? dbi.data.clients.next(`Event:${value.id}`)
|
|
9
|
-
: value.triggerType == "OneByOneGlobal"
|
|
10
|
-
? dbi.data.clients.next("Event")
|
|
11
|
-
: value.triggerType == "Random"
|
|
12
|
-
? dbi.data.clients.random()
|
|
13
|
-
: dbi.data.clients.first();
|
|
14
|
-
}
|
|
15
|
-
async function handle(eventName, ...args) {
|
|
16
|
-
if (!dbi.data.eventMap[eventName])
|
|
17
|
-
return;
|
|
18
|
-
let isDirect = args?.[0]?._DIRECT_ ?? false;
|
|
19
|
-
if (isDirect)
|
|
20
|
-
delete args[0]._DIRECT_;
|
|
21
|
-
let ctxArgs = isDirect
|
|
22
|
-
? args[0]
|
|
23
|
-
: dbi.data.eventMap[eventName].reduce((all, current, index) => {
|
|
24
|
-
all[current] = args[index];
|
|
25
|
-
return all;
|
|
26
|
-
}, {});
|
|
27
|
-
let other = {};
|
|
28
|
-
let guildLocaleName = args.reduce((all, current) => {
|
|
29
|
-
if (current?.guild?.id)
|
|
30
|
-
return current?.guild?.preferredLocale?.split?.("-")?.[0];
|
|
31
|
-
if (current instanceof discord_js_1.Guild)
|
|
32
|
-
return current?.preferredLocale?.split?.("-")?.[0];
|
|
33
|
-
return all;
|
|
34
|
-
}, null);
|
|
35
|
-
let guildLocale = guildLocaleName ? (dbi.data.locales.has(guildLocaleName) ? dbi.data.locales.get(guildLocaleName) : dbi.data.locales.get(dbi.config.defaults.locale)) : null;
|
|
36
|
-
let locale = guildLocale ? { guild: guildLocale } : null;
|
|
37
|
-
if (!await dbi.events.trigger("beforeEvent", { eventName, ...ctxArgs, other, locale }))
|
|
38
|
-
return;
|
|
39
|
-
let ordered = [];
|
|
40
|
-
let unOrdered = [];
|
|
41
|
-
for (let i = 0; i < dbi.data.events.size; i++) {
|
|
42
|
-
const value = dbi.data.events.at(i);
|
|
43
|
-
if (value.name == eventName) {
|
|
44
|
-
if (value.ordered) {
|
|
45
|
-
ordered.push(value);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
unOrdered.push(value);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
let arg = { eventName, ...ctxArgs, other, locale };
|
|
53
|
-
for (let i = 0; i < unOrdered.length; i++) {
|
|
54
|
-
const value = unOrdered[i];
|
|
55
|
-
if (dbi.config.strict) {
|
|
56
|
-
value.onExecute({ ...arg, nextClient: getClientByEvent(value) });
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
try {
|
|
60
|
-
value.onExecute({ ...arg, nextClient: getClientByEvent(value) })?.catch(error => {
|
|
61
|
-
dbi.events.trigger("eventError", Object.assign(arg, { error }));
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
dbi.events.trigger("eventError", Object.assign(arg, { error }));
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
for (let i = 0; i < ordered.length; i++) {
|
|
70
|
-
const value = ordered[i];
|
|
71
|
-
if (dbi.config.strict) {
|
|
72
|
-
await value.onExecute({ ...arg, nextClient: getClientByEvent(value) });
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
try {
|
|
76
|
-
await value.onExecute({ ...arg, nextClient: getClientByEvent(value) })?.catch(error => {
|
|
77
|
-
dbi.events.trigger("eventError", Object.assign(arg, { error }));
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
await dbi.events.trigger("eventError", Object.assign(arg, { error }));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
dbi.events.trigger("afterEvent", arg);
|
|
86
|
-
}
|
|
87
|
-
let firstClient = dbi.data.clients.first().client;
|
|
88
|
-
let originalEmit = firstClient.emit;
|
|
89
|
-
firstClient.emit = function (eventName, ...args) {
|
|
90
|
-
handle(eventName, ...args);
|
|
91
|
-
return originalEmit.call(this, eventName, ...args);
|
|
92
|
-
};
|
|
93
|
-
return () => {
|
|
94
|
-
firstClient.emit = originalEmit;
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
exports.hookEventListeners = hookEventListeners;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hookEventListeners = void 0;
|
|
4
|
+
const discord_js_1 = require("discord.js");
|
|
5
|
+
function hookEventListeners(dbi) {
|
|
6
|
+
function getClientByEvent(value) {
|
|
7
|
+
return value.triggerType == "OneByOne"
|
|
8
|
+
? dbi.data.clients.next(`Event:${value.id}`)
|
|
9
|
+
: value.triggerType == "OneByOneGlobal"
|
|
10
|
+
? dbi.data.clients.next("Event")
|
|
11
|
+
: value.triggerType == "Random"
|
|
12
|
+
? dbi.data.clients.random()
|
|
13
|
+
: dbi.data.clients.first();
|
|
14
|
+
}
|
|
15
|
+
async function handle(eventName, ...args) {
|
|
16
|
+
if (!dbi.data.eventMap[eventName])
|
|
17
|
+
return;
|
|
18
|
+
let isDirect = args?.[0]?._DIRECT_ ?? false;
|
|
19
|
+
if (isDirect)
|
|
20
|
+
delete args[0]._DIRECT_;
|
|
21
|
+
let ctxArgs = isDirect
|
|
22
|
+
? args[0]
|
|
23
|
+
: dbi.data.eventMap[eventName].reduce((all, current, index) => {
|
|
24
|
+
all[current] = args[index];
|
|
25
|
+
return all;
|
|
26
|
+
}, {});
|
|
27
|
+
let other = {};
|
|
28
|
+
let guildLocaleName = args.reduce((all, current) => {
|
|
29
|
+
if (current?.guild?.id)
|
|
30
|
+
return current?.guild?.preferredLocale?.split?.("-")?.[0];
|
|
31
|
+
if (current instanceof discord_js_1.Guild)
|
|
32
|
+
return current?.preferredLocale?.split?.("-")?.[0];
|
|
33
|
+
return all;
|
|
34
|
+
}, null);
|
|
35
|
+
let guildLocale = guildLocaleName ? (dbi.data.locales.has(guildLocaleName) ? dbi.data.locales.get(guildLocaleName) : dbi.data.locales.get(dbi.config.defaults.locale)) : null;
|
|
36
|
+
let locale = guildLocale ? { guild: guildLocale } : null;
|
|
37
|
+
if (!await dbi.events.trigger("beforeEvent", { eventName, ...ctxArgs, other, locale }))
|
|
38
|
+
return;
|
|
39
|
+
let ordered = [];
|
|
40
|
+
let unOrdered = [];
|
|
41
|
+
for (let i = 0; i < dbi.data.events.size; i++) {
|
|
42
|
+
const value = dbi.data.events.at(i);
|
|
43
|
+
if (value.name == eventName) {
|
|
44
|
+
if (value.ordered) {
|
|
45
|
+
ordered.push(value);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
unOrdered.push(value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
let arg = { eventName, ...ctxArgs, other, locale };
|
|
53
|
+
for (let i = 0; i < unOrdered.length; i++) {
|
|
54
|
+
const value = unOrdered[i];
|
|
55
|
+
if (dbi.config.strict) {
|
|
56
|
+
value.onExecute({ ...arg, nextClient: getClientByEvent(value) });
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
try {
|
|
60
|
+
value.onExecute({ ...arg, nextClient: getClientByEvent(value) })?.catch(error => {
|
|
61
|
+
dbi.events.trigger("eventError", Object.assign(arg, { error }));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
dbi.events.trigger("eventError", Object.assign(arg, { error }));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (let i = 0; i < ordered.length; i++) {
|
|
70
|
+
const value = ordered[i];
|
|
71
|
+
if (dbi.config.strict) {
|
|
72
|
+
await value.onExecute({ ...arg, nextClient: getClientByEvent(value) });
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
try {
|
|
76
|
+
await value.onExecute({ ...arg, nextClient: getClientByEvent(value) })?.catch(error => {
|
|
77
|
+
dbi.events.trigger("eventError", Object.assign(arg, { error }));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
await dbi.events.trigger("eventError", Object.assign(arg, { error }));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
dbi.events.trigger("afterEvent", arg);
|
|
86
|
+
}
|
|
87
|
+
let firstClient = dbi.data.clients.first().client;
|
|
88
|
+
let originalEmit = firstClient.emit;
|
|
89
|
+
firstClient.emit = function (eventName, ...args) {
|
|
90
|
+
handle(eventName, ...args);
|
|
91
|
+
return originalEmit.call(this, eventName, ...args);
|
|
92
|
+
};
|
|
93
|
+
return () => {
|
|
94
|
+
firstClient.emit = originalEmit;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
exports.hookEventListeners = hookEventListeners;
|
|
98
98
|
//# sourceMappingURL=hookEventListeners.js.map
|
|
@@ -1,130 +1,130 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hookInteractionListeners = void 0;
|
|
4
|
-
const customId_1 = require("../utils/customId");
|
|
5
|
-
function hookInteractionListeners(dbi) {
|
|
6
|
-
async function handle(inter) {
|
|
7
|
-
const dbiInter = dbi.data.interactions.find(i => {
|
|
8
|
-
let isUsesCustomId = (inter.isButton() || inter.isStringSelectMenu() || inter.isModalSubmit());
|
|
9
|
-
let parsedId = isUsesCustomId ? (0, customId_1.parseCustomId)(dbi, inter.customId) : null;
|
|
10
|
-
return ((i.type == "ChatInput"
|
|
11
|
-
&& (inter.isChatInputCommand() || inter.isAutocomplete())
|
|
12
|
-
&& i.name == [inter.commandName, inter.options.getSubcommandGroup(false), inter.options.getSubcommand(false)].filter(i => !!i).join(" "))
|
|
13
|
-
||
|
|
14
|
-
((i.type == "MessageContextMenu" || i.type == "UserContextMenu")
|
|
15
|
-
&& (inter.isMessageContextMenuCommand() || inter.isUserContextMenuCommand())
|
|
16
|
-
&& inter.commandName == i.name)
|
|
17
|
-
||
|
|
18
|
-
((i.type == "Button" || i.type == "SelectMenu" || i.type == "Modal")
|
|
19
|
-
&& isUsesCustomId
|
|
20
|
-
&& parsedId?.name == i.name));
|
|
21
|
-
});
|
|
22
|
-
if (!dbiInter)
|
|
23
|
-
return;
|
|
24
|
-
let userLocaleName = inter.locale.split("-")[0];
|
|
25
|
-
let userLocale = dbi.data.locales.has(userLocaleName) ? dbi.data.locales.get(userLocaleName) : dbi.data.locales.get(dbi.config.defaults.locale);
|
|
26
|
-
let guildLocaleName = inter.guild ? inter.guild.preferredLocale.split("-")[0] : null;
|
|
27
|
-
let guildLocale = guildLocaleName ? (dbi.data.locales.has(guildLocaleName) ? dbi.data.locales.get(guildLocaleName) : dbi.data.locales.get(dbi.config.defaults.locale)) : null;
|
|
28
|
-
let locale = {
|
|
29
|
-
user: userLocale,
|
|
30
|
-
guild: guildLocale
|
|
31
|
-
};
|
|
32
|
-
let data = (inter.isButton() || inter.isStringSelectMenu() || inter.isModalSubmit()) ? (0, customId_1.parseCustomId)(dbi, inter.customId).data : undefined;
|
|
33
|
-
let other = {};
|
|
34
|
-
if (!(await dbi.events.trigger("beforeInteraction", { dbi, interaction: inter, locale, setRateLimit, data, other, dbiInteraction: dbiInter })))
|
|
35
|
-
return;
|
|
36
|
-
if (inter.isAutocomplete()) {
|
|
37
|
-
let focussed = inter.options.getFocused(true);
|
|
38
|
-
let option = dbiInter.options.find(i => i.name == focussed.name);
|
|
39
|
-
if (option?.onComplete) {
|
|
40
|
-
let response = await option.onComplete({
|
|
41
|
-
value: focussed.value,
|
|
42
|
-
interaction: inter,
|
|
43
|
-
dbiInteraction: dbiInter,
|
|
44
|
-
dbi,
|
|
45
|
-
data,
|
|
46
|
-
other,
|
|
47
|
-
locale
|
|
48
|
-
});
|
|
49
|
-
await inter.respond(response);
|
|
50
|
-
}
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
let rateLimitKeyMap = {
|
|
54
|
-
"User": `${dbiInter.name}_${inter.user.id}`,
|
|
55
|
-
"Channel": `${dbiInter.name}_${inter.channelId || "Channel"}`,
|
|
56
|
-
"Guild": `${dbiInter.name}_${inter.guildId || "Guild"}`,
|
|
57
|
-
"Member": `${dbiInter.name}_${inter.user.id}_${inter.guildId || "Guild"}`,
|
|
58
|
-
"Message": `${dbiInter.name}_${inter?.message?.id}`
|
|
59
|
-
};
|
|
60
|
-
for (const type in rateLimitKeyMap) {
|
|
61
|
-
// @ts-ignore
|
|
62
|
-
let key = `RateLimit["${rateLimitKeyMap[type]}"]`;
|
|
63
|
-
let val = await dbi.config.store.get(key);
|
|
64
|
-
if (val && Date.now() > val.at + val.duration) {
|
|
65
|
-
await dbi.config.store.delete(key);
|
|
66
|
-
val = null;
|
|
67
|
-
}
|
|
68
|
-
if (val) {
|
|
69
|
-
dbi.events.trigger("interactionRateLimit", {
|
|
70
|
-
dbi,
|
|
71
|
-
interaction: inter,
|
|
72
|
-
dbiInteraction: dbiInter,
|
|
73
|
-
locale,
|
|
74
|
-
data,
|
|
75
|
-
rateLimit: {
|
|
76
|
-
type: key,
|
|
77
|
-
...val
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
async function setRateLimit(type, duration) {
|
|
84
|
-
// @ts-ignore
|
|
85
|
-
await dbi.config.store.set(`RateLimit["${rateLimitKeyMap[type]}"]`, { at: Date.now(), duration });
|
|
86
|
-
}
|
|
87
|
-
let arg = {
|
|
88
|
-
// @ts-ignore
|
|
89
|
-
dbi,
|
|
90
|
-
// @ts-ignore
|
|
91
|
-
interaction: inter,
|
|
92
|
-
// @ts-ignore
|
|
93
|
-
dbiInteraction: dbiInter,
|
|
94
|
-
// @ts-ignore
|
|
95
|
-
locale,
|
|
96
|
-
// @ts-ignore
|
|
97
|
-
setRateLimit,
|
|
98
|
-
// @ts-ignore
|
|
99
|
-
data,
|
|
100
|
-
// @ts-ignore
|
|
101
|
-
other
|
|
102
|
-
};
|
|
103
|
-
if (dbi.config.strict) {
|
|
104
|
-
// @ts-ignore
|
|
105
|
-
await dbiInter.onExecute(arg);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
try {
|
|
109
|
-
// @ts-ignore
|
|
110
|
-
await dbiInter.onExecute(arg);
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
// @ts-ignore
|
|
114
|
-
await dbi.events.trigger("interactionError", Object.assign(arg, { error }));
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
// @ts-ignore
|
|
118
|
-
dbi.events.trigger("afterInteraction", { dbi, interaction: inter, dbiInteraction: dbiInter, locale, setRateLimit, data, other });
|
|
119
|
-
}
|
|
120
|
-
dbi.data.clients.forEach(d => {
|
|
121
|
-
d.client.on("interactionCreate", handle);
|
|
122
|
-
});
|
|
123
|
-
return () => {
|
|
124
|
-
dbi.data.clients.forEach(d => {
|
|
125
|
-
d.client.off("interactionCreate", handle);
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
exports.hookInteractionListeners = hookInteractionListeners;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hookInteractionListeners = void 0;
|
|
4
|
+
const customId_1 = require("../utils/customId");
|
|
5
|
+
function hookInteractionListeners(dbi) {
|
|
6
|
+
async function handle(inter) {
|
|
7
|
+
const dbiInter = dbi.data.interactions.find(i => {
|
|
8
|
+
let isUsesCustomId = (inter.isButton() || inter.isStringSelectMenu() || inter.isModalSubmit());
|
|
9
|
+
let parsedId = isUsesCustomId ? (0, customId_1.parseCustomId)(dbi, inter.customId) : null;
|
|
10
|
+
return ((i.type == "ChatInput"
|
|
11
|
+
&& (inter.isChatInputCommand() || inter.isAutocomplete())
|
|
12
|
+
&& i.name == [inter.commandName, inter.options.getSubcommandGroup(false), inter.options.getSubcommand(false)].filter(i => !!i).join(" "))
|
|
13
|
+
||
|
|
14
|
+
((i.type == "MessageContextMenu" || i.type == "UserContextMenu")
|
|
15
|
+
&& (inter.isMessageContextMenuCommand() || inter.isUserContextMenuCommand())
|
|
16
|
+
&& inter.commandName == i.name)
|
|
17
|
+
||
|
|
18
|
+
((i.type == "Button" || i.type == "SelectMenu" || i.type == "Modal")
|
|
19
|
+
&& isUsesCustomId
|
|
20
|
+
&& parsedId?.name == i.name));
|
|
21
|
+
});
|
|
22
|
+
if (!dbiInter)
|
|
23
|
+
return;
|
|
24
|
+
let userLocaleName = inter.locale.split("-")[0];
|
|
25
|
+
let userLocale = dbi.data.locales.has(userLocaleName) ? dbi.data.locales.get(userLocaleName) : dbi.data.locales.get(dbi.config.defaults.locale);
|
|
26
|
+
let guildLocaleName = inter.guild ? inter.guild.preferredLocale.split("-")[0] : null;
|
|
27
|
+
let guildLocale = guildLocaleName ? (dbi.data.locales.has(guildLocaleName) ? dbi.data.locales.get(guildLocaleName) : dbi.data.locales.get(dbi.config.defaults.locale)) : null;
|
|
28
|
+
let locale = {
|
|
29
|
+
user: userLocale,
|
|
30
|
+
guild: guildLocale
|
|
31
|
+
};
|
|
32
|
+
let data = (inter.isButton() || inter.isStringSelectMenu() || inter.isModalSubmit()) ? (0, customId_1.parseCustomId)(dbi, inter.customId).data : undefined;
|
|
33
|
+
let other = {};
|
|
34
|
+
if (!(await dbi.events.trigger("beforeInteraction", { dbi, interaction: inter, locale, setRateLimit, data, other, dbiInteraction: dbiInter })))
|
|
35
|
+
return;
|
|
36
|
+
if (inter.isAutocomplete()) {
|
|
37
|
+
let focussed = inter.options.getFocused(true);
|
|
38
|
+
let option = dbiInter.options.find(i => i.name == focussed.name);
|
|
39
|
+
if (option?.onComplete) {
|
|
40
|
+
let response = await option.onComplete({
|
|
41
|
+
value: focussed.value,
|
|
42
|
+
interaction: inter,
|
|
43
|
+
dbiInteraction: dbiInter,
|
|
44
|
+
dbi,
|
|
45
|
+
data,
|
|
46
|
+
other,
|
|
47
|
+
locale
|
|
48
|
+
});
|
|
49
|
+
await inter.respond(response);
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
let rateLimitKeyMap = {
|
|
54
|
+
"User": `${dbiInter.name}_${inter.user.id}`,
|
|
55
|
+
"Channel": `${dbiInter.name}_${inter.channelId || "Channel"}`,
|
|
56
|
+
"Guild": `${dbiInter.name}_${inter.guildId || "Guild"}`,
|
|
57
|
+
"Member": `${dbiInter.name}_${inter.user.id}_${inter.guildId || "Guild"}`,
|
|
58
|
+
"Message": `${dbiInter.name}_${inter?.message?.id}`
|
|
59
|
+
};
|
|
60
|
+
for (const type in rateLimitKeyMap) {
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
let key = `RateLimit["${rateLimitKeyMap[type]}"]`;
|
|
63
|
+
let val = await dbi.config.store.get(key);
|
|
64
|
+
if (val && Date.now() > val.at + val.duration) {
|
|
65
|
+
await dbi.config.store.delete(key);
|
|
66
|
+
val = null;
|
|
67
|
+
}
|
|
68
|
+
if (val) {
|
|
69
|
+
dbi.events.trigger("interactionRateLimit", {
|
|
70
|
+
dbi,
|
|
71
|
+
interaction: inter,
|
|
72
|
+
dbiInteraction: dbiInter,
|
|
73
|
+
locale,
|
|
74
|
+
data,
|
|
75
|
+
rateLimit: {
|
|
76
|
+
type: key,
|
|
77
|
+
...val
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async function setRateLimit(type, duration) {
|
|
84
|
+
// @ts-ignore
|
|
85
|
+
await dbi.config.store.set(`RateLimit["${rateLimitKeyMap[type]}"]`, { at: Date.now(), duration });
|
|
86
|
+
}
|
|
87
|
+
let arg = {
|
|
88
|
+
// @ts-ignore
|
|
89
|
+
dbi,
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
interaction: inter,
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
dbiInteraction: dbiInter,
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
locale,
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
setRateLimit,
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
data,
|
|
100
|
+
// @ts-ignore
|
|
101
|
+
other
|
|
102
|
+
};
|
|
103
|
+
if (dbi.config.strict) {
|
|
104
|
+
// @ts-ignore
|
|
105
|
+
await dbiInter.onExecute(arg);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
try {
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
await dbiInter.onExecute(arg);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
// @ts-ignore
|
|
114
|
+
await dbi.events.trigger("interactionError", Object.assign(arg, { error }));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// @ts-ignore
|
|
118
|
+
dbi.events.trigger("afterInteraction", { dbi, interaction: inter, dbiInteraction: dbiInter, locale, setRateLimit, data, other });
|
|
119
|
+
}
|
|
120
|
+
dbi.data.clients.forEach(d => {
|
|
121
|
+
d.client.on("interactionCreate", handle);
|
|
122
|
+
});
|
|
123
|
+
return () => {
|
|
124
|
+
dbi.data.clients.forEach(d => {
|
|
125
|
+
d.client.off("interactionCreate", handle);
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
exports.hookInteractionListeners = hookInteractionListeners;
|
|
130
130
|
//# sourceMappingURL=hookInteractionListeners.js.map
|