Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom paths in Discord avatars #107

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions pipeline/parse/parsers/DiscordParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,20 @@
// Can be:
// - https://cdn.discordapp.com/avatars/user_id/user_avatar.png (custom avatar, we only care about `user_id/user_avatar`)
// - https://cdn.discordapp.com/embed/avatars/discriminator.png (default color avatar)
// - <path>.png/gif (custom avatar but stored using `--media=true` in DCE)
let avatar: string | undefined;
if (message.author.avatarUrl && message.author.avatarUrl.includes("discordapp.com/avatars"))
avatar = message.author.avatarUrl.slice(35).split(".")[0];
if (message.author.avatarUrl) {
if (message.author.avatarUrl.includes("discordapp.com/avatars")) {
// custom avatar as URL, extract "user_id/user_avatar"
avatar = message.author.avatarUrl.slice(35).split(".")[0];
} else if (!message.author.avatarUrl.startsWith("http")) {
// assume it's a custom avatar stored as media
// store the full path to the avatar
// note that this will not work unless the user puts the report.html in the correct
// folder, but since we don't have the online URL, we do this as best-effort
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user should probably be informed of this in some way, perhaps in the header of the report similarly to the header used for the demo. Also, once configuration is added, the user should have the option to embed images in the report (both with and without media, since Discord profile picture links expire)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be a warning after the generation process. Showing a header like the demo that can't be easily removed will be annoying.
Embedding images is also complicated. With links it's not possible, since we may have to download thousands of images off Discord servers at once, which is bad. With local files, it may be possible but there isn't an easy way right now and I don't think it's worth it.

avatar = message.author.avatarUrl;

Check warning on line 109 in pipeline/parse/parsers/DiscordParser.ts

View check run for this annotation

Codecov / codecov/patch

pipeline/parse/parsers/DiscordParser.ts#L109

Added line #L109 was not covered by tests
}
}

const pauthor: PAuthor = {
id: message.author.id,
Expand Down
11 changes: 10 additions & 1 deletion report/components/core/avatars/AuthorAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ export const AuthorAvatar = ({ index }: { index: number }) => {
const num = author.n.split("#").pop();
if (num && num.length === 4) discriminator = parseInt(num);

url = author.a ? `https://cdn.discordapp.com/avatars/${author.a}.png?size=64` : undefined;
if (author.a) {
if (!author.a.includes(".")) {
// author.a is the "user_id/user_avatar" of the avatar URL
// for example "840286670888370206/7a0ce959e13e749f4f4d93ea4b314b9c"
url = `https://cdn.discordapp.com/avatars/${author.a}.png?size=64`;
} else {
// author.a is the full path to the avatar (probably locally stored)
url = author.a;
}
}
placeholder = RawImg(DiscordDefaultDMAvatars[discriminator % 5]);
break;
case "telegram":
Expand Down
Loading