Skip to content

Commit

Permalink
Merge pull request #93 from HopperElec/pseudoremove-discrim
Browse files Browse the repository at this point in the history
Pseudo-remove Discord discriminators
  • Loading branch information
mlomb authored Nov 22, 2023
2 parents 90ad151 + cd99f45 commit 8bcf36e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
12 changes: 8 additions & 4 deletions pipeline/parse/parsers/DiscordParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
avatar: avatar ? (" " + avatar).substring(1) : undefined, // avoid leak
};
this.emit("author", pauthor, this.lastMessageTimestampInFile);
Expand Down
24 changes: 11 additions & 13 deletions report/components/core/labels/AuthorLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,19 @@ const _AuthorLabel = ({ index }: LabelProps) => {

// add discriminator in Discord
if (db.config.platform === "discord") {
let n = author.n;
let discr = 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) {
discr = parseInt(discr).toString();
n = n.slice(0, -5);
} else discr = undefined;

name = (
<>
{n}
{discr && <span className="Label__discriminator">#{`${isDemo ? 0 : discr}`.padStart(4, "0")}</span>}
</>
);
if (!isDemo && discr && discr.length === 4) {
name = (
<>
{nick}
<span className="Label__discriminator">#{discr}</span>
</>
);
}
}

if (author.b) {
Expand Down

0 comments on commit 8bcf36e

Please sign in to comment.