paste long output
This commit is contained in:
parent
13a607fcd1
commit
42dcd2c543
|
@ -25,7 +25,9 @@ class MatterLinkCommandSender(
|
|||
return 0 < FMLCommonHandler.instance().minecraftServerInstance.commandManager.executeCommand(
|
||||
this,
|
||||
cmdString
|
||||
)
|
||||
).apply {
|
||||
sendReply(cmdString)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDisplayName(): ITextComponent {
|
||||
|
@ -48,8 +50,7 @@ class MatterLinkCommandSender(
|
|||
}
|
||||
|
||||
override fun sendMessage(@Nonnull component: ITextComponent?) {
|
||||
sendReply(component!!.unformattedComponentText)
|
||||
|
||||
appendReply(component!!.unformattedComponentText)
|
||||
}
|
||||
|
||||
override fun sendCommandFeedback(): Boolean {
|
||||
|
|
|
@ -25,7 +25,9 @@ class MatterLinkCommandSender(
|
|||
return 0 < FMLCommonHandler.instance().minecraftServerInstance.commandManager.executeCommand(
|
||||
this,
|
||||
cmdString
|
||||
)
|
||||
).apply {
|
||||
sendReply(cmdString)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDisplayName(): ITextComponent {
|
||||
|
@ -48,7 +50,7 @@ class MatterLinkCommandSender(
|
|||
}
|
||||
|
||||
override fun sendMessage(@Nonnull component: ITextComponent?) {
|
||||
sendReply(component!!.unformattedComponentText)
|
||||
appendReply(component!!.unformattedComponentText)
|
||||
}
|
||||
|
||||
override fun sendCommandFeedback(): Boolean {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package matterlink.command
|
||||
|
||||
import matterlink.logger
|
||||
import net.minecraft.command.CommandBase
|
||||
import net.minecraft.command.ICommandSender
|
||||
import net.minecraft.command.WrongUsageException
|
||||
|
|
|
@ -21,7 +21,9 @@ class MatterLinkCommandSender(
|
|||
return 0 < FMLCommonHandler.instance().minecraftServerInstance.commandManager.executeCommand(
|
||||
this,
|
||||
cmdString
|
||||
)
|
||||
).apply {
|
||||
sendReply(cmdString)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDisplayName(): ITextComponent {
|
||||
|
@ -44,7 +46,7 @@ class MatterLinkCommandSender(
|
|||
}
|
||||
|
||||
override fun sendMessage(@Nonnull component: ITextComponent?) {
|
||||
sendReply(component!!.unformattedComponentText)
|
||||
appendReply(component!!.unformattedComponentText)
|
||||
}
|
||||
|
||||
override fun sendCommandFeedback(): Boolean {
|
||||
|
|
|
@ -20,7 +20,9 @@ class MatterLinkCommandSender(
|
|||
return 0 < MinecraftServer.getServer().commandManager.executeCommand(
|
||||
this,
|
||||
cmdString
|
||||
)
|
||||
).apply {
|
||||
sendReply(cmdString)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getFormattedCommandSenderName(): IChatComponent {
|
||||
|
@ -39,7 +41,7 @@ class MatterLinkCommandSender(
|
|||
}
|
||||
|
||||
override fun addChatMessage(component: IChatComponent) {
|
||||
sendReply(component.unformattedText)
|
||||
appendReply(component.unformattedText)
|
||||
}
|
||||
|
||||
override fun getCommandSenderPosition(): ChunkCoordinates = ChunkCoordinates(0, 0, 0)
|
||||
|
|
2
api
2
api
|
@ -1 +1 @@
|
|||
Subproject commit 8e17cb9937e333c099f8115289b93482dfa76a1d
|
||||
Subproject commit 15e4d115dd0e1ac1e5d287c48d6dc76a6a488ed7
|
|
@ -0,0 +1,92 @@
|
|||
package matterlink
|
||||
|
||||
import blue.endless.jankson.Jankson
|
||||
import blue.endless.jankson.JsonObject
|
||||
import blue.endless.jankson.impl.Marshaller
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
|
||||
|
||||
/**
|
||||
* Created by nikky on 09/07/18.
|
||||
* @author Nikky
|
||||
*/
|
||||
|
||||
data class Paste(
|
||||
val encrypted: Boolean = false,
|
||||
val description: String,
|
||||
val sections: List<PasteSection>
|
||||
)
|
||||
|
||||
data class PasteSection(
|
||||
val name: String,
|
||||
val syntax: String = "text",
|
||||
val contents: String
|
||||
)
|
||||
|
||||
data class PasteResponse(
|
||||
val id: String,
|
||||
val link: String
|
||||
)
|
||||
|
||||
object PasteUtil {
|
||||
private const val DEFAULT_KEY = "uKJoyicVJFnmpnrIZMklOURWxrCKXYaiBWOzPmvon"
|
||||
|
||||
private val jankson = Jankson.builder()
|
||||
.registerTypeAdapter {
|
||||
PasteResponse(
|
||||
id = it.getReified("id") ?: "",
|
||||
link = it.getReified<String>("link")
|
||||
?.replace("\\/", "/")
|
||||
?: "invalid"
|
||||
)
|
||||
}
|
||||
.registerSerializer { paste: Paste, marshaller: Marshaller ->
|
||||
JsonObject().apply {
|
||||
with(paste) {
|
||||
if (description.isNotBlank())
|
||||
this@apply["description"] = marshaller.serialize(description)
|
||||
if (encrypted)
|
||||
this@apply["encrypted"] = marshaller.serialize(encrypted)
|
||||
this@apply["sections"] = marshaller.serialize(sections)
|
||||
}
|
||||
}
|
||||
}
|
||||
.registerSerializer { section: PasteSection, marshaller: Marshaller ->
|
||||
JsonObject().apply {
|
||||
with(section) {
|
||||
if (name.isNotBlank())
|
||||
this@apply["name"] = marshaller.serialize(name)
|
||||
this@apply["syntax"] = marshaller.serialize(syntax)
|
||||
this@apply["contents"] = marshaller.serialize(contents.replace("\n", "\\n"))
|
||||
}
|
||||
}
|
||||
}
|
||||
.build()
|
||||
|
||||
fun paste(paste: Paste, key: String = ""): PasteResponse {
|
||||
val apiKey = key.takeIf { it.isNotBlank() } ?: DEFAULT_KEY
|
||||
|
||||
val url = URL("https://api.paste.ee/v1/pastes")
|
||||
val http = url.openConnection() as HttpURLConnection
|
||||
http.requestMethod = "POST"
|
||||
http.doOutput = true
|
||||
|
||||
val out = jankson.toJson(paste)
|
||||
.toJson(false, false).apply { println(this) }
|
||||
.toByteArray()
|
||||
|
||||
http.setFixedLengthStreamingMode(out.size)
|
||||
http.setRequestProperty("Content-Type", "application/json; charset=UTF-8")
|
||||
http.setRequestProperty("X-Auth-Token", apiKey)
|
||||
http.connect()
|
||||
http.outputStream.use { os ->
|
||||
os.write(out)
|
||||
}
|
||||
|
||||
val textResponse = http.inputStream.bufferedReader().use { it.readText() }
|
||||
instance.debug("response: $textResponse")
|
||||
// val jsonObject = jankson.load(http.inputStream)
|
||||
return jankson.fromJson(textResponse)
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package matterlink
|
||||
|
||||
import com.google.gson.*
|
||||
import java.lang.reflect.Type
|
||||
|
||||
object RegexDeSerializer: JsonSerializer<Regex>, JsonDeserializer<Regex> {
|
||||
override fun serialize(src: Regex, typeOfSrc: Type, context: JsonSerializationContext): JsonElement {
|
||||
return JsonPrimitive(src.pattern)
|
||||
}
|
||||
|
||||
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): Regex {
|
||||
return json.asString.toRegex()
|
||||
}
|
||||
|
||||
}
|
|
@ -73,6 +73,7 @@ fun <T : Any> JsonObject.getOrDefault(key: String, default: T, comment: String?
|
|||
}
|
||||
|
||||
inline fun <reified T : Any> Jankson.fromJson(obj: JsonObject): T = this.fromJson(obj, T::class.java)
|
||||
inline fun <reified T : Any> Jankson.fromJson(json: String): T = this.fromJson(json, T::class.java)
|
||||
|
||||
inline fun <reified T : Any> Jankson.Builder.registerTypeAdapter(noinline adapter: (JsonObject) -> T) = this.registerTypeAdapter(T::class.java, adapter)
|
||||
|
||||
|
|
|
@ -1,11 +1,38 @@
|
|||
package matterlink.bridge
|
||||
|
||||
import matterlink.antiping
|
||||
import matterlink.*
|
||||
import matterlink.api.ApiMessage
|
||||
import matterlink.api.MessageHandler
|
||||
import matterlink.mapFormat
|
||||
|
||||
object MessageHandlerInst: MessageHandler()
|
||||
object MessageHandlerInst : MessageHandler() {
|
||||
override fun transmit(msg: ApiMessage) {
|
||||
transmit(msg, cause = "")
|
||||
}
|
||||
|
||||
fun transmit(msg: ApiMessage, cause: String, maxLines: Int = 3) {
|
||||
if (msg.text.count { it == '\n' } >= maxLines) {
|
||||
try {
|
||||
val response = PasteUtil.paste(
|
||||
Paste(
|
||||
description = cause,
|
||||
sections = listOf(
|
||||
PasteSection(
|
||||
name = "log.txt",
|
||||
syntax = "text",
|
||||
contents = msg.text
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
msg.text = msg.text.substringBefore('\n')
|
||||
.take(15) + "... " + response.link
|
||||
} catch(e: Exception) {
|
||||
instance.error(e.stackTraceString)
|
||||
}
|
||||
}
|
||||
super.transmit(msg)
|
||||
}
|
||||
}
|
||||
|
||||
fun ApiMessage.format(fmt: String): String {
|
||||
return fmt.mapFormat(
|
||||
|
|
|
@ -40,14 +40,15 @@ data class CustomCommand(
|
|||
val commandSender = instance.commandSenderFor(user, userId, platform, uuid, username, execOp ?: false)
|
||||
val cmd = execute?.lazyFormat(getReplacements(user, userId, platform, uuid, args))?.stripColorIn
|
||||
?: return false
|
||||
commandSender.execute(cmd) || commandSender.reply.isNotBlank()
|
||||
commandSender.execute(cmd) || commandSender.reply.isNotEmpty()
|
||||
}
|
||||
CommandType.RESPONSE -> {
|
||||
MessageHandlerInst.transmit(
|
||||
ApiMessage(
|
||||
text = (response?.lazyFormat(getReplacements(user, userId, platform, uuid, args))
|
||||
?: "")
|
||||
)
|
||||
),
|
||||
cause = "response to command: $alias"
|
||||
)
|
||||
true
|
||||
}
|
||||
|
|
|
@ -22,7 +22,8 @@ object HelpCommand : IBridgeCommand() {
|
|||
MessageHandlerInst.transmit(
|
||||
ApiMessage(
|
||||
text = msg.stripColorOut
|
||||
)
|
||||
),
|
||||
cause = "Help Requested $args"
|
||||
)
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package matterlink.bridge.command
|
|||
import matterlink.api.ApiMessage
|
||||
import matterlink.bridge.MessageHandlerInst
|
||||
import matterlink.stripColorOut
|
||||
import java.awt.SystemColor.text
|
||||
|
||||
abstract class IMinecraftCommandSender(val user: String, val userId: String, val server: String, val uuid: String?, val username: String?, val op: Boolean) {
|
||||
/**
|
||||
|
@ -21,14 +22,27 @@ abstract class IMinecraftCommandSender(val user: String, val userId: String, val
|
|||
return command.canExecute(uuid)
|
||||
}
|
||||
|
||||
var reply: String = ""
|
||||
var finished = true
|
||||
val reply = mutableListOf<String>()
|
||||
|
||||
fun sendReply(text: String) {
|
||||
reply = text
|
||||
/**
|
||||
* accumulates response
|
||||
*/
|
||||
fun appendReply(text: String) {
|
||||
if(finished) {
|
||||
reply.clear()
|
||||
finished = false
|
||||
}
|
||||
reply += text
|
||||
}
|
||||
|
||||
fun sendReply(cmdString: String) {
|
||||
MessageHandlerInst.transmit(
|
||||
ApiMessage(
|
||||
text = text.stripColorOut
|
||||
)
|
||||
msg = ApiMessage(
|
||||
text = reply.joinToString("\n").stripColorOut
|
||||
),
|
||||
cause = "executed command: $cmdString"
|
||||
)
|
||||
finished = true
|
||||
}
|
||||
}
|
|
@ -52,26 +52,27 @@ data class BaseConfig(val rootDir: File) {
|
|||
)
|
||||
|
||||
data class DebugOptions(
|
||||
var logLevel: String = "INFO"
|
||||
val logLevel: String = "INFO"
|
||||
)
|
||||
|
||||
data class IncomingOptions(
|
||||
val chat: String = "<{username}> {text}",
|
||||
val joinPart: String = "§6-- {username} {text}",
|
||||
val action: String = "§5* {username} {text}",
|
||||
var stripColors: Boolean = true
|
||||
val stripColors: Boolean = true
|
||||
)
|
||||
|
||||
data class OutgoingOptions(
|
||||
val systemUser: String = "Server",
|
||||
//outgoing toggles
|
||||
var announceConnect: Boolean = true,
|
||||
var announceDisconnect: Boolean = true,
|
||||
val announceConnect: Boolean = true,
|
||||
val announceDisconnect: Boolean = true,
|
||||
val advancements: Boolean = true,
|
||||
var stripColors: Boolean = true,
|
||||
val stripColors: Boolean = true,
|
||||
val pasteEEKey: String = "",
|
||||
|
||||
var joinPart: JoinPartOptions = JoinPartOptions(),
|
||||
var death: DeathOptions = DeathOptions()
|
||||
val joinPart: JoinPartOptions = JoinPartOptions(),
|
||||
val death: DeathOptions = DeathOptions()
|
||||
)
|
||||
|
||||
data class DeathOptions(
|
||||
|
@ -288,6 +289,11 @@ data class BaseConfig(val rootDir: File) {
|
|||
stripColors,
|
||||
"strip colors from nicknames and messages"
|
||||
),
|
||||
pasteEEKey = it.getOrDefault(
|
||||
"pasteEEKey",
|
||||
pasteEEKey,
|
||||
"paste.ee api key, leave empty to use application default"
|
||||
),
|
||||
death = it.getOrDefault(
|
||||
"death",
|
||||
DeathOptions(),
|
||||
|
|
|
@ -9,10 +9,13 @@ object ChatProcessor {
|
|||
fun sendToBridge(user: String, msg: String, event: String) {
|
||||
val message = msg.trim()
|
||||
when {
|
||||
message.isNotBlank() -> MessageHandlerInst.transmit(ApiMessage(
|
||||
username = user.stripColorOut,
|
||||
text = message.stripColorOut,
|
||||
event = event)
|
||||
message.isNotBlank() -> MessageHandlerInst.transmit(
|
||||
ApiMessage(
|
||||
username = user.stripColorOut,
|
||||
text = message.stripColorOut,
|
||||
event = event
|
||||
),
|
||||
cause = "Message from $user"
|
||||
)
|
||||
else -> instance.warn("WARN: dropped blank message by '$user'")
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ object DeathHandler {
|
|||
val damageEmoji = emojis[random.nextInt(emojis.size)]
|
||||
msg += " $damageEmoji"
|
||||
}
|
||||
MessageHandlerInst.transmit(ApiMessage(text = msg))
|
||||
MessageHandlerInst.transmit(ApiMessage(text = msg), cause = "Death Event of $player")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,8 @@ object JoinLeaveHandler {
|
|||
ApiMessage(
|
||||
text = msg,
|
||||
event = JOIN_LEAVE
|
||||
)
|
||||
),
|
||||
cause = "$player joined"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +39,8 @@ object JoinLeaveHandler {
|
|||
ApiMessage(
|
||||
text = msg,
|
||||
event = JOIN_LEAVE
|
||||
)
|
||||
),
|
||||
cause = "$player left"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,8 @@ object ProgressHandler {
|
|||
MessageHandlerInst.transmit(
|
||||
ApiMessage(
|
||||
text = "$usr $message $display".stripColorOut
|
||||
)
|
||||
),
|
||||
cause = "Progress Event by $usr"
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue