Repository navigation
GitHub sponsors get the Sponsor role on Discord - #64
Merged
Merged
Conversation
…_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.
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
|
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 |
Code coverage overviewLanguages: TypeScript TypeScript / code-coverage/vitest
View coverage of the 4 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/membersgives 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 (branchfeature/required-roles-per-type).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 oftierSelectedAtandcreatedAt. Only user sponsors count, and the best of several sponsorships wins. Links are matched by GitHub account ID, not by login.sponsor-link.<payload>withSPONSOR_LINK_SECRET. The payload carries the Discord ID, the guild ID and an expiry, and the guild must matchSPONSOR_GUILD_ID. A token built by the bot passesverifyLinkTokenhere.msk_sponsor_links, migration 004: one GitHub account maps to one Discord account, and re-linking moves it./sponsor/verify(DE/sponsor/verifizieren), noindex.msk_sponsor_state, the processing itself, GitHub as recipient and the retention. All legal texts move to the November 2026 date, aslegalContent.test.tsrequires one date for all of them.Type of change
Checklist
npm run lintpasses (eslint on the changed files)npm run typecheckpassesnpm testpasses (1498 tests, 28 new intests/sponsors.test.ts)npm run buildpassesNotes for reviewers
Before the deploy:
https://www.msk-scripts.de/api/sponsor/callback.GITHUB_SPONSORS_TOKEN: a classic PAT of an org owner withread:organdread:user. Withoutread:user, GitHub refusesisActive,isOneTimePayment,createdAtandtierSelectedAt(checked against the real API).SPONSOR_LINK_SECRETandSPONSOR_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.