Skip to content

Commit

Permalink
Add handler helpers (#133)
Browse files Browse the repository at this point in the history
* Add handler helpers

* add necessary docs
  • Loading branch information
PaulSonOfLars authored Jan 19, 2024
1 parent a17e75b commit a61db17
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ext/handlers/callbackquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ func NewCallback(filter filters.CallbackQuery, r Response) CallbackQuery {
}
}

// SetAllowChannel Enables channel messages for this handler.
func (cb CallbackQuery) SetAllowChannel(allow bool) CallbackQuery {
cb.AllowChannel = allow
return cb
}

func (cb CallbackQuery) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error {
return cb.Response(b, ctx)
}
Expand Down
12 changes: 12 additions & 0 deletions ext/handlers/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ func NewCommand(c string, r Response) Command {
}
}

// SetAllowEdited Enables edited messages for this handler.
func (c Command) SetAllowEdited(allow bool) Command {
c.AllowEdited = allow
return c
}

// SetAllowChannel Enables channel messages for this handler.
func (c Command) SetAllowChannel(allow bool) Command {
c.AllowChannel = allow
return c
}

func (c Command) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool {
if ctx.Message != nil {
if ctx.Message.Text == "" && ctx.Message.Caption == "" {
Expand Down
12 changes: 12 additions & 0 deletions ext/handlers/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ func NewMessage(f filters.Message, r Response) Message {
}
}

// SetAllowEdited Enables edited messages for this handler.
func (m Message) SetAllowEdited(allow bool) Message {
m.AllowEdited = allow
return m
}

// SetAllowChannel Enables channel messages for this handler.
func (m Message) SetAllowChannel(allow bool) Message {
m.AllowChannel = allow
return m
}

func (m Message) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool {
if ctx.Message != nil {
return m.Filter == nil || m.Filter(ctx.Message)
Expand Down

0 comments on commit a61db17

Please sign in to comment.