Skip to content

Commit

Permalink
feat: add LLOneBot APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed May 1, 2024
1 parent 3003be9 commit fdbe4e1
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
50 changes: 50 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,26 @@ func (ctx *Ctx) SendPrivateForwardMessage(userID int64, message message.Message)
}).Data
}

// ForwardFriendSingleMessage 转发单条消息到好友
//
// https://llonebot.github.io/zh-CN/develop/extends_api
func (ctx *Ctx) ForwardFriendSingleMessage(userID int64, messageID message.MessageID) APIResponse {
return ctx.CallAction("forward_friend_single_msg", Params{
"user_id": userID,
"message_id": messageID,
})
}

// ForwardGroupSingleMessage 转发单条消息到群
//
// https://llonebot.github.io/zh-CN/develop/extends_api
func (ctx *Ctx) ForwardGroupSingleMessage(groupID int64, messageID message.MessageID) APIResponse {
return ctx.CallAction("forward_group_single_msg", Params{
"group_id": groupID,
"message_id": messageID,
})
}

// GetGroupSystemMessage 获取群系统消息
// https://github.com/Mrs4s/go-cqhttp/blob/master/docs/cqhttp.md#%E8%8E%B7%E5%8F%96%E7%BE%A4%E7%B3%BB%E7%BB%9F%E6%B6%88%E6%81%AF
func (ctx *Ctx) GetGroupSystemMessage() gjson.Result {
Expand Down Expand Up @@ -696,3 +716,33 @@ func (ctx *Ctx) UploadGroupFile(groupID int64, file, name, folder string) APIRes
func (ctx *Ctx) UploadThisGroupFile(file, name, folder string) APIResponse {
return ctx.UploadGroupFile(ctx.Event.GroupID, file, name, folder)
}

// SetMyAvatar 设置我的头像
//
// https://llonebot.github.io/zh-CN/develop/extends_api
func (ctx *Ctx) SetMyAvatar(file string) APIResponse {
return ctx.CallAction("set_qq_avatar", Params{
"file": file,
})
}

// GetFile 下载收到的群文件或私聊文件
//
// https://llonebot.github.io/zh-CN/develop/extends_api
func (ctx *Ctx) GetFile(fileID string) gjson.Result {
return ctx.CallAction("get_file", Params{
"file_id": fileID,
}).Data
}

// SetMessageEmojiLike 发送表情回应
//
// https://llonebot.github.io/zh-CN/develop/extends_api
//
// emoji_id 参考 https://bot.q.qq.com/wiki/develop/api-v2/openapi/emoji/model.html#EmojiType
func (ctx *Ctx) SetMessageEmojiLike(messageID message.MessageID, emojiID string) APIResponse {
return ctx.CallAction("set_msg_emoji_like", Params{
"message_id": messageID,
"emoji_id": emojiID,
})
}
25 changes: 23 additions & 2 deletions message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,36 @@ func Face(id int) MessageSegment {
}
}

// File 文件
// https://llonebot.github.io/zh-CN/develop/extends_api
func File(file, name string) MessageSegment {
return MessageSegment{
Type: "file",
Data: map[string]string{
"file": file,
"name": name,
},
}
}

// Image 普通图片
//
// https://github.com/botuniverse/onebot-11/tree/master/message/segment.md#%E5%9B%BE%E7%89%87
func Image(file string) MessageSegment {
return MessageSegment{
//
// https://llonebot.github.io/zh-CN/develop/extends_api
//
// summary: LLOneBot的扩展字段:图片预览文字
func Image(file string, summary ...string) MessageSegment {
m := MessageSegment{
Type: "image",
Data: map[string]string{
"file": file,
},
}
if len(summary) > 0 {
m.Data["summary"] = fmt.Sprint(summary)
}
return m
}

// ImageBytes 普通图片
Expand Down

0 comments on commit fdbe4e1

Please sign in to comment.