la logique

This commit is contained in:
unintendedfraud
2024-04-05 23:17:27 +02:00
parent 4b24ae9369
commit a8d5baff5c
+8 -6
View File
@@ -135,6 +135,7 @@ func updateUserHistoryCount(userID string) bool {
u, ok := usersHistoryCount[userID] u, ok := usersHistoryCount[userID]
if !ok { if !ok {
fmt.Println("user does not exist")
usersHistoryCount[userID] = &userHistoryCount{ usersHistoryCount[userID] = &userHistoryCount{
date: now, date: now,
count: 1, count: 1,
@@ -143,24 +144,25 @@ func updateUserHistoryCount(userID string) bool {
return false return false
} }
usersHistoryCount[userID].count++ u.count++
if now.Before(u.bannedUntilAt) { if now.Before(u.bannedUntilAt) {
return true return true
} }
if !u.bannedUntilAt.IsZero() { if !u.bannedUntilAt.IsZero() {
usersHistoryCount[userID].bannedUntilAt = time.Time{} u.bannedUntilAt = time.Time{}
} }
if u.date.Add(SPAM_PERIOD).After(now) { if u.date.Add(SPAM_PERIOD).Before(now) {
usersHistoryCount[userID].count = 1 fmt.Println("date after spam period")
usersHistoryCount[userID].date = now u.count = 1
u.date = now
return false return false
} }
if u.count > 5 { if u.count > 5 {
usersHistoryCount[userID].bannedUntilAt = now.Add(2 * time.Minute) u.bannedUntilAt = now.Add(2 * time.Minute)
return true return true
} }