fix buttons

This commit is contained in:
Simplxs 2024-02-28 22:00:41 +08:00
parent 352aa5f737
commit 12d594697d
No known key found for this signature in database
GPG Key ID: 8BD9E2834B275BD3
4 changed files with 26 additions and 61 deletions

View File

@ -10,8 +10,8 @@ import kotlinx.serialization.protobuf.ProtoNumber
data class RichText( data class RichText(
@ProtoNumber(1) val attr: Attr? = null, @ProtoNumber(1) val attr: Attr? = null,
@ProtoNumber(2) var elements: List<Elem>? = null, @ProtoNumber(2) var elements: List<Elem>? = null,
@ProtoNumber(3) val not_online_file: NotOnlineFile? = null, @ProtoNumber(3) var not_online_file: NotOnlineFile? = null,
@ProtoNumber(4) val ptt: Ptt? = null, @ProtoNumber(4) var ptt: Ptt? = null,
@ProtoNumber(5) val tmp_ptt: TmpPtt? = null, @ProtoNumber(5) val tmp_ptt: TmpPtt? = null,
@ProtoNumber(6) val trans_211_tmp_msg: Trans211TmpMsg? = null, @ProtoNumber(6) val trans_211_tmp_msg: Trans211TmpMsg? = null,
) )

View File

@ -206,53 +206,6 @@ internal object ElemConverter {
throw UnknownError("no segment") throw UnknownError("no segment")
} }
//
// /**
// * 语音消息转换消息段
// */
// private suspend fun convertVoiceElem(
// chatType: Int,
// peerId: String,
// subPeer: String,
// element: Elem
// ): MessageSegment {
// val record = element.pttElement
//
// val md5 = if (record.fileName.startsWith("silk"))
// record.fileName.substring(5)
// else record.md5HexStr
//
// return MessageSegment(
// type = "record",
// data = mapOf(
// "file" to md5,
// "url" to when (chatType) {
// MsgConstant.KCHATTYPEGROUP -> RichProtoSvc.getGroupPttDownUrl(
// "0",
// record.md5HexStr,
// record.fileUuid
// )
//
// MsgConstant.KCHATTYPEC2C -> RichProtoSvc.getC2CPttDownUrl("0", record.fileUuid)
// MsgConstant.KCHATTYPEGUILD -> RichProtoSvc.getGroupPttDownUrl(
// "0",
// record.md5HexStr,
// record.fileUuid
// )
//
// else -> throw UnsupportedOperationException("Not supported chat type: $chatType")
// }
// ).also {
// if (record.voiceChangeType != MsgConstant.KPTTVOICECHANGETYPENONE) {
// it["magic"] = "1"
// }
// if ((it["url"] as String).isBlank()) {
// it.remove("url")
// }
// }
// )
// }
//
// /** // /**
// * 视频消息转换消息段 // * 视频消息转换消息段
// */ // */
@ -354,7 +307,6 @@ internal object ElemConverter {
): MessageSegment { ): MessageSegment {
val data = element.lightApp!!.data!! val data = element.lightApp!!.data!!
val jsonStr = String(if (data[0].toInt() == 1) DeflateTools.uncompress(data.slice(1)) else data.slice(1)) val jsonStr = String(if (data[0].toInt() == 1) DeflateTools.uncompress(data.slice(1)) else data.slice(1))
LogCenter.log(jsonStr, Level.DEBUG)
val json = jsonStr.asJsonObject val json = jsonStr.asJsonObject
return when (json["app"].asString) { return when (json["app"].asString) {
"com.tencent.multimsg" -> { "com.tencent.multimsg" -> {

View File

@ -20,6 +20,7 @@ import moe.fuqiuluo.shamrock.utils.DeflateTools
import moe.fuqiuluo.shamrock.utils.FileUtils import moe.fuqiuluo.shamrock.utils.FileUtils
import protobuf.auto.toByteArray import protobuf.auto.toByteArray
import protobuf.message.Elem import protobuf.message.Elem
import protobuf.message.Ptt
import protobuf.message.RichText import protobuf.message.RichText
import protobuf.message.element.* import protobuf.message.element.*
import protobuf.message.element.commelem.* import protobuf.message.element.commelem.*
@ -40,10 +41,9 @@ internal class ElemMaker {
"face" to ElemMaker::createFaceElem, "face" to ElemMaker::createFaceElem,
"pic" to ElemMaker::createImageElem, "pic" to ElemMaker::createImageElem,
"image" to ElemMaker::createImageElem, "image" to ElemMaker::createImageElem,
// "voice" to ElemMaker::createRecordElem, "reply" to ElemMaker::createReplyElem,
// "record" to ElemMaker::createRecordElem,
// "video" to ElemMaker::createVideoElem,
"forward" to ElemMaker::createForwardStruct, "forward" to ElemMaker::createForwardStruct,
"weather" to ElemMaker::createWeatherElem,
"json" to ElemMaker::createJsonElem, "json" to ElemMaker::createJsonElem,
"poke" to ElemMaker::createPokeElem, "poke" to ElemMaker::createPokeElem,
"dice" to ElemMaker::createNewDiceElem, "dice" to ElemMaker::createNewDiceElem,
@ -55,12 +55,12 @@ internal class ElemMaker {
// "contact" to ElemMaker::createContactElem, // "contact" to ElemMaker::createContactElem,
// "location" to ElemMaker::createLocationElem, // "location" to ElemMaker::createLocationElem,
// "music" to ElemMaker::createMusicElem, // "music" to ElemMaker::createMusicElem,
"reply" to ElemMaker::createReplyElem,
// "touch" to ElemMaker::createTouchElem, // "touch" to ElemMaker::createTouchElem,
"weather" to ElemMaker::createWeatherElem, // "multi_msg" to MessageMaker::createLongMsgStruct,
//"forward" to MessageMaker::createForwardElem, // "bubble_face" to ElemMaker::createBubbleFaceElem,
//"multi_msg" to MessageMaker::createLongMsgStruct, "voice" to ElemMaker::createRecordElem,
//"bubble_face" to ElemMaker::createBubbleFaceElem, "record" to ElemMaker::createRecordElem,
// "video" to ElemMaker::createVideoElem,
) )
operator fun get(type: String): IElemMaker? = makerArray[type] operator fun get(type: String): IElemMaker? = makerArray[type]
@ -627,8 +627,8 @@ internal class ElemMaker {
serviceType = 46, serviceType = 46,
elem = ButtonExtra( elem = ButtonExtra(
field1 = Object1( field1 = Object1(
rows = data["buttons"].asJsonArray.map { row -> rows = data["rows"].asJsonArray.map { row ->
Row(buttons = row.asJsonArray.map { Row(buttons = row.asJsonObject["buttons"].asJsonArray.map {
val button = it.asJsonObject val button = it.asJsonObject
val renderData = button["render_data"].asJsonObject val renderData = button["render_data"].asJsonObject
val action = button["action"].asJsonObject val action = button["action"].asJsonObject
@ -665,6 +665,19 @@ internal class ElemMaker {
desc += "[Button消息]" desc += "[Button消息]"
} }
private suspend fun createRecordElem(
chatType: Int,
msgId: Long,
peerId: String,
data: JsonObject
) {
data.checkAndThrow("content")
rich.ptt= Ptt(
)
desc += "[语音消息]"
}
private fun JsonObject.checkAndThrow(vararg key: String) { private fun JsonObject.checkAndThrow(vararg key: String) {
key.forEach { key.forEach {
if (!containsKey(it)) throw ParamsException(it) if (!containsKey(it)) throw ParamsException(it)

View File

@ -221,7 +221,7 @@ internal object NtMsgElementMaker {
} }
rows.add(InlineKeyboardRow(buttons)) rows.add(InlineKeyboardRow(buttons))
} }
elem.inlineKeyboardElement = InlineKeyboardElement(rows, keyboard["bot_appid"].asLong) elem.inlineKeyboardElement = InlineKeyboardElement(rows, keyboard["appid"].asLong)
return Result.success(elem) return Result.success(elem)
} }