Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] add 'HandlerTypeCallbackQueryGameShortName' #108

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type HandlerType int
const (
HandlerTypeMessageText HandlerType = iota
HandlerTypeCallbackQueryData
HandlerTypeCallbackQueryGameShortName
)

type MatchType int
Expand Down Expand Up @@ -46,6 +47,8 @@ func (h handler) match(update *models.Update) bool {
data = update.Message.Text
case HandlerTypeCallbackQueryData:
data = update.CallbackQuery.Data
case HandlerTypeCallbackQueryGameShortName:
data = update.CallbackQuery.GameShortName
}

if h.matchType == MatchTypeExact {
Expand Down
23 changes: 23 additions & 0 deletions handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,26 @@ func TestBot_RegisterUnregisterHandler(t *testing.T) {
t.Fatalf("handler not found")
}
}

func Test_match_exact_game(t *testing.T) {
b := &Bot{
handlersMx: &sync.RWMutex{},
handlers: map[string]handler{},
}

id := b.RegisterHandler(HandlerTypeCallbackQueryGameShortName, "xxx", MatchTypeExact, nil)

h := b.handlers[id]
u := models.Update{
ID: 42,
CallbackQuery: &models.CallbackQuery{
ID: "1000",
GameShortName: "xxx",
},
}

res := h.match(&u)
if !res {
t.Error("unexpected true result")
}
}
Loading