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

@@ -1,86 +1,22 @@
/* eslint-disable jsdoc/check-param-names */
import type { RawFile, RequestData, REST } from '@discordjs/rest';
import type { RequestData, REST } from '@discordjs/rest';
import {
Routes,
type APIThreadChannel,
type APIThreadMember,
type RESTGetAPIChannelThreadMembersResult,
type RESTPostAPIChannelThreadsJSONBody,
type RESTPostAPIChannelThreadsResult,
type RESTPostAPIGuildForumThreadsJSONBody,
type Snowflake,
} from 'discord-api-types/v10';
export interface StartForumThreadOptions extends RESTPostAPIGuildForumThreadsJSONBody {
message: RESTPostAPIGuildForumThreadsJSONBody['message'] & { files?: RawFile[] };
}
export class ThreadsAPI {
public constructor(private readonly rest: REST) {}
/**
* Fetches a thread
*
* @see {@link https://discord.com/developers/docs/resources/channel#get-channel}
* @param threadId - The id of the thread
* @param options - The options to use when fetching the thread
*/
public async get(threadId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.channel(threadId), { signal }) as Promise<APIThreadChannel>;
}
/**
* 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 to use when starting the thread
* @param messageId - The id of the message to start the thread from
* @param options - The options to use when starting the thread
*/
public async create(
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 to use when starting the thread
* @param options - The options to use when 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>;
}
/**
* Adds the current user to a thread
*
* @see {@link https://discord.com/developers/docs/resources/channel#join-thread}
* @param threadId - The id of the thread to join
* @param options - The options to use when joining the thread
* @param options - The options for joining the thread
*/
public async join(threadId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
await this.rest.put(Routes.threadMembers(threadId, '@me'), { signal });
@@ -92,7 +28,7 @@ export class ThreadsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#add-thread-member}
* @param threadId - The id of the thread to add the member to
* @param userId - The id of the user to add to the thread
* @param options - The options to use when adding the member to the thread
* @param options - The options for adding the member to the thread
*/
public async addMember(threadId: Snowflake, userId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
await this.rest.put(Routes.threadMembers(threadId, userId), { signal });
@@ -103,7 +39,7 @@ export class ThreadsAPI {
*
* @see {@link https://discord.com/developers/docs/resources/channel#leave-thread}
* @param threadId - The id of the thread to leave
* @param options - The options to use when leaving the thread
* @param options - The options for leaving the thread
*/
public async leave(threadId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
await this.rest.delete(Routes.threadMembers(threadId, '@me'), { signal });
@@ -115,7 +51,7 @@ export class ThreadsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#remove-thread-member}
* @param threadId - The id of the thread to remove the member from
* @param userId - The id of the user to remove from the thread
* @param options - The options to use when removing the member from the thread
* @param options - The options for removing the member from the thread
*/
public async removeMember(threadId: Snowflake, userId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
await this.rest.delete(Routes.threadMembers(threadId, userId), { signal });
@@ -127,7 +63,7 @@ export class ThreadsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#get-thread-member}
* @param threadId - The id of the thread to fetch the member from
* @param userId - The id of the user
* @param options - The options to use when fetching the member
* @param options - The options for fetching the member
*/
public async getMember(threadId: Snowflake, userId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.threadMembers(threadId, userId), { signal }) as Promise<APIThreadMember>;
@@ -138,7 +74,7 @@ export class ThreadsAPI {
*
* @see {@link https://discord.com/developers/docs/resources/channel#list-thread-members}
* @param threadId - The id of the thread to fetch the members from
* @param options - The options to use when fetching the members
* @param options - The options for fetching the members
*/
public async getAllMembers(threadId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.threadMembers(threadId), { signal }) as Promise<RESTGetAPIChannelThreadMembersResult>;