mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
fix
This commit is contained in:
parent
a78b5cab23
commit
3e03d4782d
@ -2,6 +2,8 @@ package moe.fuqiuluo.shamrock.remote.action.handlers
|
|||||||
|
|
||||||
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
|
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
|
||||||
import com.tencent.qqnt.kernel.nativeinterface.MsgRecord
|
import com.tencent.qqnt.kernel.nativeinterface.MsgRecord
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.serialization.json.JsonArray
|
import kotlinx.serialization.json.JsonArray
|
||||||
import kotlinx.serialization.json.JsonElement
|
import kotlinx.serialization.json.JsonElement
|
||||||
import kotlinx.serialization.json.JsonPrimitive
|
import kotlinx.serialization.json.JsonPrimitive
|
||||||
@ -13,20 +15,19 @@ import moe.fuqiuluo.shamrock.helper.LogCenter
|
|||||||
import moe.fuqiuluo.shamrock.helper.MessageHelper
|
import moe.fuqiuluo.shamrock.helper.MessageHelper
|
||||||
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.remote.service.HttpService
|
|
||||||
import moe.fuqiuluo.shamrock.tools.asBoolean
|
|
||||||
import moe.fuqiuluo.shamrock.tools.asBooleanOrNull
|
import moe.fuqiuluo.shamrock.tools.asBooleanOrNull
|
||||||
import moe.fuqiuluo.shamrock.tools.asInt
|
import moe.fuqiuluo.shamrock.tools.asInt
|
||||||
import moe.fuqiuluo.shamrock.tools.asIntOrNull
|
import moe.fuqiuluo.shamrock.tools.asIntOrNull
|
||||||
import moe.fuqiuluo.shamrock.tools.asJsonObject
|
import moe.fuqiuluo.shamrock.tools.asJsonObject
|
||||||
import moe.fuqiuluo.shamrock.tools.asLong
|
|
||||||
import moe.fuqiuluo.shamrock.tools.asString
|
import moe.fuqiuluo.shamrock.tools.asString
|
||||||
import moe.fuqiuluo.shamrock.tools.json
|
import moe.fuqiuluo.shamrock.tools.json
|
||||||
import moe.fuqiuluo.shamrock.tools.jsonArray
|
import moe.fuqiuluo.shamrock.tools.jsonArray
|
||||||
import moe.fuqiuluo.symbols.OneBotHandler
|
import moe.fuqiuluo.symbols.OneBotHandler
|
||||||
|
import java.util.Timer
|
||||||
|
import kotlin.concurrent.timerTask
|
||||||
|
|
||||||
@OneBotHandler(".handle_quick_operation_async")
|
@OneBotHandler(".handle_quick_operation_async")
|
||||||
internal object QuickOperation: IActionHandler() {
|
internal object QuickOperation : IActionHandler() {
|
||||||
val actionMsgTypes = arrayOf(
|
val actionMsgTypes = arrayOf(
|
||||||
"record", "voice", "video", "markdown"
|
"record", "voice", "video", "markdown"
|
||||||
)
|
)
|
||||||
@ -51,36 +52,27 @@ internal object QuickOperation: IActionHandler() {
|
|||||||
|
|
||||||
if (operation.containsKey("reply")) {
|
if (operation.containsKey("reply")) {
|
||||||
LogCenter.log({ "websocket quickly reply successfully" }, Level.DEBUG)
|
LogCenter.log({ "websocket quickly reply successfully" }, Level.DEBUG)
|
||||||
val autoEscape = operation["auto_escape"].asBooleanOrNull ?: false
|
val autoEscape = operation["auto_escape"].asBooleanOrNull
|
||||||
val atSender = operation["at_sender"].asBooleanOrNull ?: false
|
val atSender = operation["at_sender"].asBooleanOrNull ?: false
|
||||||
val autoReply = operation["auto_reply"].asBooleanOrNull ?: true
|
val autoReply = operation["auto_reply"].asBooleanOrNull ?: true
|
||||||
val message = operation["reply"]
|
val message = operation["reply"]
|
||||||
if (message is JsonPrimitive) {
|
if (message is JsonPrimitive) {
|
||||||
if (autoEscape) {
|
quicklyReply(
|
||||||
val msgList = mutableSetOf<JsonElement>()
|
record,
|
||||||
msgList.add(mapOf(
|
if (autoEscape == true)
|
||||||
"type" to "text",
|
listOf(
|
||||||
"data" to mapOf(
|
mapOf(
|
||||||
"text" to message.asString
|
"type" to "text",
|
||||||
)
|
"data" to mapOf(
|
||||||
).json)
|
"text" to message.asString
|
||||||
quicklyReply(
|
)
|
||||||
record,
|
)
|
||||||
msgList.jsonArray,
|
).json
|
||||||
msgHash,
|
else MessageHelper.decodeCQCode(message.asString),
|
||||||
atSender,
|
msgHash,
|
||||||
autoReply
|
atSender,
|
||||||
)
|
autoReply
|
||||||
} else {
|
)
|
||||||
val messageArray = MessageHelper.decodeCQCode(message.asString)
|
|
||||||
quicklyReply(
|
|
||||||
record,
|
|
||||||
messageArray,
|
|
||||||
msgHash,
|
|
||||||
atSender,
|
|
||||||
autoReply
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else if (message is JsonArray) {
|
} else if (message is JsonArray) {
|
||||||
quicklyReply(
|
quicklyReply(
|
||||||
record,
|
record,
|
||||||
@ -92,17 +84,20 @@ internal object QuickOperation: IActionHandler() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MsgConstant.KCHATTYPEGROUP == record.chatType && operation.containsKey("delete") && operation["delete"].asBoolean) {
|
if (MsgConstant.KCHATTYPEGROUP == record.chatType && operation["delete"].asBooleanOrNull == true) {
|
||||||
Timer().schedule(object : TimerTask() {
|
val duration = operation["delay"].asIntOrNull
|
||||||
override fun run() {
|
if (duration != null) {
|
||||||
MsgSvc.recallMsg(msgHash)
|
Timer().schedule(timerTask {
|
||||||
}
|
GlobalScope.launch { MsgSvc.recallMsg(msgHash) }
|
||||||
}, operation['delete_delay'].asIntOrNull?.toUInt() ?: 0)
|
}, duration.toLong())
|
||||||
|
} else {
|
||||||
|
MsgSvc.recallMsg(msgHash)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (MsgConstant.KCHATTYPEGROUP == record.chatType && operation.containsKey("kick") && operation["kick"].asBoolean) {
|
if (MsgConstant.KCHATTYPEGROUP == record.chatType && operation["kick"].asBooleanOrNull == true) {
|
||||||
GroupSvc.kickMember(record.peerUin, false, "", record.senderUin)
|
GroupSvc.kickMember(record.peerUin, false, "", record.senderUin)
|
||||||
}
|
}
|
||||||
if (MsgConstant.KCHATTYPEGROUP == record.chatType && operation.containsKey("ban") && operation["ban"].asBoolean) {
|
if (MsgConstant.KCHATTYPEGROUP == record.chatType && operation["ban"].asBooleanOrNull == true) {
|
||||||
val banTime = operation["ban_duration"].asIntOrNull ?: (30 * 60)
|
val banTime = operation["ban_duration"].asIntOrNull ?: (30 * 60)
|
||||||
if (banTime <= 0) return logic("禁言时间必须大于0", session.echo)
|
if (banTime <= 0) return logic("禁言时间必须大于0", session.echo)
|
||||||
GroupSvc.banMember(record.peerUin, record.senderUin, banTime)
|
GroupSvc.banMember(record.peerUin, record.senderUin, banTime)
|
||||||
@ -132,19 +127,23 @@ internal object QuickOperation: IActionHandler() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (autoReply) messageList.add(mapOf(
|
if (autoReply) messageList.add(
|
||||||
"type" to "reply",
|
mapOf(
|
||||||
"data" to mapOf(
|
"type" to "reply",
|
||||||
"id" to msgHash
|
|
||||||
)
|
|
||||||
).json) // 添加回复
|
|
||||||
if (MsgConstant.KCHATTYPEGROUP == record.chatType && atSender) {
|
|
||||||
messageList.add(mapOf(
|
|
||||||
"type" to "at",
|
|
||||||
"data" to mapOf(
|
"data" to mapOf(
|
||||||
"qq" to record.senderUin
|
"id" to msgHash
|
||||||
)
|
)
|
||||||
).json) // 添加@发送者
|
).json
|
||||||
|
) // 添加回复
|
||||||
|
if (MsgConstant.KCHATTYPEGROUP == record.chatType && atSender) {
|
||||||
|
messageList.add(
|
||||||
|
mapOf(
|
||||||
|
"type" to "at",
|
||||||
|
"data" to mapOf(
|
||||||
|
"qq" to record.senderUin
|
||||||
|
)
|
||||||
|
).json
|
||||||
|
) // 添加@发送者
|
||||||
}
|
}
|
||||||
messageList.addAll(message)
|
messageList.addAll(message)
|
||||||
MsgSvc.sendToAio(record.chatType, record.peerUin.toString(), JsonArray(messageList), retryCnt = 3)
|
MsgSvc.sendToAio(record.chatType, record.peerUin.toString(), JsonArray(messageList), retryCnt = 3)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user