From 290e2837216dad92f10ac582698c5387f829bf66 Mon Sep 17 00:00:00 2001 From: Kirill Ivlev Date: Tue, 12 Nov 2024 21:40:25 +0400 Subject: [PATCH] TGD-35 --- src/bot/bot.update.ts | 35 ++++++++++++++++++++++++++++++++--- src/bot/scenes/quiz.scene.ts | 2 +- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/bot/bot.update.ts b/src/bot/bot.update.ts index 9b100f7..d70ae19 100644 --- a/src/bot/bot.update.ts +++ b/src/bot/bot.update.ts @@ -94,9 +94,32 @@ export class BotUpdate { } @On('callback_query') - async onInlineQuery(@Ctx() ctx: Context) { - console.log('callback query'); - console.log(ctx.callbackQuery); + async onInlineQuery(@Ctx() ctx: any) { + let data = undefined; + try { + data = JSON.parse(ctx.update.callback_query.data); + } catch(error) { + this.logger.verbose(`[onInlineQuery]: can't parse json callback, checking content for other payload`); + } + if(data) { + this.gameService.emit({ cmd: 'ApplyDebuff'}, { ...ctx.callbackQuery, from: ctx.from.id }); + await ctx.editMessageReplyMarkup(undefined); + await ctx.editMessageText("ответ принят!"); + } + if(ctx.update.callback_query.message.text.indexOf('Внимание') !== -1) { + const answer =ctx.update.callback_query.data; + this.gameService.emit({ cmd: "QuestionAnswer"}, { user: ctx.from.id, answer: answer, name: ctx.from.first_name }); + await ctx.editMessageReplyMarkup(undefined); + await ctx.editMessageText("ответ принят!"); + } else if(ctx.update.callback_query.data.startsWith('card/')) { + const cardtoplay = ctx.update.callback_query.data.substring('card/'.length); + this.gameService.emit({cmd: 'CardPlayed'}, {text: cardtoplay, user: ctx.update.callback_query.from.id}) + await ctx.editMessageReplyMarkup(undefined); + await ctx.editMessageText("карта выбрана"); + } else + { + //console.log(ctx.update); + } } @Hears(Messages.CHANGE_PHOTO) @@ -114,7 +137,13 @@ export class BotUpdate { ctx.scene.enter(QUIZ_SCENE, { answering: true}, false); } } + + @On("callback_query") + async onQuery(@Ctx() ctx: Context) { + console.log(ctx); + } } + /* diff --git a/src/bot/scenes/quiz.scene.ts b/src/bot/scenes/quiz.scene.ts index c8dadb8..1ebf907 100644 --- a/src/bot/scenes/quiz.scene.ts +++ b/src/bot/scenes/quiz.scene.ts @@ -50,7 +50,7 @@ export class QuizScene { @On('callback_query') async onInlineQuery(@Ctx() ctx: Context) { - this.gameService.emit({ cmd: 'ApplyDebuff'}, { ...ctx.callbackQuery, from: ctx.from.id }); + this.logger.verbose(`emit callback for ${ctx.callbackQuery}`); } @On('text')