seyfert 1.3.3 → 1.4.0
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/lib/api/api.js +13 -7
- package/lib/builders/Attachment.d.ts +1 -4
- package/lib/builders/Attachment.js +4 -4
- package/lib/cache/adapters/workeradapter.js +7 -3
- package/lib/cache/resources/default/base.d.ts +1 -2
- package/lib/cache/resources/default/guild-based.d.ts +1 -2
- package/lib/client/base.d.ts +26 -4
- package/lib/client/base.js +42 -2
- package/lib/client/client.d.ts +3 -3
- package/lib/client/client.js +18 -6
- package/lib/client/httpclient.d.ts +7 -8
- package/lib/client/httpclient.js +92 -13
- package/lib/client/oninteractioncreate.d.ts +2 -2
- package/lib/client/oninteractioncreate.js +15 -7
- package/lib/client/onmessagecreate.js +74 -66
- package/lib/client/workerclient.d.ts +1 -1
- package/lib/client/workerclient.js +18 -7
- package/lib/commands/applications/chat.d.ts +1 -1
- package/lib/commands/applications/chat.js +2 -1
- package/lib/commands/applications/chatcontext.d.ts +1 -1
- package/lib/commands/applications/chatcontext.js +2 -2
- package/lib/commands/applications/menu.js +0 -48
- package/lib/commands/applications/menucontext.d.ts +1 -1
- package/lib/commands/applications/menucontext.js +3 -3
- package/lib/commands/applications/options.d.ts +3 -1
- package/lib/commands/basecontext.d.ts +26 -0
- package/lib/commands/{basecontex.js → basecontext.js} +24 -0
- package/lib/commands/handler.d.ts +6 -1
- package/lib/commands/handler.js +125 -3
- package/lib/common/bot/watcher.d.ts +1 -2
- package/lib/common/bot/watcher.js +9 -4
- package/lib/common/it/logger.d.ts +1 -1
- package/lib/common/it/logger.js +9 -8
- package/lib/common/it/utils.d.ts +2 -0
- package/lib/common/it/utils.js +19 -5
- package/lib/common/shorters/interaction.js +3 -3
- package/lib/common/shorters/messages.js +2 -2
- package/lib/common/shorters/webhook.js +2 -2
- package/lib/components/componentcommand.d.ts +21 -0
- package/lib/components/{command.js → componentcommand.js} +2 -5
- package/lib/components/componentcontext.d.ts +20 -16
- package/lib/components/componentcontext.js +27 -9
- package/lib/components/handler.d.ts +10 -5
- package/lib/components/handler.js +94 -17
- package/lib/components/index.d.ts +3 -1
- package/lib/components/index.js +3 -1
- package/lib/components/modalcommand.d.ts +15 -0
- package/lib/components/modalcommand.js +9 -0
- package/lib/components/modalcontext.d.ts +104 -0
- package/lib/components/modalcontext.js +132 -0
- package/lib/events/handler.d.ts +4 -1
- package/lib/events/handler.js +2 -7
- package/lib/events/hooks/application_command.d.ts +2 -2
- package/lib/events/hooks/auto_moderation.d.ts +5 -5
- package/lib/events/hooks/channel.d.ts +5 -5
- package/lib/events/hooks/custom.d.ts +3 -3
- package/lib/events/hooks/dispatch.d.ts +4 -4
- package/lib/events/hooks/entitlement.d.ts +4 -4
- package/lib/events/hooks/guild.d.ts +23 -23
- package/lib/events/hooks/guild.js +6 -6
- package/lib/events/hooks/integration.d.ts +4 -4
- package/lib/events/hooks/interactions.d.ts +2 -2
- package/lib/events/hooks/invite.d.ts +3 -3
- package/lib/events/hooks/message.d.ts +13 -13
- package/lib/events/hooks/message.js +1 -1
- package/lib/events/hooks/presence.d.ts +7 -3
- package/lib/events/hooks/presence.js +2 -2
- package/lib/events/hooks/stage.d.ts +7 -13
- package/lib/events/hooks/stage.js +2 -2
- package/lib/events/hooks/thread.d.ts +7 -7
- package/lib/events/hooks/thread.js +2 -2
- package/lib/events/hooks/typing.d.ts +2 -2
- package/lib/events/hooks/user.d.ts +2 -2
- package/lib/events/hooks/user.js +2 -2
- package/lib/events/hooks/voice.d.ts +5 -45
- package/lib/events/hooks/voice.js +4 -7
- package/lib/events/hooks/webhook.d.ts +2 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.js +9 -4
- package/lib/langs/handler.d.ts +4 -1
- package/lib/langs/handler.js +3 -3
- package/lib/structures/Interaction.d.ts +3 -3
- package/lib/structures/Interaction.js +11 -6
- package/lib/structures/VoiceState.d.ts +6 -5
- package/lib/structures/VoiceState.js +6 -3
- package/lib/structures/channels.d.ts +1 -1
- package/lib/structures/channels.js +2 -1
- package/lib/websocket/discord/sharder.js +10 -3
- package/lib/websocket/discord/shared.d.ts +1 -0
- package/lib/websocket/discord/workermanager.d.ts +2 -3
- package/lib/websocket/discord/workermanager.js +4 -2
- package/package.json +3 -3
- package/lib/commands/basecontex.d.ts +0 -15
- package/lib/components/command.d.ts +0 -24
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ComponentHandler = void 0;
|
|
4
4
|
const collection_1 = require("../collection");
|
|
5
|
+
const commands_1 = require("../commands");
|
|
5
6
|
const common_1 = require("../common");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
7
|
+
const componentcommand_1 = require("./componentcommand");
|
|
8
|
+
const modalcommand_1 = require("./modalcommand");
|
|
8
9
|
class ComponentHandler extends common_1.BaseHandler {
|
|
9
10
|
client;
|
|
10
11
|
onFail = err => this.logger.warn('<Client>.components.onFail', err);
|
|
@@ -116,8 +117,11 @@ class ComponentHandler extends common_1.BaseHandler {
|
|
|
116
117
|
onMessageDelete(id) {
|
|
117
118
|
this.deleteValue(id, 'messageDelete');
|
|
118
119
|
}
|
|
119
|
-
async load(componentsDir) {
|
|
120
|
-
const paths =
|
|
120
|
+
async load(componentsDir, instances) {
|
|
121
|
+
const paths = instances?.map(x => {
|
|
122
|
+
const i = new x();
|
|
123
|
+
return { file: x, path: i.__filePath ?? '*' };
|
|
124
|
+
}) ?? (await this.loadFilesK(await this.getFiles(componentsDir)));
|
|
121
125
|
for (let i = 0; i < paths.length; i++) {
|
|
122
126
|
let component;
|
|
123
127
|
try {
|
|
@@ -126,7 +130,7 @@ class ComponentHandler extends common_1.BaseHandler {
|
|
|
126
130
|
continue;
|
|
127
131
|
}
|
|
128
132
|
catch (e) {
|
|
129
|
-
if (e instanceof Error && e.message
|
|
133
|
+
if (e instanceof Error && e.message.includes('is not a constructor')) {
|
|
130
134
|
this.logger.warn(`${paths[i].path
|
|
131
135
|
.split(process.cwd())
|
|
132
136
|
.slice(1)
|
|
@@ -136,8 +140,20 @@ class ComponentHandler extends common_1.BaseHandler {
|
|
|
136
140
|
this.logger.warn(e, paths[i]);
|
|
137
141
|
continue;
|
|
138
142
|
}
|
|
139
|
-
if (!(component instanceof
|
|
143
|
+
if (!(component instanceof modalcommand_1.ModalCommand) && !(component instanceof componentcommand_1.ComponentCommand))
|
|
140
144
|
continue;
|
|
145
|
+
if (component instanceof modalcommand_1.ModalCommand) {
|
|
146
|
+
component.onInternalError ??= this.client.options?.modals?.defaults?.onInternalError;
|
|
147
|
+
component.onMiddlewaresError ??= this.client.options?.modals?.defaults?.onMiddlewaresError;
|
|
148
|
+
component.onRunError ??= this.client.options?.modals?.defaults?.onRunError;
|
|
149
|
+
component.onAfterRun ??= this.client.options?.modals?.defaults?.onAfterRun;
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
component.onInternalError ??= this.client.options?.components?.defaults?.onInternalError;
|
|
153
|
+
component.onMiddlewaresError ??= this.client.options?.components?.defaults?.onMiddlewaresError;
|
|
154
|
+
component.onRunError ??= this.client.options?.components?.defaults?.onRunError;
|
|
155
|
+
component.onAfterRun ??= this.client.options?.components?.defaults?.onAfterRun;
|
|
156
|
+
}
|
|
141
157
|
component.__filePath = paths[i].path;
|
|
142
158
|
this.commands.push(component);
|
|
143
159
|
}
|
|
@@ -171,16 +187,45 @@ class ComponentHandler extends common_1.BaseHandler {
|
|
|
171
187
|
await this.reload(i.__filePath);
|
|
172
188
|
}
|
|
173
189
|
}
|
|
174
|
-
async executeComponent(
|
|
190
|
+
async executeComponent(context) {
|
|
175
191
|
for (const i of this.commands) {
|
|
176
192
|
try {
|
|
177
|
-
if (i.type ===
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
193
|
+
if (i.type === componentcommand_1.InteractionCommandType.COMPONENT &&
|
|
194
|
+
i.cType === context.interaction.componentType &&
|
|
195
|
+
(await i.filter(context))) {
|
|
196
|
+
context.command = i;
|
|
197
|
+
try {
|
|
198
|
+
const resultRunGlobalMiddlewares = await commands_1.BaseCommand.__runMiddlewares(context, (context.client.options?.globalMiddlewares ?? []), true);
|
|
199
|
+
if (resultRunGlobalMiddlewares.pass) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if ('error' in resultRunGlobalMiddlewares) {
|
|
203
|
+
return i.onMiddlewaresError?.(context, resultRunGlobalMiddlewares.error ?? 'Unknown error');
|
|
204
|
+
}
|
|
205
|
+
const resultRunMiddlewares = await commands_1.BaseCommand.__runMiddlewares(context, i.middlewares, false);
|
|
206
|
+
if (resultRunMiddlewares.pass) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if ('error' in resultRunMiddlewares) {
|
|
210
|
+
return i.onMiddlewaresError?.(context, resultRunMiddlewares.error ?? 'Unknown error');
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
await i.run(context);
|
|
214
|
+
await i.onAfterRun?.(context, undefined);
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
await i.onRunError?.(context, error);
|
|
218
|
+
await i.onAfterRun?.(context, error);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
try {
|
|
223
|
+
await i.onInternalError?.(this.client, error);
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
// supress error
|
|
227
|
+
}
|
|
228
|
+
}
|
|
184
229
|
break;
|
|
185
230
|
}
|
|
186
231
|
}
|
|
@@ -189,11 +234,43 @@ class ComponentHandler extends common_1.BaseHandler {
|
|
|
189
234
|
}
|
|
190
235
|
}
|
|
191
236
|
}
|
|
192
|
-
async executeModal(
|
|
237
|
+
async executeModal(context) {
|
|
193
238
|
for (const i of this.commands) {
|
|
194
239
|
try {
|
|
195
|
-
if (i.type ===
|
|
196
|
-
|
|
240
|
+
if (i.type === componentcommand_1.InteractionCommandType.MODAL && (await i.filter(context))) {
|
|
241
|
+
context.command = i;
|
|
242
|
+
try {
|
|
243
|
+
const resultRunGlobalMiddlewares = await commands_1.BaseCommand.__runMiddlewares(context, (context.client.options?.globalMiddlewares ?? []), true);
|
|
244
|
+
if (resultRunGlobalMiddlewares.pass) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if ('error' in resultRunGlobalMiddlewares) {
|
|
248
|
+
return i.onMiddlewaresError?.(context, resultRunGlobalMiddlewares.error ?? 'Unknown error');
|
|
249
|
+
}
|
|
250
|
+
const resultRunMiddlewares = await commands_1.BaseCommand.__runMiddlewares(context, i.middlewares, false);
|
|
251
|
+
if (resultRunMiddlewares.pass) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
if ('error' in resultRunMiddlewares) {
|
|
255
|
+
return i.onMiddlewaresError?.(context, resultRunMiddlewares.error ?? 'Unknown error');
|
|
256
|
+
}
|
|
257
|
+
try {
|
|
258
|
+
await i.run(context);
|
|
259
|
+
await i.onAfterRun?.(context, undefined);
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
await i.onRunError?.(context, error);
|
|
263
|
+
await i.onAfterRun?.(context, error);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
try {
|
|
268
|
+
await i.onInternalError?.(this.client, error);
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
// supress error
|
|
272
|
+
}
|
|
273
|
+
}
|
|
197
274
|
break;
|
|
198
275
|
}
|
|
199
276
|
}
|
|
@@ -9,8 +9,10 @@ import type { TextInputComponent } from './TextInputComponent';
|
|
|
9
9
|
import { UserSelectMenuComponent } from './UserSelectMenuComponent';
|
|
10
10
|
export type MessageComponents = ButtonComponent | LinkButtonComponent | RoleSelectMenuComponent | UserSelectMenuComponent | StringSelectMenuComponent | ChannelSelectMenuComponent | MentionableSelectMenuComponent | TextInputComponent;
|
|
11
11
|
export type ActionRowMessageComponents = Exclude<MessageComponents, TextInputComponent>;
|
|
12
|
-
export * from './
|
|
12
|
+
export * from './componentcommand';
|
|
13
13
|
export * from './componentcontext';
|
|
14
|
+
export * from './modalcommand';
|
|
15
|
+
export * from './modalcontext';
|
|
14
16
|
/**
|
|
15
17
|
* Return a new component instance based on the component type.
|
|
16
18
|
*
|
package/lib/components/index.js
CHANGED
|
@@ -23,8 +23,10 @@ const MentionableSelectMenuComponent_1 = require("./MentionableSelectMenuCompone
|
|
|
23
23
|
const RoleSelectMenuComponent_1 = require("./RoleSelectMenuComponent");
|
|
24
24
|
const StringSelectMenuComponent_1 = require("./StringSelectMenuComponent");
|
|
25
25
|
const UserSelectMenuComponent_1 = require("./UserSelectMenuComponent");
|
|
26
|
-
__exportStar(require("./
|
|
26
|
+
__exportStar(require("./componentcommand"), exports);
|
|
27
27
|
__exportStar(require("./componentcontext"), exports);
|
|
28
|
+
__exportStar(require("./modalcommand"), exports);
|
|
29
|
+
__exportStar(require("./modalcontext"), exports);
|
|
28
30
|
/**
|
|
29
31
|
* Return a new component instance based on the component type.
|
|
30
32
|
*
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RegisteredMiddlewares, UsingClient } from '../commands';
|
|
2
|
+
import type { ModalContext } from './modalcontext';
|
|
3
|
+
export interface ModalCommand {
|
|
4
|
+
__filePath?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare abstract class ModalCommand {
|
|
7
|
+
type: 1;
|
|
8
|
+
abstract filter(context: ModalContext): Promise<boolean> | boolean;
|
|
9
|
+
abstract run(context: ModalContext): any;
|
|
10
|
+
middlewares: (keyof RegisteredMiddlewares)[];
|
|
11
|
+
onAfterRun?(context: ModalContext, error: unknown | undefined): any;
|
|
12
|
+
onRunError?(context: ModalContext, error: unknown): any;
|
|
13
|
+
onMiddlewaresError?(context: ModalContext, error: string): any;
|
|
14
|
+
onInternalError?(client: UsingClient, error?: unknown): any;
|
|
15
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModalCommand = void 0;
|
|
4
|
+
const componentcommand_1 = require("./componentcommand");
|
|
5
|
+
class ModalCommand {
|
|
6
|
+
type = componentcommand_1.InteractionCommandType.MODAL;
|
|
7
|
+
middlewares = [];
|
|
8
|
+
}
|
|
9
|
+
exports.ModalCommand = ModalCommand;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { AllChannels, Guild, GuildMember, Message, ModalCommand, ModalSubmitInteraction, ReturnCache, WebhookMessage } from '..';
|
|
2
|
+
import type { CommandMetadata, ExtendContext, GlobalMetadata, RegisteredMiddlewares, UsingClient } from '../commands';
|
|
3
|
+
import { BaseContext } from '../commands/basecontext';
|
|
4
|
+
import type { InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest, ModalCreateBodyRequest, UnionToTuple, When } from '../common';
|
|
5
|
+
export interface ModalContext extends BaseContext, ExtendContext {
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Represents a context for interacting with components in a Discord bot.
|
|
9
|
+
* @template Type - The type of component interaction.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ModalContext<M extends keyof RegisteredMiddlewares = never> extends BaseContext {
|
|
12
|
+
readonly client: UsingClient;
|
|
13
|
+
interaction: ModalSubmitInteraction;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new instance of the ComponentContext class.
|
|
16
|
+
* @param client - The UsingClient instance.
|
|
17
|
+
* @param interaction - The component interaction object.
|
|
18
|
+
*/
|
|
19
|
+
constructor(client: UsingClient, interaction: ModalSubmitInteraction);
|
|
20
|
+
command?: ModalCommand;
|
|
21
|
+
metadata: CommandMetadata<UnionToTuple<M>>;
|
|
22
|
+
globalMetadata: GlobalMetadata;
|
|
23
|
+
get customId(): string;
|
|
24
|
+
get components(): {
|
|
25
|
+
components: {
|
|
26
|
+
type: import("discord-api-types/v10").ComponentType;
|
|
27
|
+
customId: string;
|
|
28
|
+
value: string;
|
|
29
|
+
}[];
|
|
30
|
+
type: import("discord-api-types/v10").ComponentType.ActionRow;
|
|
31
|
+
}[];
|
|
32
|
+
/**
|
|
33
|
+
* Gets the language object for the interaction's locale.
|
|
34
|
+
*/
|
|
35
|
+
get t(): import("..").__InternalParseLocale<import("..").DefaultLocale> & {
|
|
36
|
+
get(locale?: string | undefined): import("..").DefaultLocale;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Writes a response to the interaction.
|
|
40
|
+
* @param body - The body of the response.
|
|
41
|
+
* @param fetchReply - Whether to fetch the reply or not.
|
|
42
|
+
*/
|
|
43
|
+
write<FR extends boolean = false>(body: InteractionCreateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage, void>>;
|
|
44
|
+
/**
|
|
45
|
+
* Defers the reply to the interaction.
|
|
46
|
+
* @param ephemeral - Whether the reply should be ephemeral or not.
|
|
47
|
+
*/
|
|
48
|
+
deferReply(ephemeral?: boolean): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Edits the response of the interaction.
|
|
51
|
+
* @param body - The updated body of the response.
|
|
52
|
+
*/
|
|
53
|
+
editResponse(body: InteractionMessageUpdateBodyRequest): Promise<WebhookMessage>;
|
|
54
|
+
/**
|
|
55
|
+
* Edits the response or replies to the interaction.
|
|
56
|
+
* @param body - The body of the response or updated body of the interaction.
|
|
57
|
+
* @param fetchReply - Whether to fetch the reply or not.
|
|
58
|
+
*/
|
|
59
|
+
editOrReply<FR extends boolean = false>(body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage | Message, void | WebhookMessage | Message>>;
|
|
60
|
+
/**
|
|
61
|
+
* Deletes the response of the interaction.
|
|
62
|
+
* @returns A promise that resolves when the response is deleted.
|
|
63
|
+
*/
|
|
64
|
+
deleteResponse(): Promise<void | undefined>;
|
|
65
|
+
modal(body: ModalCreateBodyRequest): any;
|
|
66
|
+
/**
|
|
67
|
+
* Gets the channel of the interaction.
|
|
68
|
+
* @param mode - The mode to fetch the channel.
|
|
69
|
+
* @returns A promise that resolves to the channel.
|
|
70
|
+
*/
|
|
71
|
+
channel(mode?: 'rest' | 'flow'): Promise<AllChannels>;
|
|
72
|
+
channel(mode?: 'cache'): ReturnCache<AllChannels>;
|
|
73
|
+
/**
|
|
74
|
+
* Gets the bot member in the guild of the interaction.
|
|
75
|
+
* @param mode - The mode to fetch the member.
|
|
76
|
+
* @returns A promise that resolves to the bot member.
|
|
77
|
+
*/
|
|
78
|
+
me(mode?: 'rest' | 'flow'): Promise<GuildMember>;
|
|
79
|
+
me(mode?: 'cache'): ReturnCache<GuildMember | undefined>;
|
|
80
|
+
/**
|
|
81
|
+
* Gets the guild of the interaction.
|
|
82
|
+
* @param mode - The mode to fetch the guild.
|
|
83
|
+
* @returns A promise that resolves to the guild.
|
|
84
|
+
*/
|
|
85
|
+
guild(mode?: 'rest' | 'flow'): Promise<Guild<'cached' | 'api'> | undefined>;
|
|
86
|
+
guild(mode?: 'cache'): ReturnCache<Guild<'cached'> | undefined>;
|
|
87
|
+
/**
|
|
88
|
+
* Gets the ID of the guild of the interaction.
|
|
89
|
+
*/
|
|
90
|
+
get guildId(): string | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Gets the ID of the channel of the interaction.
|
|
93
|
+
*/
|
|
94
|
+
get channelId(): string;
|
|
95
|
+
/**
|
|
96
|
+
* Gets the author of the interaction.
|
|
97
|
+
*/
|
|
98
|
+
get author(): import("..").User;
|
|
99
|
+
/**
|
|
100
|
+
* Gets the member of the interaction.
|
|
101
|
+
*/
|
|
102
|
+
get member(): import("..").InteractionGuildMember | undefined;
|
|
103
|
+
isModal(): this is ModalContext;
|
|
104
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModalContext = void 0;
|
|
4
|
+
const v10_1 = require("discord-api-types/v10");
|
|
5
|
+
const basecontext_1 = require("../commands/basecontext");
|
|
6
|
+
/**
|
|
7
|
+
* Represents a context for interacting with components in a Discord bot.
|
|
8
|
+
* @template Type - The type of component interaction.
|
|
9
|
+
*/
|
|
10
|
+
class ModalContext extends basecontext_1.BaseContext {
|
|
11
|
+
client;
|
|
12
|
+
interaction;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new instance of the ComponentContext class.
|
|
15
|
+
* @param client - The UsingClient instance.
|
|
16
|
+
* @param interaction - The component interaction object.
|
|
17
|
+
*/
|
|
18
|
+
constructor(client, interaction) {
|
|
19
|
+
super(client);
|
|
20
|
+
this.client = client;
|
|
21
|
+
this.interaction = interaction;
|
|
22
|
+
}
|
|
23
|
+
command;
|
|
24
|
+
metadata = {};
|
|
25
|
+
globalMetadata = {};
|
|
26
|
+
get customId() {
|
|
27
|
+
return this.interaction.customId;
|
|
28
|
+
}
|
|
29
|
+
get components() {
|
|
30
|
+
return this.interaction.components;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Gets the language object for the interaction's locale.
|
|
34
|
+
*/
|
|
35
|
+
get t() {
|
|
36
|
+
return this.client.t(this.interaction?.locale ?? this.client.langs?.defaultLang ?? 'en-US');
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Writes a response to the interaction.
|
|
40
|
+
* @param body - The body of the response.
|
|
41
|
+
* @param fetchReply - Whether to fetch the reply or not.
|
|
42
|
+
*/
|
|
43
|
+
write(body, fetchReply) {
|
|
44
|
+
return this.interaction.write(body, fetchReply);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Defers the reply to the interaction.
|
|
48
|
+
* @param ephemeral - Whether the reply should be ephemeral or not.
|
|
49
|
+
*/
|
|
50
|
+
deferReply(ephemeral = false) {
|
|
51
|
+
return this.interaction.deferReply(ephemeral ? v10_1.MessageFlags.Ephemeral : undefined);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Edits the response of the interaction.
|
|
55
|
+
* @param body - The updated body of the response.
|
|
56
|
+
*/
|
|
57
|
+
editResponse(body) {
|
|
58
|
+
return this.interaction.editResponse(body);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Edits the response or replies to the interaction.
|
|
62
|
+
* @param body - The body of the response or updated body of the interaction.
|
|
63
|
+
* @param fetchReply - Whether to fetch the reply or not.
|
|
64
|
+
*/
|
|
65
|
+
editOrReply(body, fetchReply) {
|
|
66
|
+
return this.interaction.editOrReply(body, fetchReply);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Deletes the response of the interaction.
|
|
70
|
+
* @returns A promise that resolves when the response is deleted.
|
|
71
|
+
*/
|
|
72
|
+
deleteResponse() {
|
|
73
|
+
return this.interaction.deleteResponse();
|
|
74
|
+
}
|
|
75
|
+
modal(body) {
|
|
76
|
+
//@ts-expect-error
|
|
77
|
+
return this.interaction.modal(body);
|
|
78
|
+
}
|
|
79
|
+
channel(mode = 'cache') {
|
|
80
|
+
if (this.interaction?.channel && mode === 'cache')
|
|
81
|
+
return this.client.cache.adapter.isAsync ? Promise.resolve(this.interaction.channel) : this.interaction.channel;
|
|
82
|
+
return this.client.channels.fetch(this.channelId, mode === 'rest');
|
|
83
|
+
}
|
|
84
|
+
me(mode = 'cache') {
|
|
85
|
+
if (!this.guildId)
|
|
86
|
+
return mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve();
|
|
87
|
+
switch (mode) {
|
|
88
|
+
case 'cache':
|
|
89
|
+
return this.client.cache.members?.get(this.client.botId, this.guildId);
|
|
90
|
+
default:
|
|
91
|
+
return this.client.members.fetch(this.guildId, this.client.botId, mode === 'rest');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
guild(mode = 'cache') {
|
|
95
|
+
if (!this.guildId)
|
|
96
|
+
return (mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve());
|
|
97
|
+
switch (mode) {
|
|
98
|
+
case 'cache':
|
|
99
|
+
return this.client.cache.guilds?.get(this.guildId);
|
|
100
|
+
default:
|
|
101
|
+
return this.client.guilds.fetch(this.guildId, mode === 'rest');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Gets the ID of the guild of the interaction.
|
|
106
|
+
*/
|
|
107
|
+
get guildId() {
|
|
108
|
+
return this.interaction.guildId;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Gets the ID of the channel of the interaction.
|
|
112
|
+
*/
|
|
113
|
+
get channelId() {
|
|
114
|
+
return this.interaction.channelId;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Gets the author of the interaction.
|
|
118
|
+
*/
|
|
119
|
+
get author() {
|
|
120
|
+
return this.interaction.user;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Gets the member of the interaction.
|
|
124
|
+
*/
|
|
125
|
+
get member() {
|
|
126
|
+
return this.interaction.member;
|
|
127
|
+
}
|
|
128
|
+
isModal() {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.ModalContext = ModalContext;
|
package/lib/events/handler.d.ts
CHANGED
|
@@ -11,7 +11,10 @@ export declare class EventHandler extends BaseHandler {
|
|
|
11
11
|
onFail: (event: GatewayEvents, err: unknown) => void;
|
|
12
12
|
protected filter: (path: string) => boolean;
|
|
13
13
|
values: Partial<Record<GatewayEvents, EventValue>>;
|
|
14
|
-
load(eventsDir: string
|
|
14
|
+
load(eventsDir: string, instances?: {
|
|
15
|
+
file: ClientEvent;
|
|
16
|
+
path: string;
|
|
17
|
+
}[]): Promise<void>;
|
|
15
18
|
execute(name: GatewayEvents, ...args: [GatewayDispatchPayload, Client<true> | WorkerClient<true>, number]): Promise<void>;
|
|
16
19
|
runEvent(name: GatewayEvents, client: Client | WorkerClient, packet: any, shardId: number): Promise<void>;
|
|
17
20
|
reload(name: ClientNameEvents): Promise<any>;
|
package/lib/events/handler.js
CHANGED
|
@@ -30,8 +30,8 @@ class EventHandler extends common_1.BaseHandler {
|
|
|
30
30
|
onFail = (event, err) => this.logger.warn('<Client>.events.onFail', err, event);
|
|
31
31
|
filter = (path) => path.endsWith('.js') || (!path.endsWith('.d.ts') && path.endsWith('.ts'));
|
|
32
32
|
values = {};
|
|
33
|
-
async load(eventsDir) {
|
|
34
|
-
for (const i of await this.loadFilesK(await this.getFiles(eventsDir))) {
|
|
33
|
+
async load(eventsDir, instances) {
|
|
34
|
+
for (const i of instances ?? (await this.loadFilesK(await this.getFiles(eventsDir)))) {
|
|
35
35
|
const instance = this.callback(i.file);
|
|
36
36
|
if (!instance)
|
|
37
37
|
continue;
|
|
@@ -45,11 +45,6 @@ class EventHandler extends common_1.BaseHandler {
|
|
|
45
45
|
}
|
|
46
46
|
async execute(name, ...args) {
|
|
47
47
|
switch (name) {
|
|
48
|
-
case 'GUILD_DELETE':
|
|
49
|
-
case 'CHANNEL_UPDATE':
|
|
50
|
-
await this.runEvent(args[0].t, args[1], args[0], args[2]);
|
|
51
|
-
await args[1].cache.onPacket(args[0]);
|
|
52
|
-
return;
|
|
53
48
|
case 'MESSAGE_CREATE':
|
|
54
49
|
{
|
|
55
50
|
const { d: data } = args[0];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GatewayApplicationCommandPermissionsUpdateDispatchData } from 'discord-api-types/v10';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const APPLICATION_COMMAND_PERMISSIONS_UPDATE: (_self:
|
|
2
|
+
import type { UsingClient } from '../../commands';
|
|
3
|
+
export declare const APPLICATION_COMMAND_PERMISSIONS_UPDATE: (_self: UsingClient, data: GatewayApplicationCommandPermissionsUpdateDispatchData) => {
|
|
4
4
|
id: string;
|
|
5
5
|
applicationId: string;
|
|
6
6
|
guildId: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { GatewayAutoModerationActionExecutionDispatchData, GatewayAutoModerationRuleCreateDispatchData, GatewayAutoModerationRuleDeleteDispatchData, GatewayAutoModerationRuleUpdateDispatchData } from 'discord-api-types/v10';
|
|
2
|
-
import type { BaseClient } from '../../client/base';
|
|
3
2
|
import { AutoModerationRule } from '../../structures';
|
|
4
|
-
|
|
3
|
+
import type { UsingClient } from '../../commands';
|
|
4
|
+
export declare const AUTO_MODERATION_ACTION_EXECUTION: (_self: UsingClient, data: GatewayAutoModerationActionExecutionDispatchData) => {
|
|
5
5
|
guildId: string;
|
|
6
6
|
action: {
|
|
7
7
|
type: import("discord-api-types/v10").AutoModerationActionType;
|
|
@@ -21,6 +21,6 @@ export declare const AUTO_MODERATION_ACTION_EXECUTION: (_self: BaseClient, data:
|
|
|
21
21
|
matchedKeyword: string | null;
|
|
22
22
|
matchedContent: string | null;
|
|
23
23
|
};
|
|
24
|
-
export declare const AUTO_MODERATION_RULE_CREATE: (self:
|
|
25
|
-
export declare const AUTO_MODERATION_RULE_DELETE: (self:
|
|
26
|
-
export declare const AUTO_MODERATION_RULE_UPDATE: (self:
|
|
24
|
+
export declare const AUTO_MODERATION_RULE_CREATE: (self: UsingClient, data: GatewayAutoModerationRuleCreateDispatchData) => AutoModerationRule;
|
|
25
|
+
export declare const AUTO_MODERATION_RULE_DELETE: (self: UsingClient, data: GatewayAutoModerationRuleDeleteDispatchData) => AutoModerationRule;
|
|
26
|
+
export declare const AUTO_MODERATION_RULE_UPDATE: (self: UsingClient, data: GatewayAutoModerationRuleUpdateDispatchData) => AutoModerationRule;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { GatewayChannelCreateDispatchData, GatewayChannelDeleteDispatchData, GatewayChannelPinsUpdateDispatchData, GatewayChannelUpdateDispatchData } from 'discord-api-types/v10';
|
|
2
|
-
import type { BaseClient } from '../../client/base';
|
|
3
2
|
import type { AllChannels } from '../../structures';
|
|
4
|
-
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
3
|
+
import type { UsingClient } from '../../commands';
|
|
4
|
+
export declare const CHANNEL_CREATE: (self: UsingClient, data: GatewayChannelCreateDispatchData) => AllChannels;
|
|
5
|
+
export declare const CHANNEL_DELETE: (self: UsingClient, data: GatewayChannelDeleteDispatchData) => AllChannels;
|
|
6
|
+
export declare const CHANNEL_PINS_UPDATE: (_self: UsingClient, data: GatewayChannelPinsUpdateDispatchData) => {
|
|
7
7
|
guildId?: string | undefined;
|
|
8
8
|
channelId: string;
|
|
9
9
|
lastPinTimestamp?: string | null | undefined;
|
|
10
10
|
};
|
|
11
|
-
export declare const CHANNEL_UPDATE: (self:
|
|
11
|
+
export declare const CHANNEL_UPDATE: (self: UsingClient, data: GatewayChannelUpdateDispatchData) => Promise<[channel: AllChannels, old?: AllChannels]>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { UsingClient } from '../../commands';
|
|
2
2
|
import type { ClientUser } from '../../structures';
|
|
3
|
-
export declare const BOT_READY: (_self:
|
|
4
|
-
export declare const WORKER_READY: (_self:
|
|
3
|
+
export declare const BOT_READY: (_self: UsingClient, me: ClientUser) => ClientUser;
|
|
4
|
+
export declare const WORKER_READY: (_self: UsingClient, me: ClientUser) => ClientUser;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GatewayDispatchPayload, GatewayReadyDispatchData, GatewayResumedDispatch } from 'discord-api-types/v10';
|
|
2
|
-
import type { BaseClient } from '../../client/base';
|
|
3
2
|
import { ClientUser } from '../../structures';
|
|
4
|
-
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
3
|
+
import type { UsingClient } from '../../commands';
|
|
4
|
+
export declare const READY: (self: UsingClient, data: GatewayReadyDispatchData) => ClientUser;
|
|
5
|
+
export declare const RESUMED: (_self: UsingClient, _data: GatewayResumedDispatch['d']) => void;
|
|
6
|
+
export declare const RAW: (_self: UsingClient, data: GatewayDispatchPayload) => GatewayDispatchPayload;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { APIEntitlement } from 'discord-api-types/v10';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const ENTITLEMENT_CREATE: (_:
|
|
2
|
+
import type { UsingClient } from '../../commands';
|
|
3
|
+
export declare const ENTITLEMENT_CREATE: (_: UsingClient, data: APIEntitlement) => {
|
|
4
4
|
id: string;
|
|
5
5
|
skuId: string;
|
|
6
6
|
userId?: string | undefined;
|
|
@@ -12,7 +12,7 @@ export declare const ENTITLEMENT_CREATE: (_: BaseClient, data: APIEntitlement) =
|
|
|
12
12
|
endsAt?: string | undefined;
|
|
13
13
|
consumed?: boolean | undefined;
|
|
14
14
|
};
|
|
15
|
-
export declare const ENTITLEMENT_UPDATE: (_:
|
|
15
|
+
export declare const ENTITLEMENT_UPDATE: (_: UsingClient, data: APIEntitlement) => {
|
|
16
16
|
id: string;
|
|
17
17
|
skuId: string;
|
|
18
18
|
userId?: string | undefined;
|
|
@@ -24,7 +24,7 @@ export declare const ENTITLEMENT_UPDATE: (_: BaseClient, data: APIEntitlement) =
|
|
|
24
24
|
endsAt?: string | undefined;
|
|
25
25
|
consumed?: boolean | undefined;
|
|
26
26
|
};
|
|
27
|
-
export declare const ENTITLEMENT_DELETE: (_:
|
|
27
|
+
export declare const ENTITLEMENT_DELETE: (_: UsingClient, data: APIEntitlement) => {
|
|
28
28
|
id: string;
|
|
29
29
|
skuId: string;
|
|
30
30
|
userId?: string | undefined;
|