From 6b89af3ed810a0b0fecd14516e6c60d9b79d4369 Mon Sep 17 00:00:00 2001 From: SanaeFox <36219542+Hoshinonyaruko@users.noreply.github.com> Date: Thu, 8 Aug 2024 14:39:53 +0800 Subject: [PATCH] Beta476 (#480) * beta447 * beta448 * beta449 * beta450 * beta451 * beta452 * beta453 * beta454 * beta455 * btea455 * beta456 * beta457 * beta458 * beta460 * beta460 * beta461 * beta462 * beta463 * beta464 * beta465 * beta467 * beta468 * beta469 * beta470 * beta471 * beta472 * beta473 * beta473 * beta475 * beta476 --- botgo/event/event.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/botgo/event/event.go b/botgo/event/event.go index e4c094e6..90b0326a 100644 --- a/botgo/event/event.go +++ b/botgo/event/event.go @@ -2,12 +2,34 @@ package event import ( "encoding/json" + "sync" + "time" "github.com/tidwall/gjson" // 由于回包的 d 类型不确定,gjson 用于从回包json中提取 d 并进行针对性的解析 "github.com/tencent-connect/botgo/dto" ) +func init() { + // Start a goroutine for periodic cleaning + go cleanProcessedIDs() +} + +func cleanProcessedIDs() { + ticker := time.NewTicker(5 * time.Minute) // Adjust the interval as needed + defer ticker.Stop() + + for range ticker.C { + // Clean processedIDs, remove entries which are no longer needed + processedIDs.Range(func(key, value interface{}) bool { + processedIDs.Delete(key) + return true + }) + } +} + +var processedIDs sync.Map + var eventParseFuncMap = map[dto.OPCode]map[dto.EventType]eventParseFunc{ dto.WSDispatchEvent: { dto.EventGuildCreate: guildHandler, @@ -218,6 +240,9 @@ func groupAtMessageHandler(payload *dto.WSPayload, message []byte) error { if err := ParseData(message, data); err != nil { return err } + if _, loaded := processedIDs.LoadOrStore(data.ID, struct{}{}); loaded { + return nil + } if DefaultHandlers.GroupATMessage != nil { return DefaultHandlers.GroupATMessage(payload, data) }