fix(core): fix inconsistencies on core (#9680)

* fix(core): fix inconsistencies on `core`

* fix: add `createForumPost` back

* fix: create -> createWebhook
This commit is contained in:
Suneet Tipirneni
2023-07-06 09:35:10 -04:00
committed by GitHub
parent 75d91b52b3
commit 6d5840c61e
12 changed files with 167 additions and 178 deletions

View File

@@ -3,6 +3,8 @@
import { makeURLSearchParams, type RawFile, type REST, type RequestData } from '@discordjs/rest';
import {
Routes,
type RESTPostAPIChannelWebhookJSONBody,
type RESTPostAPIChannelWebhookResult,
type RESTDeleteAPIChannelResult,
type RESTGetAPIChannelInvitesResult,
type RESTGetAPIChannelMessageReactionUsersQuery,
@@ -26,8 +28,16 @@ import {
type RESTPostAPIChannelMessageJSONBody,
type RESTPostAPIChannelMessageResult,
type Snowflake,
type RESTPostAPIChannelThreadsJSONBody,
type RESTPostAPIChannelThreadsResult,
type APIThreadChannel,
type RESTPostAPIGuildForumThreadsJSONBody,
} from 'discord-api-types/v10';
export interface StartForumThreadOptions extends RESTPostAPIGuildForumThreadsJSONBody {
message: RESTPostAPIGuildForumThreadsJSONBody['message'] & { files?: RawFile[] };
}
export class ChannelsAPI {
public constructor(private readonly rest: REST) {}
@@ -36,8 +46,8 @@ export class ChannelsAPI {
*
* @see {@link https://discord.com/developers/docs/resources/channel#create-message}
* @param channelId - The id of the channel to send the message in
* @param body - The data to use when sending the message
* @param options - The options to use when sending the message
* @param body - The data for sending the message
* @param options - The options for sending the message
*/
public async createMessage(
channelId: Snowflake,
@@ -57,8 +67,8 @@ export class ChannelsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#edit-message}
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to edit
* @param body - The data to use when editing the message
* @param options - The options to use when editing the message
* @param body - The data for editing the message
* @param options - The options for editing the message
*/
public async editMessage(
channelId: Snowflake,
@@ -80,7 +90,7 @@ export class ChannelsAPI {
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to get the reactions for
* @param emoji - The emoji to get the reactions for
* @param query - The query options to use when fetching the reactions
* @param query - The query options for fetching the reactions
* @param options - The options for fetching the message reactions
*/
public async getMessageReactions(
@@ -233,7 +243,7 @@ export class ChannelsAPI {
*
* @see {@link https://discord.com/developers/docs/resources/channel#get-channel-messages}
* @param channelId - The id of the channel to fetch messages from
* @param query - The query options to use when fetching messages
* @param query - The query options for fetching messages
* @param options - The options for fetching the messages
*/
public async getMessages(
@@ -389,7 +399,7 @@ export class ChannelsAPI {
*
* @see {@link https://discord.com/developers/docs/resources/channel#create-channel-invite}
* @param channelId - The id of the channel to create an invite for
* @param body - The data to use when creating the invite
* @param body - The data for creating the invite
* @param options - The options for creating the invite
*/
public async createInvite(
@@ -415,6 +425,51 @@ export class ChannelsAPI {
return this.rest.get(Routes.channelInvites(channelId), { signal }) as Promise<RESTGetAPIChannelInvitesResult>;
}
/**
* Creates a new thread
*
* @see {@link https://discord.com/developers/docs/resources/channel#start-thread-from-message}
* @see {@link https://discord.com/developers/docs/resources/channel#start-thread-without-message}
* @param channelId - The id of the channel to start the thread in
* @param body - The data for starting the thread
* @param messageId - The id of the message to start the thread from
* @param options - The options for starting the thread
*/
public async createThread(
channelId: Snowflake,
body: RESTPostAPIChannelThreadsJSONBody,
messageId?: Snowflake,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.post(Routes.threads(channelId, messageId), {
body,
signal,
}) as Promise<RESTPostAPIChannelThreadsResult>;
}
/**
* Creates a new forum post
*
* @see {@link https://discord.com/developers/docs/resources/channel#start-thread-in-forum-channel}
* @param channelId - The id of the forum channel to start the thread in
* @param body - The data for starting the thread
* @param options - The options for starting the thread
*/
public async createForumThread(
channelId: Snowflake,
{ message, ...optionsBody }: StartForumThreadOptions,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
const { files, ...messageBody } = message;
const body = {
...optionsBody,
message: messageBody,
};
return this.rest.post(Routes.threads(channelId), { files, body, signal }) as Promise<APIThreadChannel>;
}
/**
* Fetches the archived threads of a channel
*
@@ -422,7 +477,7 @@ export class ChannelsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#list-private-archived-threads}
* @param channelId - The id of the channel to fetch archived threads from
* @param archivedStatus - The archived status of the threads to fetch
* @param query - The options to use when fetching archived threads
* @param query - The options for fetching archived threads
* @param options - The options for fetching archived threads
*/
public async getArchivedThreads(
@@ -442,7 +497,7 @@ export class ChannelsAPI {
*
* @see {@link https://discord.com/developers/docs/resources/channel#list-joined-private-archived-threads}
* @param channelId - The id of the channel to fetch joined archived threads from
* @param query - The options to use when fetching joined archived threads
* @param query - The options for fetching joined archived threads
* @param options - The options for fetching joined archived threads
*/
public async getJoinedPrivateArchivedThreads(
@@ -456,13 +511,33 @@ export class ChannelsAPI {
}) as Promise<RESTGetAPIChannelUsersThreadsArchivedResult>;
}
/**
* Creates a new webhook
*
* @see {@link https://discord.com/developers/docs/resources/webhook#create-webhook}
* @param channelId - The id of the channel to create the webhook in
* @param body - The data for creating the webhook
* @param options - The options for creating the webhook
*/
public async createWebhook(
channelId: Snowflake,
body: RESTPostAPIChannelWebhookJSONBody,
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
) {
return this.rest.post(Routes.channelWebhooks(channelId), {
reason,
body,
signal,
}) as Promise<RESTPostAPIChannelWebhookResult>;
}
/**
* Fetches the webhooks of a channel
*
* @see {@link https://discord.com/developers/docs/resources/webhook#get-channel-webhooks}
* @param id - The id of the channel
* @param channelId - The id of the channel
*/
public async getWebhooks(id: Snowflake) {
return this.rest.get(Routes.channelWebhooks(id)) as Promise<RESTGetAPIChannelWebhooksResult>;
public async getWebhooks(channelId: Snowflake) {
return this.rest.get(Routes.channelWebhooks(channelId)) as Promise<RESTGetAPIChannelWebhooksResult>;
}
}