From ed4b3d51f503a9a205fa3ed7464900323ba42df6 Mon Sep 17 00:00:00 2001 From: hopperelec Date: Tue, 24 Oct 2023 01:39:13 +0100 Subject: [PATCH 1/3] Don't show Discord discriminator if it is #0000 Slight relevant refactor in AuthorLabel --- pipeline/parse/parsers/DiscordParser.ts | 12 ++++++++---- report/components/core/labels/AuthorLabel.tsx | 15 +++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pipeline/parse/parsers/DiscordParser.ts b/pipeline/parse/parsers/DiscordParser.ts index d0ab4b04..662b2b46 100644 --- a/pipeline/parse/parsers/DiscordParser.ts +++ b/pipeline/parse/parsers/DiscordParser.ts @@ -82,9 +82,13 @@ export class DiscordParser extends Parser { const timestampEdit = message.timestampEdited ? Date.parse(message.timestampEdited) : undefined; const callEndedTimestamp = message.callEndedTimestamp ? Date.parse(message.callEndedTimestamp) : undefined; - // Discord allows users to have different nicknames depending the chat. We honor the nickname first - const name = message.author.nickname || message.author.name; - const isDeletedUser = name === "Deleted User"; + // Discord allows users to have different nicknames depending on the chat. We honor the nickname first + let name = message.author.nickname || message.author.name; + if (name === "Deleted User") { + name = name.concat(" #" + message.author.id); + } else if (message.author.discriminator !== "0000") { + name = name.concat("#" + message.author.discriminator); + } // About the avatar: // See: https://discord.com/developers/docs/reference#image-formatting-cdn-endpoints @@ -98,7 +102,7 @@ export class DiscordParser extends Parser { const pauthor: PAuthor = { id: message.author.id, bot: message.author.isBot, - name: name + (isDeletedUser ? " #" + message.author.id : "#" + message.author.discriminator), + name: name, avatar: avatar ? (" " + avatar).substring(1) : undefined, // avoid leak }; this.emit("author", pauthor, this.lastMessageTimestampInFile); diff --git a/report/components/core/labels/AuthorLabel.tsx b/report/components/core/labels/AuthorLabel.tsx index e46925bb..7402ce24 100644 --- a/report/components/core/labels/AuthorLabel.tsx +++ b/report/components/core/labels/AuthorLabel.tsx @@ -25,14 +25,13 @@ const _AuthorLabel = ({ index }: LabelProps) => { if (discr && discr.length === 4) { discr = parseInt(discr).toString(); n = n.slice(0, -5); - } else discr = undefined; - - name = ( - <> - {n} - {discr && #{`${isDemo ? 0 : discr}`.padStart(4, "0")}} - - ); + name = ( + <> + {n} + {discr && #{`${isDemo ? 0 : discr}`.padStart(4, "0")}} + + ); + } } if (author.b) { From 2f302e15df02412cb0734346847779c5702635ba Mon Sep 17 00:00:00 2001 From: hopperelec Date: Tue, 24 Oct 2023 02:08:50 +0100 Subject: [PATCH 2/3] Some more refactoring --- report/components/core/labels/AuthorLabel.tsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/report/components/core/labels/AuthorLabel.tsx b/report/components/core/labels/AuthorLabel.tsx index 7402ce24..13f3fb80 100644 --- a/report/components/core/labels/AuthorLabel.tsx +++ b/report/components/core/labels/AuthorLabel.tsx @@ -18,17 +18,14 @@ const _AuthorLabel = ({ index }: LabelProps) => { // add discriminator in Discord if (db.config.platform === "discord") { - let n = author.n; - let discr = n.split("#").pop(); + const discr = author.n.split("#").pop(); // only keep if it's 4 chars (and not a deleted ID) if (discr && discr.length === 4) { - discr = parseInt(discr).toString(); - n = n.slice(0, -5); name = ( <> - {n} - {discr && #{`${isDemo ? 0 : discr}`.padStart(4, "0")}} + {author.n.slice(0, -5)} + #{`${isDemo ? "0000" : discr}`} ); } From cd99f45414fb0374bd38b3bfa9074d4d3e70ddc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lombardo?= Date: Wed, 22 Nov 2023 16:34:48 -0300 Subject: [PATCH 3/3] minor refactors --- pipeline/parse/parsers/DiscordParser.ts | 2 +- report/components/core/labels/AuthorLabel.tsx | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pipeline/parse/parsers/DiscordParser.ts b/pipeline/parse/parsers/DiscordParser.ts index 662b2b46..b4286f32 100644 --- a/pipeline/parse/parsers/DiscordParser.ts +++ b/pipeline/parse/parsers/DiscordParser.ts @@ -102,7 +102,7 @@ export class DiscordParser extends Parser { const pauthor: PAuthor = { id: message.author.id, bot: message.author.isBot, - name: name, + name, avatar: avatar ? (" " + avatar).substring(1) : undefined, // avoid leak }; this.emit("author", pauthor, this.lastMessageTimestampInFile); diff --git a/report/components/core/labels/AuthorLabel.tsx b/report/components/core/labels/AuthorLabel.tsx index 13f3fb80..e14fa6b1 100644 --- a/report/components/core/labels/AuthorLabel.tsx +++ b/report/components/core/labels/AuthorLabel.tsx @@ -18,14 +18,16 @@ const _AuthorLabel = ({ index }: LabelProps) => { // add discriminator in Discord if (db.config.platform === "discord") { - const discr = author.n.split("#").pop(); + const parts = author.n.split("#"); + const nick = parts[0]; + const discr: string | undefined = parts[1]; // only keep if it's 4 chars (and not a deleted ID) - if (discr && discr.length === 4) { + if (!isDemo && discr && discr.length === 4) { name = ( <> - {author.n.slice(0, -5)} - #{`${isDemo ? "0000" : discr}`} + {nick} + #{discr} ); }