@mostfeatured/dbi 0.1.28 → 0.1.29

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.
Files changed (103) hide show
  1. package/.gitattributes +2 -2
  2. package/.hintrc +7 -7
  3. package/.vscode/settings.json +2 -2
  4. package/LICENSE +674 -674
  5. package/dist/DBI.d.ts +4 -4
  6. package/dist/DBI.d.ts.map +1 -1
  7. package/dist/DBI.js.map +1 -1
  8. package/dist/Events.js.map +1 -1
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/methods/handleMessageCommands.js.map +1 -1
  13. package/dist/methods/hookEventListeners.js.map +1 -1
  14. package/dist/methods/hookInteractionListeners.js.map +1 -1
  15. package/dist/methods/publishInteractions.js.map +1 -1
  16. package/dist/types/ApplicationRoleConnectionMetadata.js.map +1 -1
  17. package/dist/types/Builders/ButtonBuilder.js.map +1 -1
  18. package/dist/types/Builders/ChannelSelectMenuBuilder.js.map +1 -1
  19. package/dist/types/Builders/MentionableSelectMenuBuilder.js.map +1 -1
  20. package/dist/types/Builders/ModalBuilder.js.map +1 -1
  21. package/dist/types/Builders/RoleSelectMenuBuilder.js.map +1 -1
  22. package/dist/types/Builders/StringSelectMenuBuilder.js.map +1 -1
  23. package/dist/types/Builders/UserSelectMenuBuilder.js.map +1 -1
  24. package/dist/types/ChatInput/ChatInput.js.map +1 -1
  25. package/dist/types/ChatInput/ChatInputOptions.d.ts +16 -16
  26. package/dist/types/ChatInput/ChatInputOptions.d.ts.map +1 -1
  27. package/dist/types/ChatInput/ChatInputOptions.js.map +1 -1
  28. package/dist/types/Components/Button.js.map +1 -1
  29. package/dist/types/Components/ChannelSelectMenu.js.map +1 -1
  30. package/dist/types/Components/MentionableSelectMenu.js.map +1 -1
  31. package/dist/types/Components/Modal.js.map +1 -1
  32. package/dist/types/Components/RoleSelectMenu.js.map +1 -1
  33. package/dist/types/Components/StringSelectMenu.js.map +1 -1
  34. package/dist/types/Components/UserSelectMenu.js.map +1 -1
  35. package/dist/types/Event.js.map +1 -1
  36. package/dist/types/Interaction.js.map +1 -1
  37. package/dist/types/other/CustomEvent.js.map +1 -1
  38. package/dist/types/other/FakeMessageInteraction.js.map +1 -1
  39. package/dist/types/other/InteractionLocale.js.map +1 -1
  40. package/dist/types/other/Locale.js.map +1 -1
  41. package/dist/types/other/MessageContextMenu.js.map +1 -1
  42. package/dist/types/other/UserContextMenu.js.map +1 -1
  43. package/dist/utils/MemoryStore.js.map +1 -1
  44. package/dist/utils/UtilTypes.js.map +1 -1
  45. package/dist/utils/customId.js.map +1 -1
  46. package/dist/utils/permissions.js.map +1 -1
  47. package/dist/utils/recursiveImport.js.map +1 -1
  48. package/dist/utils/recursiveUnload.js.map +1 -1
  49. package/dist/utils/unloadModule.js.map +1 -1
  50. package/examples/modal/dbi.js +29 -29
  51. package/examples/modal/login.js +14 -14
  52. package/examples/modal/package.json +15 -15
  53. package/examples/modal/publish.js +12 -12
  54. package/examples/modal/src/chatInput.js +37 -37
  55. package/examples/modal/src/components.js +32 -32
  56. package/examples/modal/src/event.js +19 -19
  57. package/examples/modal/src/interactionlocales.js +23 -23
  58. package/examples/modal/src/locales.js +37 -37
  59. package/examples/modal/src/modal.js +27 -27
  60. package/generated/namespaceData.d.ts +14 -14
  61. package/package.json +2 -2
  62. package/readme.md +591 -591
  63. package/src/DBI.ts +1090 -1090
  64. package/src/Events.ts +189 -189
  65. package/src/data/eventMap.json +247 -247
  66. package/src/index.ts +23 -23
  67. package/src/methods/handleMessageCommands.ts +482 -482
  68. package/src/methods/hookEventListeners.ts +118 -118
  69. package/src/methods/hookInteractionListeners.ts +260 -260
  70. package/src/methods/publishInteractions.ts +255 -255
  71. package/src/types/ApplicationRoleConnectionMetadata.ts +19 -19
  72. package/src/types/Builders/ButtonBuilder.ts +52 -52
  73. package/src/types/Builders/ChannelSelectMenuBuilder.ts +52 -52
  74. package/src/types/Builders/MentionableSelectMenuBuilder.ts +52 -52
  75. package/src/types/Builders/ModalBuilder.ts +52 -52
  76. package/src/types/Builders/RoleSelectMenuBuilder.ts +52 -52
  77. package/src/types/Builders/StringSelectMenuBuilder.ts +52 -52
  78. package/src/types/Builders/UserSelectMenuBuilder.ts +52 -52
  79. package/src/types/ChatInput/ChatInput.ts +27 -27
  80. package/src/types/ChatInput/ChatInputOptions.ts +388 -388
  81. package/src/types/Components/Button.ts +38 -38
  82. package/src/types/Components/ChannelSelectMenu.ts +42 -42
  83. package/src/types/Components/MentionableSelectMenu.ts +42 -42
  84. package/src/types/Components/Modal.ts +45 -45
  85. package/src/types/Components/RoleSelectMenu.ts +42 -42
  86. package/src/types/Components/StringSelectMenu.ts +42 -42
  87. package/src/types/Components/UserSelectMenu.ts +42 -42
  88. package/src/types/Event.ts +144 -144
  89. package/src/types/Interaction.ts +96 -96
  90. package/src/types/other/CustomEvent.ts +18 -18
  91. package/src/types/other/FakeMessageInteraction.ts +407 -407
  92. package/src/types/other/InteractionLocale.ts +33 -33
  93. package/src/types/other/Locale.ts +69 -69
  94. package/src/types/other/MessageContextMenu.ts +26 -26
  95. package/src/types/other/UserContextMenu.ts +24 -24
  96. package/src/utils/MemoryStore.ts +27 -27
  97. package/src/utils/UtilTypes.ts +10 -10
  98. package/src/utils/customId.ts +44 -44
  99. package/src/utils/permissions.ts +4 -4
  100. package/src/utils/recursiveImport.ts +22 -22
  101. package/src/utils/recursiveUnload.ts +24 -24
  102. package/src/utils/unloadModule.ts +6 -6
  103. package/tsconfig.json +40 -40
package/src/Events.ts CHANGED
@@ -1,189 +1,189 @@
1
- import { NamespaceEnums, NamespaceData } from "../generated/namespaceData";
2
- import { DBI } from "./DBI";
3
- import { TDBIMessageCommandArgumentErrorTypes } from "./methods/handleMessageCommands";
4
- import { DBIChatInput } from "./types/ChatInput/ChatInput";
5
- import { TDBIValueName } from "./types/ChatInput/ChatInputOptions";
6
- import { ClientEvents, DBIEvent } from "./types/Event";
7
- import { IDBIBaseExecuteCtx, TDBIRateLimitTypes } from "./types/Interaction";
8
- import { FakeMessageInteraction } from "./types/other/FakeMessageInteraction";
9
- import { DBILocale } from "./types/other/Locale";
10
- import Discord, { PermissionsString } from "discord.js";
11
-
12
- export type TDBIEventNames =
13
- | "beforeInteraction"
14
- | "afterInteraction"
15
- | "interactionRateLimit"
16
- | "beforeEvent"
17
- | "afterEvent"
18
- | "interactionError"
19
- | "eventError"
20
- | "messageCommandArgumentError"
21
- | "messageCommandDirectMessageUsageError"
22
- | "messageCommandDefaultMemberPermissionsError"
23
- | "clientsReady";
24
-
25
- export type TDBIEventHandlerCtx<TNamespace extends NamespaceEnums> = {
26
- [K in keyof (ClientEvents & NamespaceData[TNamespace]["customEvents"])]: {
27
- other: Record<string, any>;
28
- locale?: { guild: DBILocale<TNamespace> };
29
- eventName: K;
30
- dbiEvent: DBIEvent<TNamespace>;
31
- } & (ClientEvents & NamespaceData[TNamespace]["customEvents"])[K];
32
- }[keyof (ClientEvents & NamespaceData[TNamespace]["customEvents"])];
33
-
34
- export class Events<TNamespace extends NamespaceEnums> {
35
- DBI: DBI<TNamespace>;
36
- handlers: Record<string, Array<(data: any) => boolean | Promise<boolean>>>;
37
- constructor(DBI: DBI<TNamespace>) {
38
- this.DBI = DBI;
39
-
40
- this.handlers = {
41
- beforeInteraction: [],
42
- afterInteraction: [],
43
- interactionRateLimit: [],
44
- beforeEvent: [],
45
- afterEvent: [],
46
- interactionError: [],
47
- eventError: [],
48
- };
49
- }
50
-
51
- async trigger(name: TDBIEventNames, data?: any, ignoreResponse = false): Promise<boolean> {
52
- let handlers = this.handlers[name];
53
- if (!handlers?.length) return true;
54
- for (let i = 0; i < handlers.length; i++) {
55
- const handler = handlers[i];
56
- if (!ignoreResponse) {
57
- let returned = await handler(data);
58
- if (returned !== true) return false;
59
- } else {
60
- handler(data);
61
- }
62
- }
63
- return true;
64
- }
65
-
66
- on(
67
- eventName: "clientsReady",
68
- handler: () => any,
69
- options?: { once: boolean }
70
- ): () => any;
71
-
72
- on(
73
- eventName: "beforeInteraction" | "afterInteraction",
74
- handler: (
75
- data: IDBIBaseExecuteCtx<TNamespace>
76
- ) => Promise<boolean> | boolean,
77
- options?: { once: boolean }
78
- ): () => any;
79
-
80
- on(
81
- eventName: "interactionError",
82
- handler: (
83
- data: IDBIBaseExecuteCtx<TNamespace> & { error: any }
84
- ) => Promise<boolean> | boolean,
85
- options?: { once: boolean }
86
- ): () => any;
87
-
88
- on(
89
- eventName: "beforeEvent" | "afterEvent",
90
- handler: (
91
- data: TDBIEventHandlerCtx<TNamespace>
92
- ) => Promise<boolean> | boolean,
93
- options?: { once: boolean }
94
- ): () => any;
95
-
96
- on(
97
- eventName: "eventError",
98
- handler: (
99
- data: TDBIEventHandlerCtx<TNamespace> & {
100
- error: any;
101
- dbiEvent: DBIEvent<TNamespace>;
102
- }
103
- ) => Promise<boolean> | boolean,
104
- options?: { once: boolean }
105
- ): () => any;
106
-
107
- on(
108
- eventName: "interactionRateLimit",
109
- handler: (
110
- data: Omit<IDBIBaseExecuteCtx<TNamespace>, "other" | "setRateLimit"> & {
111
- rateLimit: { type: TDBIRateLimitTypes; duration: number; at: number };
112
- }
113
- ) => Promise<boolean> | boolean,
114
- options?: { once: boolean }
115
- ): () => any;
116
-
117
- on(
118
- eventName: "messageCommandArgumentError",
119
- handler: (data: {
120
- message: Discord.Message;
121
- interaction: FakeMessageInteraction;
122
- error: {
123
- type: TDBIMessageCommandArgumentErrorTypes;
124
- option: any;
125
- index: number;
126
- extra?: any;
127
- };
128
- value: any;
129
- locale: { guild?: DBILocale<TNamespace>; user: DBILocale<TNamespace> };
130
- dbiInteraction: DBIChatInput<TNamespace>;
131
- }) => Promise<boolean> | boolean,
132
- options?: { once: boolean }
133
- ): () => any;
134
-
135
- on(
136
- eventName: "messageCommandDefaultMemberPermissionsError",
137
- handler: (data: {
138
- message: Discord.Message;
139
- interaction: FakeMessageInteraction;
140
- locale: { guild?: DBILocale<TNamespace>; user: DBILocale<TNamespace> };
141
- permissions: PermissionsString[];
142
- dbiInteraction: DBIChatInput<TNamespace>;
143
- }) => Promise<boolean> | boolean,
144
- options?: { once: boolean }
145
- ): () => any;
146
-
147
- on(
148
- eventName: "messageCommandDirectMessageUsageError",
149
- handler: (data: {
150
- message: Discord.Message;
151
- interaction: FakeMessageInteraction;
152
- locale: { guild?: DBILocale<TNamespace>; user: DBILocale<TNamespace> };
153
- dbiInteraction: DBIChatInput<TNamespace>;
154
- }) => Promise<boolean> | boolean,
155
- options?: { once: boolean }
156
- ): () => any;
157
-
158
- on(
159
- eventName: TDBIEventNames,
160
- handler: (data: any) => Promise<boolean> | boolean,
161
- options: { once: boolean } = { once: false }
162
- ): () => any {
163
- if (!this.handlers.hasOwnProperty(eventName)) this.handlers[eventName] = [];
164
- if (options.once) {
165
- let h = (data) => {
166
- this.off(eventName, h);
167
- return handler(data);
168
- };
169
- this.on(eventName as any, h as any, { once: false });
170
- return () => {
171
- this.off(eventName, h);
172
- };
173
- } else {
174
- this.handlers[eventName].push(handler);
175
- return () => {
176
- this.off(eventName, handler);
177
- };
178
- }
179
- }
180
-
181
- off(
182
- eventName: TDBIEventNames,
183
- handler: (data: any) => Promise<boolean> | boolean
184
- ) {
185
- let l = this.handlers[eventName];
186
- if (!l) return [];
187
- return l.splice(l.indexOf(handler), 1);
188
- }
189
- }
1
+ import { NamespaceEnums, NamespaceData } from "../generated/namespaceData";
2
+ import { DBI } from "./DBI";
3
+ import { TDBIMessageCommandArgumentErrorTypes } from "./methods/handleMessageCommands";
4
+ import { DBIChatInput } from "./types/ChatInput/ChatInput";
5
+ import { TDBIValueName } from "./types/ChatInput/ChatInputOptions";
6
+ import { ClientEvents, DBIEvent } from "./types/Event";
7
+ import { IDBIBaseExecuteCtx, TDBIRateLimitTypes } from "./types/Interaction";
8
+ import { FakeMessageInteraction } from "./types/other/FakeMessageInteraction";
9
+ import { DBILocale } from "./types/other/Locale";
10
+ import Discord, { PermissionsString } from "discord.js";
11
+
12
+ export type TDBIEventNames =
13
+ | "beforeInteraction"
14
+ | "afterInteraction"
15
+ | "interactionRateLimit"
16
+ | "beforeEvent"
17
+ | "afterEvent"
18
+ | "interactionError"
19
+ | "eventError"
20
+ | "messageCommandArgumentError"
21
+ | "messageCommandDirectMessageUsageError"
22
+ | "messageCommandDefaultMemberPermissionsError"
23
+ | "clientsReady";
24
+
25
+ export type TDBIEventHandlerCtx<TNamespace extends NamespaceEnums> = {
26
+ [K in keyof (ClientEvents & NamespaceData[TNamespace]["customEvents"])]: {
27
+ other: Record<string, any>;
28
+ locale?: { guild: DBILocale<TNamespace> };
29
+ eventName: K;
30
+ dbiEvent: DBIEvent<TNamespace>;
31
+ } & (ClientEvents & NamespaceData[TNamespace]["customEvents"])[K];
32
+ }[keyof (ClientEvents & NamespaceData[TNamespace]["customEvents"])];
33
+
34
+ export class Events<TNamespace extends NamespaceEnums> {
35
+ DBI: DBI<TNamespace>;
36
+ handlers: Record<string, Array<(data: any) => boolean | Promise<boolean>>>;
37
+ constructor(DBI: DBI<TNamespace>) {
38
+ this.DBI = DBI;
39
+
40
+ this.handlers = {
41
+ beforeInteraction: [],
42
+ afterInteraction: [],
43
+ interactionRateLimit: [],
44
+ beforeEvent: [],
45
+ afterEvent: [],
46
+ interactionError: [],
47
+ eventError: [],
48
+ };
49
+ }
50
+
51
+ async trigger(name: TDBIEventNames, data?: any, ignoreResponse = false): Promise<boolean> {
52
+ let handlers = this.handlers[name];
53
+ if (!handlers?.length) return true;
54
+ for (let i = 0; i < handlers.length; i++) {
55
+ const handler = handlers[i];
56
+ if (!ignoreResponse) {
57
+ let returned = await handler(data);
58
+ if (returned !== true) return false;
59
+ } else {
60
+ handler(data);
61
+ }
62
+ }
63
+ return true;
64
+ }
65
+
66
+ on(
67
+ eventName: "clientsReady",
68
+ handler: () => any,
69
+ options?: { once: boolean }
70
+ ): () => any;
71
+
72
+ on(
73
+ eventName: "beforeInteraction" | "afterInteraction",
74
+ handler: (
75
+ data: IDBIBaseExecuteCtx<TNamespace>
76
+ ) => Promise<boolean> | boolean,
77
+ options?: { once: boolean }
78
+ ): () => any;
79
+
80
+ on(
81
+ eventName: "interactionError",
82
+ handler: (
83
+ data: IDBIBaseExecuteCtx<TNamespace> & { error: any }
84
+ ) => Promise<boolean> | boolean,
85
+ options?: { once: boolean }
86
+ ): () => any;
87
+
88
+ on(
89
+ eventName: "beforeEvent" | "afterEvent",
90
+ handler: (
91
+ data: TDBIEventHandlerCtx<TNamespace>
92
+ ) => Promise<boolean> | boolean,
93
+ options?: { once: boolean }
94
+ ): () => any;
95
+
96
+ on(
97
+ eventName: "eventError",
98
+ handler: (
99
+ data: TDBIEventHandlerCtx<TNamespace> & {
100
+ error: any;
101
+ dbiEvent: DBIEvent<TNamespace>;
102
+ }
103
+ ) => Promise<boolean> | boolean,
104
+ options?: { once: boolean }
105
+ ): () => any;
106
+
107
+ on(
108
+ eventName: "interactionRateLimit",
109
+ handler: (
110
+ data: Omit<IDBIBaseExecuteCtx<TNamespace>, "other" | "setRateLimit"> & {
111
+ rateLimit: { type: TDBIRateLimitTypes; duration: number; at: number };
112
+ }
113
+ ) => Promise<boolean> | boolean,
114
+ options?: { once: boolean }
115
+ ): () => any;
116
+
117
+ on(
118
+ eventName: "messageCommandArgumentError",
119
+ handler: (data: {
120
+ message: Discord.Message;
121
+ interaction: FakeMessageInteraction;
122
+ error: {
123
+ type: TDBIMessageCommandArgumentErrorTypes;
124
+ option: any;
125
+ index: number;
126
+ extra?: any;
127
+ };
128
+ value: any;
129
+ locale: { guild?: DBILocale<TNamespace>; user: DBILocale<TNamespace> };
130
+ dbiInteraction: DBIChatInput<TNamespace>;
131
+ }) => Promise<boolean> | boolean,
132
+ options?: { once: boolean }
133
+ ): () => any;
134
+
135
+ on(
136
+ eventName: "messageCommandDefaultMemberPermissionsError",
137
+ handler: (data: {
138
+ message: Discord.Message;
139
+ interaction: FakeMessageInteraction;
140
+ locale: { guild?: DBILocale<TNamespace>; user: DBILocale<TNamespace> };
141
+ permissions: PermissionsString[];
142
+ dbiInteraction: DBIChatInput<TNamespace>;
143
+ }) => Promise<boolean> | boolean,
144
+ options?: { once: boolean }
145
+ ): () => any;
146
+
147
+ on(
148
+ eventName: "messageCommandDirectMessageUsageError",
149
+ handler: (data: {
150
+ message: Discord.Message;
151
+ interaction: FakeMessageInteraction;
152
+ locale: { guild?: DBILocale<TNamespace>; user: DBILocale<TNamespace> };
153
+ dbiInteraction: DBIChatInput<TNamespace>;
154
+ }) => Promise<boolean> | boolean,
155
+ options?: { once: boolean }
156
+ ): () => any;
157
+
158
+ on(
159
+ eventName: TDBIEventNames,
160
+ handler: (data: any) => Promise<boolean> | boolean,
161
+ options: { once: boolean } = { once: false }
162
+ ): () => any {
163
+ if (!this.handlers.hasOwnProperty(eventName)) this.handlers[eventName] = [];
164
+ if (options.once) {
165
+ let h = (data) => {
166
+ this.off(eventName, h);
167
+ return handler(data);
168
+ };
169
+ this.on(eventName as any, h as any, { once: false });
170
+ return () => {
171
+ this.off(eventName, h);
172
+ };
173
+ } else {
174
+ this.handlers[eventName].push(handler);
175
+ return () => {
176
+ this.off(eventName, handler);
177
+ };
178
+ }
179
+ }
180
+
181
+ off(
182
+ eventName: TDBIEventNames,
183
+ handler: (data: any) => Promise<boolean> | boolean
184
+ ) {
185
+ let l = this.handlers[eventName];
186
+ if (!l) return [];
187
+ return l.splice(l.indexOf(handler), 1);
188
+ }
189
+ }