mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 05:12:17 +00:00
Compare commits
3 Commits
df02f9f872
...
042f4bd330
Author | SHA1 | Date | |
---|---|---|---|
042f4bd330 | |||
9aef71b09f | |||
9cbe755520 |
@ -1,11 +1,13 @@
|
||||
package qq.service.msg
|
||||
|
||||
import com.google.protobuf.ByteString
|
||||
import com.tencent.mobileqq.qroute.QRoute
|
||||
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
|
||||
import com.tencent.qqnt.kernel.nativeinterface.MsgElement
|
||||
import com.tencent.qqnt.kernel.nativeinterface.MsgRecord
|
||||
import com.tencent.qqnt.msg.api.IMsgService
|
||||
import io.kritor.common.*
|
||||
import io.kritor.common.Element.ElementType
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import moe.fuqiuluo.shamrock.helper.ActionMsgException
|
||||
@ -55,11 +57,13 @@ private object MsgConvertor {
|
||||
val text = element.textElement
|
||||
val elem = Element.newBuilder()
|
||||
if (text.atType != MsgConstant.ATTYPEUNKNOWN) {
|
||||
elem.type = ElementType.AT
|
||||
elem.setAt(AtElement.newBuilder().apply {
|
||||
this.uid = text.atNtUid
|
||||
this.uin = ContactHelper.getUinByUidAsync(text.atNtUid).toLong()
|
||||
})
|
||||
} else {
|
||||
elem.type = ElementType.TEXT
|
||||
elem.setText(TextElement.newBuilder().apply {
|
||||
this.text = text.content
|
||||
})
|
||||
@ -71,6 +75,7 @@ private object MsgConvertor {
|
||||
val face = element.faceElement
|
||||
val elem = Element.newBuilder()
|
||||
if (face.faceType == 5) {
|
||||
elem.type = ElementType.POKE
|
||||
elem.setPoke(PokeElement.newBuilder().apply {
|
||||
this.id = face.vaspokeId
|
||||
this.type = face.pokeType
|
||||
@ -78,30 +83,45 @@ private object MsgConvertor {
|
||||
})
|
||||
} else {
|
||||
when (face.faceIndex) {
|
||||
114 -> elem.setBasketball(BasketballElement.newBuilder().apply {
|
||||
114 -> {
|
||||
elem.type = ElementType.BASKETBALL
|
||||
elem.setBasketball(BasketballElement.newBuilder().apply {
|
||||
this.id = face.resultId.ifNullOrEmpty { "0" }?.toInt() ?: 0
|
||||
})
|
||||
}
|
||||
|
||||
358 -> elem.setDice(DiceElement.newBuilder().apply {
|
||||
358 -> {
|
||||
elem.type = ElementType.DICE
|
||||
elem.setDice(DiceElement.newBuilder().apply {
|
||||
this.id = face.resultId.ifNullOrEmpty { "0" }?.toInt() ?: 0
|
||||
})
|
||||
}
|
||||
|
||||
359 -> elem.setRps(RpsElement.newBuilder().apply {
|
||||
359 -> {
|
||||
elem.type = ElementType.RPS
|
||||
elem.setRps(RpsElement.newBuilder().apply {
|
||||
this.id = face.resultId.ifNullOrEmpty { "0" }?.toInt() ?: 0
|
||||
})
|
||||
}
|
||||
|
||||
394 -> elem.setFace(FaceElement.newBuilder().apply {
|
||||
394 -> {
|
||||
elem.type = ElementType.FACE
|
||||
elem.setFace(FaceElement.newBuilder().apply {
|
||||
this.id = face.faceIndex
|
||||
this.isBig = face.faceType == 3
|
||||
this.result = face.resultId.ifNullOrEmpty { "1" }?.toInt() ?: 1
|
||||
})
|
||||
}
|
||||
|
||||
else -> elem.setFace(FaceElement.newBuilder().apply {
|
||||
else -> {
|
||||
elem.type = ElementType.FACE
|
||||
elem.setFace(FaceElement.newBuilder().apply {
|
||||
this.id = face.faceIndex
|
||||
this.isBig = face.faceType == 3
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.success(elem.build())
|
||||
}
|
||||
|
||||
@ -134,8 +154,9 @@ private object MsgConvertor {
|
||||
LogCenter.log({ "receive image: $image" }, Level.DEBUG)
|
||||
|
||||
val elem = Element.newBuilder()
|
||||
elem.type = ElementType.IMAGE
|
||||
elem.setImage(ImageElement.newBuilder().apply {
|
||||
this.fileMd5 = md5
|
||||
this.file = ByteString.copyFromUtf8(md5)
|
||||
this.fileUrl = when (record.chatType) {
|
||||
MsgConstant.KCHATTYPEDISC, MsgConstant.KCHATTYPEGROUP -> RichProtoSvc.getGroupPicDownUrl(
|
||||
originalUrl = originalUrl,
|
||||
@ -190,6 +211,7 @@ private object MsgConvertor {
|
||||
ptt.fileName.substring(5)
|
||||
else ptt.md5HexStr
|
||||
|
||||
elem.type = ElementType.VOICE
|
||||
elem.setVoice(VoiceElement.newBuilder().apply {
|
||||
this.fileUrl = when (record.chatType) {
|
||||
MsgConstant.KCHATTYPEC2C -> RichProtoSvc.getC2CPttDownUrl("0", ptt.fileUuid)
|
||||
@ -201,7 +223,7 @@ private object MsgConvertor {
|
||||
|
||||
else -> throw UnsupportedOperationException("Not supported chat type: ${record.chatType}")
|
||||
}
|
||||
this.fileMd5 = md5
|
||||
this.file = ByteString.copyFromUtf8(md5)
|
||||
this.magic = ptt.voiceChangeType != MsgConstant.KPTTVOICECHANGETYPENONE
|
||||
})
|
||||
|
||||
@ -218,8 +240,9 @@ private object MsgConvertor {
|
||||
it[it.size - 2].hex2ByteArray()
|
||||
}
|
||||
} else video.fileName.split(".")[0].hex2ByteArray()
|
||||
elem.type = ElementType.VIDEO
|
||||
elem.setVideo(VideoElement.newBuilder().apply {
|
||||
this.fileMd5 = md5.toHexString()
|
||||
this.file = ByteString.copyFromUtf8(md5.toHexString())
|
||||
this.fileUrl = when (record.chatType) {
|
||||
MsgConstant.KCHATTYPEGROUP -> RichProtoSvc.getGroupVideoDownUrl("0", md5, video.fileUuid)
|
||||
MsgConstant.KCHATTYPEC2C -> RichProtoSvc.getC2CVideoDownUrl("0", md5, video.fileUuid)
|
||||
@ -233,6 +256,7 @@ private object MsgConvertor {
|
||||
suspend fun convertMarketFace(record: MsgRecord, element: MsgElement): Result<Element> {
|
||||
val marketFace = element.marketFaceElement
|
||||
val elem = Element.newBuilder()
|
||||
elem.type = ElementType.MARKET_FACE
|
||||
elem.setMarketFace(MarketFaceElement.newBuilder().apply {
|
||||
this.id = marketFace.emojiId.lowercase()
|
||||
})
|
||||
@ -245,6 +269,7 @@ private object MsgConvertor {
|
||||
when (data["app"].asString) {
|
||||
"com.tencent.multimsg" -> {
|
||||
val info = data["meta"].asJsonObject["detail"].asJsonObject
|
||||
elem.type = ElementType.FORWARD
|
||||
elem.setForward(ForwardElement.newBuilder().apply {
|
||||
this.resId = info["resid"].asString
|
||||
this.uniseq = info["uniseq"].asString
|
||||
@ -257,6 +282,7 @@ private object MsgConvertor {
|
||||
|
||||
"com.tencent.troopsharecard" -> {
|
||||
val info = data["meta"].asJsonObject["contact"].asJsonObject
|
||||
elem.type = ElementType.CONTACT
|
||||
elem.setContact(ContactElement.newBuilder().apply {
|
||||
this.scene = Scene.GROUP
|
||||
this.peer = info["jumpUrl"].asString.split("group_code=")[1]
|
||||
@ -265,6 +291,7 @@ private object MsgConvertor {
|
||||
|
||||
"com.tencent.contact.lua" -> {
|
||||
val info = data["meta"].asJsonObject["contact"].asJsonObject
|
||||
elem.type = ElementType.CONTACT
|
||||
elem.setContact(ContactElement.newBuilder().apply {
|
||||
this.scene = Scene.FRIEND
|
||||
this.peer = info["jumpUrl"].asString.split("uin=")[1]
|
||||
@ -273,6 +300,7 @@ private object MsgConvertor {
|
||||
|
||||
"com.tencent.map" -> {
|
||||
val info = data["meta"].asJsonObject["Location.Search"].asJsonObject
|
||||
elem.type = ElementType.LOCATION
|
||||
elem.setLocation(LocationElement.newBuilder().apply {
|
||||
this.lat = info["lat"].asString.toFloat()
|
||||
this.lon = info["lng"].asString.toFloat()
|
||||
@ -281,16 +309,20 @@ private object MsgConvertor {
|
||||
})
|
||||
}
|
||||
|
||||
else -> elem.setJson(JsonElement.newBuilder().apply {
|
||||
else -> {
|
||||
elem.type = ElementType.JSON
|
||||
elem.setJson(JsonElement.newBuilder().apply {
|
||||
this.json = data.toString()
|
||||
})
|
||||
}
|
||||
}
|
||||
return Result.success(elem.build())
|
||||
}
|
||||
|
||||
suspend fun convertReply(record: MsgRecord, element: MsgElement): Result<Element> {
|
||||
val reply = element.replyElement
|
||||
val elem = Element.newBuilder()
|
||||
elem.type = ElementType.REPLY
|
||||
elem.setReply(ReplyElement.newBuilder().apply {
|
||||
val msgSeq = reply.replayMsgSeq
|
||||
val contact = MessageHelper.generateContact(record)
|
||||
@ -332,6 +364,7 @@ private object MsgConvertor {
|
||||
else -> RichProtoSvc.getGroupFileDownUrl(record.peerUin, fileId, bizId)
|
||||
}
|
||||
val elem = Element.newBuilder()
|
||||
elem.type = ElementType.FILE
|
||||
elem.setFile(FileElement.newBuilder().apply {
|
||||
this.name = fileName
|
||||
this.size = fileSize
|
||||
@ -347,6 +380,7 @@ private object MsgConvertor {
|
||||
suspend fun convertMarkdown(record: MsgRecord, element: MsgElement): Result<Element> {
|
||||
val markdown = element.markdownElement
|
||||
val elem = Element.newBuilder()
|
||||
elem.type = ElementType.MARKDOWN
|
||||
elem.setMarkdown(MarkdownElement.newBuilder().apply {
|
||||
this.markdown = markdown.content
|
||||
})
|
||||
@ -356,6 +390,7 @@ private object MsgConvertor {
|
||||
suspend fun convertBubbleFace(record: MsgRecord, element: MsgElement): Result<Element> {
|
||||
val bubbleFace = element.faceBubbleElement
|
||||
val elem = Element.newBuilder()
|
||||
elem.type = ElementType.BUBBLE_FACE
|
||||
elem.setBubbleFace(BubbleFaceElement.newBuilder().apply {
|
||||
this.id = bubbleFace.yellowFaceInfo.index
|
||||
this.count = bubbleFace.faceCount ?: 1
|
||||
@ -366,6 +401,7 @@ private object MsgConvertor {
|
||||
suspend fun convertInlineKeyboard(record: MsgRecord, element: MsgElement): Result<Element> {
|
||||
val inlineKeyboard = element.inlineKeyboardElement
|
||||
val elem = Element.newBuilder()
|
||||
elem.type = ElementType.BUTTON
|
||||
elem.setButton(ButtonElement.newBuilder().apply {
|
||||
inlineKeyboard.rows.forEach { row ->
|
||||
this.addRows(ButtonRow.newBuilder().apply {
|
||||
|
Reference in New Issue
Block a user