mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
Shamrock
: support inline_keyboard
msg
This commit is contained in:
parent
b3a2e605fb
commit
50d7dfa06d
@ -79,6 +79,10 @@ public final class InlineKeyboardButton {
|
|||||||
return "InlineKeyboardButton{id=" + this.id + ",label=" + this.label + ",visitedLabel=" + this.visitedLabel + ",style=" + this.style + ",type=" + this.type + ",clickLimit=" + this.clickLimit + ",unsupportTips=" + this.unsupportTips + ",data=" + this.data + ",atBotShowChannelList=" + this.atBotShowChannelList + ",permissionType=" + this.permissionType + ",specifyRoleIds=" + this.specifyRoleIds + ",specifyTinyids=" + this.specifyTinyids + ",}";
|
return "InlineKeyboardButton{id=" + this.id + ",label=" + this.label + ",visitedLabel=" + this.visitedLabel + ",style=" + this.style + ",type=" + this.type + ",clickLimit=" + this.clickLimit + ",unsupportTips=" + this.unsupportTips + ",data=" + this.data + ",atBotShowChannelList=" + this.atBotShowChannelList + ",permissionType=" + this.permissionType + ",specifyRoleIds=" + this.specifyRoleIds + ",specifyTinyids=" + this.specifyTinyids + ",}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InlineKeyboardButton(String str, String str2, String str3, int i, int i2, int i3, String str4, String str5, boolean z, int i4, ArrayList<String> arrayList, ArrayList<String> arrayList2, boolean z2, int i5, boolean z3, ArrayList<SubscribeMsgTemplateID> arrayList3) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public InlineKeyboardButton(String str, String str2, String str3, int i2, int i3, int i4, String str4, String str5, boolean z, int i5, ArrayList<String> arrayList, ArrayList<String> arrayList2) {
|
public InlineKeyboardButton(String str, String str2, String str3, int i2, int i3, int i4, String str4, String str5, boolean z, int i5, ArrayList<String> arrayList, ArrayList<String> arrayList2) {
|
||||||
this.id = "";
|
this.id = "";
|
||||||
this.label = "";
|
this.label = "";
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
package com.tencent.qqnt.kernel.nativeinterface;
|
||||||
|
|
||||||
|
public class SubscribeMsgTemplateID {
|
||||||
|
}
|
@ -11,6 +11,9 @@ import com.tencent.qqnt.aio.adapter.api.IAIOPttApi
|
|||||||
import com.tencent.qqnt.kernel.nativeinterface.ArkElement
|
import com.tencent.qqnt.kernel.nativeinterface.ArkElement
|
||||||
import com.tencent.qqnt.kernel.nativeinterface.FaceBubbleElement
|
import com.tencent.qqnt.kernel.nativeinterface.FaceBubbleElement
|
||||||
import com.tencent.qqnt.kernel.nativeinterface.FaceElement
|
import com.tencent.qqnt.kernel.nativeinterface.FaceElement
|
||||||
|
import com.tencent.qqnt.kernel.nativeinterface.InlineKeyboardButton
|
||||||
|
import com.tencent.qqnt.kernel.nativeinterface.InlineKeyboardElement
|
||||||
|
import com.tencent.qqnt.kernel.nativeinterface.InlineKeyboardRow
|
||||||
import com.tencent.qqnt.kernel.nativeinterface.MarkdownElement
|
import com.tencent.qqnt.kernel.nativeinterface.MarkdownElement
|
||||||
import com.tencent.qqnt.kernel.nativeinterface.MarketFaceElement
|
import com.tencent.qqnt.kernel.nativeinterface.MarketFaceElement
|
||||||
import com.tencent.qqnt.kernel.nativeinterface.MarketFaceSupportSize
|
import com.tencent.qqnt.kernel.nativeinterface.MarketFaceSupportSize
|
||||||
@ -53,9 +56,11 @@ import moe.fuqiuluo.shamrock.helper.LogicException
|
|||||||
import moe.fuqiuluo.shamrock.helper.MessageHelper
|
import moe.fuqiuluo.shamrock.helper.MessageHelper
|
||||||
import moe.fuqiuluo.shamrock.helper.MusicHelper
|
import moe.fuqiuluo.shamrock.helper.MusicHelper
|
||||||
import moe.fuqiuluo.shamrock.helper.ParamsException
|
import moe.fuqiuluo.shamrock.helper.ParamsException
|
||||||
|
import moe.fuqiuluo.shamrock.tools.asBoolean
|
||||||
import moe.fuqiuluo.shamrock.tools.asBooleanOrNull
|
import moe.fuqiuluo.shamrock.tools.asBooleanOrNull
|
||||||
import moe.fuqiuluo.shamrock.tools.asInt
|
import moe.fuqiuluo.shamrock.tools.asInt
|
||||||
import moe.fuqiuluo.shamrock.tools.asIntOrNull
|
import moe.fuqiuluo.shamrock.tools.asIntOrNull
|
||||||
|
import moe.fuqiuluo.shamrock.tools.asJsonArray
|
||||||
import moe.fuqiuluo.shamrock.tools.asJsonObject
|
import moe.fuqiuluo.shamrock.tools.asJsonObject
|
||||||
import moe.fuqiuluo.shamrock.tools.asLong
|
import moe.fuqiuluo.shamrock.tools.asLong
|
||||||
import moe.fuqiuluo.shamrock.tools.asString
|
import moe.fuqiuluo.shamrock.tools.asString
|
||||||
@ -108,8 +113,60 @@ internal object MessageMaker {
|
|||||||
//"node" to MessageMaker::createNodeElem,
|
//"node" to MessageMaker::createNodeElem,
|
||||||
//"multi_msg" to MessageMaker::createLongMsgStruct,
|
//"multi_msg" to MessageMaker::createLongMsgStruct,
|
||||||
"bubble_face" to MessageMaker::createBubbleFaceElem,
|
"bubble_face" to MessageMaker::createBubbleFaceElem,
|
||||||
|
"inline_keyboard" to MessageMaker::createInlineKeywordElem
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private suspend fun createInlineKeywordElem(chatType: Int, msgId: Long, peerId: String, data: JsonObject): Result<MsgElement> {
|
||||||
|
fun tryNewKeyboardButton(btn: JsonObject): InlineKeyboardButton {
|
||||||
|
return runCatching {
|
||||||
|
InlineKeyboardButton(
|
||||||
|
btn["id"].asString,
|
||||||
|
btn["label"].asString,
|
||||||
|
btn["visited_label"].asString,
|
||||||
|
btn["style"].asInt,
|
||||||
|
btn["type"].asInt,
|
||||||
|
btn["click_limit"].asInt,
|
||||||
|
btn["unsupport_tips"].asString,
|
||||||
|
btn["data"].asString,
|
||||||
|
btn["at_bot_show_channel_list"].asBoolean,
|
||||||
|
btn["permission_type"].asInt,
|
||||||
|
ArrayList(btn["specify_role_ids"].asJsonArray.map { it.asString }),
|
||||||
|
ArrayList(btn["specify_tinyids"].asJsonArray.map { it.asString }),
|
||||||
|
false, 0, false, arrayListOf()
|
||||||
|
)
|
||||||
|
}.getOrElse {
|
||||||
|
InlineKeyboardButton(
|
||||||
|
btn["id"].asString,
|
||||||
|
btn["label"].asString,
|
||||||
|
btn["visited_label"].asString,
|
||||||
|
btn["style"].asInt,
|
||||||
|
btn["type"].asInt,
|
||||||
|
btn["click_limit"].asInt,
|
||||||
|
btn["unsupport_tips"].asString,
|
||||||
|
btn["data"].asString,
|
||||||
|
btn["at_bot_show_channel_list"].asBoolean,
|
||||||
|
btn["permission_type"].asInt,
|
||||||
|
ArrayList(btn["specify_role_ids"].asJsonArray.map { it.asString }),
|
||||||
|
ArrayList(btn["specify_tinyids"].asJsonArray.map { it.asString }),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val elem = MsgElement()
|
||||||
|
elem.elementType = MsgConstant.KELEMTYPEINLINEKEYBOARD
|
||||||
|
val rows = arrayListOf<InlineKeyboardRow>()
|
||||||
|
data["rows"].asJsonArray.forEach {
|
||||||
|
val row = it.asJsonObject
|
||||||
|
val buttons = arrayListOf<InlineKeyboardButton>()
|
||||||
|
row["buttons"].asJsonArray.forEach { button ->
|
||||||
|
val btn = button.asJsonObject
|
||||||
|
buttons.add(tryNewKeyboardButton(btn))
|
||||||
|
}
|
||||||
|
rows.add(InlineKeyboardRow(buttons))
|
||||||
|
}
|
||||||
|
elem.inlineKeyboardElement = InlineKeyboardElement(rows, data["bot_appid"].asLong)
|
||||||
|
return Result.success(elem)
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun createBubbleFaceElem(chatType: Int, msgId: Long, peerId: String, data: JsonObject): Result<MsgElement> {
|
private suspend fun createBubbleFaceElem(chatType: Int, msgId: Long, peerId: String, data: JsonObject): Result<MsgElement> {
|
||||||
data.checkAndThrow("id", "count")
|
data.checkAndThrow("id", "count")
|
||||||
val faceId = data["id"].asInt
|
val faceId = data["id"].asInt
|
||||||
|
@ -58,6 +58,7 @@ internal object MessageConvert {
|
|||||||
//MsgConstant.KELEMTYPEMULTIFORWARD to XmlMultiMsgConverter,
|
//MsgConstant.KELEMTYPEMULTIFORWARD to XmlMultiMsgConverter,
|
||||||
//MsgConstant.KELEMTYPESTRUCTLONGMSG to XmlLongMsgConverter,
|
//MsgConstant.KELEMTYPESTRUCTLONGMSG to XmlLongMsgConverter,
|
||||||
MsgConstant.KELEMTYPEFACEBUBBLE to BubbleFaceConverter,
|
MsgConstant.KELEMTYPEFACEBUBBLE to BubbleFaceConverter,
|
||||||
|
MsgConstant.KELEMTYPEINLINEKEYBOARD to InlineKeyboardConverter,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,10 @@ package moe.fuqiuluo.qqinterface.servlet.msg.convert
|
|||||||
import com.tencent.mobileqq.qmmkv.QMMKV
|
import com.tencent.mobileqq.qmmkv.QMMKV
|
||||||
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
|
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
|
||||||
import com.tencent.qqnt.kernel.nativeinterface.MsgElement
|
import com.tencent.qqnt.kernel.nativeinterface.MsgElement
|
||||||
|
import kotlinx.serialization.json.add
|
||||||
|
import kotlinx.serialization.json.buildJsonObject
|
||||||
|
import kotlinx.serialization.json.put
|
||||||
|
import kotlinx.serialization.json.putJsonArray
|
||||||
import moe.fuqiuluo.qqinterface.servlet.transfile.RichProtoSvc
|
import moe.fuqiuluo.qqinterface.servlet.transfile.RichProtoSvc
|
||||||
import moe.fuqiuluo.shamrock.helper.ContactHelper
|
import moe.fuqiuluo.shamrock.helper.ContactHelper
|
||||||
import moe.fuqiuluo.shamrock.helper.Level
|
import moe.fuqiuluo.shamrock.helper.Level
|
||||||
@ -495,6 +499,53 @@ internal sealed class MessageElemConverter: IMessageConvert {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data object InlineKeyboardConverter: MessageElemConverter() {
|
||||||
|
override suspend fun convert(
|
||||||
|
chatType: Int,
|
||||||
|
peerId: String,
|
||||||
|
subPeer: String,
|
||||||
|
element: MsgElement
|
||||||
|
): MessageSegment {
|
||||||
|
val keyboard = element.inlineKeyboardElement
|
||||||
|
return MessageSegment(
|
||||||
|
type = "inline_keyboard",
|
||||||
|
data = mapOf(
|
||||||
|
"data" to buildJsonObject {
|
||||||
|
putJsonArray("rows") {
|
||||||
|
keyboard.rows.forEach { row ->
|
||||||
|
add(buildJsonObject row@{
|
||||||
|
putJsonArray("buttons") {
|
||||||
|
row.buttons.forEach { button ->
|
||||||
|
add(buildJsonObject {
|
||||||
|
put("id", button.id ?: "")
|
||||||
|
put("label", button.label ?: "")
|
||||||
|
put("visited_label", button.visitedLabel ?: "")
|
||||||
|
put("style", button.style)
|
||||||
|
put("type", button.type)
|
||||||
|
put("click_limit", button.clickLimit)
|
||||||
|
put("unsupport_tips", button.unsupportTips ?: "")
|
||||||
|
put("data", button.data)
|
||||||
|
put("at_bot_show_channel_list", button.atBotShowChannelList)
|
||||||
|
put("permission_type", button.permissionType)
|
||||||
|
putJsonArray("specify_role_ids") {
|
||||||
|
button.specifyRoleIds?.forEach { add(it) }
|
||||||
|
}
|
||||||
|
putJsonArray("specify_tinyids") {
|
||||||
|
button.specifyTinyids?.forEach { add(it) }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
put("bot_appid", keyboard.botAppid)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected fun unknownChatType(chatType: Int) {
|
protected fun unknownChatType(chatType: Int) {
|
||||||
throw UnsupportedOperationException("Not supported chat type: $chatType")
|
throw UnsupportedOperationException("Not supported chat type: $chatType")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user