@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
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
|
+
}
|