From abf295045007a2504acff96e56a330e7e5ce0a16 Mon Sep 17 00:00:00 2001 From: The Stranjer <791672+TheStranjer@users.noreply.github.com> Date: Sun, 16 Jul 2023 23:22:18 -0600 Subject: [PATCH] Prefer server-level display names when available (#888) Signed-off-by: Bob Arctor <neetzsche@tutanota.com> --- changelog.d/888.bugfix | 1 + src/bot.ts | 2 +- src/usersyncroniser.ts | 10 +++++----- 3 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 changelog.d/888.bugfix diff --git a/changelog.d/888.bugfix b/changelog.d/888.bugfix new file mode 100644 index 0000000..dbb1c3b --- /dev/null +++ b/changelog.d/888.bugfix @@ -0,0 +1 @@ +Prefer server-level display names when available. diff --git a/src/bot.ts b/src/bot.ts index 0ca0b76..67993ca 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -1027,7 +1027,7 @@ export class DiscordBot { } // Update presence because sometimes discord misses people. - await this.userSync.OnUpdateUser(msg.author, Boolean(msg.webhookID)); + await this.userSync.OnUpdateUser(msg.author, Boolean(msg.webhookID), msg); let rooms: string[]; try { rooms = await this.channelSync.GetRoomIdsFromChannel(msg.channel); diff --git a/src/usersyncroniser.ts b/src/usersyncroniser.ts index 5180520..1cdcf82 100644 --- a/src/usersyncroniser.ts +++ b/src/usersyncroniser.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { User, GuildMember } from "better-discord.js"; +import { User, GuildMember, Message } from "better-discord.js"; import { DiscordBot } from "./bot"; import { Util } from "./util"; import { DiscordBridgeConfig } from "./config"; @@ -96,8 +96,8 @@ export class UserSyncroniser { * @returns {Promise<void>} * @constructor */ - public async OnUpdateUser(discordUser: User, isWebhook: boolean = false) { - const userState = await this.GetUserUpdateState(discordUser, isWebhook); + public async OnUpdateUser(discordUser: User, isWebhook: boolean = false, msg?: Message) { + const userState = await this.GetUserUpdateState(discordUser, isWebhook, msg); try { await this.ApplyStateToProfile(userState); } catch (e) { @@ -230,7 +230,7 @@ export class UserSyncroniser { } } - public async GetUserUpdateState(discordUser: User, isWebhook: boolean = false): Promise<IUserState> { + public async GetUserUpdateState(discordUser: User, isWebhook: boolean = false, msg?: Message): Promise<IUserState> { log.verbose(`State update requested for ${discordUser.id}`); let mxidExtra = ""; if (isWebhook) { @@ -244,7 +244,7 @@ export class UserSyncroniser { id: discordUser.id + mxidExtra, mxUserId: `@_discord_${discordUser.id}${mxidExtra}:${this.config.bridge.domain}`, }); - const displayName = Util.ApplyPatternString(this.config.ghosts.usernamePattern, { + const displayName = msg?.member?.nickname || Util.ApplyPatternString(this.config.ghosts.usernamePattern, { id: discordUser.id, tag: discordUser.discriminator, username: discordUser.username, -- GitLab