1
1
mirror of https://gitlab.com/ceda_ei/Quadnite-Bot synced 2026-05-06 05:40:04 +02:00

feat: add rate limiter middleware

Signed-off-by: Sphericalkat <me@kat.bio>
This commit is contained in:
Sphericalkat
2024-09-30 10:39:07 +05:30
parent 80a0dbd2d3
commit 8274ab0980
4 changed files with 23 additions and 1 deletions

10
bot.js
View File

@@ -1,12 +1,20 @@
const { Telegraf } = require("telegraf");
const { BOT_API_KEY, FEEDBACK_ID, UGOKI_ROOT } = process.env;
const { BOT_API_KEY, FEEDBACK_ID, UGOKI_ROOT, RATE_TIMEFRAME, RATE_LIMIT } = process.env;
const fs = require("fs").promises;
const commands = require("./commands");
const axios = require("axios");
const roleplay = require("./static/roleplay.json");
const { limit } = require("@grammyjs/ratelimiter");
const bot = new Telegraf(BOT_API_KEY);
bot.catch((err) => console.log(err));
bot.use(limit({
// default config: 5 messages per 5 seconds
timeFrame: RATE_TIMEFRAME ?? 5000,
limit: RATE_LIMIT ?? 5,
onLimitExceeded: (ctx, next) => ctx.reply('Too many requests!'),
}))
const data = [
"questions",