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