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 GetCards = 'GetCards';
|
||||||
static ApplyDebuff = 'ApplyDebuff';
|
static ApplyDebuff = 'ApplyDebuff';
|
||||||
static CompleteQueue = 'CompleteQueue';
|
static CompleteQueue = 'CompleteQueue';
|
||||||
|
static GetQuestion = 'GetQuestion';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,4 +37,9 @@ export class GameController {
|
||||||
this.logger.verbose('[SimulateVersus] enter');
|
this.logger.verbose('[SimulateVersus] enter');
|
||||||
return this.gameService.simulateVersus();
|
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) {
|
async beginVersus(player1: number, player2: number) {
|
||||||
|
await this.sharedService.setConfig('current_action', JSON.stringify({
|
||||||
|
action:'versus',
|
||||||
|
data: {
|
||||||
|
player1: player1,
|
||||||
|
player2: player2,
|
||||||
|
}
|
||||||
|
}));
|
||||||
this.sharedService.sendSocketNotificationToAllClients(
|
this.sharedService.sendSocketNotificationToAllClients(
|
||||||
SocketEvents.BEGIN_VERSUS,
|
SocketEvents.BEGIN_VERSUS,
|
||||||
{ player1, player2 }
|
{ 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 { GuestsService } from './guests.service';
|
||||||
import { MongooseModule } from '@nestjs/mongoose';
|
import { MongooseModule } from '@nestjs/mongoose';
|
||||||
import { Guest, GuestSchema } from '../schemas/guest.schema';
|
import { Guest, GuestSchema } from '../schemas/guest.schema';
|
||||||
|
|
@ -23,9 +23,12 @@ import {GetGuestPropertyHandler} from "./command/get-guest-property.handler";
|
||||||
import {QueryHandlers } from "./queries";
|
import {QueryHandlers } from "./queries";
|
||||||
import {SetGuestPropertyCommandHandler} from "./command/handlers/set-guest-property.handler";
|
import {SetGuestPropertyCommandHandler} from "./command/handlers/set-guest-property.handler";
|
||||||
import {WrongAnswerReceivedGuestEventHandler} from "./event-handlers/wrong-answer-received-guest-event.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 {VoiceModule} from "../voice/voice.module";
|
||||||
import {IncreasePlayerScoreCommandHandler} from "./command/handlers/increase-player-score-command.handler";
|
import {IncreasePlayerScoreCommandHandler} from "./command/handlers/increase-player-score-command.handler";
|
||||||
|
import {QuizService} from "../quiz/quiz.service";
|
||||||
|
import {QuizModule} from "../quiz/quiz.module";
|
||||||
|
|
||||||
|
|
||||||
const commandHandlers = [
|
const commandHandlers = [
|
||||||
GuestsRemoveKeyboardHandler,
|
GuestsRemoveKeyboardHandler,
|
||||||
|
|
@ -62,7 +65,7 @@ const eventHandlers = [
|
||||||
CardsModule,
|
CardsModule,
|
||||||
],
|
],
|
||||||
providers: [GuestsService, ConfigService, ...commandHandlers,...QueryHandlers, ...eventHandlers, ],
|
providers: [GuestsService, ConfigService, ...commandHandlers,...QueryHandlers, ...eventHandlers, ],
|
||||||
exports: [GuestsService],
|
exports: [GuestsService,],
|
||||||
controllers: [GuestsController],
|
controllers: [GuestsController],
|
||||||
})
|
})
|
||||||
export class GuestsModule {}
|
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 {screpaDictManyInvalidAnswersDict} from "../voice/dicts/screpa-dict-many-invalid-answers.dict";
|
||||||
import {GuestPropertiesConsts} from "../schemas/properties.consts";
|
import {GuestPropertiesConsts} from "../schemas/properties.consts";
|
||||||
import {GuestNamesInCases} from "./guest.types";
|
import {GuestNamesInCases} from "./guest.types";
|
||||||
|
import {QuizService} from "../quiz/quiz.service";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GuestsService {
|
export class GuestsService {
|
||||||
|
|
@ -87,6 +88,9 @@ export class GuestsService {
|
||||||
this.logger.verbose(`Keyboard hidden`);
|
this.logger.verbose(`Keyboard hidden`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async postQuestion(questionDto: QuestionDto, targetId = null) {
|
async postQuestion(questionDto: QuestionDto, targetId = null) {
|
||||||
const guests = await this.findAll();
|
const guests = await this.findAll();
|
||||||
const extra = {
|
const extra = {
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,13 @@ import {CommandsConsts} from "../Consts/commands.consts";
|
||||||
import {EventBus} from "@nestjs/cqrs";
|
import {EventBus} from "@nestjs/cqrs";
|
||||||
import {PlayerCardSelectedEvent} from "../game/events/player-card-selected.event";
|
import {PlayerCardSelectedEvent} from "../game/events/player-card-selected.event";
|
||||||
import {getCard} from "../helpers/card-parser";
|
import {getCard} from "../helpers/card-parser";
|
||||||
|
import {QuizService} from "../quiz/quiz.service";
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
export class GuestsMessageController {
|
export class GuestsMessageController {
|
||||||
private readonly logger = new Logger(GuestsMessageController.name);
|
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'} )
|
@MessagePattern({ cmd: 'GuestInfo'} )
|
||||||
async getGuestInformation(@Payload() data: GetGuestInfoModel, @Ctx() context: RmqContext) {
|
async getGuestInformation(@Payload() data: GetGuestInfoModel, @Ctx() context: RmqContext) {
|
||||||
|
|
@ -58,4 +59,9 @@ export class GuestsMessageController {
|
||||||
);
|
);
|
||||||
return;
|
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();
|
return item.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async validateAnswer(answer: string, id: number) {
|
async validateAnswer(answer: string, id: number) {
|
||||||
this.logger.verbose(`enter validate answer ${answer} ${id}`);
|
this.logger.verbose(`enter validate answer ${answer} ${id}`);
|
||||||
const question = await this.get();
|
const question = await this.get();
|
||||||
|
|
@ -299,4 +300,17 @@ export class QuizService {
|
||||||
const question = await this.get();
|
const question = await this.get();
|
||||||
return question.userAnswers;
|
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 },
|
{ cmd: CommandsConsts.SetCommands },
|
||||||
[
|
[
|
||||||
{ command: 'start', description: 'главное меню'},
|
{ command: 'start', description: 'главное меню'},
|
||||||
{ command: 'cards', description: 'сыграть карту'}
|
{ command: 'cards', description: 'сыграть карту'},
|
||||||
|
{ command: 'question', description: 'вернутся к вопросу'}
|
||||||
]
|
]
|
||||||
).subscribe(() => {
|
).subscribe(() => {
|
||||||
this.logger.verbose('Bot commands updated');
|
this.logger.verbose('Bot commands updated');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue