From 689cdb920fb216466d0b5e07005859086b14a8c4 Mon Sep 17 00:00:00 2001 From: Miepee <38186597+Miepee@users.noreply.github.com> Date: Mon, 6 Jun 2022 21:55:48 +0200 Subject: [PATCH] Force Discord avatars to be PNGs in a friendly matter Co-Authored-By: Travis Ralston --- src/matrixeventprocessor.ts | 4 ++-- src/usersyncroniser.ts | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts index 5ef631c6..262b3135 100644 --- a/src/matrixeventprocessor.ts +++ b/src/matrixeventprocessor.ts @@ -499,13 +499,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; } diff --git a/src/usersyncroniser.ts b/src/usersyncroniser.ts index 51805200..0528ce45 100644 --- a/src/usersyncroniser.ts +++ b/src/usersyncroniser.ts @@ -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; @@ -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;