From dc85d0929b33f350d42e246c600c58fee4a26507 Mon Sep 17 00:00:00 2001 From: Vernon Stinebaker Date: Mon, 16 Feb 2026 22:33:13 +0800 Subject: [PATCH] Add Discord mention_only option for @-mention only responses - Add MentionOnly config option to DiscordConfig - Add botUserID tracking in DiscordChannel - Add mention checking logic in handleMessage - Add network_mode: host to docker-compose for connectivity --- docker-compose.yml | 2 ++ pkg/channels/discord.go | 19 +++++++++++++++++++ pkg/config/config.go | 7 ++++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 48769627c..d4fa234fc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,6 +8,7 @@ services: context: . dockerfile: Dockerfile container_name: picoclaw-agent + network_mode: host profiles: - agent volumes: @@ -26,6 +27,7 @@ services: context: . dockerfile: Dockerfile container_name: picoclaw-gateway + network_mode: host restart: unless-stopped profiles: - gateway diff --git a/pkg/channels/discord.go b/pkg/channels/discord.go index 00aa8ab4d..169e46c01 100644 --- a/pkg/channels/discord.go +++ b/pkg/channels/discord.go @@ -26,6 +26,7 @@ type DiscordChannel struct { config config.DiscordConfig transcriber *voice.GroqTranscriber ctx context.Context + botUserID string } func NewDiscordChannel(cfg config.DiscordConfig, bus *bus.MessageBus) (*DiscordChannel, error) { @@ -72,6 +73,7 @@ func (c *DiscordChannel) Start(ctx context.Context) error { if err != nil { return fmt.Errorf("failed to get bot user: %w", err) } + c.botUserID = botUser.ID logger.InfoCF("discord", "Discord bot connected", map[string]any{ "username": botUser.Username, "user_id": botUser.ID, @@ -296,6 +298,23 @@ func (c *DiscordChannel) handleMessage(s *discordgo.Session, m *discordgo.Messag return } + // 如果配置为仅响应提及,则检查是否被提及 + if c.config.MentionOnly { + isMentioned := false + for _, mention := range m.Mentions { + if mention.ID == c.botUserID { + isMentioned = true + break + } + } + if !isMentioned { + logger.DebugCF("discord", "Message ignored - bot not mentioned", map[string]any{ + "user_id": m.Author.ID, + }) + return + } + } + senderID := m.Author.ID senderName := m.Author.Username if m.Author.Discriminator != "" && m.Author.Discriminator != "0" { diff --git a/pkg/config/config.go b/pkg/config/config.go index d189ff00b..fbc7e77be 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -104,9 +104,10 @@ type FeishuConfig struct { } type DiscordConfig struct { - Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_DISCORD_ENABLED"` - Token string `json:"token" env:"PICOCLAW_CHANNELS_DISCORD_TOKEN"` - AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_DISCORD_ALLOW_FROM"` + Enabled bool `json:"enabled" env:"PICOCLAW_CHANNELS_DISCORD_ENABLED"` + Token string `json:"token" env:"PICOCLAW_CHANNELS_DISCORD_TOKEN"` + AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_DISCORD_ALLOW_FROM"` + MentionOnly bool `json:"mention_only" env:"PICOCLAW_CHANNELS_DISCORD_MENTION_ONLY"` } type MaixCamConfig struct {