mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
Shamrock
: fix #73
This commit is contained in:
parent
5f0cf952e8
commit
7439622cd6
@ -634,24 +634,26 @@ internal object MessageMaker {
|
||||
}
|
||||
|
||||
private suspend fun createImageElem(chatType: Int, msgId: Long, peerId: String, data: JsonObject): Result<MsgElement> {
|
||||
data.checkAndThrow("file")
|
||||
val isOriginal = data["original"].asBooleanOrNull ?: true
|
||||
val isFlash = data["flash"].asBooleanOrNull ?: false
|
||||
val file = data["file"].asString.let {
|
||||
val md5 = it.replace(regex = "[{}\\-]".toRegex(), replacement = "").split(".")[0].lowercase()
|
||||
var tmpPicFile = if (md5.length == 32) {
|
||||
val filePath = data["file"].asStringOrNull
|
||||
val url = data["url"].asStringOrNull
|
||||
var file: File? = null
|
||||
if (filePath != null) {
|
||||
val md5 = filePath.replace(regex = "[{}\\-]".toRegex(), replacement = "").split(".")[0].lowercase()
|
||||
file = if (md5.length == 32) {
|
||||
FileUtils.getFile(md5)
|
||||
} else {
|
||||
FileUtils.parseAndSave(it)
|
||||
FileUtils.parseAndSave(filePath)
|
||||
}
|
||||
if (!tmpPicFile.exists() && data.containsKey("url")) {
|
||||
tmpPicFile = FileUtils.parseAndSave(data["url"].asString)
|
||||
}
|
||||
return@let tmpPicFile
|
||||
if ((file == null || !file.exists()) && url != null) {
|
||||
file = FileUtils.parseAndSave(url)
|
||||
}
|
||||
if (!file.exists()) {
|
||||
if (file?.exists() == false) {
|
||||
throw LogicException("Image(${file.name}) file is not exists, please check your filename.")
|
||||
}
|
||||
requireNotNull(file)
|
||||
|
||||
Transfer with when (chatType) {
|
||||
MsgConstant.KCHATTYPEGROUP -> Troop(peerId)
|
||||
|
@ -193,6 +193,8 @@ internal object MessageHelper {
|
||||
hasActionMsg = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LogCenter.log("不支持的消息类型: ${msg["type"].asString}", Level.ERROR)
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
LogCenter.log(e.stackTraceToString(), Level.ERROR)
|
||||
|
@ -3,6 +3,7 @@ package moe.fuqiuluo.shamrock.remote.action.handlers
|
||||
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
|
||||
import moe.fuqiuluo.shamrock.remote.action.ActionSession
|
||||
import moe.fuqiuluo.shamrock.remote.action.IActionHandler
|
||||
import moe.fuqiuluo.shamrock.tools.jsonArray
|
||||
|
||||
internal object SendGroupMessage: IActionHandler() {
|
||||
override suspend fun internalHandle(session: ActionSession): String {
|
||||
@ -11,6 +12,9 @@ internal object SendGroupMessage: IActionHandler() {
|
||||
val autoEscape = session.getBooleanOrDefault("auto_escape", false)
|
||||
val message = session.getString("message")
|
||||
SendMessage(MsgConstant.KCHATTYPEGROUP, groupId, message, autoEscape, echo = session.echo)
|
||||
} else if (session.isObject("message")) {
|
||||
val message = session.getObject("message")
|
||||
SendMessage(MsgConstant.KCHATTYPEGROUP, groupId, listOf( message ).jsonArray, session.echo)
|
||||
} else {
|
||||
val message = session.getArray("message")
|
||||
SendMessage(MsgConstant.KCHATTYPEGROUP, groupId, message, session.echo)
|
||||
|
@ -14,6 +14,7 @@ import moe.fuqiuluo.shamrock.tools.json
|
||||
import moe.fuqiuluo.shamrock.helper.Level
|
||||
import moe.fuqiuluo.shamrock.helper.LogCenter
|
||||
import moe.fuqiuluo.shamrock.tools.EmptyJsonString
|
||||
import moe.fuqiuluo.shamrock.tools.jsonArray
|
||||
|
||||
internal object SendMessage: IActionHandler() {
|
||||
override suspend fun internalHandle(session: ActionSession): String {
|
||||
@ -47,9 +48,12 @@ internal object SendMessage: IActionHandler() {
|
||||
val autoEscape = session.getBooleanOrDefault("auto_escape", false)
|
||||
val message = session.getString("message")
|
||||
invoke(chatType, peerId, message, autoEscape, echo = session.echo, fromId = fromId)
|
||||
} else {
|
||||
} else if (session.isArray("message")) {
|
||||
val message = session.getArray("message")
|
||||
invoke(chatType, peerId, message, session.echo, fromId = fromId)
|
||||
} else {
|
||||
val message = session.getObject("message")
|
||||
invoke(chatType, peerId, listOf( message ).jsonArray, session.echo, fromId = fromId)
|
||||
}
|
||||
} catch (e: ParamsException) {
|
||||
return noParam(e.message!!, session.echo)
|
||||
|
@ -3,6 +3,7 @@ package moe.fuqiuluo.shamrock.remote.action.handlers
|
||||
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
|
||||
import moe.fuqiuluo.shamrock.remote.action.ActionSession
|
||||
import moe.fuqiuluo.shamrock.remote.action.IActionHandler
|
||||
import moe.fuqiuluo.shamrock.tools.jsonArray
|
||||
|
||||
internal object SendPrivateMessage: IActionHandler() {
|
||||
override suspend fun internalHandle(session: ActionSession): String {
|
||||
@ -20,7 +21,7 @@ internal object SendPrivateMessage: IActionHandler() {
|
||||
echo = session.echo,
|
||||
fromId = groupId ?: userId
|
||||
)
|
||||
} else {
|
||||
} else if (session.isArray("message")) {
|
||||
val message = session.getArray("message")
|
||||
SendMessage(
|
||||
chatType = chatTYpe,
|
||||
@ -29,6 +30,15 @@ internal object SendPrivateMessage: IActionHandler() {
|
||||
echo = session.echo,
|
||||
fromId = groupId ?: userId
|
||||
)
|
||||
} else {
|
||||
val message = session.getObject("message")
|
||||
SendMessage(
|
||||
chatType = chatTYpe,
|
||||
peerId = userId,
|
||||
message = listOf( message ).jsonArray,
|
||||
echo = session.echo,
|
||||
fromId = groupId ?: userId
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,12 +17,15 @@ import moe.fuqiuluo.shamrock.tools.fetchGetOrThrow
|
||||
import moe.fuqiuluo.shamrock.tools.fetchOrNull
|
||||
import moe.fuqiuluo.shamrock.tools.fetchOrThrow
|
||||
import moe.fuqiuluo.shamrock.tools.fetchPostJsonArray
|
||||
import moe.fuqiuluo.shamrock.tools.fetchPostJsonObject
|
||||
import moe.fuqiuluo.shamrock.tools.fetchPostJsonString
|
||||
import moe.fuqiuluo.shamrock.tools.fetchPostOrNull
|
||||
import moe.fuqiuluo.shamrock.tools.fetchPostOrThrow
|
||||
import moe.fuqiuluo.shamrock.tools.getOrPost
|
||||
import moe.fuqiuluo.shamrock.tools.isJsonData
|
||||
import moe.fuqiuluo.shamrock.tools.isJsonObject
|
||||
import moe.fuqiuluo.shamrock.tools.isJsonString
|
||||
import moe.fuqiuluo.shamrock.tools.jsonArray
|
||||
import moe.fuqiuluo.shamrock.tools.respond
|
||||
|
||||
fun Routing.messageAction() {
|
||||
@ -116,20 +119,30 @@ fun Routing.messageAction() {
|
||||
|
||||
val userId = fetchPostOrNull("user_id")
|
||||
val groupId = fetchPostOrNull("group_id")
|
||||
val peerId = if (chatType == MsgConstant.KCHATTYPEC2C) userId!! else groupId!!
|
||||
|
||||
call.respondText(if (isJsonData() && !isJsonString("message")) {
|
||||
if (isJsonObject("message")) {
|
||||
SendMessage(
|
||||
chatType = chatType,
|
||||
peerId = if (chatType == MsgConstant.KCHATTYPEC2C) userId!! else groupId!!,
|
||||
peerId = peerId,
|
||||
message = listOf(fetchPostJsonObject("message")).jsonArray,
|
||||
fromId = groupId ?: userId ?: ""
|
||||
)
|
||||
} else {
|
||||
SendMessage(
|
||||
chatType = chatType,
|
||||
peerId = peerId,
|
||||
message = fetchPostJsonArray("message"),
|
||||
fromId = groupId ?: userId ?: ""
|
||||
)
|
||||
}
|
||||
} else {
|
||||
val autoEscape = fetchPostOrNull("auto_escape")?.toBooleanStrict() ?: false
|
||||
//SendMessage(chatType, peerId, fetchPostOrThrow("message"), autoEscape)
|
||||
SendMessage(
|
||||
chatType = chatType,
|
||||
peerId = if (chatType == MsgConstant.KCHATTYPEC2C) userId!! else groupId!!,
|
||||
peerId = peerId,
|
||||
message = fetchPostOrThrow("message"),
|
||||
autoEscape = autoEscape,
|
||||
fromId = groupId ?: userId ?: ""
|
||||
@ -154,7 +167,19 @@ fun Routing.messageAction() {
|
||||
if (isJsonString("message")) {
|
||||
SendMessage(MsgConstant.KCHATTYPEGROUP, groupId, fetchPostJsonString("message"), autoEscape)
|
||||
} else {
|
||||
SendMessage(MsgConstant.KCHATTYPEGROUP, groupId, fetchPostJsonArray("message"))
|
||||
if (isJsonObject("message")) {
|
||||
SendMessage(
|
||||
chatType = MsgConstant.KCHATTYPEGROUP,
|
||||
peerId = groupId,
|
||||
message = listOf(fetchPostJsonObject("message")).jsonArray
|
||||
)
|
||||
} else {
|
||||
SendMessage(
|
||||
chatType = MsgConstant.KCHATTYPEGROUP,
|
||||
peerId = groupId,
|
||||
message = fetchPostJsonArray("message")
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SendMessage(MsgConstant.KCHATTYPEGROUP, groupId, fetchPostOrThrow("message"), autoEscape)
|
||||
@ -183,27 +208,43 @@ fun Routing.messageAction() {
|
||||
val groupId = fetchPostOrNull("group_id")
|
||||
val autoEscape = fetchPostOrNull("auto_escape")?.toBooleanStrict() ?: false
|
||||
|
||||
val chatType = if (groupId == null) MsgConstant.KCHATTYPEC2C else MsgConstant.KCHATTYPETEMPC2CFROMGROUP
|
||||
val fromId = groupId ?: userId
|
||||
|
||||
|
||||
val result = if (isJsonData()) {
|
||||
if (isJsonString("message")) {
|
||||
SendMessage(
|
||||
chatType = if (groupId == null) MsgConstant.KCHATTYPEC2C else MsgConstant.KCHATTYPETEMPC2CFROMGROUP,
|
||||
userId,
|
||||
fetchPostJsonString("message"),
|
||||
autoEscape
|
||||
chatType = chatType,
|
||||
peerId = userId,
|
||||
message = fetchPostJsonString("message"),
|
||||
autoEscape = autoEscape,
|
||||
fromId = fromId
|
||||
)
|
||||
} else {
|
||||
if (isJsonObject("message")) {
|
||||
SendMessage(
|
||||
chatType = chatType,
|
||||
peerId = userId,
|
||||
message = listOf(fetchPostJsonObject("message")).jsonArray,
|
||||
fromId = fromId
|
||||
)
|
||||
} else {
|
||||
SendMessage(
|
||||
chatType = if (groupId == null) MsgConstant.KCHATTYPEC2C else MsgConstant.KCHATTYPETEMPC2CFROMGROUP,
|
||||
userId,
|
||||
fetchPostJsonArray("message")
|
||||
chatType = chatType,
|
||||
peerId = userId,
|
||||
message = fetchPostJsonArray("message"),
|
||||
fromId = fromId
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SendMessage(
|
||||
chatType = if (groupId == null) MsgConstant.KCHATTYPEC2C else MsgConstant.KCHATTYPETEMPC2CFROMGROUP,
|
||||
userId,
|
||||
fetchPostOrThrow("message"),
|
||||
autoEscape
|
||||
chatType = chatType,
|
||||
peerId = userId,
|
||||
message = fetchPostOrThrow("message"),
|
||||
autoEscape = autoEscape,
|
||||
fromId = fromId
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user