feat(discord): multi-bot support with per-bot trigger injection#88
Open
stevengonsalvez wants to merge 1 commit into
Open
feat(discord): multi-bot support with per-bot trigger injection#88stevengonsalvez wants to merge 1 commit into
stevengonsalvez wants to merge 1 commit into
Conversation
Add DISCORD_BOTS env var for running multiple Discord bots in a single NanoClaw instance. Each bot gets its own identity, JID prefix, and trigger name for correct routing in multi-group setups. Format: DISCORD_BOTS=name:token:triggerName;name:token:triggerName Key changes: - Parameterize DiscordChannel with jidPrefix, label, triggerName via options object (backward-compatible — single-token setup unchanged) - Each bot injects its own trigger on @mention and reply-to-bot instead of the global ASSISTANT_NAME, fixing trigger routing for non-primary groups - Validate bot names against /^[a-z0-9-]+$/i to prevent regex injection via JID prefix interpolation - Strict 3-part colon parsing (name:token:triggerName) with warnings for malformed entries - Export parseDiscordBots for testability with 9 new test cases covering valid entries, malformed input, name validation, and edge cases - DB migration LIKE pattern covers both dc: and dc-name: prefixes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DISCORD_BOTSenv var for running multiple Discord bots in a single NanoClaw instance, each with its own identity, JID prefix, and trigger nameASSISTANT_NAME— without this fix, non-primary groups never match their trigger pattern in multi-bot setupsDISCORD_BOT_TOKENsetup works identically to beforeMotivation
When running multiple Discord bots (e.g., one per NanoClaw group with distinct personas), the original code injected the global
ASSISTANT_NAMEon @mention and reply-to-bot for all bots. This meant only the primary group's trigger matched — secondary groups never activated.Config format
Each entry produces:
discord-{name}(e.g.discord-engineer)dc-{name}:(e.g.dc-engineer:12345)@{triggerName}injected on @mention and reply-to-botBot names are validated against
/^[a-z0-9-]+$/ito prevent regex injection via JID prefix interpolation.Changes
src/channels/discord.tsDiscordBotOptions, per-bottriggerPattern,DISCORD_BOTSparser with name validation, multi-bot registration with single-bot fallbacksrc/channels/discord.test.tsbuildTriggerPatternto config mock, 9 new tests for parser + optionssrc/db.tsdc-%:multi-bot prefixes.env.exampleDISCORD_BOTSformatTest plan
DISCORD_BOT_TOKENstill works withdc:prefixASSISTANT_NAME)DISCORD_BOTSentries are skipped with warningDISCORD_BOTStakes precedence overDISCORD_BOT_TOKENwith logged info message