From 6b9dfca8349e8a08f5b224f322f0fadb4c4b4090 Mon Sep 17 00:00:00 2001 From: Richard Hillebrand <57721238+Mirasaki@users.noreply.github.com> Date: Thu, 26 Jun 2025 15:06:11 +0200 Subject: [PATCH 1/2] fix: message placeholders not being parsed and handled correctly Fixes #123 --- src/adapter/discord/discord-publisher.ts | 6 ++++-- src/index.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/adapter/discord/discord-publisher.ts b/src/adapter/discord/discord-publisher.ts index f298aa3..bf019dc 100644 --- a/src/adapter/discord/discord-publisher.ts +++ b/src/adapter/discord/discord-publisher.ts @@ -85,13 +85,15 @@ export class DiscordPublisher implements GameStatusPublisher { let message = this.formats.playerCount .replace('${playerCount}', status.playerCount.toString()) .replace('${maxPlayers}', status.maxPlayers.toString()); - if (status.queuedPlayers) { + if (status.queuedPlayers && message.indexOf('${queuedPlayersMessage}') !== -1) { message = message.replace( '${queuedPlayersMessage}', this.formats.queuedPlayers.replace('${queuedPlayers}', status.queuedPlayers.toString(10)) ); } else { - message = message.replace('${queuedPlayersMessage}', ''); + message = message + .replace('${queuedPlayersMessage}', '') + .replace('${queuedPlayers}', ''); } this.client.user?.setPresence({ status: 'online', diff --git a/src/index.ts b/src/index.ts index 3330974..d3488d2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,7 +22,7 @@ class App { this.client = await this.createDiscordClient(); try { const publisher = new DiscordPublisher(this.client, new FileBackedMapRepository(), { - playerCount: process.env.DISCORD_PUBLISHER_MESSAGE_FORMAT || '${playerCount}/${maxPlayers} $queuedPlayers', + playerCount: process.env.DISCORD_PUBLISHER_MESSAGE_FORMAT || '${playerCount}/${maxPlayers} $queuedPlayersMessage', queuedPlayers: process.env.DISCORD_PUBLISHER_MESSAGE_QUEUED_FORMAT || '(+${queuedPlayers})', }); this.useCase = new ProvideGameStatus(providerFactory().build(), publisher); From 7bf41cc5eb125f09ed98cb6712c45d820d63339e Mon Sep 17 00:00:00 2001 From: Richard Hillebrand <57721238+Mirasaki@users.noreply.github.com> Date: Thu, 26 Jun 2025 15:12:10 +0200 Subject: [PATCH 2/2] fix: improve parsing of queued players formats --- src/adapter/discord/discord-publisher.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/adapter/discord/discord-publisher.ts b/src/adapter/discord/discord-publisher.ts index bf019dc..7fb09e7 100644 --- a/src/adapter/discord/discord-publisher.ts +++ b/src/adapter/discord/discord-publisher.ts @@ -85,11 +85,19 @@ export class DiscordPublisher implements GameStatusPublisher { let message = this.formats.playerCount .replace('${playerCount}', status.playerCount.toString()) .replace('${maxPlayers}', status.maxPlayers.toString()); - if (status.queuedPlayers && message.indexOf('${queuedPlayersMessage}') !== -1) { - message = message.replace( + if (status.queuedPlayers) { + if (message.indexOf('${queuedPlayersMessage}') !== -1) { + message = message.replace( '${queuedPlayersMessage}', this.formats.queuedPlayers.replace('${queuedPlayers}', status.queuedPlayers.toString(10)) - ); + ); + } + if (message.indexOf('${queuedPlayers}') !== -1) { + message = message.replace( + '${queuedPlayers}', + status.queuedPlayers.toString(10) + ); + } } else { message = message .replace('${queuedPlayersMessage}', '')