diff --git a/src/Consts/commands.consts.ts b/src/Consts/commands.consts.ts index feb6b6d..fc65d8e 100644 --- a/src/Consts/commands.consts.ts +++ b/src/Consts/commands.consts.ts @@ -9,4 +9,5 @@ export class CommandsConsts { static GetCards = 'GetCards'; static ApplyDebuff = 'ApplyDebuff'; static CompleteQueue = 'CompleteQueue'; + static GetQuestion = 'GetQuestion'; } diff --git a/src/game/game.controller.ts b/src/game/game.controller.ts index 5726cf9..a451301 100644 --- a/src/game/game.controller.ts +++ b/src/game/game.controller.ts @@ -37,4 +37,9 @@ export class GameController { this.logger.verbose('[SimulateVersus] enter'); return this.gameService.simulateVersus(); } + + @Get('state-details') + async getStateDetails() { + return this.gameService.getStateDetails(); + } } diff --git a/src/game/game.service.ts b/src/game/game.service.ts index 3a367bd..759382b 100644 --- a/src/game/game.service.ts +++ b/src/game/game.service.ts @@ -130,9 +130,20 @@ export class GameService implements OnApplicationBootstrap{ } async beginVersus(player1: number, player2: number) { + await this.sharedService.setConfig('current_action', JSON.stringify({ + action:'versus', + data: { + player1: player1, + player2: player2, + } + })); this.sharedService.sendSocketNotificationToAllClients( SocketEvents.BEGIN_VERSUS, { player1, player2 } ) } + + async getStateDetails() { + return await this.sharedService.getConfig('current_action') || null; + } } diff --git a/src/guests/guests.module.ts b/src/guests/guests.module.ts index 5b5de11..8964c88 100644 --- a/src/guests/guests.module.ts +++ b/src/guests/guests.module.ts @@ -1,4 +1,4 @@ -import { Module } from '@nestjs/common'; +import {forwardRef, Module} from '@nestjs/common'; import { GuestsService } from './guests.service'; import { MongooseModule } from '@nestjs/mongoose'; import { Guest, GuestSchema } from '../schemas/guest.schema'; @@ -23,9 +23,12 @@ import {GetGuestPropertyHandler} from "./command/get-guest-property.handler"; import {QueryHandlers } from "./queries"; import {SetGuestPropertyCommandHandler} from "./command/handlers/set-guest-property.handler"; import {WrongAnswerReceivedGuestEventHandler} from "./event-handlers/wrong-answer-received-guest-event.handler"; -import {VoiceService} from "../voice/voice.service"; + import {VoiceModule} from "../voice/voice.module"; import {IncreasePlayerScoreCommandHandler} from "./command/handlers/increase-player-score-command.handler"; +import {QuizService} from "../quiz/quiz.service"; +import {QuizModule} from "../quiz/quiz.module"; + const commandHandlers = [ GuestsRemoveKeyboardHandler, @@ -62,7 +65,7 @@ const eventHandlers = [ CardsModule, ], providers: [GuestsService, ConfigService, ...commandHandlers,...QueryHandlers, ...eventHandlers, ], - exports: [GuestsService], + exports: [GuestsService,], controllers: [GuestsController], }) export class GuestsModule {} diff --git a/src/guests/guests.service.ts b/src/guests/guests.service.ts index dfe0cc0..cf3078e 100644 --- a/src/guests/guests.service.ts +++ b/src/guests/guests.service.ts @@ -28,6 +28,7 @@ import {VoiceService} from "../voice/voice.service"; import {screpaDictManyInvalidAnswersDict} from "../voice/dicts/screpa-dict-many-invalid-answers.dict"; import {GuestPropertiesConsts} from "../schemas/properties.consts"; import {GuestNamesInCases} from "./guest.types"; +import {QuizService} from "../quiz/quiz.service"; @Injectable() export class GuestsService { @@ -87,6 +88,9 @@ export class GuestsService { this.logger.verbose(`Keyboard hidden`); } + + + async postQuestion(questionDto: QuestionDto, targetId = null) { const guests = await this.findAll(); const extra = { diff --git a/src/messaging/guests.controller.ts b/src/messaging/guests.controller.ts index 49adfd6..049160a 100644 --- a/src/messaging/guests.controller.ts +++ b/src/messaging/guests.controller.ts @@ -9,12 +9,13 @@ import {CommandsConsts} from "../Consts/commands.consts"; import {EventBus} from "@nestjs/cqrs"; import {PlayerCardSelectedEvent} from "../game/events/player-card-selected.event"; import {getCard} from "../helpers/card-parser"; +import {QuizService} from "../quiz/quiz.service"; @Controller() export class GuestsMessageController { private readonly logger = new Logger(GuestsMessageController.name); - constructor(private guestService: GuestsService, private sharedService: SharedService, private eventBus: EventBus) { + constructor(private guestService: GuestsService, private sharedService: SharedService, private eventBus: EventBus, private quizService: QuizService) { } @MessagePattern({ cmd: 'GuestInfo'} ) async getGuestInformation(@Payload() data: GetGuestInfoModel, @Ctx() context: RmqContext) { @@ -58,4 +59,9 @@ export class GuestsMessageController { ); return; } + + @MessagePattern({ cmd: CommandsConsts.GetQuestion}) + async getQuestion(@Payload() data: { user: number, inline: false}) { + await this.quizService.displayQuestionForUser(data.user); + } } \ No newline at end of file diff --git a/src/quiz/quiz.service.ts b/src/quiz/quiz.service.ts index d4f93eb..269cc4b 100644 --- a/src/quiz/quiz.service.ts +++ b/src/quiz/quiz.service.ts @@ -55,6 +55,7 @@ export class QuizService { return item.save(); } + async validateAnswer(answer: string, id: number) { this.logger.verbose(`enter validate answer ${answer} ${id}`); const question = await this.get(); @@ -299,4 +300,17 @@ export class QuizService { const question = await this.get(); return question.userAnswers; } + + async displayQuestionForUser(telegramId: number) { + const question = await this.get(); + const dto: QuestionDto = { + id: question.id, + text: question.text, + answers: question.answers, + valid: question.valid, + note: question.note, + qId: question.qId, + } + await this.guestService.postQuestion(dto, telegramId); + } } diff --git a/src/state/state.controller.ts b/src/state/state.controller.ts index 7cf564c..b06fa96 100644 --- a/src/state/state.controller.ts +++ b/src/state/state.controller.ts @@ -40,7 +40,8 @@ export class StateController { { cmd: CommandsConsts.SetCommands }, [ { command: 'start', description: 'главное меню'}, - { command: 'cards', description: 'сыграть карту'} + { command: 'cards', description: 'сыграть карту'}, + { command: 'question', description: 'вернутся к вопросу'} ] ).subscribe(() => { this.logger.verbose('Bot commands updated');