Add `dkit cdn`: build Discord CDN image URLs offline from an ID and a hash
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
Research direction
Start with the image-formatting documentation at developers/reference.mdx, then inspect dkit.core.parse and core/data.py for the existing snowflake parser and dataset registration. The issue also names src/dkit/data/cdn.json, .github/workflows/ci.yml, README.md, CHANGELOG.md, and required tests. Done means the CLI builds the documented CDN URLs offline and meets the listed behavior, coverage, lint, formatting, and documentation criteria.
Written by the indexing model from the issue text.
Description
Building an avatar, icon or banner URL means remembering the path of each endpoint, the a_ prefix for animated hashes, the allowed sizes and the default avatar rule. dkit could build the URL offline.
Proposed behaviour
A suggested interface (if you want a different one, please propose it in a comment on this issue before you start coding):
$ dkit cdn avatar 80351110224678912 a_1269e74af4df7417b13759eae50c83dc --format webp --size 256
https://cdn.discordapp.com/avatars/80351110224678912/a_1269e74af4df7417b13759eae50c83dc.webp?size=256
$ dkit cdn default-avatar 80351110224678912 # index 5 (see below)
$ dkit cdn --list # every endpoint type with its path
$ dkit --json cdn guild-icon GUILD_ID HASH
Rules that come straight from the docs ("Image Formatting" in developers/reference.mdx):
- Base URL
https://cdn.discordapp.com/, formats JPEG (.jpg,.jpeg), PNG, WebP, GIF and Lottie (.json). The format is the extension at the end of the URL. ?size=can be any power of two between 16 and 4096. Anything else is a usage error (exit 2) with a hint.- A hash that starts with
a_is available in an animated format, as GIF or as animated WebP (.webpplus?animated=true). - Default user avatar: the index is
(user_id >> 22) % 6for users on the new username system anddiscriminator % 5for legacy users. For example(80351110224678912 >> 22) % 6is5. Thesizeparameter is ignored for default avatars and stickers. - Sticker GIFs are not on the CDN base URL, they live at
https://media.discordapp.net/stickers/<sticker_id>.gif. - IDs are snowflakes: reuse
parse_snowflakefromdkit.core.parse.
Data
- New
src/dkit/data/cdn.jsonwith the endpoint table (type, path template, whether it supports GIF), the formats and the size rule, withsource,source_renderedandlast_verified. - Copy the endpoint table by machine from the docs. Footnotes you do not implement (for example custom emoji recommendations) can be stored as notes. If something is not documented, say so (CONTRIBUTING rule 4).
- Register the dataset in
DATASETS(core/data.py) and raise the JSON file count in the wheel check in.github/workflows/ci.ymlby one (it is 10 onmaintoday; if another data PR is merged before yours, rebase and raise it once more).
Acceptance criteria
- Tests for several endpoint types, formats, valid and invalid sizes,
a_hashes, the default avatar rule (both branches) and--json. - 100% line and branch coverage,
ruff checkandruff format --checkclean. - README section and an entry under
[Unreleased]inCHANGELOG.md(single### Addedblock, ends with the issue number, no removed lines). - The command never makes a request, it only builds the URL (CONTRIBUTING rule 2).
Please comment on this issue before you start (see CONTRIBUTING.md). AI-assisted contributions are welcome, please mention it in the PR description.
- Dominant language
- Python
- Stars
- 1
- Forks
- 7
- Avg merge
- 11h 50m
- Merged PRs (30d)
- 35
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Bytewave1/dkit
-
documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
enhancement good first issue new command
Difficulty 3/5 1-2 days Newbie friendliness 48/100
Maintainers usually reply within 1 day
-
enhancement good first issue new command
Difficulty 3/5 1-2 days Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
enhancement new command
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 1 day
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
NousResearch/hermes-agent#147104 ·
Maintainers usually reply within 1 day
-
[oblt-aw][autodoc] Document new required `shared-org-key` input for `obs-aw-dependency-review`Possibly taken @github-actions claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
bot-triaged module: inductor oncall: pt2 topic: fuzzer triaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
getchaintips leaves out the active tip once a header is staged on it, where Core always lists itOpen
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
btclib-org/btclib-node#2158 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
patrick-hudson/put.gd-desktop#979 · 1 comment ·
Maintainers usually reply within 1 day