README
telegraf-rate-limiter
Description
Multilingual utilities for telegraf.
Installation
npm i @riddea/telegraf-rate-limiter
Use
import { RateLimiter } from "@riddea/telegraf-rate-limiter";
import { Telegraf } from "telegraf";
// Import RateLimiter package
import { RateLimiter } from "@riddea/telegraf-rate-limiter";
// Put your bot token from @BotFather
const bot = new Telegraf("");
// Set 1 message per 2 second
const rateLimiter = new RateLimiter(1, 2000);
bot.on("message", async (ctx) => {
// Take user ID and check member have rate limit or no
const limited = rateLimiter.take(ctx.from.id);
// Send message if member has limit
if (limited) return await ctx.reply("Hey! Wait 2 second before send new message!");
// Doing other if member don't have limits
await ctx.reply("Hello!");
});
bot.launch();
// Enable graceful stop
process.once("SIGINT", () => bot.stop("SIGINT"));
process.once("SIGTERM", () => bot.stop("SIGTERM"));
Example
Contributing
This project opened for contribution! You can create a new Pull request
with your code changes.
LICENSE
This code has MIT license. See the LICENSE
file for getting more information.
Ogirinal code take from discord.js-rate-limiter