Skip to content

Commit

Permalink
Merge pull request #29 from gabeklavans/feature/inline-score-popup
Browse files Browse the repository at this point in the history
feat(bot): default callback_query just echo its data
  • Loading branch information
gabeklavans authored Jun 22, 2024
2 parents 07bb609 + 71cb9f4 commit 917be69
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ bot.on("callback_query:game_short_name", async (ctx) => {
}
});

// Use the default callback handler to just display its text data.
// So far, it just displays the score of the player whose button was clicked.
bot.on("callback_query:data", (ctx) => {
ctx.answerCallbackQuery({
text: ctx.callbackQuery.data,
cache_time: 24 * 60 * 60, // 1 day
});
});

bot.on("inline_query", (ctx) => {
const query = ctx.inlineQuery.query;
ctx.answerInlineQuery(
Expand All @@ -64,9 +73,9 @@ bot.on("inline_query", (ctx) => {
type: "game",
id: idx.toString(),
game_short_name: shortName,
reply_markup: startingInlineKeyboard
reply_markup: startingInlineKeyboard,
};
})
}),
).catch(console.error);
});

Expand All @@ -79,7 +88,7 @@ function searchGames(query?: string) {
return GAME_LIST.map((game) => game.shortName);
} else {
return GAME_LIST.filter((game) => game.name.toLocaleLowerCase().includes(query.toLocaleLowerCase())).map(
(game) => game.shortName
(game) => game.shortName,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function updateInlineKeyboard(gameSession: GameSession) {
if (idx === 0 && Object.values(gameSession.players).filter((p) => p.done).length >= 2) {
inlineText += " 🏆";
}
inlineKeyboard.text(inlineText);
inlineKeyboard.text(inlineText, player.score ? player.score.toString() : "waiting...");
if (idx % 2 == 1) inlineKeyboard.row();
});

Expand Down

0 comments on commit 917be69

Please sign in to comment.