Skip to content

refactor: give the bot one module for where it sits in the office - #124

Merged
ChristopherPHolder merged 2 commits into
mainfrom
refactor/office-seat
Oct 31, 2026
Merged

ChristopherPHolder merged 2 commits into
mainfrom
refactor/office-seat

Conversation

@ChristopherPHolder

Copy link
Copy Markdown
Collaborator

What and why

Closes #117. Stacked on #123; once that merges, this diff is only the last commit.

Where the bot sits in the office was decided and carried out inside DiscordGateway, next to the discord.js client:

  • a wanted Ref and a recording Ref;
  • a semaphore, so it only moves one step at a time;
  • the nickname changes;
  • the 5-second wait for Discord to confirm the bot left before recording;
  • going back after a shard reconnect.

None of this was reachable without a real Discord client, so none of it was tested.

  • OfficeSeat now owns all of that, with two members:
    • want(presence): Program calls it when the office opens or empties.
    • record(mode): Capture calls it with Capturing, Paused or Off.
  • SeatAdapter is the Discord side it talks to: move to a channel or out of it (always muted and deafened), whether the bot is still in voice, rename, and a stream of reconnects. There are two adapters:
    • the real one, built in DiscordGateway from the guild and client;
    • an in-memory one, used in tests.
  • DiscordGateway loses moveBot and setRecording and exposes seat instead. Its test layer no longer takes a recordings queue.
  • RecordingMode and the nicknames move to OfficeSeat.

Behaviour doesn't change. The same voice-state messages, nicknames, logs and timeouts are sent in the same order. Going back after a reconnect now listens through a stream instead of client.on callbacks.

Two things are left as they are:

  • The Recorder still follows botPresence itself. It needs the opened and emptied events to stop a recording and to catch up at startup.
  • VoiceCapture still joins through gateway.voiceAdapter. It's the audio connection's own Discord adapter, so the discord.js type is fine there.

How I tested it

  • New OfficeSeat tests, through an in-memory adapter:
    • joins and leaves;
    • steps out and renames before capturing;
    • stays put while capturing, then goes back on pause or stop;
    • goes back after a reconnect unless it's capturing;
    • records anyway after the 5-second wait when Discord doesn't confirm;
    • carries on when Discord isn't connected.
  • The Program and Sentry tests run with the real OfficeSeat over the test gateway, with the same moves expected as before.
  • The Recorder and Capture tests use an OfficeSeat fake that records the modes.
  • pnpm vp run ci passes. I didn't try it against a real Discord server.

Checklist

  • vp run ci passes
  • Tests cover the change
  • Docs updated if what gets posted, the configuration, the Console or the deploy changed (module table only)
  • New environment variables are wired through (none)
  • Ready to ship: merging this deploys it to production

@ChristopherPHolder
ChristopherPHolder enabled auto-merge (squash) October 31, 2026 11:12
@ChristopherPHolder
ChristopherPHolder merged commit 5636f08 into main Oct 31, 2026
2 checks passed
@ChristopherPHolder

Copy link
Copy Markdown
Collaborator Author

Note: this branch was stacked on #123, so this squash (5636f08) also carries #123's change, BotPosts (#116). #123 is closed as already merged.

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.

Give the bot one module for where it sits in the office

1 participant