@mostfeatured/dbi 0.1.29 → 0.1.30
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.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.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 +6 -6
- 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,408 +1,408 @@
|
|
|
1
|
-
import { Message, MessagePayload, ApplicationCommandType, ChatInputCommandInteraction, Locale, APIInteractionGuildMember, GuildMember, PermissionsBitField, CacheType, CommandInteractionOptionResolver, CommandOptionDataTypeResolvable, ApplicationCommandOptionType, User, Attachment, InteractionEditReplyOptions, InteractionReplyOptions } from 'discord.js';
|
|
2
|
-
import { TDBIInteractions } from '../Interaction';
|
|
3
|
-
import { plsParseArgs } from "plsargs";
|
|
4
|
-
import { DBI } from '../../DBI';
|
|
5
|
-
import { NamespaceEnums } from "../../../generated/namespaceData";
|
|
6
|
-
import { ChannelType } from "discord-api-types/v10";
|
|
7
|
-
|
|
8
|
-
export class FakeMessageInteraction /* implements ChatInputCommandInteraction */ {
|
|
9
|
-
channelId: string;
|
|
10
|
-
commandName: string;
|
|
11
|
-
appPermissions: any;
|
|
12
|
-
applicationId: string;
|
|
13
|
-
channel: any;
|
|
14
|
-
command: any;
|
|
15
|
-
commandGuildId: string;
|
|
16
|
-
commandId: any;
|
|
17
|
-
commandType: ApplicationCommandType.ChatInput;
|
|
18
|
-
// awaitModalSubmit: (...arr: any[]) => any;
|
|
19
|
-
// fetchReply: () => Promise<any>;
|
|
20
|
-
deferred: boolean = false;
|
|
21
|
-
client: any;
|
|
22
|
-
createdAt: Date;
|
|
23
|
-
ephemeral: boolean = false;
|
|
24
|
-
createdTimestamp: number;
|
|
25
|
-
guild: any;
|
|
26
|
-
guildId: string;
|
|
27
|
-
guildLocale: Locale;
|
|
28
|
-
id: string;
|
|
29
|
-
user: User;
|
|
30
|
-
private repliedMessage: Message | undefined;
|
|
31
|
-
private lastFollowUp: Message | undefined;
|
|
32
|
-
member: GuildMember | APIInteractionGuildMember;
|
|
33
|
-
memberPermissions: Readonly<PermissionsBitField>;
|
|
34
|
-
parsedArgs = new Map<string, FakeMessageInteractionArgument>();
|
|
35
|
-
args: import("plsargs/src/Result").Result;
|
|
36
|
-
usedCommandName: string;
|
|
37
|
-
fullCommandName: string;
|
|
38
|
-
options: any;
|
|
39
|
-
dbiChatInput: TDBIInteractions<NamespaceEnums>;
|
|
40
|
-
dbiChatInputOptions: any[];
|
|
41
|
-
fake: boolean = true;
|
|
42
|
-
_hoistedOptions: any;
|
|
43
|
-
_initialized: boolean = false;
|
|
44
|
-
_lastAction: string | undefined;
|
|
45
|
-
|
|
46
|
-
constructor(public dbi: DBI<NamespaceEnums>, public message: Message, chatInput: TDBIInteractions<NamespaceEnums>, public locale: string, commandName: string, public usedPrefix: string) {
|
|
47
|
-
const self = this;
|
|
48
|
-
|
|
49
|
-
this.channelId = message.channel.id;
|
|
50
|
-
this.commandName = chatInput.name.split(" ").at(0);
|
|
51
|
-
this.appPermissions = message.guild?.members.me.permissionsIn(message.channel as any) ?? new PermissionsBitField(8n);
|
|
52
|
-
this.applicationId = message.client.user.id;
|
|
53
|
-
this.channel = message.channel as any;
|
|
54
|
-
this.commandGuildId = message.guild.id;
|
|
55
|
-
this.commandType = ApplicationCommandType.ChatInput;
|
|
56
|
-
|
|
57
|
-
this.client = message.client;
|
|
58
|
-
this.createdAt = message.createdAt;
|
|
59
|
-
this.createdTimestamp = message.createdTimestamp;
|
|
60
|
-
this.guild = message.guild;
|
|
61
|
-
this.guildId = message.guild?.id;
|
|
62
|
-
this.guildLocale = message.guild?.preferredLocale;
|
|
63
|
-
this.id = message.guild?.commands.cache.find((cmd) => cmd.name === this.commandName)?.id ?? message.client.application.commands.cache.find((cmd) => cmd.name === this.commandName)?.id ?? "-1";
|
|
64
|
-
this.locale = message.guild?.preferredLocale;
|
|
65
|
-
this.member = message.member;
|
|
66
|
-
this.memberPermissions = message.member?.permissions;
|
|
67
|
-
this.user = message.author;
|
|
68
|
-
|
|
69
|
-
this.usedCommandName = commandName;
|
|
70
|
-
this.fullCommandName = chatInput.name;
|
|
71
|
-
this.dbiChatInput = chatInput;
|
|
72
|
-
this.dbiChatInputOptions = chatInput.options ? chatInput.options.map(i => ({ ...i })) : [];
|
|
73
|
-
|
|
74
|
-
{
|
|
75
|
-
const argContent = message.content.slice(usedPrefix.length + commandName.length).replace(/ +/, " ").trim();
|
|
76
|
-
const args = plsParseArgs(argContent);
|
|
77
|
-
|
|
78
|
-
this.args = args;
|
|
79
|
-
|
|
80
|
-
const options = chatInput.options ?? [];
|
|
81
|
-
const atchs = [...message.attachments.values()];
|
|
82
|
-
for (let i = 0, attachmentIndex = 0, namedValueSize = 0; i < options.length; i++) {
|
|
83
|
-
const option = options[i];
|
|
84
|
-
if (!option) break;
|
|
85
|
-
if (option.type === ApplicationCommandOptionType.Attachment) {
|
|
86
|
-
this.parsedArgs.set(option.name, {
|
|
87
|
-
name: option.name,
|
|
88
|
-
type: option.type,
|
|
89
|
-
value: atchs.at(attachmentIndex)?.url,
|
|
90
|
-
attachment: atchs.at(attachmentIndex++)
|
|
91
|
-
})
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
const value = option.messageCommands?.rest ? args._.slice(i).join(" ") : (args.get(option.name) ?? args.get(i - attachmentIndex - namedValueSize));
|
|
95
|
-
if (args.has(option.name)) namedValueSize++;
|
|
96
|
-
|
|
97
|
-
const interactionChoicesLocale = this.dbi.data.interactionLocales.get(self.dbiChatInput.name)?.data?.[locale]?.options[option.name]?.choices;
|
|
98
|
-
|
|
99
|
-
const localizedChoices = option.choices?.length ? option.choices.map(choice => ({
|
|
100
|
-
...choice,
|
|
101
|
-
name: interactionChoicesLocale?.[choice.value] ?? choice.name
|
|
102
|
-
})) : option._choices;
|
|
103
|
-
|
|
104
|
-
this.parsedArgs.set(option.name, {
|
|
105
|
-
name: option.name,
|
|
106
|
-
type: option.type,
|
|
107
|
-
value:
|
|
108
|
-
localizedChoices?.find(c => c.value === value || c.name === value)?.value ??
|
|
109
|
-
option.choices?.find(c => c.value === value || c.name === value)?.value ??
|
|
110
|
-
value
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
this.options = {
|
|
116
|
-
get(name: string) {
|
|
117
|
-
const rawValue = self.getRawOptionValue(name);
|
|
118
|
-
if (!rawValue) return null;
|
|
119
|
-
return {
|
|
120
|
-
value: rawValue,
|
|
121
|
-
get boolean() { return self.options.getBoolean(name); },
|
|
122
|
-
get channel() { return self.options.getChannel(name); },
|
|
123
|
-
get string() { return self.options.getString(name); },
|
|
124
|
-
get integer() { return self.options.getInteger(name); },
|
|
125
|
-
get number() { return self.options.getNumber(name); },
|
|
126
|
-
get user() { return self.options.getUser(name); },
|
|
127
|
-
get member() { return self.options.getMember(name); },
|
|
128
|
-
get role() { return self.options.getRole(name); },
|
|
129
|
-
get mentionable() { return self.options.getMentionable(name); },
|
|
130
|
-
get attachment() { return self.options.getAttachment(name); }
|
|
131
|
-
};
|
|
132
|
-
},
|
|
133
|
-
get _hoistedOptions() {
|
|
134
|
-
return self._hoistedOptions;
|
|
135
|
-
},
|
|
136
|
-
getSubcommand() {
|
|
137
|
-
let splitted = self.fullCommandName.split(" ");
|
|
138
|
-
if (splitted.length === 1) return null;
|
|
139
|
-
return splitted.at(-1);
|
|
140
|
-
},
|
|
141
|
-
getSubcommandGroup() {
|
|
142
|
-
let splitted = self.fullCommandName.split(" ");
|
|
143
|
-
if (splitted.length === 3) return splitted[1];
|
|
144
|
-
return null;
|
|
145
|
-
},
|
|
146
|
-
getBoolean(name: string) {
|
|
147
|
-
const rawValue = self.getRawOptionValue(name);
|
|
148
|
-
if (!rawValue) return null;
|
|
149
|
-
return !!self.dbi.config.messageCommands.typeAliases.booleans[rawValue.toLowerCase()];
|
|
150
|
-
},
|
|
151
|
-
getChannel(name: string, _: any, channelType?: ChannelType | ChannelType[]) {
|
|
152
|
-
const rawValue = self.getRawOptionValue(name);
|
|
153
|
-
if (!rawValue) return null;
|
|
154
|
-
let value = rawValue.replace(/<#|>/g, "");
|
|
155
|
-
let channel = self.message.client.channels.cache.get(value);
|
|
156
|
-
if (!channel) channel = self.message.client.channels.cache.find(c => {
|
|
157
|
-
if (self.guildId && (c as any).guildId && (c as any).guildId !== self.guildId) return false;
|
|
158
|
-
return (c as any).name === value;
|
|
159
|
-
});
|
|
160
|
-
// @ts-ignore
|
|
161
|
-
if (channelType && channel?.type !== channelType && !channelType?.includes?.(channel?.type)) return null;
|
|
162
|
-
return channel;
|
|
163
|
-
},
|
|
164
|
-
getString(name: string) {
|
|
165
|
-
const dbiOption = self.getClonedDBIOption(name);
|
|
166
|
-
let rawValue = `${self.getRawOptionValue(name)}`;
|
|
167
|
-
let choices = dbiOption.choices ?? dbiOption._choices;
|
|
168
|
-
if (choices) return choices.find(c => c.value === rawValue || c.name === rawValue)?.value ?? rawValue;
|
|
169
|
-
return rawValue;
|
|
170
|
-
},
|
|
171
|
-
getInteger(name: string) {
|
|
172
|
-
const dbiOption = self.getClonedDBIOption(name);
|
|
173
|
-
let rawValue = self.getRawOptionValue(name);
|
|
174
|
-
let parsedValue = parseInt(rawValue);
|
|
175
|
-
let choices = dbiOption.choices ?? dbiOption._choices;
|
|
176
|
-
if (choices) return choices.find(c => c.value === parsedValue || c.name === rawValue)?.value ?? rawValue;
|
|
177
|
-
return rawValue;
|
|
178
|
-
},
|
|
179
|
-
getNumber(name: string) {
|
|
180
|
-
const dbiOption = self.getClonedDBIOption(name);
|
|
181
|
-
let rawValue = self.getRawOptionValue(name);
|
|
182
|
-
let parsedValue = parseFloat(rawValue);
|
|
183
|
-
let choices = dbiOption.choices ?? dbiOption._choices;
|
|
184
|
-
if (choices) return choices.find(c => c.value === parsedValue || c.name === rawValue)?.value ?? rawValue;
|
|
185
|
-
return rawValue;
|
|
186
|
-
},
|
|
187
|
-
getUser(name: string) {
|
|
188
|
-
const rawValue = self.getRawOptionValue(name);
|
|
189
|
-
if (!rawValue) return null;
|
|
190
|
-
let value = rawValue.replace(/<@!?|>/g, "");
|
|
191
|
-
let user = self.message.client.users.cache.get(value);
|
|
192
|
-
if (!user) user = self.message.client.users.cache.find(u => u.username === value || u.tag === value);
|
|
193
|
-
return user;
|
|
194
|
-
},
|
|
195
|
-
getUserId(name: string) {
|
|
196
|
-
const rawValue = self.getRawOptionValue(name);
|
|
197
|
-
if (!rawValue) return null;
|
|
198
|
-
return rawValue.replace(/<@!?|>/g, "");
|
|
199
|
-
},
|
|
200
|
-
getMember(name: string) {
|
|
201
|
-
const rawValue = self.getRawOptionValue(name);
|
|
202
|
-
if (!rawValue) return null;
|
|
203
|
-
let value = rawValue.replace(/<@!?|>/g, "");
|
|
204
|
-
let member = self.message.guild?.members.cache.get(value);
|
|
205
|
-
if (!member) member = self.message.guild?.members.cache.find(m => m.user.username === value || m.user.tag === value);
|
|
206
|
-
return member;
|
|
207
|
-
},
|
|
208
|
-
getMemberId(name: string) {
|
|
209
|
-
const rawValue = self.getRawOptionValue(name);
|
|
210
|
-
if (!rawValue) return null;
|
|
211
|
-
return rawValue.replace(/<@!?|>/g, "");
|
|
212
|
-
},
|
|
213
|
-
getRole(name: string) {
|
|
214
|
-
const rawValue = self.getRawOptionValue(name);
|
|
215
|
-
if (!rawValue) return null;
|
|
216
|
-
let value = rawValue.replace(/<@&|>/g, "");
|
|
217
|
-
let role = self.message.guild?.roles.cache.get(value);
|
|
218
|
-
if (!role) role = self.message.guild?.roles.cache.find(r => r.name === value);
|
|
219
|
-
return role;
|
|
220
|
-
},
|
|
221
|
-
getRoleId(name: string) {
|
|
222
|
-
const rawValue = self.getRawOptionValue(name);
|
|
223
|
-
if (!rawValue) return null;
|
|
224
|
-
return rawValue.replace(/<@&|>/g, "");
|
|
225
|
-
},
|
|
226
|
-
getMentionable(name: string) {
|
|
227
|
-
const rawValue = self.getRawOptionValue(name);
|
|
228
|
-
if (!rawValue) return null;
|
|
229
|
-
let value = rawValue.replace(/<(@|#)(!|&)?|>/g, "");
|
|
230
|
-
let user = self.message.client.users.cache.get(value);
|
|
231
|
-
if (!user) user = self.message.client.users.cache.find(u => u.username === value || u.tag === value);
|
|
232
|
-
if (user) return user;
|
|
233
|
-
let member = self.message.guild?.members.cache.get(value);
|
|
234
|
-
if (!member) member = self.message.guild?.members.cache.find(m => m.user.username === value || m.user.tag === value);
|
|
235
|
-
if (member) return member;
|
|
236
|
-
let role = self.message.guild?.roles.cache.get(value);
|
|
237
|
-
if (!role) role = self.message.guild?.roles.cache.find(r => r.name === value);
|
|
238
|
-
if (role) return role;
|
|
239
|
-
return null;
|
|
240
|
-
},
|
|
241
|
-
getMentionableId(name: string) {
|
|
242
|
-
const rawValue = self.getRawOptionValue(name);
|
|
243
|
-
if (!rawValue) return null;
|
|
244
|
-
return rawValue.replace(/<@(!|&)?|>/g, "");
|
|
245
|
-
},
|
|
246
|
-
getMessage() {
|
|
247
|
-
return self.message;
|
|
248
|
-
},
|
|
249
|
-
getAttachment(name: string) {
|
|
250
|
-
let d = self.parsedArgs.get(name);
|
|
251
|
-
return d?.attachment ?? null;
|
|
252
|
-
},
|
|
253
|
-
getChannelId(name: string) {
|
|
254
|
-
const rawValue = self.getRawOptionValue(name);
|
|
255
|
-
if (!rawValue) return null;
|
|
256
|
-
let value = rawValue.replace(/<#|>/g, "");
|
|
257
|
-
return value;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
init() {
|
|
263
|
-
if (this._initialized) return;
|
|
264
|
-
this._initialized = true;
|
|
265
|
-
this._hoistedOptionsInit();
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
_hoistedOptionsInit() {
|
|
269
|
-
this._hoistedOptions = [...this.parsedArgs.values()].map(arg => {
|
|
270
|
-
switch (arg.type) {
|
|
271
|
-
case ApplicationCommandOptionType.String: {
|
|
272
|
-
return { ...this.options.get(arg.name), value: this.options.getString(arg.name) };
|
|
273
|
-
}
|
|
274
|
-
case ApplicationCommandOptionType.Integer: {
|
|
275
|
-
return { ...this.options.get(arg.name), value: this.options.getInteger(arg.name) };
|
|
276
|
-
}
|
|
277
|
-
case ApplicationCommandOptionType.Number: {
|
|
278
|
-
return { ...this.options.get(arg.name), value: this.options.getNumber(arg.name) };
|
|
279
|
-
}
|
|
280
|
-
case ApplicationCommandOptionType.Boolean: {
|
|
281
|
-
return { ...this.options.get(arg.name), value: this.options.getBoolean(arg.name) };
|
|
282
|
-
}
|
|
283
|
-
case ApplicationCommandOptionType.User: {
|
|
284
|
-
return { ...this.options.get(arg.name), value: this.options.getUser(arg.name)?.id };
|
|
285
|
-
}
|
|
286
|
-
case ApplicationCommandOptionType.Channel: {
|
|
287
|
-
return { ...this.options.get(arg.name), value: this.options.getChannel(arg.name)?.id };
|
|
288
|
-
}
|
|
289
|
-
case ApplicationCommandOptionType.Role: {
|
|
290
|
-
return { ...this.options.get(arg.name), value: this.options.getRole(arg.name)?.id };
|
|
291
|
-
}
|
|
292
|
-
case ApplicationCommandOptionType.Mentionable: {
|
|
293
|
-
return { ...this.options.get(arg.name), value: this.options.getMentionable(arg.name)?.id };
|
|
294
|
-
}
|
|
295
|
-
case ApplicationCommandOptionType.Attachment: {
|
|
296
|
-
return { ...this.options.get(arg.name), value: this.options.getAttachment(arg.name)?.url };
|
|
297
|
-
}
|
|
298
|
-
case ApplicationCommandOptionType.Subcommand: {
|
|
299
|
-
return { ...this.options.get(arg.name), value: this.options.getSubcommand() };
|
|
300
|
-
}
|
|
301
|
-
case ApplicationCommandOptionType.SubcommandGroup: {
|
|
302
|
-
return { ...this.options.get(arg.name), value: this.options.getSubcommandGroup() };
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
private getRawOptionValue(name: string): any {
|
|
309
|
-
return this.parsedArgs.get(name)?.value;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
private getClonedDBIOption(name: string): any {
|
|
313
|
-
return this.dbiChatInputOptions.find(o => o.name === name);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
inGuild() {
|
|
317
|
-
return true;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
async deferReply(options: any): Promise<any> {
|
|
321
|
-
if (this.repliedMessage) throw new Error("Already deferred reply.");
|
|
322
|
-
this.repliedMessage = await this.message.reply(options?.content ?? (await this.dbi.config.defaults.messageCommands.deferReplyContent({
|
|
323
|
-
// @ts-ignore
|
|
324
|
-
dbiInteraction: this.dbiChatInput,
|
|
325
|
-
interaction: this,
|
|
326
|
-
locale: {
|
|
327
|
-
user: this.dbi.data.locales.get(this.locale) ||
|
|
328
|
-
this.dbi.data.locales.get(this.dbi.config.defaults.locale.name),
|
|
329
|
-
guild: this.message.guild?.preferredLocale
|
|
330
|
-
? this.dbi.data.locales.get(
|
|
331
|
-
this.message.guild?.preferredLocale?.split("-")?.at(0)
|
|
332
|
-
) || this.dbi.data.locales.get(this.dbi.config.defaults.locale.name)
|
|
333
|
-
: null,
|
|
334
|
-
}
|
|
335
|
-
})));
|
|
336
|
-
this.deferred = true;
|
|
337
|
-
this._lastAction = "deferReply";
|
|
338
|
-
return this.repliedMessage;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
async deleteReply() {
|
|
342
|
-
if (!this.repliedMessage) throw new Error("No deferred reply.");
|
|
343
|
-
await this.repliedMessage.delete();
|
|
344
|
-
this.repliedMessage = undefined;
|
|
345
|
-
this._lastAction = "deleteReply";
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
async followUp(content: string | MessagePayload) {
|
|
349
|
-
if (!this.repliedMessage) throw new Error("No deferred reply.");
|
|
350
|
-
if (!this.lastFollowUp) {
|
|
351
|
-
this.lastFollowUp = await this.repliedMessage.reply(content);
|
|
352
|
-
} else {
|
|
353
|
-
this.lastFollowUp = await this.lastFollowUp.reply(content);
|
|
354
|
-
}
|
|
355
|
-
this._lastAction = "followUp";
|
|
356
|
-
return this.lastFollowUp;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
async editReply(content: string | MessagePayload | InteractionEditReplyOptions) {
|
|
360
|
-
if (!this.repliedMessage) throw new Error("No deferred reply.");
|
|
361
|
-
if (typeof content !== "string" && this._lastAction === "deferReply" && typeof (content as any).content === "undefined") {
|
|
362
|
-
(content as any).content = null;
|
|
363
|
-
}
|
|
364
|
-
await this.repliedMessage.edit(content);
|
|
365
|
-
this._lastAction = "editReply";
|
|
366
|
-
return this.repliedMessage;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
async reply(content: string | MessagePayload | InteractionReplyOptions): Promise<any> {
|
|
370
|
-
if (this.repliedMessage) throw new Error("Already deferred reply.");
|
|
371
|
-
this.repliedMessage = await this.message.reply(content as any);
|
|
372
|
-
this._lastAction = "reply";
|
|
373
|
-
return this.repliedMessage;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
async awaitModalSubmit() {
|
|
377
|
-
throw new Error("Method not implemented.");
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
async fetchReply() {
|
|
381
|
-
return this.repliedMessage?.id && await this.message.channel.messages.fetch(this.repliedMessage.id);
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
isAnySelectMenu() { return false; }
|
|
385
|
-
isAutocomplete() { return false; }
|
|
386
|
-
isButton() { return false; }
|
|
387
|
-
isChannelSelectMenu() { return false; }
|
|
388
|
-
isChatInputCommand() { return true; }
|
|
389
|
-
isCommand() { return true; }
|
|
390
|
-
isContextMenuCommand() { return false; }
|
|
391
|
-
isMentionableSelectMenu() { return false; }
|
|
392
|
-
isMessageComponent() { return false; }
|
|
393
|
-
isMessageContextMenuCommand() { return false; }
|
|
394
|
-
isModalSubmit() { return false; }
|
|
395
|
-
isRepliable() { return true; }
|
|
396
|
-
isRoleSelectMenu() { return false; }
|
|
397
|
-
isStringSelectMenu() { return false; }
|
|
398
|
-
isUserContextMenuCommand() { return false; }
|
|
399
|
-
isUserSelectMenu() { return false; }
|
|
400
|
-
isSelectMenu() { return false; }
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
interface FakeMessageInteractionArgument {
|
|
404
|
-
type: ApplicationCommandOptionType,
|
|
405
|
-
value: any,
|
|
406
|
-
attachment?: Attachment,
|
|
407
|
-
name: string
|
|
1
|
+
import { Message, MessagePayload, ApplicationCommandType, ChatInputCommandInteraction, Locale, APIInteractionGuildMember, GuildMember, PermissionsBitField, CacheType, CommandInteractionOptionResolver, CommandOptionDataTypeResolvable, ApplicationCommandOptionType, User, Attachment, InteractionEditReplyOptions, InteractionReplyOptions } from 'discord.js';
|
|
2
|
+
import { TDBIInteractions } from '../Interaction';
|
|
3
|
+
import { plsParseArgs } from "plsargs";
|
|
4
|
+
import { DBI } from '../../DBI';
|
|
5
|
+
import { NamespaceEnums } from "../../../generated/namespaceData";
|
|
6
|
+
import { ChannelType } from "discord-api-types/v10";
|
|
7
|
+
|
|
8
|
+
export class FakeMessageInteraction /* implements ChatInputCommandInteraction */ {
|
|
9
|
+
channelId: string;
|
|
10
|
+
commandName: string;
|
|
11
|
+
appPermissions: any;
|
|
12
|
+
applicationId: string;
|
|
13
|
+
channel: any;
|
|
14
|
+
command: any;
|
|
15
|
+
commandGuildId: string;
|
|
16
|
+
commandId: any;
|
|
17
|
+
commandType: ApplicationCommandType.ChatInput;
|
|
18
|
+
// awaitModalSubmit: (...arr: any[]) => any;
|
|
19
|
+
// fetchReply: () => Promise<any>;
|
|
20
|
+
deferred: boolean = false;
|
|
21
|
+
client: any;
|
|
22
|
+
createdAt: Date;
|
|
23
|
+
ephemeral: boolean = false;
|
|
24
|
+
createdTimestamp: number;
|
|
25
|
+
guild: any;
|
|
26
|
+
guildId: string;
|
|
27
|
+
guildLocale: Locale;
|
|
28
|
+
id: string;
|
|
29
|
+
user: User;
|
|
30
|
+
private repliedMessage: Message | undefined;
|
|
31
|
+
private lastFollowUp: Message | undefined;
|
|
32
|
+
member: GuildMember | APIInteractionGuildMember;
|
|
33
|
+
memberPermissions: Readonly<PermissionsBitField>;
|
|
34
|
+
parsedArgs = new Map<string, FakeMessageInteractionArgument>();
|
|
35
|
+
args: import("plsargs/src/Result").Result;
|
|
36
|
+
usedCommandName: string;
|
|
37
|
+
fullCommandName: string;
|
|
38
|
+
options: any;
|
|
39
|
+
dbiChatInput: TDBIInteractions<NamespaceEnums>;
|
|
40
|
+
dbiChatInputOptions: any[];
|
|
41
|
+
fake: boolean = true;
|
|
42
|
+
_hoistedOptions: any;
|
|
43
|
+
_initialized: boolean = false;
|
|
44
|
+
_lastAction: string | undefined;
|
|
45
|
+
|
|
46
|
+
constructor(public dbi: DBI<NamespaceEnums>, public message: Message, chatInput: TDBIInteractions<NamespaceEnums>, public locale: string, commandName: string, public usedPrefix: string) {
|
|
47
|
+
const self = this;
|
|
48
|
+
|
|
49
|
+
this.channelId = message.channel.id;
|
|
50
|
+
this.commandName = chatInput.name.split(" ").at(0);
|
|
51
|
+
this.appPermissions = message.guild?.members.me.permissionsIn(message.channel as any) ?? new PermissionsBitField(8n);
|
|
52
|
+
this.applicationId = message.client.user.id;
|
|
53
|
+
this.channel = message.channel as any;
|
|
54
|
+
this.commandGuildId = message.guild.id;
|
|
55
|
+
this.commandType = ApplicationCommandType.ChatInput;
|
|
56
|
+
|
|
57
|
+
this.client = message.client;
|
|
58
|
+
this.createdAt = message.createdAt;
|
|
59
|
+
this.createdTimestamp = message.createdTimestamp;
|
|
60
|
+
this.guild = message.guild;
|
|
61
|
+
this.guildId = message.guild?.id;
|
|
62
|
+
this.guildLocale = message.guild?.preferredLocale;
|
|
63
|
+
this.id = message.guild?.commands.cache.find((cmd) => cmd.name === this.commandName)?.id ?? message.client.application.commands.cache.find((cmd) => cmd.name === this.commandName)?.id ?? "-1";
|
|
64
|
+
this.locale = message.guild?.preferredLocale;
|
|
65
|
+
this.member = message.member;
|
|
66
|
+
this.memberPermissions = message.member?.permissions;
|
|
67
|
+
this.user = message.author;
|
|
68
|
+
|
|
69
|
+
this.usedCommandName = commandName;
|
|
70
|
+
this.fullCommandName = chatInput.name;
|
|
71
|
+
this.dbiChatInput = chatInput;
|
|
72
|
+
this.dbiChatInputOptions = chatInput.options ? chatInput.options.map(i => ({ ...i })) : [];
|
|
73
|
+
|
|
74
|
+
{
|
|
75
|
+
const argContent = message.content.slice(usedPrefix.length + commandName.length).replace(/ +/, " ").trim();
|
|
76
|
+
const args = plsParseArgs(argContent);
|
|
77
|
+
|
|
78
|
+
this.args = args;
|
|
79
|
+
|
|
80
|
+
const options = chatInput.options ?? [];
|
|
81
|
+
const atchs = [...message.attachments.values()];
|
|
82
|
+
for (let i = 0, attachmentIndex = 0, namedValueSize = 0; i < options.length; i++) {
|
|
83
|
+
const option = options[i];
|
|
84
|
+
if (!option) break;
|
|
85
|
+
if (option.type === ApplicationCommandOptionType.Attachment) {
|
|
86
|
+
this.parsedArgs.set(option.name, {
|
|
87
|
+
name: option.name,
|
|
88
|
+
type: option.type,
|
|
89
|
+
value: atchs.at(attachmentIndex)?.url,
|
|
90
|
+
attachment: atchs.at(attachmentIndex++)
|
|
91
|
+
})
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const value = option.messageCommands?.rest ? args._.slice(i).join(" ") : (args.get(option.name) ?? args.get(i - attachmentIndex - namedValueSize));
|
|
95
|
+
if (args.has(option.name)) namedValueSize++;
|
|
96
|
+
|
|
97
|
+
const interactionChoicesLocale = this.dbi.data.interactionLocales.get(self.dbiChatInput.name)?.data?.[locale]?.options[option.name]?.choices;
|
|
98
|
+
|
|
99
|
+
const localizedChoices = option.choices?.length ? option.choices.map(choice => ({
|
|
100
|
+
...choice,
|
|
101
|
+
name: interactionChoicesLocale?.[choice.value] ?? choice.name
|
|
102
|
+
})) : option._choices;
|
|
103
|
+
|
|
104
|
+
this.parsedArgs.set(option.name, {
|
|
105
|
+
name: option.name,
|
|
106
|
+
type: option.type,
|
|
107
|
+
value:
|
|
108
|
+
localizedChoices?.find(c => c.value === value || c.name === value)?.value ??
|
|
109
|
+
option.choices?.find(c => c.value === value || c.name === value)?.value ??
|
|
110
|
+
value
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
this.options = {
|
|
116
|
+
get(name: string) {
|
|
117
|
+
const rawValue = self.getRawOptionValue(name);
|
|
118
|
+
if (!rawValue) return null;
|
|
119
|
+
return {
|
|
120
|
+
value: rawValue,
|
|
121
|
+
get boolean() { return self.options.getBoolean(name); },
|
|
122
|
+
get channel() { return self.options.getChannel(name); },
|
|
123
|
+
get string() { return self.options.getString(name); },
|
|
124
|
+
get integer() { return self.options.getInteger(name); },
|
|
125
|
+
get number() { return self.options.getNumber(name); },
|
|
126
|
+
get user() { return self.options.getUser(name); },
|
|
127
|
+
get member() { return self.options.getMember(name); },
|
|
128
|
+
get role() { return self.options.getRole(name); },
|
|
129
|
+
get mentionable() { return self.options.getMentionable(name); },
|
|
130
|
+
get attachment() { return self.options.getAttachment(name); }
|
|
131
|
+
};
|
|
132
|
+
},
|
|
133
|
+
get _hoistedOptions() {
|
|
134
|
+
return self._hoistedOptions;
|
|
135
|
+
},
|
|
136
|
+
getSubcommand() {
|
|
137
|
+
let splitted = self.fullCommandName.split(" ");
|
|
138
|
+
if (splitted.length === 1) return null;
|
|
139
|
+
return splitted.at(-1);
|
|
140
|
+
},
|
|
141
|
+
getSubcommandGroup() {
|
|
142
|
+
let splitted = self.fullCommandName.split(" ");
|
|
143
|
+
if (splitted.length === 3) return splitted[1];
|
|
144
|
+
return null;
|
|
145
|
+
},
|
|
146
|
+
getBoolean(name: string) {
|
|
147
|
+
const rawValue = self.getRawOptionValue(name);
|
|
148
|
+
if (!rawValue) return null;
|
|
149
|
+
return !!self.dbi.config.messageCommands.typeAliases.booleans[rawValue.toLowerCase()];
|
|
150
|
+
},
|
|
151
|
+
getChannel(name: string, _: any, channelType?: ChannelType | ChannelType[]) {
|
|
152
|
+
const rawValue = self.getRawOptionValue(name);
|
|
153
|
+
if (!rawValue) return null;
|
|
154
|
+
let value = rawValue.replace(/<#|>/g, "");
|
|
155
|
+
let channel = self.message.client.channels.cache.get(value);
|
|
156
|
+
if (!channel) channel = self.message.client.channels.cache.find(c => {
|
|
157
|
+
if (self.guildId && (c as any).guildId && (c as any).guildId !== self.guildId) return false;
|
|
158
|
+
return (c as any).name === value;
|
|
159
|
+
});
|
|
160
|
+
// @ts-ignore
|
|
161
|
+
if (channelType && channel?.type !== channelType && !channelType?.includes?.(channel?.type)) return null;
|
|
162
|
+
return channel;
|
|
163
|
+
},
|
|
164
|
+
getString(name: string) {
|
|
165
|
+
const dbiOption = self.getClonedDBIOption(name);
|
|
166
|
+
let rawValue = `${self.getRawOptionValue(name)}`;
|
|
167
|
+
let choices = dbiOption.choices ?? dbiOption._choices;
|
|
168
|
+
if (choices) return choices.find(c => c.value === rawValue || c.name === rawValue)?.value ?? rawValue;
|
|
169
|
+
return rawValue;
|
|
170
|
+
},
|
|
171
|
+
getInteger(name: string) {
|
|
172
|
+
const dbiOption = self.getClonedDBIOption(name);
|
|
173
|
+
let rawValue = self.getRawOptionValue(name);
|
|
174
|
+
let parsedValue = parseInt(rawValue);
|
|
175
|
+
let choices = dbiOption.choices ?? dbiOption._choices;
|
|
176
|
+
if (choices) return choices.find(c => c.value === parsedValue || c.name === rawValue)?.value ?? rawValue;
|
|
177
|
+
return rawValue;
|
|
178
|
+
},
|
|
179
|
+
getNumber(name: string) {
|
|
180
|
+
const dbiOption = self.getClonedDBIOption(name);
|
|
181
|
+
let rawValue = self.getRawOptionValue(name);
|
|
182
|
+
let parsedValue = parseFloat(rawValue);
|
|
183
|
+
let choices = dbiOption.choices ?? dbiOption._choices;
|
|
184
|
+
if (choices) return choices.find(c => c.value === parsedValue || c.name === rawValue)?.value ?? rawValue;
|
|
185
|
+
return rawValue;
|
|
186
|
+
},
|
|
187
|
+
getUser(name: string) {
|
|
188
|
+
const rawValue = self.getRawOptionValue(name);
|
|
189
|
+
if (!rawValue) return null;
|
|
190
|
+
let value = rawValue.replace(/<@!?|>/g, "");
|
|
191
|
+
let user = self.message.client.users.cache.get(value);
|
|
192
|
+
if (!user) user = self.message.client.users.cache.find(u => u.username === value || u.tag === value);
|
|
193
|
+
return user;
|
|
194
|
+
},
|
|
195
|
+
getUserId(name: string) {
|
|
196
|
+
const rawValue = self.getRawOptionValue(name);
|
|
197
|
+
if (!rawValue) return null;
|
|
198
|
+
return rawValue.replace(/<@!?|>/g, "");
|
|
199
|
+
},
|
|
200
|
+
getMember(name: string) {
|
|
201
|
+
const rawValue = self.getRawOptionValue(name);
|
|
202
|
+
if (!rawValue) return null;
|
|
203
|
+
let value = rawValue.replace(/<@!?|>/g, "");
|
|
204
|
+
let member = self.message.guild?.members.cache.get(value);
|
|
205
|
+
if (!member) member = self.message.guild?.members.cache.find(m => m.user.username === value || m.user.tag === value);
|
|
206
|
+
return member;
|
|
207
|
+
},
|
|
208
|
+
getMemberId(name: string) {
|
|
209
|
+
const rawValue = self.getRawOptionValue(name);
|
|
210
|
+
if (!rawValue) return null;
|
|
211
|
+
return rawValue.replace(/<@!?|>/g, "");
|
|
212
|
+
},
|
|
213
|
+
getRole(name: string) {
|
|
214
|
+
const rawValue = self.getRawOptionValue(name);
|
|
215
|
+
if (!rawValue) return null;
|
|
216
|
+
let value = rawValue.replace(/<@&|>/g, "");
|
|
217
|
+
let role = self.message.guild?.roles.cache.get(value);
|
|
218
|
+
if (!role) role = self.message.guild?.roles.cache.find(r => r.name === value);
|
|
219
|
+
return role;
|
|
220
|
+
},
|
|
221
|
+
getRoleId(name: string) {
|
|
222
|
+
const rawValue = self.getRawOptionValue(name);
|
|
223
|
+
if (!rawValue) return null;
|
|
224
|
+
return rawValue.replace(/<@&|>/g, "");
|
|
225
|
+
},
|
|
226
|
+
getMentionable(name: string) {
|
|
227
|
+
const rawValue = self.getRawOptionValue(name);
|
|
228
|
+
if (!rawValue) return null;
|
|
229
|
+
let value = rawValue.replace(/<(@|#)(!|&)?|>/g, "");
|
|
230
|
+
let user = self.message.client.users.cache.get(value);
|
|
231
|
+
if (!user) user = self.message.client.users.cache.find(u => u.username === value || u.tag === value);
|
|
232
|
+
if (user) return user;
|
|
233
|
+
let member = self.message.guild?.members.cache.get(value);
|
|
234
|
+
if (!member) member = self.message.guild?.members.cache.find(m => m.user.username === value || m.user.tag === value);
|
|
235
|
+
if (member) return member;
|
|
236
|
+
let role = self.message.guild?.roles.cache.get(value);
|
|
237
|
+
if (!role) role = self.message.guild?.roles.cache.find(r => r.name === value);
|
|
238
|
+
if (role) return role;
|
|
239
|
+
return null;
|
|
240
|
+
},
|
|
241
|
+
getMentionableId(name: string) {
|
|
242
|
+
const rawValue = self.getRawOptionValue(name);
|
|
243
|
+
if (!rawValue) return null;
|
|
244
|
+
return rawValue.replace(/<@(!|&)?|>/g, "");
|
|
245
|
+
},
|
|
246
|
+
getMessage() {
|
|
247
|
+
return self.message;
|
|
248
|
+
},
|
|
249
|
+
getAttachment(name: string) {
|
|
250
|
+
let d = self.parsedArgs.get(name);
|
|
251
|
+
return d?.attachment ?? null;
|
|
252
|
+
},
|
|
253
|
+
getChannelId(name: string) {
|
|
254
|
+
const rawValue = self.getRawOptionValue(name);
|
|
255
|
+
if (!rawValue) return null;
|
|
256
|
+
let value = rawValue.replace(/<#|>/g, "");
|
|
257
|
+
return value;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
init() {
|
|
263
|
+
if (this._initialized) return;
|
|
264
|
+
this._initialized = true;
|
|
265
|
+
this._hoistedOptionsInit();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
_hoistedOptionsInit() {
|
|
269
|
+
this._hoistedOptions = [...this.parsedArgs.values()].map(arg => {
|
|
270
|
+
switch (arg.type) {
|
|
271
|
+
case ApplicationCommandOptionType.String: {
|
|
272
|
+
return { ...this.options.get(arg.name), value: this.options.getString(arg.name) };
|
|
273
|
+
}
|
|
274
|
+
case ApplicationCommandOptionType.Integer: {
|
|
275
|
+
return { ...this.options.get(arg.name), value: this.options.getInteger(arg.name) };
|
|
276
|
+
}
|
|
277
|
+
case ApplicationCommandOptionType.Number: {
|
|
278
|
+
return { ...this.options.get(arg.name), value: this.options.getNumber(arg.name) };
|
|
279
|
+
}
|
|
280
|
+
case ApplicationCommandOptionType.Boolean: {
|
|
281
|
+
return { ...this.options.get(arg.name), value: this.options.getBoolean(arg.name) };
|
|
282
|
+
}
|
|
283
|
+
case ApplicationCommandOptionType.User: {
|
|
284
|
+
return { ...this.options.get(arg.name), value: this.options.getUser(arg.name)?.id };
|
|
285
|
+
}
|
|
286
|
+
case ApplicationCommandOptionType.Channel: {
|
|
287
|
+
return { ...this.options.get(arg.name), value: this.options.getChannel(arg.name)?.id };
|
|
288
|
+
}
|
|
289
|
+
case ApplicationCommandOptionType.Role: {
|
|
290
|
+
return { ...this.options.get(arg.name), value: this.options.getRole(arg.name)?.id };
|
|
291
|
+
}
|
|
292
|
+
case ApplicationCommandOptionType.Mentionable: {
|
|
293
|
+
return { ...this.options.get(arg.name), value: this.options.getMentionable(arg.name)?.id };
|
|
294
|
+
}
|
|
295
|
+
case ApplicationCommandOptionType.Attachment: {
|
|
296
|
+
return { ...this.options.get(arg.name), value: this.options.getAttachment(arg.name)?.url };
|
|
297
|
+
}
|
|
298
|
+
case ApplicationCommandOptionType.Subcommand: {
|
|
299
|
+
return { ...this.options.get(arg.name), value: this.options.getSubcommand() };
|
|
300
|
+
}
|
|
301
|
+
case ApplicationCommandOptionType.SubcommandGroup: {
|
|
302
|
+
return { ...this.options.get(arg.name), value: this.options.getSubcommandGroup() };
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
private getRawOptionValue(name: string): any {
|
|
309
|
+
return this.parsedArgs.get(name)?.value;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
private getClonedDBIOption(name: string): any {
|
|
313
|
+
return this.dbiChatInputOptions.find(o => o.name === name);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
inGuild() {
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
async deferReply(options: any): Promise<any> {
|
|
321
|
+
if (this.repliedMessage) throw new Error("Already deferred reply.");
|
|
322
|
+
this.repliedMessage = await this.message.reply(options?.content ?? (await this.dbi.config.defaults.messageCommands.deferReplyContent({
|
|
323
|
+
// @ts-ignore
|
|
324
|
+
dbiInteraction: this.dbiChatInput,
|
|
325
|
+
interaction: this,
|
|
326
|
+
locale: {
|
|
327
|
+
user: this.dbi.data.locales.get(this.locale) ||
|
|
328
|
+
this.dbi.data.locales.get(this.dbi.config.defaults.locale.name),
|
|
329
|
+
guild: this.message.guild?.preferredLocale
|
|
330
|
+
? this.dbi.data.locales.get(
|
|
331
|
+
this.message.guild?.preferredLocale?.split("-")?.at(0)
|
|
332
|
+
) || this.dbi.data.locales.get(this.dbi.config.defaults.locale.name)
|
|
333
|
+
: null,
|
|
334
|
+
}
|
|
335
|
+
})));
|
|
336
|
+
this.deferred = true;
|
|
337
|
+
this._lastAction = "deferReply";
|
|
338
|
+
return this.repliedMessage;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
async deleteReply() {
|
|
342
|
+
if (!this.repliedMessage) throw new Error("No deferred reply.");
|
|
343
|
+
await this.repliedMessage.delete();
|
|
344
|
+
this.repliedMessage = undefined;
|
|
345
|
+
this._lastAction = "deleteReply";
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
async followUp(content: string | MessagePayload) {
|
|
349
|
+
if (!this.repliedMessage) throw new Error("No deferred reply.");
|
|
350
|
+
if (!this.lastFollowUp) {
|
|
351
|
+
this.lastFollowUp = await this.repliedMessage.reply(content);
|
|
352
|
+
} else {
|
|
353
|
+
this.lastFollowUp = await this.lastFollowUp.reply(content);
|
|
354
|
+
}
|
|
355
|
+
this._lastAction = "followUp";
|
|
356
|
+
return this.lastFollowUp;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
async editReply(content: string | MessagePayload | InteractionEditReplyOptions) {
|
|
360
|
+
if (!this.repliedMessage) throw new Error("No deferred reply.");
|
|
361
|
+
if (typeof content !== "string" && this._lastAction === "deferReply" && typeof (content as any).content === "undefined") {
|
|
362
|
+
(content as any).content = null;
|
|
363
|
+
}
|
|
364
|
+
await this.repliedMessage.edit(content);
|
|
365
|
+
this._lastAction = "editReply";
|
|
366
|
+
return this.repliedMessage;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
async reply(content: string | MessagePayload | InteractionReplyOptions): Promise<any> {
|
|
370
|
+
if (this.repliedMessage) throw new Error("Already deferred reply.");
|
|
371
|
+
this.repliedMessage = await this.message.reply(content as any);
|
|
372
|
+
this._lastAction = "reply";
|
|
373
|
+
return this.repliedMessage;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
async awaitModalSubmit() {
|
|
377
|
+
throw new Error("Method not implemented.");
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
async fetchReply() {
|
|
381
|
+
return this.repliedMessage?.id && await this.message.channel.messages.fetch(this.repliedMessage.id);
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
isAnySelectMenu() { return false; }
|
|
385
|
+
isAutocomplete() { return false; }
|
|
386
|
+
isButton() { return false; }
|
|
387
|
+
isChannelSelectMenu() { return false; }
|
|
388
|
+
isChatInputCommand() { return true; }
|
|
389
|
+
isCommand() { return true; }
|
|
390
|
+
isContextMenuCommand() { return false; }
|
|
391
|
+
isMentionableSelectMenu() { return false; }
|
|
392
|
+
isMessageComponent() { return false; }
|
|
393
|
+
isMessageContextMenuCommand() { return false; }
|
|
394
|
+
isModalSubmit() { return false; }
|
|
395
|
+
isRepliable() { return true; }
|
|
396
|
+
isRoleSelectMenu() { return false; }
|
|
397
|
+
isStringSelectMenu() { return false; }
|
|
398
|
+
isUserContextMenuCommand() { return false; }
|
|
399
|
+
isUserSelectMenu() { return false; }
|
|
400
|
+
isSelectMenu() { return false; }
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
interface FakeMessageInteractionArgument {
|
|
404
|
+
type: ApplicationCommandOptionType,
|
|
405
|
+
value: any,
|
|
406
|
+
attachment?: Attachment,
|
|
407
|
+
name: string
|
|
408
408
|
}
|