TGD-35
This commit is contained in:
parent
9177d1fc16
commit
456cdcb4aa
8 changed files with 39 additions and 27 deletions
|
|
@ -10,4 +10,5 @@ export class CommandsConsts {
|
|||
static ApplyDebuff = 'ApplyDebuff';
|
||||
static CompleteQueue = 'CompleteQueue';
|
||||
static GetQuestion = 'GetQuestion';
|
||||
static QuestionAnswer = "QuestionAnswer";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,7 +197,6 @@ export class BanPlayer extends GameCard {
|
|||
eventBus.publish(new CardsSetChangedEvent(sourceUser.telegramId));
|
||||
})
|
||||
eventBus.pipe(ofType(NextQuestionEvent)).subscribe(async (r)=> {
|
||||
this.logger.verbose(`next event`);
|
||||
const players = await queryBus.execute(new FilterGuestsWithPropertyQuery(DebuffsConsts.bannedFor, '$gt', 0))
|
||||
this.logger.verbose(`enter: ban card handler, banned players count ${players.length}`);
|
||||
players.map(async (player) => {
|
||||
|
|
|
|||
|
|
@ -28,13 +28,16 @@ export class TgPostCardsToUserCommandHandler implements ICommandHandler<PostCard
|
|||
},
|
||||
}
|
||||
if (command.cards.length === 0) {
|
||||
this.telegramService.emit({ cmd: CommandsConsts.SendMessage }, { chatId: command.chatId, message: "У вас нет карт которые можно сейчас использовать"});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
command.cards.forEach((card) => {
|
||||
extra.reply_markup.keyboard.push([
|
||||
{text: Messages.EMOJI_CARD + ' ' + card},
|
||||
]);
|
||||
extra_Inline.reply_markup.inline_keyboard.push([{ text: Messages.EMOJI_CARD + ' ' + card}])
|
||||
extra_Inline.reply_markup.inline_keyboard.push([{ text: Messages.EMOJI_CARD + ' ' + card, callback_data: `card/${card}`}])
|
||||
});
|
||||
await this.sharedService.setConfig(`buttons_${command.chatId}`,
|
||||
JSON.stringify(extra),
|
||||
|
|
|
|||
|
|
@ -96,12 +96,18 @@ export class GuestsService {
|
|||
const extra = {
|
||||
reply_markup: {
|
||||
keyboard: [],
|
||||
inline_keyboard: [],
|
||||
},
|
||||
};
|
||||
questionDto.answers.forEach((item, index) => {
|
||||
extra.reply_markup.keyboard.push([
|
||||
{ text: this.nums[index] + ' ' + item },
|
||||
]);
|
||||
// extra.reply_markup.keyboard.push([
|
||||
// { text: this.nums[index] + ' ' + item },
|
||||
// ]);
|
||||
if(item !== null){
|
||||
extra.reply_markup.inline_keyboard.push(
|
||||
[ { text: item, callback_data: `${item.substring(0,50)}` },
|
||||
]);
|
||||
}
|
||||
});
|
||||
if (!targetId) {
|
||||
guests.forEach((guest) => {
|
||||
|
|
|
|||
|
|
@ -64,4 +64,5 @@ export class GuestsMessageController {
|
|||
async getQuestion(@Payload() data: { user: number, inline: false}) {
|
||||
await this.quizService.displayQuestionForUser(data.user);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,4 +2,10 @@ export interface ValidateAnswerModel {
|
|||
answer: string;
|
||||
user: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface ValidateAnswerInline {
|
||||
answer: string;
|
||||
user: number;
|
||||
name: string;
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import {Controller, Logger} from "@nestjs/common";
|
||||
import {MessagePattern, Payload} from "@nestjs/microservices";
|
||||
import {CommandsConsts} from "../Consts/commands.consts";
|
||||
import {ValidateAnswerModel} from "./models/validate-answer.model";
|
||||
import {ValidateAnswerInline, ValidateAnswerModel} from "./models/validate-answer.model";
|
||||
import {QuizAnsweredEvent} from "../game/events/quiz.answered";
|
||||
import {QuizService} from "../quiz/quiz.service";
|
||||
import {CommandBus, EventBus} from "@nestjs/cqrs";
|
||||
|
|
@ -15,11 +15,12 @@ export class QuizMessagingController {
|
|||
constructor(private quizService: QuizService, private eventBus: EventBus, private cmdBus: CommandBus, private gameService: GameService) {
|
||||
}
|
||||
|
||||
@MessagePattern({ cmd: CommandsConsts.ValidateAnswer})
|
||||
async validateAnswer(@Payload() data: ValidateAnswerModel) {
|
||||
|
||||
@MessagePattern({ cmd: CommandsConsts.QuestionAnswer})
|
||||
async getQuestionAnswer(@Payload() data: ValidateAnswerInline) {
|
||||
this.logger.verbose(`Validate answer ${data}`);
|
||||
this.eventBus.publish(new QuizAnsweredEvent(data.name));
|
||||
const result = await this.quizService.validateAnswer(
|
||||
const result = await this.quizService.validateAnswerInline(
|
||||
data.answer,
|
||||
data.user,
|
||||
);
|
||||
|
|
@ -36,7 +37,7 @@ export class QuizMessagingController {
|
|||
@MessagePattern({ cmd: CommandsConsts.GetCards})
|
||||
async getCardsForUser(@Payload() data: { user: number, inline: boolean}) {
|
||||
this.logger.verbose(`getCardsForUser ${data}`);
|
||||
await this.cmdBus.execute(new SendBetweenRoundsActionsCommand(data.user, data.inline))
|
||||
await this.cmdBus.execute(new SendBetweenRoundsActionsCommand(data.user, true))
|
||||
}
|
||||
|
||||
@MessagePattern({ cmd: CommandsConsts.ApplyDebuff})
|
||||
|
|
|
|||
|
|
@ -55,25 +55,20 @@ export class QuizService {
|
|||
return item.save();
|
||||
}
|
||||
|
||||
|
||||
async validateAnswer(answer: string, id: number) {
|
||||
this.logger.verbose(`enter validate answer ${answer} ${id}`);
|
||||
async validateAnswerInline(answer:string, id: number) {
|
||||
this.logger.verbose(`[validateAnswer] enter ${answer} ${id}`);
|
||||
const question = await this.get();
|
||||
await question.save();
|
||||
const regexp = new RegExp(
|
||||
Object.keys(this.answerNumbers)
|
||||
.map((x) => {
|
||||
x = this.answerNumbers[x].replace('.', '.').replace(' ', ' ');
|
||||
return x;
|
||||
})
|
||||
.join('|'),
|
||||
'gi',
|
||||
);
|
||||
this.logger.verbose(
|
||||
`Validating answer for question: ${JSON.stringify(question.text)}`,
|
||||
);
|
||||
const filtered = answer.replace(regexp, '').trim();
|
||||
const isAnswerValid = question.valid === filtered;
|
||||
// check that answer exist
|
||||
const shortAnswers = question.answers.map((answer) => answer.substring(0,50));
|
||||
const shortValidAnswer = question.valid.substring(0,50);
|
||||
if(shortAnswers.indexOf(answer) === -1) {
|
||||
this.logger.warn(`[validateAnswer] this question is not on game now`);
|
||||
return;
|
||||
}
|
||||
const isAnswerValid = shortValidAnswer === answer;
|
||||
if(question.userAnswers.find(answer => answer.user === id)) {
|
||||
this.logger.verbose("question->user answer is already containing record");
|
||||
return;
|
||||
|
|
@ -85,11 +80,11 @@ export class QuizService {
|
|||
})
|
||||
await question.save();
|
||||
this.logger.verbose("question saved with user details")
|
||||
if (question.valid === filtered) {
|
||||
if (shortValidAnswer=== answer) {
|
||||
question.answeredBy = id;
|
||||
this.logger.verbose(`extra ${question.note}`);
|
||||
this.eventBus.publish(
|
||||
new ValidAnswerReceivedEvent(id, filtered, question.note),
|
||||
new ValidAnswerReceivedEvent(id, answer, question.note),
|
||||
);
|
||||
await question.save();
|
||||
await this.markQuestionStorageAsAnsweredCorrectly(question.text);
|
||||
|
|
|
|||
Loading…
Reference in a new issue