seyfert 4.3.1-dev-27804544209.0 → 4.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/Routes/cdn.d.ts +1 -1
- package/lib/api/Routes/guilds.d.ts +2 -2
- package/lib/api/api.d.ts +4 -16
- package/lib/api/api.js +30 -153
- package/lib/api/shared.d.ts +1 -30
- package/lib/api/utils/constants.d.ts +1 -1
- package/lib/api/utils/constants.js +1 -1
- package/lib/api/utils/utils.d.ts +1 -2
- package/lib/api/utils/utils.js +1 -1
- package/lib/builders/MediaGallery.d.ts +1 -1
- package/lib/builders/MediaGallery.js +0 -10
- package/lib/builders/Modal.d.ts +8 -18
- package/lib/builders/Modal.js +7 -36
- package/lib/builders/Poll.js +0 -18
- package/lib/builders/RadioGroup.d.ts +3 -4
- package/lib/builders/RadioGroup.js +3 -24
- package/lib/builders/SelectMenu.d.ts +6 -8
- package/lib/builders/SelectMenu.js +3 -24
- package/lib/builders/types.d.ts +2 -3
- package/lib/cache/adapters/limited.js +1 -1
- package/lib/cache/index.d.ts +22 -16
- package/lib/cache/index.js +2 -38
- package/lib/cache/resources/bans.d.ts +1 -1
- package/lib/cache/resources/channels.d.ts +1 -1
- package/lib/cache/resources/default/base.js +1 -1
- package/lib/cache/resources/default/guild-based.d.ts +4 -4
- package/lib/cache/resources/default/guild-based.js +1 -1
- package/lib/cache/resources/default/guild-related.d.ts +4 -4
- package/lib/cache/resources/default/guild-related.js +1 -1
- package/lib/cache/resources/emojis.d.ts +1 -1
- package/lib/cache/resources/members.d.ts +1 -1
- package/lib/cache/resources/messages.d.ts +2 -2
- package/lib/cache/resources/overwrites.d.ts +1 -1
- package/lib/cache/resources/roles.d.ts +1 -1
- package/lib/cache/resources/stickers.d.ts +1 -1
- package/lib/cache/resources/voice-states.d.ts +1 -1
- package/lib/client/base.d.ts +21 -77
- package/lib/client/base.js +34 -583
- package/lib/client/client.d.ts +3 -26
- package/lib/client/client.js +9 -33
- package/lib/client/collectors.d.ts +8 -9
- package/lib/client/collectors.js +43 -16
- package/lib/client/httpclient.d.ts +0 -3
- package/lib/client/index.d.ts +1 -3
- package/lib/client/index.js +0 -4
- package/lib/client/workerclient.d.ts +1 -10
- package/lib/client/workerclient.js +13 -21
- package/lib/collection.d.ts +8 -10
- package/lib/collection.js +25 -19
- package/lib/commands/applications/chat.d.ts +16 -20
- package/lib/commands/applications/chat.js +6 -56
- package/lib/commands/applications/chatcontext.d.ts +13 -23
- package/lib/commands/applications/chatcontext.js +2 -23
- package/lib/commands/applications/entryPoint.d.ts +4 -6
- package/lib/commands/applications/entryPoint.js +1 -1
- package/lib/commands/applications/entrycontext.d.ts +7 -7
- package/lib/commands/applications/entrycontext.js +1 -3
- package/lib/commands/applications/menu.d.ts +4 -6
- package/lib/commands/applications/menucontext.d.ts +7 -7
- package/lib/commands/applications/menucontext.js +1 -3
- package/lib/commands/applications/options.d.ts +12 -12
- package/lib/commands/applications/shared.d.ts +12 -31
- package/lib/commands/decorators.d.ts +33 -40
- package/lib/commands/decorators.js +2 -11
- package/lib/commands/handle.d.ts +4 -15
- package/lib/commands/handle.js +142 -232
- package/lib/commands/handler.d.ts +7 -20
- package/lib/commands/handler.js +62 -133
- package/lib/commands/index.d.ts +0 -1
- package/lib/commands/optionresolver.d.ts +2 -2
- package/lib/common/it/error.d.ts +0 -8
- package/lib/common/it/error.js +0 -7
- package/lib/common/it/formatter.d.ts +11 -14
- package/lib/common/it/formatter.js +3 -4
- package/lib/common/it/logger.d.ts +1 -6
- package/lib/common/it/logger.js +3 -17
- package/lib/common/it/utils.d.ts +4 -4
- package/lib/common/it/utils.js +5 -11
- package/lib/common/shorters/application.d.ts +2 -2
- package/lib/common/shorters/bans.d.ts +3 -7
- package/lib/common/shorters/bans.js +4 -12
- package/lib/common/shorters/channels.d.ts +1 -1
- package/lib/common/shorters/channels.js +1 -1
- package/lib/common/shorters/interaction.d.ts +1 -1
- package/lib/common/shorters/members.d.ts +6 -6
- package/lib/common/shorters/members.js +7 -7
- package/lib/common/shorters/messages.d.ts +1 -1
- package/lib/common/shorters/users.d.ts +1 -1
- package/lib/common/shorters/webhook.d.ts +2 -3
- package/lib/common/shorters/webhook.js +7 -0
- package/lib/common/types/options.d.ts +0 -4
- package/lib/common/types/util.d.ts +0 -8
- package/lib/common/types/write.d.ts +1 -2
- package/lib/components/StringSelectMenuComponent.d.ts +1 -1
- package/lib/components/componentcommand.d.ts +7 -8
- package/lib/components/componentcontext.d.ts +20 -21
- package/lib/components/componentcontext.js +2 -7
- package/lib/components/handler.d.ts +6 -18
- package/lib/components/handler.js +43 -102
- package/lib/components/modalcommand.d.ts +4 -5
- package/lib/components/modalcontext.d.ts +15 -35
- package/lib/components/modalcontext.js +1 -54
- package/lib/events/event.d.ts +3 -9
- package/lib/events/handler.d.ts +6 -51
- package/lib/events/handler.js +34 -163
- package/lib/events/hooks/interactions.d.ts +1 -1
- package/lib/events/hooks/voice.d.ts +2 -1
- package/lib/events/hooks/voice.js +1 -2
- package/lib/index.d.ts +4 -9
- package/lib/index.js +7 -12
- package/lib/langs/handler.d.ts +9 -14
- package/lib/langs/handler.js +8 -45
- package/lib/structures/Application.d.ts +1 -1
- package/lib/structures/Emoji.d.ts +2 -2
- package/lib/structures/Emoji.js +2 -2
- package/lib/structures/Guild.d.ts +3 -3
- package/lib/structures/GuildBan.d.ts +3 -3
- package/lib/structures/GuildBan.js +3 -3
- package/lib/structures/GuildMember.d.ts +8 -8
- package/lib/structures/GuildMember.js +7 -28
- package/lib/structures/GuildRole.d.ts +1 -1
- package/lib/structures/GuildRole.js +2 -2
- package/lib/structures/Interaction.d.ts +8 -10
- package/lib/structures/Interaction.js +9 -28
- package/lib/structures/Message.d.ts +3 -10
- package/lib/structures/Message.js +10 -22
- package/lib/structures/VoiceState.d.ts +0 -4
- package/lib/structures/VoiceState.js +0 -12
- package/lib/structures/Webhook.d.ts +1 -9
- package/lib/structures/Webhook.js +1 -4
- package/lib/structures/channels.d.ts +9 -16
- package/lib/structures/channels.js +21 -22
- package/lib/structures/extra/BitField.d.ts +2 -2
- package/lib/structures/extra/BitField.js +1 -2
- package/lib/structures/extra/DiscordBase.js +1 -1
- package/lib/structures/extra/Permissions.d.ts +3 -2
- package/lib/structures/extra/Permissions.js +1 -6
- package/lib/types/payloads/_interactions/responses.d.ts +2 -2
- package/lib/types/payloads/components.d.ts +4 -4
- package/lib/websocket/constants/index.js +1 -2
- package/lib/websocket/discord/shard.d.ts +2 -2
- package/lib/websocket/discord/sharder.d.ts +7 -8
- package/lib/websocket/discord/sharder.js +5 -25
- package/lib/websocket/discord/shared.d.ts +6 -19
- package/lib/websocket/discord/workermanager.d.ts +7 -21
- package/lib/websocket/discord/workermanager.js +4 -28
- package/package.json +3 -5
- package/lib/client/intents.d.ts +0 -3
- package/lib/client/intents.js +0 -9
- package/lib/client/plugins/api.d.ts +0 -4
- package/lib/client/plugins/api.js +0 -550
- package/lib/client/plugins/errors.d.ts +0 -25
- package/lib/client/plugins/errors.js +0 -79
- package/lib/client/plugins/order.d.ts +0 -10
- package/lib/client/plugins/order.js +0 -32
- package/lib/client/plugins/registry.d.ts +0 -273
- package/lib/client/plugins/registry.js +0 -868
- package/lib/client/plugins/shared.d.ts +0 -23
- package/lib/client/plugins/shared.js +0 -193
- package/lib/client/plugins/types.d.ts +0 -402
- package/lib/client/plugins/types.js +0 -8
- package/lib/client/plugins.d.ts +0 -78
- package/lib/client/plugins.js +0 -558
- package/lib/events/utils.d.ts +0 -4
- package/lib/events/utils.js +0 -59
package/lib/api/Routes/cdn.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Identify, OmitInsert } from '../../common';
|
|
2
2
|
import type { APIThreadChannel, RESTDeleteAPIAutoModerationRuleResult, RESTDeleteAPIGuildBanResult, RESTDeleteAPIGuildEmojiResult, RESTDeleteAPIGuildIntegrationResult, RESTDeleteAPIGuildMemberResult, RESTDeleteAPIGuildMemberRoleResult, RESTDeleteAPIGuildResult, RESTDeleteAPIGuildRoleResult, RESTDeleteAPIGuildScheduledEventResult, RESTDeleteAPIGuildStickerResult, RESTDeleteAPIGuildTemplateResult, RESTGetAPIAuditLogQuery, RESTGetAPIAuditLogResult, RESTGetAPIAutoModerationRuleResult, RESTGetAPIAutoModerationRulesResult, RESTGetAPIGuildBanResult, RESTGetAPIGuildBansQuery, RESTGetAPIGuildBansResult, RESTGetAPIGuildChannelsResult, RESTGetAPIGuildEmojiResult, RESTGetAPIGuildEmojisResult, RESTGetAPIGuildIntegrationsResult, RESTGetAPIGuildInvitesResult, RESTGetAPIGuildMemberResult, RESTGetAPIGuildMembersQuery, RESTGetAPIGuildMembersResult, RESTGetAPIGuildMembersSearchQuery, RESTGetAPIGuildMembersSearchResult, RESTGetAPIGuildMessagesSearchQuery, RESTGetAPIGuildMessagesSearchResult, RESTGetAPIGuildPreviewResult, RESTGetAPIGuildPruneCountQuery, RESTGetAPIGuildPruneCountResult, RESTGetAPIGuildQuery, RESTGetAPIGuildResult, RESTGetAPIGuildRoleMemberCountsResult, RESTGetAPIGuildRoleResult, RESTGetAPIGuildRolesResult, RESTGetAPIGuildScheduledEventQuery, RESTGetAPIGuildScheduledEventResult, RESTGetAPIGuildScheduledEventsQuery, RESTGetAPIGuildScheduledEventsResult, RESTGetAPIGuildScheduledEventUsersQuery, RESTGetAPIGuildScheduledEventUsersResult, RESTGetAPIGuildSoundboardSoundsResult, RESTGetAPIGuildStickerResult, RESTGetAPIGuildStickersResult, RESTGetAPIGuildTemplatesResult, RESTGetAPIGuildThreadsResult, RESTGetAPIGuildVanityUrlResult, RESTGetAPIGuildVoiceRegionsResult, RESTGetAPIGuildVoiceStateCurrentMemberResult, RESTGetAPIGuildVoiceStateUserResult, RESTGetAPIGuildWebhooksResult, RESTGetAPIGuildWelcomeScreenResult, RESTGetAPIGuildWidgetImageQuery, RESTGetAPIGuildWidgetImageResult, RESTGetAPIGuildWidgetJSONResult, RESTGetAPIGuildWidgetSettingsResult, RESTGetAPITemplateResult, RESTPatchAPIAutoModerationRuleJSONBody, RESTPatchAPIAutoModerationRuleResult, RESTPatchAPICurrentGuildMemberJSONBody, RESTPatchAPIGuildChannelPositionsJSONBody, RESTPatchAPIGuildChannelPositionsResult, RESTPatchAPIGuildEmojiJSONBody, RESTPatchAPIGuildEmojiResult, RESTPatchAPIGuildJSONBody, RESTPatchAPIGuildMemberJSONBody, RESTPatchAPIGuildMemberResult, RESTPatchAPIGuildResult, RESTPatchAPIGuildRoleJSONBody, RESTPatchAPIGuildRolePositionsJSONBody, RESTPatchAPIGuildRolePositionsResult, RESTPatchAPIGuildRoleResult, RESTPatchAPIGuildScheduledEventJSONBody, RESTPatchAPIGuildScheduledEventResult, RESTPatchAPIGuildSoundboardSoundJSONBody, RESTPatchAPIGuildSoundboardSoundResult, RESTPatchAPIGuildStickerJSONBody, RESTPatchAPIGuildStickerResult, RESTPatchAPIGuildTemplateJSONBody, RESTPatchAPIGuildTemplateResult, RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody, RESTPatchAPIGuildVoiceStateCurrentMemberResult, RESTPatchAPIGuildVoiceStateUserJSONBody, RESTPatchAPIGuildVoiceStateUserResult, RESTPatchAPIGuildWelcomeScreenJSONBody, RESTPatchAPIGuildWelcomeScreenResult, RESTPatchAPIGuildWidgetSettingsJSONBody, RESTPatchAPIGuildWidgetSettingsResult, RESTPostAPIAutoModerationRuleJSONBody, RESTPostAPIAutoModerationRuleResult, RESTPostAPIGuildBulkBanJSONBody, RESTPostAPIGuildBulkBanResult, RESTPostAPIGuildChannelJSONBody, RESTPostAPIGuildChannelResult, RESTPostAPIGuildEmojiJSONBody, RESTPostAPIGuildEmojiResult, RESTPostAPIGuildPruneJSONBody, RESTPostAPIGuildPruneResult, RESTPostAPIGuildRoleJSONBody, RESTPostAPIGuildRoleResult, RESTPostAPIGuildScheduledEventJSONBody, RESTPostAPIGuildScheduledEventResult, RESTPostAPIGuildSoundboardSoundJSONBody, RESTPostAPIGuildSoundboardSoundResult, RESTPostAPIGuildStickerFormDataBody, RESTPostAPIGuildStickerResult, RESTPostAPIGuildsMFAJSONBody, RESTPostAPIGuildsMFAResult, RESTPostAPIGuildTemplatesJSONBody, RESTPostAPIGuildTemplatesResult, RESTPostAPITemplateCreateGuildJSONBody, RESTPostAPITemplateCreateGuildResult, RESTPutAPIGuildBanJSONBody, RESTPutAPIGuildBanResult, RESTPutAPIGuildMemberJSONBody, RESTPutAPIGuildMemberResult, RESTPutAPIGuildMemberRoleResult, RESTPutAPIGuildTemplateSyncResult } from '../../types';
|
|
3
|
-
import type { RestArguments, RestArgumentsNoBody
|
|
3
|
+
import type { RestArguments, RestArgumentsNoBody } from '../api';
|
|
4
4
|
import type { RawFile } from '../shared';
|
|
5
5
|
export interface GuildRoutes {
|
|
6
6
|
guilds: {
|
|
@@ -40,7 +40,7 @@ export interface GuildRoutes {
|
|
|
40
40
|
members: {
|
|
41
41
|
get(args?: RestArgumentsNoBody<RESTGetAPIGuildMembersQuery>): Promise<RESTGetAPIGuildMembersResult>;
|
|
42
42
|
search: {
|
|
43
|
-
get(args:
|
|
43
|
+
get(args: RestArgumentsNoBody<RESTGetAPIGuildMembersSearchQuery>): Promise<RESTGetAPIGuildMembersSearchResult>;
|
|
44
44
|
};
|
|
45
45
|
'@me': {
|
|
46
46
|
patch(args: RestArguments<RESTPatchAPICurrentGuildMemberJSONBody>): Promise<RESTGetAPIGuildMemberResult>;
|
package/lib/api/api.d.ts
CHANGED
|
@@ -3,15 +3,14 @@ import { type Awaitable, Logger, SeyfertError } from '../common';
|
|
|
3
3
|
import type { WorkerSendApiRequest } from '../websocket/discord/worker';
|
|
4
4
|
import { Bucket } from './bucket';
|
|
5
5
|
import type { APIRoutes } from './Routes';
|
|
6
|
-
import { type ApiHandlerInternalOptions, type ApiHandlerOptions, type ApiRequestOptions, type HttpMethods, type RawFile, type RequestHeaders
|
|
7
|
-
export
|
|
8
|
-
export interface ApiHandler<TClient = unknown> {
|
|
6
|
+
import { type ApiHandlerInternalOptions, type ApiHandlerOptions, type ApiRequestOptions, type HttpMethods, type RawFile, type RequestHeaders } from './shared';
|
|
7
|
+
export interface ApiHandler {
|
|
9
8
|
debugger?: Logger;
|
|
10
9
|
}
|
|
11
10
|
export type OnRatelimitCallback = (response: Response, request: ApiRequestOptions) => Awaitable<any>;
|
|
12
11
|
export type OnSuccessRequestCallback = (method: HttpMethods, url: `/${string}`, response: Response) => Awaitable<any>;
|
|
13
12
|
export type OnFailRequestCallback = (method: HttpMethods, url: `/${string}`, error: unknown, statusCode?: number) => Awaitable<any>;
|
|
14
|
-
export declare class ApiHandler
|
|
13
|
+
export declare class ApiHandler {
|
|
15
14
|
options: ApiHandlerInternalOptions;
|
|
16
15
|
globalBlock: boolean;
|
|
17
16
|
ratelimits: Map<string, Bucket>;
|
|
@@ -24,30 +23,22 @@ export declare class ApiHandler<TClient = unknown> {
|
|
|
24
23
|
onRatelimit?: OnRatelimitCallback;
|
|
25
24
|
onSuccessRequest?: OnSuccessRequestCallback;
|
|
26
25
|
onFailRequest?: OnFailRequestCallback;
|
|
27
|
-
pluginRestObserverProvider?: () => readonly RestObserverEntry[];
|
|
28
|
-
pluginRestObserverClient?: TClient;
|
|
29
|
-
private restObservers;
|
|
30
26
|
constructor(options: ApiHandlerOptions);
|
|
31
|
-
observe(observer: RestObserver<TClient>, _opts?: RestObserveOptions): RestObserverDisposer;
|
|
32
27
|
set debug(active: boolean);
|
|
33
28
|
get proxy(): APIRoutes;
|
|
34
29
|
globalUnblock(): void;
|
|
35
30
|
randomUUID(): UUID;
|
|
36
31
|
protected sendMessage(_body: WorkerSendApiRequest): void;
|
|
37
32
|
protected postMessage<T = unknown>(body: WorkerSendApiRequest): Promise<T>;
|
|
38
|
-
private notifyRequest;
|
|
39
33
|
private notifySuccessRequest;
|
|
40
34
|
private notifyFailRequest;
|
|
41
|
-
private notifyRatelimit;
|
|
42
|
-
private notifyRestObservers;
|
|
43
|
-
private notifyRestObserverEntries;
|
|
44
35
|
request<T = unknown>(method: HttpMethods, url: `/${string}`, { auth, ...request }?: ApiRequestOptions): Promise<T>;
|
|
45
36
|
parseError(method: HttpMethods, route: `/${string}`, response: Response, result: string | Record<string, any>, originTrace?: {
|
|
46
37
|
stack?: string;
|
|
47
38
|
}): SeyfertError;
|
|
48
39
|
parseValidationError(data: Record<string, any>, path?: string, errors?: string[]): string[];
|
|
49
40
|
handle50X(method: HttpMethods, url: `/${string}`, request: ApiRequestOptions, next: () => void): Promise<unknown>;
|
|
50
|
-
handle429(route: string, method: HttpMethods, url: `/${string}`, request: ApiRequestOptions, response: Response, result: string, next: () => void, reject: (err: unknown) => void, now: number
|
|
41
|
+
handle429(route: string, method: HttpMethods, url: `/${string}`, request: ApiRequestOptions, response: Response, result: string, next: () => void, reject: (err: unknown) => void, now: number): Promise<unknown>;
|
|
51
42
|
clearResetInterval(route: string): void;
|
|
52
43
|
setResetBucket(route: string, resp: Response, now: number, headerNow: number): void;
|
|
53
44
|
setRatelimitsBucket(route: string, resp: Response): void;
|
|
@@ -72,6 +63,3 @@ export type RestArgumentsNoBody<Q extends never | Record<string, any> = never> =
|
|
|
72
63
|
query?: Q;
|
|
73
64
|
files?: RawFile[];
|
|
74
65
|
} & RequestOptions;
|
|
75
|
-
export type RestArgumentsRequiredQuery<Q extends Record<string, any>> = Omit<RestArgumentsNoBody<Q>, 'query'> & {
|
|
76
|
-
query: Q;
|
|
77
|
-
};
|
package/lib/api/api.js
CHANGED
|
@@ -18,9 +18,6 @@ class ApiHandler {
|
|
|
18
18
|
onRatelimit;
|
|
19
19
|
onSuccessRequest;
|
|
20
20
|
onFailRequest;
|
|
21
|
-
pluginRestObserverProvider;
|
|
22
|
-
pluginRestObserverClient;
|
|
23
|
-
restObservers = new Map();
|
|
24
21
|
constructor(options) {
|
|
25
22
|
this.options = {
|
|
26
23
|
baseUrl: 'api/v10',
|
|
@@ -62,17 +59,6 @@ class ApiHandler {
|
|
|
62
59
|
};
|
|
63
60
|
}
|
|
64
61
|
}
|
|
65
|
-
observe(observer, _opts) {
|
|
66
|
-
const id = Symbol('rest-observer');
|
|
67
|
-
this.restObservers.set(id, { observer });
|
|
68
|
-
let disposed = false;
|
|
69
|
-
return () => {
|
|
70
|
-
if (disposed)
|
|
71
|
-
return;
|
|
72
|
-
disposed = true;
|
|
73
|
-
this.restObservers.delete(id);
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
62
|
set debug(active) {
|
|
77
63
|
this.debugger = active
|
|
78
64
|
? new common_1.Logger({
|
|
@@ -105,22 +91,7 @@ class ApiHandler {
|
|
|
105
91
|
this.workerPromises.set(body.nonce, { reject: rej, resolve: res });
|
|
106
92
|
});
|
|
107
93
|
}
|
|
108
|
-
async
|
|
109
|
-
await this.notifyRestObservers('onRequest', () => freezeRestPayload({
|
|
110
|
-
client: this.pluginRestObserverClient,
|
|
111
|
-
method,
|
|
112
|
-
url,
|
|
113
|
-
request: readonlyRequestOptions(request),
|
|
114
|
-
}));
|
|
115
|
-
}
|
|
116
|
-
async notifySuccessRequest(method, url, response, request) {
|
|
117
|
-
await this.notifyRestObservers('onSuccess', () => freezeRestPayload({
|
|
118
|
-
client: this.pluginRestObserverClient,
|
|
119
|
-
method,
|
|
120
|
-
url,
|
|
121
|
-
request: readonlyRequestOptions(request),
|
|
122
|
-
response,
|
|
123
|
-
}));
|
|
94
|
+
async notifySuccessRequest(method, url, response) {
|
|
124
95
|
try {
|
|
125
96
|
await this.onSuccessRequest?.(method, url, response);
|
|
126
97
|
}
|
|
@@ -128,15 +99,7 @@ class ApiHandler {
|
|
|
128
99
|
this.debugger?.warn('onSuccessRequest callback error', error);
|
|
129
100
|
}
|
|
130
101
|
}
|
|
131
|
-
async notifyFailRequest(method, url, error, statusCode
|
|
132
|
-
await this.notifyRestObservers('onFail', () => freezeRestPayload({
|
|
133
|
-
client: this.pluginRestObserverClient,
|
|
134
|
-
method,
|
|
135
|
-
url,
|
|
136
|
-
request: readonlyRequestOptions(request),
|
|
137
|
-
error,
|
|
138
|
-
statusCode,
|
|
139
|
-
}));
|
|
102
|
+
async notifyFailRequest(method, url, error, statusCode) {
|
|
140
103
|
try {
|
|
141
104
|
await this.onFailRequest?.(method, url, error, statusCode);
|
|
142
105
|
}
|
|
@@ -144,49 +107,6 @@ class ApiHandler {
|
|
|
144
107
|
this.debugger?.warn('onFailRequest callback error', callbackError);
|
|
145
108
|
}
|
|
146
109
|
}
|
|
147
|
-
async notifyRatelimit(response, request, method, url) {
|
|
148
|
-
await this.notifyRestObservers('onRatelimit', () => freezeRestPayload({
|
|
149
|
-
client: this.pluginRestObserverClient,
|
|
150
|
-
method,
|
|
151
|
-
url,
|
|
152
|
-
request: readonlyRequestOptions(request),
|
|
153
|
-
response,
|
|
154
|
-
}));
|
|
155
|
-
try {
|
|
156
|
-
await this.onRatelimit?.(response, request);
|
|
157
|
-
}
|
|
158
|
-
catch (error) {
|
|
159
|
-
this.debugger?.warn('onRatelimit callback error', error);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
async notifyRestObservers(name, createPayload) {
|
|
163
|
-
let payload;
|
|
164
|
-
let hasPayload = false;
|
|
165
|
-
const getPayload = () => {
|
|
166
|
-
if (!hasPayload) {
|
|
167
|
-
payload = createPayload();
|
|
168
|
-
hasPayload = true;
|
|
169
|
-
}
|
|
170
|
-
return payload;
|
|
171
|
-
};
|
|
172
|
-
await this.notifyRestObserverEntries(name, getPayload, this.pluginRestObserverProvider?.() ?? []);
|
|
173
|
-
await this.notifyRestObserverEntries(name, getPayload, this.restObservers.values());
|
|
174
|
-
}
|
|
175
|
-
async notifyRestObserverEntries(name, getPayload, entries) {
|
|
176
|
-
for (const entry of entries) {
|
|
177
|
-
const observer = entry.observer[name];
|
|
178
|
-
if (!observer)
|
|
179
|
-
continue;
|
|
180
|
-
const payload = getPayload();
|
|
181
|
-
try {
|
|
182
|
-
await observer(payload);
|
|
183
|
-
}
|
|
184
|
-
catch (error) {
|
|
185
|
-
const source = entry.plugin ? `[plugin:${entry.plugin}] ` : '';
|
|
186
|
-
this.debugger?.warn(`${source}REST observer "${name}" callback error`, error);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
110
|
async request(method, url, { auth = true, ...request } = {}) {
|
|
191
111
|
const originTrace = {};
|
|
192
112
|
Error.captureStackTrace(originTrace, this.request);
|
|
@@ -207,24 +127,14 @@ class ApiHandler {
|
|
|
207
127
|
const headers = {
|
|
208
128
|
'User-Agent': this.options.userAgent,
|
|
209
129
|
};
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
headers,
|
|
216
|
-
request: { ...request, auth },
|
|
217
|
-
}));
|
|
218
|
-
}
|
|
219
|
-
catch (err) {
|
|
220
|
-
next();
|
|
221
|
-
reject(err);
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
130
|
+
const { data, finalUrl } = this.parseRequest({
|
|
131
|
+
url,
|
|
132
|
+
headers,
|
|
133
|
+
request: { ...request, auth },
|
|
134
|
+
});
|
|
224
135
|
let response;
|
|
225
136
|
try {
|
|
226
137
|
const requestUrl = `${this.options.domain}/${this.options.baseUrl}${finalUrl}`;
|
|
227
|
-
await this.notifyRequest(method, finalUrl, { ...request, auth });
|
|
228
138
|
this.debugger?.debug(`Sending, Method: ${method} | Url: [${finalUrl}](${route}) | Auth: ${auth}`);
|
|
229
139
|
response = await fetch(requestUrl, {
|
|
230
140
|
method,
|
|
@@ -235,7 +145,7 @@ class ApiHandler {
|
|
|
235
145
|
}
|
|
236
146
|
catch (err) {
|
|
237
147
|
this.debugger?.debug('Fetch error', err);
|
|
238
|
-
await this.notifyFailRequest(method, finalUrl, err
|
|
148
|
+
await this.notifyFailRequest(method, finalUrl, err);
|
|
239
149
|
next();
|
|
240
150
|
reject(err);
|
|
241
151
|
return;
|
|
@@ -244,14 +154,13 @@ class ApiHandler {
|
|
|
244
154
|
const headerNow = Date.parse(response.headers.get('date') ?? '');
|
|
245
155
|
this.setRatelimitsBucket(route, response);
|
|
246
156
|
this.setResetBucket(route, response, now, headerNow);
|
|
247
|
-
const observerResponse = response.clone();
|
|
248
157
|
let result = await response.text();
|
|
249
158
|
if (response.status >= 300) {
|
|
250
159
|
if (response.status === 429) {
|
|
251
|
-
const result429 = await this.handle429(route, method, url,
|
|
160
|
+
const result429 = await this.handle429(route, method, url, request, response, result, next, reject, now);
|
|
252
161
|
if (result429 !== false)
|
|
253
162
|
return resolve(result429);
|
|
254
|
-
await this.notifyFailRequest(method, finalUrl, result, response.status
|
|
163
|
+
await this.notifyFailRequest(method, finalUrl, result, response.status);
|
|
255
164
|
return this.clearResetInterval(route);
|
|
256
165
|
}
|
|
257
166
|
if ([502, 503].includes(response.status) && ++attempts < 4) {
|
|
@@ -267,7 +176,7 @@ class ApiHandler {
|
|
|
267
176
|
}
|
|
268
177
|
catch (err) {
|
|
269
178
|
this.debugger?.warn('SeyfertError parsing result error (', result, ')', err);
|
|
270
|
-
await this.notifyFailRequest(method, finalUrl, err, response.status
|
|
179
|
+
await this.notifyFailRequest(method, finalUrl, err, response.status);
|
|
271
180
|
reject(err);
|
|
272
181
|
return;
|
|
273
182
|
}
|
|
@@ -275,7 +184,7 @@ class ApiHandler {
|
|
|
275
184
|
}
|
|
276
185
|
const parsedError = this.parseError(method, route, response, result, originTrace);
|
|
277
186
|
this.debugger?.warn(parsedError.message);
|
|
278
|
-
await this.notifyFailRequest(method, finalUrl, parsedError, response.status
|
|
187
|
+
await this.notifyFailRequest(method, finalUrl, parsedError, response.status);
|
|
279
188
|
reject(parsedError);
|
|
280
189
|
return;
|
|
281
190
|
}
|
|
@@ -286,14 +195,14 @@ class ApiHandler {
|
|
|
286
195
|
}
|
|
287
196
|
catch (err) {
|
|
288
197
|
this.debugger?.warn('Failed parsing result (', result, ')', err);
|
|
289
|
-
await this.notifyFailRequest(method, finalUrl, err, response.status
|
|
198
|
+
await this.notifyFailRequest(method, finalUrl, err, response.status);
|
|
290
199
|
next();
|
|
291
200
|
reject(err);
|
|
292
201
|
return;
|
|
293
202
|
}
|
|
294
203
|
}
|
|
295
204
|
}
|
|
296
|
-
await this.notifySuccessRequest(method, finalUrl,
|
|
205
|
+
await this.notifySuccessRequest(method, finalUrl, response);
|
|
297
206
|
next();
|
|
298
207
|
return resolve(result || undefined);
|
|
299
208
|
};
|
|
@@ -376,12 +285,15 @@ class ApiHandler {
|
|
|
376
285
|
next();
|
|
377
286
|
await (0, common_1.delay)(wait);
|
|
378
287
|
return this.request(method, url, {
|
|
379
|
-
|
|
288
|
+
body: request.body,
|
|
289
|
+
auth: request.auth,
|
|
290
|
+
reason: request.reason,
|
|
291
|
+
route: request.route,
|
|
380
292
|
unshift: true,
|
|
381
293
|
});
|
|
382
294
|
}
|
|
383
|
-
async handle429(route, method, url, request, response, result, next, reject, now
|
|
384
|
-
await this.
|
|
295
|
+
async handle429(route, method, url, request, response, result, next, reject, now) {
|
|
296
|
+
await this.onRatelimit?.(response, request);
|
|
385
297
|
const bucket = this.ratelimits.get(route);
|
|
386
298
|
let retryAfter;
|
|
387
299
|
const data = JSON.parse(result);
|
|
@@ -413,13 +325,19 @@ class ApiHandler {
|
|
|
413
325
|
await (0, common_1.delay)(retryAfter);
|
|
414
326
|
next();
|
|
415
327
|
return this.request(method, url, {
|
|
416
|
-
|
|
328
|
+
body: request.body,
|
|
329
|
+
auth: request.auth,
|
|
330
|
+
reason: request.reason,
|
|
331
|
+
route: request.route,
|
|
417
332
|
unshift: true,
|
|
418
333
|
});
|
|
419
334
|
}
|
|
420
335
|
next();
|
|
421
336
|
return this.request(method, url, {
|
|
422
|
-
|
|
337
|
+
body: request.body,
|
|
338
|
+
auth: request.auth,
|
|
339
|
+
reason: request.reason,
|
|
340
|
+
route: request.route,
|
|
423
341
|
unshift: true,
|
|
424
342
|
});
|
|
425
343
|
}
|
|
@@ -471,11 +389,7 @@ class ApiHandler {
|
|
|
471
389
|
let finalUrl = options.url;
|
|
472
390
|
let data;
|
|
473
391
|
if (options.request.auth) {
|
|
474
|
-
|
|
475
|
-
if (token === 'INVALID' || typeof token !== 'string' || token.length === 0) {
|
|
476
|
-
throw new common_1.SeyfertError('INVALID_TOKEN', { metadata: { detail: 'token is not a string' } });
|
|
477
|
-
}
|
|
478
|
-
options.headers.Authorization = `${this.options.type} ${token}`;
|
|
392
|
+
options.headers.Authorization = `${this.options.type} ${options.request.token || this.options.token}`;
|
|
479
393
|
}
|
|
480
394
|
if (options.request.query) {
|
|
481
395
|
const params = new URLSearchParams();
|
|
@@ -535,7 +449,7 @@ class ApiHandler {
|
|
|
535
449
|
.replace(/^\/webhooks\/(\d+)\/[A-Za-z0-9-_]{64,}/, '/webhooks/$1/:token');
|
|
536
450
|
if (method === 'DELETE' && route.endsWith('/messages/:id')) {
|
|
537
451
|
const messageID = url.slice(url.lastIndexOf('/') + 1);
|
|
538
|
-
const createdAt = (0, common_1.snowflakeToTimestamp)(messageID);
|
|
452
|
+
const createdAt = Number((0, common_1.snowflakeToTimestamp)(messageID));
|
|
539
453
|
if (Date.now() - createdAt >= 1000 * 60 * 60 * 24 * 14) {
|
|
540
454
|
method += '_OLD';
|
|
541
455
|
}
|
|
@@ -557,40 +471,3 @@ class ApiHandler {
|
|
|
557
471
|
}
|
|
558
472
|
}
|
|
559
473
|
exports.ApiHandler = ApiHandler;
|
|
560
|
-
function freezeRestPayload(payload) {
|
|
561
|
-
return Object.freeze(payload);
|
|
562
|
-
}
|
|
563
|
-
function readonlyRequestOptions(request) {
|
|
564
|
-
const clone = deepClonePlain({
|
|
565
|
-
...request,
|
|
566
|
-
body: request.body ? deepClonePlain(request.body) : undefined,
|
|
567
|
-
query: request.query ? deepClonePlain(request.query) : undefined,
|
|
568
|
-
files: request.files?.map(file => deepClonePlain(file)),
|
|
569
|
-
});
|
|
570
|
-
return deepFreezePlain(clone);
|
|
571
|
-
}
|
|
572
|
-
function deepClonePlain(value) {
|
|
573
|
-
if (Array.isArray(value))
|
|
574
|
-
return value.map(deepClonePlain);
|
|
575
|
-
if (!isPlainObject(value))
|
|
576
|
-
return value;
|
|
577
|
-
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, deepClonePlain(entry)]));
|
|
578
|
-
}
|
|
579
|
-
function deepFreezePlain(value) {
|
|
580
|
-
if (Array.isArray(value)) {
|
|
581
|
-
for (const entry of value)
|
|
582
|
-
deepFreezePlain(entry);
|
|
583
|
-
return Object.freeze(value);
|
|
584
|
-
}
|
|
585
|
-
if (!isPlainObject(value))
|
|
586
|
-
return value;
|
|
587
|
-
for (const entry of Object.values(value))
|
|
588
|
-
deepFreezePlain(entry);
|
|
589
|
-
return Object.freeze(value);
|
|
590
|
-
}
|
|
591
|
-
function isPlainObject(value) {
|
|
592
|
-
if (typeof value !== 'object' || value === null)
|
|
593
|
-
return false;
|
|
594
|
-
const prototype = Object.getPrototypeOf(value);
|
|
595
|
-
return prototype === Object.prototype || prototype === null;
|
|
596
|
-
}
|
package/lib/api/shared.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MakeRequired } from '../common';
|
|
2
2
|
export * from './api';
|
|
3
3
|
export * from './utils/constants';
|
|
4
4
|
export * from './utils/types';
|
|
@@ -34,32 +34,3 @@ export interface ApiRequestOptions {
|
|
|
34
34
|
token?: string;
|
|
35
35
|
}
|
|
36
36
|
export type HttpMethods = 'GET' | 'DELETE' | 'PUT' | 'POST' | 'PATCH';
|
|
37
|
-
export interface RestObserverRequestPayload<TClient = unknown> {
|
|
38
|
-
readonly client: TClient;
|
|
39
|
-
readonly method: HttpMethods;
|
|
40
|
-
readonly url: `/${string}`;
|
|
41
|
-
readonly request: Readonly<ApiRequestOptions>;
|
|
42
|
-
}
|
|
43
|
-
export interface RestObserverSuccessPayload<TClient = unknown> extends RestObserverRequestPayload<TClient> {
|
|
44
|
-
readonly response: Response;
|
|
45
|
-
}
|
|
46
|
-
export interface RestObserverFailPayload<TClient = unknown> extends RestObserverRequestPayload<TClient> {
|
|
47
|
-
readonly error: unknown;
|
|
48
|
-
readonly statusCode?: number;
|
|
49
|
-
}
|
|
50
|
-
export interface RestObserverRatelimitPayload<TClient = unknown> extends RestObserverRequestPayload<TClient> {
|
|
51
|
-
readonly response: Response;
|
|
52
|
-
}
|
|
53
|
-
export interface RestObserver<TClient = unknown> {
|
|
54
|
-
onRequest?(payload: RestObserverRequestPayload<TClient>): Awaitable<unknown>;
|
|
55
|
-
onSuccess?(payload: RestObserverSuccessPayload<TClient>): Awaitable<unknown>;
|
|
56
|
-
onFail?(payload: RestObserverFailPayload<TClient>): Awaitable<unknown>;
|
|
57
|
-
onRatelimit?(payload: RestObserverRatelimitPayload<TClient>): Awaitable<unknown>;
|
|
58
|
-
}
|
|
59
|
-
export interface RestObserverEntry<TClient = unknown> {
|
|
60
|
-
readonly plugin?: string;
|
|
61
|
-
readonly observer: RestObserver<TClient>;
|
|
62
|
-
}
|
|
63
|
-
export interface RestObserveOptions {
|
|
64
|
-
}
|
|
65
|
-
export type RestObserverDisposer = () => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const DefaultUserAgent: "DiscordBot (https://seyfert.dev, v4.
|
|
1
|
+
export declare const DefaultUserAgent: "DiscordBot (https://seyfert.dev, v4.4.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_TAG_BADGE_EXTENSIONS = exports.ALLOWED_SOUNDS_EXTENSIONS = exports.ALLOWED_SIZES = exports.ALLOWED_STICKER_EXTENSIONS = exports.ALLOWED_EXTENSIONS = exports.DefaultUserAgent = void 0;
|
|
4
|
-
exports.DefaultUserAgent = 'DiscordBot (https://seyfert.dev, v4.
|
|
4
|
+
exports.DefaultUserAgent = 'DiscordBot (https://seyfert.dev, v4.4.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];
|
package/lib/api/utils/utils.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { Snowflake } from '../../types';
|
|
2
|
-
import type { UserAvatarDefault } from '../Routes/cdn';
|
|
3
2
|
/**
|
|
4
3
|
* Calculates the default avatar index for a given user id.
|
|
5
4
|
*
|
|
6
5
|
* @param userId - The user id to calculate the default avatar index for
|
|
7
6
|
*/
|
|
8
|
-
export declare function calculateUserDefaultAvatarIndex(userId: Snowflake, discriminator: string):
|
|
7
|
+
export declare function calculateUserDefaultAvatarIndex(userId: Snowflake, discriminator: string): number;
|
|
9
8
|
/**
|
|
10
9
|
* Verifies that a value is a buffer-like object.
|
|
11
10
|
*
|
package/lib/api/utils/utils.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.isBufferLike = isBufferLike;
|
|
|
8
8
|
* @param userId - The user id to calculate the default avatar index for
|
|
9
9
|
*/
|
|
10
10
|
function calculateUserDefaultAvatarIndex(userId, discriminator) {
|
|
11
|
-
return
|
|
11
|
+
return discriminator === '0' ? Number(BigInt(userId) >> 22n) % 6 : Number.parseInt(discriminator) % 5;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Verifies that a value is a buffer-like object.
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MediaGalleryItem = exports.MediaGallery = void 0;
|
|
4
|
-
const common_1 = require("../common");
|
|
5
4
|
const types_1 = require("../types");
|
|
6
5
|
const Base_1 = require("./Base");
|
|
7
6
|
/**
|
|
@@ -105,15 +104,6 @@ class MediaGalleryItem {
|
|
|
105
104
|
* @returns The JSON representation of the item data.
|
|
106
105
|
*/
|
|
107
106
|
toJSON() {
|
|
108
|
-
if (!this.data.media)
|
|
109
|
-
throw new common_1.SeyfertError('MISSING_MEDIA', {
|
|
110
|
-
metadata: {
|
|
111
|
-
...(0, common_1.createValidationMetadata)('media to be set before calling toJSON()', this.data.media, {
|
|
112
|
-
component: 'MediaGalleryItem',
|
|
113
|
-
}),
|
|
114
|
-
detail: 'Cannot convert to JSON without media.',
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
107
|
return { ...this.data };
|
|
118
108
|
}
|
|
119
109
|
}
|
package/lib/builders/Modal.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { RestOrArray } from '../common';
|
|
2
2
|
import { type APIModalInteractionResponseCallbackData, type APITextInputComponent, type TextInputStyle } from '../types';
|
|
3
3
|
import { BaseComponentBuilder, type OptionValuesLength } from './Base';
|
|
4
4
|
import type { ModalBuilderComponents, ModalSubmitCallback } from './types';
|
|
@@ -8,16 +8,10 @@ import type { ModalBuilderComponents, ModalSubmitCallback } from './types';
|
|
|
8
8
|
* @example
|
|
9
9
|
* const modal = new Modal();
|
|
10
10
|
* modal.setTitle("Sample Modal");
|
|
11
|
-
* modal.setCustomId("sample-modal");
|
|
12
11
|
* modal.addComponents(
|
|
13
|
-
* new
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* new TextInput()
|
|
17
|
-
* .setCustomId("sample-input")
|
|
18
|
-
* .setStyle(TextInputStyle.Paragraph)
|
|
19
|
-
* )
|
|
20
|
-
* );
|
|
12
|
+
* new ActionRow<TextInput>()
|
|
13
|
+
* .addComponents(new TextInput().setLabel("Enter text"))
|
|
14
|
+
* ));
|
|
21
15
|
* modal.run((interaction) => {
|
|
22
16
|
* // Handle modal submission
|
|
23
17
|
* });
|
|
@@ -70,14 +64,10 @@ export declare class Modal {
|
|
|
70
64
|
/**
|
|
71
65
|
* Represents a text input component builder.
|
|
72
66
|
* @example
|
|
73
|
-
* const textInput = new TextInput()
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* const label = new Label()
|
|
78
|
-
* .setLabel("Feedback")
|
|
79
|
-
* .setComponent(textInput);
|
|
80
|
-
* const json = label.toJSON();
|
|
67
|
+
* const textInput = new TextInput().setLabel("Enter text");
|
|
68
|
+
* textInput.setStyle(TextInputStyle.Paragraph);
|
|
69
|
+
* textInput.setPlaceholder("Type here");
|
|
70
|
+
* const json = textInput.toJSON();
|
|
81
71
|
*/
|
|
82
72
|
export declare class TextInput extends BaseComponentBuilder<APITextInputComponent> {
|
|
83
73
|
/**
|
package/lib/builders/Modal.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TextInput = exports.Modal = void 0;
|
|
4
|
-
const common_1 = require("../common");
|
|
5
4
|
const types_1 = require("../types");
|
|
6
5
|
const _1 = require(".");
|
|
7
6
|
const Base_1 = require("./Base");
|
|
@@ -11,16 +10,10 @@ const Base_1 = require("./Base");
|
|
|
11
10
|
* @example
|
|
12
11
|
* const modal = new Modal();
|
|
13
12
|
* modal.setTitle("Sample Modal");
|
|
14
|
-
* modal.setCustomId("sample-modal");
|
|
15
13
|
* modal.addComponents(
|
|
16
|
-
* new
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* new TextInput()
|
|
20
|
-
* .setCustomId("sample-input")
|
|
21
|
-
* .setStyle(TextInputStyle.Paragraph)
|
|
22
|
-
* )
|
|
23
|
-
* );
|
|
14
|
+
* new ActionRow<TextInput>()
|
|
15
|
+
* .addComponents(new TextInput().setLabel("Enter text"))
|
|
16
|
+
* ));
|
|
24
17
|
* modal.run((interaction) => {
|
|
25
18
|
* // Handle modal submission
|
|
26
19
|
* });
|
|
@@ -89,24 +82,6 @@ class Modal {
|
|
|
89
82
|
* @returns The modal data in JSON format.
|
|
90
83
|
*/
|
|
91
84
|
toJSON() {
|
|
92
|
-
if (!this.data.custom_id)
|
|
93
|
-
throw new common_1.SeyfertError('MISSING_MODAL_CUSTOM_ID', {
|
|
94
|
-
metadata: {
|
|
95
|
-
...(0, common_1.createValidationMetadata)('custom_id to be set before calling toJSON()', this.data.custom_id, {
|
|
96
|
-
component: 'Modal',
|
|
97
|
-
}),
|
|
98
|
-
detail: 'Cannot convert to JSON without a custom_id.',
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
if (!this.data.title)
|
|
102
|
-
throw new common_1.SeyfertError('MISSING_MODAL_TITLE', {
|
|
103
|
-
metadata: {
|
|
104
|
-
...(0, common_1.createValidationMetadata)('title to be set before calling toJSON()', this.data.title, {
|
|
105
|
-
component: 'Modal',
|
|
106
|
-
}),
|
|
107
|
-
detail: 'Cannot convert to JSON without a title.',
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
85
|
return {
|
|
111
86
|
custom_id: this.data.custom_id,
|
|
112
87
|
title: this.data.title,
|
|
@@ -118,14 +93,10 @@ exports.Modal = Modal;
|
|
|
118
93
|
/**
|
|
119
94
|
* Represents a text input component builder.
|
|
120
95
|
* @example
|
|
121
|
-
* const textInput = new TextInput()
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* const label = new Label()
|
|
126
|
-
* .setLabel("Feedback")
|
|
127
|
-
* .setComponent(textInput);
|
|
128
|
-
* const json = label.toJSON();
|
|
96
|
+
* const textInput = new TextInput().setLabel("Enter text");
|
|
97
|
+
* textInput.setStyle(TextInputStyle.Paragraph);
|
|
98
|
+
* textInput.setPlaceholder("Type here");
|
|
99
|
+
* const json = textInput.toJSON();
|
|
129
100
|
*/
|
|
130
101
|
class TextInput extends Base_1.BaseComponentBuilder {
|
|
131
102
|
/**
|
package/lib/builders/Poll.js
CHANGED
|
@@ -33,24 +33,6 @@ class PollBuilder {
|
|
|
33
33
|
return this;
|
|
34
34
|
}
|
|
35
35
|
toJSON() {
|
|
36
|
-
if (!this.data.question?.text && !this.data.question?.emoji)
|
|
37
|
-
throw new common_1.SeyfertError('MISSING_POLL_QUESTION', {
|
|
38
|
-
metadata: {
|
|
39
|
-
...(0, common_1.createValidationMetadata)('question to be set before calling toJSON()', this.data.question, {
|
|
40
|
-
component: 'PollBuilder',
|
|
41
|
-
}),
|
|
42
|
-
detail: 'Cannot convert to JSON without a question.',
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
if (!this.data.answers?.length)
|
|
46
|
-
throw new common_1.SeyfertError('MISSING_POLL_ANSWERS', {
|
|
47
|
-
metadata: {
|
|
48
|
-
...(0, common_1.createValidationMetadata)('at least one answer to be set before calling toJSON()', this.data.answers, {
|
|
49
|
-
component: 'PollBuilder',
|
|
50
|
-
}),
|
|
51
|
-
detail: 'Cannot convert to JSON without answers.',
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
36
|
return { ...this.data };
|
|
55
37
|
}
|
|
56
38
|
resolvedPollMedia(data) {
|