Skip to content

feat(discord): smart auto-thread mode#1053

Closed
Hypn0sis wants to merge 5 commits intoRightNow-AI:mainfrom
Hypn0sis:feat/discord-smart-thread-pr
Closed

feat(discord): smart auto-thread mode#1053
Hypn0sis wants to merge 5 commits intoRightNow-AI:mainfrom
Hypn0sis:feat/discord-smart-thread-pr

Conversation

@Hypn0sis
Copy link
Copy Markdown
Contributor

@Hypn0sis Hypn0sis commented Apr 14, 2026

Summary

  • Adds auto_thread config field to DiscordConfig with three modes:
    • "true" — always create a thread from each message
    • "false" — never create a thread (default, opt-in)
    • "smart" — create a thread only when the bot is @mentioned
  • Thread name is derived from the message content (strips mention prefix, truncates to Discord's 100-char limit)
  • Auto-thread creation happens after all policy guards (group_policy, mention_only, free_response, rate-limit) so threads are never created for messages the bot would ignore
  • Incoming messages from inside a bot-created thread are detected and routed back into the same thread, preventing duplicate threads
  • MESSAGE_UPDATE events (Discord embed resolution) are deduplicated against already-forwarded MESSAGE_CREATE events to prevent double responses
  • Fixes api_send_thread_message to POST directly to channels/{thread_id}/messages (the correct Discord API endpoint for threads)
  • Adds RevoltAdapter::with_urls_and_channels constructor to support custom URLs + channel restrictions together

Config example

[channels.discord]
bot_token_env = "DISCORD_BOT_TOKEN"
auto_thread = "smart"   # or "true" / "false"

Test plan

  • cargo check --workspace --lib passes
  • cargo clippy -p openfang-channels -p openfang-types -p openfang-api -- -D warnings passes
  • cargo test -p openfang-channels -p openfang-types passes
  • Live: set auto_thread = "smart", mention bot in a server channel → thread created
  • Live: set auto_thread = "smart", message without mention → no thread
  • Live: set auto_thread = "false" → no threads ever
  • Live: replies inside a bot-created thread stay in the thread (no new thread spawned)

@Hypn0sis Hypn0sis force-pushed the feat/discord-smart-thread-pr branch from 1bae8fa to 0c20d0e Compare April 14, 2026 08:57
wasmtime 41.0.4 had 10 CVEs (RUSTSEC-2026-0085..0096) including two
critical sandbox-escape vulnerabilities. Upgraded to 43.0.1 which fixes
all of them.

rumqttc 0.24 pulled in rustls-webpki 0.102.8 (RUSTSEC-2026-0049, faulty
CRL matching). rumqttc 0.25 resolves the transitive dependency.

copy and func_wrap closures must return wasmtime::Result<T>.
… CVE

rumqttc 0.25 still pins rustls-webpki 0.102.8 (RUSTSEC-2026-0049)
via its default use-rustls feature. The MQTT adapter does not actually
use TLS (the use_tls branch is a no-op stub), so switch to
use-native-tls with default-features = false to eliminate the
vulnerable transitive dependency entirely.
@Hypn0sis
Copy link
Copy Markdown
Contributor Author

Closing in favour of two separate PRs: fix(deps) CVEs → #1041, feat(discord) smart auto-thread → new PR.

@Hypn0sis Hypn0sis closed this Apr 14, 2026
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