diff --git a/core/src/main/kotlin/matterlink/bridge/MessageHandlerInst.kt b/core/src/main/kotlin/matterlink/bridge/MessageHandlerInst.kt index 0a5bcec..a48ed70 100644 --- a/core/src/main/kotlin/matterlink/bridge/MessageHandlerInst.kt +++ b/core/src/main/kotlin/matterlink/bridge/MessageHandlerInst.kt @@ -11,6 +11,16 @@ object MessageHandlerInst : MessageHandler() { } fun transmit(msg: ApiMessage, cause: String, maxLines: Int = cfg.outgoing.inlineLimit) { + if (msg.username.isEmpty()) { + msg.username = cfg.outgoing.systemUser + + if(msg.avatar.isEmpty() && cfg.outgoing.avatar.enable) { + msg.avatar = cfg.outgoing.avatar.systemUserAvatar + } + } + if (msg.gateway.isEmpty()) + msg.gateway = cfg.connect.gateway + if (msg.text.lines().count() >= maxLines) { try { val response = PasteUtil.paste( diff --git a/core/src/main/kotlin/matterlink/config/BaseConfig.kt b/core/src/main/kotlin/matterlink/config/BaseConfig.kt index 204c377..dbf0930 100644 --- a/core/src/main/kotlin/matterlink/config/BaseConfig.kt +++ b/core/src/main/kotlin/matterlink/config/BaseConfig.kt @@ -4,8 +4,11 @@ import blue.endless.jankson.Jankson import blue.endless.jankson.JsonObject import blue.endless.jankson.impl.Marshaller import blue.endless.jankson.impl.SyntaxError -import matterlink.* import matterlink.bridge.MessageHandlerInst +import matterlink.getOrDefault +import matterlink.logger +import matterlink.registerTypeAdapter +import matterlink.stackTraceString import java.io.File import java.io.FileNotFoundException @@ -65,6 +68,7 @@ data class BaseConfig(val rootDir: File) { val inlineLimit: Int = 5, val joinPart: JoinPartOptions = JoinPartOptions(), + var avatar: AvatarOptions = AvatarOptions(), val death: DeathOptions = DeathOptions() ) @@ -104,6 +108,13 @@ data class BaseConfig(val rootDir: File) { ) ) + data class AvatarOptions( + val enable: Boolean = true, + val urlTemplate: String = "https://visage.surgeplay.com/head/512/{uuid}", + // https://www.freepik.com/free-icon/right-arrow-angle-and-horizontal-down-line-code-signs_732795.htm + val systemUserAvatar: String = "https://image.freepik.com/free-icon/right-arrow-angle-and-horizontal-down-line-code-signs_318-53994.jpg" + ) + data class JoinPartOptions( val enable: Boolean = true, val joinServer: String = "{username:antiping} has connected to the platform", @@ -285,6 +296,11 @@ data class BaseConfig(val rootDir: File) { DeathOptions(), "Death messages settings" ), + avatar = it.getOrDefault( + "avatar", + AvatarOptions(), + "Avatar options" + ), joinPart = it.getOrDefault( "joinPart", JoinPartOptions(), @@ -323,6 +339,22 @@ data class BaseConfig(val rootDir: File) { ) } } + .registerTypeAdapter { + with(AvatarOptions()) { + AvatarOptions( + enable = it.getOrDefault( + "enable", + enable, + "enable ingame avatar" + ), + urlTemplate = it.getOrDefault( + "urlTemplate", + urlTemplate, + "template for constructing the user avatar url using the uuid" + ) + ) + } + } .registerTypeAdapter { with(JoinPartOptions()) { JoinPartOptions( diff --git a/core/src/main/kotlin/matterlink/handlers/ChatProcessor.kt b/core/src/main/kotlin/matterlink/handlers/ChatProcessor.kt index 1ffa2a9..4b06f4a 100644 --- a/core/src/main/kotlin/matterlink/handlers/ChatProcessor.kt +++ b/core/src/main/kotlin/matterlink/handlers/ChatProcessor.kt @@ -3,6 +3,7 @@ package matterlink.handlers import matterlink.api.ApiMessage import matterlink.bridge.MessageHandlerInst import matterlink.bridge.command.BridgeCommandRegistry +import matterlink.config.cfg import matterlink.instance import matterlink.logger import matterlink.stripColorOut @@ -21,7 +22,12 @@ object ChatProcessor { username = user.stripColorOut, text = message.stripColorOut, event = event - ), + ).apply { + if(cfg.outgoing.avatar.enable) { + if(uuid != null) + avatar = cfg.outgoing.avatar.urlTemplate.replace("{uuid}", uuid.toString()) + } + }, cause = "Message from $user" ) else -> logger.warn("WARN: dropped blank message by '$user'")