add question command & handler
This commit is contained in:
parent
457554e952
commit
9177d1fc16
8 changed files with 50 additions and 5 deletions
|
|
@ -9,4 +9,5 @@ export class CommandsConsts {
|
|||
static GetCards = 'GetCards';
|
||||
static ApplyDebuff = 'ApplyDebuff';
|
||||
static CompleteQueue = 'CompleteQueue';
|
||||
static GetQuestion = 'GetQuestion';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {}
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Reference in a new issue