From 6f8231df77c99b7102544d7af2cb8f0193d5a3cb Mon Sep 17 00:00:00 2001 From: Oanh Nguyen Date: Mon, 16 Sep 2024 15:16:03 +0700 Subject: [PATCH] add 'HandlerTypeCallbackQueryGameShortName' (#108) --- handlers.go | 3 +++ handlers_test.go | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/handlers.go b/handlers.go index 7dbd063..2d356c0 100644 --- a/handlers.go +++ b/handlers.go @@ -12,6 +12,7 @@ type HandlerType int const ( HandlerTypeMessageText HandlerType = iota HandlerTypeCallbackQueryData + HandlerTypeCallbackQueryGameShortName ) type MatchType int @@ -53,6 +54,8 @@ func (h handler) match(update *models.Update) bool { return false } data = update.CallbackQuery.Data + case HandlerTypeCallbackQueryGameShortName: + data = update.CallbackQuery.GameShortName } if h.matchType == MatchTypeExact { diff --git a/handlers_test.go b/handlers_test.go index b9aee70..a054140 100644 --- a/handlers_test.go +++ b/handlers_test.go @@ -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") + } +}