seyfert 1.4.0 → 1.5.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/README.md +7 -7
- package/lib/api/Router.js +3 -1
- package/lib/api/Routes/guilds.d.ts +4 -1
- package/lib/cache/index.d.ts +6 -2
- package/lib/cache/index.js +18 -0
- package/lib/cache/resources/bans.d.ts +12 -0
- package/lib/cache/resources/bans.js +35 -0
- package/lib/cache/resources/members.js +4 -4
- package/lib/cache/resources/messages.js +8 -6
- package/lib/client/base.d.ts +7 -3
- package/lib/client/base.js +43 -24
- package/lib/client/client.d.ts +17 -5
- package/lib/client/client.js +39 -43
- package/lib/client/collectors.d.ts +36 -0
- package/lib/client/collectors.js +85 -0
- package/lib/client/httpclient.js +6 -6
- package/lib/client/onmessagecreate.d.ts +12 -2
- package/lib/client/onmessagecreate.js +32 -17
- package/lib/client/workerclient.d.ts +4 -1
- package/lib/client/workerclient.js +59 -67
- package/lib/collection.d.ts +2 -2
- package/lib/collection.js +2 -2
- package/lib/commands/applications/chat.d.ts +10 -9
- package/lib/commands/applications/chat.js +21 -7
- package/lib/commands/applications/menu.d.ts +8 -7
- package/lib/commands/applications/menu.js +3 -2
- package/lib/commands/applications/shared.d.ts +12 -0
- package/lib/commands/decorators.d.ts +11 -17
- package/lib/commands/decorators.js +7 -14
- package/lib/commands/handler.js +39 -29
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.js +3 -1
- package/lib/common/it/formatter.d.ts +155 -0
- package/lib/common/it/formatter.js +184 -0
- package/lib/common/it/logger.js +5 -5
- package/lib/common/it/utils.js +2 -4
- package/lib/common/shorters/bans.d.ts +43 -0
- package/lib/common/shorters/bans.js +78 -0
- package/lib/common/shorters/emojis.d.ts +1 -1
- package/lib/common/shorters/emojis.js +4 -3
- package/lib/common/shorters/interaction.js +9 -7
- package/lib/common/shorters/messages.js +2 -2
- package/lib/common/shorters/webhook.js +2 -2
- package/lib/components/componentcommand.d.ts +3 -2
- package/lib/components/componentcommand.js +2 -1
- package/lib/components/componentcontext.d.ts +1 -1
- package/lib/components/handler.d.ts +1 -1
- package/lib/components/handler.js +25 -28
- package/lib/components/modalcommand.d.ts +2 -1
- package/lib/components/modalcommand.js +1 -0
- package/lib/components/modalcontext.d.ts +1 -1
- package/lib/events/event.d.ts +4 -3
- package/lib/events/handler.d.ts +8 -5
- package/lib/events/handler.js +58 -13
- package/lib/events/hooks/guild.d.ts +18 -73
- package/lib/events/hooks/integration.d.ts +57 -0
- package/lib/events/hooks/invite.d.ts +3 -0
- package/lib/events/hooks/message.d.ts +11 -6
- package/lib/events/hooks/presence.d.ts +4 -0
- package/lib/events/hooks/thread.d.ts +14 -3
- package/lib/events/hooks/typing.d.ts +1 -0
- package/lib/index.d.ts +3 -3
- package/lib/index.js +3 -2
- package/lib/structures/Guild.d.ts +9 -1
- package/lib/structures/Guild.js +2 -0
- package/lib/structures/GuildBan.d.ts +25 -0
- package/lib/structures/GuildBan.js +36 -0
- package/lib/structures/GuildEmoji.d.ts +1 -1
- package/lib/structures/GuildMember.d.ts +7 -2
- package/lib/structures/GuildMember.js +4 -4
- package/lib/structures/Interaction.d.ts +3 -2
- package/lib/structures/Interaction.js +21 -9
- package/lib/structures/Message.d.ts +69 -8
- package/lib/structures/Message.js +59 -17
- package/lib/structures/Sticker.d.ts +3 -3
- package/lib/structures/User.d.ts +1 -0
- package/lib/structures/User.js +4 -1
- package/lib/structures/channels.d.ts +4 -1
- package/lib/structures/channels.js +36 -6
- package/lib/structures/extra/functions.js +1 -1
- package/lib/websocket/discord/basesocket.d.ts +1 -0
- package/lib/websocket/discord/basesocket.js +17 -0
- package/lib/websocket/discord/shard.d.ts +1 -0
- package/lib/websocket/discord/shard.js +6 -0
- package/package.json +8 -8
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BanShorter = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
const GuildBan_1 = require("../../structures/GuildBan");
|
|
6
|
+
class BanShorter extends base_1.BaseShorter {
|
|
7
|
+
/**
|
|
8
|
+
* Bulk creates bans in the guild.
|
|
9
|
+
* @param guildId The ID of the guild.
|
|
10
|
+
* @param body The request body for bulk banning members.
|
|
11
|
+
* @param reason The reason for bulk banning members.
|
|
12
|
+
*/
|
|
13
|
+
async bulkCreate(guildId, body, reason) {
|
|
14
|
+
const bans = await this.client.proxy.guilds(guildId)['bulk-bans'].post({ reason, body });
|
|
15
|
+
for (const id of bans.banned_users)
|
|
16
|
+
this.client.cache.members?.removeIfNI('GuildBans', id, guildId);
|
|
17
|
+
return bans;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Unbans a member from the guild.
|
|
21
|
+
* @param guildId The ID of the guild.
|
|
22
|
+
* @param memberId The ID of the member to unban.
|
|
23
|
+
* @param reason The reason for unbanning the member.
|
|
24
|
+
*/
|
|
25
|
+
async remove(guildId, memberId, reason) {
|
|
26
|
+
await this.client.proxy.guilds(guildId).bans(memberId).delete({ reason });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Bans a member from the guild.
|
|
30
|
+
* @param guildId The ID of the guild.
|
|
31
|
+
* @param memberId The ID of the member to ban.
|
|
32
|
+
* @param body The request body for banning the member.
|
|
33
|
+
* @param reason The reason for banning the member.
|
|
34
|
+
*/
|
|
35
|
+
async create(guildId, memberId, body, reason) {
|
|
36
|
+
await this.client.proxy.guilds(guildId).bans(memberId).put({ reason, body });
|
|
37
|
+
await this.client.cache.members?.removeIfNI('GuildBans', memberId, guildId);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Fetches a ban from the guild.
|
|
41
|
+
* @param guildId The ID of the guild.
|
|
42
|
+
* @param userId The ID of the user to fetch.
|
|
43
|
+
* @param force Whether to force fetching the ban from the API even if it exists in the cache.
|
|
44
|
+
* @returns A Promise that resolves to the fetched ban.
|
|
45
|
+
*/
|
|
46
|
+
async fetch(guildId, userId, force = false) {
|
|
47
|
+
let ban;
|
|
48
|
+
if (!force) {
|
|
49
|
+
ban = await this.client.cache.bans?.get(userId, guildId);
|
|
50
|
+
if (ban)
|
|
51
|
+
return ban;
|
|
52
|
+
}
|
|
53
|
+
ban = await this.client.proxy.guilds(guildId).bans(userId).get();
|
|
54
|
+
await this.client.cache.members?.set(ban.user.id, guildId, ban);
|
|
55
|
+
return new GuildBan_1.GuildBan(this.client, ban, guildId);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Lists bans in the guild based on the provided query.
|
|
59
|
+
* @param guildId The ID of the guild.
|
|
60
|
+
* @param query The query parameters for listing bans.
|
|
61
|
+
* @param force Whether to force listing bans from the API even if they exist in the cache.
|
|
62
|
+
* @returns A Promise that resolves to an array of listed bans.
|
|
63
|
+
*/
|
|
64
|
+
async list(guildId, query, force = false) {
|
|
65
|
+
let bans;
|
|
66
|
+
if (!force) {
|
|
67
|
+
bans = (await this.client.cache.bans?.values(guildId)) ?? [];
|
|
68
|
+
if (bans.length)
|
|
69
|
+
return bans;
|
|
70
|
+
}
|
|
71
|
+
bans = await this.client.proxy.guilds(guildId).bans.get({
|
|
72
|
+
query,
|
|
73
|
+
});
|
|
74
|
+
await this.client.cache.bans?.set(bans.map(x => [x.user.id, x]), guildId);
|
|
75
|
+
return bans.map(m => new GuildBan_1.GuildBan(this.client, m, guildId));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.BanShorter = BanShorter;
|
|
@@ -19,7 +19,7 @@ export declare class EmojiShorter extends BaseShorter {
|
|
|
19
19
|
*/
|
|
20
20
|
create(guildId: string, body: OmitInsert<RESTPostAPIGuildEmojiJSONBody, 'image', {
|
|
21
21
|
image: ImageResolvable;
|
|
22
|
-
}>): Promise<
|
|
22
|
+
}>): Promise<GuildEmoji>;
|
|
23
23
|
/**
|
|
24
24
|
* Fetches an emoji by its ID.
|
|
25
25
|
* @param guildId The ID of the guild.
|
|
@@ -34,7 +34,8 @@ class EmojiShorter extends base_1.BaseShorter {
|
|
|
34
34
|
const emoji = await this.client.proxy.guilds(guildId).emojis.post({
|
|
35
35
|
body: bodyResolved,
|
|
36
36
|
});
|
|
37
|
-
await this.client.cache.
|
|
37
|
+
await this.client.cache.emojis?.setIfNI('GuildEmojisAndStickers', emoji.id, guildId, emoji);
|
|
38
|
+
return new __1.GuildEmoji(this.client, emoji, guildId);
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
41
|
* Fetches an emoji by its ID.
|
|
@@ -61,7 +62,7 @@ class EmojiShorter extends base_1.BaseShorter {
|
|
|
61
62
|
*/
|
|
62
63
|
async delete(guildId, emojiId, reason) {
|
|
63
64
|
await this.client.proxy.guilds(guildId).emojis(emojiId).delete({ reason });
|
|
64
|
-
await this.client.cache.
|
|
65
|
+
await this.client.cache.emojis?.removeIfNI('GuildEmojisAndStickers', emojiId, guildId);
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* Edits an emoji in the guild.
|
|
@@ -73,7 +74,7 @@ class EmojiShorter extends base_1.BaseShorter {
|
|
|
73
74
|
*/
|
|
74
75
|
async edit(guildId, emojiId, body, reason) {
|
|
75
76
|
const emoji = await this.client.proxy.guilds(guildId).emojis(emojiId).patch({ body, reason });
|
|
76
|
-
await this.client.cache.
|
|
77
|
+
await this.client.cache.emojis?.setIfNI('GuildEmojisAndStickers', emoji.id, guildId, emoji);
|
|
77
78
|
return new __1.GuildEmoji(this.client, emoji, guildId);
|
|
78
79
|
}
|
|
79
80
|
}
|
|
@@ -9,14 +9,15 @@ class InteractionShorter extends base_1.BaseShorter {
|
|
|
9
9
|
const { files, ...rest } = body.data ?? {};
|
|
10
10
|
//@ts-expect-error
|
|
11
11
|
const data = body.data instanceof __1.Modal ? body.data : rest;
|
|
12
|
+
const parsedFiles = files ? await (0, __1.resolveFiles)(files) : undefined;
|
|
12
13
|
return this.client.proxy
|
|
13
14
|
.interactions(id)(token)
|
|
14
15
|
.callback.post({
|
|
15
16
|
body: __1.BaseInteraction.transformBodyRequest({
|
|
16
17
|
type: body.type,
|
|
17
18
|
data,
|
|
18
|
-
}, this.client),
|
|
19
|
-
files:
|
|
19
|
+
}, parsedFiles, this.client),
|
|
20
|
+
files: parsedFiles,
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
23
|
fetchResponse(token, messageId) {
|
|
@@ -27,12 +28,13 @@ class InteractionShorter extends base_1.BaseShorter {
|
|
|
27
28
|
}
|
|
28
29
|
async editMessage(token, messageId, body) {
|
|
29
30
|
const { files, ...data } = body;
|
|
31
|
+
const parsedFiles = files ? await (0, __1.resolveFiles)(files) : undefined;
|
|
30
32
|
const apiMessage = await this.client.proxy
|
|
31
33
|
.webhooks(this.client.applicationId)(token)
|
|
32
34
|
.messages(messageId)
|
|
33
35
|
.patch({
|
|
34
|
-
body: __1.BaseInteraction.transformBody(data, this.client),
|
|
35
|
-
files:
|
|
36
|
+
body: __1.BaseInteraction.transformBody(data, parsedFiles, this.client),
|
|
37
|
+
files: parsedFiles,
|
|
36
38
|
});
|
|
37
39
|
return new __1.WebhookMessage(this.client, apiMessage, this.client.applicationId, token);
|
|
38
40
|
}
|
|
@@ -50,12 +52,12 @@ class InteractionShorter extends base_1.BaseShorter {
|
|
|
50
52
|
return this.deleteResponse(interactionId, token, '@original');
|
|
51
53
|
}
|
|
52
54
|
async followup(token, { files, ...body }) {
|
|
53
|
-
|
|
55
|
+
const parsedFiles = files ? await (0, __1.resolveFiles)(files) : undefined;
|
|
54
56
|
const apiMessage = await this.client.proxy
|
|
55
57
|
.webhooks(this.client.applicationId)(token)
|
|
56
58
|
.post({
|
|
57
|
-
body: __1.BaseInteraction.transformBody(body, this.client),
|
|
58
|
-
files:
|
|
59
|
+
body: __1.BaseInteraction.transformBody(body, parsedFiles, this.client),
|
|
60
|
+
files: parsedFiles,
|
|
59
61
|
});
|
|
60
62
|
return new __1.WebhookMessage(this.client, apiMessage, this.client.applicationId, token);
|
|
61
63
|
}
|
|
@@ -7,7 +7,7 @@ const base_1 = require("./base");
|
|
|
7
7
|
class MessageShorter extends base_1.BaseShorter {
|
|
8
8
|
async write(channelId, { files, ...body }) {
|
|
9
9
|
const parsedFiles = files ? await (0, builders_1.resolveFiles)(files) : [];
|
|
10
|
-
const transformedBody = structures_1.MessagesMethods.transformMessageBody(body, this.client);
|
|
10
|
+
const transformedBody = structures_1.MessagesMethods.transformMessageBody(body, parsedFiles, this.client);
|
|
11
11
|
return this.client.proxy
|
|
12
12
|
.channels(channelId)
|
|
13
13
|
.messages.post({
|
|
@@ -25,7 +25,7 @@ class MessageShorter extends base_1.BaseShorter {
|
|
|
25
25
|
.channels(channelId)
|
|
26
26
|
.messages(messageId)
|
|
27
27
|
.patch({
|
|
28
|
-
body: structures_1.MessagesMethods.transformMessageBody(body, this.client),
|
|
28
|
+
body: structures_1.MessagesMethods.transformMessageBody(body, parsedFiles, this.client),
|
|
29
29
|
files: parsedFiles,
|
|
30
30
|
})
|
|
31
31
|
.then(async (message) => {
|
|
@@ -67,8 +67,8 @@ class WebhookShorter extends base_1.BaseShorter {
|
|
|
67
67
|
*/
|
|
68
68
|
async writeMessage(webhookId, token, { body: data, ...payload }) {
|
|
69
69
|
const { files, ...body } = data;
|
|
70
|
-
const transformedBody = structures_1.MessagesMethods.transformMessageBody(body, this.client);
|
|
71
70
|
const parsedFiles = files ? await (0, builders_1.resolveFiles)(files) : [];
|
|
71
|
+
const transformedBody = structures_1.MessagesMethods.transformMessageBody(body, parsedFiles, this.client);
|
|
72
72
|
return this.client.proxy
|
|
73
73
|
.webhooks(webhookId)(token)
|
|
74
74
|
.post({ ...payload, files: parsedFiles, body: transformedBody })
|
|
@@ -84,8 +84,8 @@ class WebhookShorter extends base_1.BaseShorter {
|
|
|
84
84
|
*/
|
|
85
85
|
async editMessage(webhookId, token, { messageId, body: data, ...json }) {
|
|
86
86
|
const { files, ...body } = data;
|
|
87
|
-
const transformedBody = structures_1.MessagesMethods.transformMessageBody(body, this.client);
|
|
88
87
|
const parsedFiles = files ? await (0, builders_1.resolveFiles)(files) : [];
|
|
88
|
+
const transformedBody = structures_1.MessagesMethods.transformMessageBody(body, parsedFiles, this.client);
|
|
89
89
|
return this.client.proxy
|
|
90
90
|
.webhooks(webhookId)(token)
|
|
91
91
|
.messages(messageId)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ContextComponentCommandInteractionMap, ComponentContext } from './componentcontext';
|
|
2
|
-
import type { RegisteredMiddlewares, UsingClient } from '../commands';
|
|
2
|
+
import type { ExtraProps, RegisteredMiddlewares, UsingClient } from '../commands';
|
|
3
3
|
export declare const InteractionCommandType: {
|
|
4
4
|
readonly COMPONENT: 0;
|
|
5
5
|
readonly MODAL: 1;
|
|
@@ -12,10 +12,11 @@ export declare abstract class ComponentCommand {
|
|
|
12
12
|
abstract componentType: keyof ContextComponentCommandInteractionMap;
|
|
13
13
|
abstract filter(context: ComponentContext<typeof this.componentType>): Promise<boolean> | boolean;
|
|
14
14
|
abstract run(context: ComponentContext<typeof this.componentType>): any;
|
|
15
|
+
middlewares: (keyof RegisteredMiddlewares)[];
|
|
16
|
+
props: ExtraProps;
|
|
15
17
|
get cType(): number;
|
|
16
18
|
onAfterRun?(context: ComponentContext, error: unknown | undefined): any;
|
|
17
19
|
onRunError?(context: ComponentContext, error: unknown): any;
|
|
18
20
|
onMiddlewaresError?(context: ComponentContext, error: string): any;
|
|
19
21
|
onInternalError?(client: UsingClient, error?: unknown): any;
|
|
20
|
-
middlewares: (keyof RegisteredMiddlewares)[];
|
|
21
22
|
}
|
|
@@ -8,9 +8,10 @@ exports.InteractionCommandType = {
|
|
|
8
8
|
};
|
|
9
9
|
class ComponentCommand {
|
|
10
10
|
type = exports.InteractionCommandType.COMPONENT;
|
|
11
|
+
middlewares = [];
|
|
12
|
+
props;
|
|
11
13
|
get cType() {
|
|
12
14
|
return v10_1.ComponentType[this.componentType];
|
|
13
15
|
}
|
|
14
|
-
middlewares = [];
|
|
15
16
|
}
|
|
16
17
|
exports.ComponentCommand = ComponentCommand;
|
|
@@ -17,7 +17,7 @@ export declare class ComponentContext<Type extends keyof ContextComponentCommand
|
|
|
17
17
|
* @param interaction - The component interaction object.
|
|
18
18
|
*/
|
|
19
19
|
constructor(client: UsingClient, interaction: ContextComponentCommandInteractionMap[Type]);
|
|
20
|
-
command
|
|
20
|
+
command: ComponentCommand;
|
|
21
21
|
metadata: CommandMetadata<UnionToTuple<M>>;
|
|
22
22
|
globalMetadata: GlobalMetadata;
|
|
23
23
|
/**
|
|
@@ -42,7 +42,7 @@ export declare class ComponentHandler extends BaseHandler {
|
|
|
42
42
|
new (): ModalCommand | ComponentCommand;
|
|
43
43
|
}[]): Promise<void>;
|
|
44
44
|
reload(path: string): Promise<any>;
|
|
45
|
-
reloadAll(): Promise<void>;
|
|
45
|
+
reloadAll(stopIfFail?: boolean): Promise<void>;
|
|
46
46
|
executeComponent(context: ComponentContext): Promise<any>;
|
|
47
47
|
executeModal(context: ModalContext): Promise<any>;
|
|
48
48
|
setHandlers({ callback }: {
|
|
@@ -22,7 +22,7 @@ class ComponentHandler extends common_1.BaseHandler {
|
|
|
22
22
|
this.values.set(messageId, {
|
|
23
23
|
components: [],
|
|
24
24
|
options,
|
|
25
|
-
idle: options.idle
|
|
25
|
+
idle: options.idle && options.idle > 0
|
|
26
26
|
? setTimeout(() => {
|
|
27
27
|
this.deleteValue(messageId);
|
|
28
28
|
options.onStop?.('idle', () => {
|
|
@@ -30,7 +30,7 @@ class ComponentHandler extends common_1.BaseHandler {
|
|
|
30
30
|
});
|
|
31
31
|
}, options.idle)
|
|
32
32
|
: undefined,
|
|
33
|
-
timeout: options.timeout
|
|
33
|
+
timeout: options.timeout && options.timeout > 0
|
|
34
34
|
? setTimeout(() => {
|
|
35
35
|
this.deleteValue(messageId);
|
|
36
36
|
options.onStop?.('timeout', () => {
|
|
@@ -122,39 +122,33 @@ class ComponentHandler extends common_1.BaseHandler {
|
|
|
122
122
|
const i = new x();
|
|
123
123
|
return { file: x, path: i.__filePath ?? '*' };
|
|
124
124
|
}) ?? (await this.loadFilesK(await this.getFiles(componentsDir)));
|
|
125
|
-
for (
|
|
125
|
+
for (const value of paths) {
|
|
126
126
|
let component;
|
|
127
127
|
try {
|
|
128
|
-
component = this.callback(
|
|
128
|
+
component = this.callback(value.file);
|
|
129
129
|
if (!component)
|
|
130
130
|
continue;
|
|
131
131
|
}
|
|
132
132
|
catch (e) {
|
|
133
133
|
if (e instanceof Error && e.message.includes('is not a constructor')) {
|
|
134
|
-
this.logger.warn(`${
|
|
134
|
+
this.logger.warn(`${value.path
|
|
135
135
|
.split(process.cwd())
|
|
136
136
|
.slice(1)
|
|
137
137
|
.join(process.cwd())} doesn't export the class by \`export default <ComponentCommand>\``);
|
|
138
138
|
}
|
|
139
139
|
else
|
|
140
|
-
this.logger.warn(e,
|
|
140
|
+
this.logger.warn(e, value);
|
|
141
141
|
continue;
|
|
142
142
|
}
|
|
143
|
-
if (!(component instanceof modalcommand_1.ModalCommand
|
|
143
|
+
if (!(component instanceof modalcommand_1.ModalCommand || component instanceof componentcommand_1.ComponentCommand))
|
|
144
144
|
continue;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
}
|
|
157
|
-
component.__filePath = paths[i].path;
|
|
145
|
+
component.props ??= this.client.options.commands?.defaults?.props ?? {};
|
|
146
|
+
const is = component instanceof modalcommand_1.ModalCommand ? 'modals' : 'components';
|
|
147
|
+
component.onInternalError ??= this.client.options?.[is]?.defaults?.onInternalError;
|
|
148
|
+
component.onMiddlewaresError ??= this.client.options?.[is]?.defaults?.onMiddlewaresError;
|
|
149
|
+
component.onRunError ??= this.client.options?.[is]?.defaults?.onRunError;
|
|
150
|
+
component.onAfterRun ??= this.client.options?.[is]?.defaults?.onAfterRun;
|
|
151
|
+
component.__filePath = value.path;
|
|
158
152
|
this.commands.push(component);
|
|
159
153
|
}
|
|
160
154
|
}
|
|
@@ -165,7 +159,7 @@ class ComponentHandler extends common_1.BaseHandler {
|
|
|
165
159
|
x.__filePath?.endsWith(`${path}.ts`) ||
|
|
166
160
|
x.__filePath?.endsWith(path) ||
|
|
167
161
|
x.__filePath === path);
|
|
168
|
-
if (!component
|
|
162
|
+
if (!component?.__filePath)
|
|
169
163
|
return null;
|
|
170
164
|
delete require.cache[component.__filePath];
|
|
171
165
|
const index = this.client.components.commands.findIndex(x => x.__filePath === component.__filePath);
|
|
@@ -178,13 +172,16 @@ class ComponentHandler extends common_1.BaseHandler {
|
|
|
178
172
|
this.client.components.commands.push(command);
|
|
179
173
|
return imported;
|
|
180
174
|
}
|
|
181
|
-
async reloadAll() {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
175
|
+
async reloadAll(stopIfFail = true) {
|
|
176
|
+
for (const i of this.commands) {
|
|
177
|
+
try {
|
|
178
|
+
await this.reload(i.__filePath ?? '');
|
|
179
|
+
}
|
|
180
|
+
catch (e) {
|
|
181
|
+
if (stopIfFail) {
|
|
182
|
+
throw e;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
188
185
|
}
|
|
189
186
|
}
|
|
190
187
|
async executeComponent(context) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RegisteredMiddlewares, UsingClient } from '../commands';
|
|
1
|
+
import type { ExtraProps, RegisteredMiddlewares, UsingClient } from '../commands';
|
|
2
2
|
import type { ModalContext } from './modalcontext';
|
|
3
3
|
export interface ModalCommand {
|
|
4
4
|
__filePath?: string;
|
|
@@ -8,6 +8,7 @@ export declare abstract class ModalCommand {
|
|
|
8
8
|
abstract filter(context: ModalContext): Promise<boolean> | boolean;
|
|
9
9
|
abstract run(context: ModalContext): any;
|
|
10
10
|
middlewares: (keyof RegisteredMiddlewares)[];
|
|
11
|
+
props: ExtraProps;
|
|
11
12
|
onAfterRun?(context: ModalContext, error: unknown | undefined): any;
|
|
12
13
|
onRunError?(context: ModalContext, error: unknown): any;
|
|
13
14
|
onMiddlewaresError?(context: ModalContext, error: string): any;
|
|
@@ -17,7 +17,7 @@ export declare class ModalContext<M extends keyof RegisteredMiddlewares = never>
|
|
|
17
17
|
* @param interaction - The component interaction object.
|
|
18
18
|
*/
|
|
19
19
|
constructor(client: UsingClient, interaction: ModalSubmitInteraction);
|
|
20
|
-
command
|
|
20
|
+
command: ModalCommand;
|
|
21
21
|
metadata: CommandMetadata<UnionToTuple<M>>;
|
|
22
22
|
globalMetadata: GlobalMetadata;
|
|
23
23
|
get customId(): string;
|
package/lib/events/event.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import type { UsingClient } from '../commands';
|
|
2
2
|
import type { ClientEvents } from './hooks';
|
|
3
|
-
export interface
|
|
4
|
-
name: `${keyof ClientEvents}`;
|
|
5
|
-
once?: boolean;
|
|
3
|
+
export interface CustomEvents {
|
|
6
4
|
}
|
|
7
5
|
export type ClientNameEvents = Extract<keyof ClientEvents, string>;
|
|
6
|
+
export type CustomEventsKeys = Extract<keyof CustomEvents, string>;
|
|
8
7
|
export interface ClientDataEvent {
|
|
9
8
|
name: ClientNameEvents;
|
|
10
9
|
once: boolean;
|
|
11
10
|
}
|
|
12
11
|
export type CallbackEventHandler = {
|
|
13
12
|
[K in keyof ClientEvents]: (...data: [Awaited<ClientEvents[K]>, UsingClient, number]) => unknown;
|
|
13
|
+
} & {
|
|
14
|
+
[K in keyof CustomEvents]: (...data: [Parameters<CustomEvents[K]>, UsingClient, number]) => unknown;
|
|
14
15
|
};
|
|
15
16
|
export type EventContext<T extends {
|
|
16
17
|
data: {
|
package/lib/events/handler.d.ts
CHANGED
|
@@ -2,23 +2,26 @@ import type { GatewayDispatchPayload } from 'discord-api-types/v10';
|
|
|
2
2
|
import type { Client, WorkerClient } from '../client';
|
|
3
3
|
import { BaseHandler, type MakeRequired, type SnakeCase } from '../common';
|
|
4
4
|
import type { ClientEvents } from '../events/hooks';
|
|
5
|
-
import type { ClientEvent,
|
|
5
|
+
import type { ClientEvent, CustomEvents, CustomEventsKeys } from './event';
|
|
6
6
|
export type EventValue = MakeRequired<ClientEvent, '__filePath'> & {
|
|
7
7
|
fired?: boolean;
|
|
8
8
|
};
|
|
9
9
|
export type GatewayEvents = Uppercase<SnakeCase<keyof ClientEvents>>;
|
|
10
10
|
export declare class EventHandler extends BaseHandler {
|
|
11
|
-
|
|
11
|
+
protected client: Client | WorkerClient;
|
|
12
|
+
constructor(client: Client | WorkerClient);
|
|
13
|
+
onFail: (event: GatewayEvents | CustomEventsKeys, err: unknown) => void;
|
|
12
14
|
protected filter: (path: string) => boolean;
|
|
13
|
-
values: Partial<Record<GatewayEvents, EventValue>>;
|
|
15
|
+
values: Partial<Record<GatewayEvents | CustomEventsKeys, EventValue>>;
|
|
14
16
|
load(eventsDir: string, instances?: {
|
|
15
17
|
file: ClientEvent;
|
|
16
18
|
path: string;
|
|
17
19
|
}[]): Promise<void>;
|
|
18
20
|
execute(name: GatewayEvents, ...args: [GatewayDispatchPayload, Client<true> | WorkerClient<true>, number]): Promise<void>;
|
|
19
21
|
runEvent(name: GatewayEvents, client: Client | WorkerClient, packet: any, shardId: number): Promise<void>;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
runCustom<T extends CustomEventsKeys>(name: T, ...args: Parameters<CustomEvents[T]>): Promise<void>;
|
|
23
|
+
reload(name: GatewayEvents | CustomEventsKeys): Promise<any>;
|
|
24
|
+
reloadAll(stopIfFail?: boolean): Promise<void>;
|
|
22
25
|
setHandlers({ callback }: {
|
|
23
26
|
callback: EventHandler['callback'];
|
|
24
27
|
}): void;
|
package/lib/events/handler.js
CHANGED
|
@@ -27,10 +27,16 @@ exports.EventHandler = void 0;
|
|
|
27
27
|
const common_1 = require("../common");
|
|
28
28
|
const RawEvents = __importStar(require("../events/hooks"));
|
|
29
29
|
class EventHandler extends common_1.BaseHandler {
|
|
30
|
+
client;
|
|
31
|
+
constructor(client) {
|
|
32
|
+
super(client.logger);
|
|
33
|
+
this.client = client;
|
|
34
|
+
}
|
|
30
35
|
onFail = (event, err) => this.logger.warn('<Client>.events.onFail', err, event);
|
|
31
36
|
filter = (path) => path.endsWith('.js') || (!path.endsWith('.d.ts') && path.endsWith('.ts'));
|
|
32
37
|
values = {};
|
|
33
38
|
async load(eventsDir, instances) {
|
|
39
|
+
const discordEvents = Object.keys(RawEvents).map(x => common_1.ReplaceRegex.camel(x.toLowerCase()));
|
|
34
40
|
for (const i of instances ?? (await this.loadFilesK(await this.getFiles(eventsDir)))) {
|
|
35
41
|
const instance = this.callback(i.file);
|
|
36
42
|
if (!instance)
|
|
@@ -40,7 +46,9 @@ class EventHandler extends common_1.BaseHandler {
|
|
|
40
46
|
continue;
|
|
41
47
|
}
|
|
42
48
|
instance.__filePath = i.path;
|
|
43
|
-
this.values[
|
|
49
|
+
this.values[discordEvents.includes(instance.data.name)
|
|
50
|
+
? common_1.ReplaceRegex.snake(instance.data.name).toUpperCase()
|
|
51
|
+
: instance.data.name] = instance;
|
|
44
52
|
}
|
|
45
53
|
}
|
|
46
54
|
async execute(name, ...args) {
|
|
@@ -48,8 +56,8 @@ class EventHandler extends common_1.BaseHandler {
|
|
|
48
56
|
case 'MESSAGE_CREATE':
|
|
49
57
|
{
|
|
50
58
|
const { d: data } = args[0];
|
|
51
|
-
if (args[1].components?.values.has(data.
|
|
52
|
-
args[1].components.values.get(data.
|
|
59
|
+
if (args[1].components?.values.has(data.interaction_metadata?.id ?? data.id)) {
|
|
60
|
+
args[1].components.values.get(data.interaction_metadata?.id ?? data.id).messageId = data.id;
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
63
|
break;
|
|
@@ -75,39 +83,76 @@ class EventHandler extends common_1.BaseHandler {
|
|
|
75
83
|
}
|
|
76
84
|
break;
|
|
77
85
|
}
|
|
78
|
-
await
|
|
86
|
+
await Promise.all([
|
|
87
|
+
this.runEvent(args[0].t, args[1], args[0].d, args[2]),
|
|
88
|
+
this.client.collectors.run(args[0].t, args[0].d),
|
|
89
|
+
]);
|
|
79
90
|
}
|
|
80
91
|
async runEvent(name, client, packet, shardId) {
|
|
81
92
|
const Event = this.values[name];
|
|
82
93
|
if (!Event) {
|
|
83
|
-
return
|
|
94
|
+
return this.client.cache.onPacket({
|
|
95
|
+
t: name,
|
|
96
|
+
d: packet,
|
|
97
|
+
});
|
|
84
98
|
}
|
|
85
99
|
try {
|
|
86
100
|
if (Event.data.once && Event.fired) {
|
|
87
|
-
return
|
|
101
|
+
return this.client.cache.onPacket({
|
|
102
|
+
t: name,
|
|
103
|
+
d: packet,
|
|
104
|
+
});
|
|
88
105
|
}
|
|
89
106
|
Event.fired = true;
|
|
90
107
|
const hook = await RawEvents[name]?.(client, packet);
|
|
91
|
-
|
|
108
|
+
if (name !== 'RAW')
|
|
109
|
+
await this.client.cache.onPacket({
|
|
110
|
+
t: name,
|
|
111
|
+
d: packet,
|
|
112
|
+
});
|
|
113
|
+
await Event.run(hook, client, shardId);
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
await this.onFail(name, e);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async runCustom(name, ...args) {
|
|
120
|
+
const Event = this.values[name];
|
|
121
|
+
if (!Event) {
|
|
122
|
+
return this.client.collectors.run(name, args);
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
if (Event.data.once && Event.fired) {
|
|
126
|
+
return this.client.collectors.run(name, args);
|
|
127
|
+
}
|
|
128
|
+
Event.fired = true;
|
|
129
|
+
this.logger.debug(`executed a custom event [${name}]`, Event.data.once ? 'once' : '');
|
|
130
|
+
await Promise.all([Event.run(args, this.client), this.client.collectors.run(name, args)]);
|
|
92
131
|
}
|
|
93
132
|
catch (e) {
|
|
94
133
|
await this.onFail(name, e);
|
|
95
134
|
}
|
|
96
135
|
}
|
|
97
136
|
async reload(name) {
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
if (!event)
|
|
137
|
+
const event = this.values[name];
|
|
138
|
+
if (!event?.__filePath)
|
|
101
139
|
return null;
|
|
102
140
|
delete require.cache[event.__filePath];
|
|
103
141
|
const imported = await (0, common_1.magicImport)(event.__filePath).then(x => x.default ?? x);
|
|
104
142
|
imported.__filePath = event.__filePath;
|
|
105
|
-
this.values[
|
|
143
|
+
this.values[name] = imported;
|
|
106
144
|
return imported;
|
|
107
145
|
}
|
|
108
|
-
async reloadAll() {
|
|
146
|
+
async reloadAll(stopIfFail = true) {
|
|
109
147
|
for (const i in this.values) {
|
|
110
|
-
|
|
148
|
+
try {
|
|
149
|
+
await this.reload(i);
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
if (stopIfFail) {
|
|
153
|
+
throw e;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
111
156
|
}
|
|
112
157
|
}
|
|
113
158
|
setHandlers({ callback }) {
|