Mr Folio gets a Get release pings button - #252
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5b63a277f5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (interaction.type === MESSAGE_COMPONENT) { | ||
| // A button press. Only the release-pings button exists; anything else is acknowledged and ignored. | ||
| if (interaction.data?.custom_id !== PINGS_BUTTON) return json({ type: PONG }) | ||
| const said = await togglePings(env, interaction, discord(env)).catch((error) => { |
There was a problem hiding this comment.
Defer slow component role updates
When Discord's role API takes more than three seconds due to transient latency, this branch sends no initial response until togglePings completes. Discord requires the initial interaction response within three seconds, so the user can see “interaction failed” even though the role change later succeeds; retrying may then reverse the successful change. Unlike the application-command path below, component interactions need the same timeout/defer-and-edit handling. See Discord's interaction response deadline.
Useful? React with 👍 / 👎.
What this changes
A "Get release pings" button for Mr Folio. Nothing in the server says how to get the
Folio updatesrole, which is what @-mentions people when a release is posted. The button gives the role when pressed and takes it back when pressed again, and the answer is private to the person who pressed.tools/folio-bot/pings.mjs: the button (one row, one button, custom idfolio-release-pings) and the toggle. It reads the person's roles from the interaction itself, so there is no second lookup.worker.js: handles message-component interactions (type 3). A button this bot did not make is acknowledged and ignored.wrangler.toml:ROLE_UPDATES = "1553093586705449062".GUILD_IDcheck/redeemuses).How I checked it
node --testintools/folio-bot: 50 pass (44 before, 5 inpings.test.mjs, 1 inworker.test.mjs): the button's shape, give and take back, a 403 that says what to fix, another server or a missing setting changing nothing, Discord failing, and a signed press answered privately.Before it can work
Folio updatessits aboveMr Folioin Server Settings › Roles, and Discord only lets a bot hand out roles below its own, so the first press would get a 403 and the message above. DragFolio updatesbelowMr Folio(or Mr Folio above it).tools/folio-bot(~/dev/folio-site/node_modules/.bin/wrangler deploy).Cheap way out: revert; no other command reads these files.