fix(feishu): 用 crypto/rand 选择随机表情并修正示例配置
This commit is contained in:
parent
b15cff1266
commit
6aa1d02fff
2 changed files with 11 additions and 5 deletions
|
|
@ -12,7 +12,7 @@
|
||||||
# Feishu (飞书)
|
# Feishu (飞书)
|
||||||
# PICOCLAW_CHANNELS_FEISHU_APP_ID=cli_xxx
|
# PICOCLAW_CHANNELS_FEISHU_APP_ID=cli_xxx
|
||||||
# PICOCLAW_CHANNELS_FEISHU_APP_SECRET=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) ────────────────
|
# ── Web Search (optional) ────────────────
|
||||||
# BRAVE_SEARCH_API_KEY=BSA...
|
# BRAVE_SEARCH_API_KEY=BSA...
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,11 @@ package feishu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/rand"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/big"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -204,10 +205,15 @@ func (c *FeishuChannel) ReactToMessage(ctx context.Context, chatID, messageID st
|
||||||
// Default to "Pin" if no config
|
// Default to "Pin" if no config
|
||||||
emojiList = []string{"Pin"}
|
emojiList = []string{"Pin"}
|
||||||
}
|
}
|
||||||
logger.Info(fmt.Sprintf("[MABEN] c.config.RandomReactionEmoji, %v", c.config.RandomReactionEmoji))
|
|
||||||
|
|
||||||
// Randomly choose one from the list
|
// Randomly choose one from the list using crypto/rand for better distribution
|
||||||
chosenEmoji := emojiList[rand.Intn(len(emojiList))]
|
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().
|
req := larkim.NewCreateMessageReactionReqBuilder().
|
||||||
MessageId(messageID).
|
MessageId(messageID).
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue