Skip to content

Commit

Permalink
Force Discord avatars to be PNGs in a friendly matter
Browse files Browse the repository at this point in the history
Co-Authored-By: Travis Ralston <[email protected]>
  • Loading branch information
Miepee and turt2live committed Jun 7, 2022
1 parent cbd3c67 commit f2b9d1b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/matrixeventprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,13 @@ export class MatrixEventProcessor {
if (userOrMember instanceof Discord.User) {
embed.setAuthor(
userOrMember.username,
userOrMember.avatarURL() || undefined,
userOrMember.avatarURL({ format: 'png' }) || undefined,
);
return;
} else if (userOrMember instanceof Discord.GuildMember) {
embed.setAuthor(
userOrMember.displayName,
userOrMember.user.avatarURL() || undefined,
userOrMember.user.avatarURL({ format: 'png' }) || undefined,
);
return;
}
Expand Down
8 changes: 5 additions & 3 deletions src/usersyncroniser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export class UserSyncroniser {
userState.createUser = true;
userState.displayName = displayName;
if (discordUser.avatar) {
userState.avatarUrl = discordUser.avatarURL();
userState.avatarUrl = discordUser.avatarURL({ format: 'png' });
userState.avatarId = discordUser.avatar;
}
return userState;
Expand All @@ -270,10 +270,12 @@ export class UserSyncroniser {
}

const oldAvatarUrl = remoteUser.avatarurl;
if (oldAvatarUrl !== discordUser.avatarURL()) {
const pngAvatarUrl = discordUser.avatarURL({ format: 'png' });
const webpAvatarUrl = discordUser.avatarURL();
if (oldAvatarUrl !== webpAvatarUrl && oldAvatarUrl !== pngAvatarUrl) {
log.verbose(`User ${discordUser.id} avatarurl should be updated`);
if (discordUser.avatar) {
userState.avatarUrl = discordUser.avatarURL();
userState.avatarUrl = pngAvatarUrl;
userState.avatarId = discordUser.avatar;
} else {
userState.removeAvatar = true;
Expand Down

0 comments on commit f2b9d1b

Please sign in to comment.