From b2ce91acc788b3c08eb66f5234673ec164cebdfc Mon Sep 17 00:00:00 2001 From: Demian Date: Thu, 6 Aug 2020 22:13:11 +0300 Subject: [PATCH] bot: add global-scope Use function --- bot.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bot.go b/bot.go index 82613ad..98eddc1 100644 --- a/bot.go +++ b/bot.go @@ -55,6 +55,7 @@ func NewBot(pref Settings) (*Bot, error) { bot.Me = user } + bot.group = bot.Group() return bot, nil } @@ -67,6 +68,7 @@ type Bot struct { Poller Poller OnError func(error, Context) + group *Group handlers map[string]HandlerFunc synchronous bool verbose bool @@ -139,6 +141,11 @@ type Command struct { Description string `json:"description"` } +// Use adds middleware to the global bot chain. +func (b *Bot) Use(middleware ...MiddlewareFunc) { + b.group.Use(middleware...) +} + // Group returns a new group. func (b *Bot) Group() *Group { return &Group{b: b}