Skip to content

feat(discord): add /remind slash command#797

Merged
thepagent merged 9 commits into
mainfrom
feat/remind-slash-command
May 11, 2026
Merged

feat(discord): add /remind slash command#797
thepagent merged 9 commits into
mainfrom
feat/remind-slash-command

Conversation

@chaodu-agent
Copy link
Copy Markdown
Collaborator

Summary

Adds a /remind slash command that lets humans schedule one-shot delayed mentions to users/roles in the channel.

Closes #796

What Changed

  • src/remind.rs — New module: Reminder struct, ReminderStore (JSON persistence), delay parser, scheduler
  • src/discord.rs — Register /remind command with 3 string options (targets, message, delay); handler validates input, persists, and schedules via tokio; re-schedules pending reminders on ready
  • src/main.rs — Wire up ReminderStore and pass to Discord Handler
  • docs/slash-commands.md — Document the new command

Usage

/remind targets:@超渡法師 @普渡法師 message:Review PR #42 delay:2h

Fires after 2 hours:

⏰ Reminder from @pahud:
"Review PR #42"
cc @超渡法師 @普渡法師

Design Decisions

  • String option for targets — Discord Mentionable type only allows one mention per option; using a string lets users specify multiple @user @role mentions
  • JSON file persistence — Simple, no external deps; stored at $HOME/.openab/reminders.json
  • tokio::time::sleep — Lightweight in-process scheduling; no need for external scheduler for one-shots
  • Human-onlycmd.user.bot check prevents bot-to-bot reminder loops

Testing

  • Unit tests for delay parser (parse_delay) and formatter (format_delay)
  • Manual testing requires a Discord bot token (not available in CI)

Not Included (future work)

Implements a /remind slash command that lets humans schedule delayed
mentions to users/roles in the channel.

- Command: /remind <targets> <message> <delay>
- Delay range: 1m to 30d (supports m/h/d and combinations)
- Only humans can invoke (bots rejected)
- Persistence: reminders.json survives restarts
- Re-schedules pending reminders on bot ready

Closes #796
@chaodu-agent chaodu-agent requested a review from thepagent as a code owner May 11, 2026 15:59
@github-actions github-actions Bot added the closing-soon PR missing Discord Discussion URL — will auto-close in 3 days label May 11, 2026
@github-actions
Copy link
Copy Markdown

⚠️ This PR is missing a Discord Discussion URL in the body.

All PRs must reference a prior Discord discussion to ensure community alignment before implementation.

Please edit the PR description to include a link like:

Discord Discussion URL: https://discord.com/channels/...

This PR will be automatically closed in 3 days if the link is not added.

@github-actions github-actions Bot added the pending-screening PR awaiting automated screening label May 11, 2026
@chaodu-agent

This comment has been minimized.

普渡法師 and others added 2 commits May 11, 2026 17:22
… input validation

- Cargo.toml: add serde feature to chrono (fixes E0277 CI failure)
- remind.rs: release mutex before sync file I/O to avoid blocking executor
- remind.rs: replace unwrap_or_default() with explicit error log on serialization failure
- remind.rs: fix test_parse_delay_too_short (remove wrong assertion that bare "30" errors)
- discord.rs: add 1800-char cap on reminder message
- discord.rs: neutralize @everyone/@here in message via zero-width space
…emoval

- F4: Per-user rate limit (max 5 active reminders)
- F7: create_dir_all before writing reminders.json
- F8: Deduplicate reminder scheduling on reconnect via scheduled_ids
- F9: Only remove reminder from store after successful send
@chaodu-agent chaodu-agent force-pushed the feat/remind-slash-command branch from b65cfbc to aa1bf41 Compare May 11, 2026 17:22
@chaodu-agent
Copy link
Copy Markdown
Collaborator Author

LGTM ✅ — All findings addressed, CI green.

What This PR Does

Adds a /remind slash command that lets humans schedule one-shot delayed mentions to users/roles in the channel. Reminders persist to JSON and survive bot restarts.

How It Works

src/remind.rs provides ReminderStore (Arc<Mutex> + JSON file) and schedule_reminder (tokio::spawn + sleep). src/discord.rs registers the /remind command and handles interactions; the ready event re-schedules persisted reminders on startup.

Findings

# Severity Finding Status
1 🟢 Broken unit test fixed — correct assertions now ✅ Fixed
2 🟢 Mutex released before file I/O — no longer blocks executor ✅ Fixed
3 🟢 Serialization error logged and write skipped — no silent data loss ✅ Fixed
4 🟢 Per-user rate limit (max 5 active reminders) added ✅ Fixed
5 🟢 Message length cap (1800 chars) enforced ✅ Fixed
6 🟢 @everyone/@here neutralized with zero-width space ✅ Fixed
7 🟢 create_dir_all ensures persistence directory exists ✅ Fixed
8 🟢 Dedup via scheduled_ids prevents double-fire on reconnect ✅ Fixed
9 🟢 Reminder only removed after successful send ✅ Fixed
What's Good (🟢)
  • All original review findings addressed in two focused commits
  • CI fully green (cargo check + clippy + test + 7 Docker smoke-tests)
  • Clean module separation maintained
  • Good unit test coverage for delay parsing

Reviewers: 普渡法師 ✅, 擺渡法師 ✅, 覺渡法師 ✅ | Aggregated by 超渡法師

…dation

- parse_delay: empty, invalid unit, case-insensitive, whitespace, boundaries
- format_delay: zero, pure units
- ReminderStore: add/remove/pending, persistence across reload
- sanitize_message: @everyone/@here neutralization
- validate_message: length cap enforcement
- Extract sanitize_message/validate_message as testable helpers
thepagent
thepagent previously approved these changes May 11, 2026
- Add MAX_TARGETS = 10 constant
- Reject /remind with >10 mentions (suggest using @ROLE)
- Update docs/slash-commands.md with constraint
- Add test for constant
@thepagent thepagent merged commit 2f20fdb into main May 11, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

closing-soon PR missing Discord Discussion URL — will auto-close in 3 days discord feature pending-screening PR awaiting automated screening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(discord): add /remind slash command for one-shot delayed mentions

2 participants