Skip to content

Commit

Permalink
fix: player treshold setting (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc authored Feb 9, 2021
1 parent 330e399 commit ce92507
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/discord/services/queue-prompts.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe('QueuePromptsService', () => {

describe('when slots change again', () => {
beforeEach(async () => {
events.queueSlotsChange.next({ slots: [
queueService.slots = [
{ id: 0, gameClass: Tf2ClassName.scout, playerId: players[0].id, ready: false },
{ id: 1, gameClass: Tf2ClassName.scout, playerId: null, ready: false },
{ id: 2, gameClass: Tf2ClassName.scout, playerId: null, ready: false },
Expand All @@ -179,8 +179,8 @@ describe('QueuePromptsService', () => {
{ id: 9, gameClass: Tf2ClassName.demoman, playerId: null, ready: false },
{ id: 10, gameClass: Tf2ClassName.medic, playerId: null, ready: false },
{ id: 11, gameClass: Tf2ClassName.medic, playerId: null, ready: false },
]});

];
events.queueSlotsChange.next({ slots: queueService.slots });
await new Promise(resolve => setTimeout(resolve, 100));
});

Expand Down
13 changes: 7 additions & 6 deletions src/discord/services/queue-prompts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { DiscordService } from './discord.service';
@Injectable()
export class QueuePromptsService implements OnModuleInit {

private readonly playerThreshold = this.queueService.requiredPlayerCount * promptPlayerThresholdRatio;
private requiredPlayerCount = 0;
private message?: Message;

constructor(
Expand All @@ -24,15 +24,14 @@ export class QueuePromptsService implements OnModuleInit {
private queueService: QueueService,
private playersService: PlayersService,
private queueConfigService: QueueConfigService,
) {
console.log(this.playerThreshold);
}
) { }

onModuleInit() {
this.events.queueSlotsChange.subscribe(({ slots }) => this.refreshPrompt(slots));
this.events.queueSlotsChange.subscribe(() => this.refreshPrompt(this.queueService.slots));
}

private async refreshPrompt(slots: QueueSlot[]) {
this.requiredPlayerCount = slots.length;
const clientName = new URL(this.environment.clientUrl).hostname;

const embed = queuePreview({
Expand Down Expand Up @@ -69,7 +68,9 @@ export class QueuePromptsService implements OnModuleInit {
}

private playerThresholdMet() {
return this.queueService.playerCount >= this.playerThreshold;
console.log(this.queueService.playerCount);
console.log(this.requiredPlayerCount * promptPlayerThresholdRatio);
return this.queueService.playerCount >= (this.requiredPlayerCount * promptPlayerThresholdRatio);
}

@Cron(CronExpression.EVERY_5_MINUTES)
Expand Down

0 comments on commit ce92507

Please sign in to comment.