From b2c7728d0635f7493d86a071a5a2dedd6be42d35 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Sat, 30 Dec 2023 17:29:28 +0700 Subject: [PATCH] use command instead of hears --- src/index.ts | 2 +- src/service/telegram/index.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 10a2ad5..ad73ce3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,7 +30,7 @@ async function main() { await httpApi.listen(); await telegramApi.probe(); - telegram.hears(/\/roll(.*)/, roll); + telegram.hears("roll", roll); logger.info("bot successfully started"); } catch (e) { diff --git a/src/service/telegram/index.ts b/src/service/telegram/index.ts index 143c617..f38eb27 100644 --- a/src/service/telegram/index.ts +++ b/src/service/telegram/index.ts @@ -162,12 +162,12 @@ export class TelegramService { }; public hears = ( - what: string | RegExp, + command: string, callback: ( text: string ) => string | Promise | undefined | void ) => - this.bot.hears(what, async (ctx) => { + this.bot.command(command, async (ctx) => { let text: string | void | undefined = "%% not received %%"; try { @@ -191,7 +191,7 @@ export class TelegramService { ctx.reply(text, { parse_mode: "MarkdownV2" }); } catch (error) { console.warn( - `error replying to ${what} (${ctx.update.message.text}) with message "${text}"`, + `error replying to ${command} (${ctx.update.message.text}) with message "${text}"`, error ); }