Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
conorwastakenwastaken committed Oct 8, 2021
2 parents 6f902fd + 7145134 commit 81983d5
Show file tree
Hide file tree
Showing 13 changed files with 379 additions and 31 deletions.
87 changes: 68 additions & 19 deletions index.d.ts

Large diffs are not rendered by default.

94 changes: 94 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,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 @@ -858,6 +879,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 @@ -1269,6 +1303,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 @@ -2253,6 +2302,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 @@ -2430,6 +2487,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
16 changes: 15 additions & 1 deletion lib/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ module.exports.AuditLogActions = {
STAGE_INSTANCE_UPDATE: 84,
STAGE_INSTANCE_DELETE: 85,

STICKER_CREATE: 90,
STICKER_UPDATE: 91,
STICKER_DELETE: 92,

THREAD_CREATE: 110,
THREAD_UPDATE: 111,
THREAD_DELETE: 112
Expand Down Expand Up @@ -279,7 +283,6 @@ module.exports.UserFlags = {
DISCORD_CERTIFIED_MODERATOR: 1 << 18
};


module.exports.Intents = {
guilds: 1 << 0,
guildMembers: 1 << 1,
Expand Down Expand Up @@ -311,3 +314,14 @@ module.exports.InteractionResponseType = {
DEFERRED_UPDATE_MESSAGE: 6,
UPDATE_MESSAGE: 7
};

module.exports.StickerTypes = {
STANDARD: 1,
GUILD: 2
};

module.exports.StickerFormats = {
PNG: 1,
APNG: 2,
LOTTIE: 3
};
27 changes: 24 additions & 3 deletions lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ class Shard extends EventEmitter {
if(packet.d.user.username !== undefined) {
let user = this.client.users.get(packet.d.user.id);
let oldUser = null;
if(user && (user.username !== packet.d.user.username || user.avatar !== packet.d.user.avatar || user.discriminator !== packet.d.user.discriminator)) {
if(user && (user.username !== packet.d.user.username || user.discriminator !== packet.d.user.discriminator || user.avatar !== packet.d.user.avatar)) {
oldUser = {
username: user.username,
discriminator: user.discriminator,
Expand All @@ -617,7 +617,7 @@ class Shard extends EventEmitter {
if(!user || oldUser) {
user = this.client.users.update(packet.d.user, this.client);
/**
* Fired when a user's username, avatar, or discriminator changes
* Fired when a user's avatar, discriminator or username changes
* @event Client#userUpdate
* @prop {User} user The updated user
* @prop {Object?} oldUser The old user data
Expand Down Expand Up @@ -1131,7 +1131,7 @@ class Shard extends EventEmitter {
if(!(this.client.options.intents & Constants.Intents.guildPresences) && packet.d.user.username !== undefined) {
let user = this.client.users.get(packet.d.user.id);
let oldUser = null;
if(user && (user.username !== packet.d.user.username || user.avatar !== packet.d.user.avatar || user.discriminator !== packet.d.user.discriminator)) {
if(user && (user.username !== packet.d.user.username || user.discriminator !== packet.d.user.discriminator || user.avatar !== packet.d.user.avatar)) {
oldUser = {
username: user.username,
discriminator: user.discriminator,
Expand Down Expand Up @@ -1265,6 +1265,7 @@ class Shard extends EventEmitter {
publicUpdatesChannelID: guild.publicUpdatesChannelID,
rulesChannelID: guild.rulesChannelID,
splash: guild.splash,
stickers: guild.stickers,
systemChannelFlags: guild.systemChannelFlags,
systemChannelID: guild.systemChannelID,
vanityURL: guild.vanityURL,
Expand Down Expand Up @@ -1299,6 +1300,7 @@ class Shard extends EventEmitter {
* @prop {String?} oldGuild.publicUpdatesChannelID ID of the guild's updates channel if the guild has "COMMUNITY" features
* @prop {String?} oldGuild.rulesChannelID The channel where "COMMUNITY" guilds display rules and/or guidelines
* @prop {String?} oldGuild.splash The hash of the guild splash image, or null if no splash (VIP only)
* @prop {Array<Object>?} stickers An array of guild sticker objects
* @prop {Number} oldGuild.systemChannelFlags the flags for the system channel
* @prop {String?} oldGuild.systemChannelID The ID of the default channel for system messages (built-in join messages and boost messages)
* @prop {String?} oldGuild.vanityURL The vanity URL of the guild (VIP only)
Expand Down Expand Up @@ -2032,6 +2034,25 @@ class Shard extends EventEmitter {
this.emit("guildEmojisUpdate", guild || {id: packet.d.guild_id}, emojis, oldEmojis);
break;
}
case "GUILD_STICKERS_UPDATE": {
const guild = this.client.guilds.get(packet.d.guild_id);
let oldStickers = null;
let stickers = packet.d.stickers;
if(guild) {
oldStickers = guild.stickers;
guild.update(packet.d);
stickers = guild.stickers;
}
/**
* Fired when a guild's stickers are updated
* @event Client#guildStickersUpdate
* @prop {Guild} guild The guild. If the guild is uncached, this is an object with an ID key. No other property is guaranteed
* @prop {Array} stickers The updated stickers of the guild
* @prop {Array?} oldStickers The old stickers of the guild. If the guild is uncached, this will be null
*/
this.emit("guildStickersUpdate", guild || {id: packet.d.guild_id}, stickers, oldStickers);
break;
}
case "CHANNEL_PINS_UPDATE": {
const channel = this.client.getChannel(packet.d.channel_id);
if(!channel) {
Expand Down
6 changes: 5 additions & 1 deletion lib/rest/Endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ module.exports.GUILD_PREVIEW = (guildID)
module.exports.GUILD_PRUNE = (guildID) => `/guilds/${guildID}/prune`;
module.exports.GUILD_ROLE = (guildID, roleID) => `/guilds/${guildID}/roles/${roleID}`;
module.exports.GUILD_ROLES = (guildID) => `/guilds/${guildID}/roles`;
module.exports.GUILD_STICKER = (guildID, stickerID) => `/guilds/${guildID}/stickers/${stickerID}`;
module.exports.GUILD_STICKERS = (guildID) => `/guilds/${guildID}/stickers`;
module.exports.GUILD_TEMPLATE = (code) => `/guilds/templates/${code}`;
module.exports.GUILD_TEMPLATES = (guildID) => `/guilds/${guildID}/templates`;
module.exports.GUILD_TEMPLATE_GUILD = (guildID, code) => `/guilds/${guildID}/templates/${code}`;
Expand All @@ -73,6 +75,8 @@ module.exports.INVITE = (inviteID)
module.exports.OAUTH2_APPLICATION = (appID) => `/oauth2/applications/${appID}`;
module.exports.STAGE_INSTANCE = (channelID) => `/stage-instances/${channelID}`;
module.exports.STAGE_INSTANCES = "/stage-instances";
module.exports.STICKER = (stickerID) => `/stickers/${stickerID}`;
module.exports.STICKER_PACKS = "/sticker-packs";
module.exports.THREAD_MEMBER = (channelID, userID) => `/channels/${channelID}/thread-members/${userID}`;
module.exports.THREAD_MEMBERS = (channelID) => `/channels/${channelID}/thread-members`;
module.exports.THREAD_WITH_MESSAGE = (channelID, msgID) => `/channels/${channelID}/messages/${msgID}/threads`;
Expand Down Expand Up @@ -109,11 +113,11 @@ module.exports.WEBHOOK_TOKEN_SLACK = (hookID, token)
module.exports.ACHIEVEMENT_ICON = (applicationID, achievementID, icon) => `/app-assets/${applicationID}/achievements/${achievementID}/icons/${icon}`;
module.exports.APPLICATION_ASSET = (applicationID, asset) => `/app-assets/${applicationID}/${asset}`;
module.exports.APPLICATION_ICON = (applicationID, icon) => `/app-icons/${applicationID}/${icon}`;
module.exports.BANNER = (guildOrUserID, hash) => `/banners/${guildOrUserID}/${hash}`;
module.exports.CHANNEL_ICON = (chanID, chanIcon) => `/channel-icons/${chanID}/${chanIcon}`;
module.exports.CUSTOM_EMOJI = (emojiID) => `/emojis/${emojiID}`;
module.exports.DEFAULT_USER_AVATAR = (userDiscriminator) => `/embed/avatars/${userDiscriminator}`;
module.exports.GUILD_AVATAR = (guildID, userID, guildAvatar) => `/guilds/${guildID}/users/${userID}/avatars/${guildAvatar}`;
module.exports.GUILD_BANNER = (guildID, guildBanner) => `/banners/${guildID}/${guildBanner}`;
module.exports.GUILD_DISCOVERY_SPLASH = (guildID, guildDiscoverySplash) => `/discovery-splashes/${guildID}/${guildDiscoverySplash}`;
module.exports.GUILD_ICON = (guildID, guildIcon) => `/icons/${guildID}/${guildIcon}`;
module.exports.GUILD_SPLASH = (guildID, guildSplash) => `/splashes/${guildID}/${guildSplash}`;
Expand Down
8 changes: 7 additions & 1 deletion lib/rest/RequestHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ class RequestHandler {
headers["Content-Type"] = "multipart/form-data; boundary=" + data.boundary;
data.attach("file", file.file, file.name);
if(body) {
data.attach("payload_json", body);
if(method === "POST" && url.endsWith("/stickers")) {
for(const key in body) {
data.attach(key, body[key]);
}
} else {
data.attach("payload_json", body);
}
}
data = data.finish();
} else {
Expand Down
1 change: 1 addition & 0 deletions lib/structures/GroupChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class GroupChannel extends PrivateChannel { // (╯°□°)╯︵ ┻━┻
* Get the group's icon with the given format and size
* @arg {String} [format] The filetype of the icon ("jpg", "jpeg", "png", "gif", or "webp")
* @arg {Number} [size] The size of the icon (any power of two between 16 and 4096)
* @returns {String?}
*/
dynamicIconURL(format, size) {
return this.icon ? this.client._formatImage(Endpoints.CHANNEL_ICON(this.id, this.icon), format, size) : null;
Expand Down
Loading

0 comments on commit 81983d5

Please sign in to comment.