@mostfeatured/dbi 0.0.64 → 0.0.66
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 +180 -164
- package/dist/DBI.d.ts.map +1 -1
- package/dist/DBI.js +364 -332
- package/dist/DBI.js.map +1 -1
- package/dist/index.d.ts +16 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -21
- package/dist/index.js.map +1 -1
- package/dist/methods/hookEventListeners.d.ts.map +1 -1
- package/dist/methods/hookEventListeners.js +97 -87
- package/dist/methods/hookEventListeners.js.map +1 -1
- package/dist/methods/hookInteractionListeners.d.ts.map +1 -1
- package/dist/methods/hookInteractionListeners.js +129 -125
- package/dist/methods/hookInteractionListeners.js.map +1 -1
- package/dist/methods/publishInteractions.d.ts +8 -7
- package/dist/methods/publishInteractions.d.ts.map +1 -1
- package/dist/methods/publishInteractions.js +241 -236
- package/dist/methods/publishInteractions.js.map +1 -1
- package/dist/types/CustomEvent.js +19 -19
- package/dist/types/CustomEvent.js.map +1 -1
- package/dist/types/Event.d.ts +265 -263
- package/dist/types/Event.d.ts.map +1 -1
- package/dist/types/Event.js +24 -22
- package/dist/types/Event.js.map +1 -1
- package/dist/types/Interaction.d.ts +49 -47
- package/dist/types/Interaction.d.ts.map +1 -1
- package/dist/types/Interaction.js +26 -24
- package/dist/types/Interaction.js.map +1 -1
- package/dist/utils/recursiveImport.d.ts +5 -4
- package/dist/utils/recursiveImport.d.ts.map +1 -1
- package/dist/utils/recursiveImport.js +27 -26
- package/dist/utils/recursiveImport.js.map +1 -1
- package/generated/namespaceData.d.ts +2 -1
- package/package.json +2 -1
- package/readme.md +10 -10
- package/src/DBI.ts +79 -26
- package/src/index.ts +11 -2
- package/src/methods/hookEventListeners.ts +21 -7
- package/src/methods/hookInteractionListeners.ts +6 -2
- package/src/methods/publishInteractions.ts +30 -25
- package/src/types/CustomEvent.ts +1 -1
- package/src/types/Event.ts +4 -2
- package/src/types/Interaction.ts +5 -2
- package/src/utils/recursiveImport.ts +4 -3
package/dist/types/Event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Event.js","sourceRoot":"","sources":["../../src/types/Event.ts"],"names":[],"mappings":";;;AAqGA,MAAa,QAAQ;IACV,IAAI,CAAU;IACvB,KAAK,CAAuB;IAC5B,EAAE,CAAU;IACZ,IAAI,CAAS;IACb,SAAS,CAA0B;IACnC,OAAO,CAAW;IAClB,GAAG,CAAkB;IACrB,YAAY,GAAoB,EAAE,GAAiC;QACjE,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACpB,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAW,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"Event.js","sourceRoot":"","sources":["../../src/types/Event.ts"],"names":[],"mappings":";;;AAqGA,MAAa,QAAQ;IACV,IAAI,CAAU;IACvB,KAAK,CAAuB;IAC5B,WAAW,CAAsD;IACjE,EAAE,CAAU;IACZ,IAAI,CAAS;IACb,SAAS,CAA0B;IACnC,OAAO,CAAW;IAClB,GAAG,CAAkB;IACrB,YAAY,GAAoB,EAAE,GAAiC;QACjE,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACpB,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAW,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,KAAK,CAAC;QACpC,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC,WAAW,IAAI,gBAAgB,CAAC;IACzD,CAAC;CACF;AAnBD,4BAmBC","sourcesContent":["import Discord from \"discord.js\";\r\nimport { NamespaceEnums, NamespaceData } from \"../../generated/namespaceData\";\r\nimport { DBI, DBIClientData } from \"../DBI\";\r\nimport { DBILocale } from \"./Locale\";\r\n\r\nexport interface ClientEvents {\r\n applicationCommandPermissionsUpdate: { data: Discord.ApplicationCommandPermissionsUpdateData };\r\n cacheSweep: { message: string };\r\n channelCreate: { channel: Discord.NonThreadGuildBasedChannel };\r\n channelDelete: { channel: Discord.DMChannel | Discord.NonThreadGuildBasedChannel };\r\n channelPinsUpdate: { channel: Discord.TextBasedChannel, date: Date };\r\n channelUpdate: {\r\n oldChannel: Discord.DMChannel | Discord.NonThreadGuildBasedChannel,\r\n newChannel: Discord.DMChannel | Discord.NonThreadGuildBasedChannel,\r\n };\r\n debug: { message: string };\r\n warn: { message: string };\r\n emojiCreate: { emoji: Discord.GuildEmoji };\r\n emojiDelete: { emoji: Discord.GuildEmoji };\r\n emojiUpdate: { oldEmoji: Discord.GuildEmoji, newEmoji: Discord.GuildEmoji };\r\n error: { error: Error };\r\n guildBanAdd: { ban: Discord.GuildBan };\r\n guildBanRemove: { ban: Discord.GuildBan };\r\n guildCreate: { guild: Discord.Guild };\r\n guildDelete: { guild: Discord.Guild };\r\n guildUnavailable: { guild: Discord.Guild };\r\n guildIntegrationsUpdate: { guild: Discord.Guild };\r\n guildMemberAdd: { member: Discord.GuildMember };\r\n guildMemberAvailable: { member: Discord.GuildMember | Discord.PartialGuildMember };\r\n guildMemberRemove: { member: Discord.GuildMember | Discord.PartialGuildMember };\r\n guildMembersChunk: {\r\n members: Discord.Collection<Discord.Snowflake, Discord.GuildMember>,\r\n guild: Discord.Guild,\r\n data: { count: number; index: number; nonce: string | undefined },\r\n };\r\n guildMemberUpdate: { oldMember: Discord.GuildMember | Discord.PartialGuildMember, newMember: Discord.GuildMember };\r\n guildUpdate: { oldGuild: Discord.Guild, newGuild: Discord.Guild };\r\n inviteCreate: { invite: Discord.Invite };\r\n inviteDelete: { invite: Discord.Invite };\r\n messageCreate: { message: Discord.Message };\r\n messageDelete: { message: Discord.Message | Discord.PartialMessage };\r\n messageReactionRemoveAll: {\r\n message: Discord.Message | Discord.PartialMessage,\r\n reactions: Discord.Collection<string | Discord.Snowflake, Discord.MessageReaction>,\r\n };\r\n messageReactionRemoveEmoji: { reaction: Discord.MessageReaction | Discord.PartialMessageReaction };\r\n messageDeleteBulk: { messages: Discord.Collection<Discord.Snowflake, Discord.Message | Discord.PartialMessage>, channel: Discord.TextBasedChannel };\r\n messageReactionAdd: { reaction: Discord.MessageReaction | Discord.PartialMessageReaction, user: Discord.User | Discord.PartialUser };\r\n messageReactionRemove: { reaction: Discord.MessageReaction | Discord.PartialMessageReaction, user: Discord.User | Discord.PartialUser };\r\n messageUpdate: { oldMessage: Discord.Message | Discord.PartialMessage, newMessage: Discord.Message | Discord.PartialMessage };\r\n presenceUpdate: { oldPresence: Discord.Presence | null, newPresence: Discord.Presence };\r\n ready: { client: Discord.Client<true> };\r\n invalidated: {};\r\n roleCreate: { role: Discord.Role };\r\n roleDelete: { role: Discord.Role };\r\n roleUpdate: { oldRole: Discord.Role, newRole: Discord.Role };\r\n threadCreate: { thread: Discord.AnyThreadChannel, newlyCreated: boolean };\r\n threadDelete: { thread: Discord.AnyThreadChannel };\r\n threadListSync: { threads: Discord.Collection<Discord.Snowflake, Discord.AnyThreadChannel>, guild: Discord.Guild };\r\n threadMemberUpdate: { oldMember: Discord.ThreadMember, newMember: Discord.ThreadMember };\r\n threadMembersUpdate: {\r\n addedMembers: Discord.Collection<Discord.Snowflake, Discord.ThreadMember>,\r\n removedMembers: Discord.Collection<Discord.Snowflake, Discord.ThreadMember | Discord.PartialThreadMember>,\r\n thread: Discord.AnyThreadChannel,\r\n };\r\n threadUpdate: { oldThread: Discord.AnyThreadChannel, newThread: Discord.AnyThreadChannel };\r\n typingStart: { typing: Discord.Typing };\r\n userUpdate: { oldUser: Discord.User | Discord.PartialUser, newUser: Discord.User };\r\n voiceStateUpdate: { oldState: Discord.VoiceState, newState: Discord.VoiceState };\r\n webhookUpdate: { channel: Discord.TextChannel | Discord.NewsChannel | Discord.VoiceChannel };\r\n interactionCreate: { interaction: Discord.Interaction };\r\n shardDisconnect: { closeEvent: Discord.CloseEvent, shardId: number };\r\n shardError: { error: Error, shardId: number };\r\n shardReady: { shardId: number, unavailableGuilds: Set<Discord.Snowflake> | undefined };\r\n shardReconnecting: { shardId: number };\r\n shardResume: { shardId: number, replayedEvents: number };\r\n stageInstanceCreate: { stageInstance: Discord.StageInstance };\r\n stageInstanceUpdate: { oldStageInstance: Discord.StageInstance | null, newStageInstance: Discord.StageInstance };\r\n stageInstanceDelete: { stageInstance: Discord.StageInstance };\r\n stickerCreate: { sticker: Discord.Sticker };\r\n stickerDelete: { sticker: Discord.Sticker };\r\n stickerUpdate: { oldSticker: Discord.Sticker, newSticker: Discord.Sticker };\r\n guildScheduledEventCreate: { guildScheduledEvent: Discord.GuildScheduledEvent };\r\n guildScheduledEventUpdate: {\r\n oldGuildScheduledEvent: Discord.GuildScheduledEvent | null,\r\n newGuildScheduledEvent: Discord.GuildScheduledEvent,\r\n };\r\n guildScheduledEventDelete: { guildScheduledEvent: Discord.GuildScheduledEvent };\r\n guildScheduledEventUserAdd: { guildScheduledEvent: Discord.GuildScheduledEvent, user: Discord.User };\r\n guildScheduledEventUserRemove: { guildScheduledEvent: Discord.GuildScheduledEvent, user: Discord.User };\r\n}\r\n\r\nexport type DBIEventCombinations<TNamespace extends NamespaceEnums> = {\r\n [K in keyof (ClientEvents & NamespaceData[TNamespace][\"customEvents\"])]: {\r\n name: K,\r\n onExecute: (ctx: (ClientEvents & NamespaceData[TNamespace][\"customEvents\"])[K] & { other: Record<string, any>, locale?: { guild: DBILocale<TNamespace> }, eventName: string, nextClient: DBIClientData<TNamespace> }) => Promise<any> | any\r\n }\r\n}[keyof (ClientEvents) | keyof NamespaceData[TNamespace][\"customEvents\"]];\r\n\r\nexport type TDBIEventOmitted<TNamespace extends NamespaceEnums> = Omit<DBIEvent<TNamespace>, \"type\" | \"name\" | \"onExecute\" | \"client\" | \"dbi\"> & DBIEventCombinations<TNamespace>;\r\n\r\nexport class DBIEvent<TNamespace extends NamespaceEnums> {\r\n readonly type: \"Event\";\r\n other?: Record<string, any>;\r\n triggerType?: \"OneByOne\" | \"OneByOneGlobal\" | \"Random\" | \"First\";\r\n id?: string;\r\n name: string;\r\n onExecute: (...args: any[]) => any;\r\n ordered?: boolean;\r\n dbi: DBI<TNamespace>;\r\n constructor(dbi: DBI<TNamespace>, cfg: TDBIEventOmitted<TNamespace>) {\r\n this.dbi = dbi;\r\n this.type = \"Event\";\r\n this.id = cfg.id;\r\n this.other = cfg.other;\r\n this.name = cfg.name as any;\r\n this.onExecute = cfg.onExecute;\r\n this.ordered = cfg.ordered ?? false;\r\n this.triggerType = cfg.triggerType ?? \"OneByOneGlobal\";\r\n }\r\n}"]}
|
|
@@ -1,48 +1,50 @@
|
|
|
1
|
-
import Discord from "discord.js";
|
|
2
|
-
import { NamespaceEnums } 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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
$
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export declare type
|
|
30
|
-
export declare type
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
dbi: DBI<TNamespace
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
+
}
|
|
48
50
|
//# sourceMappingURL=Interaction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Interaction.d.ts","sourceRoot":"","sources":["../../src/types/Interaction.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"Interaction.d.ts","sourceRoot":"","sources":["../../src/types/Interaction.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,25 +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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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;
|
|
25
27
|
//# sourceMappingURL=Interaction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Interaction.js","sourceRoot":"","sources":["../../src/types/Interaction.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"Interaction.js","sourceRoot":"","sources":["../../src/types/Interaction.ts"],"names":[],"mappings":";;;AA4DA,MAAa,kBAAkB;IAC7B,YAAY,GAAoB,EAAE,GAAgD;QAChF,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC,WAAW,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,SAAS,CAAC;IACpE,CAAC;IAED,OAAO,CAAiD;IACxD,GAAG,CAAkB;IACrB,IAAI,CAAS;IACb,WAAW,CAAS;IACX,IAAI,CAAuB;IACpC,OAAO,CAAe;IACtB,KAAK,CAAuB;IAC5B,UAAU,CAAkB;IAC5B,SAAS,CAAC,GAAmC;IAE7C,CAAC;CACF;AAvBD,gDAuBC","sourcesContent":["import Discord from \"discord.js\";\r\nimport { NamespaceEnums, NamespaceData } from \"../../generated/namespaceData\";\r\nimport { DBI } from \"../DBI\";\r\nimport { DBIButton } from \"./Button\";\r\nimport { DBIChatInput } from \"./ChatInput/ChatInput\";\r\nimport { DBILocale } from \"./Locale\";\r\nimport { DBIMessageContextMenu } from \"./MessageContextMenu\";\r\nimport { DBIModal } from \"./Modal\";\r\nimport { DBISelectMenu } from \"./SelectMenu\";\r\nimport { DBIUserContextMenu } from \"./UserContextMenu\";\r\n\r\nexport type TDBIInteractions<TNamespace extends NamespaceEnums> = DBIChatInput<TNamespace> | DBIButton<TNamespace> | DBISelectMenu<TNamespace> | DBIMessageContextMenu<TNamespace> | DBIUserContextMenu<TNamespace> | DBIModal<TNamespace>;\r\n\r\nexport interface IDBIBaseExecuteCtx<TNamespace extends NamespaceEnums> {\r\n interaction:\r\n | Discord.ChatInputCommandInteraction\r\n | Discord.UserContextMenuCommandInteraction\r\n | Discord.MessageContextMenuCommandInteraction\r\n | Discord.ModalSubmitInteraction\r\n | Discord.AutocompleteInteraction\r\n | Discord.SelectMenuInteraction\r\n | Discord.ButtonInteraction;\r\n locale: {\r\n user: DBILocale<TNamespace>,\r\n guild?: DBILocale<TNamespace>\r\n }\r\n dbi: DBI<TNamespace>;\r\n dbiInteraction: TDBIInteractions<TNamespace>;\r\n setRateLimit(type: TDBIRateLimitTypes, duration: number): Promise<any>;\r\n other: Record<string, any>;\r\n clientNamespace: NamespaceData[TNamespace][\"clientNamespaces\"];\r\n}\r\n\r\nexport type TDBIReferencedData = ({ [key: string]: any, $ref: string, $unRef(): boolean } | string | number);\r\n\r\nexport type TDBIInteractionTypes =\r\n | \"ChatInput\"\r\n | \"UserContextMenu\"\r\n | \"MessageContextMenu\"\r\n | \"Modal\"\r\n | \"Autocomplete\"\r\n | \"SelectMenu\"\r\n | \"Button\";\r\n\r\nexport type TDBIRateLimitTypes =\r\n | \"User\"\r\n | \"Channel\"\r\n | \"Guild\"\r\n | \"Member\"\r\n | \"Message\";\r\n\r\n\r\nexport type DBIRateLimit = {\r\n type: TDBIRateLimitTypes;\r\n /**\r\n * Duration in milliseconds.\r\n */\r\n duration: number;\r\n}\r\n\r\nexport class DBIBaseInteraction<TNamespace extends NamespaceEnums> {\r\n constructor(dbi: DBI<TNamespace>, cfg: Omit<DBIBaseInteraction<TNamespace>, \"dbi\">) {\r\n this.dbi = dbi;\r\n this.name = cfg.name;\r\n this.description = cfg.description;\r\n this.onExecute = cfg.onExecute;\r\n this.type = cfg.type;\r\n this.options = cfg.options;\r\n this.other = cfg.other;\r\n this.publish = cfg.publish ?? dbi.data.clients.first()?.namespace;\r\n }\r\n \r\n publish?: NamespaceData[TNamespace][\"clientNamespaces\"];\r\n dbi: DBI<TNamespace>;\r\n name: string;\r\n description: string;\r\n readonly type: TDBIInteractionTypes;\r\n options?: any | any[];\r\n other?: Record<string, any>;\r\n rateLimits?: DBIRateLimit[];\r\n onExecute(ctx: IDBIBaseExecuteCtx<TNamespace>): Promise<void> | void {\r\n\r\n }\r\n}"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @example
|
|
3
|
+
* await recursiveImport("./src", [".js"], [".d.ts"])
|
|
4
|
+
*/
|
|
5
|
+
export declare function recursiveImport(folderPath: string, exts?: string[], ignore?: string[]): Promise<any>;
|
|
5
6
|
//# sourceMappingURL=recursiveImport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recursiveImport.d.ts","sourceRoot":"","sources":["../../src/utils/recursiveImport.ts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"recursiveImport.d.ts","sourceRoot":"","sources":["../../src/utils/recursiveImport.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,EAAY,EAAE,MAAM,GAAE,MAAM,EAAoC,GAAG,OAAO,CAAC,GAAG,CAAC,CAepJ"}
|
|
@@ -1,27 +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
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
let
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
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;
|
|
27
28
|
//# sourceMappingURL=recursiveImport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recursiveImport.js","sourceRoot":"","sources":["../../src/utils/recursiveImport.ts"],"names":[],"mappings":";;;;AAAA,oDAAoB;AACpB,wDAAwB;AAExB
|
|
1
|
+
{"version":3,"file":"recursiveImport.js","sourceRoot":"","sources":["../../src/utils/recursiveImport.ts"],"names":[],"mappings":";;;;AAAA,oDAAoB;AACpB,wDAAwB;AAExB;;;GAGG;AACI,KAAK,UAAU,eAAe,CAAC,UAAkB,EAAE,OAAiB,CAAC,KAAK,CAAC,EAAE,SAAmB,CAAC,OAAO,EAAC,SAAS,EAAC,WAAW,CAAC;IACpI,IAAI,KAAK,GAAG,MAAM,YAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3E,IAAI,OAAO,GAAG,SAAS,CAAC;IAExB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACxB,IAAI,QAAQ,GAAG,cAAI,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,QAAQ,GAAG,cAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAChD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,cAAI,CAAC,GAAG,GAAG,CAAC,EAAE;YACtC,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE;gBACtB,MAAM,eAAe,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;aACtC;iBAAM,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE;gBAC5F,gEAAa,QAAQ,GAAC,CAAA;aACvB;SACF;KACF;AACH,CAAC;AAfD,0CAeC","sourcesContent":["import fs from \"fs\";\r\nimport path from \"path\";\r\n\r\n/**\r\n * @example\r\n * await recursiveImport(\"./src\", [\".js\"], [\".d.ts\"])\r\n */\r\nexport async function recursiveImport(folderPath: string, exts: string[] = [\".js\"], ignore: string[] = [\".d.ts\",\".js.map\",\".d.ts.map\"]): Promise<any> {\r\n let files = await fs.promises.readdir(folderPath, { withFileTypes: true });\r\n let dirName = __dirname;\r\n \r\n for (const file of files) {\r\n let filePath = path.resolve(folderPath, file.name);\r\n let relative = path.relative(dirName, filePath);\r\n if (!relative.includes(`${path.sep}-`)) {\r\n if (file.isDirectory()) {\r\n await recursiveImport(filePath, exts)\r\n } else if (exts.some(i => file.name.endsWith(i)) && !ignore.some(i => file.name.endsWith(i))) {\r\n await import(filePath)\r\n }\r\n }\r\n }\r\n}"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
3
|
"@discordjs/rest": "^1.0.1",
|
|
4
|
+
"async-and-quick": "^1.0.2",
|
|
4
5
|
"discord-api-types": "^0.37.0",
|
|
5
6
|
"discord-hybrid-sharding": "^1.7.4",
|
|
6
7
|
"discord.js": "^14.7.0",
|
|
@@ -9,7 +10,7 @@
|
|
|
9
10
|
"stuffs": "^0.1.21"
|
|
10
11
|
},
|
|
11
12
|
"name": "@mostfeatured/dbi",
|
|
12
|
-
"version": "0.0.
|
|
13
|
+
"version": "0.0.66",
|
|
13
14
|
"main": "dist/index.js",
|
|
14
15
|
"type": "commonjs",
|
|
15
16
|
"private": false,
|
package/readme.md
CHANGED
|
@@ -44,10 +44,10 @@ We start the infrastructure with the `createDBI()` function. The first parameter
|
|
|
44
44
|
|
|
45
45
|
As the second step, we open our `login.js` file and write the code group that we will use to open the bot.
|
|
46
46
|
```js
|
|
47
|
-
const {
|
|
47
|
+
const { Utils } = require("@mostfeatured/dbi");
|
|
48
48
|
const dbi = require("./dbi");
|
|
49
49
|
(async () => {
|
|
50
|
-
await recursiveImport("./src");
|
|
50
|
+
await Utils.recursiveImport("./src");
|
|
51
51
|
await dbi.load();
|
|
52
52
|
await dbi.login();
|
|
53
53
|
await dbi.client.user.setActivity({
|
|
@@ -57,15 +57,15 @@ const dbi = require("./dbi");
|
|
|
57
57
|
})();
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
We import the `recursiveImport()` function into it. With this function we can `import`/`require` all files in `x` folder endlessly. In this way, the infrastructure is aware of these files.
|
|
60
|
+
We import the `Utils.recursiveImport()` function into it. With this function we can `import`/`require` all files in `x` folder endlessly. In this way, the infrastructure is aware of these files.
|
|
61
61
|
We access our infrastructure from our main `dbi.js` file and create an `async` environment and first define all project files to the infrastructure. After the definition, we load all the features we have defined to the infrastructure with the `load()` function. Right after, we log in to Discord with the `login()` function.
|
|
62
62
|
|
|
63
63
|
As the 3rd step, we open our `publish.js` file and repeat all the operations we did in the second step.
|
|
64
64
|
```js
|
|
65
|
-
const {
|
|
65
|
+
const { Utils } = require("@mostfeatured/dbi");
|
|
66
66
|
const dbi = require("./dbi");
|
|
67
67
|
(async () => {
|
|
68
|
-
await recursiveImport("./src");
|
|
68
|
+
await Utils.recursiveImport("./src");
|
|
69
69
|
await dbi.load();
|
|
70
70
|
await dbi.publish("Guild", "<yourGuildId>");
|
|
71
71
|
// await dbi.publish("Global");
|
|
@@ -317,11 +317,11 @@ module.exports = dbi;
|
|
|
317
317
|
|
|
318
318
|
2. adım olarak `login.js` dosyamızı açıyoruz ve içerisine botu açmak için kullanacağımız kod gurubunu yazıyoruz.
|
|
319
319
|
```js
|
|
320
|
-
const {
|
|
320
|
+
const { Utils } = require("@mostfeatured/dbi");
|
|
321
321
|
const dbi = require("./dbi");
|
|
322
322
|
|
|
323
323
|
(async () => {
|
|
324
|
-
await recursiveImport("./src");
|
|
324
|
+
await Utils.recursiveImport("./src");
|
|
325
325
|
|
|
326
326
|
await dbi.load();
|
|
327
327
|
await dbi.login();
|
|
@@ -334,17 +334,17 @@ const dbi = require("./dbi");
|
|
|
334
334
|
})();
|
|
335
335
|
```
|
|
336
336
|
|
|
337
|
-
İçeriye `recursiveImport()` fonksiyonunu alıyoruz. Bu fonksiyon ile sonsuz bir şekilde `x` klasöründeki bütün dosyaları `import`/`require` edebiliyoruz. Bu sayede altyapı bu dosyalardan haberdar oluyor.
|
|
337
|
+
İçeriye `Utils.recursiveImport()` fonksiyonunu alıyoruz. Bu fonksiyon ile sonsuz bir şekilde `x` klasöründeki bütün dosyaları `import`/`require` edebiliyoruz. Bu sayede altyapı bu dosyalardan haberdar oluyor.
|
|
338
338
|
Ana `dbi.js` dosyamızdan altyapımıza ulaşıyoruz ve `async` bir ortam oluşturup ilk önce tüm proje dosylarını altyapıya tanımlıyoruz. Tanımlamanın ardından tanımladığımız tüm özellikleri altyapıya `load()` fonksiyonunu ile yüklüyoruz. Hemen ardından `login()` fonksiyonu ile Discord'a giriş sağlıyoruz.
|
|
339
339
|
|
|
340
340
|
|
|
341
341
|
3. adım olarak `publish.js` dosyamızı açıyoruz ve ikinci aşamada yaptığımız tüm işlemleri tekrardan uyguluyoruz.
|
|
342
342
|
```js
|
|
343
|
-
const {
|
|
343
|
+
const { Utils } = require("@mostfeatured/dbi");
|
|
344
344
|
const dbi = require("./dbi");
|
|
345
345
|
|
|
346
346
|
(async () => {
|
|
347
|
-
await recursiveImport("./src");
|
|
347
|
+
await Utils.recursiveImport("./src");
|
|
348
348
|
|
|
349
349
|
await dbi.load();
|
|
350
350
|
await dbi.publish("Guild", "<yourGuildId>");
|
package/src/DBI.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { DBIInteractionLocale, TDBIInteractionLocaleOmitted } from "./types/Inte
|
|
|
20
20
|
import { TDBIInteractions } from "./types/Interaction";
|
|
21
21
|
import { NamespaceData, NamespaceEnums } from "../generated/namespaceData";
|
|
22
22
|
import { DBICustomEvent, TDBICustomEventOmitted } from "./types/CustomEvent";
|
|
23
|
+
import aaq from "async-and-quick";
|
|
23
24
|
|
|
24
25
|
export interface DBIStore {
|
|
25
26
|
get(key: string, defaultValue?: any): Promise<any>;
|
|
@@ -28,11 +29,14 @@ export interface DBIStore {
|
|
|
28
29
|
has(key: string): Promise<boolean>;
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
export type DBIClientData<TNamespace extends NamespaceEnums> = { namespace: NamespaceData[TNamespace]["clientNamespaces"], token: string, options: Discord.Options, client: Discord.Client<true> };
|
|
33
|
+
|
|
31
34
|
export interface DBIConfig {
|
|
32
35
|
discord: {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
namespace: string,
|
|
37
|
+
token: string,
|
|
38
|
+
options: Discord.ClientOptions,
|
|
39
|
+
}[];
|
|
36
40
|
defaults: {
|
|
37
41
|
locale: TDBILocaleString,
|
|
38
42
|
directMessages: boolean,
|
|
@@ -59,7 +63,12 @@ export interface DBIConfigConstructor {
|
|
|
59
63
|
discord: {
|
|
60
64
|
token: string;
|
|
61
65
|
options: Discord.ClientOptions
|
|
62
|
-
}
|
|
66
|
+
} | {
|
|
67
|
+
namespace: string,
|
|
68
|
+
token: string,
|
|
69
|
+
options: Discord.ClientOptions,
|
|
70
|
+
}[];
|
|
71
|
+
|
|
63
72
|
defaults?: {
|
|
64
73
|
locale?: TDBILocaleString,
|
|
65
74
|
directMessages?: boolean,
|
|
@@ -105,7 +114,6 @@ export interface DBIRegisterAPI<TNamespace extends NamespaceEnums> {
|
|
|
105
114
|
export class DBI<TNamespace extends NamespaceEnums, TOtherData = Record<string, any>> {
|
|
106
115
|
namespace: TNamespace;
|
|
107
116
|
config: DBIConfig;
|
|
108
|
-
client: Discord.Client<true>;
|
|
109
117
|
data: {
|
|
110
118
|
interactions: Discord.Collection<string, TDBIInteractions<TNamespace>>;
|
|
111
119
|
events: Discord.Collection<string, DBIEvent<TNamespace>>;
|
|
@@ -118,6 +126,15 @@ export class DBI<TNamespace extends NamespaceEnums, TOtherData = Record<string,
|
|
|
118
126
|
registers: Set<(...args: any[]) => any>;
|
|
119
127
|
registerUnloaders: Set<(...args: any[]) => any>;
|
|
120
128
|
refs: Map<string, { at: number, value: any, ttl?: number }>;
|
|
129
|
+
clients:
|
|
130
|
+
& DBIClientData<TNamespace>[]
|
|
131
|
+
& {
|
|
132
|
+
next(key?: string): DBIClientData<TNamespace>,
|
|
133
|
+
random(): DBIClientData<TNamespace>,
|
|
134
|
+
first(): DBIClientData<TNamespace>,
|
|
135
|
+
get(namespace: NamespaceData[TNamespace]["clientNamespaces"]): DBIClientData<TNamespace>,
|
|
136
|
+
indexes: Record<string, number>
|
|
137
|
+
}
|
|
121
138
|
};
|
|
122
139
|
events: Events<TNamespace>;
|
|
123
140
|
cluster?: Sharding.Client;
|
|
@@ -125,6 +142,7 @@ export class DBI<TNamespace extends NamespaceEnums, TOtherData = Record<string,
|
|
|
125
142
|
private _hooked: boolean;
|
|
126
143
|
constructor(namespace: TNamespace, config: DBIConfigConstructor) {
|
|
127
144
|
this.namespace = namespace as any;
|
|
145
|
+
const self = this;
|
|
128
146
|
|
|
129
147
|
config.store = config.store as any || new MemoryStore();
|
|
130
148
|
config.defaults = {
|
|
@@ -154,18 +172,50 @@ export class DBI<TNamespace extends NamespaceEnums, TOtherData = Record<string,
|
|
|
154
172
|
unloaders: new Set(),
|
|
155
173
|
registers: new Set(),
|
|
156
174
|
registerUnloaders: new Set(),
|
|
157
|
-
refs: config.data?.refs ?? new Map()
|
|
175
|
+
refs: config.data?.refs ?? new Map(),
|
|
176
|
+
clients: Object.assign([], {
|
|
177
|
+
next(key = "global") {
|
|
178
|
+
this.indexes[key] = (((this.indexes[key] ?? -1) + 1) % this.length);
|
|
179
|
+
return this[this.indexes[key]];
|
|
180
|
+
},
|
|
181
|
+
random() {
|
|
182
|
+
return this[Math.floor(Math.random() * this.length)];
|
|
183
|
+
},
|
|
184
|
+
first() {
|
|
185
|
+
return this[0];
|
|
186
|
+
},
|
|
187
|
+
get(namespace: string) {
|
|
188
|
+
return this.find((i: any) => i.namespace === namespace);
|
|
189
|
+
},
|
|
190
|
+
indexes: {}
|
|
191
|
+
}) as any
|
|
158
192
|
}
|
|
159
193
|
|
|
160
194
|
this.events = new Events(this as any);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
195
|
+
|
|
196
|
+
config.discord = Array.isArray(config.discord) ?
|
|
197
|
+
config.discord :
|
|
198
|
+
[{ token: config.discord.token, options: config.discord.options, namespace: "default" }];
|
|
199
|
+
|
|
200
|
+
this.data.clients.push(...(
|
|
201
|
+
config.discord as any
|
|
202
|
+
));
|
|
203
|
+
for (let clientContext of this.data.clients) {
|
|
204
|
+
let client = new Discord.Client({
|
|
205
|
+
...(clientContext.options || {}) as any,
|
|
206
|
+
...(config.sharding == "hybrid" ? {
|
|
207
|
+
shards: (Sharding as any).data.SHARD_LIST,
|
|
208
|
+
shardCount: (Sharding as any).data.TOTAL_SHARDS
|
|
209
|
+
} : {})
|
|
210
|
+
});
|
|
211
|
+
clientContext.client = client;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (this.data.clients.length === 0) throw new Error("No clients provided.");
|
|
215
|
+
if (this.data.clients.length !== 1 && !(config.sharding && config.sharding === "off"))
|
|
216
|
+
throw new Error("Sharding only supports 1 client.");
|
|
217
|
+
|
|
218
|
+
this.cluster = config.sharding == "hybrid" ? new Sharding.Client(this.data.clients[0].client) : undefined;
|
|
169
219
|
this._loaded = false;
|
|
170
220
|
this._hooked = false;
|
|
171
221
|
}
|
|
@@ -290,7 +340,7 @@ export class DBI<TNamespace extends NamespaceEnums, TOtherData = Record<string,
|
|
|
290
340
|
};
|
|
291
341
|
CustomEvent = Object.assign(CustomEvent, class { constructor(...args: any[]) { return CustomEvent.apply(this, args as any); } });
|
|
292
342
|
|
|
293
|
-
let InteractionLocale = function(cfg: TDBIInteractionLocaleOmitted) {
|
|
343
|
+
let InteractionLocale = function (cfg: TDBIInteractionLocaleOmitted) {
|
|
294
344
|
let dbiInteractionLocale = new DBIInteractionLocale(self, cfg);
|
|
295
345
|
if (self.config.strict && self.data.interactionLocales.has(dbiInteractionLocale.name)) throw new Error(`DBIInteractionLocale "${dbiInteractionLocale.name}" already loaded!`);
|
|
296
346
|
self.data.interactionLocales.set(dbiInteractionLocale.name, dbiInteractionLocale);
|
|
@@ -324,16 +374,17 @@ export class DBI<TNamespace extends NamespaceEnums, TOtherData = Record<string,
|
|
|
324
374
|
return this.data.interactions.get(name as any) as any;
|
|
325
375
|
}
|
|
326
376
|
|
|
327
|
-
emit<TEventName extends keyof (NamespaceData[TNamespace]["customEvents"] & ClientEvents)>(name: TEventName, args: (NamespaceData[TNamespace]["customEvents"] & ClientEvents)[TEventName]
|
|
328
|
-
this.client.emit(name as any, { ...args, _DIRECT_: true } as any);
|
|
377
|
+
emit<TEventName extends keyof (NamespaceData[TNamespace]["customEvents"] & ClientEvents)>(name: TEventName, args: (NamespaceData[TNamespace]["customEvents"] & ClientEvents)[TEventName]): void {
|
|
378
|
+
this.data.clients.forEach((d) => d.client.emit(name as any, { ...args, _DIRECT_: true } as any));
|
|
329
379
|
}
|
|
330
380
|
|
|
331
|
-
/**
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
381
|
+
/**
|
|
382
|
+
* @deprecated
|
|
383
|
+
*/
|
|
384
|
+
get client() {
|
|
385
|
+
console.log("[DEPRECTED] dbi.client is a deprected api. Please use dbi.data.clients.first().client instead.", Error().stack);
|
|
386
|
+
return this.data.clients[0]?.client;
|
|
387
|
+
}
|
|
337
388
|
/**
|
|
338
389
|
* this.data.events.get(name)
|
|
339
390
|
*/
|
|
@@ -381,7 +432,9 @@ export class DBI<TNamespace extends NamespaceEnums, TOtherData = Record<string,
|
|
|
381
432
|
}
|
|
382
433
|
|
|
383
434
|
async login(): Promise<any> {
|
|
384
|
-
await
|
|
435
|
+
await aaq.quickForEach(this.data.clients, async (clientContext) => {
|
|
436
|
+
await clientContext.client.login(this.config.sharding == "default" ? null : clientContext.token);
|
|
437
|
+
});
|
|
385
438
|
}
|
|
386
439
|
|
|
387
440
|
async register(cb: (api: DBIRegisterAPI<TNamespace>) => void): Promise<any> {
|
|
@@ -416,7 +469,7 @@ export class DBI<TNamespace extends NamespaceEnums, TOtherData = Record<string,
|
|
|
416
469
|
switch (args[0]) {
|
|
417
470
|
case "Global": {
|
|
418
471
|
return await publishInteractions(
|
|
419
|
-
this.
|
|
472
|
+
this.data.clients,
|
|
420
473
|
args[1] ? new Discord.Collection() : interactions,
|
|
421
474
|
this.data.interactionLocales,
|
|
422
475
|
args[0]
|
|
@@ -424,7 +477,7 @@ export class DBI<TNamespace extends NamespaceEnums, TOtherData = Record<string,
|
|
|
424
477
|
}
|
|
425
478
|
case "Guild": {
|
|
426
479
|
return await publishInteractions(
|
|
427
|
-
this.
|
|
480
|
+
this.data.clients,
|
|
428
481
|
args[2] ? new Discord.Collection() : interactions,
|
|
429
482
|
this.data.interactionLocales,
|
|
430
483
|
args[0],
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NamespaceEnums } from "../generated/namespaceData";
|
|
2
2
|
import { DBI, DBIConfigConstructor } from "./DBI";
|
|
3
|
-
|
|
3
|
+
import { recursiveImport as _recursiveImport } from "./utils/recursiveImport";
|
|
4
4
|
export { MemoryStore } from "./utils/MemoryStore";
|
|
5
5
|
|
|
6
6
|
import path from "path";
|
|
@@ -14,5 +14,14 @@ export function createDBI<TNamespace extends NamespaceEnums, TOtherType = Record
|
|
|
14
14
|
|
|
15
15
|
export const Utils = {
|
|
16
16
|
parseCustomId,
|
|
17
|
-
buildCustomId
|
|
17
|
+
buildCustomId,
|
|
18
|
+
recursiveImport: _recursiveImport
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated
|
|
23
|
+
*/
|
|
24
|
+
export async function recursiveImport(...args: any[]) {
|
|
25
|
+
console.log("[DEPRECTED] recursiveImport is a deprected api. Please use Utils.recursiveImport instead.", Error().stack);
|
|
26
|
+
return await _recursiveImport.call(this, ...args);
|
|
18
27
|
}
|