This commit is contained in:
Kirill Ivlev 2024-11-12 21:40:25 +04:00
parent 245651160e
commit 290e283721
2 changed files with 33 additions and 4 deletions

View file

@ -94,9 +94,32 @@ export class BotUpdate {
} }
@On('callback_query') @On('callback_query')
async onInlineQuery(@Ctx() ctx: Context) { async onInlineQuery(@Ctx() ctx: any) {
console.log('callback query'); let data = undefined;
console.log(ctx.callbackQuery); 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) @Hears(Messages.CHANGE_PHOTO)
@ -114,7 +137,13 @@ export class BotUpdate {
ctx.scene.enter(QUIZ_SCENE, { answering: true}, false); ctx.scene.enter(QUIZ_SCENE, { answering: true}, false);
} }
} }
@On("callback_query")
async onQuery(@Ctx() ctx: Context) {
console.log(ctx);
} }
}
/* /*

View file

@ -50,7 +50,7 @@ export class QuizScene {
@On('callback_query') @On('callback_query')
async onInlineQuery(@Ctx() ctx: Context) { async onInlineQuery(@Ctx() ctx: Context) {
this.gameService.emit({ cmd: 'ApplyDebuff'}, { ...ctx.callbackQuery, from: ctx.from.id });
this.logger.verbose(`emit callback for ${ctx.callbackQuery}`); this.logger.verbose(`emit callback for ${ctx.callbackQuery}`);
} }
@On('text') @On('text')