From 9a0f6a10904185a416093eebcba7f51283d4147d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=7E?= <158024940+xyy0411@users.noreply.github.com> Date: Sun, 13 Oct 2024 23:07:40 +0800 Subject: [PATCH] fix --- plugin/niuniu/utils.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index 1c649225a3..fcae4da6bf 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -6,6 +6,7 @@ import ( "math" "math/rand" "strings" + "time" ) var ( @@ -215,3 +216,35 @@ func contains(s string, array []string) bool { } return false } + +func randomChoice(options []string) string { + return options[rand.Intn(len(options))] +} + +func updateMap(t string, d bool) { + value, ok := prop.Load(t) + if value == nil { + return + } + // 检查一次是否已经过期 + if !d { + if time.Since(value.TimeLimit) > time.Minute*8 { + prop.Delete(t) + } + return + } + if ok { + prop.Store(t, &propsCount{ + Count: value.Count + 1, + TimeLimit: value.TimeLimit, + }) + } else { + prop.Store(t, &propsCount{ + Count: 1, + TimeLimit: time.Now(), + }) + } + if time.Since(value.TimeLimit) > time.Minute*8 { + prop.Delete(t) + } +}