types: Export some core-specific types (#10620)

types: export core-specific types

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Jiralite
2024-12-05 09:09:43 +00:00
committed by GitHub
parent eceaa85ad4
commit abf4b6103c
4 changed files with 65 additions and 58 deletions

View File

@@ -41,6 +41,14 @@ export interface StartForumThreadOptions extends RESTPostAPIGuildForumThreadsJSO
message: RESTPostAPIGuildForumThreadsJSONBody['message'] & { files?: RawFile[] }; message: RESTPostAPIGuildForumThreadsJSONBody['message'] & { files?: RawFile[] };
} }
export interface CreateMessageOptions extends RESTPostAPIChannelMessageJSONBody {
files?: RawFile[];
}
export interface EditMessageOptions extends RESTPatchAPIChannelMessageJSONBody {
files?: RawFile[];
}
export class ChannelsAPI { export class ChannelsAPI {
public constructor(private readonly rest: REST) {} public constructor(private readonly rest: REST) {}
@@ -54,7 +62,7 @@ export class ChannelsAPI {
*/ */
public async createMessage( public async createMessage(
channelId: Snowflake, channelId: Snowflake,
{ files, ...body }: RESTPostAPIChannelMessageJSONBody & { files?: RawFile[] }, { files, ...body }: CreateMessageOptions,
{ signal }: Pick<RequestData, 'signal'> = {}, { signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.rest.post(Routes.channelMessages(channelId), { return this.rest.post(Routes.channelMessages(channelId), {
@@ -76,7 +84,7 @@ export class ChannelsAPI {
public async editMessage( public async editMessage(
channelId: Snowflake, channelId: Snowflake,
messageId: Snowflake, messageId: Snowflake,
{ files, ...body }: RESTPatchAPIChannelMessageJSONBody & { files?: RawFile[] }, { files, ...body }: EditMessageOptions,
{ signal }: Pick<RequestData, 'signal'> = {}, { signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.rest.patch(Routes.channelMessage(channelId, messageId), { return this.rest.patch(Routes.channelMessage(channelId, messageId), {

View File

@@ -1,6 +1,6 @@
/* eslint-disable jsdoc/check-param-names */ /* eslint-disable jsdoc/check-param-names */
import { makeURLSearchParams, type REST, type RawFile, type RequestData } from '@discordjs/rest'; import { makeURLSearchParams, type RawFile, type REST, type RequestData } from '@discordjs/rest';
import { import {
Routes, Routes,
type GuildMFALevel, type GuildMFALevel,
@@ -110,6 +110,10 @@ import {
} from 'discord-api-types/v10'; } from 'discord-api-types/v10';
import { VoiceAPI } from './voice'; import { VoiceAPI } from './voice';
export interface CreateStickerOptions extends Omit<RESTPostAPIGuildStickerFormDataBody, 'file'> {
file: RawFile;
}
export class GuildsAPI { export class GuildsAPI {
public constructor(private readonly rest: REST) {} public constructor(private readonly rest: REST) {}
@@ -1013,7 +1017,7 @@ export class GuildsAPI {
*/ */
public async createSticker( public async createSticker(
guildId: Snowflake, guildId: Snowflake,
{ file, ...body }: Omit<RESTPostAPIGuildStickerFormDataBody, 'file'> & { file: RawFile }, { file, ...body }: CreateStickerOptions,
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {}, { reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
) { ) {
const fileData = { ...file, key: 'file' }; const fileData = { ...file, key: 'file' };

View File

@@ -16,6 +16,26 @@ import {
} from 'discord-api-types/v10'; } from 'discord-api-types/v10';
import type { WebhooksAPI } from './webhook.js'; import type { WebhooksAPI } from './webhook.js';
export interface CreateInteractionResponseOptions
extends APIInteractionResponseCallbackData,
RESTPostAPIInteractionCallbackQuery {
files?: RawFile[];
}
export type CreateInteractionDeferResponseOptions = APIInteractionResponseDeferredChannelMessageWithSource['data'] &
RESTPostAPIInteractionCallbackQuery;
export type CreateInteractionFollowUpResponseOptions = APIInteractionResponseCallbackData & { files?: RawFile[] };
export type EditInteractionResponseOptions = APIInteractionResponseCallbackData & { files?: RawFile[] };
export type CreateInteractionUpdateMessageResponseOptions = APIInteractionResponseCallbackData &
RESTPostAPIInteractionCallbackQuery & { files?: RawFile[] };
export type CreateAutocompleteResponseOptions = APICommandAutocompleteInteractionResponseCallbackData &
RESTPostAPIInteractionCallbackQuery;
export type CreateModalResponseOptions = APIModalInteractionResponseCallbackData & RESTPostAPIInteractionCallbackQuery;
export class InteractionsAPI { export class InteractionsAPI {
public constructor( public constructor(
private readonly rest: REST, private readonly rest: REST,
@@ -34,8 +54,7 @@ export class InteractionsAPI {
public async reply( public async reply(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
body: APIInteractionResponseCallbackData & body: CreateInteractionResponseOptions & { with_response: true },
RESTPostAPIInteractionCallbackQuery & { files?: RawFile[]; with_response: true },
options?: Pick<RequestData, 'signal'>, options?: Pick<RequestData, 'signal'>,
): Promise<RESTPostAPIInteractionCallbackWithResponseResult>; ): Promise<RESTPostAPIInteractionCallbackWithResponseResult>;
@@ -51,19 +70,14 @@ export class InteractionsAPI {
public async reply( public async reply(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
body: APIInteractionResponseCallbackData & body: CreateInteractionResponseOptions & { with_response?: false },
RESTPostAPIInteractionCallbackQuery & { files?: RawFile[]; with_response?: false },
options?: Pick<RequestData, 'signal'>, options?: Pick<RequestData, 'signal'>,
): Promise<undefined>; ): Promise<undefined>;
public async reply( public async reply(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
{ { files, with_response, ...data }: CreateInteractionResponseOptions,
files,
with_response,
...data
}: APIInteractionResponseCallbackData & RESTPostAPIInteractionCallbackQuery & { files?: RawFile[] },
{ signal }: Pick<RequestData, 'signal'> = {}, { signal }: Pick<RequestData, 'signal'> = {},
) { ) {
const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
@@ -92,8 +106,7 @@ export class InteractionsAPI {
public async defer( public async defer(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
body: APIInteractionResponseDeferredChannelMessageWithSource['data'] & body: CreateInteractionDeferResponseOptions & { with_response: true },
RESTPostAPIInteractionCallbackQuery & { with_response: true },
options?: Pick<RequestData, 'signal'>, options?: Pick<RequestData, 'signal'>,
): Promise<RESTPostAPIInteractionCallbackWithResponseResult>; ): Promise<RESTPostAPIInteractionCallbackWithResponseResult>;
@@ -109,18 +122,14 @@ export class InteractionsAPI {
public async defer( public async defer(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
body?: APIInteractionResponseDeferredChannelMessageWithSource['data'] & body?: CreateInteractionDeferResponseOptions & { with_response?: false },
RESTPostAPIInteractionCallbackQuery & { with_response?: false },
options?: Pick<RequestData, 'signal'>, options?: Pick<RequestData, 'signal'>,
): Promise<undefined>; ): Promise<undefined>;
public async defer( public async defer(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
{ { with_response, ...data }: CreateInteractionDeferResponseOptions = {},
with_response,
...data
}: APIInteractionResponseDeferredChannelMessageWithSource['data'] & RESTPostAPIInteractionCallbackQuery = {},
{ signal }: Pick<RequestData, 'signal'> = {}, { signal }: Pick<RequestData, 'signal'> = {},
) { ) {
const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
@@ -198,7 +207,7 @@ export class InteractionsAPI {
public async followUp( public async followUp(
applicationId: Snowflake, applicationId: Snowflake,
interactionToken: string, interactionToken: string,
body: APIInteractionResponseCallbackData & { files?: RawFile[] }, body: CreateInteractionFollowUpResponseOptions,
{ signal }: Pick<RequestData, 'signal'> = {}, { signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.webhooks.execute(applicationId, interactionToken, { ...body, wait: true }, { signal }); return this.webhooks.execute(applicationId, interactionToken, { ...body, wait: true }, { signal });
@@ -218,7 +227,7 @@ export class InteractionsAPI {
public async editReply( public async editReply(
applicationId: Snowflake, applicationId: Snowflake,
interactionToken: string, interactionToken: string,
callbackData: APIInteractionResponseCallbackData & { files?: RawFile[] }, callbackData: EditInteractionResponseOptions,
messageId?: Snowflake | '@original', messageId?: Snowflake | '@original',
{ signal }: Pick<RequestData, 'signal'> = {}, { signal }: Pick<RequestData, 'signal'> = {},
) { ) {
@@ -280,8 +289,7 @@ export class InteractionsAPI {
public async updateMessage( public async updateMessage(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
callbackData: APIInteractionResponseCallbackData & callbackData: CreateInteractionUpdateMessageResponseOptions & { with_response: true },
RESTPostAPIInteractionCallbackQuery & { files?: RawFile[]; with_response: true },
options: Pick<RequestData, 'signal'>, options: Pick<RequestData, 'signal'>,
): Promise<RESTPostAPIInteractionCallbackWithResponseResult>; ): Promise<RESTPostAPIInteractionCallbackWithResponseResult>;
@@ -297,19 +305,14 @@ export class InteractionsAPI {
public async updateMessage( public async updateMessage(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
callbackData: APIInteractionResponseCallbackData & callbackData: CreateInteractionUpdateMessageResponseOptions & { with_response?: false },
RESTPostAPIInteractionCallbackQuery & { files?: RawFile[]; with_response?: false },
options: Pick<RequestData, 'signal'>, options: Pick<RequestData, 'signal'>,
): Promise<undefined>; ): Promise<undefined>;
public async updateMessage( public async updateMessage(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
{ { files, with_response, ...data }: CreateInteractionUpdateMessageResponseOptions,
files,
with_response,
...data
}: APIInteractionResponseCallbackData & RESTPostAPIInteractionCallbackQuery & { files?: RawFile[] },
{ signal }: Pick<RequestData, 'signal'> = {}, { signal }: Pick<RequestData, 'signal'> = {},
) { ) {
const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
@@ -337,8 +340,7 @@ export class InteractionsAPI {
public async createAutocompleteResponse( public async createAutocompleteResponse(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
callbackData: APICommandAutocompleteInteractionResponseCallbackData & callbackData: CreateAutocompleteResponseOptions & { with_response: true },
RESTPostAPIInteractionCallbackQuery & { with_response: true },
options?: Pick<RequestData, 'signal'>, options?: Pick<RequestData, 'signal'>,
): Promise<APICommandAutocompleteInteractionResponseCallbackData>; ): Promise<APICommandAutocompleteInteractionResponseCallbackData>;
@@ -354,18 +356,14 @@ export class InteractionsAPI {
public async createAutocompleteResponse( public async createAutocompleteResponse(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
callbackData: APICommandAutocompleteInteractionResponseCallbackData & callbackData: CreateAutocompleteResponseOptions & { with_response?: false },
RESTPostAPIInteractionCallbackQuery & { with_response?: false },
options: Pick<RequestData, 'signal'>, options: Pick<RequestData, 'signal'>,
): Promise<undefined>; ): Promise<undefined>;
public async createAutocompleteResponse( public async createAutocompleteResponse(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
{ { with_response, ...data }: CreateAutocompleteResponseOptions,
with_response,
...data
}: APICommandAutocompleteInteractionResponseCallbackData & RESTPostAPIInteractionCallbackQuery,
{ signal }: Pick<RequestData, 'signal'> = {}, { signal }: Pick<RequestData, 'signal'> = {},
) { ) {
const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
@@ -392,8 +390,7 @@ export class InteractionsAPI {
public async createModal( public async createModal(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
callbackData: APIModalInteractionResponseCallbackData & callbackData: CreateModalResponseOptions & { with_response: true },
RESTPostAPIInteractionCallbackQuery & { with_response: true },
options?: Pick<RequestData, 'signal'>, options?: Pick<RequestData, 'signal'>,
): Promise<RESTPostAPIInteractionCallbackWithResponseResult>; ): Promise<RESTPostAPIInteractionCallbackWithResponseResult>;
@@ -409,15 +406,14 @@ export class InteractionsAPI {
public async createModal( public async createModal(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
callbackData: APIModalInteractionResponseCallbackData & callbackData: CreateModalResponseOptions & { with_response?: false },
RESTPostAPIInteractionCallbackQuery & { with_response?: false },
options?: Pick<RequestData, 'signal'>, options?: Pick<RequestData, 'signal'>,
): Promise<undefined>; ): Promise<undefined>;
public async createModal( public async createModal(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
{ with_response, ...data }: APIModalInteractionResponseCallbackData & RESTPostAPIInteractionCallbackQuery, { with_response, ...data }: CreateModalResponseOptions,
{ signal }: Pick<RequestData, 'signal'> = {}, { signal }: Pick<RequestData, 'signal'> = {},
) { ) {
const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {

View File

@@ -18,6 +18,14 @@ import {
type Snowflake, type Snowflake,
} from 'discord-api-types/v10'; } from 'discord-api-types/v10';
export type CreateWebhookMessageOptions = RESTPostAPIWebhookWithTokenJSONBody &
RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[] };
export type EditWebhookMessageOptions = RESTPatchAPIWebhookWithTokenMessageJSONBody & {
files?: RawFile[];
thread_id?: string;
};
export class WebhooksAPI { export class WebhooksAPI {
public constructor(private readonly rest: REST) {} public constructor(private readonly rest: REST) {}
@@ -92,7 +100,7 @@ export class WebhooksAPI {
public async execute( public async execute(
id: Snowflake, id: Snowflake,
token: string, token: string,
body: RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[]; wait: true }, body: CreateWebhookMessageOptions & { wait: true },
options?: Pick<RequestData, 'signal'>, options?: Pick<RequestData, 'signal'>,
): Promise<RESTPostAPIWebhookWithTokenWaitResult>; ): Promise<RESTPostAPIWebhookWithTokenWaitResult>;
@@ -108,7 +116,7 @@ export class WebhooksAPI {
public async execute( public async execute(
id: Snowflake, id: Snowflake,
token: string, token: string,
body: RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[]; wait?: false }, body: CreateWebhookMessageOptions & { wait?: false },
options?: Pick<RequestData, 'signal'>, options?: Pick<RequestData, 'signal'>,
): Promise<void>; ): Promise<void>;
@@ -124,12 +132,7 @@ export class WebhooksAPI {
public async execute( public async execute(
id: Snowflake, id: Snowflake,
token: string, token: string,
{ { wait, thread_id, files, ...body }: CreateWebhookMessageOptions,
wait,
thread_id,
files,
...body
}: RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[] },
{ signal }: Pick<RequestData, 'signal'> = {}, { signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.rest.post(Routes.webhook(id, token), { return this.rest.post(Routes.webhook(id, token), {
@@ -230,11 +233,7 @@ export class WebhooksAPI {
id: Snowflake, id: Snowflake,
token: string, token: string,
messageId: Snowflake, messageId: Snowflake,
{ { thread_id, files, ...body }: EditWebhookMessageOptions,
thread_id,
files,
...body
}: RESTPatchAPIWebhookWithTokenMessageJSONBody & { files?: RawFile[]; thread_id?: string },
{ signal }: Pick<RequestData, 'signal'> = {}, { signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.rest.patch(Routes.webhookMessage(id, token, messageId), { return this.rest.patch(Routes.webhookMessage(id, token, messageId), {