Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta362 #374

Merged
merged 28 commits into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions botstats/botstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func recordStats(receivedIncrement int, sentIncrement int) {

updateCounter(b, messageReceivedKey, receivedIncrement)
updateCounter(b, messageSentKey, sentIncrement)
b.Put([]byte(lastMessageTimeKey), []byte(today+" "+now.Format(time.RFC3339)))
// Ensure the time format is RFC3339 and only store date and time
b.Put([]byte(lastMessageTimeKey), []byte(now.Format(time.RFC3339)))

return nil
})
Expand Down Expand Up @@ -98,19 +99,13 @@ func getInt(b *bbolt.Bucket, key string) int {
}

func getLastMessageTime(b *bbolt.Bucket) int64 {
lastTimeBytes := b.Get([]byte("lastMessageTimeKey")) // 确保使用正确的键
lastTimeBytes := b.Get([]byte("lastMessageTime")) // 确保使用正确的键
if lastTimeBytes == nil {
return 0 // 如果键不存在或值为空,直接返回0
}

// 将字节切片转换为字符串,并尝试按空格分割
splitResult := strings.Split(string(lastTimeBytes), " ")
if len(splitResult) < 2 {
return 0 // 如果没有足够的分割结果,返回0
}

// 安全地解析时间
lastTime, err := time.Parse(time.RFC3339, splitResult[1])
lastTime, err := time.Parse(time.RFC3339, string(lastTimeBytes))
if err != nil {
return 0 // 如果解析时间出错,返回0
}
Expand Down
Loading