Update tokens.nim

This commit is contained in:
drpepper66666 2023-07-04 18:45:02 +02:00 committed by GitHub
parent ec46eaa400
commit b94c35325e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -65,12 +65,12 @@ proc rateLimitError*(): ref RateLimitError =
newException(RateLimitError, "rate limited")
proc fetchToken(): Future[Token] {.async.} =
let eligibleBearerTokens = bearerTokens
var eligibleBearerTokens = bearerTokens
.filter(proc (x: string): bool = not failedBearerTokens.hasKey(x) or getTime() - failedBearerTokens[x] >= failDelay)
if len(eligibleBearerTokens) == 0:
echo "[tokens] all bearer tokens failed recently"
raise rateLimitError()
eligibleBearerTokens = bearerTokens.toSeq()
let auth = sample(eligibleBearerTokens)
log "using token " & auth