From ebe8d92c75064afec18223b048b5949638bb1ebd Mon Sep 17 00:00:00 2001 From: openclaw Date: Sun, 15 Feb 2026 07:03:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=9F=E4=B8=80=E6=89=80=E6=9C=89?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E4=BD=BF=E7=94=A8=E5=90=8C=E4=B8=80userID?= =?UTF-8?q?=EF=BC=8CTG=E5=92=8CQQ=E6=95=B0=E6=8D=AE=E4=BA=92=E9=80=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/bot/telegram.go | 12 +++++++----- internal/qq/qq.go | 18 ++++++------------ 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/internal/bot/telegram.go b/internal/bot/telegram.go index 0b7df0a..7ae4a98 100644 --- a/internal/bot/telegram.go +++ b/internal/bot/telegram.go @@ -12,6 +12,9 @@ import ( tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" ) +// DefaultUserID 统一用户ID,使所有平台共享同一份账本 +const DefaultUserID int64 = 1 + type TGBot struct { api *tgbotapi.BotAPI finance *service.FinanceService @@ -53,7 +56,6 @@ func (b *TGBot) Start(ctx context.Context) { func (b *TGBot) handleMessage(msg *tgbotapi.Message) { text := msg.Text chatID := msg.Chat.ID - userID := msg.From.ID var reply string @@ -66,7 +68,7 @@ func (b *TGBot) handleMessage(msg *tgbotapi.Message) { case text == "/today": today := time.Now().Format("2006-01-02") - items, err := b.finance.GetTransactionsByDate(userID, today) + items, err := b.finance.GetTransactionsByDate(DefaultUserID, today) if err != nil { reply = "❌ 查询失败" } else if len(items) == 0 { @@ -84,7 +86,7 @@ func (b *TGBot) handleMessage(msg *tgbotapi.Message) { } case text == "/list": - items, err := b.finance.GetTransactions(userID, 10) + items, err := b.finance.GetTransactions(DefaultUserID, 10) if err != nil { reply = "❌ 查询失败" } else if len(items) == 0 { @@ -103,10 +105,10 @@ func (b *TGBot) handleMessage(msg *tgbotapi.Message) { default: // 记账逻辑 - amount, category, err := b.finance.AddTransaction(userID, text) + amount, category, err := b.finance.AddTransaction(DefaultUserID, text) if err != nil { reply = "❌ 记账失败,请稍后重试" - log.Printf("记账失败 user=%d: %v", userID, err) + log.Printf("记账失败: %v", err) } else if amount == 0 { reply = "📍 没看到金额,这笔花了多少钱?" } else { diff --git a/internal/qq/qq.go b/internal/qq/qq.go index bc3feba..4867550 100644 --- a/internal/qq/qq.go +++ b/internal/qq/qq.go @@ -3,7 +3,6 @@ package qq import ( "context" "fmt" - "hash/fnv" "log" "strings" "time" @@ -18,6 +17,9 @@ import ( "github.com/tencent-connect/botgo/token" ) +// DefaultUserID 统一用户ID,使所有平台共享同一份账本 +const DefaultUserID int64 = 1 + type QQBot struct { api openapi.OpenAPI finance *service.FinanceService @@ -34,13 +36,6 @@ func NewQQBot(appID string, secret string, finance *service.FinanceService) *QQB } } -// hashUserID 将 QQ 的字符串用户标识转为 int64 -func hashUserID(authorID string) int64 { - h := fnv.New64a() - h.Write([]byte(authorID)) - return int64(h.Sum64()) -} - func (b *QQBot) Start(ctx context.Context) { // 创建 token source 并启动自动刷新 tokenSource := token.NewQQBotTokenSource(b.credentials) @@ -89,7 +84,6 @@ func isCommand(text string, keywords ...string) bool { // processAndReply 通用记账处理 func (b *QQBot) processAndReply(userID string, content string) string { - uid := hashUserID(userID) text := strings.TrimSpace(message.ETLInput(content)) if text == "" { return "" @@ -111,7 +105,7 @@ func (b *QQBot) processAndReply(userID string, content string) string { "• 帮助 — 本帮助信息" case isCommand(text, "查看", "记录", "列表", "list", "/list", "最近"): - items, err := b.finance.GetTransactions(uid, 10) + items, err := b.finance.GetTransactions(DefaultUserID, 10) if err != nil { return "❌ 查询失败" } @@ -126,7 +120,7 @@ func (b *QQBot) processAndReply(userID string, content string) string { return sb.String() case isCommand(text, "今日", "今天", "today"): - items, err := b.finance.GetTransactionsByDate(uid, today) + items, err := b.finance.GetTransactionsByDate(DefaultUserID, today) if err != nil { return "❌ 查询失败" } @@ -144,7 +138,7 @@ func (b *QQBot) processAndReply(userID string, content string) string { return sb.String() } - amount, category, err := b.finance.AddTransaction(uid, text) + amount, category, err := b.finance.AddTransaction(DefaultUserID, text) if err != nil { log.Printf("QQ记账失败 user=%s: %v", userID, err) return "❌ 记账失败,请稍后重试"