Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Role icon support #1278

Merged
merged 10 commits into from
Oct 23, 2021
9 changes: 8 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ declare namespace Eris {
// Guild
type DefaultNotifications = 0 | 1;
type ExplicitContentFilter = 0 | 1 | 2;
type GuildFeatures = "ANIMATED_ICON" | "BANNER" | "COMMERCE" | "COMMUNITY" | "DISCOVERABLE" | "FEATURABLE" | "INVITE_SPLASH" | "MEMBER_VERIFICATION_GATE_ENABLED" | "NEWS" | "PARTNERED" | "PREVIEW_ENABLED" | "VANITY_URL" | "VERIFIED" | "VIP_REGIONS" | "WELCOME_SCREEN_ENABLED" | "TICKETED_EVENTS_ENABLED" | "MONETIZATION_ENABLED" | "MORE_STICKERS" | "THREE_DAY_THREAD_ARCHIVE" | "SEVEN_DAY_THREAD_ARCHIVE" | "PRIVATE_THREADS";
type GuildFeatures = "ANIMATED_ICON" | "BANNER" | "COMMERCE" | "COMMUNITY" | "DISCOVERABLE" | "FEATURABLE" | "INVITE_SPLASH" | "MEMBER_VERIFICATION_GATE_ENABLED" | "NEWS" | "PARTNERED" | "PREVIEW_ENABLED" |"ROLE_ICONS" | "VANITY_URL" | "VERIFIED" | "VIP_REGIONS" | "WELCOME_SCREEN_ENABLED" | "TICKETED_EVENTS_ENABLED" | "MONETIZATION_ENABLED" | "MORE_STICKERS" | "THREE_DAY_THREAD_ARCHIVE" | "SEVEN_DAY_THREAD_ARCHIVE" | "PRIVATE_THREADS";
conorwastakenwastaken marked this conversation as resolved.
Show resolved Hide resolved
type NSFWLevel = 0 | 1 | 2 | 3;
type PossiblyUncachedGuild = Guild | Uncached;
type PremiumTier = 0 | 1 | 2 | 3;
Expand Down Expand Up @@ -474,11 +474,13 @@ declare namespace Eris {
interface OldRole {
color: number;
hoist: boolean;
icon: string | null;
managed: boolean;
mentionable: boolean;
name: string;
permissions: Permission;
position: number;
unicodeEmoji: string | null;
}
interface OldVoiceState {
deaf: boolean;
Expand Down Expand Up @@ -1019,9 +1021,11 @@ declare namespace Eris {
interface RoleOptions {
color?: number;
hoist?: boolean;
icon?: string;
mentionable?: boolean;
name?: string;
permissions?: bigint | number | string | Permission;
unicodeEmoji?: string;
}
interface RoleTags {
bot_id?: string;
Expand Down Expand Up @@ -2503,6 +2507,8 @@ declare namespace Eris {
createdAt: number;
guild: Guild;
hoist: boolean;
icon: string | null;
iconURL: string | null;
id: string;
json: Partial<Record<Exclude<keyof Constants["Permissions"], "all" | "allGuild" | "allText" | "allVoice">, boolean>>;
managed: boolean;
Expand All @@ -2512,6 +2518,7 @@ declare namespace Eris {
permissions: Permission;
position: number;
tags?: RoleTags;
unicodeEmoji: string | null;
constructor(data: BaseData, guild: Guild);
delete(reason?: string): Promise<void>;
edit(options: RoleOptions, reason?: string): Promise<Role>;
Expand Down
6 changes: 6 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,11 @@ class Client extends EventEmitter {
* @arg {Object | Role} [options] An object or Role containing the properties to set
* @arg {Number} [options.color] The hex color of the role, in number form (ex: 0x3d15b3 or 4040115)
* @arg {Boolean} [options.hoist] Whether to hoist the role in the user list or not
* @arg {String} [options.icon] The role icon as a base64 data URI
* @arg {Boolean} [options.mentionable] Whether the role is mentionable or not
* @arg {String} [options.name] The name of the role
* @arg {BigInt | Number | String | Permission} [options.permissions] The role permissions
* @arg {String} [options.unicodeEmoji] The role's unicode emoji
* @arg {String} [reason] The reason to be displayed in audit logs
* @returns {Promise<Role>}
*/
Expand All @@ -675,7 +677,9 @@ class Client extends EventEmitter {
permissions: options.permissions,
color: options.color,
hoist: options.hoist,
icon: options.icon,
mentionable: options.mentionable,
unicode_emoji: options.unicodeEmoji,
reason: reason
}).then((role) => {
const guild = this.guilds.get(guildID);
Expand Down Expand Up @@ -1311,9 +1315,11 @@ class Client extends EventEmitter {
* @arg {Object} options The properties to edit
* @arg {Number} [options.color] The hex color of the role, in number form (ex: 0x3da5b3 or 4040115)
* @arg {Boolean} [options.hoist] Whether to hoist the role in the user list or not
* @arg {String} [options.icon] The role icon as a base64 data URI
* @arg {Boolean} [options.mentionable] Whether the role is mentionable or not
* @arg {String} [options.name] The name of the role
* @arg {BigInt | Number | String | Permission} [options.permissions] The role permissions
conorwastakenwastaken marked this conversation as resolved.
Show resolved Hide resolved
* @arg {String} [options.unicodeEmoji] The role's unicode emoji
* @arg {String} [reason] The reason to be displayed in audit logs
* @returns {Promise<Role>}
*/
Expand Down
6 changes: 5 additions & 1 deletion lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -1379,12 +1379,14 @@ class Shard extends EventEmitter {
const oldRole = {
color: role.color,
hoist: role.hoist,
icon: role.icon,
managed: role.managed,
mentionable: role.mentionable,
name: role.name,
permissions: role.permissions,
position: role.position,
tags: role.tags
tags: role.tags,
unicodeEmoji: role.unicodeEmoji
};
/**
* Fired when a guild role is updated
Expand All @@ -1394,12 +1396,14 @@ class Shard extends EventEmitter {
* @prop {Object} oldRole The old role data
* @prop {Number} oldRole.color The hex color of the role in base 10
* @prop {Boolean} oldRole.hoist Whether users with this role are hoisted in the user list or not
* @prop {String?} oldRole.icon The hash of the role's icon image, or null if no icon
conorwastakenwastaken marked this conversation as resolved.
Show resolved Hide resolved
* @prop {Boolean} oldRole.managed Whether a guild integration manages this role or not
* @prop {Boolean} oldRole.mentionable Whether the role is mentionable or not
* @prop {String} oldRole.name The name of the role
* @prop {Permission} oldRole.permissions The permissions number of the role
* @prop {Number} oldRole.position The position of the role
* @prop {Object?} oldRole.tags The tags of the role
* @prop {String?} oldRole.unicodeEmoji Unicode emoji for the role
*/
this.emit("guildRoleUpdate", guild, guild.roles.update(packet.d.role, guild), oldRole);
break;
Expand Down
3 changes: 2 additions & 1 deletion lib/rest/Endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ module.exports.GUILD_BANNER = (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}`;
module.exports.TEAM_ICON = (teamID, teamIcon) => `/team-icons/${teamID}/${teamIcon}`;
module.exports.ROLE_ICON = (roleID, roleIcon) => `/role-icons/${roleID}/${roleIcon}`;
module.exports.TEAM_ICON = (teamID, teamIcon) => `/team-icons/${teamID}/${teamIcon}`;
module.exports.USER_AVATAR = (userID, userAvatar) => `/avatars/${userID}/${userAvatar}`;

// Client Endpoints
Expand Down
4 changes: 4 additions & 0 deletions lib/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,11 @@ class Guild extends Base {
* @arg {Object | Role} [options] An object or Role containing the properties to set
* @arg {Number} [options.color] The hex color of the role, in number form (ex: 0x3d15b3 or 4040115)
* @arg {Boolean} [options.hoist] Whether to hoist the role in the user list or not
* @arg {String} [options.icon] The role icon as a base64 data URI
* @arg {Boolean} [options.mentionable] Whether the role is mentionable or not
* @arg {String} [options.name] The name of the role
* @arg {BigInt | Number | String | Permission} [options.permissions] The role permissions
* @arg {String} [options.unicodeEmoji] The role's unicode emoji
* @arg {String} [reason] The reason to be displayed in audit logs
* @returns {Promise<Role>}
*/
Expand Down Expand Up @@ -587,9 +589,11 @@ class Guild extends Base {
* @arg {Object} options The properties to edit
* @arg {Number} [options.color] The hex color of the role, in number form (ex: 0x3da5b3 or 4040115)
* @arg {Boolean} [options.hoist] Whether to hoist the role in the user list or not
* @arg {String} [options.icon] The role icon as a base64 data URI
* @arg {Boolean} [options.mentionable] Whether the role is mentionable or not
* @arg {String} [options.name] The name of the role
* @arg {BigInt | Number | String | Permission} [options.permissions] The role permissions
* @arg {String} [options.unicodeEmoji] The role's unicode emoji
* @arg {String} [reason] The reason to be displayed in audit logs
* @returns {Promise<Role>}
*/
Expand Down
22 changes: 20 additions & 2 deletions lib/structures/Role.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"use strict";

const Base = require("./Base");
const Endpoints = require("../rest/Endpoints");
const Permission = require("./Permission");

/**
* Represents a role
* @prop {Number} color The hex color of the role in base 10
* @prop {Number} createdAt Timestamp of the role's creation
* @prop {Boolean} hoist Whether users with this role are hoisted in the user list or not
* @prop {String?} icon The hash of the role's icon image, or null if no icon
* @prop {String?} iconURL The URL of the role's icon image
* @prop {String} id The ID of the role
* @prop {Object} json Generates a JSON representation of the role permissions
* @prop {Guild} guild The guild that owns the role
Expand All @@ -21,6 +24,7 @@ const Permission = require("./Permission");
* @prop {String?} tags.bot_id The ID of the bot associated with the role
* @prop {String?} tags.integration_id The ID of the integration associated with the role
* @prop {Boolean?} tags.premium_subscriber Whether the role is the guild's premium subscriber role
* @prop {String?} unicodeEmoji Unicode emoji for the role
*/
class Role extends Base {
constructor(data, guild) {
Expand Down Expand Up @@ -57,16 +61,26 @@ class Role extends Base {
this.tags.premium_subscriber = true;
}
}
if(data.icon !== undefined) {
this.icon = data.icon;
}
if(data.unicode_emoji !== undefined) {
this.unicodeEmoji = data.unicode_emoji;
}
}

get mention() {
return `<@&${this.id}>`;
get iconURL() {
return this.icon ? this.guild.shard.client._formatImage(Endpoints.ROLE_ICON(this.id, this.icon)) : null;
}

get json() {
return this.permissions.json;
}

get mention() {
return `<@&${this.id}>`;
}

/**
* Delete the role
* @arg {String} [reason] The reason to be displayed in audit logs
Expand All @@ -81,9 +95,11 @@ class Role extends Base {
* @arg {Object} options The properties to edit
* @arg {Number} [options.color] The hex color of the role, in number form (ex: 0x3da5b3 or 4040115)
* @arg {Boolean} [options.hoist] Whether to hoist the role in the user list or not
* @arg {String} [options.icon] The role icon as a base64 data URI
* @arg {Boolean} [options.mentionable] Whether the role is mentionable or not
* @arg {String} [options.name] The name of the role
* @arg {BigInt | Number} [options.permissions] The role permissions number
* @arg {String?} unicodeEmoji Unicode emoji for the role
* @arg {String} [reason] The reason to be displayed in audit logs
* @returns {Promise<Role>}
*/
Expand All @@ -104,12 +120,14 @@ class Role extends Base {
return super.toJSON([
"color",
"hoist",
"icon",
"managed",
"mentionable",
"name",
"permissions",
"position",
"tags",
"unicodeEmoji",
...props
]);
}
Expand Down