Skip to content

Commit

Permalink
feat: onebot11 adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
CakmLexi committed Jun 23, 2024
1 parent 3b718ba commit ed842f1
Show file tree
Hide file tree
Showing 8 changed files with 3,431 additions and 48 deletions.
572 changes: 572 additions & 0 deletions src/adapter/adapter.ts

Large diffs are not rendered by default.

1,359 changes: 1,359 additions & 0 deletions src/adapter/onebot/onebot11.ts

Large diffs are not rendered by default.

34 changes: 1 addition & 33 deletions src/event/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class KarinMessage extends KarinEvent {
/**
* - 事件类型
*/
event: 'message' | 'meta_event'
event: 'message' | 'message_sent'
/**
* - 机器人ID 请尽量使用UID
*/
Expand Down Expand Up @@ -63,38 +63,6 @@ export class KarinMessage extends KarinEvent {
* 群ID
*/
group_id: string
/**
* 框架处理后的文本
*/
msg: string
/**
* 游戏类型
*/
game: string
/**
* 图片数组
*/
image: Array<string>
/**
* AT数组
*/
at: Array<string>
/**
* 是否AT机器人
*/
atBot: boolean
/**
* 是否AT全体
*/
atAll: boolean
/**
* 文件元素
*/
file: object
/**
* 引用消息ID
*/
reply_id?: string
}) {
super({ event, event_id: message_id, self_id, user_id, group_id, time, contact, sender, sub_event: contact.scene === 'group' ? 'group_message' : 'friend_message' })
this.message_id = message_id
Expand Down
53 changes: 45 additions & 8 deletions src/types/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,25 @@ export interface KarinAdapter {
* - 连接时间
*/
start_time: number
/**
* - 适配器连接地址
* - 仅在`http`、`ws`、`grpc`有效 比如 ws://127.0.0.1:7000
*/
connect?: string
}

/**
* 获取Bot自身UID
*/
get self_id(): string

/**
* 专属当前Bot的日志打印方法
* @param level - 日志等级
* @param args - 日志内容
*/
logger(level: 'info' | 'error' | 'trace' | 'debug' | 'mark' | 'warn' | 'fatal', ...args: any[]): void

/**
* - 获取头像url
*/
Expand Down Expand Up @@ -212,7 +224,7 @@ export interface KarinAdapter {
* - 获取消息数量 默认为1
*/
count: number,
): Promise<Array<PushMessageBody>>
): Promise<Array<PushMessageBody> | void>

/**
* - 下载合并转发消息
Expand All @@ -222,7 +234,7 @@ export interface KarinAdapter {
* - 资源ID
*/
res_id: string,
): Promise<Array<PushMessageBody>>
): Promise<Array<PushMessageBody> | void>

/**
* - 获取精华消息
Expand All @@ -240,7 +252,7 @@ export interface KarinAdapter {
* - 每页数量
*/
page_size: number,
): Promise<EssenceMessageBody>
): Promise<EssenceMessageBody | void>

/**
* - 设置精华消息
Expand Down Expand Up @@ -395,7 +407,7 @@ export interface KarinAdapter {
/**
* - 群ID
*/
group_id: number,
group_id: string,
/**
* - 如果Bot是群主,是否解散群
* - 此项属于拓展选项,Kritor标准没有,仅在OneBot11中有效
Expand Down Expand Up @@ -436,7 +448,7 @@ export interface KarinAdapter {
/**
* - 登录账户名称
*/
account_name: number
account_name: string
}>

/**
Expand Down Expand Up @@ -588,9 +600,34 @@ export interface KarinAdapter {

/**
* 发送合并转发消息
* @param {contact} contact
* @param {Array<KarinNodeElement>} elements
* @return {Promise<void>}
* @param contact 联系人信息
* @param elements 消息元素
* @return {Promise<{message_id?}>}
*/
sendForwardMessage(contact: contact, elements: Array<KarinNodeElement>): Promise<{ message_id?: string }>

/**
* 对消息进行表情回应
* @param Contact - 联系人信息
* @param message_id - 消息ID
* @param face_id - 表情ID
*/
ReactMessageWithEmojiRequest(contact: contact, message_id: string, face_id: number, is_set: boolean): Promise<void>

/**
* 上传群文件
* @param group_id - 群号
* @param file - 本地文件绝对路径
* @param name - 文件名称 必须提供
* @param folder - 父目录ID 不提供则上传到根目录
*/
UploadGroupFile(group_id: string, file: string, name: string, folder?: string): Promise<void>

/**
* 上传私聊文件
* @param user_id - 用户ID
* @param file - 本地文件绝对路径
* @param name - 文件名称 必须提供
*/
UploadPrivateFile(user_id: string, file: string, name: string): Promise<void>
}
15 changes: 13 additions & 2 deletions src/types/element.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type ElementType = 'text' | 'at' | 'face' | 'bubble_face' | 'reply' | 'image' | 'voice' | 'video' | 'basketball' | 'dice' | 'rps' | 'poke' | 'music' | 'weather' | 'location' | 'share' | 'gift' | 'market_face' | 'forward' | 'contact' | 'json' | 'xml' | 'file' | 'markdown' | 'keyboard' | 'node' | 'rows' | 'record'
export type ElementType = 'text' | 'at' | 'face' | 'bubble_face' | 'reply' | 'image' | 'voice' | 'video' | 'basketball' | 'dice' | 'rps' | 'poke' | 'music' | 'weather' | 'location' | 'share' | 'gift' | 'market_face' | 'forward' | 'contact' | 'json' | 'xml' | 'file' | 'markdown' | 'keyboard' | 'node' | 'rows' | 'record' | 'long_msg'

export interface Element {
/**
Expand Down Expand Up @@ -586,6 +586,17 @@ export interface RowElement extends Element {
rows: Array<ButtonElement>
}

/**
* - 长消息元素
*/
export interface LongMsgElement extends Element {
type: 'long_msg'
/**
* - 消息ID
*/
id: string
}

/**
* - 构建自定义转发节点 此元素仅可通过专用接口发送 不支持混合发送
*/
Expand All @@ -596,4 +607,4 @@ export interface KarinNodeElement extends Element {
content: KarinElement | Array<KarinElement>
}

export type KarinElement = TextElement | AtElement | FaceElement | BubbleFaceElement | ReplyElement | ImageElement | VoiceElement | VideoElement | BasketballElement | DiceElement | RpsElement | PokeElement | MusicElement | WeatherElement | LocationElement | ShareElement | GiftElement | MarketFaceElement | ForwardElement | ContactElement | JsonElement | XmlElement | FileElement | MarkdownElement | ButtonElement | RowElement | RecordElement
export type KarinElement = TextElement | AtElement | FaceElement | BubbleFaceElement | ReplyElement | ImageElement | VoiceElement | VideoElement | BasketballElement | DiceElement | RpsElement | PokeElement | MusicElement | WeatherElement | LocationElement | ShareElement | GiftElement | MarketFaceElement | ForwardElement | ContactElement | JsonElement | XmlElement | FileElement | MarkdownElement | ButtonElement | RowElement | RecordElement | LongMsgElement
Loading

0 comments on commit ed842f1

Please sign in to comment.