mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
Shamrock
: fix #169
This commit is contained in:
parent
89a4912ed7
commit
35c82fcc51
@ -7,6 +7,9 @@ import com.tencent.qqnt.kernel.nativeinterface.MsgRecord
|
|||||||
import moe.fuqiuluo.qqinterface.servlet.GroupSvc
|
import moe.fuqiuluo.qqinterface.servlet.GroupSvc
|
||||||
import moe.fuqiuluo.qqinterface.servlet.MsgSvc
|
import moe.fuqiuluo.qqinterface.servlet.MsgSvc
|
||||||
import io.ktor.client.statement.bodyAsText
|
import io.ktor.client.statement.bodyAsText
|
||||||
|
import io.ktor.http.ContentType
|
||||||
|
import io.ktor.server.application.call
|
||||||
|
import io.ktor.server.response.respondText
|
||||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
@ -14,6 +17,7 @@ import kotlinx.coroutines.launch
|
|||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlinx.serialization.json.JsonArray
|
import kotlinx.serialization.json.JsonArray
|
||||||
import kotlinx.serialization.json.JsonElement
|
import kotlinx.serialization.json.JsonElement
|
||||||
|
import kotlinx.serialization.json.JsonObject
|
||||||
import kotlinx.serialization.json.JsonPrimitive
|
import kotlinx.serialization.json.JsonPrimitive
|
||||||
import moe.fuqiuluo.qqinterface.servlet.msg.*
|
import moe.fuqiuluo.qqinterface.servlet.msg.*
|
||||||
import moe.fuqiuluo.shamrock.remote.service.api.HttpTransmitServlet
|
import moe.fuqiuluo.shamrock.remote.service.api.HttpTransmitServlet
|
||||||
@ -21,6 +25,11 @@ import moe.fuqiuluo.shamrock.remote.service.data.push.*
|
|||||||
import moe.fuqiuluo.shamrock.tools.*
|
import moe.fuqiuluo.shamrock.tools.*
|
||||||
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.remote.action.ActionManager
|
||||||
|
import moe.fuqiuluo.shamrock.remote.action.ActionSession
|
||||||
|
import moe.fuqiuluo.shamrock.remote.config.ECHO_KEY
|
||||||
|
import moe.fuqiuluo.shamrock.remote.entries.EmptyObject
|
||||||
|
import moe.fuqiuluo.shamrock.remote.entries.Status
|
||||||
import moe.fuqiuluo.shamrock.remote.service.api.GlobalEventTransmitter
|
import moe.fuqiuluo.shamrock.remote.service.api.GlobalEventTransmitter
|
||||||
|
|
||||||
internal object HttpService: HttpTransmitServlet() {
|
internal object HttpService: HttpTransmitServlet() {
|
||||||
@ -66,65 +75,86 @@ internal object HttpService: HttpTransmitServlet() {
|
|||||||
|
|
||||||
private suspend fun handleQuicklyReply(record: MsgRecord, msgHash: Int, jsonText: String) {
|
private suspend fun handleQuicklyReply(record: MsgRecord, msgHash: Int, jsonText: String) {
|
||||||
try {
|
try {
|
||||||
val data = Json.parseToJsonElement(jsonText).asJsonObject
|
val data = Json.parseToJsonElement(jsonText)
|
||||||
if (data.containsKey("reply")) {
|
|
||||||
LogCenter.log({ "quickly reply successfully" }, Level.DEBUG)
|
if (data is JsonObject) {
|
||||||
val autoEscape = data["auto_escape"].asBooleanOrNull ?: false
|
if (data.containsKey("reply")) {
|
||||||
val atSender = data["at_sender"].asBooleanOrNull ?: false
|
LogCenter.log({ "quickly reply successfully" }, Level.DEBUG)
|
||||||
val autoReply = data["auto_reply"].asBooleanOrNull ?: true
|
val autoEscape = data["auto_escape"].asBooleanOrNull ?: false
|
||||||
val message = data["reply"]
|
val atSender = data["at_sender"].asBooleanOrNull ?: false
|
||||||
if (message is JsonPrimitive) {
|
val autoReply = data["auto_reply"].asBooleanOrNull ?: true
|
||||||
if (autoEscape) {
|
val message = data["reply"]
|
||||||
val msgList = mutableSetOf<JsonElement>()
|
if (message is JsonPrimitive) {
|
||||||
msgList.add(mapOf(
|
if (autoEscape) {
|
||||||
"type" to "text",
|
val msgList = mutableSetOf<JsonElement>()
|
||||||
"data" to mapOf(
|
msgList.add(mapOf(
|
||||||
"text" to message.asString
|
"type" to "text",
|
||||||
|
"data" to mapOf(
|
||||||
|
"text" to message.asString
|
||||||
|
)
|
||||||
|
).json)
|
||||||
|
quicklyReply(
|
||||||
|
record,
|
||||||
|
msgList.jsonArray,
|
||||||
|
msgHash,
|
||||||
|
atSender,
|
||||||
|
autoReply
|
||||||
)
|
)
|
||||||
).json)
|
} else {
|
||||||
|
val messageArray = MessageHelper.decodeCQCode(message.asString)
|
||||||
|
quicklyReply(
|
||||||
|
record,
|
||||||
|
messageArray,
|
||||||
|
msgHash,
|
||||||
|
atSender,
|
||||||
|
autoReply
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else if (message is JsonArray) {
|
||||||
quicklyReply(
|
quicklyReply(
|
||||||
record,
|
record,
|
||||||
msgList.jsonArray,
|
message,
|
||||||
msgHash,
|
|
||||||
atSender,
|
|
||||||
autoReply
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
val messageArray = MessageHelper.decodeCQCode(message.asString)
|
|
||||||
quicklyReply(
|
|
||||||
record,
|
|
||||||
messageArray,
|
|
||||||
msgHash,
|
msgHash,
|
||||||
atSender,
|
atSender,
|
||||||
autoReply
|
autoReply
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if (message is JsonArray) {
|
|
||||||
quicklyReply(
|
|
||||||
record,
|
|
||||||
message,
|
|
||||||
msgHash,
|
|
||||||
atSender,
|
|
||||||
autoReply
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
if (MsgConstant.KCHATTYPEGROUP == record.chatType && data.containsKey("delete") && data["delete"].asBoolean) {
|
||||||
if (MsgConstant.KCHATTYPEGROUP == record.chatType && data.containsKey("delete") && data["delete"].asBoolean) {
|
MsgSvc.recallMsg(msgHash)
|
||||||
MsgSvc.recallMsg(msgHash)
|
}
|
||||||
}
|
if (MsgConstant.KCHATTYPEGROUP == record.chatType && data.containsKey("kick") && data["kick"].asBoolean) {
|
||||||
if (MsgConstant.KCHATTYPEGROUP == record.chatType && data.containsKey("kick") && data["kick"].asBoolean) {
|
GroupSvc.kickMember(record.peerUin, false, record.senderUin)
|
||||||
GroupSvc.kickMember(record.peerUin, false, record.senderUin)
|
}
|
||||||
}
|
if (MsgConstant.KCHATTYPEGROUP == record.chatType && data.containsKey("ban") && data["ban"].asBoolean) {
|
||||||
if (MsgConstant.KCHATTYPEGROUP == record.chatType && data.containsKey("ban") && data["ban"].asBoolean) {
|
val banTime = data["ban_duration"].asIntOrNull ?: (30 * 60)
|
||||||
val banTime = data["ban_duration"].asIntOrNull ?: (30 * 60)
|
if (banTime <= 0) return
|
||||||
if (banTime <= 0) return
|
GroupSvc.banMember(record.peerUin, record.senderUin, banTime)
|
||||||
GroupSvc.banMember(record.peerUin, record.senderUin, banTime)
|
}
|
||||||
|
} else if (data is JsonArray) {
|
||||||
|
data.forEach {
|
||||||
|
handleQuicklyActions(it.asJsonObject)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
LogCenter.log("处理快速操作错误: $e", Level.WARN)
|
LogCenter.log("处理快速操作错误: $e", Level.WARN)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun handleQuicklyActions(data: JsonObject) {
|
||||||
|
val action = data["action"].asString
|
||||||
|
val echo = data["echo"] ?: EmptyJsonString
|
||||||
|
|
||||||
|
val params = data["params"].asJsonObjectOrNull ?: EmptyJsonObject
|
||||||
|
|
||||||
|
val handler = ActionManager[action]
|
||||||
|
if (handler == null) {
|
||||||
|
LogCenter.log("HTTP快速操作:不支持的Action: $action", Level.WARN)
|
||||||
|
} else {
|
||||||
|
handler.handle(ActionSession(params, echo))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun quicklyReply(
|
private suspend fun quicklyReply(
|
||||||
record: MsgRecord,
|
record: MsgRecord,
|
||||||
message: JsonArray,
|
message: JsonArray,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user