Removed command handler

This commit is contained in:
nefrace 2023-01-24 01:12:19 +03:00
parent d797a52029
commit 906c769453
1 changed files with 2 additions and 7 deletions

View File

@ -6,7 +6,6 @@ import (
type UpdateHandler func(u *Update) error type UpdateHandler func(u *Update) error
type dispatchHandler func(u *Update) (bool, error) type dispatchHandler func(u *Update) (bool, error)
type commandHandler func(u *UpdateCommand) error
type Dispatcher struct { type Dispatcher struct {
handlers []dispatchHandler handlers []dispatchHandler
@ -26,7 +25,7 @@ func (d *Dispatcher) Run(u *Update) error {
return nil return nil
} }
func (d *Dispatcher) HandleCommand(command *Command, handler commandHandler) *Dispatcher { func (d *Dispatcher) HandleCommand(command *Command, handler UpdateHandler) *Dispatcher {
newHandler := func(u *Update) (bool, error) { newHandler := func(u *Update) (bool, error) {
if !strings.HasPrefix(u.Text(), command.String()) { if !strings.HasPrefix(u.Text(), command.String()) {
return false, nil return false, nil
@ -34,11 +33,7 @@ func (d *Dispatcher) HandleCommand(command *Command, handler commandHandler) *Di
if command.IsAdminOnly && !u.IsUserAdmin() && u.ChatID() < 0 { if command.IsAdminOnly && !u.IsUserAdmin() && u.ChatID() < 0 {
return false, nil return false, nil
} }
upd := &UpdateCommand{ err := handler(u)
Update: *u,
Param: command.Param(u.Text()),
}
err := handler(upd)
return true, err return true, err
} }
d.handlers = append(d.handlers, newHandler) d.handlers = append(d.handlers, newHandler)