mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-11-19 13:18:52 -06:00
Keep # in in-game names when dropping the discriminator
This commit is contained in:
@@ -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);
|
||||
})
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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) =>
|
||||
|
||||
5
changelog/2026-11-05-in-game-name-with-hash.md
Normal file
5
changelog/2026-11-05-in-game-name-with-hash.md
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user