From a8d5baff5c9426d2f8b113b7d44b48c4b5fe491a Mon Sep 17 00:00:00 2001 From: unintendedfraud Date: Fri, 5 Apr 2024 23:17:27 +0200 Subject: [PATCH] la logique --- handlers/message_created.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/handlers/message_created.go b/handlers/message_created.go index 4217509..1dae80b 100644 --- a/handlers/message_created.go +++ b/handlers/message_created.go @@ -135,6 +135,7 @@ func updateUserHistoryCount(userID string) bool { u, ok := usersHistoryCount[userID] if !ok { + fmt.Println("user does not exist") usersHistoryCount[userID] = &userHistoryCount{ date: now, count: 1, @@ -143,24 +144,25 @@ func updateUserHistoryCount(userID string) bool { return false } - usersHistoryCount[userID].count++ + u.count++ if now.Before(u.bannedUntilAt) { return true } if !u.bannedUntilAt.IsZero() { - usersHistoryCount[userID].bannedUntilAt = time.Time{} + u.bannedUntilAt = time.Time{} } - if u.date.Add(SPAM_PERIOD).After(now) { - usersHistoryCount[userID].count = 1 - usersHistoryCount[userID].date = now + if u.date.Add(SPAM_PERIOD).Before(now) { + fmt.Println("date after spam period") + u.count = 1 + u.date = now return false } if u.count > 5 { - usersHistoryCount[userID].bannedUntilAt = now.Add(2 * time.Minute) + u.bannedUntilAt = now.Add(2 * time.Minute) return true }