diff --git a/src/nim_censor_bot.nim b/src/nim_censor_bot.nim index 6c6d1bc..12715d4 100644 --- a/src/nim_censor_bot.nim +++ b/src/nim_censor_bot.nim @@ -61,13 +61,13 @@ func NewBannedUsers*(userid = int64(0), bantime = 0.0, bantype = ""): dbConn.createTables(NewCensoredData()) dbConn.createTables(NewBannedUsers()) -# Ratelimits a user if there is more than 20 timestamps within 60 secs. +# Ratelimits a user if there is more than 30 timestamps within 60 secs. # Resets their ratelimit counter if 60s has passed since first timestamp proc ManageRateLimit(): void= for i in RateLimiter.keys().toSeq(): if RateLimiter[i][^1] - RateLimiter[i][0] >= 60: RateLimiter.del(i) - elif len(RateLimiter[i]) >= 20: + elif len(RateLimiter[i]) >= 30: var BannedUser = NewBannedUsers(i, epochTime(), "auto") RateLimiter.del(i) with dbConn: @@ -103,10 +103,11 @@ proc startHandler(b: Telebot, c: Command): Future[bool] {.gcsafe, async.} = ManageRateLimit() if not dbConn.exists(BannedUsers, "userid = ?", c.message.chat.id): # Update rate-limit counter - if RateLimiter.contains(c.message.chat.id): - RateLimiter[c.message.chat.id].insert(epochTime()) - else: - RateLimiter[c.message.chat.id] = @[epochTime()] + if not AdminID.contains($c.message.chat.id): + if RateLimiter.contains(c.message.chat.id): + RateLimiter[c.message.chat.id].insert(epochTime()) + else: + RateLimiter[c.message.chat.id] = @[epochTime()] if param == "": discard await b.sendMessage(c.message.chat.id, "Hey, To create a censored post, you can share any album, video, photo, gif, sticker, etc. " & @@ -145,10 +146,11 @@ proc sourceHandler(b: Telebot, c: Command): Future[bool] {.gcsafe, async.} = ManageRateLimit() if not dbConn.exists(BannedUsers, "userid = ?", c.message.chat.id): # Update rate-limit counter - if RateLimiter.contains(c.message.chat.id): - RateLimiter[c.message.chat.id].insert(epochTime()) - else: - RateLimiter[c.message.chat.id] = @[epochTime()] + if not AdminID.contains($c.message.chat.id): + if RateLimiter.contains(c.message.chat.id): + RateLimiter[c.message.chat.id].insert(epochTime()) + else: + RateLimiter[c.message.chat.id] = @[epochTime()] discard await b.sendMessage(c.message.chat.id, "Hey, this bot is open-source and licensed under AGPL-v3! " & "\n\nYou are welcome to selfhost your own instance of this bot" & @@ -216,10 +218,11 @@ proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} = # Dont bother about rate-limited/banned users if not dbConn.exists(BannedUsers, "userid = ?", response.chat.id): # Update rate-limit counter - if RateLimiter.contains(response.chat.id): - RateLimiter[response.chat.id].insert(epochTime()) - else: - RateLimiter[response.chat.id] = @[epochTime()] + if not AdminID.contains($response.chat.id): + if RateLimiter.contains(response.chat.id): + RateLimiter[response.chat.id].insert(epochTime()) + else: + RateLimiter[response.chat.id] = @[epochTime()] if not response.text.isSome: var fileid = "" var ftype = ""