Skip to content

Commit

Permalink
Fully expose stickers (abalabahaha#1258)
Browse files Browse the repository at this point in the history
Co-authored-by: Bsian <chharry321@gmail.com>
  • Loading branch information
iiFDCT and bsian03 committed Oct 5, 2021
1 parent 558bbe5 commit 7145134
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 15 deletions.
61 changes: 51 additions & 10 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ declare namespace Eris {
addMessageReaction(messageID: string, reaction: string): Promise<void>;
/** @deprecated */
addMessageReaction(messageID: string, reaction: string, userID: string): Promise<void>;
createMessage(content: MessageContent, file?: MessageFile | MessageFile[]): Promise<Message>;
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message>;
deleteMessage(messageID: string, reason?: string): Promise<void>;
editMessage(messageID: string, content: MessageContent): Promise<Message>;
getMessage(messageID: string): Promise<Message>;
Expand Down Expand Up @@ -421,6 +421,7 @@ declare namespace Eris {
region: string;
rulesChannelID: string | null;
splash: string | null;
stickers?: Sticker[];
systemChannelFlags: number;
systemChannelID: string | null;
vanityURL: string | null;
Expand Down Expand Up @@ -519,6 +520,7 @@ declare namespace Eris {
guildRoleCreate: [guild: Guild, role: Role];
guildRoleDelete: [guild: Guild, role: Role];
guildRoleUpdate: [guild: Guild, role: Role, oldRole: OldRole];
guildStickersUpdate: [guild: PossiblyUncachedGuild, stickers: Sticker[], oldStickers: Sticker[] | null];
guildUnavailable: [guild: UnavailableGuild];
guildUpdate: [guild: Guild, oldGuild: OldGuild];
hello: [trace: string[], id: number];
Expand Down Expand Up @@ -601,7 +603,7 @@ declare namespace Eris {
interface RawRESTRequest {
auth: boolean;
body?: unknown;
file?: MessageFile;
file?: FileContent;
method: string;
resp: IncomingMessage;
route: string;
Expand Down Expand Up @@ -877,6 +879,14 @@ declare namespace Eris {
label?: string;
type: 2;
}
interface CreateStickerOptions extends Required<Pick<EditStickerOptions, "name" | "tags">> {
file: FileContent;
}
interface EditStickerOptions {
description?: string;
name?: string;
tags?: string;
}
interface SelectMenu {
custom_id: string;
disabled?: boolean;
Expand Down Expand Up @@ -914,7 +924,7 @@ declare namespace Eris {
id: string;
name: string;
}
interface MessageFile {
interface FileContent {
file: Buffer | string;
name: string;
}
Expand Down Expand Up @@ -946,13 +956,23 @@ declare namespace Eris {
pack_id?: string;
sort_value?: number;
tags: string;
type: Constants["StickerTypes"][keyof Constants["StickerTypes"]];
user?: User;
}
interface StickerItems {
id: string;
name: string;
format_type: Constants["StickerFormats"][keyof Constants["StickerFormats"]];
}
interface StickerPack {
id: string;
stickers: Sticker[];
name: string;
sku_id: string;
cover_sticker_id?: string;
description: string;
banner_asset_id: string;
}
interface URLButton extends ButtonBase {
style: 5;
url: string;
Expand Down Expand Up @@ -1102,7 +1122,7 @@ declare namespace Eris {
components?: ActionRow[];
content?: string;
embeds?: EmbedOptions[];
file?: MessageFile | MessageFile[];
file?: FileContent | FileContent[];
tts?: boolean;
username?: string;
wait?: boolean;
Expand Down Expand Up @@ -1188,6 +1208,10 @@ declare namespace Eris {
STAGE_INSTANCE_CREATE: 83;
STAGE_INSTANCE_UPDATE: 84;
STAGE_INSTANCE_DELETE: 85;

STICKER_CREATE: 90;
STICKER_UPDATE: 91;
STICKER_DELETE: 92;
};
ChannelTypes: {
GUILD_TEXT: 0;
Expand Down Expand Up @@ -1330,6 +1354,10 @@ declare namespace Eris {
all: 146028888063n;
};
REST_VERSION: 8;
StickerTypes: {
STANDARD: 1;
GUILD: 2;
};
StickerFormats: {
PNG: 1;
APNG: 2;
Expand Down Expand Up @@ -1685,8 +1713,9 @@ declare namespace Eris {
createGuild(name: string, options?: CreateGuildOptions): Promise<Guild>;
createGuildEmoji(guildID: string, options: EmojiOptions, reason?: string): Promise<Emoji>;
createGuildFromTemplate(code: string, name: string, icon?: string): Promise<Guild>;
createGuildSticker(guildID: string, options: CreateStickerOptions, reason?: string): Promise<Sticker>;
createGuildTemplate(guildID: string, name: string, description?: string | null): Promise<GuildTemplate>;
createMessage(channelID: string, content: MessageContent, file?: MessageFile | MessageFile[]): Promise<Message>;
createMessage(channelID: string, content: MessageContent, file?: FileContent | FileContent[]): Promise<Message>;
createRole(guildID: string, options?: RoleOptions | Role, reason?: string): Promise<Role>;
crosspostMessage(channelID: string, messageID: string): Promise<Message>;
deleteChannel(channelID: string, reason?: string): Promise<void>;
Expand All @@ -1695,6 +1724,7 @@ declare namespace Eris {
deleteGuildDiscoverySubcategory(guildID: string, categoryID: string, reason?: string): Promise<void>;
deleteGuildEmoji(guildID: string, emojiID: string, reason?: string): Promise<void>;
deleteGuildIntegration(guildID: string, integrationID: string): Promise<void>;
deleteGuildSticker(guildID: string, stickerID: string, reason?: string): Promise<void>;
deleteGuildTemplate(guildID: string, code: string): Promise<GuildTemplate>;
deleteInvite(inviteID: string, reason?: string): Promise<void>;
deleteMessage(channelID: string, messageID: string, reason?: string): Promise<void>;
Expand Down Expand Up @@ -1732,6 +1762,7 @@ declare namespace Eris {
): Promise<Emoji>;
editGuildIntegration(guildID: string, integrationID: string, options: IntegrationOptions): Promise<void>;
editGuildMember(guildID: string, memberID: string, options: MemberOptions, reason?: string): Promise<Member>;
editGuildSticker(guildID: string, stickerID: string, options?: EditStickerOptions, reason?: string): Promise<Sticker>;
editGuildTemplate(guildID: string, code: string, options: GuildTemplateOptions): Promise<GuildTemplate>;
editGuildVanity(guildID: string, code: string | null): Promise<GuildVanity>;
editGuildVoiceState(guildID: string, options: VoiceStateOptions, userID?: string): Promise<void>;
Expand Down Expand Up @@ -1808,6 +1839,7 @@ declare namespace Eris {
getMessages(channelID: string, options?: GetMessagesOptions): Promise<Message[]>;
/** @deprecated */
getMessages(channelID: string, limit?: number, before?: string, after?: string, around?: string): Promise<Message[]>;
getNitroStickerPacks(): Promise<{ sticker_packs: StickerPack[] }>;
getOAuthApplication(appID?: string): Promise<OAuthApplicationInfo>;
getPins(channelID: string): Promise<Message[]>;
getPruneCount(guildID: string, options?: GetPruneOptions): Promise<number>;
Expand All @@ -1824,6 +1856,9 @@ declare namespace Eris {
getRESTGuilds(options?: GetRESTGuildsOptions): Promise<Guild[]>;
/** @deprecated */
getRESTGuilds(limit?: number, before?: string, after?: string): Promise<Guild[]>;
getRESTGuildSticker(guildID: string, stickerID: string): Promise<Sticker>;
getRESTGuildStickers(guildID: string): Promise<Sticker[]>;
getRESTSticker(stickerID: string): Promise<Sticker>;
getRESTUser(userID: string): Promise<User>;
getSelf(): Promise<ExtendedUser>;
getSelfBilling(): Promise<{
Expand Down Expand Up @@ -2071,6 +2106,7 @@ declare namespace Eris {
shard: Shard;
splash: string | null;
splashURL: string | null;
stickers?: Sticker[];
systemChannelFlags: number;
systemChannelID: string | null;
unavailable: boolean;
Expand Down Expand Up @@ -2108,12 +2144,14 @@ declare namespace Eris {
createChannel(name: string, type?: number, reason?: string, options?: CreateChannelOptions | string): Promise<unknown>;
createEmoji(options: { image: string; name: string; roles?: string[] }, reason?: string): Promise<Emoji>;
createRole(options: RoleOptions | Role, reason?: string): Promise<Role>;
createSticker(options: CreateStickerOptions, reason?: string): Promise<Sticker>;
createTemplate(name: string, description?: string | null): Promise<GuildTemplate>;
delete(): Promise<void>;
deleteDiscoverySubcategory(categoryID: string, reason?: string): Promise<void>;
deleteEmoji(emojiID: string, reason?: string): Promise<void>;
deleteIntegration(integrationID: string): Promise<void>;
deleteRole(roleID: string): Promise<void>;
deleteSticker(stickerID: string, reason?: string): Promise<void>;
deleteTemplate(code: string): Promise<GuildTemplate>;
dynamicBannerURL(format?: ImageFormat, size?: number): string | null;
dynamicDiscoverySplashURL(format?: ImageFormat, size?: number): string | null;
Expand All @@ -2127,6 +2165,7 @@ declare namespace Eris {
/** @deprecated */
editNickname(nick: string): Promise<void>;
editRole(roleID: string, options: RoleOptions): Promise<Role>;
editSticker(stickerID: string, options?: EditStickerOptions, reason?: string): Promise<Sticker>;
editTemplate(code: string, options: GuildTemplateOptions): Promise<GuildTemplate>;
editVanity(code: string | null): Promise<GuildVanity>;
editVoiceState(options: VoiceStateOptions, userID?: string): Promise<void>;
Expand All @@ -2153,6 +2192,8 @@ declare namespace Eris {
/** @deprecated */
getRESTMembers(limit?: number, after?: string): Promise<Member[]>;
getRESTRoles(): Promise<Role[]>;
getRESTSticker(stickerID: string): Promise<Sticker>;
getRESTStickers(): Promise<Sticker[]>;
getTemplates(): Promise<GuildTemplate[]>;
getVanity(): Promise<GuildVanity>;
getVoiceRegions(): Promise<VoiceRegion[]>;
Expand Down Expand Up @@ -2186,7 +2227,7 @@ declare namespace Eris {
message?: Message<GuildTextableChannel>;
reason: string | null;
role?: Role | { id: string; name: string };
target?: Guild | AnyGuildChannel | Member | Role | Invite | Emoji | Message<GuildTextableChannel> | null;
target?: Guild | AnyGuildChannel | Member | Role | Invite | Emoji | Sticker | Message<GuildTextableChannel> | null;
targetID: string;
user: User;
constructor(data: BaseData, guild: Guild);
Expand Down Expand Up @@ -2401,7 +2442,7 @@ declare namespace Eris {
rateLimitPerUser: 0;
type: 5;
createInvite(options?: CreateInviteOptions, reason?: string): Promise<Invite<"withMetadata", NewsChannel>>;
createMessage(content: MessageContent, file?: MessageFile | MessageFile[]): Promise<Message<NewsChannel>>;
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message<NewsChannel>>;
crosspostMessage(messageID: string): Promise<Message<NewsChannel>>;
editMessage(messageID: string, content: MessageContent): Promise<Message<NewsChannel>>;
follow(webhookChannelID: string): Promise<ChannelFollow>;
Expand Down Expand Up @@ -2453,7 +2494,7 @@ declare namespace Eris {
addMessageReaction(messageID: string, reaction: string): Promise<void>;
/** @deprecated */
addMessageReaction(messageID: string, reaction: string, userID: string): Promise<void>;
createMessage(content: MessageContent, file?: MessageFile | MessageFile[]): Promise<Message<PrivateChannel>>;
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message<PrivateChannel>>;
deleteMessage(messageID: string, reason?: string): Promise<void>;
editMessage(messageID: string, content: MessageContent): Promise<Message<PrivateChannel>>;
getMessage(messageID: string): Promise<Message<PrivateChannel>>;
Expand Down Expand Up @@ -2497,7 +2538,7 @@ declare namespace Eris {
/** @deprecated */
constructor(client: Client, forceQueueing?: boolean);
globalUnblock(): void;
request(method: RequestMethod, url: string, auth?: boolean, body?: { [s: string]: unknown }, file?: MessageFile, _route?: string, short?: boolean): Promise<unknown>;
request(method: RequestMethod, url: string, auth?: boolean, body?: { [s: string]: unknown }, file?: FileContent, _route?: string, short?: boolean): Promise<unknown>;
routefy(url: string, method: RequestMethod): string;
toString(): string;
toJSON(props?: string[]): JSONCache;
Expand Down Expand Up @@ -2662,7 +2703,7 @@ declare namespace Eris {
/** @deprecated */
addMessageReaction(messageID: string, reaction: string, userID: string): Promise<void>;
createInvite(options?: CreateInviteOptions, reason?: string): Promise<Invite<"withMetadata", TextChannel>>;
createMessage(content: MessageContent, file?: MessageFile | MessageFile[]): Promise<Message<TextChannel>>;
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message<TextChannel>>;
createWebhook(options: { name: string; avatar?: string | null}, reason?: string): Promise<Webhook>;
deleteMessage(messageID: string, reason?: string): Promise<void>;
deleteMessages(messageIDs: string[], reason?: string): Promise<void>;
Expand Down
94 changes: 94 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,27 @@ class Client extends EventEmitter {
}).then((guild) => new Guild(guild, this));
}

/**
* Create a guild sticker
* @arg {Object} options Sticker options
* @arg {String} [options.description] The description of the sticker
* @arg {Object} options.file A file object
* @arg {Buffer} options.file.file A buffer containing file data
* @arg {String} options.file.name What to name the file
* @arg {String} options.name The name of the sticker
* @arg {String} options.tags The Discord name of a unicode emoji representing the sticker's expression
* @arg {String} [reason] The reason to be displayed in audit logs
* @returns {Promise<Object>} A sticker object
*/
createGuildSticker(guildID, options, reason) {
return this.requestHandler.request("POST", Endpoints.GUILD_STICKERS(guildID), true, {
description: options.description || "",
name: options.name,
tags: options.tags,
reason: reason
}, options.file);
}

/**
* Create a template for a guild
* @arg {String} guildID The ID of the guild
Expand Down Expand Up @@ -765,6 +786,19 @@ class Client extends EventEmitter {
return this.requestHandler.request("DELETE", Endpoints.GUILD_INTEGRATION(guildID, integrationID), true);
}

/**
* Delete a guild sticker
* @arg {String} guildID The ID of the guild
* @arg {String} stickerID The ID of the sticker
* @arg {String} [reason] The reason to be displayed in audit logs
* @returns {Promise}
*/
deleteGuildSticker(guildID, stickerID, reason) {
return this.requestHandler.request("DELETE", Endpoints.GUILD_STICKER(guildID, stickerID), true, {
reason
});
}

/**
* Delete a guild template
* @arg {String} guildID The ID of the guild
Expand Down Expand Up @@ -1159,6 +1193,21 @@ class Client extends EventEmitter {
}).then((member) => new Member(member, this.guilds.get(guildID), this));
}

/**
* Edit a guild sticker
* @arg {String} stickerID The ID of the sticker
* @arg {Object} options The properties to edit
* @arg {String} [options.description] The description of the sticker
* @arg {String} [options.name] The name of the sticker
* @arg {String} [options.tags] The Discord name of a unicode emoji representing the sticker's expression
* @arg {String} [reason] The reason to be displayed in audit logs
* @returns {Promise<Object>} A sticker object
*/
editGuildSticker(guildID, stickerID, options, reason) {
options.reason = reason;
return this.requestHandler.request("PATCH", Endpoints.GUILD_STICKER(guildID, stickerID), true, options);
}

/**
* Edit a guild template
* @arg {String} guildID The ID of the guild
Expand Down Expand Up @@ -2037,6 +2086,14 @@ class Client extends EventEmitter {
});
}

/**
* Get the list of sticker packs available to Nitro subscribers
* @returns {Promise<Object>} An object whichs contains a value which contains an array of sticker packs
*/
getNitroStickerPacks() {
return this.requestHandler.request("GET", Endpoints.STICKER_PACKS, true);
}

/**
* Get data on an OAuth2 application
* @arg {String} [appID="@me"] The client ID of the application to get data for (user accounts only). "@me" refers to the logged in user's own application
Expand Down Expand Up @@ -2214,6 +2271,43 @@ class Client extends EventEmitter {
return this.requestHandler.request("GET", Endpoints.USER_GUILDS("@me"), true, options).then((guilds) => guilds.map((guild) => new Guild(guild, this)));
}

/**
* Get a guild sticker via the REST API. REST mode is required to use this endpoint.
* @arg {String} guildID The ID of the guild
* @arg {String} stickerID The ID of the sticker
* @returns {Promise<Object>} A sticker object
*/
getRESTGuildSticker(guildID, stickerID) {
if(!this.options.restMode) {
return Promise.reject(new Error("Eris REST mode is not enabled"));
}
return this.requestHandler.request("GET", Endpoints.GUILD_STICKER(guildID, stickerID), true);
}

/**
* Get a guild's stickers via the REST API. REST mode is required to use this endpoint.
* @arg {String} guildID The ID of the guild
* @returns {Promise<Array<Object>>} An array of guild sticker objects
*/
getRESTGuildStickers(guildID) {
if(!this.options.restMode) {
return Promise.reject(new Error("Eris REST mode is not enabled"));
}
return this.requestHandler.request("GET", Endpoints.GUILD_STICKERS(guildID), true);
}

/**
* Get a sticker via the REST API. REST mode is required to use this endpoint.
* @arg {String} stickerID The ID of the sticker
* @returns {Promise<Object>} A sticker object
*/
getRESTSticker(stickerID) {
if(!this.options.restMode) {
return Promise.reject(new Error("Eris REST mode is not enabled"));
}
return this.requestHandler.request("GET", Endpoints.STICKER(stickerID), true);
}

/**
* Get a user's data via the REST API. REST mode is required to use this endpoint.
* @arg {String} userID The ID of the user
Expand Down
Loading

0 comments on commit 7145134

Please sign in to comment.