Skip to content

Commit

Permalink
Merge branch 'main' into beta137
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoshinonyaruko authored Jan 23, 2024
2 parents f6931f7 + 4a88413 commit 44f8dcb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions echo/messageidmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,39 @@ func GetLazyMessagesIdv2(groupID, userID string) string {
return randomMessageID
}

// GetLazyMessagesIdv2 获取指定群号和用户ID中最近5分钟内的 message_id
func GetLazyMessagesIdv2(groupID, userID string) string {

Check failure on line 127 in echo/messageidmap.go

View workflow job for this annotation

GitHub Actions / Build on linux for amd64

GetLazyMessagesIdv2 redeclared in this block

Check failure on line 127 in echo/messageidmap.go

View workflow job for this annotation

GitHub Actions / Build on linux for 386

GetLazyMessagesIdv2 redeclared in this block

Check failure on line 127 in echo/messageidmap.go

View workflow job for this annotation

GitHub Actions / Build on linux for arm

GetLazyMessagesIdv2 redeclared in this block

Check failure on line 127 in echo/messageidmap.go

View workflow job for this annotation

GitHub Actions / Build on linux for arm64

GetLazyMessagesIdv2 redeclared in this block

Check failure on line 127 in echo/messageidmap.go

View workflow job for this annotation

GitHub Actions / Build on darwin for amd64

GetLazyMessagesIdv2 redeclared in this block

Check failure on line 127 in echo/messageidmap.go

View workflow job for this annotation

GitHub Actions / Build on darwin for arm64

GetLazyMessagesIdv2 redeclared in this block

Check failure on line 127 in echo/messageidmap.go

View workflow job for this annotation

GitHub Actions / Build on windows for amd64

GetLazyMessagesIdv2 redeclared in this block

Check failure on line 127 in echo/messageidmap.go

View workflow job for this annotation

GitHub Actions / Build on windows for 386

GetLazyMessagesIdv2 redeclared in this block
store := initInstance()
store.mu.RLock()
defer store.mu.RUnlock()

// 构建复合键
key := groupID + "." + userID

fiveMinutesAgo := time.Now().Add(-5 * time.Minute)
var recentMessages []string
for _, record := range store.records[key] {
if record.timestamp.After(fiveMinutesAgo) {
recentMessages = append(recentMessages, record.messageID)
}
}

var randomMessageID string
if len(recentMessages) > 0 {
randomIndex := rand.Intn(len(recentMessages))
randomMessageID = recentMessages[randomIndex]
} else {
// 如果没有找到最近消息,处理默认行为
msgType := GetMessageTypeByGroupidv2(config.GetAppIDStr(), groupID)
if strings.HasPrefix(msgType, "guild") {
randomMessageID = "1000" // 频道主动信息
} else {
randomMessageID = ""
}
}
return randomMessageID
}

// 通过group_id获取类型
func GetMessageTypeByGroupidv2(appID string, GroupID interface{}) string {
// 从appID和userID生成key
Expand Down

0 comments on commit 44f8dcb

Please sign in to comment.