mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
Shamrock
: 支持NTQQ骰子消息(new_dice
)
This commit is contained in:
parent
64c800c945
commit
3a0dc41329
@ -99,6 +99,8 @@ void decode_cqcode(const std::string& code, std::vector<std::unordered_map<std::
|
||||
replace_string(cache, "]", "]");
|
||||
replace_string(cache, ",", ",");
|
||||
kv.emplace(key_tmp, cache);
|
||||
} else {
|
||||
kv.emplace("_type", cache);
|
||||
}
|
||||
dest.push_back(kv);
|
||||
kv.clear();
|
||||
|
@ -70,6 +70,8 @@ import tencent.im.oidb.cmd0xdc2.oidb_cmd0xdc2
|
||||
import tencent.im.oidb.oidb_sso
|
||||
import java.io.File
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.random.Random
|
||||
import kotlin.random.nextInt
|
||||
|
||||
internal typealias IMaker = suspend (Int, Long, String, JsonObject) -> Result<MsgElement>
|
||||
|
||||
@ -96,6 +98,7 @@ internal object MessageMaker {
|
||||
"touch" to MessageMaker::createTouchElem,
|
||||
"weather" to MessageMaker::createWeatherElem,
|
||||
"json" to MessageMaker::createJsonElem,
|
||||
"new_dice" to MessageMaker::createNewDiceElem,
|
||||
//"node" to MessageMaker::createNodeElem,
|
||||
//"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(
|
||||
chatType: Int,
|
||||
msgId: Long,
|
||||
|
@ -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(
|
||||
type = "face",
|
||||
data = hashMapOf(
|
||||
|
@ -6,6 +6,7 @@ import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.serialization.json.JsonArray
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import moe.fuqiuluo.qqinterface.servlet.MsgSvc
|
||||
import moe.fuqiuluo.qqinterface.servlet.TicketSvc
|
||||
import moe.fuqiuluo.qqinterface.servlet.msg.convert.toSegments
|
||||
@ -93,7 +94,7 @@ internal object SendForwardMessage : IActionHandler() {
|
||||
if (data["content"] is JsonArray) {
|
||||
data["content"].asJsonArray.forEach { msg ->
|
||||
if (msg.asJsonObject["type"].asStringOrNull == "node") {
|
||||
LogCenter.log("合并转发消息不支持嵌套", Level.ERROR)
|
||||
LogCenter.log("合并转发消息不支持嵌套", Level.WARN)
|
||||
return@map ForwardMsgNode.EmptyNode
|
||||
}
|
||||
}
|
||||
@ -135,7 +136,9 @@ internal object SendForwardMessage : IActionHandler() {
|
||||
msgId = MessageHelper.sendMessageWithMsgId(MsgConstant.KCHATTYPEC2C,
|
||||
selfUin,
|
||||
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 ->
|
||||
if (code != 0) {
|
||||
@ -143,6 +146,10 @@ internal object SendForwardMessage : IActionHandler() {
|
||||
}
|
||||
it.resume(node.name to msgId)
|
||||
}).first
|
||||
}.invokeOnCompletion {
|
||||
it?.let {
|
||||
LogCenter.log("合并转发消息节点消息发送失败:${it.stackTraceToString()}", Level.ERROR)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
if (record.chatType == MsgConstant.KCHATTYPEGUILD) return // TODO: 频道消息暂不处理
|
||||
if (record.peerUin == TicketSvc.getLongUin()) return // 发给自己的消息不处理
|
||||
@ -181,6 +185,7 @@ internal object AioListener: IKernelMsgListener {
|
||||
|
||||
val rawMsg = record.elements.toCQCode(record.chatType, record.peerUin.toString())
|
||||
if (rawMsg.isEmpty()) return@launch
|
||||
LogCenter.log("自发消息(target = ${record.peerUin}, id = $msgHash, msg = $rawMsg)")
|
||||
|
||||
when (record.chatType) {
|
||||
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?) {
|
||||
LogCenter.log("onMsgSecurityNotify($msgRecord)")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user