From 1ca684fdf49d241e64940037d5d9ff2bfa1ee700 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Thu, 5 Nov 2026 19:43:42 +0200 Subject: [PATCH] Keep # in in-game names when dropping the discriminator --- .../lobbies/core/ScoreboardAttribution.ts | 2 +- .../scanner-ingest/core/Matches.test.ts | 20 +++++++++++++++++++ app/features/scanner-ingest/core/Matches.ts | 12 ++++++----- .../scanner-ingest/core/Scoreboards.test.ts | 19 ++++++++++++++++++ .../scanner-ingest/core/Scoreboards.ts | 3 ++- app/utils/string.test.ts | 19 ++++++++++++++++++ app/utils/strings.ts | 6 +++++- .../2026-11-05-in-game-name-with-hash.md | 5 +++++ 8 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 changelog/2026-11-05-in-game-name-with-hash.md diff --git a/app/features/lobbies/core/ScoreboardAttribution.ts b/app/features/lobbies/core/ScoreboardAttribution.ts index 5a9202d58..ddfca238d 100644 --- a/app/features/lobbies/core/ScoreboardAttribution.ts +++ b/app/features/lobbies/core/ScoreboardAttribution.ts @@ -195,7 +195,7 @@ function anchoredUserIds( const byInGameName = read ? sidePlayers.filter((player) => { const inGameName = player.inGameName - ? Matches.normalizeInGameName(player.inGameName) + ? Matches.normalizeSiteInGameName(player.inGameName) : ""; return inGameName && isSameNameRead(read, inGameName); }) diff --git a/app/features/scanner-ingest/core/Matches.test.ts b/app/features/scanner-ingest/core/Matches.test.ts index d60636f90..e3f976b57 100644 --- a/app/features/scanner-ingest/core/Matches.test.ts +++ b/app/features/scanner-ingest/core/Matches.test.ts @@ -327,6 +327,26 @@ describe("mergeMatches", () => { }); }); +describe("Matches.normalizeSiteInGameName", () => { + test.each([ + { why: "plain name", siteName: "Sendou#2955", read: "Sendou" }, + { + why: "# inside the name", + siteName: "Kiter#2772#1382", + read: "Kiter#2772", + }, + { + why: "name starting with #", + siteName: "# Sowoul ##1013", + read: "# Sowoul #", + }, + ])("matches the scoreboard read of a $why", ({ siteName, read }) => { + expect(Matches.normalizeSiteInGameName(siteName)).toBe( + Matches.normalizeInGameName(read), + ); + }); +}); + describe("Matches.gameStartedAt", () => { const PLAYED_AT = Date.UTC(2026, 7, 1, 18, 0, 0); diff --git a/app/features/scanner-ingest/core/Matches.ts b/app/features/scanner-ingest/core/Matches.ts index 6784cd882..f6a17149a 100644 --- a/app/features/scanner-ingest/core/Matches.ts +++ b/app/features/scanner-ingest/core/Matches.ts @@ -165,12 +165,14 @@ export function gameStartedAt(match: ScannerMatch): number | null { return startedAt; } -/** Lowercased, width-normalized in-game name without the #discriminator. */ +/** Lowercased, width-normalized in-game name as read off a scoreboard, which shows no #discriminator. */ export function normalizeInGameName(name: string): string { - return inGameNameWithoutDiscriminator(name) - .normalize("NFKC") - .trim() - .toLowerCase(); + return name.normalize("NFKC").trim().toLowerCase(); +} + +/** {@link normalizeInGameName} of an in-game name saved on the site, its #discriminator dropped. */ +export function normalizeSiteInGameName(inGameName: string): string { + return normalizeInGameName(inGameNameWithoutDiscriminator(inGameName)); } function canonicalObjective( diff --git a/app/features/scanner-ingest/core/Scoreboards.test.ts b/app/features/scanner-ingest/core/Scoreboards.test.ts index 28ee113e1..f5f27ccbe 100644 --- a/app/features/scanner-ingest/core/Scoreboards.test.ts +++ b/app/features/scanner-ingest/core/Scoreboards.test.ts @@ -862,6 +862,25 @@ describe("Scoreboards.povWeaponId", () => { }, ); + test("a teammate's seat whose name differs only after a # is not the sender's", () => { + const names = NAMES.map((name, i) => (i === 0 ? "Brook #4" : name)); + + expect( + Scoreboards.povWeaponId({ + match: testMatch({ povIndex: 0, names, weapons }), + game: testGame({ + winnerUserIds: [1, 2, 3, 4], + loserUserIds: [5, 6, 7, 8], + inGameNameByUserId: new Map([ + [1, "Brook #3#2493"], + [2, "Brook #4#2564"], + ]), + }), + povUserId: SENDER_ID, + }), + ).toBe(null); + }); + test("returns null when the seat's weapon was not read", () => { expect( Scoreboards.povWeaponId({ diff --git a/app/features/scanner-ingest/core/Scoreboards.ts b/app/features/scanner-ingest/core/Scoreboards.ts index 5b31f99e4..e7f2a6265 100644 --- a/app/features/scanner-ingest/core/Scoreboards.ts +++ b/app/features/scanner-ingest/core/Scoreboards.ts @@ -210,7 +210,8 @@ export function povWeaponId({ const seatName = Matches.normalizeInGameName(seat.name); const seatUserIds = [...game.inGameNameByUserId] .filter( - ([, inGameName]) => Matches.normalizeInGameName(inGameName) === seatName, + ([, inGameName]) => + Matches.normalizeSiteInGameName(inGameName) === seatName, ) .map(([userId]) => userId); if (seatName && seatUserIds.length > 0 && !seatUserIds.includes(povUserId)) { diff --git a/app/utils/string.test.ts b/app/utils/string.test.ts index 24cf60662..4577eaa99 100644 --- a/app/utils/string.test.ts +++ b/app/utils/string.test.ts @@ -1,10 +1,29 @@ import { describe, expect, test } from "vitest"; import { + inGameNameWithoutDiscriminator, pathnameFromPotentialURL, removeMarkdown, truncateBySentence, } from "./strings"; +describe("inGameNameWithoutDiscriminator()", () => { + test.each([ + { why: "plain name", inGameName: "Sendou#1234", expected: "Sendou" }, + { + why: "# inside the name", + inGameName: "Brook #4#2564", + expected: "Brook #4", + }, + { + why: "name starting with #", + inGameName: "# Sowoul ##1013", + expected: "# Sowoul #", + }, + ])("keeps the name of $why", ({ inGameName, expected }) => { + expect(inGameNameWithoutDiscriminator(inGameName)).toBe(expected); + }); +}); + describe("pathnameFromPotentialURL()", () => { test("Resolves path name from valid URL", () => { expect(pathnameFromPotentialURL("https://bsky.app/sendouc")).toBe( diff --git a/app/utils/strings.ts b/app/utils/strings.ts index aa3919f2d..ce8352998 100644 --- a/app/utils/strings.ts +++ b/app/utils/strings.ts @@ -2,7 +2,11 @@ import type { GearType } from "~/modules/in-game-lists/types"; import { assertUnreachable } from "./types"; export function inGameNameWithoutDiscriminator(inGameName: string) { - return inGameName.split("#")[0]; + const discriminatorIdx = inGameName.lastIndexOf("#"); + + return discriminatorIdx === -1 + ? inGameName + : inGameName.slice(0, discriminatorIdx); } export const rawSensToString = (sens: number) => diff --git a/changelog/2026-11-05-in-game-name-with-hash.md b/changelog/2026-11-05-in-game-name-with-hash.md new file mode 100644 index 000000000..c1e1a1965 --- /dev/null +++ b/changelog/2026-11-05-in-game-name-with-hash.md @@ -0,0 +1,5 @@ +--- +navItem: [sendouq, scanner] +type: bug +--- +In-game names containing a # are no longer cut short on SendouQ group cards or mixed up with similar names by the scanner