Skip to content

Commit

Permalink
feat: application emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
sdanialraza authored Jul 20, 2024
1 parent efa16a6 commit 6054ca0
Showing 1 changed file with 87 additions and 1 deletion.
88 changes: 87 additions & 1 deletion packages/core/src/api/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,101 @@

import type { RequestData, REST } from '@discordjs/rest';
import {
Routes,
type RESTGetAPIApplicationEmojiResult,
type RESTGetAPIApplicationEmojisResult,
type RESTGetCurrentApplicationResult,
type RESTPatchAPIApplicationEmojiJSONBody,
type RESTPatchAPIApplicationEmojiResult,
type RESTPatchCurrentApplicationJSONBody,
type RESTPatchCurrentApplicationResult,
Routes,
type RESTPostAPIApplicationEmojiJSONBody,
type RESTPostAPIApplicationEmojiResult,
type Snowflake,
} from 'discord-api-types/v10';

export class ApplicationsAPI {
public constructor(private readonly rest: REST) {}

/**
* Fetches all emojis of an application
*
* @see {@link https://discord.com/developers/docs/resources/emoji#list-application-emojis}
* @param applicationId - The id of the application to fetch the emojis of
* @param options - The options for fetching the emojis
*/
public async getEmojis(applicationId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.applicationEmojis(applicationId), {
signal,
}) as Promise<RESTGetAPIApplicationEmojisResult>;
}

/**
* Fetches an emoji of an application
*
* @see {@link https://discord.com/developers/docs/resources/emoji#get-application-emoji}
* @param applicationId - The id of the application to fetch the emoji of
* @param emojiId - The id of the emoji to fetch
* @param options - The options for fetching the emoji
*/
public async getEmoji(applicationId: Snowflake, emojiId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.applicationEmoji(applicationId, emojiId), {
signal,
}) as Promise<RESTGetAPIApplicationEmojiResult>;
}

/**
* Creates a new emoji of an application
*
* @see {@link https://discord.com/developers/docs/resources/emoji#create-application-emoji}
* @param applicationId - The id of the application to create the emoji of
* @param body - The data for creating the emoji
* @param options - The options for creating the emoji
*/
public async createEmoji(
applicationId: Snowflake,
body: RESTPostAPIApplicationEmojiJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.post(Routes.applicationEmojis(applicationId), {
body,
signal,
}) as Promise<RESTPostAPIApplicationEmojiResult>;
}

/**
* Edits an emoji of an application
*
* @see {@link https://discord.com/developers/docs/resources/emoji#modify-application-emoji}
* @param applicationId - The id of the application to edit the emoji of
* @param emojiId - The id of the emoji to edit
* @param body - The data for editing the emoji
* @param options - The options for editing the emoji
*/
public async editEmoji(
applicationId: Snowflake,
emojiId: Snowflake,
body: RESTPatchAPIApplicationEmojiJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.patch(Routes.applicationEmoji(applicationId, emojiId), {
body,
signal,
}) as Promise<RESTPatchAPIApplicationEmojiResult>;
}

/**
* Deletes an emoji of an application
*
* @see {@link https://discord.com/developers/docs/resources/emoji#delete-application-emoji}
* @param applicationId - The id of the application to delete the emoji of
* @param emojiId - The id of the emoji to delete
* @param options - The options for deleting the emoji
*/
public async deleteEmoji(applicationId: Snowflake, emojiId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
await this.rest.delete(Routes.applicationEmoji(applicationId, emojiId), { signal });
}

/**
* Fetches the application associated with the requesting bot user.
*
Expand Down

0 comments on commit 6054ca0

Please sign in to comment.