mirror of
https://github.com/woodchen-ink/Q58Bot.git
synced 2025-07-18 13:52:07 +08:00
修复(service/binance.go): 优化币安服务定时价格更新,移除冗余代码,增强效率。
修复(service/guard.go): 优化消息过滤器,增强消息处理准确性,添加自动撤回及提示功能。
This commit is contained in:
parent
19c3b5ebd5
commit
6b4d776a89
@ -143,23 +143,17 @@ func sendPriceUpdate() {
|
|||||||
func RunBinance() {
|
func RunBinance() {
|
||||||
log.Println("Starting Binance service...")
|
log.Println("Starting Binance service...")
|
||||||
|
|
||||||
|
// 立即发送一次价格更新
|
||||||
sendPriceUpdate()
|
sendPriceUpdate()
|
||||||
|
|
||||||
var scheduleNextUpdate func()
|
ticker := time.NewTicker(1 * time.Minute)
|
||||||
scheduleNextUpdate = func() {
|
defer ticker.Stop()
|
||||||
now := time.Now().In(singaporeTZ)
|
|
||||||
nextHour := now.Add(time.Hour).Truncate(time.Hour)
|
|
||||||
duration := nextHour.Sub(now)
|
|
||||||
|
|
||||||
time.AfterFunc(duration, func() {
|
for range ticker.C {
|
||||||
|
now := time.Now().In(singaporeTZ)
|
||||||
|
if now.Minute() == 0 {
|
||||||
log.Println("Sending hourly price update...")
|
log.Println("Sending hourly price update...")
|
||||||
sendPriceUpdate()
|
sendPriceUpdate()
|
||||||
scheduleNextUpdate()
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduleNextUpdate()
|
|
||||||
|
|
||||||
// 保持主 goroutine 运行
|
|
||||||
select {}
|
|
||||||
}
|
}
|
||||||
|
@ -147,16 +147,20 @@ func processMessage(bot *tgbotapi.BotAPI, message *tgbotapi.Message, linkFilter
|
|||||||
if shouldFilter {
|
if shouldFilter {
|
||||||
log.Printf("Message should be filtered: %s", message.Text)
|
log.Printf("Message should be filtered: %s", message.Text)
|
||||||
if message.From.ID != core.ADMIN_ID {
|
if message.From.ID != core.ADMIN_ID {
|
||||||
|
// 删除原始消息
|
||||||
deleteMsg := tgbotapi.NewDeleteMessage(message.Chat.ID, message.MessageID)
|
deleteMsg := tgbotapi.NewDeleteMessage(message.Chat.ID, message.MessageID)
|
||||||
_, err := bot.Request(deleteMsg)
|
_, err := bot.Request(deleteMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to delete message: %v", err)
|
log.Printf("Failed to delete message: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 发送提示消息
|
||||||
notification := tgbotapi.NewMessage(message.Chat.ID, "已撤回该消息。注:一个链接不能发两次.")
|
notification := tgbotapi.NewMessage(message.Chat.ID, "已撤回该消息。注:一个链接不能发两次.")
|
||||||
sent, err := bot.Send(notification)
|
sent, err := bot.Send(notification)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to send notification: %v", err)
|
log.Printf("Failed to send notification: %v", err)
|
||||||
} else {
|
} else {
|
||||||
|
// 3分钟后删除提示消息
|
||||||
go deleteMessageAfterDelay(bot, message.Chat.ID, sent.MessageID, 3*time.Minute)
|
go deleteMessageAfterDelay(bot, message.Chat.ID, sent.MessageID, 3*time.Minute)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,5 +170,16 @@ func processMessage(bot *tgbotapi.BotAPI, message *tgbotapi.Message, linkFilter
|
|||||||
log.Printf("New non-whitelisted links found: %v", newLinks)
|
log.Printf("New non-whitelisted links found: %v", newLinks)
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckAndReplyPrompt(bot, message)
|
// 检查并回复提示词
|
||||||
|
if reply, found := GetPromptReply(message.Text); found {
|
||||||
|
replyMsg := tgbotapi.NewMessage(message.Chat.ID, reply)
|
||||||
|
replyMsg.ReplyToMessageID = message.MessageID
|
||||||
|
sent, err := bot.Send(replyMsg)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed to send prompt reply: %v", err)
|
||||||
|
} else {
|
||||||
|
// 3分钟后删除提示词回复
|
||||||
|
go deleteMessageAfterDelay(bot, message.Chat.ID, sent.MessageID, 3*time.Minute)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user