Moved logging away for handling extarnally
This commit is contained in:
parent
599584ea58
commit
d797a52029
3
bot.go
3
bot.go
|
@ -21,9 +21,6 @@ type bot struct {
|
|||
|
||||
func DefaultHandler(u *Update) error {
|
||||
err := u.Bot.state.Call(u)
|
||||
if err != nil {
|
||||
u.LogError("", err, true)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -56,3 +56,18 @@ func (d *Dispatcher) HandleFilter(filter FilterFn, handler UpdateHandler) *Dispa
|
|||
d.handlers = append(d.handlers, newHandler)
|
||||
return d
|
||||
}
|
||||
|
||||
func (d *Dispatcher) HandleReply(handler UpdateHandler) *Dispatcher {
|
||||
newHandler := func(u *Update) (bool, error) {
|
||||
if !u.IsMessage() {
|
||||
return false, nil
|
||||
}
|
||||
if u.Message.ReplyToMessage == nil {
|
||||
return false, nil
|
||||
}
|
||||
err := handler(u)
|
||||
return true, err
|
||||
}
|
||||
d.handlers = append(d.handlers, newHandler)
|
||||
return d
|
||||
}
|
||||
|
|
24
filters.go
24
filters.go
|
@ -10,8 +10,32 @@ func TextStartsWith(text string) FilterFn {
|
|||
}
|
||||
}
|
||||
|
||||
func TextStartsWithAny(subs ...string) FilterFn {
|
||||
return func(u *Update) bool {
|
||||
text := u.Text()
|
||||
for _, sub := range subs {
|
||||
if strings.HasPrefix(text, sub) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func TextHas(text string) FilterFn {
|
||||
return func(u *Update) bool {
|
||||
return strings.Contains(u.Text(), text)
|
||||
}
|
||||
}
|
||||
|
||||
func TextHasAny(subs ...string) FilterFn {
|
||||
return func(u *Update) bool {
|
||||
text := u.Text()
|
||||
for _, sub := range subs {
|
||||
if strings.Contains(text, sub) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue