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
This commit is contained in:
parent
13e4028d42
commit
dc85d0929b
3 changed files with 25 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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" {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue