Shamrock: 支持NTQQ骰子消息(new_dice)

This commit is contained in:
WhiteChi 2023-11-29 22:11:36 +08:00
parent 64c800c945
commit 3a0dc41329
5 changed files with 46 additions and 6 deletions

View File

@ -99,6 +99,8 @@ void decode_cqcode(const std::string& code, std::vector<std::unordered_map<std::
replace_string(cache, "&#93;", "]"); replace_string(cache, "&#93;", "]");
replace_string(cache, "&#44;", ","); replace_string(cache, "&#44;", ",");
kv.emplace(key_tmp, cache); kv.emplace(key_tmp, cache);
} else {
kv.emplace("_type", cache);
} }
dest.push_back(kv); dest.push_back(kv);
kv.clear(); kv.clear();

View File

@ -70,6 +70,8 @@ import tencent.im.oidb.cmd0xdc2.oidb_cmd0xdc2
import tencent.im.oidb.oidb_sso import tencent.im.oidb.oidb_sso
import java.io.File import java.io.File
import kotlin.math.roundToInt import kotlin.math.roundToInt
import kotlin.random.Random
import kotlin.random.nextInt
internal typealias IMaker = suspend (Int, Long, String, JsonObject) -> Result<MsgElement> internal typealias IMaker = suspend (Int, Long, String, JsonObject) -> Result<MsgElement>
@ -96,6 +98,7 @@ internal object MessageMaker {
"touch" to MessageMaker::createTouchElem, "touch" to MessageMaker::createTouchElem,
"weather" to MessageMaker::createWeatherElem, "weather" to MessageMaker::createWeatherElem,
"json" to MessageMaker::createJsonElem, "json" to MessageMaker::createJsonElem,
"new_dice" to MessageMaker::createNewDiceElem,
//"node" to MessageMaker::createNodeElem, //"node" to MessageMaker::createNodeElem,
//"multi_msg" to MessageMaker::createLongMsgStruct, //"multi_msg" to MessageMaker::createLongMsgStruct,
) )
@ -111,6 +114,24 @@ internal object MessageMaker {
// //
// } // }
private suspend fun createNewDiceElem(chatType: Int, msgId: Long, peerId: String, data: JsonObject): Result<MsgElement> {
val elem = MsgElement()
elem.elementType = MsgConstant.KELEMTYPEFACE
val face = FaceElement()
face.faceIndex = 358
face.faceText = "/骰子"
face.faceType = 3
face.packId = "1"
face.stickerId = "33"
face.sourceType = 1
face.stickerType = 2
face.resultId = ""
face.surpriseId = ""
face.randomType = 1
elem.faceElement = face
return Result.success(elem)
}
private suspend fun createJsonElem( private suspend fun createJsonElem(
chatType: Int, chatType: Int,
msgId: Long, msgId: Long,

View File

@ -55,6 +55,15 @@ internal sealed class MessageElemConverter: IMessageConvert {
) )
) )
} }
if (face.faceIndex == 358) {
if (face.sourceType == 1) return MessageSegment("new_dice")
return MessageSegment(
type = "new_dice",
data = hashMapOf(
"id" to face.resultId.ifEmpty { "0" }.toInt()
)
)
}
return MessageSegment( return MessageSegment(
type = "face", type = "face",
data = hashMapOf( data = hashMapOf(

View File

@ -6,6 +6,7 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch 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.JsonObject
import moe.fuqiuluo.qqinterface.servlet.MsgSvc import moe.fuqiuluo.qqinterface.servlet.MsgSvc
import moe.fuqiuluo.qqinterface.servlet.TicketSvc import moe.fuqiuluo.qqinterface.servlet.TicketSvc
import moe.fuqiuluo.qqinterface.servlet.msg.convert.toSegments import moe.fuqiuluo.qqinterface.servlet.msg.convert.toSegments
@ -93,7 +94,7 @@ internal object SendForwardMessage : IActionHandler() {
if (data["content"] is JsonArray) { if (data["content"] is JsonArray) {
data["content"].asJsonArray.forEach { msg -> data["content"].asJsonArray.forEach { msg ->
if (msg.asJsonObject["type"].asStringOrNull == "node") { if (msg.asJsonObject["type"].asStringOrNull == "node") {
LogCenter.log("合并转发消息不支持嵌套", Level.ERROR) LogCenter.log("合并转发消息不支持嵌套", Level.WARN)
return@map ForwardMsgNode.EmptyNode return@map ForwardMsgNode.EmptyNode
} }
} }
@ -135,7 +136,9 @@ internal object SendForwardMessage : IActionHandler() {
msgId = MessageHelper.sendMessageWithMsgId(MsgConstant.KCHATTYPEC2C, msgId = MessageHelper.sendMessageWithMsgId(MsgConstant.KCHATTYPEC2C,
selfUin, selfUin,
node.content!!.let { msg -> node.content!!.let { msg ->
if (msg is JsonArray) msg else MessageHelper.decodeCQCode(msg.asString) if (msg is JsonArray) msg
else if (msg is JsonObject) listOf(msg).jsonArray
else MessageHelper.decodeCQCode(msg.asString)
}, },
{ code, why -> { code, why ->
if (code != 0) { if (code != 0) {
@ -143,6 +146,10 @@ internal object SendForwardMessage : IActionHandler() {
} }
it.resume(node.name to msgId) it.resume(node.name to msgId)
}).first }).first
}.invokeOnCompletion {
it?.let {
LogCenter.log("合并转发消息节点消息发送失败:${it.stackTraceToString()}", Level.ERROR)
}
} }
} }
} }

View File

@ -119,6 +119,10 @@ internal object AioListener: IKernelMsgListener {
} }
} }
override fun onMsgRecall(chatType: Int, peerId: String, msgId: Long) {
LogCenter.log("onMsgRecall($chatType, $peerId, $msgId)")
}
override fun onAddSendMsg(record: MsgRecord) { override fun onAddSendMsg(record: MsgRecord) {
if (record.chatType == MsgConstant.KCHATTYPEGUILD) return // TODO: 频道消息暂不处理 if (record.chatType == MsgConstant.KCHATTYPEGUILD) return // TODO: 频道消息暂不处理
if (record.peerUin == TicketSvc.getLongUin()) return // 发给自己的消息不处理 if (record.peerUin == TicketSvc.getLongUin()) return // 发给自己的消息不处理
@ -181,6 +185,7 @@ internal object AioListener: IKernelMsgListener {
val rawMsg = record.elements.toCQCode(record.chatType, record.peerUin.toString()) val rawMsg = record.elements.toCQCode(record.chatType, record.peerUin.toString())
if (rawMsg.isEmpty()) return@launch if (rawMsg.isEmpty()) return@launch
LogCenter.log("自发消息(target = ${record.peerUin}, id = $msgHash, msg = $rawMsg)")
when (record.chatType) { when (record.chatType) {
MsgConstant.KCHATTYPEGROUP -> { MsgConstant.KCHATTYPEGROUP -> {
@ -441,10 +446,6 @@ internal object AioListener: IKernelMsgListener {
} }
override fun onMsgRecall(chatType: Int, peerId: String?, msgId: Long) {
LogCenter.log("onMsgRecall($chatType, $peerId, $msgId)")
}
override fun onMsgSecurityNotify(msgRecord: MsgRecord?) { override fun onMsgSecurityNotify(msgRecord: MsgRecord?) {
LogCenter.log("onMsgSecurityNotify($msgRecord)") LogCenter.log("onMsgSecurityNotify($msgRecord)")
} }