Skip to content

Commit

Permalink
Beta476 (#480)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Hoshinonyaruko authored Aug 8, 2024
1 parent 820c5b5 commit 6b89af3
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions botgo/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 6b89af3

Please sign in to comment.