Skip to content

Give GitHub sponsors a Discord role, synced daily with the shop - #11

Merged
Musiker15 merged 5 commits into
mainfrom
feature/sponsor-role
Nov 5, 2026
Merged

Musiker15 merged 5 commits into
mainfrom
feature/sponsor-role

Conversation

@Musiker15

Copy link
Copy Markdown
Member

Sponsors of the MSK-Scripts org on GitHub get a Sponsor role, which opens script support tickets for them. The shop (MSK-Scripts/msk-shop, branch feature/github-sponsors-role) signs them in with GitHub and grants the role on the spot. This side posts the entry point and keeps the role in line every day.

What it adds

  • /sponsor post posts a panel with a link to the sponsors page and a persistent sponsor_verify button. The button replies ephemerally with a personal link to the shop, valid for 15 minutes and signed with SPONSOR_LINK_SECRET.
  • A daily sync reads the shop's list of valid sponsors (SPONSOR_SYNC_SECRET) and adds or removes the role. It runs at syncHour and once a minute after start. If the list can't be fetched or a single row is malformed, it changes nothing.
  • The sync has a brake. If it would take the role from more than half of the holders and at least three members, it removes nobody and logs a warning; additions still happen. /sponsor sync force:true bypasses the brake for one run, and the daily run never forces.
  • /sponsor sync runs the sync by hand.
  • Config features.sponsor (enabled, role, shopBaseUrl, sponsorsUrl, syncHour), off by default. With it off, the command is not registered.
  • English and German texts, both READMEs.

Tests

npm test: 177 passed (32 new). Covered:

  • the token against a fixed vector;
  • the role diff, which skips bots;
  • rejection of bad shop answers, including a timeout;
  • the brake and force;
  • the schedule.

I broke each guard once on purpose, saw the test fail, then restored it.

Setup

The installation's config.jsonc needs these entries:

  • features.sponsor.enabled: true
  • shopBaseUrl
  • sponsorsUrl
  • roles.sponsor

They are not in the example config, because the brand scan doesn't allow the shop address in tracked files. Both secrets go in .env with the same values as in the shop.

Sponsors get ticket support on Discord through a role. The shop does the
GitHub login, the sponsorship check and the first grant; the bot does the
rest, in core/sponsor.js:

- /sponsor post puts a panel in the channel with a link to the sponsors page
  and a persistent `sponsor_verify` button.
- The button answers ephemerally with a personal link into the shop, signed
  with SPONSOR_LINK_SECRET and valid for 15 minutes.
- Once a minute after startup and then daily at features.sponsor.syncHour,
  the bot fetches the shop's list with SPONSOR_SYNC_SECRET and adds or
  removes the role to match. /sponsor sync runs it by hand.

The token and the list are a contract with the shop, which implements the
same format on its side. The harness pins the token against a vector
computed in Python rather than by this code, so a change that breaks the
format cannot also move the expectation.

A list that did not arrive changes nothing. A non-200, an `ok` that is not
true, a timeout or a single malformed row aborts the whole sync, adds
included. Reading "no list" as "no sponsors" would strip the role from every
paying member because the shop had a bad minute. Bots are never touched.

Off by default. Switched on without both secrets (32 characters at least),
a role or an https shop URL, the sync stays off and the gap is listed at
boot with everything else that is missing. shopBaseUrl and sponsorsUrl ship
empty: the brand scan keeps the shop's address out of tracked files, so the
installation sets both in its own config.jsonc.

One command with two subcommands rather than two commands, because both
belong to the same feature and the same people and one role gate covers
them. Gated to founder and manager like the other posting commands.

Checked by breaking it: a changed signing prefix, a dropped bot guard, an
accepted non-200 and an accepted bad row each turn the harness red.
Two rows in the command table, a short paragraph on how the link and the
daily sync work and which settings and secrets they need, and the two new
files in the project tree.
AST-only update for core/sponsor.js and the /sponsor command. 1073 nodes, 2030 edges, 85 communities.
A list that arrives, parses and still says most sponsors are gone is more
likely a fault in the shop than a wave of cancellations. Taking the role from
everybody on the strength of it would cost every paying member their ticket
support until the next run.

So when a sync would remove the role from more than half of the current
holders AND at least three members, it removes nothing that run, still makes
the additions, and logs the counts. The floor of three keeps a small server,
where one cancellation is already half, from being stuck behind the brake.

`/sponsor sync force:true` bypasses it for that one run, after somebody has
checked the shop. The daily run never forces, and a harness check reads the
scheduled call to keep it that way.

validUntil stays unevaluated and a single malformed row still rejects the
whole list: the shop remains the authority on who is a sponsor.

Checked by breaking it: a brake that never fires, a brake without the floor
of three and a command that drops the force option each turn the harness red.
@Musiker15
Musiker15 merged commit 0217896 into main Nov 5, 2026
6 checks passed
@Musiker15
Musiker15 deleted the feature/sponsor-role branch November 5, 2026 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant