feat(onebot): decode bot markdown and keyboards

Fixes #337
This commit is contained in:
DrSmoothl committed 2026-08-09 13:06:35 +08:00
1 parent 1e0c91e74d
commit 4aba81ec6b
12 files changed
+536 -46

No files matched your search

@@ -492,7 +492,12 @@ export const ELEMENT_CODECS = {
},
markdown: {
// 收侧(S)无对应,仅发·解存在。
async toSegment(element) {
return {
type: 'markdown',
data: { content: element.text },
};
},
async fromSegment(data) {
return {
type: 'markdown',
@@ -500,6 +505,36 @@ export const ELEMENT_CODECS = {
};
},
},
inline_keyboard: {
async toSegment(element) {
return {
type: 'inline_keyboard',
data: {
bot_appid: element.botAppid,
rows: element.rows.map((row) => ({
buttons: row.buttons.map((button) => ({
id: button.id,
label: button.label,
visited_label: button.visitedLabel,
style: button.style,
type: button.type,
click_limit: button.clickLimit,
unsupport_tips: button.unsupportedTips,
data: button.data,
at_bot_show_channel_list: button.atBotShowChannelList,
permission_type: button.permissionType,
specify_role_ids: button.specifyRoleIds,
specify_user_ids: button.specifyUserIds,
is_reply: button.isReply,
enter: button.enter,
anchor: button.anchor,
})),
})),
},
};
},
},
} satisfies ElementCodecMap;
/**
@@ -1791,6 +1791,7 @@ function elementPreview(element: MessageElement): string {
case 'json': return '[JSON消息]';
case 'xml': return '[XML消息]';
case 'markdown': return '[Markdown]';
case 'inline_keyboard': return '[交互按钮]';
case 'forward': return '[聊天记录]';
case 'poke': return '[窗口抖动]';
default: return '';