Shamrock: fix markdown parser

This commit is contained in:
白池 2024-02-18 20:28:45 +08:00
parent 4283651b1e
commit 388c963e88
2 changed files with 7 additions and 5 deletions

View File

@ -154,7 +154,9 @@ internal object MessageMaker {
val elem = MsgElement() val elem = MsgElement()
elem.elementType = MsgConstant.KELEMTYPEINLINEKEYBOARD elem.elementType = MsgConstant.KELEMTYPEINLINEKEYBOARD
val rows = arrayListOf<InlineKeyboardRow>() val rows = arrayListOf<InlineKeyboardRow>()
data["rows"].asJsonArray.forEach {
val keyboard = Json.parseToJsonElement(data["data"].asString).asJsonObject
keyboard["rows"].asJsonArray.forEach {
val row = it.asJsonObject val row = it.asJsonObject
val buttons = arrayListOf<InlineKeyboardButton>() val buttons = arrayListOf<InlineKeyboardButton>()
row["buttons"].asJsonArray.forEach { button -> row["buttons"].asJsonArray.forEach { button ->
@ -163,7 +165,7 @@ internal object MessageMaker {
} }
rows.add(InlineKeyboardRow(buttons)) rows.add(InlineKeyboardRow(buttons))
} }
elem.inlineKeyboardElement = InlineKeyboardElement(rows, data["bot_appid"].asLong) elem.inlineKeyboardElement = InlineKeyboardElement(rows, keyboard["bot_appid"].asLong)
return Result.success(elem) return Result.success(elem)
} }
@ -626,10 +628,10 @@ internal object MessageMaker {
} }
private suspend fun createMarkdownElem(chatType: Int, msgId: Long, peerId: String, data: JsonObject): Result<MsgElement> { private suspend fun createMarkdownElem(chatType: Int, msgId: Long, peerId: String, data: JsonObject): Result<MsgElement> {
data.checkAndThrow("text") data.checkAndThrow("content")
val elem = MsgElement() val elem = MsgElement()
elem.elementType = MsgConstant.KELEMTYPEMARKDOWN elem.elementType = MsgConstant.KELEMTYPEMARKDOWN
val markdown = MarkdownElement(data["text"].asString) val markdown = MarkdownElement(data["content"].asString)
elem.markdownElement = markdown elem.markdownElement = markdown
return Result.success(elem) return Result.success(elem)
} }

View File

@ -540,7 +540,7 @@ internal sealed class MessageElemConverter: IMessageConvert {
} }
} }
put("bot_appid", keyboard.botAppid) put("bot_appid", keyboard.botAppid)
} }.toString()
) )
) )
} }