Skip to content

Commit

Permalink
add 'HandlerTypeCallbackQueryGameShortName'
Browse files Browse the repository at this point in the history
  • Loading branch information
oanhnn committed Aug 19, 2024
1 parent b3b73e9 commit 5083421
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
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")
}
}

0 comments on commit 5083421

Please sign in to comment.