feat: treat quota limit of 0 as unlimited
All checks were successful
CI / build (push) Successful in 41s

Pre-check now skips periods where limit is 0, allowing users to have
unlimited quota by setting daily_limit_mb/weekly_limit_mb/monthly_limit_mb
to 0 in the database.
This commit is contained in:
2026-06-25 22:09:36 +03:30
parent f39e4e6fb0
commit 8bcb0094b2

View File

@@ -113,11 +113,13 @@ func (h *Handler) handleURLInput(ctx context.Context, chatID int64, text string,
return
}
// Reject if user has already exhausted quota (used >= limit) with a minimum threshold.
// Reject if user has already exhausted quota (limit of 0 = unlimited).
q, err := h.Repo.GetOrCreateQuotas(userID)
if err == nil {
q = h.resetQuotasIfNeeded(q)
if q.DailyUsedMB >= q.DailyLimitMB || q.WeeklyUsedMB >= q.WeeklyLimitMB || q.MonthlyUsedMB >= q.MonthlyLimitMB {
if (q.DailyLimitMB > 0 && q.DailyUsedMB >= q.DailyLimitMB) ||
(q.WeeklyLimitMB > 0 && q.WeeklyUsedMB >= q.WeeklyLimitMB) ||
(q.MonthlyLimitMB > 0 && q.MonthlyUsedMB >= q.MonthlyLimitMB) {
h.sendText(ctx, chatID, fmt.Sprintf(
"Quota exceeded. Daily: %d/%d MB, Weekly: %d/%d MB, Monthly: %d/%d MB.",
q.DailyUsedMB, q.DailyLimitMB, q.WeeklyUsedMB, q.WeeklyLimitMB, q.MonthlyUsedMB, q.MonthlyLimitMB))