Repository navigation
Give GitHub sponsors a Discord role, synced daily with the shop - #11
Merged
Merged
Conversation
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.
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.
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 postposts a panel with a link to the sponsors page and a persistentsponsor_verifybutton. The button replies ephemerally with a personal link to the shop, valid for 15 minutes and signed withSPONSOR_LINK_SECRET.SPONSOR_SYNC_SECRET) and adds or removes the role. It runs atsyncHourand once a minute after start. If the list can't be fetched or a single row is malformed, it changes nothing./sponsor sync force:truebypasses the brake for one run, and the daily run never forces./sponsor syncruns the sync by hand.features.sponsor(enabled,role,shopBaseUrl,sponsorsUrl,syncHour), off by default. With it off, the command is not registered.Tests
npm test: 177 passed (32 new). Covered:force;I broke each guard once on purpose, saw the test fail, then restored it.
Setup
The installation's
config.jsoncneeds these entries:features.sponsor.enabled: trueshopBaseUrlsponsorsUrlroles.sponsorThey are not in the example config, because the brand scan doesn't allow the shop address in tracked files. Both secrets go in
.envwith the same values as in the shop.