mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-15 00:27:29 +08:00
fix bug
This commit is contained in:
@@ -3,8 +3,10 @@ package channels
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"clawgo/pkg/bus"
|
||||
"clawgo/pkg/logger"
|
||||
)
|
||||
|
||||
type Channel interface {
|
||||
@@ -47,8 +49,14 @@ func (c *BaseChannel) IsAllowed(senderID string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Normalize sender id for channels that include display suffix, e.g. "12345|alice".
|
||||
rawSenderID := senderID
|
||||
if idx := strings.Index(senderID, "|"); idx > 0 {
|
||||
rawSenderID = senderID[:idx]
|
||||
}
|
||||
|
||||
for _, allowed := range c.allowList {
|
||||
if senderID == allowed {
|
||||
if senderID == allowed || rawSenderID == allowed {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -58,6 +66,11 @@ func (c *BaseChannel) IsAllowed(senderID string) bool {
|
||||
|
||||
func (c *BaseChannel) HandleMessage(senderID, chatID, content string, media []string, metadata map[string]string) {
|
||||
if !c.IsAllowed(senderID) {
|
||||
logger.WarnCF("channels", "Message rejected by allowlist", map[string]interface{}{
|
||||
"channel": c.name,
|
||||
"sender_id": senderID,
|
||||
"chat_id": chatID,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -172,9 +172,6 @@ func (c *TelegramChannel) handleMessage(message *telego.Message) {
|
||||
}
|
||||
|
||||
senderID := fmt.Sprintf("%d", user.ID)
|
||||
if user.Username != "" {
|
||||
senderID = fmt.Sprintf("%d|%s", user.ID, user.Username)
|
||||
}
|
||||
|
||||
chatID := message.Chat.ID
|
||||
c.chatIDs[senderID] = chatID
|
||||
@@ -262,6 +259,11 @@ func (c *TelegramChannel) handleMessage(message *telego.Message) {
|
||||
|
||||
log.Printf("Telegram message from %s: %s...", senderID, truncateString(content, 50))
|
||||
|
||||
if !c.IsAllowed(senderID) {
|
||||
log.Printf("Telegram message rejected by allowlist: sender=%s chat=%d", senderID, chatID)
|
||||
return
|
||||
}
|
||||
|
||||
// Thinking indicator
|
||||
_ = c.bot.SendChatAction(context.Background(), &telego.SendChatActionParams{
|
||||
ChatID: telegoutil.ID(chatID),
|
||||
|
||||
Reference in New Issue
Block a user