From 2e444a465e6ef40fb5ead235bad4bdcd5442653e Mon Sep 17 00:00:00 2001 From: reboxer <7484116+reboxer@users.noreply.github.com> Date: Fri, 19 Apr 2019 07:27:32 -0300 Subject: [PATCH] Add support for guild banner (#475) --- index.d.ts | 2 ++ lib/Client.js | 4 +++- lib/gateway/Shard.js | 2 ++ lib/structures/Guild.js | 8 +++++++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 95b184d83..454b93cd0 100644 --- a/index.d.ts +++ b/index.d.ts @@ -384,6 +384,7 @@ declare module "eris" { afkTimeout?: number; ownerID?: string; splash?: string; + banner?: string; } interface MemberOptions { roles?: string[]; nick?: string; mute?: boolean; deaf?: boolean; channelID?: string; } interface RoleOptions { name?: string; permissions?: number; color?: number; hoist?: boolean; mentionable?: boolean; } @@ -1020,6 +1021,7 @@ declare module "eris" { public joinedAt: number; public ownerID: string; public splash?: string; + public banner?: string; public unavailable: boolean; public large: boolean; public maxPresences: number; diff --git a/lib/Client.js b/lib/Client.js index 6009822f3..94312bbd4 100644 --- a/lib/Client.js +++ b/lib/Client.js @@ -1404,6 +1404,7 @@ class Client extends EventEmitter { * @arg {Number} [options.afkTimeout] The AFK timeout in seconds * @arg {String} [options.ownerID] The ID of the user to transfer server ownership to (bot user must be owner) * @arg {String} [options.splash] The guild splash image as a base64 data URI (VIP only). Note: base64 strings alone are not base64 data URI strings + * @arg {String} [options.banner] The guild banner image as a base64 data URI (VIP only). Note: base64 strings alone are not base64 data URI strings * @arg {String} [reason] The reason to be displayed in audit logs * @returns {Promise} */ @@ -1417,8 +1418,9 @@ class Client extends EventEmitter { system_channel_id: options.systemChannelID, afk_channel_id: options.afkChannelID, afk_timeout: options.afkTimeout, - splash: options.splash, owner_id: options.ownerID, + splash: options.splash, + banner: options.banner, reason: reason }).then((guild) => new Guild(guild, this)); } diff --git a/lib/gateway/Shard.js b/lib/gateway/Shard.js index 850bf07f1..6a53695bf 100644 --- a/lib/gateway/Shard.js +++ b/lib/gateway/Shard.js @@ -698,6 +698,7 @@ class Shard extends EventEmitter { name: guild.name, verificationLevel: guild.verificationLevel, splash: guild.splash, + banner: guild.banner, region: guild.region, ownerID: guild.ownerID, icon: guild.icon, @@ -724,6 +725,7 @@ class Shard extends EventEmitter { * @prop {Number} oldGuild.afkTimeout The AFK timeout in seconds * @prop {String} oldGuild.ownerID The ID of the user that is the guild owner * @prop {String?} oldGuild.splash The hash of the guild splash image, or null if no splash (VIP only) + * @prop {String?} oldGuild.banner The hash of the guild banner image, or null if no splash (VIP only) * @prop {Object[]} oldGuild.features An array of guild features * @prop {Object[]} oldGuild.emojis An array of guild emojis */ diff --git a/lib/structures/Guild.js b/lib/structures/Guild.js index 2a09500bb..e6decc718 100644 --- a/lib/structures/Guild.js +++ b/lib/structures/Guild.js @@ -127,6 +127,7 @@ class Guild extends Base { this.name = data.name !== undefined ? data.name : this.name; this.verificationLevel = data.verification_level !== undefined ? data.verification_level : this.verificationLevel; this.splash = data.splash !== undefined ? data.splash : this.splash; + this.banner = data.banner !== undefined ? data.banner : this.banner; this.region = data.region !== undefined ? data.region : this.region; this.ownerID = data.owner_id !== undefined ? data.owner_id : this.ownerID; this.icon = data.icon !== undefined ? data.icon : this.icon; @@ -176,6 +177,10 @@ class Guild extends Base { return this.splash ? `${CDN_URL}/splashes/${this.id}/${this.splash}.jpg` : null; } + get bannerURL() { + return this.banner ? `${CDN_URL}/banners/${this.id}/${this.banner}.jpg` : null; + } + /** * Create a channel in the guild * @arg {String} name The name of the channel @@ -507,6 +512,7 @@ class Guild extends Base { * @arg {Number} [options.afkTimeout] The AFK timeout in seconds * @arg {String} [options.ownerID] The ID of the member to transfer guild ownership to (bot user must be owner) * @arg {String} [options.splash] The guild splash image as a base64 data URI (VIP only). Note: base64 strings alone are not base64 data URI strings + * @arg {String} [options.banner] The guild banner image as a base64 data URI (VIP only). Note: base64 strings alone are not base64 data URI strings * @arg {String} [reason] The reason to be displayed in audit logs * @returns {Promise} */ @@ -566,7 +572,7 @@ class Guild extends Base { toJSON() { const base = super.toJSON(true); - for(const prop of ["afkChannelID", "afkTimeout", "channels", "defaultNotifications", "emojis", "explicitContentFilter", "features", "icon", "joinedAt", "large", "maxPresences", "memberCount", "members", "mfaLevel", "name", "ownerID", "region", "roles", "splash", "unavailable", "verificationLevel"]) { + for(const prop of ["afkChannelID", "afkTimeout", "channels", "defaultNotifications", "emojis", "explicitContentFilter", "features", "icon", "joinedAt", "large", "maxPresences", "memberCount", "members", "mfaLevel", "name", "ownerID", "region", "roles", "splash", "banner", "unavailable", "verificationLevel"]) { if(this[prop] !== undefined) { base[prop] = this[prop] && this[prop].toJSON ? this[prop].toJSON() : this[prop]; }