Skip to content

Commit

Permalink
Merge branch 'main' into types/loosen-message-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Jul 7, 2023
2 parents 343ad32 + cf8012c commit dbfa42f
Show file tree
Hide file tree
Showing 32 changed files with 269 additions and 218 deletions.
2 changes: 1 addition & 1 deletion packages/builders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@discordjs/formatters": "workspace:^",
"@discordjs/util": "workspace:^",
"@sapphire/shapeshift": "^3.9.0",
"discord-api-types": "^0.37.42",
"discord-api-types": "^0.37.45",
"fast-deep-equal": "^3.1.3",
"ts-mixer": "^6.0.3",
"tslib": "^2.5.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class SharedNameAndDescription {
}

/**
* SSets a name localization for this command.
* Sets a name localization for this command.
*
* @param locale - The locale to set
* @param localizedName - The localized name for the given `locale`
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@discordjs/ws": "workspace:^",
"@sapphire/snowflake": "^3.5.1",
"@vladfrangu/async_event_emitter": "^2.2.2",
"discord-api-types": "^0.37.42"
"discord-api-types": "^0.37.45"
},
"devDependencies": {
"@favware/cliff-jumper": "^2.0.0",
Expand Down
36 changes: 18 additions & 18 deletions packages/core/src/api/applicationCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export class ApplicationCommandsAPI {
*
* @see {@link https://discord.com/developers/docs/interactions/application-commands#get-global-application-commands}
* @param applicationId - The application id to fetch commands for
* @param query - The query options to use when fetching commands
* @param options - The options to use when fetching commands
* @param query - The query options for fetching commands
* @param options - The options for fetching commands
*/
public async getGlobalCommands(
applicationId: Snowflake,
Expand All @@ -55,8 +55,8 @@ export class ApplicationCommandsAPI {
*
* @see {@link https://discord.com/developers/docs/interactions/application-commands#create-global-application-command}
* @param applicationId - The application id to create the command for
* @param body - The data to use when creating the command
* @param options - The options to use when creating the command
* @param body - The data for creating the command
* @param options - The options for creating the command
*/
public async createGlobalCommand(
applicationId: Snowflake,
Expand All @@ -75,7 +75,7 @@ export class ApplicationCommandsAPI {
* @see {@link https://discord.com/developers/docs/interactions/application-commands#get-global-application-command}
* @param applicationId - The application id to fetch the command from
* @param commandId - The command id to fetch
* @param options - The options to use when fetching the command
* @param options - The options for fetching the command
*/
public async getGlobalCommand(
applicationId: Snowflake,
Expand All @@ -93,7 +93,7 @@ export class ApplicationCommandsAPI {
* @see {@link https://discord.com/developers/docs/interactions/application-commands#edit-global-application-command}
* @param applicationId - The application id of the command
* @param commandId - The id of the command to edit
* @param body - The data to use when editing the command
* @param body - The data for editing the command
* @param options - The options for editing the command
*/
public async editGlobalCommand(
Expand Down Expand Up @@ -129,7 +129,7 @@ export class ApplicationCommandsAPI {
*
* @see {@link https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands}
* @param applicationId - The application id to overwrite commands for
* @param body - The data to use when overwriting commands
* @param body - The data for overwriting commands
* @param options - The options for overwriting commands
*/
public async bulkOverwriteGlobalCommands(
Expand All @@ -149,8 +149,8 @@ export class ApplicationCommandsAPI {
* @see {@link https://discord.com/developers/docs/interactions/application-commands#get-guild-application-commands}
* @param applicationId - The application id to fetch commands for
* @param guildId - The guild id to fetch commands for
* @param query - The data to use when fetching commands
* @param options - The options to use when fetching commands
* @param query - The data for fetching commands
* @param options - The options for fetching commands
*/
public async getGuildCommands(
applicationId: Snowflake,
Expand All @@ -170,8 +170,8 @@ export class ApplicationCommandsAPI {
* @see {@link https://discord.com/developers/docs/interactions/application-commands#create-guild-application-command}
* @param applicationId - The application id to create the command for
* @param guildId - The guild id to create the command for
* @param body - The data to use when creating the command
* @param options - The options to use when creating the command
* @param body - The data for creating the command
* @param options - The options for creating the command
*/
public async createGuildCommand(
applicationId: Snowflake,
Expand All @@ -192,7 +192,7 @@ export class ApplicationCommandsAPI {
* @param applicationId - The application id to fetch the command from
* @param guildId - The guild id to fetch the command from
* @param commandId - The command id to fetch
* @param options - The options to use when fetching the command
* @param options - The options for fetching the command
*/
public async getGuildCommand(
applicationId: Snowflake,
Expand All @@ -212,8 +212,8 @@ export class ApplicationCommandsAPI {
* @param applicationId - The application id of the command
* @param guildId - The guild id of the command
* @param commandId - The command id to edit
* @param body - The data to use when editing the command
* @param options - The options to use when editing the command
* @param body - The data for editing the command
* @param options - The options for editing the command
*/
public async editGuildCommand(
applicationId: Snowflake,
Expand Down Expand Up @@ -252,8 +252,8 @@ export class ApplicationCommandsAPI {
* @see {@link https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-guild-application-commands}
* @param applicationId - The application id to overwrite commands for
* @param guildId - The guild id to overwrite commands for
* @param body - The data to use when overwriting commands
* @param options - The options to use when overwriting the commands
* @param body - The data for overwriting commands
* @param options - The options for overwriting the commands
*/
public async bulkOverwriteGuildCommands(
applicationId: Snowflake,
Expand Down Expand Up @@ -313,8 +313,8 @@ export class ApplicationCommandsAPI {
* @param applicationId - The application id to edit the permissions for
* @param guildId - The guild id to edit the permissions for
* @param commandId - The id of the command to edit the permissions for
* @param body - The data to use when editing the permissions
* @param options - The options to use when editing the permissions
* @param body - The data for editing the permissions
* @param options - The options for editing the permissions
*/
public async editGuildCommandPermissions(
userToken: string,
Expand Down
141 changes: 129 additions & 12 deletions packages/core/src/api/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -25,9 +27,18 @@ import {
type RESTPostAPIChannelMessageCrosspostResult,
type RESTPostAPIChannelMessageJSONBody,
type RESTPostAPIChannelMessageResult,
type RESTPutAPIChannelPermissionJSONBody,
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) {}

Expand All @@ -36,8 +47,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,
Expand All @@ -57,8 +68,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,
Expand All @@ -80,7 +91,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(
Expand Down Expand Up @@ -233,7 +244,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(
Expand Down Expand Up @@ -389,7 +400,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(
Expand All @@ -415,14 +426,59 @@ 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
*
* @see {@link https://discord.com/developers/docs/resources/channel#list-public-archived-threads}
* @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(
Expand All @@ -442,7 +498,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(
Expand All @@ -456,13 +512,74 @@ 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(channelId: Snowflake) {
return this.rest.get(Routes.channelWebhooks(channelId)) as Promise<RESTGetAPIChannelWebhooksResult>;
}

/**
* Edits the permission overwrite for a user or role in a channel
*
* @see {@link https://discord.com/developers/docs/resources/channel#edit-channel-permissions}
* @param channelId - The id of the channel to edit the permission overwrite in
* @param overwriteId - The id of the user or role to edit the permission overwrite for
* @param body - The data for editing the permission overwrite
* @param options - The options for editing the permission overwrite
*/
public async editPermissionOverwrite(
channelId: Snowflake,
overwriteId: Snowflake,
body: RESTPutAPIChannelPermissionJSONBody,
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
) {
await this.rest.put(Routes.channelPermission(channelId, overwriteId), {
reason,
body,
signal,
});
}

/**
* Deletes the permission overwrite for a user or role in a channel
*
* @see {@link https://discord.com/developers/docs/resources/channel#delete-channel-permission}
* @param channelId - The id of the channel to delete the permission overwrite in
* @param overwriteId - The id of the user or role to delete the permission overwrite for
* @param options - The options for deleting the permission overwrite
*/
public async getWebhooks(id: Snowflake) {
return this.rest.get(Routes.channelWebhooks(id)) as Promise<RESTGetAPIChannelWebhooksResult>;
public async deletePermissionOverwrite(
channelId: Snowflake,
overwriteId: Snowflake,
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
) {
await this.rest.delete(Routes.channelPermission(channelId, overwriteId), {
reason,
signal,
});
}
}
Loading

0 comments on commit dbfa42f

Please sign in to comment.