Add throttler for bot
Signed-off-by: adithyagenie <adithyagenie@gmail.com>
This commit is contained in:
parent
a5d82b03e7
commit
5c1ffd5fd5
3 changed files with 24 additions and 1 deletions
|
@ -19,7 +19,8 @@
|
||||||
"fastify": "^4.27.0",
|
"fastify": "^4.27.0",
|
||||||
"grammy": "^1.24.1",
|
"grammy": "^1.24.1",
|
||||||
"leetcode-query": "^1.2.3",
|
"leetcode-query": "^1.2.3",
|
||||||
"node-schedule": "^2.1.1"
|
"node-schedule": "^2.1.1",
|
||||||
|
"@grammyjs/transformer-throttler": "^1.2.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@grammyjs/types": "^3.8.0",
|
"@grammyjs/types": "^3.8.0",
|
||||||
|
|
|
@ -11,6 +11,9 @@ importers:
|
||||||
'@grammyjs/parse-mode':
|
'@grammyjs/parse-mode':
|
||||||
specifier: ^1.10.0
|
specifier: ^1.10.0
|
||||||
version: 1.10.0(grammy@1.24.1)
|
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:
|
codeforces-api-ts:
|
||||||
specifier: ^3.0.1
|
specifier: ^3.0.1
|
||||||
version: 3.0.1
|
version: 3.0.1
|
||||||
|
@ -75,6 +78,12 @@ packages:
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
grammy: ^1.20.1
|
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':
|
'@grammyjs/types@3.8.0':
|
||||||
resolution: {integrity: sha512-5r2rUJ/s939iQEt6j2gyl1owbWwKAYAg2gQH7FfWIP1swL2assZ97vRUl8cBU3UEp7es9c/VioWeQjKbV6g4eg==}
|
resolution: {integrity: sha512-5r2rUJ/s939iQEt6j2gyl1owbWwKAYAg2gQH7FfWIP1swL2assZ97vRUl8cBU3UEp7es9c/VioWeQjKbV6g4eg==}
|
||||||
|
|
||||||
|
@ -126,6 +135,9 @@ packages:
|
||||||
base64-js@1.5.1:
|
base64-js@1.5.1:
|
||||||
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
|
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
|
||||||
|
|
||||||
|
bottleneck@2.19.5:
|
||||||
|
resolution: {integrity: sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw==}
|
||||||
|
|
||||||
buffer@6.0.3:
|
buffer@6.0.3:
|
||||||
resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==}
|
resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==}
|
||||||
|
|
||||||
|
@ -473,6 +485,11 @@ snapshots:
|
||||||
dependencies:
|
dependencies:
|
||||||
grammy: 1.24.1
|
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': {}
|
'@grammyjs/types@3.8.0': {}
|
||||||
|
|
||||||
'@types/node-fetch@2.6.11':
|
'@types/node-fetch@2.6.11':
|
||||||
|
@ -520,6 +537,8 @@ snapshots:
|
||||||
|
|
||||||
base64-js@1.5.1: {}
|
base64-js@1.5.1: {}
|
||||||
|
|
||||||
|
bottleneck@2.19.5: {}
|
||||||
|
|
||||||
buffer@6.0.3:
|
buffer@6.0.3:
|
||||||
dependencies:
|
dependencies:
|
||||||
base64-js: 1.5.1
|
base64-js: 1.5.1
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
import { Bot, Context } from "grammy";
|
import { Bot, Context } from "grammy";
|
||||||
import { parseMode, ParseModeFlavor } from "@grammyjs/parse-mode";
|
import { parseMode, ParseModeFlavor } from "@grammyjs/parse-mode";
|
||||||
import { helpCommand, messageSink, setCommands, startCommand } from "./commands/miscCommands";
|
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 const bot = new Bot<ParseModeFlavor<Context>>(`${process.env.BOT_TOKEN}`);
|
||||||
export type myBot = Bot<ParseModeFlavor<Context>>;
|
export type myBot = Bot<ParseModeFlavor<Context>>;
|
||||||
|
|
||||||
export async function botInit() {
|
export async function botInit() {
|
||||||
|
const throttler = apiThrottler();
|
||||||
|
bot.api.config.use(throttler);
|
||||||
bot.api.config.use(parseMode("HTML"));
|
bot.api.config.use(parseMode("HTML"));
|
||||||
setCommands(bot);
|
setCommands(bot);
|
||||||
bot.hears(/^\/start/, async(ctx) => await startCommand(ctx));
|
bot.hears(/^\/start/, async(ctx) => await startCommand(ctx));
|
||||||
|
|
Loading…
Reference in a new issue