Skip to content

Commit

Permalink
fix: mention players when a sub is needed
Browse files Browse the repository at this point in the history
  • Loading branch information
garrappachc committed Jan 27, 2021
1 parent 97dc34d commit 07adb0f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/discord/services/__mocks__/discord.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export class DiscordService {
}

findRole(role: string) {
return `&<${role}>`;
return {
mentionable: true,
toString: () => `&<${role}>`,
};
}

}
4 changes: 3 additions & 1 deletion src/games/services/player-substitution.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jest.mock('@/queue/services/queue.service');

const environment = {
clientUrl: 'FAKE_CLIENT_URL',
discordQueueNotificationsMentionRole: 'TF2 gamers',
};

describe('PlayerSubstitutionService', () => {
Expand Down Expand Up @@ -161,7 +162,8 @@ describe('PlayerSubstitutionService', () => {
it('should notify on discord', async () => {
const spy = jest.spyOn(discordService.getPlayersChannel(), 'send');
await service.substitutePlayer(mockGame.id, player1.id);
expect(spy).toHaveBeenCalled();
expect(spy).toHaveBeenCalledWith('&<TF2 gamers>');
expect(spy).toHaveBeenCalledWith({ embed: expect.any(Object) });
});

// eslint-disable-next-line jest/expect-expect
Expand Down
26 changes: 17 additions & 9 deletions src/games/services/player-substitution.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,23 @@ export class PlayerSubstitutionService {
this.events.gameChanges.next({ game: game.toJSON() });
this.events.substituteRequestsChange.next();

const message = await this.discordService.getPlayersChannel()?.send({
embed:substituteRequest({
gameNumber: game.number,
gameClass: slot.gameClass,
team: slot.team.toUpperCase(),
gameUrl: `${this.environment.clientUrl}/game/${game.id}`,
}),
});
this.discordNotifications.set(playerId, message);
const channel = this.discordService.getPlayersChannel();
if (channel) {
const roleToMention = this.discordService.findRole(this.environment.discordQueueNotificationsMentionRole);
if (roleToMention?.mentionable) {
await channel?.send(`${roleToMention}`);
}

const message = await channel.send({
embed: substituteRequest({
gameNumber: game.number,
gameClass: slot.gameClass,
team: slot.team.toUpperCase(),
gameUrl: `${this.environment.clientUrl}/game/${game.id}`,
}),
});
this.discordNotifications.set(playerId, message);
}

return game;
}
Expand Down

0 comments on commit 07adb0f

Please sign in to comment.