From 071d5ba1f80dc27b5b9bac6abdcddd4716053f62 Mon Sep 17 00:00:00 2001 From: JoBe <165585785+JoBeGaming@users.noreply.github.com> Date: Wed, 3 Jun 2026 07:30:34 +0200 Subject: [PATCH 1/5] Potential fix for https://github.com/OpenRedstoneEngineers/ChattORE/issues/26. Also renamed mentions of `chad` to `patrick` (rip King). --- chattore/src/main/kotlin/feature/Discord.kt | 27 ++++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/chattore/src/main/kotlin/feature/Discord.kt b/chattore/src/main/kotlin/feature/Discord.kt index ae05be1..7928591 100644 --- a/chattore/src/main/kotlin/feature/Discord.kt +++ b/chattore/src/main/kotlin/feature/Discord.kt @@ -22,8 +22,8 @@ fun String.discordEscape() = this.replace("""_""", "\\_") data class DiscordConfig( val enable: Boolean = false, val networkToken: String = "nouNetwork", - val channelId: Long = 1234L, - val chadId: Long = 1234L, + val channelId: Long = 1234L, // game-chat + val patrickId: Long = 1234L, val playingMessage: String = "on the ORE Network", val discordFormat: String = "`%prefix%` **%sender%**: %message%", val serverTokens: Map = mapOf( @@ -90,7 +90,7 @@ fun PluginScope.createDiscordFeature( } } -private suspend fun getGameChat(api: Kord, id: Long): TextChannel = api.getChannelOf(Snowflake(id)) +private suspend fun getGameChat(api: Kord, chatid: Long): TextChannel = api.getChannelOf(Snowflake(chatid)) ?: throw IllegalArgumentException("Cannot find game-chat channel") private class DiscordBroadcastListener( @@ -141,10 +141,19 @@ private class DiscordListener( fun onMessageCreate(event: MessageCreateEvent) { // guaranteed to not happen because events are filtered beforehand val sender = event.member ?: throw IllegalStateException("onMessageCreate: event.member is null") - if (sender.isBot && sender.id != Snowflake(config.chadId)) return + + var displayName = sender.effectiveName + if (sender.isBot) { + // Bot other than Patrick. + if (sender.id != Snowflake(config.patrickId)) return + + // Bot is patrick. We add a '[Bot]' prefix. + // See https://github.com/OpenRedstoneEngineers/ChattORE/issues/26. + displayName = "[Bot] " + displayName + } + val attachments = event.message.attachments.joinToString(" ", " ") { it.url } val toSend = replaceEmojis(event.message.content) + attachments - val displayName = sender.effectiveName logger.info("[Discord] $displayName (${sender.id}): $toSend") val transformedMessage = toSend.replace(urlMarkdownRegex) { matchResult -> val text = matchResult.groupValues[1].trim() @@ -170,10 +179,10 @@ private suspend fun CoroutineScope.spawnServerBots( if (availableServers != configServers) { logger.warn( """ - Supplied server keys in Discord configuration section does not match available servers: - Available servers: ${availableServers.joinToString()} - Configured servers: ${configServers.joinToString()} - """.trimIndent() + Supplied server keys in Discord configuration section does not match available servers: + Available servers: ${availableServers.joinToString()} + Configured servers: ${configServers.joinToString()} + """.trimIndent() ) } return serverTokens.mapValues { (_, token) -> From 3d4ff9b1c981c98c569d712ad645f01b76c0f4a9 Mon Sep 17 00:00:00 2001 From: JoBe <165585785+JoBeGaming@users.noreply.github.com> Date: Wed, 3 Jun 2026 12:14:20 +0200 Subject: [PATCH 2/5] Fix some comments for the PR --- chattore/src/main/kotlin/feature/Discord.kt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/chattore/src/main/kotlin/feature/Discord.kt b/chattore/src/main/kotlin/feature/Discord.kt index 7928591..205b659 100644 --- a/chattore/src/main/kotlin/feature/Discord.kt +++ b/chattore/src/main/kotlin/feature/Discord.kt @@ -90,8 +90,8 @@ fun PluginScope.createDiscordFeature( } } -private suspend fun getGameChat(api: Kord, chatid: Long): TextChannel = api.getChannelOf(Snowflake(chatid)) - ?: throw IllegalArgumentException("Cannot find game-chat channel") +private suspend fun getGameChat(api: Kord, channelId: Long): TextChannel = api.getChannelOf(Snowflake(channelId)) + ?: throw IllegalArgumentException("Cannot find game-chat channel") // Todo: We might want to use this function for other channels too, so the error might need to look different. private class DiscordBroadcastListener( private val config: DiscordConfig, @@ -144,11 +144,7 @@ private class DiscordListener( var displayName = sender.effectiveName if (sender.isBot) { - // Bot other than Patrick. if (sender.id != Snowflake(config.patrickId)) return - - // Bot is patrick. We add a '[Bot]' prefix. - // See https://github.com/OpenRedstoneEngineers/ChattORE/issues/26. displayName = "[Bot] " + displayName } From 017763203b82be416353f81bfc4e1a08073a16e6 Mon Sep 17 00:00:00 2001 From: JoBe <165585785+JoBeGaming@users.noreply.github.com> Date: Wed, 3 Jun 2026 17:56:29 +0200 Subject: [PATCH 3/5] See https://github.com/OpenRedstoneEngineers/ChattORE/pull/30#discussion_r3349329281 --- chattore/src/main/kotlin/feature/Discord.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chattore/src/main/kotlin/feature/Discord.kt b/chattore/src/main/kotlin/feature/Discord.kt index 205b659..2bbae71 100644 --- a/chattore/src/main/kotlin/feature/Discord.kt +++ b/chattore/src/main/kotlin/feature/Discord.kt @@ -91,7 +91,7 @@ fun PluginScope.createDiscordFeature( } private suspend fun getGameChat(api: Kord, channelId: Long): TextChannel = api.getChannelOf(Snowflake(channelId)) - ?: throw IllegalArgumentException("Cannot find game-chat channel") // Todo: We might want to use this function for other channels too, so the error might need to look different. + ?: throw IllegalArgumentException("Cannot find game-chat channel (with id $channelId)") private class DiscordBroadcastListener( private val config: DiscordConfig, From cc4a277f4ea90ccff68437eb4c78669c0108bc32 Mon Sep 17 00:00:00 2001 From: JoBe <165585785+JoBeGaming@users.noreply.github.com> Date: Wed, 3 Jun 2026 19:05:14 +0200 Subject: [PATCH 4/5] See https://github.com/OpenRedstoneEngineers/ChattORE/pull/30/changes#r3346620231 (Still didn't change any configs, see https://discord.com/channels/116914772766752769/742095081594421268/1511777278835556473) --- chattore/src/main/kotlin/feature/Discord.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chattore/src/main/kotlin/feature/Discord.kt b/chattore/src/main/kotlin/feature/Discord.kt index 2bbae71..bde52b8 100644 --- a/chattore/src/main/kotlin/feature/Discord.kt +++ b/chattore/src/main/kotlin/feature/Discord.kt @@ -22,7 +22,7 @@ fun String.discordEscape() = this.replace("""_""", "\\_") data class DiscordConfig( val enable: Boolean = false, val networkToken: String = "nouNetwork", - val channelId: Long = 1234L, // game-chat + val gameChatChannelId: Long = 1234L, val patrickId: Long = 1234L, val playingMessage: String = "on the ORE Network", val discordFormat: String = "`%prefix%` **%sender%**: %message%", From 6dda77236d901ad29175f61d43c7e13882770d41 Mon Sep 17 00:00:00 2001 From: JoBe <165585785+JoBeGaming@users.noreply.github.com> Date: Wed, 3 Jun 2026 19:09:19 +0200 Subject: [PATCH 5/5] Ok I'm dumb i didn't rename the other uses of `channelId`. --- chattore/src/main/kotlin/feature/Discord.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chattore/src/main/kotlin/feature/Discord.kt b/chattore/src/main/kotlin/feature/Discord.kt index bde52b8..765ece4 100644 --- a/chattore/src/main/kotlin/feature/Discord.kt +++ b/chattore/src/main/kotlin/feature/Discord.kt @@ -70,8 +70,8 @@ fun PluginScope.createDiscordFeature( } } val discordMap = spawnServerBots(proxy, logger, config) - val serverChannels = discordMap.mapValues { (_, api) -> getGameChat(api, config.channelId) } - val mainBotChannel = getGameChat(discordNetwork, config.channelId) + val serverChannels = discordMap.mapValues { (_, api) -> getGameChat(api, config.gameChatChannelId) } + val mainBotChannel = getGameChat(discordNetwork, config.gameChatChannelId) val listener = DiscordListener(logger, messenger, proxy, emojis, config) @OptIn(KordPreview::class) mainBotChannel.live().onMessageCreate(block = listener::onMessageCreate)