diff --git a/adapters/kook/src/message.ts b/adapters/kook/src/message.ts index 342c6538..27bebcef 100644 --- a/adapters/kook/src/message.ts +++ b/adapters/kook/src/message.ts @@ -230,6 +230,37 @@ export class KookMessageEncoder extends MessageEnco title: attrs.title, }) } + } else if (type === 'button') { + this.flushText() + this.cardBuffer.push({ + type: 'action-group', + elements: [encodeButton(element)], + }) + } else if (type === 'button-group') { + this.flushText() + this.cardBuffer.push({ + type: 'action-group', + elements: element.children.map(encodeButton), + }) + } else if (type === 'hr') { + this.flushText() + this.cardBuffer.push({ + type: 'divider', + }) + } else if (type === 'kook:countdown') { + this.flushText() + this.cardBuffer.push({ + type: 'countdown', + startTime: attrs.startTime, + endTime: attrs.endTime, + mode: attrs.mode, + }) + } else if (type === 'kook:invite') { + this.flushText() + this.cardBuffer.push({ + type: 'invite', + code: attrs.code, + }) } else if (type === 'quote') { await this.flush() this.additional.quote = attrs.id @@ -258,3 +289,21 @@ export namespace KookMessageEncoder { ]).role('radio').description('发送图文等混合内容时采用的方式。').default('separate'), }).description('发送设置') } + +function encodeButton({ attrs, children }: h): Kook.Card.Button { + let theme: Kook.Card.Button.Theme = 'primary' + if (attrs.class === 'secondary') theme = 'info' + if (attrs.class === 'warning') theme = 'warning' + if (attrs.class === 'danger') theme = 'danger' + if (attrs.class === 'success') theme = 'success' + return { + type: 'button', + theme, + value: attrs.id, + click: attrs.type === 'link' ? 'link' : 'return-val', + text: { + type: 'plain-text', + content: children.join(''), + }, + } +} diff --git a/adapters/kook/src/types.ts b/adapters/kook/src/types.ts index 4670f2ef..ca18d224 100644 --- a/adapters/kook/src/types.ts +++ b/adapters/kook/src/types.ts @@ -144,8 +144,8 @@ export interface Card { } export namespace Card { - export type Theme = 'primary' | 'secondary' | 'warning' | 'danger' | 'info' - export type Module = Section | Container | ImageGroup | Header | Divider | File | Countdown | Context + export type Theme = 'primary' | 'secondary' | 'warning' | 'danger' | 'info' | 'none' | 'success' + export type Module = Section | Container | ImageGroup | ActionGroup | Header | Divider | Invite | File | Countdown | Context export interface Text { type: 'plain-text' | 'kmarkdown' @@ -182,22 +182,21 @@ export namespace Card { export interface Button { type: 'button' - theme?: Theme - value: string + theme?: Button.Theme + value?: string text: Text click?: string } + export namespace Button { + export type Theme = 'primary' | 'secondary' | 'warning' | 'danger' | 'info' | 'success' + } + export interface ImageGroup { type: 'image-group' elements: Image[] } - export interface ActionGroup { - type: 'action-group' - elements: Button[] - } - export interface Header { type: 'header' text: Text @@ -207,6 +206,11 @@ export namespace Card { type: 'divider' } + export interface Invite { + type: 'invite' + code: string + } + export interface ActionGroup { type: 'action-group' elements: Button[] @@ -226,8 +230,8 @@ export namespace Card { export interface Countdown { type: 'countdown' - end_time: string - start_time: string + endTime: string + startTime: string mode: 'day' | 'hour' | 'second' } } diff --git a/adapters/kook/src/utils.ts b/adapters/kook/src/utils.ts index c586e35c..274e01c0 100644 --- a/adapters/kook/src/utils.ts +++ b/adapters/kook/src/utils.ts @@ -158,6 +158,13 @@ export function adaptSession(bot: Bot, input: any) { _data: body, })) switch (type) { + case 'message_btn_click': + session.type = 'interaction/button' + adaptMessageModify(input, body, session) + session.event.button = { + id: body.value, + } + break case 'updated_message': case 'updated_private_message': session.type = 'message-updated'