ratelimit

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Enforce

func Enforce(l *Limiter, rule Rule) middleware.Middleware

func Inject

func Inject(l *Limiter) middleware.Middleware

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine(l *Limiter) *Engine

func (*Engine) AddRule

func (e *Engine) AddRule(rule Rule)

func (*Engine) Limiter

func (e *Engine) Limiter() *Limiter

func (*Engine) Middleware

func (e *Engine) Middleware() middleware.Middleware

type Limiter

type Limiter struct {
	// contains filtered or unexported fields
}

func NewLimiter

func NewLimiter() *Limiter

func (*Limiter) Allow

func (l *Limiter) Allow(action, key string, limit int, window time.Duration) (bool, time.Duration)

Allow returns whether the action is allowed and retry-after duration when denied.

type Rule

type Rule struct {
	Action     string
	Limit      int
	Window     time.Duration
	Scope      Scope
	Command    string
	Callback   string
	KeyFunc    func(*botctx.Context) string
	OnDenyText string
	OnlyType   event.Type
}

type Scope

type Scope string
const (
	ScopeUser     Scope = "user"
	ScopeChat     Scope = "chat"
	ScopeCommand  Scope = "command"
	ScopeCallback Scope = "callback"
	ScopeGlobal   Scope = "global"
	ScopeCustom   Scope = "custom"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL