add color stripping to incoming chat
This commit is contained in:
parent
e652a27a06
commit
cee1673728
|
@ -34,7 +34,7 @@ fun String.lazyFormat(env: Map<String, () -> String>): String {
|
|||
return result
|
||||
}
|
||||
|
||||
val String.stripColor: String
|
||||
val String.stripColorOut: String
|
||||
get() =
|
||||
if (cfg.outgoing.stripColors)
|
||||
this.replace("§.".toRegex(), "")
|
||||
|
@ -42,6 +42,14 @@ val String.stripColor: String
|
|||
this
|
||||
|
||||
|
||||
val String.stripColorIn: String
|
||||
get() =
|
||||
if (cfg.incoming.stripColors)
|
||||
this.replace("§.".toRegex(), "")
|
||||
else
|
||||
this
|
||||
|
||||
|
||||
val Exception.stackTraceString: String
|
||||
get() {
|
||||
val sw = StringWriter()
|
||||
|
|
|
@ -5,7 +5,7 @@ import matterlink.bridge.MessageHandlerInst
|
|||
import matterlink.handlers.TickHandler
|
||||
import matterlink.instance
|
||||
import matterlink.lazyFormat
|
||||
import matterlink.stripColor
|
||||
import matterlink.stripColorOut
|
||||
|
||||
data class CustomCommand(
|
||||
val type: CommandType = CommandType.RESPONSE,
|
||||
|
@ -35,7 +35,7 @@ data class CustomCommand(
|
|||
if (!canExecute(userId, server)) {
|
||||
MessageHandlerInst.transmit(
|
||||
ApiMessage(
|
||||
text = "$user is not permitted to perform command: $alias".stripColor
|
||||
text = "$user is not permitted to perform command: $alias".stripColorOut
|
||||
)
|
||||
)
|
||||
return false
|
||||
|
@ -54,7 +54,7 @@ data class CustomCommand(
|
|||
CommandType.RESPONSE -> {
|
||||
MessageHandlerInst.transmit(
|
||||
ApiMessage(
|
||||
text = (response?.lazyFormat(getReplacements(user, userId, server, args))?.stripColor ?: "")
|
||||
text = (response?.lazyFormat(getReplacements(user, userId, server, args))?.stripColorOut ?: "")
|
||||
)
|
||||
)
|
||||
true
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package matterlink.config
|
||||
|
||||
import matterlink.bridge.MessageHandlerInst
|
||||
import matterlink.stripColor
|
||||
import java.io.File
|
||||
import java.util.regex.Pattern
|
||||
|
||||
|
@ -40,7 +39,8 @@ abstract class BaseConfig(rootDir: File) {
|
|||
data class IncomingOption(
|
||||
val chat: String = "<{username}> {text}",
|
||||
val joinPart: String = "§6-- {username} {text}",
|
||||
val action: String = "§5* {username} {text}"
|
||||
val action: String = "§5* {username} {text}",
|
||||
var stripColors: Boolean = true
|
||||
)
|
||||
|
||||
data class OutgoingOptions(
|
||||
|
@ -193,6 +193,12 @@ abstract class BaseConfig(rootDir: File) {
|
|||
category,
|
||||
incoming.action,
|
||||
"User actions (/me) sent by users from other gateways"
|
||||
),
|
||||
stripColors = getBoolean(
|
||||
"stripColors",
|
||||
category,
|
||||
incoming.stripColors,
|
||||
"strip colors from incoming text"
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -3,15 +3,15 @@ package matterlink.handlers
|
|||
import matterlink.api.ApiMessage
|
||||
import matterlink.bridge.MessageHandlerInst
|
||||
import matterlink.instance
|
||||
import matterlink.stripColor
|
||||
import matterlink.stripColorOut
|
||||
|
||||
object ChatProcessor {
|
||||
fun sendToBridge(user: String, msg: String, event: String) {
|
||||
val message = msg.trim()
|
||||
when {
|
||||
message.isNotBlank() -> MessageHandlerInst.transmit(ApiMessage(
|
||||
username = user.stripColor,
|
||||
text = message.stripColor,
|
||||
username = user.stripColorOut,
|
||||
text = message.stripColorOut,
|
||||
event = event)
|
||||
)
|
||||
else -> instance.warn("WARN: dropped blank message by '$user'")
|
||||
|
|
|
@ -4,7 +4,7 @@ import matterlink.antiping
|
|||
import matterlink.api.ApiMessage
|
||||
import matterlink.bridge.MessageHandlerInst
|
||||
import matterlink.config.cfg
|
||||
import matterlink.stripColor
|
||||
import matterlink.stripColorOut
|
||||
import java.util.*
|
||||
|
||||
object DeathHandler {
|
||||
|
@ -16,7 +16,7 @@ object DeathHandler {
|
|||
damageType: String
|
||||
) {
|
||||
if (cfg.outgoing.death.enable) {
|
||||
var msg = deathMessage.replace(player, player.stripColor.antiping)
|
||||
var msg = deathMessage.replace(player, player.stripColorOut.antiping)
|
||||
if (cfg.outgoing.death.damageType) {
|
||||
val emojis = cfg.outgoing.death.damageTypeMapping[damageType]?.split(' ')
|
||||
?: listOf("\uD83D\uDC7B unknown type '$damageType'")
|
||||
|
|
|
@ -6,15 +6,15 @@ import matterlink.api.ApiMessage.Companion.JOIN_LEAVE
|
|||
import matterlink.bridge.MessageHandlerInst
|
||||
import matterlink.config.cfg
|
||||
import matterlink.mapFormat
|
||||
import matterlink.stripColor
|
||||
import matterlink.stripColorOut
|
||||
|
||||
object JoinLeaveHandler {
|
||||
fun handleJoin(player: String) {
|
||||
if (cfg.outgoing.joinPart.enable) {
|
||||
val msg = cfg.outgoing.joinPart.joinServer.mapFormat(
|
||||
mapOf(
|
||||
"{username}" to player.stripColor,
|
||||
"{username:antiping}" to player.stripColor.antiping
|
||||
"{username}" to player.stripColorOut,
|
||||
"{username:antiping}" to player.stripColorOut.antiping
|
||||
)
|
||||
)
|
||||
MessageHandlerInst.transmit(
|
||||
|
@ -30,8 +30,8 @@ object JoinLeaveHandler {
|
|||
if (cfg.outgoing.joinPart.enable) {
|
||||
val msg = cfg.outgoing.joinPart.partServer.mapFormat(
|
||||
mapOf(
|
||||
"{username}" to player.stripColor,
|
||||
"{username:antiping}" to player.stripColor.antiping
|
||||
"{username}" to player.stripColorOut,
|
||||
"{username:antiping}" to player.stripColorOut.antiping
|
||||
)
|
||||
)
|
||||
MessageHandlerInst.transmit(
|
||||
|
|
|
@ -4,16 +4,16 @@ import matterlink.antiping
|
|||
import matterlink.api.ApiMessage
|
||||
import matterlink.bridge.MessageHandlerInst
|
||||
import matterlink.config.cfg
|
||||
import matterlink.stripColor
|
||||
import matterlink.stripColorOut
|
||||
|
||||
object ProgressHandler {
|
||||
|
||||
fun handleProgress(name: String, message: String, display: String) {
|
||||
if (!cfg.outgoing.advancements) return
|
||||
val usr = name.stripColor.antiping
|
||||
val usr = name.stripColorOut.antiping
|
||||
MessageHandlerInst.transmit(
|
||||
ApiMessage(
|
||||
text = "$usr $message $display".stripColor
|
||||
text = "$usr $message $display".stripColorOut
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package matterlink.handlers
|
||||
|
||||
import com.sun.xml.internal.ws.util.StringUtils
|
||||
import matterlink.bridge.MessageHandlerInst
|
||||
import matterlink.bridge.command.BridgeCommandRegistry
|
||||
import matterlink.bridge.format
|
||||
import matterlink.config.cfg
|
||||
import matterlink.instance
|
||||
import matterlink.stripColorIn
|
||||
|
||||
object ServerChatHandler {
|
||||
|
||||
|
@ -24,7 +24,7 @@ object ServerChatHandler {
|
|||
"" -> {
|
||||
// try to handle command and do not handle as a chat message
|
||||
if (BridgeCommandRegistry.handleCommand(nextMessage)) return
|
||||
nextMessage.format(cfg.incoming.chat)
|
||||
nextMessage.format(cfg.incoming.chat.stripColorIn)
|
||||
}
|
||||
"join_leave" -> nextMessage.format(cfg.incoming.joinPart)
|
||||
else -> {
|
||||
|
|
Loading…
Reference in New Issue