Add throttler for bot

Signed-off-by: adithyagenie <adithyagenie@gmail.com>
This commit is contained in:
adithyagenie 2024-06-16 00:33:06 +05:30
parent a5d82b03e7
commit 5c1ffd5fd5
Signed by: adithyagenie
GPG key ID: C66E41599E458D96
3 changed files with 24 additions and 1 deletions

View file

@ -19,7 +19,8 @@
"fastify": "^4.27.0",
"grammy": "^1.24.1",
"leetcode-query": "^1.2.3",
"node-schedule": "^2.1.1"
"node-schedule": "^2.1.1",
"@grammyjs/transformer-throttler": "^1.2.1"
},
"devDependencies": {
"@grammyjs/types": "^3.8.0",

View file

@ -11,6 +11,9 @@ importers:
'@grammyjs/parse-mode':
specifier: ^1.10.0
version: 1.10.0(grammy@1.24.1)
'@grammyjs/transformer-throttler':
specifier: ^1.2.1
version: 1.2.1(grammy@1.24.1)
codeforces-api-ts:
specifier: ^3.0.1
version: 3.0.1
@ -75,6 +78,12 @@ packages:
peerDependencies:
grammy: ^1.20.1
'@grammyjs/transformer-throttler@1.2.1':
resolution: {integrity: sha512-CpWB0F3rJdUiKsq7826QhQsxbZi4wqfz1ccKX+fr+AOC+o8K7ZvS+wqX0suSu1QCsyUq2MDpNiKhyL2ZOJUS4w==}
engines: {node: ^12.20.0 || >=14.13.1}
peerDependencies:
grammy: ^1.0.0
'@grammyjs/types@3.8.0':
resolution: {integrity: sha512-5r2rUJ/s939iQEt6j2gyl1owbWwKAYAg2gQH7FfWIP1swL2assZ97vRUl8cBU3UEp7es9c/VioWeQjKbV6g4eg==}
@ -126,6 +135,9 @@ packages:
base64-js@1.5.1:
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
bottleneck@2.19.5:
resolution: {integrity: sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw==}
buffer@6.0.3:
resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==}
@ -473,6 +485,11 @@ snapshots:
dependencies:
grammy: 1.24.1
'@grammyjs/transformer-throttler@1.2.1(grammy@1.24.1)':
dependencies:
bottleneck: 2.19.5
grammy: 1.24.1
'@grammyjs/types@3.8.0': {}
'@types/node-fetch@2.6.11':
@ -520,6 +537,8 @@ snapshots:
base64-js@1.5.1: {}
bottleneck@2.19.5: {}
buffer@6.0.3:
dependencies:
base64-js: 1.5.1

View file

@ -1,12 +1,15 @@
import { Bot, Context } from "grammy";
import { parseMode, ParseModeFlavor } from "@grammyjs/parse-mode";
import { helpCommand, messageSink, setCommands, startCommand } from "./commands/miscCommands";
import { apiThrottler } from "@grammyjs/transformer-throttler";
export const bot = new Bot<ParseModeFlavor<Context>>(`${process.env.BOT_TOKEN}`);
export type myBot = Bot<ParseModeFlavor<Context>>;
export async function botInit() {
const throttler = apiThrottler();
bot.api.config.use(throttler);
bot.api.config.use(parseMode("HTML"));
setCommands(bot);
bot.hears(/^\/start/, async(ctx) => await startCommand(ctx));