From 6aa1d02fff77912490e0d9a03508f6476571ee42 Mon Sep 17 00:00:00 2001 From: mutezebra Date: Sun, 8 Mar 2026 17:30:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(feishu):=20=E7=94=A8=20crypto/rand=20?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=9A=8F=E6=9C=BA=E8=A1=A8=E6=83=85=E5=B9=B6?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=A4=BA=E4=BE=8B=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 2 +- pkg/channels/feishu/feishu_64.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 798815a7a..e0a07236e 100644 --- a/.env.example +++ b/.env.example @@ -12,7 +12,7 @@ # Feishu (飞书) # PICOCLAW_CHANNELS_FEISHU_APP_ID=cli_xxx # PICOCLAW_CHANNELS_FEISHU_APP_SECRET=xxx -# PICOCLAW_CHANNELS_FEISHU_RANDOM_REACTION_EMOJI=Typing,Onit +# PICOCLAW_CHANNELS_FEISHU_RANDOM_REACTION_EMOJI=Typing,OneSecond # ── Web Search (optional) ──────────────── # BRAVE_SEARCH_API_KEY=BSA... diff --git a/pkg/channels/feishu/feishu_64.go b/pkg/channels/feishu/feishu_64.go index fdb3b8e22..5217dd4e9 100644 --- a/pkg/channels/feishu/feishu_64.go +++ b/pkg/channels/feishu/feishu_64.go @@ -4,10 +4,11 @@ package feishu import ( "context" + "crypto/rand" "encoding/json" "fmt" "io" - "math/rand" + "math/big" "net/http" "os" "path/filepath" @@ -204,10 +205,15 @@ func (c *FeishuChannel) ReactToMessage(ctx context.Context, chatID, messageID st // Default to "Pin" if no config emojiList = []string{"Pin"} } - logger.Info(fmt.Sprintf("[MABEN] c.config.RandomReactionEmoji, %v", c.config.RandomReactionEmoji)) - // Randomly choose one from the list - chosenEmoji := emojiList[rand.Intn(len(emojiList))] + // Randomly choose one from the list using crypto/rand for better distribution + idx, err := rand.Int(rand.Reader, big.NewInt(int64(len(emojiList)))) + var chosenEmoji string + if err != nil { + chosenEmoji = emojiList[0] + } else { + chosenEmoji = emojiList[idx.Int64()] + } req := larkim.NewCreateMessageReactionReqBuilder(). MessageId(messageID).