From c440a97ee35e065c42876e6ea83af3e15d52197f Mon Sep 17 00:00:00 2001 From: Edgar To Date: Sun, 16 Sep 2018 23:32:55 +0200 Subject: [PATCH] fix(select): dont call hide without key dont use hide to determine if action can be triggered. The hitSelectButton does it by itself while checking for the specific key. --- inline-menu.js | 1 - test/select.js | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/inline-menu.js b/inline-menu.js index a7910ff..beb75d9 100644 --- a/inline-menu.js +++ b/inline-menu.js @@ -285,7 +285,6 @@ class TelegrafInlineMenu { this.addHandler({ action: actionCodeBase.concat(/(.+)/), middleware: hitSelectButton, - hide: additionalArgs.hide, setMenuAfter: true }) diff --git a/test/select.js b/test/select.js index 11e998e..34d8c4e 100644 --- a/test/select.js +++ b/test/select.js @@ -213,3 +213,26 @@ test('hidden key can not be set', async t => { await bot.handleUpdate({callback_query: {data: 'a:b:c:a'}}) }) + +test('hide always has two args', async t => { + t.plan(2) + const menu = new TelegrafInlineMenu('foo') + menu.select('c', ['a', 'b'], { + setFunc: t.fail, + hide: (...args) => { + t.is(args.length, 2) + return false + } + }) + + const bot = new Telegraf() + bot.use(menu.init({actionCode: 'a:b'})) + + bot.context.editMessageText = () => Promise.resolve() + + // Calls hide for every option: +2 + await bot.handleUpdate({callback_query: {data: 'a:b'}}) + + // Does not call hide + await bot.handleUpdate({callback_query: {data: 'c'}}) +})