forked from PaulSonOfLars/gotgbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callbackquery.go
42 lines (33 loc) · 927 Bytes
/
callbackquery.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package handlers
import (
"fmt"
"github.com/asvedr/gotgbot/v2"
"github.com/asvedr/gotgbot/v2/ext"
"github.com/asvedr/gotgbot/v2/ext/handlers/filters"
)
type CallbackQuery struct {
AllowChannel bool
Filter filters.CallbackQuery
Response Response
}
func NewCallback(filter filters.CallbackQuery, r Response) CallbackQuery {
return CallbackQuery{
Filter: filter,
Response: r,
}
}
func (cb CallbackQuery) HandleUpdate(b *gotgbot.Bot, ctx *ext.Context) error {
return cb.Response(b, ctx)
}
func (cb CallbackQuery) CheckUpdate(b *gotgbot.Bot, ctx *ext.Context) bool {
if ctx.CallbackQuery == nil {
return false
}
if !cb.AllowChannel && ctx.CallbackQuery.Message != nil && ctx.CallbackQuery.Message.Chat.Type == "channel" {
return false
}
return cb.Filter == nil || cb.Filter(ctx.CallbackQuery)
}
func (cb CallbackQuery) Name() string {
return fmt.Sprintf("inlinequery_%p", cb.Response)
}