Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@libtelegram/helpers

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@libtelegram/helpers

AntiFlood middleware for LibTelegram

  • 0.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

anti-flood Coverage Status

LibTelegram AntiFlood middleware

Learn about the hitting limits in Telegram Bots API.

Installation

You can install this package by the following command.

npm install @libtelegram/anti-flood

API

const antiFlood = require('@libtelegram/anti-flood');

The antiFlood object exposes various factories to create middlewares

antiFlood.omission(options[, callback])

The omission function skips the message if the time elapsed since the previous message is less than a delay

function callback(usr, msg) {
  usr.reply('Too many messages');
}

bot.use(antiFlood.omission({ delay: 1 / 2 }, callback));
options

The omission function takes an options object that may contain any of the following keys:

delay

The minimum time interval between messages in seconds

Defaults to 0.5.

callback

Callback to be called after too many messages are detected

callback has a signature of (usr, msg).

antiFlood.penalty(options[, callback])

function callback(usr, msg) {
  usr.reply('You won\'t be able to use the bot for 2 minutes');
}

bot.use(antiFlood.penalty({
  maxAttempts: 3,
  timeLimit: 2,
  timeBlocked: 2 * 60,
}, callback));
options

The penalty function takes an options object that may contain any of the following keys:

maxAttempts

The maximum number of requests from a user for a given time limit. After exceeding the number of attempts, the bot will not respond to user messages

Defaults to 5.

timeLimit

The time in seconds during which the counter of attempts is added.

Defaults to 2.

timeBlocked

The time in seconds for which the user will be blocked

Defaults to 60.

callback

Callback to be called after user is blocked

callback has a signature of (usr, msg).

License

MIT

Keywords

FAQs

Package last updated on 31 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc