Skip to content

Add scheduled Bible reading sessions with subscriber management - #24

Open
KallynGowdy wants to merge 1 commit into
mainfrom
claude/discord-bot-issue-17-acjves
Open

KallynGowdy wants to merge 1 commit into
mainfrom
claude/discord-bot-issue-17-acjves

Conversation

@KallynGowdy

Copy link
Copy Markdown
Contributor

Summary

This PR adds support for creating and managing scheduled shared Bible reading sessions in Discord. Users can launch sessions for a specific book/chapter at a scheduled time, and other users can subscribe via emoji reactions to receive personalized links when the session starts.

Key Changes

Core Session Management

  • New SessionStore trait in store/store.rs defining operations for creating, retrieving, and managing scheduled sessions
  • Database schema (migration/m20260819_000000_create_scheduled_sessions.rs) with two new tables:
    • scheduled_sessions: stores session metadata (UUID, guild/channel/creator IDs, book, chapter, scheduled time, reminder settings, status)
    • scheduled_session_subscribers: tracks which users have subscribed to each session via emoji reactions
  • Sea-orm entities for both tables with proper relationships and constraints

Implementation

  • FakeStore in-memory implementation with test helpers (with_scheduled_session builder method) and comprehensive test suite
  • SqliteStore production implementation using sea-orm for all CRUD operations
  • Session lifecycle management:
    • Create sessions with auto-incrementing IDs and UUID for sharing
    • Track announcement message IDs for reaction-based subscription
    • Mark reminders as sent and sessions as started
    • List pending sessions for scheduler bootstrap

User-Facing Features

  • /launchsession slash command with modal UI collecting:
    • Book name and chapter number
    • When to start ("now" or "YYYY-MM-DD HH:MM" UTC)
    • Optional reminder lead time in minutes
  • Two session modes:
    • "Now" sessions: immediately provide creator with personalized link (no announcement/subscription flow)
    • Scheduled sessions: post announcement in channel, allow others to subscribe via 📖 emoji reactions
  • Reaction handlers (handler/reaction.rs) for adding/removing subscribers when users react with 📖

Scheduling & Jobs

  • Job scheduler integration (session/scheduler.rs) using tokio_cron_scheduler:
    • Register start and reminder jobs for each session
    • Bootstrap pending sessions on bot startup (survives restarts)
    • Dynamically compute delays from absolute scheduled_at timestamps
  • Job implementations (session/jobs.rs):
    • Start job: posts personalized links for all subscribers (each in their preferred language/translation)
    • Reminder job: pings subscribers N minutes before start

Utilities

  • Time parsing (session/time_parse.rs): validates "now" or future UTC datetime strings
  • Reminder parsing: validates positive integer minute values
  • Session URL builder (util/format.rs): generates seedbible.org links with sessionId parameter for collaborative sessions
  • Reply builders (poise_impl/replies.rs): ephemeral confirmations and public announcements with proper formatting

Notable Implementation Details

  • Session UUIDs are globally unique and placed in the seedbible.org sessionId query parameter to auto-create shared sessions
  • Each subscriber receives a personalized link respecting their individual language/translation preferences
  • Reminder and start jobs are one-shot async tasks with computed delays, allowing sessions to survive bot restarts
  • Duplicate subscriber additions are prevented at the database level (unique constraint) and application level
  • All session state transitions (pending → started) are persisted to prevent duplicate job execution

https://claude.ai/code/session_01KmHj65AfgKRPCtVPpyxcSZ

Adds a session-builder modal (book, chapter, when, reminder) that either
hands the creator an immediate personalized seedbible.org link ("now"), or
persists a scheduled session, posts a 📖-reaction announcement, and fires
start/reminder jobs via tokio-cron-scheduler. Subscribers react to opt in
and each gets a link personalized to their own language/translation, all
sharing the same session UUID so they land in the same collaborative room.

- New scheduled_sessions/scheduled_session_subscribers tables + SessionStore
  trait, implemented for SqliteStore and FakeStore
- New session module: modal, "now"/"YYYY-MM-DD HH:MM" time parsing, job
  bodies, and scheduler bootstrap/registration (survives restarts by
  recomputing delays from the stored absolute scheduled_at)
- New reaction_add/reaction_remove handler for the subscribe flow
- get_session_url() alongside the existing get_passage_url(), unmodified
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