mirror of
https://github.com/woodchen-ink/Q58Bot.git
synced 2025-07-18 05:42:06 +08:00
币对价格消息触发器改为完全匹配, 不区分大小写
This commit is contained in:
parent
5f63a202b4
commit
2af6b41866
@ -22,7 +22,8 @@
|
||||
|
||||
### 虚拟币价格实时获取
|
||||
- 从币安获取所有交易对, 缓存到内存里, 每小时刷新一次
|
||||
- 当群消息触及关键词时, 会返回对应虚拟币/USDT的价格
|
||||
- 当群消息为虚拟币名称时, 会返回对应虚拟币/USDT的价格
|
||||
- 例如,如果用户发送 "BTC"、"btc" 或 "Btc",都会触发比特币的价格信息发送,但发送 "What's the price of BTC?" 则不会触发。
|
||||
|
||||
### 链接拦截
|
||||
- 新增: 当非管理员时, 才会进行链接拦截
|
||||
|
@ -61,10 +61,14 @@ func StartSymbolRefresh(interval time.Duration) {
|
||||
// HandleSymbolQuery 处理虚拟币名查询
|
||||
func HandleSymbolQuery(bot *tgbotapi.BotAPI, message *tgbotapi.Message) {
|
||||
symbols := GetAllSymbols()
|
||||
upperMsg := strings.ToUpper(message.Text)
|
||||
msg := strings.TrimSpace(message.Text)
|
||||
|
||||
for _, symbol := range symbols {
|
||||
if strings.Contains(upperMsg, strings.TrimSuffix(symbol, "USDT")) {
|
||||
// 移除USDT后缀
|
||||
coinName := strings.TrimSuffix(symbol, "USDT")
|
||||
|
||||
// 不区分大小写的完全匹配检查
|
||||
if strings.EqualFold(msg, coinName) {
|
||||
info, err := getTickerInfo(symbol)
|
||||
if err != nil {
|
||||
log.Printf("Error getting ticker info for %s: %v", symbol, err)
|
||||
@ -74,9 +78,9 @@ func HandleSymbolQuery(bot *tgbotapi.BotAPI, message *tgbotapi.Message) {
|
||||
info.symbol,
|
||||
info.last,
|
||||
formatChange(info.changePercent))
|
||||
msg := tgbotapi.NewMessage(message.Chat.ID, replyMessage)
|
||||
msg.ParseMode = "Markdown"
|
||||
bot.Send(msg)
|
||||
replyMsg := tgbotapi.NewMessage(message.Chat.ID, replyMessage)
|
||||
replyMsg.ParseMode = "Markdown"
|
||||
bot.Send(replyMsg)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user