Skip to content

Commit

Permalink
Add support for guild banner (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
reboxer authored and abalabahaha committed Apr 19, 2019
1 parent 73d46f1 commit 2e444a4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions index.d.ts
Expand Up @@ -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; }
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion lib/Client.js
Expand Up @@ -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<Guild>}
*/
Expand All @@ -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));
}
Expand Down
2 changes: 2 additions & 0 deletions lib/gateway/Shard.js
Expand Up @@ -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,
Expand All @@ -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
*/
Expand Down
8 changes: 7 additions & 1 deletion lib/structures/Guild.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Guild>}
*/
Expand Down Expand Up @@ -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];
}
Expand Down

0 comments on commit 2e444a4

Please sign in to comment.