Skip to content

Commit

Permalink
Merge 5bdffb8 into 9f34b5a
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoshinonyaruko authored May 29, 2024
2 parents 9f34b5a + 5bdffb8 commit d5b603d
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions handlers/send_private_msg_sse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"sync"

"github.com/hoshinonyaruko/gensokyo/callapi"
"github.com/hoshinonyaruko/gensokyo/config"
Expand All @@ -15,36 +16,34 @@ import (
"github.com/tencent-connect/botgo/openapi"
)

var msgIDToIndex = make(map[string]int)
var msgIDToRelatedID = make(map[string]string)
var msgIDToIndex sync.Map
var msgIDToRelatedID sync.Map

func init() {
callapi.RegisterHandler("send_private_msg_sse", HandleSendPrivateMsgSSE)
}

func incrementIndex(msgID string) int {
if _, exists := msgIDToIndex[msgID]; !exists {
msgIDToIndex[msgID] = 0 // 初始化为0
actual, loaded := msgIDToIndex.LoadOrStore(msgID, 0)
if !loaded {
return 0
}
msgIDToIndex[msgID]++ // 递增Index
return msgIDToIndex[msgID]
newVal := actual.(int) + 1
msgIDToIndex.Store(msgID, newVal)
return newVal
}

func UpdateRelatedID(MessageID, ID string) {
msgIDToRelatedID.Store(MessageID, ID)
}

// GetRelatedID 根据MessageID获取相关的ID
func GetRelatedID(MessageID string) string {
if relatedID, exists := msgIDToRelatedID[MessageID]; exists {
return relatedID
if relatedID, ok := msgIDToRelatedID.Load(MessageID); ok {
return relatedID.(string)
}
// 如果没有找到转换关系,返回空字符串
return ""
}

// UpdateRelatedID 更新MessageID到respID的映射关系
func UpdateRelatedID(MessageID, ID string) {
msgIDToRelatedID[MessageID] = ID
}

func HandleSendPrivateMsgSSE(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.OpenAPI, message callapi.ActionMessage) (string, error) {
// 使用 message.Echo 作为key来获取消息类型
var retmsg string
Expand Down

0 comments on commit d5b603d

Please sign in to comment.