Documentation
¶
Overview ¶
Package middleware provides common middleware implementations for maxbot.
Index ¶
- func AutoRespond() maxbot.MiddlewareFunc
- func Blacklist(userIDs ...int64) maxbot.MiddlewareFunc
- func Chain(middleware ...maxbot.MiddlewareFunc) maxbot.MiddlewareFunc
- func CommandArgs(min int, usage string) maxbot.MiddlewareFunc
- func FilterWords(words []string, caseSensitive bool) maxbot.MiddlewareFunc
- func IgnoreBots() maxbot.MiddlewareFunc
- func Logger() maxbot.MiddlewareFunc
- func OnlyGroups() maxbot.MiddlewareFunc
- func OnlyPrivate() maxbot.MiddlewareFunc
- func RateLimit(max int, window time.Duration) maxbot.MiddlewareFunc
- func Recover(onPanic ...func(error)) maxbot.MiddlewareFunc
- func RestrictChatType(types ...string) maxbot.MiddlewareFunc
- func Throttle(d time.Duration) maxbot.MiddlewareFunc
- func Whitelist(userIDs ...int64) maxbot.MiddlewareFunc
- type Metrics
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 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) Middleware ¶
func (m *Metrics) Middleware() maxbot.MiddlewareFunc
Middleware returns a middleware function that collects metrics.