middleware

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package middleware provides common middleware implementations for maxbot.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoRespond

func AutoRespond() maxbot.MiddlewareFunc

AutoRespond automatically responds to callback queries.

func Blacklist

func Blacklist(userIDs ...int64) maxbot.MiddlewareFunc

Blacklist blocks specified users.

func Chain

func Chain(middleware ...maxbot.MiddlewareFunc) maxbot.MiddlewareFunc

Chain combines multiple middleware into one.

func CommandArgs

func CommandArgs(min int, usage string) maxbot.MiddlewareFunc

CommandArgs ensures command has minimum number of arguments.

func FilterWords

func FilterWords(words []string, caseSensitive bool) maxbot.MiddlewareFunc

FilterWords filters messages containing banned words.

func IgnoreBots

func IgnoreBots() maxbot.MiddlewareFunc

IgnoreBots ignores messages from bots.

func Logger

func Logger() maxbot.MiddlewareFunc

Logger logs all incoming updates with timing information.

func OnlyGroups

func OnlyGroups() maxbot.MiddlewareFunc

OnlyGroups allows handler only in group chats.

func OnlyPrivate

func OnlyPrivate() maxbot.MiddlewareFunc

OnlyPrivate allows handler only in private chats.

func RateLimit

func RateLimit(max int, window time.Duration) maxbot.MiddlewareFunc

RateLimit limits requests per user per time window.

func Recover

func Recover(onPanic ...func(error)) maxbot.MiddlewareFunc

Recover recovers from panics in handlers.

func RestrictChatType

func RestrictChatType(types ...string) maxbot.MiddlewareFunc

RestrictChatType restricts handler to specific chat types.

func Throttle

func Throttle(d time.Duration) maxbot.MiddlewareFunc

Throttle limits handler execution to once per duration per user.

func Whitelist

func Whitelist(userIDs ...int64) maxbot.MiddlewareFunc

Whitelist allows only specified users.

Types

type Metrics

type Metrics struct {
	TotalMessages   int64
	TotalCallbacks  int64
	UniqueUsers     map[int64]bool
	CommandsUsed    map[string]int64
	AverageResponse time.Duration
}

Metrics collects basic metrics about bot usage.

func (*Metrics) GetStats

func (m *Metrics) GetStats() string

GetStats returns formatted statistics.

func (*Metrics) Middleware

func (m *Metrics) Middleware() maxbot.MiddlewareFunc

Middleware returns a middleware function that collects metrics.

Jump to

Keyboard shortcuts

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