Skip to content

GitHub sponsors get the Sponsor role on Discord - #64

Merged
Musiker15 merged 9 commits into
mainfrom
feature/github-sponsors-role
Nov 5, 2026
Merged

Musiker15 merged 9 commits into
mainfrom
feature/github-sponsors-role

Conversation

@Musiker15

Copy link
Copy Markdown
Member

Summary

Sponsors of the MSK-Scripts org on GitHub get the Sponsor role on the MSK Discord, which opens script support tickets for them. The multibot posts a Verify button; clicking it gives the member a personal signed link (15 minutes) to /api/sponsor/start. The shop signs them in with GitHub, links the Discord ID to the GitHub account, checks the sponsorship and grants the role right away through the Discord API. /api/sponsor/members gives the bot the list of linked members with a valid sponsorship for its daily sync, which also removes the role again.

Bot side: MSK-Scripts/discord_multibot (branch feature/sponsor-role). Ticket side: MSK-Scripts/discord_ticketbot (branch feature/required-roles-per-type).

  • Validity rule (lib/sponsors.ts, pure and tested): a monthly sponsorship of at least 5 $ counts while it is active. A one-time payment of at least 5 $ counts for 30 days from the later of tierSelectedAt and createdAt. Only user sponsors count, and the best of several sponsorships wins. Links are matched by GitHub account ID, not by login.
  • Link token: HMAC-SHA256 over sponsor-link.<payload> with SPONSOR_LINK_SECRET. The payload carries the Discord ID, the guild ID and an expiry, and the guild must match SPONSOR_GUILD_ID. A token built by the bot passes verifyLinkToken here.
  • Table msk_sponsor_links, migration 004: one GitHub account maps to one Discord account, and re-linking moves it.
  • Result page /sponsor/verify (DE /sponsor/verifizieren), noindex.
  • Privacy policy (DE and EN): new cookie msk_sponsor_state, the processing itself, GitHub as recipient and the retention. All legal texts move to the November 2026 date, as legalContent.test.ts requires one date for all of them.
  • The feature stays off and fails closed until every env var is set.

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Documentation
  • Tests
  • Chore / dependencies

Checklist

  • npm run lint passes (eslint on the changed files)
  • npm run typecheck passes
  • npm test passes (1498 tests, 28 new in tests/sponsors.test.ts)
  • npm run build passes
  • The change is focused and every changed line relates to it
  • No secrets or credentials are committed
  • Docs updated if behavior, env vars, routes or the DB schema changed
  • Tests added/updated for security-, billing- or parsing-critical logic

Notes for reviewers

Before the deploy:

  • A GitHub OAuth app in the org with the callback https://www.msk-scripts.de/api/sponsor/callback.
  • GITHUB_SPONSORS_TOKEN: a classic PAT of an org owner with read:org and read:user. Without read:user, GitHub refuses isActive, isOneTimePayment, createdAt and tierSelectedAt (checked against the real API).
  • SPONSOR_LINK_SECRET and SPONSOR_SYNC_SECRET, at least 32 characters, the same values as in the multibot.
  • SPONSOR_DISCORD_BOT_TOKEN, SPONSOR_GUILD_ID, SPONSOR_ROLE_ID.

Not verified yet: how GitHub reports a repeated one-time payment, as a new sponsorship or the same one with a new tierSelectedAt. The rule covers both, but it is worth one look at the real data after the first one-time sponsor.

A link can be used more than once within its 15 minutes. Whoever gets hold of someone else's link can at most attach that Discord account to their own GitHub account; they don't get the role themselves. I left it like that.

…_links

The Discord bot hands a member a signed link into the shop; lib/sponsorLink.ts
holds that contract (HMAC-SHA256 over "sponsor-link." + payload, 15 min TTL,
guild check), the signed OAuth state cookie and the env check that keeps the
feature off with a log line naming what is missing.

lib/sponsors.ts asks GitHub for the org's sponsorships and decides who counts:
monthly while active, one-time for 30 days, at least $5, users only, the best
of several, keyed by databaseId. lib/sponsorLinks.ts stores Discord user to
GitHub account, one GitHub account per Discord user, and grants the role.
/api/sponsor/start checks the bot's link and sends the browser to GitHub OAuth
without a scope. /api/sponsor/callback checks the state, links the accounts,
checks the sponsorship and grants the Discord role right away.
/api/sponsor/members gives the bot the list of valid sponsors for its daily
reconcile, behind a bearer secret, and answers 502 instead of an empty list
when GitHub fails.

Tests cover the token, the validity rule and the members auth; the route
guard test learns readStateCookie and bearerMatches.
One short text per status in English and German (/de/sponsor/verifizieren),
links to GitHub Sponsors and back to Discord. noindex, blocked in robots.txt,
no closing band.
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@graphify-labs

graphify-labs Bot commented Nov 5, 2026

Copy link
Copy Markdown

Graphify reviews are paused for this workspace because nobody has used it in 7 days. A workspace owner can resume reviews from the Repositories page: https://app.graphify.com/msk-scripts/repositories

@github-code-quality

github-code-quality Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: TypeScript

TypeScript / code-coverage/vitest

main ae3b8f0 feature/github-spons... 1f1c61d +/-
72% 73% +1%
View coverage of the 4 most impacted files.
File main ae3b8f0 feature/github-spons... 1f1c61d +/-
lib/i18n.ts 100% 100% 0%
lib/sponsorLinks.ts 0% 22% +22%
lib/sponsors.ts 0% 96% +96%
lib/sponsorLink.ts 0% 97% +97%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 05, 2026 10:41 UTC

Comment thread lib/sponsorLink.ts Fixed
@Musiker15
Musiker15 merged commit 3174ce3 into main Nov 5, 2026
11 checks passed
@Musiker15
Musiker15 deleted the feature/github-sponsors-role branch November 5, 2026 10:43
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.

2 participants