@mostfeatured/dbi 0.1.2 → 0.1.4
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 +4 -1
- package/dist/DBI.d.ts.map +1 -1
- package/dist/DBI.js +106 -49
- package/dist/DBI.js.map +1 -1
- package/dist/Events.d.ts +6 -6
- package/dist/Events.d.ts.map +1 -1
- package/dist/Events.js +1 -1
- package/dist/Events.js.map +1 -1
- package/dist/methods/handleMessageCommands.d.ts.map +1 -1
- package/dist/methods/handleMessageCommands.js +71 -37
- package/dist/methods/handleMessageCommands.js.map +1 -1
- package/dist/methods/hookInteractionListeners.d.ts.map +1 -1
- package/dist/methods/hookInteractionListeners.js +122 -36
- package/dist/methods/hookInteractionListeners.js.map +1 -1
- package/dist/types/ChatInput/ChatInputOptions.d.ts +81 -23
- package/dist/types/ChatInput/ChatInputOptions.d.ts.map +1 -1
- package/dist/types/ChatInput/ChatInputOptions.js +28 -15
- package/dist/types/ChatInput/ChatInputOptions.js.map +1 -1
- package/package.json +1 -1
- package/src/DBI.ts +523 -170
- package/src/Events.ts +68 -21
- package/src/methods/handleMessageCommands.ts +182 -63
- package/src/methods/hookInteractionListeners.ts +155 -60
- package/src/types/ChatInput/ChatInputOptions.ts +213 -36
package/src/Events.ts
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
1
|
import { NamespaceEnums, NamespaceData } from "../generated/namespaceData";
|
|
2
2
|
import { DBI } from "./DBI";
|
|
3
3
|
import { TDBIMessageCommandArgumentErrorTypes } from "./methods/handleMessageCommands";
|
|
4
|
+
import { TDBIValueName } from "./types/ChatInput/ChatInputOptions";
|
|
4
5
|
import { ClientEvents, DBIEvent } from "./types/Event";
|
|
5
6
|
import { IDBIBaseExecuteCtx, TDBIRateLimitTypes } from "./types/Interaction";
|
|
6
7
|
import { FakeMessageInteraction } from "./types/other/FakeMessageInteraction";
|
|
7
8
|
import { DBILocale } from "./types/other/Locale";
|
|
8
9
|
import Discord from "discord.js";
|
|
9
10
|
|
|
10
|
-
export type TDBIEventNames =
|
|
11
|
+
export type TDBIEventNames =
|
|
12
|
+
| "beforeInteraction"
|
|
13
|
+
| "afterInteraction"
|
|
14
|
+
| "interactionRateLimit"
|
|
15
|
+
| "beforeEvent"
|
|
16
|
+
| "afterEvent"
|
|
17
|
+
| "interactionError"
|
|
18
|
+
| "eventError"
|
|
19
|
+
| "messageCommandArgumentError";
|
|
11
20
|
|
|
12
21
|
export type TDBIEventHandlerCtx<TNamespace extends NamespaceEnums> = {
|
|
13
|
-
[K in keyof (ClientEvents & NamespaceData[TNamespace]["customEvents"])]: {
|
|
22
|
+
[K in keyof (ClientEvents & NamespaceData[TNamespace]["customEvents"])]: {
|
|
23
|
+
other: Record<string, any>;
|
|
24
|
+
locale?: { guild: DBILocale<TNamespace> };
|
|
25
|
+
eventName: K;
|
|
26
|
+
dbiEvent: DBIEvent<TNamespace>;
|
|
27
|
+
} & (ClientEvents & NamespaceData[TNamespace]["customEvents"])[K];
|
|
14
28
|
}[keyof (ClientEvents & NamespaceData[TNamespace]["customEvents"])];
|
|
15
29
|
|
|
16
30
|
export class Events<TNamespace extends NamespaceEnums> {
|
|
@@ -26,8 +40,8 @@ export class Events<TNamespace extends NamespaceEnums> {
|
|
|
26
40
|
beforeEvent: [],
|
|
27
41
|
afterEvent: [],
|
|
28
42
|
interactionError: [],
|
|
29
|
-
eventError: []
|
|
30
|
-
}
|
|
43
|
+
eventError: [],
|
|
44
|
+
};
|
|
31
45
|
}
|
|
32
46
|
|
|
33
47
|
async trigger(name: TDBIEventNames, data: any): Promise<boolean> {
|
|
@@ -43,41 +57,71 @@ export class Events<TNamespace extends NamespaceEnums> {
|
|
|
43
57
|
|
|
44
58
|
on(
|
|
45
59
|
eventName: "beforeInteraction" | "afterInteraction",
|
|
46
|
-
handler: (
|
|
60
|
+
handler: (
|
|
61
|
+
data: IDBIBaseExecuteCtx<TNamespace>
|
|
62
|
+
) => Promise<boolean> | boolean,
|
|
47
63
|
options?: { once: boolean }
|
|
48
|
-
): (
|
|
64
|
+
): () => any;
|
|
49
65
|
|
|
50
66
|
on(
|
|
51
67
|
eventName: "interactionError",
|
|
52
|
-
handler: (
|
|
68
|
+
handler: (
|
|
69
|
+
data: IDBIBaseExecuteCtx<TNamespace> & { error: any }
|
|
70
|
+
) => Promise<boolean> | boolean,
|
|
53
71
|
options?: { once: boolean }
|
|
54
|
-
): (
|
|
72
|
+
): () => any;
|
|
55
73
|
|
|
56
74
|
on(
|
|
57
75
|
eventName: "beforeEvent" | "afterEvent",
|
|
58
|
-
handler: (
|
|
76
|
+
handler: (
|
|
77
|
+
data: TDBIEventHandlerCtx<TNamespace>
|
|
78
|
+
) => Promise<boolean> | boolean,
|
|
59
79
|
options?: { once: boolean }
|
|
60
|
-
): (
|
|
80
|
+
): () => any;
|
|
61
81
|
|
|
62
82
|
on(
|
|
63
83
|
eventName: "eventError",
|
|
64
|
-
handler: (
|
|
84
|
+
handler: (
|
|
85
|
+
data: TDBIEventHandlerCtx<TNamespace> & {
|
|
86
|
+
error: any;
|
|
87
|
+
dbiEvent: DBIEvent<TNamespace>;
|
|
88
|
+
}
|
|
89
|
+
) => Promise<boolean> | boolean,
|
|
65
90
|
options?: { once: boolean }
|
|
66
|
-
): (
|
|
91
|
+
): () => any;
|
|
67
92
|
|
|
68
93
|
on(
|
|
69
94
|
eventName: "interactionRateLimit",
|
|
70
|
-
handler: (
|
|
95
|
+
handler: (
|
|
96
|
+
data: Omit<IDBIBaseExecuteCtx<TNamespace>, "other" | "setRateLimit"> & {
|
|
97
|
+
rateLimit: { type: TDBIRateLimitTypes; duration: number; at: number };
|
|
98
|
+
}
|
|
99
|
+
) => Promise<boolean> | boolean,
|
|
71
100
|
options?: { once: boolean }
|
|
72
|
-
): (
|
|
101
|
+
): () => any;
|
|
73
102
|
|
|
74
103
|
on(
|
|
75
104
|
eventName: "messageCommandArgumentError",
|
|
76
|
-
handler: (data: {
|
|
105
|
+
handler: (data: {
|
|
106
|
+
message: Discord.Message;
|
|
107
|
+
interaction: FakeMessageInteraction;
|
|
108
|
+
error: {
|
|
109
|
+
type: TDBIMessageCommandArgumentErrorTypes;
|
|
110
|
+
option: any;
|
|
111
|
+
index: number;
|
|
112
|
+
extra?: any;
|
|
113
|
+
};
|
|
114
|
+
value: any;
|
|
115
|
+
locale: { guild?: DBILocale<TNamespace>; user: DBILocale<TNamespace> };
|
|
116
|
+
}) => Promise<boolean> | boolean,
|
|
77
117
|
options?: { once: boolean }
|
|
78
|
-
): (
|
|
118
|
+
): () => any;
|
|
79
119
|
|
|
80
|
-
on(
|
|
120
|
+
on(
|
|
121
|
+
eventName: TDBIEventNames,
|
|
122
|
+
handler: (data: any) => Promise<boolean> | boolean,
|
|
123
|
+
options: { once: boolean } = { once: false }
|
|
124
|
+
): () => any {
|
|
81
125
|
if (!this.handlers.hasOwnProperty(eventName)) this.handlers[eventName] = [];
|
|
82
126
|
if (options.once) {
|
|
83
127
|
let h = (data) => {
|
|
@@ -87,18 +131,21 @@ export class Events<TNamespace extends NamespaceEnums> {
|
|
|
87
131
|
this.on(eventName as any, h as any, { once: false });
|
|
88
132
|
return () => {
|
|
89
133
|
this.off(eventName, h);
|
|
90
|
-
}
|
|
134
|
+
};
|
|
91
135
|
} else {
|
|
92
136
|
this.handlers[eventName].push(handler);
|
|
93
137
|
return () => {
|
|
94
138
|
this.off(eventName, handler);
|
|
95
|
-
}
|
|
139
|
+
};
|
|
96
140
|
}
|
|
97
141
|
}
|
|
98
142
|
|
|
99
|
-
off(
|
|
143
|
+
off(
|
|
144
|
+
eventName: TDBIEventNames,
|
|
145
|
+
handler: (data: any) => Promise<boolean> | boolean
|
|
146
|
+
) {
|
|
100
147
|
let l = this.handlers[eventName];
|
|
101
148
|
if (!l) return [];
|
|
102
149
|
return l.splice(l.indexOf(handler), 1);
|
|
103
150
|
}
|
|
104
|
-
}
|
|
151
|
+
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ApplicationCommandType,
|
|
3
|
+
ChatInputCommandInteraction,
|
|
4
|
+
Message,
|
|
5
|
+
MessagePayload,
|
|
6
|
+
ApplicationCommandOptionType,
|
|
7
|
+
} from "discord.js";
|
|
2
8
|
import { NamespaceEnums } from "../../generated/namespaceData";
|
|
3
9
|
import { DBI } from "../DBI";
|
|
4
10
|
import { FakeMessageInteraction } from "../types/other/FakeMessageInteraction";
|
|
@@ -7,24 +13,49 @@ import { TDBILocaleString } from "../types/other/Locale";
|
|
|
7
13
|
const INTEGER_REGEX = /^-?\d+$/;
|
|
8
14
|
const NUMBER_REGEX = /^-?\d+(?:\.\d+)?$/;
|
|
9
15
|
|
|
10
|
-
export type TDBIMessageCommandArgumentErrorTypes =
|
|
16
|
+
export type TDBIMessageCommandArgumentErrorTypes =
|
|
17
|
+
| "MissingRequiredOption"
|
|
18
|
+
| "MinLength"
|
|
19
|
+
| "MaxLength"
|
|
20
|
+
| "InvalidChoice"
|
|
21
|
+
| "InvalidInteger"
|
|
22
|
+
| "MinInteger"
|
|
23
|
+
| "MaxInteger"
|
|
24
|
+
| "InvalidNumber"
|
|
25
|
+
| "MinNumber"
|
|
26
|
+
| "MaxNumber"
|
|
27
|
+
| "InvalidBoolean"
|
|
28
|
+
| "InvalidUser"
|
|
29
|
+
| "InvalidChannel"
|
|
30
|
+
| "InvalidRole"
|
|
31
|
+
| "InvalidMentionable"
|
|
32
|
+
| "InvalidCompleteChoice";
|
|
11
33
|
|
|
12
|
-
export async function handleMessageCommands(
|
|
13
|
-
|
|
34
|
+
export async function handleMessageCommands(
|
|
35
|
+
dbi: DBI<NamespaceEnums>,
|
|
36
|
+
message: Message
|
|
37
|
+
) {
|
|
38
|
+
const chatInputs = dbi.data.interactions.filter(
|
|
39
|
+
(i) => i.type === "ChatInput"
|
|
40
|
+
);
|
|
14
41
|
const prefixes = dbi.config.messageCommands.prefixes ?? [];
|
|
15
42
|
if (!prefixes.length) return;
|
|
16
43
|
const content = message.content;
|
|
17
|
-
const usedPrefix = prefixes.find(p => content.startsWith(p));
|
|
44
|
+
const usedPrefix = prefixes.find((p) => content.startsWith(p));
|
|
18
45
|
if (!usedPrefix) return;
|
|
19
46
|
const contentWithoutPrefix = content.slice(usedPrefix?.length ?? 0);
|
|
20
47
|
const contentLower = contentWithoutPrefix.toLowerCase();
|
|
21
48
|
|
|
22
|
-
let locale: string =
|
|
49
|
+
let locale: string =
|
|
50
|
+
message.guild.preferredLocale?.split("-")?.at(0) ||
|
|
51
|
+
(dbi.config.defaults.locale as any);
|
|
23
52
|
let usedAlias: string | undefined;
|
|
24
|
-
let chatInput = chatInputs.find(i => {
|
|
53
|
+
let chatInput = chatInputs.find((i) => {
|
|
25
54
|
let found = contentLower.startsWith(i.name);
|
|
26
55
|
if (found) return true;
|
|
27
|
-
let alias = i.other?.messageCommand?.aliases?.find(a =>
|
|
56
|
+
let alias = i.other?.messageCommand?.aliases?.find((a) =>
|
|
57
|
+
contentLower.startsWith(a)
|
|
58
|
+
);
|
|
28
59
|
if (alias) {
|
|
29
60
|
usedAlias = alias;
|
|
30
61
|
return true;
|
|
@@ -34,12 +65,15 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
34
65
|
let commandName = usedAlias ?? chatInput?.name;
|
|
35
66
|
|
|
36
67
|
if (!chatInput) {
|
|
37
|
-
fLoop: for (const [localeInterName, localeData] of dbi.data
|
|
38
|
-
|
|
68
|
+
fLoop: for (const [localeInterName, localeData] of dbi.data
|
|
69
|
+
.interactionLocales) {
|
|
70
|
+
for (const [localeName, translation] of Object.entries(
|
|
71
|
+
localeData.data || {}
|
|
72
|
+
)) {
|
|
39
73
|
if (contentLower.startsWith(translation.name)) {
|
|
40
74
|
commandName = translation.name;
|
|
41
75
|
locale = localeName;
|
|
42
|
-
chatInput = chatInputs.find(i => i.name === localeData.name);
|
|
76
|
+
chatInput = chatInputs.find((i) => i.name === localeData.name);
|
|
43
77
|
break fLoop;
|
|
44
78
|
}
|
|
45
79
|
}
|
|
@@ -48,7 +82,14 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
48
82
|
|
|
49
83
|
if (!chatInput) return;
|
|
50
84
|
|
|
51
|
-
const interaction = new FakeMessageInteraction(
|
|
85
|
+
const interaction = new FakeMessageInteraction(
|
|
86
|
+
dbi,
|
|
87
|
+
message,
|
|
88
|
+
chatInput as any,
|
|
89
|
+
locale,
|
|
90
|
+
commandName,
|
|
91
|
+
usedPrefix
|
|
92
|
+
);
|
|
52
93
|
|
|
53
94
|
if (chatInput.options.length) {
|
|
54
95
|
let errorType: TDBIMessageCommandArgumentErrorTypes;
|
|
@@ -66,21 +107,22 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
66
107
|
|
|
67
108
|
switch (option.type) {
|
|
68
109
|
case ApplicationCommandOptionType.String: {
|
|
69
|
-
|
|
70
110
|
if (!option.required && !value) break;
|
|
71
111
|
|
|
72
112
|
if (option.autocomplete && option.onComplete) {
|
|
73
113
|
let choices = await option.onComplete({
|
|
74
114
|
interaction,
|
|
75
|
-
value
|
|
76
|
-
});
|
|
77
|
-
if (!choices.length) choices = await option.onComplete({
|
|
78
|
-
interaction,
|
|
79
|
-
value: ""
|
|
115
|
+
value,
|
|
80
116
|
});
|
|
81
|
-
if (choices.length
|
|
117
|
+
if (!choices.length)
|
|
118
|
+
choices = await option.onComplete({
|
|
119
|
+
interaction,
|
|
120
|
+
value: "",
|
|
121
|
+
});
|
|
122
|
+
if (choices.length > 20)
|
|
123
|
+
throw new Error("Autocomplete returned more than 20 choices.");
|
|
82
124
|
lastExtra = choices;
|
|
83
|
-
if (!choices.find(c => c.name === value || c.value === value)) {
|
|
125
|
+
if (!choices.find((c) => c.name === value || c.value === value)) {
|
|
84
126
|
if (value) {
|
|
85
127
|
errorType = "InvalidCompleteChoice";
|
|
86
128
|
break;
|
|
@@ -93,10 +135,25 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
93
135
|
}
|
|
94
136
|
|
|
95
137
|
if (option.choices) {
|
|
96
|
-
const localeData = dbi.data.interactionLocales.get(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
138
|
+
const localeData = dbi.data.interactionLocales.get(
|
|
139
|
+
chatInput.name
|
|
140
|
+
)?.data;
|
|
141
|
+
const choicesLocaleData =
|
|
142
|
+
localeData?.[locale as TDBILocaleString]?.options?.[option.name]
|
|
143
|
+
?.choices;
|
|
144
|
+
if (
|
|
145
|
+
!option.choices.find(
|
|
146
|
+
(c) =>
|
|
147
|
+
c.name === value ||
|
|
148
|
+
c.value === value ||
|
|
149
|
+
(choicesLocaleData?.[c.value] &&
|
|
150
|
+
choicesLocaleData?.[c.value] === value)
|
|
151
|
+
)
|
|
152
|
+
) {
|
|
153
|
+
lastExtra = option.choices.map((c) => ({
|
|
154
|
+
name: choicesLocaleData?.[c.value] ?? c.name,
|
|
155
|
+
value: c.value,
|
|
156
|
+
}));
|
|
100
157
|
if (value) {
|
|
101
158
|
errorType = "InvalidChoice";
|
|
102
159
|
break;
|
|
@@ -108,11 +165,11 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
108
165
|
break;
|
|
109
166
|
}
|
|
110
167
|
|
|
111
|
-
if (option.minLength && value
|
|
168
|
+
if (option.minLength && value?.length < option.minLength) {
|
|
112
169
|
errorType = "MinLength";
|
|
113
170
|
break;
|
|
114
171
|
}
|
|
115
|
-
if (option.maxLength && value
|
|
172
|
+
if (option.maxLength && value?.length > option.maxLength) {
|
|
116
173
|
errorType = "MaxLength";
|
|
117
174
|
break;
|
|
118
175
|
}
|
|
@@ -127,15 +184,19 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
127
184
|
if (option.autocomplete && option.onComplete) {
|
|
128
185
|
let choices = await option.onComplete({
|
|
129
186
|
interaction,
|
|
130
|
-
value
|
|
187
|
+
value,
|
|
131
188
|
});
|
|
132
|
-
if (!choices.length)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
189
|
+
if (!choices.length)
|
|
190
|
+
choices = await option.onComplete({
|
|
191
|
+
interaction,
|
|
192
|
+
value: "",
|
|
193
|
+
});
|
|
194
|
+
if (choices.length > 20)
|
|
195
|
+
throw new Error("Autocomplete returned more than 20 choices.");
|
|
137
196
|
lastExtra = choices;
|
|
138
|
-
if (
|
|
197
|
+
if (
|
|
198
|
+
!choices.find((c) => c.value === parsedInt || c.name === value)
|
|
199
|
+
) {
|
|
139
200
|
if (value) {
|
|
140
201
|
errorType = "InvalidCompleteChoice";
|
|
141
202
|
break;
|
|
@@ -149,10 +210,25 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
149
210
|
}
|
|
150
211
|
|
|
151
212
|
if (option.choices) {
|
|
152
|
-
const localeData = dbi.data.interactionLocales.get(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
213
|
+
const localeData = dbi.data.interactionLocales.get(
|
|
214
|
+
chatInput.name
|
|
215
|
+
)?.data;
|
|
216
|
+
const choicesLocaleData =
|
|
217
|
+
localeData?.[locale as TDBILocaleString]?.options?.[option.name]
|
|
218
|
+
?.choices;
|
|
219
|
+
if (
|
|
220
|
+
!option.choices.find(
|
|
221
|
+
(c) =>
|
|
222
|
+
c.value === parsedInt ||
|
|
223
|
+
c.name === value ||
|
|
224
|
+
(choicesLocaleData?.[c.value] &&
|
|
225
|
+
choicesLocaleData?.[c.value] === value)
|
|
226
|
+
)
|
|
227
|
+
) {
|
|
228
|
+
lastExtra = option.choices.map((c) => ({
|
|
229
|
+
name: choicesLocaleData?.[c.value] ?? c.name,
|
|
230
|
+
value: c.value,
|
|
231
|
+
}));
|
|
156
232
|
if (value) {
|
|
157
233
|
errorType = "InvalidChoice";
|
|
158
234
|
break;
|
|
@@ -189,15 +265,19 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
189
265
|
if (option.autocomplete && option.onComplete) {
|
|
190
266
|
let choices = await option.onComplete({
|
|
191
267
|
interaction,
|
|
192
|
-
value
|
|
193
|
-
});
|
|
194
|
-
if (!choices.length) choices = await option.onComplete({
|
|
195
|
-
interaction,
|
|
196
|
-
value: ""
|
|
268
|
+
value,
|
|
197
269
|
});
|
|
198
|
-
if (choices.length
|
|
270
|
+
if (!choices.length)
|
|
271
|
+
choices = await option.onComplete({
|
|
272
|
+
interaction,
|
|
273
|
+
value: "",
|
|
274
|
+
});
|
|
275
|
+
if (choices.length > 20)
|
|
276
|
+
throw new Error("Autocomplete returned more than 20 choices.");
|
|
199
277
|
lastExtra = choices;
|
|
200
|
-
if (
|
|
278
|
+
if (
|
|
279
|
+
!choices.find((c) => c.value === parsedFloat || c.name === value)
|
|
280
|
+
) {
|
|
201
281
|
if (value) {
|
|
202
282
|
errorType = "InvalidCompleteChoice";
|
|
203
283
|
break;
|
|
@@ -211,10 +291,25 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
211
291
|
}
|
|
212
292
|
|
|
213
293
|
if (option.choices) {
|
|
214
|
-
const localeData = dbi.data.interactionLocales.get(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
294
|
+
const localeData = dbi.data.interactionLocales.get(
|
|
295
|
+
chatInput.name
|
|
296
|
+
)?.data;
|
|
297
|
+
const choicesLocaleData =
|
|
298
|
+
localeData?.[locale as TDBILocaleString]?.options?.[option.name]
|
|
299
|
+
?.choices;
|
|
300
|
+
if (
|
|
301
|
+
!option.choices.find(
|
|
302
|
+
(c) =>
|
|
303
|
+
c.value === parsedFloat ||
|
|
304
|
+
c.name === value ||
|
|
305
|
+
(choicesLocaleData?.[c.value] &&
|
|
306
|
+
choicesLocaleData?.[c.value] === value)
|
|
307
|
+
)
|
|
308
|
+
) {
|
|
309
|
+
lastExtra = option.choices.map((c) => ({
|
|
310
|
+
name: choicesLocaleData?.[c.value] ?? c.name,
|
|
311
|
+
value: c.value,
|
|
312
|
+
}));
|
|
218
313
|
if (value) {
|
|
219
314
|
errorType = "InvalidChoice";
|
|
220
315
|
break;
|
|
@@ -243,15 +338,19 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
243
338
|
break;
|
|
244
339
|
}
|
|
245
340
|
case ApplicationCommandOptionType.Boolean: {
|
|
246
|
-
let boolKeys = Object.keys(
|
|
247
|
-
|
|
341
|
+
let boolKeys = Object.keys(
|
|
342
|
+
dbi.config.messageCommands.typeAliases.booleans
|
|
343
|
+
);
|
|
344
|
+
if (option.required && !boolKeys.includes(value?.toLowerCase?.())) {
|
|
248
345
|
errorType = "InvalidBoolean";
|
|
249
346
|
break;
|
|
250
347
|
}
|
|
251
348
|
break;
|
|
252
349
|
}
|
|
253
350
|
case ApplicationCommandOptionType.User: {
|
|
254
|
-
await message.client.users
|
|
351
|
+
await message.client.users
|
|
352
|
+
.fetch(interaction.options.getUserId(option.name))
|
|
353
|
+
.catch(() => {});
|
|
255
354
|
if (option.required && !interaction.options.getUser(option.name)) {
|
|
256
355
|
errorType = "InvalidUser";
|
|
257
356
|
break;
|
|
@@ -259,15 +358,26 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
259
358
|
break;
|
|
260
359
|
}
|
|
261
360
|
case ApplicationCommandOptionType.Channel: {
|
|
262
|
-
await message.client.channels
|
|
263
|
-
|
|
361
|
+
await message.client.channels
|
|
362
|
+
.fetch(interaction.options.getChannelId(option.name))
|
|
363
|
+
.catch(() => {});
|
|
364
|
+
if (
|
|
365
|
+
option.required &&
|
|
366
|
+
!interaction.options.getChannel(
|
|
367
|
+
option.name,
|
|
368
|
+
null,
|
|
369
|
+
option.channelTypes
|
|
370
|
+
)
|
|
371
|
+
) {
|
|
264
372
|
errorType = "InvalidChannel";
|
|
265
373
|
break;
|
|
266
374
|
}
|
|
267
375
|
break;
|
|
268
376
|
}
|
|
269
377
|
case ApplicationCommandOptionType.Role: {
|
|
270
|
-
await message.guild.roles
|
|
378
|
+
await message.guild.roles
|
|
379
|
+
.fetch(interaction.options.getRoleId(option.name))
|
|
380
|
+
.catch(() => {});
|
|
271
381
|
if (option.required && !interaction.options.getRole(option.name)) {
|
|
272
382
|
errorType = "InvalidRole";
|
|
273
383
|
break;
|
|
@@ -276,10 +386,13 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
276
386
|
}
|
|
277
387
|
case ApplicationCommandOptionType.Mentionable: {
|
|
278
388
|
let mentionableId = interaction.options.getMentionableId(option.name);
|
|
279
|
-
await message.guild.roles.fetch(mentionableId).catch(() => {
|
|
280
|
-
await message.client.channels.fetch(mentionableId).catch(() => {
|
|
281
|
-
await message.client.users.fetch(mentionableId).catch(() => {
|
|
282
|
-
if (
|
|
389
|
+
await message.guild.roles.fetch(mentionableId).catch(() => {});
|
|
390
|
+
await message.client.channels.fetch(mentionableId).catch(() => {});
|
|
391
|
+
await message.client.users.fetch(mentionableId).catch(() => {});
|
|
392
|
+
if (
|
|
393
|
+
option.required &&
|
|
394
|
+
!interaction.options.getMentionable(option.name)
|
|
395
|
+
) {
|
|
283
396
|
errorType = "InvalidMentionable";
|
|
284
397
|
break;
|
|
285
398
|
}
|
|
@@ -308,16 +421,22 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
308
421
|
interaction,
|
|
309
422
|
message,
|
|
310
423
|
locale: {
|
|
311
|
-
user:
|
|
312
|
-
|
|
424
|
+
user:
|
|
425
|
+
dbi.data.locales.get(interaction.locale) ||
|
|
426
|
+
dbi.data.locales.get(dbi.config.defaults.locale),
|
|
427
|
+
guild: message.guild?.preferredLocale
|
|
428
|
+
? dbi.data.locales.get(
|
|
429
|
+
message.guild?.preferredLocale?.split("-")?.at(0)
|
|
430
|
+
) || dbi.data.locales.get(dbi.config.defaults.locale)
|
|
431
|
+
: null,
|
|
313
432
|
},
|
|
314
433
|
error: {
|
|
315
434
|
type: errorType,
|
|
316
435
|
option: lastOption,
|
|
317
436
|
extra: lastExtra,
|
|
318
|
-
index: lastIndex
|
|
437
|
+
index: lastIndex,
|
|
319
438
|
},
|
|
320
|
-
value: lastValue
|
|
439
|
+
value: lastValue,
|
|
321
440
|
});
|
|
322
441
|
if (!res) return;
|
|
323
442
|
}
|
|
@@ -325,4 +444,4 @@ export async function handleMessageCommands(dbi: DBI<NamespaceEnums>, message: M
|
|
|
325
444
|
|
|
326
445
|
interaction.init();
|
|
327
446
|
dbi.data.clients.first().client.emit("interactionCreate", interaction as any);
|
|
328
|
-
}
|
|
447
|
+
}
|