Skip to content

A simple-to-use Golang library for gotgbot to rate-limit users and avoid spamming requests to your Telegram bot.

License

Notifications You must be signed in to change notification settings

AnimeKaizoku/ratelimiter

Repository files navigation

Rate Limiter - gotgbot

ratelimiter-Logo

Name: Rate Limiter
Version: v1.0.7
Edit: 2 Feb 2021
By: ALiwoto and Contributors (C)

Go Reference Go-linux Go-macos Go-windows


How to use

import "github.com/AnimeKaizoku/ratelimiter/ratelimiter"


func loadLimiter(d *ext.Dispatcher) {
	limiter = ratelimiter.NewLimiter(d, &ratelimiter.LimiterConfig{
		ConsiderChannel:  false,
		ConsiderUser:     true,
		ConsiderEdits:    false,
		IgnoreMediaGroup: true,
		TextOnly:         false,
		HandlerGroups:    []int{0, 1, 2},
	})

	// 14 messages per 6 seconds
	limiter.SetFloodWaitTime(6 * time.Second)
	limiter.SetMaxMessageCount(14)

	// add sudo users as exceptions, so they don't get rate-limited by library
	limiter.AddExceptionID(sudoUsers...)

	limiter.Start()
}

Helpful links:

About

A simple-to-use Golang library for gotgbot to rate-limit users and avoid spamming requests to your Telegram bot.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages