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

Support per-guild avatars #1219

Merged
merged 4 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,11 @@ declare namespace Eris {
videoQualityMode: VideoQualityMode;
}
interface OldMember {
roles: string[];
avatar: string | null;
nick: string | null;
premiumSince: number;
pending?: boolean;
premiumSince: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Premium since can be null for old members

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That can go in its own PR, that addition isn't really an addition, it's a relocation

roles: string[];
}
interface OldMessage {
attachments: Attachment[];
Expand Down Expand Up @@ -812,7 +813,7 @@ declare namespace Eris {
channelID?: string | null;
deaf?: boolean;
mute?: boolean;
nick?: string;
nick?: string | null;
roles?: string[];
}
interface MemberPartial {
Expand Down Expand Up @@ -1681,6 +1682,7 @@ declare namespace Eris {
editGuildWelcomeScreen(guildID: string, options: WelcomeScreenOptions): Promise<WelcomeScreen>;
editGuildWidget(guildID: string, options: Widget): Promise<Widget>;
editMessage(channelID: string, messageID: string, content: MessageContent): Promise<Message>;
/** @deprecated */
editNickname(guildID: string, nick: string, reason?: string): Promise<void>;
editRole(guildID: string, roleID: string, options: RoleOptions, reason?: string): Promise<Role>; // TODO not all options are available?
editRolePosition(guildID: string, roleID: string, position: number): Promise<void>;
Expand Down Expand Up @@ -2059,6 +2061,7 @@ declare namespace Eris {
editEmoji(emojiID: string, options: { name: string; roles?: string[] }, reason?: string): Promise<Emoji>;
editIntegration(integrationID: string, options: IntegrationOptions): Promise<void>;
editMember(memberID: string, options: MemberOptions, reason?: string): Promise<Member>;
/** @deprecated */
editNickname(nick: string): Promise<void>;
editRole(roleID: string, options: RoleOptions): Promise<Role>;
editTemplate(code: string, options: GuildTemplateOptions): Promise<GuildTemplate>;
Expand Down
4 changes: 2 additions & 2 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ class Client extends EventEmitter {
/**
* Edit a guild member
* @arg {String} guildID The ID of the guild
* @arg {String} memberID The ID of the member
* @arg {String} memberID The ID of the member (you can use "@me" if you are only editing the bot user's nickname)
* @arg {Object} options The properties to edit
* @arg {String?} [options.channelID] The ID of the voice channel to move the member to (must be in voice). Set to `null` to disconnect the member
* @arg {Boolean} [options.deaf] Server deafen the member
Expand Down Expand Up @@ -1259,7 +1259,7 @@ class Client extends EventEmitter {
}

/**
* Edit the bot's nickname in a guild
* [DEPRECATED] Edit the bot's nickname in a guild
abalabahaha marked this conversation as resolved.
Show resolved Hide resolved
* @arg {String} guildID The ID of the guild
* @arg {String} nick The nickname
* @arg {String} [reason] The reason to be displayed in audit logs
Expand Down
6 changes: 4 additions & 2 deletions lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,7 @@ class Shard extends EventEmitter {
let oldMember = null;
if(member) {
oldMember = {
avatar: member.avatar,
roles: member.roles,
nick: member.nick,
premiumSince: member.premiumSince,
Expand All @@ -1144,11 +1145,12 @@ class Shard extends EventEmitter {
}
member = guild.members.update(packet.d, guild);
/**
* Fired when a member's roles or nickname are updated or they start boosting a server
* Fired when a member's guild avatar, roles or nickname are updated or they start boosting a server
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing when a member passes the rules gate for a server?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can also go in its own PR

* @event Client#guildMemberUpdate
* @prop {Guild} guild The guild
* @prop {Member} member The updated member
* @prop {Object?} oldMember The old member data
* @prop {Object?} oldMember The old member data, or null if the member wasn't cached
* @prop {String?} oldMember.avatar The hash of the member's guild avatar, or null if no guild avatar
* @prop {Array<String>} oldMember.roles An array of role IDs this member is a part of
* @prop {String?} oldMember.nick The server nickname of the member
* @prop {Number} oldMember.premiumSince Timestamp of when the member boosted the guild
Expand Down
1 change: 1 addition & 0 deletions lib/rest/Endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ module.exports.APPLICATION_ICON = (applicationID, icon)
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}`;
Expand Down
4 changes: 2 additions & 2 deletions lib/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ class Guild extends Base {

/**
* Edit a guild member
* @arg {String} memberID The ID of the member
* @arg {String} memberID The ID of the member (use "@me" to edit the current bot user)
* @arg {Object} options The properties to edit
* @arg {String?} [options.channelID] The ID of the voice channel to move the member to (must be in voice). Set to `null` to disconnect the member
* @arg {Boolean} [options.deaf] Server deafen the member
Expand All @@ -573,7 +573,7 @@ class Guild extends Base {
}

/**
* Edit the bot's nickname in the guild
* [DEPRECATED] Edit the bot's nickname in the guild
* @arg {String} nick The nickname
* @returns {Promise}
*/
Expand Down
12 changes: 6 additions & 6 deletions lib/structures/Member.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"use strict";

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

/**
* Represents a server member
* @prop {Array<Object>?} activities The member's current activities
* @prop {String?} avatar The hash of the user's avatar, or null if no avatar
* @prop {String?} avatar The hash of the member's guild avatar, or null if no guild avatar
* @prop {String} avatarURL The URL of the user's avatar which can be either a JPG or GIF
* @prop {Boolean} bot Whether the user is an OAuth bot or not
* @prop {Object?} clientStatus The member's per-client status
Expand Down Expand Up @@ -98,14 +99,13 @@ class Member extends Base {
if(data.pending !== undefined) {
this.pending = data.pending;
}
}

get avatar() {
return this.user.avatar;
if(data.avatar !== undefined) {
this.avatar = data.avatar;
}
}

get avatarURL() {
return this.user.avatarURL;
return this.avatar ? this.guild.shard.client._formatImage(Endpoints.GUILD_AVATAR(this.guild.id, this.id, this.avatar)) : this.user.avatarURL;
}

get bot() {
Expand Down