@mostfeatured/dbi 0.1.29 โ 0.1.31
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/.gitattributes +2 -2
- package/.hintrc +7 -7
- package/.vscode/settings.json +2 -2
- package/LICENSE +674 -674
- package/dist/DBI.js.map +1 -1
- package/dist/Events.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/methods/handleMessageCommands.js +1 -1
- package/dist/methods/handleMessageCommands.js.map +1 -1
- package/dist/methods/hookEventListeners.js.map +1 -1
- package/dist/methods/hookInteractionListeners.js.map +1 -1
- package/dist/methods/publishInteractions.js.map +1 -1
- package/dist/types/ApplicationRoleConnectionMetadata.js.map +1 -1
- package/dist/types/Builders/ButtonBuilder.js.map +1 -1
- package/dist/types/Builders/ChannelSelectMenuBuilder.js.map +1 -1
- package/dist/types/Builders/MentionableSelectMenuBuilder.js.map +1 -1
- package/dist/types/Builders/ModalBuilder.js.map +1 -1
- package/dist/types/Builders/RoleSelectMenuBuilder.js.map +1 -1
- package/dist/types/Builders/StringSelectMenuBuilder.js.map +1 -1
- package/dist/types/Builders/UserSelectMenuBuilder.js.map +1 -1
- package/dist/types/ChatInput/ChatInput.js.map +1 -1
- package/dist/types/ChatInput/ChatInputOptions.d.ts +16 -16
- package/dist/types/ChatInput/ChatInputOptions.d.ts.map +1 -1
- package/dist/types/ChatInput/ChatInputOptions.js.map +1 -1
- package/dist/types/Components/Button.js.map +1 -1
- package/dist/types/Components/ChannelSelectMenu.js.map +1 -1
- package/dist/types/Components/MentionableSelectMenu.js.map +1 -1
- package/dist/types/Components/Modal.js.map +1 -1
- package/dist/types/Components/RoleSelectMenu.js.map +1 -1
- package/dist/types/Components/StringSelectMenu.js.map +1 -1
- package/dist/types/Components/UserSelectMenu.js.map +1 -1
- package/dist/types/Event.js.map +1 -1
- package/dist/types/Interaction.d.ts +1 -0
- package/dist/types/Interaction.d.ts.map +1 -1
- package/dist/types/Interaction.js.map +1 -1
- package/dist/types/other/CustomEvent.js.map +1 -1
- package/dist/types/other/FakeMessageInteraction.js.map +1 -1
- package/dist/types/other/InteractionLocale.js.map +1 -1
- package/dist/types/other/Locale.js.map +1 -1
- package/dist/types/other/MessageContextMenu.js.map +1 -1
- package/dist/types/other/UserContextMenu.js.map +1 -1
- package/dist/utils/MemoryStore.js.map +1 -1
- package/dist/utils/UtilTypes.js.map +1 -1
- package/dist/utils/customId.js.map +1 -1
- package/dist/utils/permissions.js.map +1 -1
- package/dist/utils/recursiveImport.js.map +1 -1
- package/dist/utils/recursiveUnload.js.map +1 -1
- package/dist/utils/unloadModule.js.map +1 -1
- package/examples/modal/dbi.js +29 -29
- package/examples/modal/login.js +14 -14
- package/examples/modal/package.json +15 -15
- package/examples/modal/publish.js +12 -12
- package/examples/modal/src/chatInput.js +37 -37
- package/examples/modal/src/components.js +32 -32
- package/examples/modal/src/event.js +19 -19
- package/examples/modal/src/interactionlocales.js +23 -23
- package/examples/modal/src/locales.js +37 -37
- package/examples/modal/src/modal.js +27 -27
- package/generated/namespaceData.d.ts +14 -14
- package/package.json +45 -45
- package/readme.md +591 -591
- package/src/DBI.ts +1090 -1090
- package/src/Events.ts +189 -189
- package/src/data/eventMap.json +247 -247
- package/src/index.ts +23 -23
- package/src/methods/handleMessageCommands.ts +482 -482
- package/src/methods/hookEventListeners.ts +118 -118
- package/src/methods/hookInteractionListeners.ts +260 -260
- package/src/methods/publishInteractions.ts +255 -255
- package/src/types/ApplicationRoleConnectionMetadata.ts +19 -19
- package/src/types/Builders/ButtonBuilder.ts +52 -52
- package/src/types/Builders/ChannelSelectMenuBuilder.ts +52 -52
- package/src/types/Builders/MentionableSelectMenuBuilder.ts +52 -52
- package/src/types/Builders/ModalBuilder.ts +52 -52
- package/src/types/Builders/RoleSelectMenuBuilder.ts +52 -52
- package/src/types/Builders/StringSelectMenuBuilder.ts +52 -52
- package/src/types/Builders/UserSelectMenuBuilder.ts +52 -52
- package/src/types/ChatInput/ChatInput.ts +27 -27
- package/src/types/ChatInput/ChatInputOptions.ts +388 -388
- package/src/types/Components/Button.ts +38 -38
- package/src/types/Components/ChannelSelectMenu.ts +42 -42
- package/src/types/Components/MentionableSelectMenu.ts +42 -42
- package/src/types/Components/Modal.ts +45 -45
- package/src/types/Components/RoleSelectMenu.ts +42 -42
- package/src/types/Components/StringSelectMenu.ts +42 -42
- package/src/types/Components/UserSelectMenu.ts +42 -42
- package/src/types/Event.ts +144 -144
- package/src/types/Interaction.ts +96 -96
- package/src/types/other/CustomEvent.ts +18 -18
- package/src/types/other/FakeMessageInteraction.ts +407 -407
- package/src/types/other/InteractionLocale.ts +33 -33
- package/src/types/other/Locale.ts +69 -69
- package/src/types/other/MessageContextMenu.ts +26 -26
- package/src/types/other/UserContextMenu.ts +24 -24
- package/src/utils/MemoryStore.ts +27 -27
- package/src/utils/UtilTypes.ts +10 -10
- package/src/utils/customId.ts +44 -44
- package/src/utils/permissions.ts +4 -4
- package/src/utils/recursiveImport.ts +22 -22
- package/src/utils/recursiveUnload.ts +24 -24
- package/src/utils/unloadModule.ts +6 -6
- package/tsconfig.json +40 -40
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { NamespaceEnums } from "../../../generated/namespaceData";
|
|
2
|
-
import { DBI } from "../../DBI";
|
|
3
|
-
import { TDBILocaleString } from "./Locale";
|
|
4
|
-
|
|
5
|
-
export type TDBIInteractionLocaleData = {
|
|
6
|
-
[K in TDBILocaleString]?: {
|
|
7
|
-
name: string;
|
|
8
|
-
description: string;
|
|
9
|
-
options?: {
|
|
10
|
-
[k: string]: {
|
|
11
|
-
name: string;
|
|
12
|
-
description: string;
|
|
13
|
-
choices?: {
|
|
14
|
-
[k: string]: string
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type TDBIInteractionLocaleOmitted = Omit<DBIInteractionLocale, "dbi">;
|
|
22
|
-
|
|
23
|
-
export class DBIInteractionLocale {
|
|
24
|
-
name: string;
|
|
25
|
-
data: TDBIInteractionLocaleData;
|
|
26
|
-
dbi: DBI<NamespaceEnums>;
|
|
27
|
-
flag?: string;
|
|
28
|
-
constructor(dbi, cfg: TDBIInteractionLocaleOmitted) {
|
|
29
|
-
this.dbi = dbi;
|
|
30
|
-
this.name = cfg.name;
|
|
31
|
-
this.data = cfg.data;
|
|
32
|
-
this.flag = cfg.flag;
|
|
33
|
-
}
|
|
1
|
+
import { NamespaceEnums } from "../../../generated/namespaceData";
|
|
2
|
+
import { DBI } from "../../DBI";
|
|
3
|
+
import { TDBILocaleString } from "./Locale";
|
|
4
|
+
|
|
5
|
+
export type TDBIInteractionLocaleData = {
|
|
6
|
+
[K in TDBILocaleString]?: {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
options?: {
|
|
10
|
+
[k: string]: {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
choices?: {
|
|
14
|
+
[k: string]: string
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type TDBIInteractionLocaleOmitted = Omit<DBIInteractionLocale, "dbi">;
|
|
22
|
+
|
|
23
|
+
export class DBIInteractionLocale {
|
|
24
|
+
name: string;
|
|
25
|
+
data: TDBIInteractionLocaleData;
|
|
26
|
+
dbi: DBI<NamespaceEnums>;
|
|
27
|
+
flag?: string;
|
|
28
|
+
constructor(dbi, cfg: TDBIInteractionLocaleOmitted) {
|
|
29
|
+
this.dbi = dbi;
|
|
30
|
+
this.name = cfg.name;
|
|
31
|
+
this.data = cfg.data;
|
|
32
|
+
this.flag = cfg.flag;
|
|
33
|
+
}
|
|
34
34
|
}
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import stuffs from "stuffs";
|
|
2
|
-
import { NamespaceData, NamespaceEnums } from "../../../generated/namespaceData";
|
|
3
|
-
import { DBI } from "../../DBI";
|
|
4
|
-
import _ from "lodash";
|
|
5
|
-
import util from "util";
|
|
6
|
-
|
|
7
|
-
export interface DBILangObject {
|
|
8
|
-
[property: string]: DBILangObject & ((...args: any[]) => string);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface DBILangConstructorObject {
|
|
12
|
-
[property: string]: DBILangConstructorObject | string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type TDBILocaleString = "en" | "bg" | "zh" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "no" | "pl" | "pt" | "ro" | "ru" | "es" | "sv" | "th" | "tr" | "uk" | "vi";
|
|
16
|
-
|
|
17
|
-
export type TDBILocaleConstructor<TNamespace extends NamespaceEnums> = Omit<DBILocale<TNamespace>, "data" | "dbi" | "mergeLocale" | "_data" | "get" | "format"> & { data: DBILangConstructorObject };
|
|
18
|
-
|
|
19
|
-
export class DBILocale<TNamespace extends NamespaceEnums> {
|
|
20
|
-
name: TDBILocaleString;
|
|
21
|
-
data: NamespaceData[TNamespace]["contentLocale"];
|
|
22
|
-
_data: DBILangConstructorObject;
|
|
23
|
-
dbi: DBI<TNamespace, {}>;
|
|
24
|
-
flag?: string
|
|
25
|
-
constructor(dbi: DBI<TNamespace, {}>, cfg: TDBILocaleConstructor<TNamespace>) {
|
|
26
|
-
this.dbi = dbi;
|
|
27
|
-
this.name = cfg.name;
|
|
28
|
-
this.flag = cfg.flag;
|
|
29
|
-
this._data = cfg.data;
|
|
30
|
-
this.data = createInfinitePathProxy((path, ...args) => {
|
|
31
|
-
return this.format(path.join("."), ...args);
|
|
32
|
-
});;
|
|
33
|
-
}
|
|
34
|
-
mergeLocale(locale: DBILocale<TNamespace>): DBILocale<TNamespace> {
|
|
35
|
-
this._data = stuffs.defaultify(locale._data, this._data, true) as any;
|
|
36
|
-
locale._data = this._data;
|
|
37
|
-
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
get(path: string): string | null {
|
|
41
|
-
return _.get(this._data as any, path) as string || null;
|
|
42
|
-
}
|
|
43
|
-
format(path: string, ...args: any[]): string {
|
|
44
|
-
let value = this.get(path);
|
|
45
|
-
if (!value) {
|
|
46
|
-
const defaultLocale = this.dbi.locale(this.dbi.config.defaults.locale.name as any);
|
|
47
|
-
if (!defaultLocale || defaultLocale.name === this.name) return this.dbi.config.defaults.locale.invalidPath({
|
|
48
|
-
locale: this,
|
|
49
|
-
path,
|
|
50
|
-
});
|
|
51
|
-
value = defaultLocale.get(path);
|
|
52
|
-
}
|
|
53
|
-
if (!value) return this.dbi.config.defaults.locale.invalidPath({
|
|
54
|
-
locale: this,
|
|
55
|
-
path,
|
|
56
|
-
});
|
|
57
|
-
return stuffs.mapReplace(value, args.map((t, i) => [new RegExp(`\\{${i}(;[^}]+)?\\}`, "g"), t]));
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function createInfinitePathProxy(onApplyPath: (path: string[], ...args: any[]) => string, path: string[] = []): any {
|
|
62
|
-
return new Proxy(() => { }, {
|
|
63
|
-
get(target, key) {
|
|
64
|
-
return createInfinitePathProxy(onApplyPath, [...path, key.toString()]);
|
|
65
|
-
},
|
|
66
|
-
apply(target, thisArg, args) {
|
|
67
|
-
return onApplyPath(path, ...args);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
1
|
+
import stuffs from "stuffs";
|
|
2
|
+
import { NamespaceData, NamespaceEnums } from "../../../generated/namespaceData";
|
|
3
|
+
import { DBI } from "../../DBI";
|
|
4
|
+
import _ from "lodash";
|
|
5
|
+
import util from "util";
|
|
6
|
+
|
|
7
|
+
export interface DBILangObject {
|
|
8
|
+
[property: string]: DBILangObject & ((...args: any[]) => string);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface DBILangConstructorObject {
|
|
12
|
+
[property: string]: DBILangConstructorObject | string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type TDBILocaleString = "en" | "bg" | "zh" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "no" | "pl" | "pt" | "ro" | "ru" | "es" | "sv" | "th" | "tr" | "uk" | "vi";
|
|
16
|
+
|
|
17
|
+
export type TDBILocaleConstructor<TNamespace extends NamespaceEnums> = Omit<DBILocale<TNamespace>, "data" | "dbi" | "mergeLocale" | "_data" | "get" | "format"> & { data: DBILangConstructorObject };
|
|
18
|
+
|
|
19
|
+
export class DBILocale<TNamespace extends NamespaceEnums> {
|
|
20
|
+
name: TDBILocaleString;
|
|
21
|
+
data: NamespaceData[TNamespace]["contentLocale"];
|
|
22
|
+
_data: DBILangConstructorObject;
|
|
23
|
+
dbi: DBI<TNamespace, {}>;
|
|
24
|
+
flag?: string
|
|
25
|
+
constructor(dbi: DBI<TNamespace, {}>, cfg: TDBILocaleConstructor<TNamespace>) {
|
|
26
|
+
this.dbi = dbi;
|
|
27
|
+
this.name = cfg.name;
|
|
28
|
+
this.flag = cfg.flag;
|
|
29
|
+
this._data = cfg.data;
|
|
30
|
+
this.data = createInfinitePathProxy((path, ...args) => {
|
|
31
|
+
return this.format(path.join("."), ...args);
|
|
32
|
+
});;
|
|
33
|
+
}
|
|
34
|
+
mergeLocale(locale: DBILocale<TNamespace>): DBILocale<TNamespace> {
|
|
35
|
+
this._data = stuffs.defaultify(locale._data, this._data, true) as any;
|
|
36
|
+
locale._data = this._data;
|
|
37
|
+
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
get(path: string): string | null {
|
|
41
|
+
return _.get(this._data as any, path) as string || null;
|
|
42
|
+
}
|
|
43
|
+
format(path: string, ...args: any[]): string {
|
|
44
|
+
let value = this.get(path);
|
|
45
|
+
if (!value) {
|
|
46
|
+
const defaultLocale = this.dbi.locale(this.dbi.config.defaults.locale.name as any);
|
|
47
|
+
if (!defaultLocale || defaultLocale.name === this.name) return this.dbi.config.defaults.locale.invalidPath({
|
|
48
|
+
locale: this,
|
|
49
|
+
path,
|
|
50
|
+
});
|
|
51
|
+
value = defaultLocale.get(path);
|
|
52
|
+
}
|
|
53
|
+
if (!value) return this.dbi.config.defaults.locale.invalidPath({
|
|
54
|
+
locale: this,
|
|
55
|
+
path,
|
|
56
|
+
});
|
|
57
|
+
return stuffs.mapReplace(value, args.map((t, i) => [new RegExp(`\\{${i}(;[^}]+)?\\}`, "g"), t]));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function createInfinitePathProxy(onApplyPath: (path: string[], ...args: any[]) => string, path: string[] = []): any {
|
|
62
|
+
return new Proxy(() => { }, {
|
|
63
|
+
get(target, key) {
|
|
64
|
+
return createInfinitePathProxy(onApplyPath, [...path, key.toString()]);
|
|
65
|
+
},
|
|
66
|
+
apply(target, thisArg, args) {
|
|
67
|
+
return onApplyPath(path, ...args);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
70
|
}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { DBI } from "../../DBI";
|
|
2
|
-
import { DBIBaseInteraction, IDBIBaseExecuteCtx } from "../Interaction";
|
|
3
|
-
import Discord from "discord.js";
|
|
4
|
-
import { NamespaceEnums } from "../../../generated/namespaceData";
|
|
5
|
-
|
|
6
|
-
export type TDBIMessageContextMenuOmitted<TNamespace extends NamespaceEnums> = Omit<DBIMessageContextMenu<TNamespace>, "type" | "description" | "dbi" | "options" | "toJSON">;
|
|
7
|
-
|
|
8
|
-
export interface IDBIMessageContextMenuExecuteCtx<TNamespace extends NamespaceEnums> extends IDBIBaseExecuteCtx<TNamespace> {
|
|
9
|
-
interaction: Discord.MessageContextMenuCommandInteraction<"cached">;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export class DBIMessageContextMenu<TNamespace extends NamespaceEnums> extends DBIBaseInteraction<TNamespace> {
|
|
14
|
-
constructor(dbi: DBI<TNamespace>, cfg: TDBIMessageContextMenuOmitted<TNamespace>) {
|
|
15
|
-
super(dbi, {
|
|
16
|
-
...(cfg as any),
|
|
17
|
-
type: "MessageContextMenu"
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
this.directMessages = cfg.directMessages ?? dbi.config.defaults.directMessages;
|
|
21
|
-
this.defaultMemberPermissions = cfg.defaultMemberPermissions ?? dbi.config.defaults.defaultMemberPermissions;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
directMessages?: boolean;
|
|
25
|
-
defaultMemberPermissions?: Discord.PermissionsString[];
|
|
26
|
-
override onExecute(ctx: IDBIMessageContextMenuExecuteCtx<TNamespace>): Promise<void> | void {}
|
|
1
|
+
import { DBI } from "../../DBI";
|
|
2
|
+
import { DBIBaseInteraction, IDBIBaseExecuteCtx } from "../Interaction";
|
|
3
|
+
import Discord from "discord.js";
|
|
4
|
+
import { NamespaceEnums } from "../../../generated/namespaceData";
|
|
5
|
+
|
|
6
|
+
export type TDBIMessageContextMenuOmitted<TNamespace extends NamespaceEnums> = Omit<DBIMessageContextMenu<TNamespace>, "type" | "description" | "dbi" | "options" | "toJSON">;
|
|
7
|
+
|
|
8
|
+
export interface IDBIMessageContextMenuExecuteCtx<TNamespace extends NamespaceEnums> extends IDBIBaseExecuteCtx<TNamespace> {
|
|
9
|
+
interaction: Discord.MessageContextMenuCommandInteraction<"cached">;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export class DBIMessageContextMenu<TNamespace extends NamespaceEnums> extends DBIBaseInteraction<TNamespace> {
|
|
14
|
+
constructor(dbi: DBI<TNamespace>, cfg: TDBIMessageContextMenuOmitted<TNamespace>) {
|
|
15
|
+
super(dbi, {
|
|
16
|
+
...(cfg as any),
|
|
17
|
+
type: "MessageContextMenu"
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
this.directMessages = cfg.directMessages ?? dbi.config.defaults.directMessages;
|
|
21
|
+
this.defaultMemberPermissions = cfg.defaultMemberPermissions ?? dbi.config.defaults.defaultMemberPermissions;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
directMessages?: boolean;
|
|
25
|
+
defaultMemberPermissions?: Discord.PermissionsString[];
|
|
26
|
+
override onExecute(ctx: IDBIMessageContextMenuExecuteCtx<TNamespace>): Promise<void> | void {}
|
|
27
27
|
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { DBI } from "../../DBI";
|
|
2
|
-
import { DBIBaseInteraction, IDBIBaseExecuteCtx } from "../Interaction";
|
|
3
|
-
import Discord from "discord.js";
|
|
4
|
-
import { NamespaceEnums } from "../../../generated/namespaceData";
|
|
5
|
-
|
|
6
|
-
export type TDBIUserContextMenuOmitted<TNamespace extends NamespaceEnums> = Omit<DBIUserContextMenu<TNamespace>, "type" | "description" | "dbi" | "options" | "toJSON">;
|
|
7
|
-
|
|
8
|
-
export interface IDBIUserContextMenuExecuteCtx<TNamespace extends NamespaceEnums> extends IDBIBaseExecuteCtx<TNamespace> {
|
|
9
|
-
interaction: Discord.UserContextMenuCommandInteraction<"cached">;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class DBIUserContextMenu<TNamespace extends NamespaceEnums> extends DBIBaseInteraction<TNamespace> {
|
|
13
|
-
constructor(dbi: DBI<TNamespace>, cfg: TDBIUserContextMenuOmitted<TNamespace>) {
|
|
14
|
-
super(dbi, {
|
|
15
|
-
...(cfg as any),
|
|
16
|
-
type: "UserContextMenu"
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
this.directMessages = cfg.directMessages ?? dbi.config.defaults.directMessages;
|
|
20
|
-
this.defaultMemberPermissions = cfg.defaultMemberPermissions ?? dbi.config.defaults.defaultMemberPermissions;
|
|
21
|
-
}
|
|
22
|
-
directMessages?: boolean;
|
|
23
|
-
defaultMemberPermissions?: Discord.PermissionsString[];
|
|
24
|
-
override onExecute(ctx: IDBIUserContextMenuExecuteCtx<TNamespace>): Promise<void> | void {}
|
|
1
|
+
import { DBI } from "../../DBI";
|
|
2
|
+
import { DBIBaseInteraction, IDBIBaseExecuteCtx } from "../Interaction";
|
|
3
|
+
import Discord from "discord.js";
|
|
4
|
+
import { NamespaceEnums } from "../../../generated/namespaceData";
|
|
5
|
+
|
|
6
|
+
export type TDBIUserContextMenuOmitted<TNamespace extends NamespaceEnums> = Omit<DBIUserContextMenu<TNamespace>, "type" | "description" | "dbi" | "options" | "toJSON">;
|
|
7
|
+
|
|
8
|
+
export interface IDBIUserContextMenuExecuteCtx<TNamespace extends NamespaceEnums> extends IDBIBaseExecuteCtx<TNamespace> {
|
|
9
|
+
interaction: Discord.UserContextMenuCommandInteraction<"cached">;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class DBIUserContextMenu<TNamespace extends NamespaceEnums> extends DBIBaseInteraction<TNamespace> {
|
|
13
|
+
constructor(dbi: DBI<TNamespace>, cfg: TDBIUserContextMenuOmitted<TNamespace>) {
|
|
14
|
+
super(dbi, {
|
|
15
|
+
...(cfg as any),
|
|
16
|
+
type: "UserContextMenu"
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
this.directMessages = cfg.directMessages ?? dbi.config.defaults.directMessages;
|
|
20
|
+
this.defaultMemberPermissions = cfg.defaultMemberPermissions ?? dbi.config.defaults.defaultMemberPermissions;
|
|
21
|
+
}
|
|
22
|
+
directMessages?: boolean;
|
|
23
|
+
defaultMemberPermissions?: Discord.PermissionsString[];
|
|
24
|
+
override onExecute(ctx: IDBIUserContextMenuExecuteCtx<TNamespace>): Promise<void> | void {}
|
|
25
25
|
}
|
package/src/utils/MemoryStore.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import _ from "lodash";
|
|
2
|
-
|
|
3
|
-
export class MemoryStore {
|
|
4
|
-
store: Record<string, any>;
|
|
5
|
-
constructor() {
|
|
6
|
-
this.store = {};
|
|
7
|
-
}
|
|
8
|
-
async get(key: string, defaultValue?: any): Promise<any> {
|
|
9
|
-
let val = _.get(this.store, key);
|
|
10
|
-
if (!val) {
|
|
11
|
-
this.set(key, defaultValue);
|
|
12
|
-
return defaultValue;
|
|
13
|
-
}
|
|
14
|
-
return val;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async set(key: string, value: any): Promise<any> {
|
|
18
|
-
return this.store = _.set(this.store, key, value);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async delete(key: string): Promise<boolean> {
|
|
22
|
-
return _.unset(this.store, key);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async has(key: string): Promise<boolean> {
|
|
26
|
-
return _.has(this.store, key);
|
|
27
|
-
}
|
|
1
|
+
import _ from "lodash";
|
|
2
|
+
|
|
3
|
+
export class MemoryStore {
|
|
4
|
+
store: Record<string, any>;
|
|
5
|
+
constructor() {
|
|
6
|
+
this.store = {};
|
|
7
|
+
}
|
|
8
|
+
async get(key: string, defaultValue?: any): Promise<any> {
|
|
9
|
+
let val = _.get(this.store, key);
|
|
10
|
+
if (!val) {
|
|
11
|
+
this.set(key, defaultValue);
|
|
12
|
+
return defaultValue;
|
|
13
|
+
}
|
|
14
|
+
return val;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async set(key: string, value: any): Promise<any> {
|
|
18
|
+
return this.store = _.set(this.store, key, value);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async delete(key: string): Promise<boolean> {
|
|
22
|
+
return _.unset(this.store, key);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async has(key: string): Promise<boolean> {
|
|
26
|
+
return _.has(this.store, key);
|
|
27
|
+
}
|
|
28
28
|
}
|
package/src/utils/UtilTypes.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export interface IDBIToJSONArgs<T> {
|
|
2
|
-
reference?: {
|
|
3
|
-
ttl?: number;
|
|
4
|
-
data: (string | number | object | boolean | null | undefined)[];
|
|
5
|
-
};
|
|
6
|
-
overrides?: RecursivePartial<T>;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type RecursivePartial<T> = {
|
|
10
|
-
[P in keyof T]?: RecursivePartial<T[P]>;
|
|
1
|
+
export interface IDBIToJSONArgs<T> {
|
|
2
|
+
reference?: {
|
|
3
|
+
ttl?: number;
|
|
4
|
+
data: (string | number | object | boolean | null | undefined)[];
|
|
5
|
+
};
|
|
6
|
+
overrides?: RecursivePartial<T>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type RecursivePartial<T> = {
|
|
10
|
+
[P in keyof T]?: RecursivePartial<T[P]>;
|
|
11
11
|
}
|
package/src/utils/customId.ts
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { DBI } from "../DBI";
|
|
2
|
-
import * as stuffs from "stuffs";
|
|
3
|
-
import { NamespaceEnums } from "../../generated/namespaceData";
|
|
4
|
-
|
|
5
|
-
export function buildCustomId(dbi: DBI<NamespaceEnums>, name: string, data: any[], ttl?: number): string {
|
|
6
|
-
let customId = [
|
|
7
|
-
name,
|
|
8
|
-
...data.map(value => {
|
|
9
|
-
if (typeof value == "string") return value;
|
|
10
|
-
if (typeof value == "number") return `ฯ${value}`;
|
|
11
|
-
if (typeof value == "bigint") return `แ${value.toString()}`;
|
|
12
|
-
if (typeof value == "boolean") return `๐ซ${value ? 1 : 0}`;
|
|
13
|
-
if (typeof value == "undefined") return "๐ถu";
|
|
14
|
-
if (value === null) return "๐ถn";
|
|
15
|
-
let id = stuffs.randomString(8);
|
|
16
|
-
Object.assign(value, {
|
|
17
|
-
$ref: id,
|
|
18
|
-
$unRef() { return dbi.data.refs.delete(id); },
|
|
19
|
-
})
|
|
20
|
-
dbi.data.refs.set(id, { at: Date.now(), value, ttl });
|
|
21
|
-
return `ยค${id}`;
|
|
22
|
-
})
|
|
23
|
-
].join("โ");
|
|
24
|
-
if (!dbi.config.strict) customId = customId.slice(0, 100);
|
|
25
|
-
if (customId.length > 100) throw new Error("Custom id cannot be longer than 100 characters.")
|
|
26
|
-
return customId;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function parseCustomId(dbi: DBI<NamespaceEnums>, customId: string): { name: string, data: any[] } {
|
|
30
|
-
let splitted = customId.split("โ");
|
|
31
|
-
let name = splitted.shift();
|
|
32
|
-
let data = splitted.map(value => {
|
|
33
|
-
if (value.startsWith("ฯ")) return Number(value.slice(1));
|
|
34
|
-
if (value.startsWith("๐ซ")) return !!Number(value.slice(1));
|
|
35
|
-
if (value.startsWith("แ")) return BigInt(value.slice(1));
|
|
36
|
-
if (value.startsWith("ยค")) return dbi.data.refs.get(value.slice(1))?.value;
|
|
37
|
-
if (value == "๐ถu") return undefined;
|
|
38
|
-
if (value == "๐ถn") return null;
|
|
39
|
-
return value;
|
|
40
|
-
});
|
|
41
|
-
return {
|
|
42
|
-
name,
|
|
43
|
-
data
|
|
44
|
-
}
|
|
1
|
+
import { DBI } from "../DBI";
|
|
2
|
+
import * as stuffs from "stuffs";
|
|
3
|
+
import { NamespaceEnums } from "../../generated/namespaceData";
|
|
4
|
+
|
|
5
|
+
export function buildCustomId(dbi: DBI<NamespaceEnums>, name: string, data: any[], ttl?: number): string {
|
|
6
|
+
let customId = [
|
|
7
|
+
name,
|
|
8
|
+
...data.map(value => {
|
|
9
|
+
if (typeof value == "string") return value;
|
|
10
|
+
if (typeof value == "number") return `ฯ${value}`;
|
|
11
|
+
if (typeof value == "bigint") return `แ${value.toString()}`;
|
|
12
|
+
if (typeof value == "boolean") return `๐ซ${value ? 1 : 0}`;
|
|
13
|
+
if (typeof value == "undefined") return "๐ถu";
|
|
14
|
+
if (value === null) return "๐ถn";
|
|
15
|
+
let id = stuffs.randomString(8);
|
|
16
|
+
Object.assign(value, {
|
|
17
|
+
$ref: id,
|
|
18
|
+
$unRef() { return dbi.data.refs.delete(id); },
|
|
19
|
+
})
|
|
20
|
+
dbi.data.refs.set(id, { at: Date.now(), value, ttl });
|
|
21
|
+
return `ยค${id}`;
|
|
22
|
+
})
|
|
23
|
+
].join("โ");
|
|
24
|
+
if (!dbi.config.strict) customId = customId.slice(0, 100);
|
|
25
|
+
if (customId.length > 100) throw new Error("Custom id cannot be longer than 100 characters.")
|
|
26
|
+
return customId;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function parseCustomId(dbi: DBI<NamespaceEnums>, customId: string): { name: string, data: any[] } {
|
|
30
|
+
let splitted = customId.split("โ");
|
|
31
|
+
let name = splitted.shift();
|
|
32
|
+
let data = splitted.map(value => {
|
|
33
|
+
if (value.startsWith("ฯ")) return Number(value.slice(1));
|
|
34
|
+
if (value.startsWith("๐ซ")) return !!Number(value.slice(1));
|
|
35
|
+
if (value.startsWith("แ")) return BigInt(value.slice(1));
|
|
36
|
+
if (value.startsWith("ยค")) return dbi.data.refs.get(value.slice(1))?.value;
|
|
37
|
+
if (value == "๐ถu") return undefined;
|
|
38
|
+
if (value == "๐ถn") return null;
|
|
39
|
+
return value;
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
name,
|
|
43
|
+
data
|
|
44
|
+
}
|
|
45
45
|
}
|
package/src/utils/permissions.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PermissionFlagsBits, PermissionsString } from "discord.js";
|
|
2
|
-
|
|
3
|
-
export function reducePermissions(permStrings: PermissionsString[] = []): bigint {
|
|
4
|
-
return permStrings.reduce((all, curr) => PermissionFlagsBits[curr] | all, 0n);
|
|
1
|
+
import { PermissionFlagsBits, PermissionsString } from "discord.js";
|
|
2
|
+
|
|
3
|
+
export function reducePermissions(permStrings: PermissionsString[] = []): bigint {
|
|
4
|
+
return permStrings.reduce((all, curr) => PermissionFlagsBits[curr] | all, 0n);
|
|
5
5
|
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @example
|
|
6
|
-
* await recursiveImport("./src", [".js"], [".d.ts"])
|
|
7
|
-
*/
|
|
8
|
-
export async function recursiveImport(folderPath: string, exts: string[] = [".js"], ignore: string[] = [".d.ts",".js.map",".d.ts.map"]): Promise<any> {
|
|
9
|
-
let files = await fs.promises.readdir(folderPath, { withFileTypes: true });
|
|
10
|
-
let dirName = __dirname;
|
|
11
|
-
|
|
12
|
-
for (const file of files) {
|
|
13
|
-
let filePath = path.resolve(folderPath, file.name);
|
|
14
|
-
let relative = path.relative(dirName, filePath);
|
|
15
|
-
if (!relative.includes(`${path.sep}-`)) {
|
|
16
|
-
if (file.isDirectory()) {
|
|
17
|
-
await recursiveImport(filePath, exts)
|
|
18
|
-
} else if (exts.some(i => file.name.endsWith(i)) && !ignore.some(i => file.name.endsWith(i))) {
|
|
19
|
-
await import(filePath);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @example
|
|
6
|
+
* await recursiveImport("./src", [".js"], [".d.ts"])
|
|
7
|
+
*/
|
|
8
|
+
export async function recursiveImport(folderPath: string, exts: string[] = [".js"], ignore: string[] = [".d.ts",".js.map",".d.ts.map"]): Promise<any> {
|
|
9
|
+
let files = await fs.promises.readdir(folderPath, { withFileTypes: true });
|
|
10
|
+
let dirName = __dirname;
|
|
11
|
+
|
|
12
|
+
for (const file of files) {
|
|
13
|
+
let filePath = path.resolve(folderPath, file.name);
|
|
14
|
+
let relative = path.relative(dirName, filePath);
|
|
15
|
+
if (!relative.includes(`${path.sep}-`)) {
|
|
16
|
+
if (file.isDirectory()) {
|
|
17
|
+
await recursiveImport(filePath, exts)
|
|
18
|
+
} else if (exts.some(i => file.name.endsWith(i)) && !ignore.some(i => file.name.endsWith(i))) {
|
|
19
|
+
await import(filePath);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
23
|
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { unloadModule } from "./unloadModule";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @example
|
|
7
|
-
* await recursiveUnload("./src", [".js"], [".d.ts"])
|
|
8
|
-
* await dbi.unload()
|
|
9
|
-
*/
|
|
10
|
-
export async function recursiveUnload(folderPath: string, exts: string[] = [".js"], ignore: string[] = [".d.ts",".js.map",".d.ts.map"]): Promise<any> {
|
|
11
|
-
let files = await fs.promises.readdir(folderPath, { withFileTypes: true });
|
|
12
|
-
let dirName = __dirname;
|
|
13
|
-
|
|
14
|
-
for (const file of files) {
|
|
15
|
-
let filePath = path.resolve(folderPath, file.name);
|
|
16
|
-
let relative = path.relative(dirName, filePath);
|
|
17
|
-
if (!relative.includes(`${path.sep}-`)) {
|
|
18
|
-
if (file.isDirectory()) {
|
|
19
|
-
await recursiveUnload(filePath, exts)
|
|
20
|
-
} else if (exts.some(i => file.name.endsWith(i)) && !ignore.some(i => file.name.endsWith(i))) {
|
|
21
|
-
unloadModule(filePath)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { unloadModule } from "./unloadModule";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @example
|
|
7
|
+
* await recursiveUnload("./src", [".js"], [".d.ts"])
|
|
8
|
+
* await dbi.unload()
|
|
9
|
+
*/
|
|
10
|
+
export async function recursiveUnload(folderPath: string, exts: string[] = [".js"], ignore: string[] = [".d.ts",".js.map",".d.ts.map"]): Promise<any> {
|
|
11
|
+
let files = await fs.promises.readdir(folderPath, { withFileTypes: true });
|
|
12
|
+
let dirName = __dirname;
|
|
13
|
+
|
|
14
|
+
for (const file of files) {
|
|
15
|
+
let filePath = path.resolve(folderPath, file.name);
|
|
16
|
+
let relative = path.relative(dirName, filePath);
|
|
17
|
+
if (!relative.includes(`${path.sep}-`)) {
|
|
18
|
+
if (file.isDirectory()) {
|
|
19
|
+
await recursiveUnload(filePath, exts)
|
|
20
|
+
} else if (exts.some(i => file.name.endsWith(i)) && !ignore.some(i => file.name.endsWith(i))) {
|
|
21
|
+
unloadModule(filePath)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
25
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export function unloadModule(modulePath) {
|
|
2
|
-
let nodeModule = require.cache[modulePath];
|
|
3
|
-
if (nodeModule) {
|
|
4
|
-
for (let child of nodeModule.children) unloadModule(child.id);
|
|
5
|
-
}
|
|
6
|
-
delete require.cache[modulePath];
|
|
1
|
+
export function unloadModule(modulePath) {
|
|
2
|
+
let nodeModule = require.cache[modulePath];
|
|
3
|
+
if (nodeModule) {
|
|
4
|
+
for (let child of nodeModule.children) unloadModule(child.id);
|
|
5
|
+
}
|
|
6
|
+
delete require.cache[modulePath];
|
|
7
7
|
}
|