seyfert 2.0.0 → 2.1.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/Routes/interactions.d.ts +8 -2
- package/lib/api/Routes/skus.d.ts +11 -0
- package/lib/api/Routes/skus.js +2 -0
- package/lib/api/api.d.ts +1 -1
- package/lib/api/api.js +14 -12
- package/lib/api/shared.d.ts +1 -1
- package/lib/api/utils/constants.d.ts +1 -1
- package/lib/api/utils/constants.js +1 -1
- package/lib/builders/Attachment.d.ts +1 -1
- package/lib/builders/Attachment.js +12 -12
- package/lib/cache/index.d.ts +4 -1
- package/lib/cache/index.js +11 -3
- package/lib/client/base.d.ts +3 -3
- package/lib/client/base.js +8 -3
- package/lib/client/client.d.ts +4 -0
- package/lib/client/client.js +30 -14
- package/lib/client/httpclient.js +2 -2
- package/lib/client/workerclient.d.ts +3 -2
- package/lib/client/workerclient.js +23 -11
- package/lib/commands/applications/entryPoint.d.ts +46 -0
- package/lib/commands/applications/entryPoint.js +56 -0
- package/lib/commands/applications/entrycontext.d.ts +40 -0
- package/lib/commands/applications/entrycontext.js +85 -0
- package/lib/commands/applications/options.d.ts +3 -2
- package/lib/commands/decorators.d.ts +11 -17
- package/lib/commands/decorators.js +3 -0
- package/lib/commands/handle.d.ts +6 -5
- package/lib/commands/handle.js +42 -0
- package/lib/commands/handler.d.ts +6 -4
- package/lib/commands/handler.js +6 -1
- package/lib/commands/index.d.ts +2 -0
- package/lib/commands/index.js +2 -0
- package/lib/commands/optionresolver.js +1 -1
- package/lib/common/bot/watcher.d.ts +1 -1
- package/lib/common/it/utils.d.ts +10 -3
- package/lib/common/it/utils.js +10 -0
- package/lib/common/shorters/interaction.d.ts +1 -1
- package/lib/common/types/util.d.ts +1 -1
- package/lib/common/types/write.d.ts +2 -2
- package/lib/deps/mixer.js +6 -1
- package/lib/events/handler.js +3 -3
- package/lib/events/hooks/custom.d.ts +1 -0
- package/lib/events/hooks/custom.js +5 -1
- package/lib/events/hooks/subscriptions.d.ts +35 -0
- package/lib/events/hooks/subscriptions.js +16 -0
- package/lib/structures/Interaction.d.ts +24 -4
- package/lib/structures/Interaction.js +54 -5
- package/lib/structures/Message.d.ts +0 -3
- package/lib/structures/Message.js +0 -3
- package/lib/structures/channels.js +2 -2
- package/lib/structures/extra/BaseGuild.d.ts +11 -1
- package/lib/structures/extra/BaseGuild.js +27 -0
- package/lib/types/gateway.d.ts +19 -2
- package/lib/types/payloads/_interactions/_applicationCommands/chatInput.d.ts +6 -1
- package/lib/types/payloads/_interactions/applicationCommands.d.ts +41 -6
- package/lib/types/payloads/_interactions/applicationCommands.js +28 -1
- package/lib/types/payloads/_interactions/responses.d.ts +74 -2
- package/lib/types/payloads/_interactions/responses.js +4 -0
- package/lib/types/payloads/channel.d.ts +44 -4
- package/lib/types/payloads/channel.js +5 -1
- package/lib/types/payloads/monetization.d.ts +29 -1
- package/lib/types/payloads/monetization.js +10 -1
- package/lib/types/rest/channel.d.ts +4 -17
- package/lib/types/rest/interactions.d.ts +30 -8
- package/lib/types/rest/monetization.d.ts +22 -1
- package/lib/types/rest/webhook.d.ts +2 -2
- package/lib/types/utils/index.d.ts +16 -5
- package/lib/types/utils/index.js +15 -4
- package/lib/websocket/SharedTypes.d.ts +9 -3
- package/lib/websocket/constants/index.d.ts +3 -2
- package/lib/websocket/constants/index.js +11 -1
- package/lib/websocket/discord/shard.d.ts +3 -2
- package/lib/websocket/discord/shard.js +25 -11
- package/lib/websocket/discord/sharder.js +59 -1
- package/lib/websocket/discord/shared.d.ts +21 -1
- package/lib/websocket/discord/socket/custom.d.ts +1 -1
- package/lib/websocket/discord/socket/custom.js +51 -34
- package/lib/websocket/discord/worker.d.ts +2 -1
- package/lib/websocket/discord/workermanager.d.ts +2 -1
- package/lib/websocket/discord/workermanager.js +30 -13
- package/package.json +8 -3
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import type { RESTPostAPIInteractionCallbackJSONBody } from '../../types';
|
|
1
|
+
import type { RESTPostAPIInteractionCallbackJSONBody, RESTPostAPIInteractionCallbackQuery, RESTPostAPIInteractionCallbackResult } from '../../types';
|
|
2
2
|
import type { ProxyRequestMethod } from '../Router';
|
|
3
3
|
import type { RestArguments } from '../api';
|
|
4
4
|
export interface InteractionRoutes {
|
|
5
5
|
interactions: (id: string) => (token: string) => {
|
|
6
6
|
callback: {
|
|
7
|
-
post(args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIInteractionCallbackJSONBody>
|
|
7
|
+
post(args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIInteractionCallbackJSONBody, Omit<RESTPostAPIInteractionCallbackQuery, 'with_response'> & {
|
|
8
|
+
with_response: true;
|
|
9
|
+
}>): Promise<RESTPostAPIInteractionCallbackResult>;
|
|
10
|
+
post(args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIInteractionCallbackJSONBody, Omit<RESTPostAPIInteractionCallbackQuery, 'with_response'> & {
|
|
11
|
+
with_response: false;
|
|
12
|
+
}>): Promise<undefined>;
|
|
13
|
+
post(args: RestArguments<ProxyRequestMethod.Post, RESTPostAPIInteractionCallbackJSONBody, RESTPostAPIInteractionCallbackQuery>): Promise<RESTPostAPIInteractionCallbackResult | undefined>;
|
|
8
14
|
};
|
|
9
15
|
};
|
|
10
16
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RESTGetAPISKUSubscriptionsResult, RESTGetAPISKUSubscriptionsQuery, RESTGetAPISKUSubscriptionResult } from '../../types';
|
|
2
|
+
import type { RestArguments } from '../api';
|
|
3
|
+
import type { ProxyRequestMethod } from '../Router';
|
|
4
|
+
export interface SKuRoutes {
|
|
5
|
+
skus(id: string): {
|
|
6
|
+
get: (args?: RestArguments<ProxyRequestMethod.Get, RESTGetAPISKUSubscriptionsQuery>) => Promise<RESTGetAPISKUSubscriptionsResult>;
|
|
7
|
+
subscriptions(id: string): {
|
|
8
|
+
get: (args?: RestArguments<ProxyRequestMethod.Get>) => Promise<RESTGetAPISKUSubscriptionResult>;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
}
|
package/lib/api/api.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare class ApiHandler {
|
|
|
19
19
|
request<T = any>(method: HttpMethods, url: `/${string}`, { auth, ...request }?: ApiRequestOptions): Promise<T>;
|
|
20
20
|
parseError(response: Response, result: unknown): Error;
|
|
21
21
|
handle50X(method: HttpMethods, url: `/${string}`, request: ApiRequestOptions, next: () => void): Promise<any>;
|
|
22
|
-
handle429(route: string, method: HttpMethods, url: `/${string}`, request: ApiRequestOptions, response: Response, result:
|
|
22
|
+
handle429(route: string, method: HttpMethods, url: `/${string}`, request: ApiRequestOptions, response: Response, result: string, next: () => void, reject: (err: unknown) => void, now: number): Promise<any>;
|
|
23
23
|
clearResetInterval(route: string): void;
|
|
24
24
|
setResetBucket(route: string, resp: Response, now: number, headerNow: number): void;
|
|
25
25
|
setRatelimitsBucket(route: string, resp: Response): void;
|
package/lib/api/api.js
CHANGED
|
@@ -196,17 +196,19 @@ class ApiHandler {
|
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
198
|
async handle429(route, method, url, request, response, result, next, reject, now) {
|
|
199
|
-
const content =
|
|
200
|
-
let retryAfter;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
199
|
+
const content = `${JSON.stringify(request)} `;
|
|
200
|
+
let retryAfter = Number(response.headers.get('x-ratelimit-reset-after') || response.headers.get('retry-after')) * 1000;
|
|
201
|
+
if (Number.isNaN(retryAfter)) {
|
|
202
|
+
try {
|
|
203
|
+
retryAfter = JSON.parse(result).retry_after * 1000;
|
|
204
|
+
}
|
|
205
|
+
catch (err) {
|
|
206
|
+
this.debugger?.warn(`Unexpected error: ${err}`);
|
|
207
|
+
reject(err);
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
208
210
|
}
|
|
209
|
-
this.debugger?.info(`${response.headers.get('x-ratelimit-global') ? 'Global' : 'Unexpected'} 429: ${result}\n${content} ${now} ${route} ${response.status}: ${this.ratelimits.get(route).remaining}/${this.ratelimits.get(route).limit} left | Reset ${retryAfter} (${this.ratelimits.get(route).reset - now}ms left) | Scope ${response.headers.get('x-ratelimit-scope')}`);
|
|
211
|
+
this.debugger?.info(`${response.headers.get('x-ratelimit-global') ? 'Global' : 'Unexpected'} 429: ${result.slice(0, 256)}\n${content} ${now} ${route} ${response.status}: ${this.ratelimits.get(route).remaining}/${this.ratelimits.get(route).limit} left | Reset ${retryAfter} (${this.ratelimits.get(route).reset - now}ms left) | Scope ${response.headers.get('x-ratelimit-scope')}`);
|
|
210
212
|
if (retryAfter) {
|
|
211
213
|
await (0, common_1.delay)(retryAfter);
|
|
212
214
|
next();
|
|
@@ -285,10 +287,10 @@ class ApiHandler {
|
|
|
285
287
|
for (const [index, file] of options.request.files.entries()) {
|
|
286
288
|
const fileKey = file.key ?? `files[${index}]`;
|
|
287
289
|
if ((0, utils_1.isBufferLike)(file.data)) {
|
|
288
|
-
formData.append(fileKey, new Blob([file.data], { type: file.contentType }), file.
|
|
290
|
+
formData.append(fileKey, new Blob([file.data], { type: file.contentType }), file.filename);
|
|
289
291
|
}
|
|
290
292
|
else {
|
|
291
|
-
formData.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.
|
|
293
|
+
formData.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.filename);
|
|
292
294
|
}
|
|
293
295
|
}
|
|
294
296
|
if (options.request.body) {
|
package/lib/api/shared.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const DefaultUserAgent = "DiscordBot (https://seyfert.dev, v2.
|
|
1
|
+
export declare const DefaultUserAgent = "DiscordBot (https://seyfert.dev, v2.1.0)";
|
|
2
2
|
export declare const ALLOWED_EXTENSIONS: readonly ["webp", "png", "jpg", "jpeg", "gif"];
|
|
3
3
|
export declare const ALLOWED_STICKER_EXTENSIONS: readonly ["png", "json", "gif"];
|
|
4
4
|
export declare const ALLOWED_SIZES: readonly [16, 32, 64, 100, 128, 256, 512, 1024, 2048, 4096];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ALLOWED_SIZES = exports.ALLOWED_STICKER_EXTENSIONS = exports.ALLOWED_EXTENSIONS = exports.DefaultUserAgent = void 0;
|
|
4
|
-
exports.DefaultUserAgent = 'DiscordBot (https://seyfert.dev, v2.
|
|
4
|
+
exports.DefaultUserAgent = 'DiscordBot (https://seyfert.dev, v2.1.0)';
|
|
5
5
|
exports.ALLOWED_EXTENSIONS = ['webp', 'png', 'jpg', 'jpeg', 'gif'];
|
|
6
6
|
exports.ALLOWED_STICKER_EXTENSIONS = ['png', 'json', 'gif'];
|
|
7
7
|
exports.ALLOWED_SIZES = [16, 32, 64, 100, 128, 256, 512, 1_024, 2_048, 4_096];
|
|
@@ -10,7 +10,7 @@ export interface AttachmentResolvableMap {
|
|
|
10
10
|
export type AttachmentResolvable = AttachmentResolvableMap[keyof AttachmentResolvableMap] | AttachmentBuilder | Attachment;
|
|
11
11
|
export type AttachmentDataType = keyof AttachmentResolvableMap;
|
|
12
12
|
export interface AttachmentData {
|
|
13
|
-
|
|
13
|
+
filename: string;
|
|
14
14
|
description: string;
|
|
15
15
|
resolvable: AttachmentResolvable;
|
|
16
16
|
type: AttachmentDataType;
|
|
@@ -28,7 +28,7 @@ class AttachmentBuilder {
|
|
|
28
28
|
* Creates a new Attachment instance.
|
|
29
29
|
* @param data - The partial attachment data.
|
|
30
30
|
*/
|
|
31
|
-
constructor(data = {
|
|
31
|
+
constructor(data = { filename: `${((0, node_crypto_1.randomBytes)?.(8))?.toString('base64url') || 'default'}.jpg` }) {
|
|
32
32
|
this.data = data;
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
@@ -39,7 +39,7 @@ class AttachmentBuilder {
|
|
|
39
39
|
* attachment.setName('example.jpg');
|
|
40
40
|
*/
|
|
41
41
|
setName(name) {
|
|
42
|
-
this.data.
|
|
42
|
+
this.data.filename = name;
|
|
43
43
|
return this;
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
@@ -79,17 +79,17 @@ class AttachmentBuilder {
|
|
|
79
79
|
if (spoiler === this.spoiler)
|
|
80
80
|
return this;
|
|
81
81
|
if (!spoiler) {
|
|
82
|
-
this.data.
|
|
82
|
+
this.data.filename = this.data.filename.slice('SPOILER_'.length);
|
|
83
83
|
return this;
|
|
84
84
|
}
|
|
85
|
-
this.data.
|
|
85
|
+
this.data.filename = `SPOILER_${this.data.filename}`;
|
|
86
86
|
return this;
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* Gets whether the attachment is a spoiler.
|
|
90
90
|
*/
|
|
91
91
|
get spoiler() {
|
|
92
|
-
return this.data.
|
|
92
|
+
return this.data.filename?.startsWith('SPOILER_') ?? false;
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
95
|
* Converts the Attachment instance to JSON.
|
|
@@ -109,10 +109,10 @@ function resolveAttachment(resolve) {
|
|
|
109
109
|
if ('id' in resolve)
|
|
110
110
|
return resolve;
|
|
111
111
|
if (resolve instanceof AttachmentBuilder) {
|
|
112
|
-
const
|
|
113
|
-
return { filename
|
|
112
|
+
const { filename, description } = resolve.toJSON();
|
|
113
|
+
return { filename, description };
|
|
114
114
|
}
|
|
115
|
-
return { filename: resolve.
|
|
115
|
+
return { filename: resolve.filename, description: resolve.description };
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
118
118
|
* Resolves a list of attachments to raw files.
|
|
@@ -122,9 +122,9 @@ function resolveAttachment(resolve) {
|
|
|
122
122
|
async function resolveFiles(resources) {
|
|
123
123
|
const data = await Promise.all(resources.map(async (resource, i) => {
|
|
124
124
|
if (resource instanceof AttachmentBuilder) {
|
|
125
|
-
const { type, resolvable,
|
|
125
|
+
const { type, resolvable, filename } = resource.toJSON();
|
|
126
126
|
const resolve = await resolveAttachmentData(resolvable, type);
|
|
127
|
-
return { ...resolve, key: `files[${i}]`,
|
|
127
|
+
return { ...resolve, key: `files[${i}]`, filename };
|
|
128
128
|
}
|
|
129
129
|
if (resource instanceof Attachment) {
|
|
130
130
|
const resolve = await resolveAttachmentData(resource.url, 'url');
|
|
@@ -132,14 +132,14 @@ async function resolveFiles(resources) {
|
|
|
132
132
|
data: resolve.data,
|
|
133
133
|
contentType: resolve.contentType,
|
|
134
134
|
key: `files[${i}]`,
|
|
135
|
-
|
|
135
|
+
filename: resource.filename,
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
138
|
return {
|
|
139
139
|
data: resource.data,
|
|
140
140
|
contentType: resource.contentType,
|
|
141
141
|
key: `files[${i}]`,
|
|
142
|
-
|
|
142
|
+
filename: resource.filename,
|
|
143
143
|
};
|
|
144
144
|
}));
|
|
145
145
|
return data;
|
package/lib/cache/index.d.ts
CHANGED
|
@@ -16,6 +16,9 @@ import { GatewayIntentBits, type GatewayDispatchPayload } from '../types';
|
|
|
16
16
|
import type { InternalOptions, UsingClient } from '../commands';
|
|
17
17
|
import { Overwrites } from './resources/overwrites';
|
|
18
18
|
import { Messages } from './resources/messages';
|
|
19
|
+
export { BaseResource } from './resources/default/base';
|
|
20
|
+
export { GuildRelatedResource } from './resources/default/guild-related';
|
|
21
|
+
export { GuildBasedResource } from './resources/default/guild-based';
|
|
19
22
|
export type InferAsyncCache = InternalOptions extends {
|
|
20
23
|
asyncCache: infer P;
|
|
21
24
|
} ? P : false;
|
|
@@ -116,7 +119,7 @@ export declare class Cache {
|
|
|
116
119
|
string,
|
|
117
120
|
string
|
|
118
121
|
])[]): Promise<void>;
|
|
119
|
-
onPacket
|
|
122
|
+
onPacket(event: GatewayDispatchPayload): Promise<void>;
|
|
120
123
|
testAdapter(): Promise<void>;
|
|
121
124
|
private testUsersAndMembers;
|
|
122
125
|
private testChannelsAndOverwrites;
|
package/lib/cache/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.Cache = void 0;
|
|
17
|
+
exports.Cache = exports.GuildBasedResource = exports.GuildRelatedResource = exports.BaseResource = void 0;
|
|
18
18
|
const common_1 = require("../common");
|
|
19
19
|
const guilds_1 = require("./resources/guilds");
|
|
20
20
|
const users_1 = require("./resources/users");
|
|
@@ -31,6 +31,12 @@ const bans_1 = require("./resources/bans");
|
|
|
31
31
|
const types_1 = require("../types");
|
|
32
32
|
const overwrites_1 = require("./resources/overwrites");
|
|
33
33
|
const messages_1 = require("./resources/messages");
|
|
34
|
+
var base_1 = require("./resources/default/base");
|
|
35
|
+
Object.defineProperty(exports, "BaseResource", { enumerable: true, get: function () { return base_1.BaseResource; } });
|
|
36
|
+
var guild_related_1 = require("./resources/default/guild-related");
|
|
37
|
+
Object.defineProperty(exports, "GuildRelatedResource", { enumerable: true, get: function () { return guild_related_1.GuildRelatedResource; } });
|
|
38
|
+
var guild_based_1 = require("./resources/default/guild-based");
|
|
39
|
+
Object.defineProperty(exports, "GuildBasedResource", { enumerable: true, get: function () { return guild_based_1.GuildBasedResource; } });
|
|
34
40
|
__exportStar(require("./adapters/index"), exports);
|
|
35
41
|
class Cache {
|
|
36
42
|
intents;
|
|
@@ -103,8 +109,10 @@ class Cache {
|
|
|
103
109
|
if (!this.disabledCache.bans) {
|
|
104
110
|
this.bans = new bans_1.Bans(this, client);
|
|
105
111
|
}
|
|
106
|
-
if (this.disabledCache.onPacket)
|
|
107
|
-
|
|
112
|
+
if (this.disabledCache.onPacket) {
|
|
113
|
+
//@ts-expect-error
|
|
114
|
+
this.onPacket = () => { };
|
|
115
|
+
}
|
|
108
116
|
}
|
|
109
117
|
/** @internal */
|
|
110
118
|
__setClient(client) {
|
package/lib/client/base.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { LocaleString, RESTPostAPIChannelMessageJSONBody } from '../types';
|
|
|
9
9
|
import type { Awaitable, DeepPartial, IntentStrings, OmitInsert, PermissionStrings, When } from '../common/types/util';
|
|
10
10
|
import { ComponentHandler } from '../components/handler';
|
|
11
11
|
import { LangsHandler } from '../langs/handler';
|
|
12
|
-
import type { ChatInputCommandInteraction, ComponentInteraction, MessageCommandInteraction, ModalSubmitInteraction, UserCommandInteraction } from '../structures';
|
|
12
|
+
import type { ChatInputCommandInteraction, ComponentInteraction, EntryPointInteraction, MessageCommandInteraction, ModalSubmitInteraction, UserCommandInteraction } from '../structures';
|
|
13
13
|
import type { ComponentCommand, ModalCommand } from '../components';
|
|
14
14
|
import { BanShorter } from '../common/shorters/bans';
|
|
15
15
|
import { HandleCommand } from '../commands/handle';
|
|
@@ -78,7 +78,7 @@ export declare class BaseClient {
|
|
|
78
78
|
}>;
|
|
79
79
|
}
|
|
80
80
|
export interface BaseClientOptions {
|
|
81
|
-
context?: (interaction: ChatInputCommandInteraction<boolean> | UserCommandInteraction<boolean> | MessageCommandInteraction<boolean> | ComponentInteraction | ModalSubmitInteraction | When<InferWithPrefix, MessageStructure, never>) => {};
|
|
81
|
+
context?: (interaction: ChatInputCommandInteraction<boolean> | UserCommandInteraction<boolean> | MessageCommandInteraction<boolean> | ComponentInteraction | ModalSubmitInteraction | EntryPointInteraction<boolean> | When<InferWithPrefix, MessageStructure, never>) => {};
|
|
82
82
|
globalMiddlewares?: readonly (keyof RegisteredMiddlewares)[];
|
|
83
83
|
commands?: {
|
|
84
84
|
defaults?: {
|
|
@@ -160,7 +160,7 @@ export interface ServicesOptions {
|
|
|
160
160
|
rest?: ApiHandler;
|
|
161
161
|
cache?: {
|
|
162
162
|
adapter?: Adapter;
|
|
163
|
-
disabledCache?: Cache['disabledCache'];
|
|
163
|
+
disabledCache?: true | Cache['disabledCache'];
|
|
164
164
|
};
|
|
165
165
|
langs?: {
|
|
166
166
|
default?: string;
|
package/lib/client/base.js
CHANGED
|
@@ -123,7 +123,9 @@ class BaseClient {
|
|
|
123
123
|
this.rest = rest;
|
|
124
124
|
}
|
|
125
125
|
if (cache) {
|
|
126
|
-
this.cache = new cache_1.Cache(this.cache?.intents ?? 0, cache?.adapter ?? this.cache?.adapter ?? new cache_1.MemoryAdapter(), cache.disabledCache
|
|
126
|
+
this.cache = new cache_1.Cache(this.cache?.intents ?? 0, cache?.adapter ?? this.cache?.adapter ?? new cache_1.MemoryAdapter(), (typeof cache.disabledCache === 'boolean' ? { onPacket: cache.disabledCache } : cache.disabledCache) ??
|
|
127
|
+
this.cache?.disabledCache ??
|
|
128
|
+
[], this);
|
|
127
129
|
}
|
|
128
130
|
if (middlewares) {
|
|
129
131
|
this.middlewares = middlewares;
|
|
@@ -232,7 +234,10 @@ class BaseClient {
|
|
|
232
234
|
applicationId ??= await this.getRC().then(x => x.applicationId ?? this.applicationId);
|
|
233
235
|
BaseClient.assertString(applicationId, 'applicationId is not a string');
|
|
234
236
|
const commands = this.commands.values;
|
|
235
|
-
const filter = (0, common_1.filterSplit)(commands, command => !command.guildId);
|
|
237
|
+
const filter = (0, common_1.filterSplit)(commands, command => ('guildId' in command ? !command.guildId : true));
|
|
238
|
+
if (this.commands?.entryPoint) {
|
|
239
|
+
filter.expect.push(this.commands.entryPoint);
|
|
240
|
+
}
|
|
236
241
|
if (!cachePath || (await this.shouldUploadCommands(cachePath)))
|
|
237
242
|
await this.proxy.applications(applicationId).commands.put({
|
|
238
243
|
body: filter.expect
|
|
@@ -252,7 +257,7 @@ class BaseClient {
|
|
|
252
257
|
.guilds(guildId)
|
|
253
258
|
.commands.put({
|
|
254
259
|
body: filter.never
|
|
255
|
-
.filter(cmd => cmd.guildId
|
|
260
|
+
.filter(cmd => cmd.guildId.includes(guildId) && (!('ignore' in cmd) || cmd.ignore !== shared_1.IgnoreCommand.Slash))
|
|
256
261
|
.map(x => x.toJSON()),
|
|
257
262
|
});
|
|
258
263
|
}
|
package/lib/client/client.d.ts
CHANGED
package/lib/client/client.js
CHANGED
|
@@ -12,7 +12,7 @@ const collectors_1 = require("./collectors");
|
|
|
12
12
|
const transformers_1 = require("./transformers");
|
|
13
13
|
let parentPort;
|
|
14
14
|
class Client extends base_1.BaseClient {
|
|
15
|
-
__handleGuilds
|
|
15
|
+
__handleGuilds;
|
|
16
16
|
gateway;
|
|
17
17
|
me;
|
|
18
18
|
memberUpdateHandler = new memberUpdate_1.MemberUpdateHandler();
|
|
@@ -100,6 +100,24 @@ class Client extends base_1.BaseClient {
|
|
|
100
100
|
...this.options?.gateway?.properties,
|
|
101
101
|
},
|
|
102
102
|
compress: this.options?.gateway?.compress,
|
|
103
|
+
resharding: {
|
|
104
|
+
getInfo: () => this.proxy.gateway.bot.get(),
|
|
105
|
+
interval: this.options?.resharding?.interval ?? 0,
|
|
106
|
+
percentage: this.options?.resharding?.percentage ?? 0,
|
|
107
|
+
reloadGuilds: ids => {
|
|
108
|
+
this.__handleGuilds = this.__handleGuilds?.concat(ids) ?? ids;
|
|
109
|
+
},
|
|
110
|
+
onGuild: id => {
|
|
111
|
+
if (this.__handleGuilds) {
|
|
112
|
+
const index = this.__handleGuilds.indexOf(id);
|
|
113
|
+
if (index === -1)
|
|
114
|
+
return false;
|
|
115
|
+
this.__handleGuilds.splice(index, 1);
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
119
|
+
},
|
|
120
|
+
},
|
|
103
121
|
});
|
|
104
122
|
}
|
|
105
123
|
this.cache.intents = this.gateway.options.intents;
|
|
@@ -131,16 +149,16 @@ class Client extends base_1.BaseClient {
|
|
|
131
149
|
break;
|
|
132
150
|
case 'GUILD_DELETE':
|
|
133
151
|
case 'GUILD_CREATE': {
|
|
134
|
-
if (this.__handleGuilds?.
|
|
135
|
-
this.__handleGuilds?.
|
|
136
|
-
if (!this.__handleGuilds?.
|
|
152
|
+
if (this.__handleGuilds?.includes(packet.d.id)) {
|
|
153
|
+
this.__handleGuilds?.splice(this.__handleGuilds.indexOf(packet.d.id), 1);
|
|
154
|
+
if (!this.__handleGuilds?.length && [...this.gateway.values()].every(shard => shard.data.session_id)) {
|
|
137
155
|
delete this.__handleGuilds;
|
|
138
|
-
await this.cache.onPacket
|
|
156
|
+
await this.cache.onPacket(packet);
|
|
139
157
|
return this.events?.runEvent('BOT_READY', this, this.me, -1);
|
|
140
158
|
}
|
|
141
|
-
if (!this.__handleGuilds?.
|
|
159
|
+
if (!this.__handleGuilds?.length)
|
|
142
160
|
delete this.__handleGuilds;
|
|
143
|
-
return this.cache.onPacket
|
|
161
|
+
return this.cache.onPacket(packet);
|
|
144
162
|
}
|
|
145
163
|
await this.events?.execute(packet.t, packet, this, shardId);
|
|
146
164
|
break;
|
|
@@ -156,16 +174,13 @@ class Client extends base_1.BaseClient {
|
|
|
156
174
|
await this.events?.execute(packet.t, packet, this, shardId);
|
|
157
175
|
await this.handleCommand.message(packet.d, shardId);
|
|
158
176
|
break;
|
|
159
|
-
case 'READY':
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
for (const g of packet.d.guilds) {
|
|
163
|
-
this.__handleGuilds?.add(g.id);
|
|
164
|
-
}
|
|
177
|
+
case 'READY': {
|
|
178
|
+
const ids = packet.d.guilds.map(x => x.id);
|
|
179
|
+
this.__handleGuilds = this.__handleGuilds?.concat(ids) ?? ids;
|
|
165
180
|
this.botId = packet.d.user.id;
|
|
166
181
|
this.applicationId = packet.d.application.id;
|
|
167
182
|
this.me = transformers_1.Transformers.ClientUser(this, packet.d.user, packet.d.application);
|
|
168
|
-
if (!(this.__handleGuilds?.
|
|
183
|
+
if (!(this.__handleGuilds?.length &&
|
|
169
184
|
(this.gateway.options.intents & types_1.GatewayIntentBits.Guilds) === types_1.GatewayIntentBits.Guilds)) {
|
|
170
185
|
if ([...this.gateway.values()].every(shard => shard.data.session_id)) {
|
|
171
186
|
await this.events?.runEvent('BOT_READY', this, this.me, -1);
|
|
@@ -175,6 +190,7 @@ class Client extends base_1.BaseClient {
|
|
|
175
190
|
this.debugger?.debug(`#${shardId}[${packet.d.user.username}](${this.botId}) is online...`);
|
|
176
191
|
await this.events?.execute(packet.t, packet, this, shardId);
|
|
177
192
|
break;
|
|
193
|
+
}
|
|
178
194
|
default:
|
|
179
195
|
await this.events?.execute(packet.t, packet, this, shardId);
|
|
180
196
|
break;
|
package/lib/client/httpclient.js
CHANGED
|
@@ -21,10 +21,10 @@ class HttpClient extends base_1.BaseClient {
|
|
|
21
21
|
for (const [index, file] of files.entries()) {
|
|
22
22
|
const fileKey = file.key ?? `files[${index}]`;
|
|
23
23
|
if ((0, utils_1.isBufferLike)(file.data)) {
|
|
24
|
-
response.append(fileKey, new Blob([file.data], { type: file.contentType }), file.
|
|
24
|
+
response.append(fileKey, new Blob([file.data], { type: file.contentType }), file.filename);
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
|
-
response.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.
|
|
27
|
+
response.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.filename);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
if (body) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type GatewayDispatchPayload } from '../types';
|
|
2
|
-
import type { Cache } from '../cache';
|
|
3
2
|
import { type DeepPartial, type When } from '../common';
|
|
4
3
|
import { EventHandler } from '../events';
|
|
5
4
|
import { Shard, type ShardManagerOptions, type WorkerData } from '../websocket';
|
|
@@ -35,6 +34,7 @@ export declare class WorkerClient<Ready extends boolean = boolean> extends BaseC
|
|
|
35
34
|
};
|
|
36
35
|
}): void;
|
|
37
36
|
setWorkerData(data: WorkerData): void;
|
|
37
|
+
get workerData(): WorkerData;
|
|
38
38
|
start(options?: Omit<DeepPartial<StartOptions>, 'httpConnection' | 'token' | 'connection'>): Promise<void>;
|
|
39
39
|
loadEvents(dir?: string): Promise<void>;
|
|
40
40
|
postMessage(body: unknown): unknown;
|
|
@@ -46,10 +46,11 @@ export declare class WorkerClient<Ready extends boolean = boolean> extends BaseC
|
|
|
46
46
|
}
|
|
47
47
|
export declare function generateShardInfo(shard: Shard): WorkerShardInfo;
|
|
48
48
|
interface WorkerClientOptions extends BaseClientOptions {
|
|
49
|
-
disabledCache?: Cache['disabledCache'];
|
|
50
49
|
commands?: NonNullable<Client['options']>['commands'];
|
|
51
50
|
handlePayload?: ShardManagerOptions['handlePayload'];
|
|
52
51
|
gateway?: ClientOptions['gateway'];
|
|
53
52
|
postMessage?: (body: unknown) => unknown;
|
|
53
|
+
/** can have perfomance issues in big bots if the client sends every event, specially in startup (false by default) */
|
|
54
|
+
sendPayloadToParent?: boolean;
|
|
54
55
|
}
|
|
55
56
|
export {};
|
|
@@ -74,6 +74,9 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
74
74
|
setWorkerData(data) {
|
|
75
75
|
workerData = data;
|
|
76
76
|
}
|
|
77
|
+
get workerData() {
|
|
78
|
+
return workerData;
|
|
79
|
+
}
|
|
77
80
|
async start(options = {}) {
|
|
78
81
|
const worker_threads = (0, common_1.lazyLoadPackage)('node:worker_threads');
|
|
79
82
|
if (worker_threads?.parentPort) {
|
|
@@ -87,7 +90,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
87
90
|
if (this.__setServicesCache) {
|
|
88
91
|
this.setServices({
|
|
89
92
|
cache: {
|
|
90
|
-
disabledCache: this.
|
|
93
|
+
disabledCache: this.cache.disabledCache,
|
|
91
94
|
},
|
|
92
95
|
});
|
|
93
96
|
}
|
|
@@ -99,7 +102,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
99
102
|
this.setServices({
|
|
100
103
|
cache: {
|
|
101
104
|
adapter,
|
|
102
|
-
disabledCache: this.
|
|
105
|
+
disabledCache: this.cache.disabledCache,
|
|
103
106
|
},
|
|
104
107
|
});
|
|
105
108
|
}
|
|
@@ -182,6 +185,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
182
185
|
const onPacket = this.onPacket.bind(this);
|
|
183
186
|
const handlePayload = this.options?.handlePayload?.bind(this);
|
|
184
187
|
const self = this;
|
|
188
|
+
const { sendPayloadToParent } = this.options;
|
|
185
189
|
for (const id of workerData.shards) {
|
|
186
190
|
let shard = this.shards.get(id);
|
|
187
191
|
if (!shard) {
|
|
@@ -197,13 +201,14 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
197
201
|
},
|
|
198
202
|
async handlePayload(shardId, payload) {
|
|
199
203
|
await handlePayload?.(shardId, payload);
|
|
200
|
-
await onPacket
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
await onPacket(payload, shardId);
|
|
205
|
+
if (sendPayloadToParent)
|
|
206
|
+
self.postMessage({
|
|
207
|
+
workerId: workerData.workerId,
|
|
208
|
+
shardId,
|
|
209
|
+
type: 'RECEIVE_PAYLOAD',
|
|
210
|
+
payload,
|
|
211
|
+
});
|
|
207
212
|
},
|
|
208
213
|
});
|
|
209
214
|
this.shards.set(id, shard);
|
|
@@ -342,7 +347,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
342
347
|
this.__handleGuilds?.delete(packet.d.id);
|
|
343
348
|
if (!this.__handleGuilds?.size && [...this.shards.values()].every(shard => shard.data.session_id)) {
|
|
344
349
|
delete this.__handleGuilds;
|
|
345
|
-
await this.cache.onPacket
|
|
350
|
+
await this.cache.onPacket(packet);
|
|
346
351
|
this.postMessage({
|
|
347
352
|
type: 'WORKER_READY',
|
|
348
353
|
workerId: this.workerId,
|
|
@@ -351,7 +356,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
351
356
|
}
|
|
352
357
|
if (!this.__handleGuilds?.size)
|
|
353
358
|
delete this.__handleGuilds;
|
|
354
|
-
return this.cache.onPacket
|
|
359
|
+
return this.cache.onPacket(packet);
|
|
355
360
|
}
|
|
356
361
|
await this.events?.execute(packet.t, packet, this, shardId);
|
|
357
362
|
break;
|
|
@@ -376,6 +381,13 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
376
381
|
this.applicationId = packet.d.application.id;
|
|
377
382
|
this.me = transformers_1.Transformers.ClientUser(this, packet.d.user, packet.d.application);
|
|
378
383
|
await this.events?.execute(packet.t, packet, this, shardId);
|
|
384
|
+
if ([...this.shards.values()].every(shard => shard.data.session_id)) {
|
|
385
|
+
this.postMessage({
|
|
386
|
+
type: 'WORKER_SHARDS_CONNECTED',
|
|
387
|
+
workerId: this.workerId,
|
|
388
|
+
});
|
|
389
|
+
await this.events?.runEvent('WORKER_SHARDS_CONNECTED', this, this.me, -1);
|
|
390
|
+
}
|
|
379
391
|
if (!(this.__handleGuilds?.size &&
|
|
380
392
|
(workerData.intents & types_1.GatewayIntentBits.Guilds) === types_1.GatewayIntentBits.Guilds)) {
|
|
381
393
|
if ([...this.shards.values()].every(shard => shard.data.session_id)) {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type PermissionStrings } from '../../common';
|
|
2
|
+
import { ApplicationCommandType, type EntryPointCommandHandlerType, type ApplicationIntegrationType, type InteractionContextType, type LocaleString } from '../../types';
|
|
3
|
+
import type { RegisteredMiddlewares } from '../decorators';
|
|
4
|
+
import type { EntryPointContext } from './entrycontext';
|
|
5
|
+
import type { ExtraProps, UsingClient } from './shared';
|
|
6
|
+
export declare abstract class EntryPointCommand {
|
|
7
|
+
middlewares: (keyof RegisteredMiddlewares)[];
|
|
8
|
+
__filePath?: string;
|
|
9
|
+
__t?: {
|
|
10
|
+
name: string | undefined;
|
|
11
|
+
description: string | undefined;
|
|
12
|
+
};
|
|
13
|
+
name: string;
|
|
14
|
+
type: ApplicationCommandType;
|
|
15
|
+
nsfw?: boolean;
|
|
16
|
+
integrationTypes: ApplicationIntegrationType[];
|
|
17
|
+
contexts: InteractionContextType[];
|
|
18
|
+
description: string;
|
|
19
|
+
botPermissions?: bigint;
|
|
20
|
+
dm?: boolean;
|
|
21
|
+
handler: EntryPointCommandHandlerType;
|
|
22
|
+
name_localizations?: Partial<Record<LocaleString, string>>;
|
|
23
|
+
description_localizations?: Partial<Record<LocaleString, string>>;
|
|
24
|
+
props: ExtraProps;
|
|
25
|
+
toJSON(): {
|
|
26
|
+
handler: EntryPointCommandHandlerType;
|
|
27
|
+
name: string;
|
|
28
|
+
type: ApplicationCommandType;
|
|
29
|
+
nsfw: boolean | undefined;
|
|
30
|
+
default_member_permissions: null;
|
|
31
|
+
guild_id: null;
|
|
32
|
+
description: string;
|
|
33
|
+
name_localizations: Partial<Record<"id" | "en-US" | "en-GB" | "bg" | "zh-CN" | "zh-TW" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "lt" | "no" | "pl" | "pt-BR" | "ro" | "ru" | "es-ES" | "es-419" | "sv-SE" | "th" | "tr" | "uk" | "vi", string>> | undefined;
|
|
34
|
+
description_localizations: Partial<Record<"id" | "en-US" | "en-GB" | "bg" | "zh-CN" | "zh-TW" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "lt" | "no" | "pl" | "pt-BR" | "ro" | "ru" | "es-ES" | "es-419" | "sv-SE" | "th" | "tr" | "uk" | "vi", string>> | undefined;
|
|
35
|
+
dm_permission: boolean | undefined;
|
|
36
|
+
contexts: InteractionContextType[];
|
|
37
|
+
integration_types: ApplicationIntegrationType[];
|
|
38
|
+
};
|
|
39
|
+
reload(): Promise<void>;
|
|
40
|
+
abstract run?(context: EntryPointContext): any;
|
|
41
|
+
onAfterRun?(context: EntryPointContext, error: unknown | undefined): any;
|
|
42
|
+
onRunError(context: EntryPointContext<never>, error: unknown): any;
|
|
43
|
+
onMiddlewaresError(context: EntryPointContext<never>, error: string): any;
|
|
44
|
+
onBotPermissionsFail(context: EntryPointContext<never>, permissions: PermissionStrings): any;
|
|
45
|
+
onInternalError(client: UsingClient, command: EntryPointCommand, error?: unknown): any;
|
|
46
|
+
}
|