Skip to content

Commit

Permalink
fix: Discord -> MC plugin message format
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Feb 8, 2024
1 parent cbb9635 commit 14a358e
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.mineinabyss.chatty.listeners
import com.mineinabyss.chatty.chatty
import com.mineinabyss.chatty.chattyProxyChannel
import com.mineinabyss.chatty.components.ChannelData
import com.mineinabyss.chatty.helpers.defaultChannel
import com.mineinabyss.chatty.helpers.globalChannel
import com.mineinabyss.chatty.helpers.handleChatFilters
import com.mineinabyss.chatty.helpers.handleUrlReplacements
import com.mineinabyss.geary.papermc.tracking.entities.toGeary
Expand All @@ -29,7 +31,12 @@ class DiscordListener {

@Subscribe(priority = ListenerPriority.HIGHEST)
fun DiscordGuildMessagePostProcessEvent.sendDiscordToProxy() {
val minecraftMessage = ComponentDSV.textOfChildren(if (chatty.config.chat.formatURLs) handleUrlReplacements(minecraftMessage.toComponent(), null).toComponentDSV() else minecraftMessage)
val senderName = mm.deserialize(message.author.displayName ?: message.author.name)
val channel = defaultChannel().takeIf { it.value.discordsrv } ?: globalChannel()?.takeIf { it.value.discordsrv } ?: chatty.config.channels.entries.firstOrNull { it.value.discordsrv } ?: return
val channelId = ComponentDSV.text(channel.key)
val simpleMessage = mm.deserialize(message.author.name + ": " + message.contentRaw)
val message = if (chatty.config.chat.formatURLs) handleUrlReplacements(minecraftMessage.toComponent(), null).toComponentDSV() else minecraftMessage
val minecraftMessage = ComponentDSV.textOfChildren(senderName, channelId, message, simpleMessage)
chatty.plugin.server.sendPluginMessage(chatty.plugin, chattyProxyChannel, gson.serialize(minecraftMessage).toByteArray())
setMinecraftMessage(minecraftMessage)
}
Expand Down

0 comments on commit 14a358e

Please sign in to comment.