mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-06 12:03:50 +08:00
fix golint
This commit is contained in:
parent
6d5b0e01a2
commit
614109e116
374
coolq/api.go
374
coolq/api.go
@ -21,14 +21,19 @@ import (
|
|||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//Version go-cqhttp的版本信息,在编译时使用ldfalgs进行覆盖
|
||||||
var Version = "unknown"
|
var Version = "unknown"
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=get_login_info-%E8%8E%B7%E5%8F%96%E7%99%BB%E5%BD%95%E5%8F%B7%E4%BF%A1%E6%81%AF
|
//CQGetLoginInfo : 获取登录号信息
|
||||||
|
//
|
||||||
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_login_info-%E8%8E%B7%E5%8F%96%E7%99%BB%E5%BD%95%E5%8F%B7%E4%BF%A1%E6%81%AF
|
||||||
func (bot *CQBot) CQGetLoginInfo() MSG {
|
func (bot *CQBot) CQGetLoginInfo() MSG {
|
||||||
return OK(MSG{"user_id": bot.Client.Uin, "nickname": bot.Client.Nickname})
|
return OK(MSG{"user_id": bot.Client.Uin, "nickname": bot.Client.Nickname})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=get_friend_list-%E8%8E%B7%E5%8F%96%E5%A5%BD%E5%8F%8B%E5%88%97%E8%A1%A8
|
//CQGetFriendList : 获取好友列表
|
||||||
|
//
|
||||||
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_friend_list-%E8%8E%B7%E5%8F%96%E5%A5%BD%E5%8F%8B%E5%88%97%E8%A1%A8
|
||||||
func (bot *CQBot) CQGetFriendList() MSG {
|
func (bot *CQBot) CQGetFriendList() MSG {
|
||||||
fs := make([]MSG, 0)
|
fs := make([]MSG, 0)
|
||||||
for _, f := range bot.Client.FriendList {
|
for _, f := range bot.Client.FriendList {
|
||||||
@ -41,7 +46,9 @@ func (bot *CQBot) CQGetFriendList() MSG {
|
|||||||
return OK(fs)
|
return OK(fs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=get_group_list-%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%88%97%E8%A1%A8
|
//CQGetGroupList : 获取群列表
|
||||||
|
//
|
||||||
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_list-%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%88%97%E8%A1%A8
|
||||||
func (bot *CQBot) CQGetGroupList(noCache bool) MSG {
|
func (bot *CQBot) CQGetGroupList(noCache bool) MSG {
|
||||||
gs := make([]MSG, 0)
|
gs := make([]MSG, 0)
|
||||||
if noCache {
|
if noCache {
|
||||||
@ -58,15 +65,17 @@ func (bot *CQBot) CQGetGroupList(noCache bool) MSG {
|
|||||||
return OK(gs)
|
return OK(gs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=get_group_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E4%BF%A1%E6%81%AF
|
//CQGetGroupInfo : 获取群信息
|
||||||
func (bot *CQBot) CQGetGroupInfo(groupId int64, noCache bool) MSG {
|
//
|
||||||
group := bot.Client.FindGroup(groupId)
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E4%BF%A1%E6%81%AF
|
||||||
|
func (bot *CQBot) CQGetGroupInfo(groupID int64, noCache bool) MSG {
|
||||||
|
group := bot.Client.FindGroup(groupID)
|
||||||
if group == nil {
|
if group == nil {
|
||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
if noCache {
|
if noCache {
|
||||||
var err error
|
var err error
|
||||||
group, err = bot.Client.GetGroupInfo(groupId)
|
group, err = bot.Client.GetGroupInfo(groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Failed(100, "GET_GROUP_INFO_API_ERROR", err.Error())
|
return Failed(100, "GET_GROUP_INFO_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
@ -79,58 +88,68 @@ func (bot *CQBot) CQGetGroupInfo(groupId int64, noCache bool) MSG {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=get_group_member_list-%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%88%90%E5%91%98%E5%88%97%E8%A1%A8
|
//CQGetGroupMemberList : 获取群成员列表
|
||||||
func (bot *CQBot) CQGetGroupMemberList(groupId int64, noCache bool) MSG {
|
//
|
||||||
group := bot.Client.FindGroup(groupId)
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_member_list-%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%88%90%E5%91%98%E5%88%97%E8%A1%A8
|
||||||
|
func (bot *CQBot) CQGetGroupMemberList(groupID int64, noCache bool) MSG {
|
||||||
|
group := bot.Client.FindGroup(groupID)
|
||||||
if group == nil {
|
if group == nil {
|
||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
if noCache {
|
if noCache {
|
||||||
t, err := bot.Client.GetGroupMembers(group)
|
t, err := bot.Client.GetGroupMembers(group)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("刷新群 %v 成员列表失败: %v", groupId, err)
|
log.Warnf("刷新群 %v 成员列表失败: %v", groupID, err)
|
||||||
return Failed(100, "GET_MEMBERS_API_ERROR", err.Error())
|
return Failed(100, "GET_MEMBERS_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
group.Members = t
|
group.Members = t
|
||||||
}
|
}
|
||||||
members := make([]MSG, 0)
|
members := make([]MSG, 0)
|
||||||
for _, m := range group.Members {
|
for _, m := range group.Members {
|
||||||
members = append(members, convertGroupMemberInfo(groupId, m))
|
members = append(members, convertGroupMemberInfo(groupID, m))
|
||||||
}
|
}
|
||||||
return OK(members)
|
return OK(members)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=get_group_member_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%88%90%E5%91%98%E4%BF%A1%E6%81%AF
|
//CQGetGroupMemberInfo : 获取群成员信息
|
||||||
func (bot *CQBot) CQGetGroupMemberInfo(groupId, userId int64) MSG {
|
//
|
||||||
group := bot.Client.FindGroup(groupId)
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_member_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%88%90%E5%91%98%E4%BF%A1%E6%81%AF
|
||||||
|
func (bot *CQBot) CQGetGroupMemberInfo(groupID, userID int64) MSG {
|
||||||
|
group := bot.Client.FindGroup(groupID)
|
||||||
if group == nil {
|
if group == nil {
|
||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
member := group.FindMember(userId)
|
member := group.FindMember(userID)
|
||||||
if member == nil {
|
if member == nil {
|
||||||
return Failed(100, "MEMBER_NOT_FOUND", "群员不存在")
|
return Failed(100, "MEMBER_NOT_FOUND", "群员不存在")
|
||||||
}
|
}
|
||||||
return OK(convertGroupMemberInfo(groupId, member))
|
return OK(convertGroupMemberInfo(groupID, member))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQGetGroupFileSystemInfo(groupId int64) MSG {
|
//CQGetGroupFileSystemInfo : 扩展API-获取群文件系统信息
|
||||||
fs, err := bot.Client.GetGroupFileSystem(groupId)
|
//
|
||||||
|
//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F%E4%BF%A1%E6%81%AF
|
||||||
|
func (bot *CQBot) CQGetGroupFileSystemInfo(groupID int64) MSG {
|
||||||
|
fs, err := bot.Client.GetGroupFileSystem(groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取群 %v 文件系统信息失败: %v", groupId, err)
|
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
|
||||||
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
return OK(fs)
|
return OK(fs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQGetGroupRootFiles(groupId int64) MSG {
|
//CQGetGroupRootFiles : 扩展API-获取群根目录文件列表
|
||||||
fs, err := bot.Client.GetGroupFileSystem(groupId)
|
//
|
||||||
|
//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%A0%B9%E7%9B%AE%E5%BD%95%E6%96%87%E4%BB%B6%E5%88%97%E8%A1%A8
|
||||||
|
func (bot *CQBot) CQGetGroupRootFiles(groupID int64) MSG {
|
||||||
|
fs, err := bot.Client.GetGroupFileSystem(groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取群 %v 文件系统信息失败: %v", groupId, err)
|
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
|
||||||
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
files, folders, err := fs.Root()
|
files, folders, err := fs.Root()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取群 %v 根目录文件失败: %v", groupId, err)
|
log.Errorf("获取群 %v 根目录文件失败: %v", groupID, err)
|
||||||
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
return OK(MSG{
|
return OK(MSG{
|
||||||
@ -139,15 +158,18 @@ func (bot *CQBot) CQGetGroupRootFiles(groupId int64) MSG {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQGetGroupFilesByFolderId(groupId int64, folderId string) MSG {
|
//CQGetGroupFilesByFolderID : 扩展API-获取群子目录文件列表
|
||||||
fs, err := bot.Client.GetGroupFileSystem(groupId)
|
//
|
||||||
|
//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%AD%90%E7%9B%AE%E5%BD%95%E6%96%87%E4%BB%B6%E5%88%97%E8%A1%A8
|
||||||
|
func (bot *CQBot) CQGetGroupFilesByFolderID(groupID int64, folderID string) MSG {
|
||||||
|
fs, err := bot.Client.GetGroupFileSystem(groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取群 %v 文件系统信息失败: %v", groupId, err)
|
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
|
||||||
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
files, folders, err := fs.GetFilesByFolder(folderId)
|
files, folders, err := fs.GetFilesByFolder(folderID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取群 %v 根目录 %v 子文件失败: %v", groupId, folderId, err)
|
log.Errorf("获取群 %v 根目录 %v 子文件失败: %v", groupID, folderID, err)
|
||||||
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
return OK(MSG{
|
return OK(MSG{
|
||||||
@ -156,8 +178,11 @@ func (bot *CQBot) CQGetGroupFilesByFolderId(groupId int64, folderId string) MSG
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQGetGroupFileUrl(groupId int64, fileId string, busId int32) MSG {
|
//CQGetGroupFileURL : 扩展API-获取群文件资源链接
|
||||||
url := bot.Client.GetGroupFileUrl(groupId, fileId, busId)
|
//
|
||||||
|
//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%96%87%E4%BB%B6%E8%B5%84%E6%BA%90%E9%93%BE%E6%8E%A5
|
||||||
|
func (bot *CQBot) CQGetGroupFileURL(groupID int64, fileID string, busID int32) MSG {
|
||||||
|
url := bot.Client.GetGroupFileUrl(groupID, fileID, busID)
|
||||||
if url == "" {
|
if url == "" {
|
||||||
return Failed(100, "FILE_SYSTEM_API_ERROR")
|
return Failed(100, "FILE_SYSTEM_API_ERROR")
|
||||||
}
|
}
|
||||||
@ -166,6 +191,9 @@ func (bot *CQBot) CQGetGroupFileUrl(groupId int64, fileId string, busId int32) M
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//CQGetWordSlices : 隐藏API-获取中文分词
|
||||||
|
//
|
||||||
|
//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E4%B8%AD%E6%96%87%E5%88%86%E8%AF%8D-%E9%9A%90%E8%97%8F-api
|
||||||
func (bot *CQBot) CQGetWordSlices(content string) MSG {
|
func (bot *CQBot) CQGetWordSlices(content string) MSG {
|
||||||
slices, err := bot.Client.GetWordSegmentation(content)
|
slices, err := bot.Client.GetWordSegmentation(content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -177,14 +205,16 @@ func (bot *CQBot) CQGetWordSlices(content string) MSG {
|
|||||||
return OK(MSG{"slices": slices})
|
return OK(MSG{"slices": slices})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=send_group_msg-%E5%8F%91%E9%80%81%E7%BE%A4%E6%B6%88%E6%81%AF
|
//CQSendGroupMessage : 发送群消息
|
||||||
func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bool) MSG {
|
//
|
||||||
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#send_group_msg-%E5%8F%91%E9%80%81%E7%BE%A4%E6%B6%88%E6%81%AF
|
||||||
|
func (bot *CQBot) CQSendGroupMessage(groupID int64, i interface{}, autoEscape bool) MSG {
|
||||||
var str string
|
var str string
|
||||||
fixAt := func(elem []message.IMessageElement) {
|
fixAt := func(elem []message.IMessageElement) {
|
||||||
for _, e := range elem {
|
for _, e := range elem {
|
||||||
if at, ok := e.(*message.AtElement); ok && at.Target != 0 {
|
if at, ok := e.(*message.AtElement); ok && at.Target != 0 {
|
||||||
at.Display = "@" + func() string {
|
at.Display = "@" + func() string {
|
||||||
mem := bot.Client.FindGroup(groupId).FindMember(at.Target)
|
mem := bot.Client.FindGroup(groupID).FindMember(at.Target)
|
||||||
if mem != nil {
|
if mem != nil {
|
||||||
return mem.DisplayName()
|
return mem.DisplayName()
|
||||||
}
|
}
|
||||||
@ -197,11 +227,11 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bo
|
|||||||
if m.Type == gjson.JSON {
|
if m.Type == gjson.JSON {
|
||||||
elem := bot.ConvertObjectMessage(m, true)
|
elem := bot.ConvertObjectMessage(m, true)
|
||||||
fixAt(elem)
|
fixAt(elem)
|
||||||
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
mid := bot.SendGroupMessage(groupID, &message.SendingMessage{Elements: elem})
|
||||||
if mid == -1 {
|
if mid == -1 {
|
||||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
||||||
}
|
}
|
||||||
log.Infof("发送群 %v(%v) 的消息: %v (%v)", groupId, groupId, limitedString(m.String()), mid)
|
log.Infof("发送群 %v(%v) 的消息: %v (%v)", groupID, groupID, limitedString(m.String()), mid)
|
||||||
return OK(MSG{"message_id": mid})
|
return OK(MSG{"message_id": mid})
|
||||||
}
|
}
|
||||||
str = func() string {
|
str = func() string {
|
||||||
@ -224,15 +254,18 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bo
|
|||||||
elem = bot.ConvertStringMessage(str, true)
|
elem = bot.ConvertStringMessage(str, true)
|
||||||
}
|
}
|
||||||
fixAt(elem)
|
fixAt(elem)
|
||||||
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
mid := bot.SendGroupMessage(groupID, &message.SendingMessage{Elements: elem})
|
||||||
if mid == -1 {
|
if mid == -1 {
|
||||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
||||||
}
|
}
|
||||||
log.Infof("发送群 %v(%v) 的消息: %v (%v)", groupId, groupId, limitedString(str), mid)
|
log.Infof("发送群 %v(%v) 的消息: %v (%v)", groupID, groupID, limitedString(str), mid)
|
||||||
return OK(MSG{"message_id": mid})
|
return OK(MSG{"message_id": mid})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
//CQSendGroupForwardMessage : 扩展API-发送合并转发(群)
|
||||||
|
//
|
||||||
|
//https://docs.go-cqhttp.org/api/#%E5%8F%91%E9%80%81%E5%90%88%E5%B9%B6%E8%BD%AC%E5%8F%91-%E7%BE%A4
|
||||||
|
func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
|
||||||
if m.Type != gjson.JSON {
|
if m.Type != gjson.JSON {
|
||||||
return Failed(100)
|
return Failed(100)
|
||||||
}
|
}
|
||||||
@ -299,7 +332,7 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
|||||||
SenderId: uin,
|
SenderId: uin,
|
||||||
SenderName: name,
|
SenderName: name,
|
||||||
Time: int32(msgTime),
|
Time: int32(msgTime),
|
||||||
Message: []message.IMessageElement{bot.Client.UploadGroupForwardMessage(groupId, &message.ForwardMessage{Nodes: taowa})},
|
Message: []message.IMessageElement{bot.Client.UploadGroupForwardMessage(groupID, &message.ForwardMessage{Nodes: taowa})},
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -309,18 +342,18 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
|||||||
var newElem []message.IMessageElement
|
var newElem []message.IMessageElement
|
||||||
for _, elem := range content {
|
for _, elem := range content {
|
||||||
if img, ok := elem.(*LocalImageElement); ok {
|
if img, ok := elem.(*LocalImageElement); ok {
|
||||||
gm, err := bot.UploadLocalImageAsGroup(groupId, img)
|
gm, err := bot.UploadLocalImageAsGroup(groupID, img)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("警告:群 %v 图片上传失败: %v", groupId, err)
|
log.Warnf("警告:群 %v 图片上传失败: %v", groupID, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
newElem = append(newElem, gm)
|
newElem = append(newElem, gm)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if video, ok := elem.(*LocalVideoElement); ok {
|
if video, ok := elem.(*LocalVideoElement); ok {
|
||||||
gm, err := bot.UploadLocalVideo(groupId, video)
|
gm, err := bot.UploadLocalVideo(groupID, video)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("警告:群 %v 视频上传失败: %v", groupId, err)
|
log.Warnf("警告:群 %v 视频上传失败: %v", groupID, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
newElem = append(newElem, gm)
|
newElem = append(newElem, gm)
|
||||||
@ -347,7 +380,7 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
|||||||
sendNodes = convert(m)
|
sendNodes = convert(m)
|
||||||
}
|
}
|
||||||
if len(sendNodes) > 0 {
|
if len(sendNodes) > 0 {
|
||||||
gm := bot.Client.SendGroupForwardMessage(groupId, &message.ForwardMessage{Nodes: sendNodes})
|
gm := bot.Client.SendGroupForwardMessage(groupID, &message.ForwardMessage{Nodes: sendNodes})
|
||||||
return OK(MSG{
|
return OK(MSG{
|
||||||
"message_id": bot.InsertGroupMessage(gm),
|
"message_id": bot.InsertGroupMessage(gm),
|
||||||
})
|
})
|
||||||
@ -355,17 +388,19 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
|||||||
return Failed(100)
|
return Failed(100)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=send_private_msg-%E5%8F%91%E9%80%81%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF
|
//CQSendPrivateMessage : 发送私聊消息
|
||||||
func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}, autoEscape bool) MSG {
|
//
|
||||||
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#send_private_msg-%E5%8F%91%E9%80%81%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF
|
||||||
|
func (bot *CQBot) CQSendPrivateMessage(userID int64, i interface{}, autoEscape bool) MSG {
|
||||||
var str string
|
var str string
|
||||||
if m, ok := i.(gjson.Result); ok {
|
if m, ok := i.(gjson.Result); ok {
|
||||||
if m.Type == gjson.JSON {
|
if m.Type == gjson.JSON {
|
||||||
elem := bot.ConvertObjectMessage(m, false)
|
elem := bot.ConvertObjectMessage(m, false)
|
||||||
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
mid := bot.SendPrivateMessage(userID, &message.SendingMessage{Elements: elem})
|
||||||
if mid == -1 {
|
if mid == -1 {
|
||||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
||||||
}
|
}
|
||||||
log.Infof("发送好友 %v(%v) 的消息: %v (%v)", userId, userId, limitedString(m.String()), mid)
|
log.Infof("发送好友 %v(%v) 的消息: %v (%v)", userID, userID, limitedString(m.String()), mid)
|
||||||
return OK(MSG{"message_id": mid})
|
return OK(MSG{"message_id": mid})
|
||||||
}
|
}
|
||||||
str = func() string {
|
str = func() string {
|
||||||
@ -386,18 +421,20 @@ func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}, autoEscape b
|
|||||||
} else {
|
} else {
|
||||||
elem = bot.ConvertStringMessage(str, false)
|
elem = bot.ConvertStringMessage(str, false)
|
||||||
}
|
}
|
||||||
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
mid := bot.SendPrivateMessage(userID, &message.SendingMessage{Elements: elem})
|
||||||
if mid == -1 {
|
if mid == -1 {
|
||||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
||||||
}
|
}
|
||||||
log.Infof("发送好友 %v(%v) 的消息: %v (%v)", userId, userId, limitedString(str), mid)
|
log.Infof("发送好友 %v(%v) 的消息: %v (%v)", userID, userID, limitedString(str), mid)
|
||||||
return OK(MSG{"message_id": mid})
|
return OK(MSG{"message_id": mid})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=set_group_card-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%90%8D%E7%89%87%EF%BC%88%E7%BE%A4%E5%A4%87%E6%B3%A8%EF%BC%89
|
//CQSetGroupCard : 设置群名片(群备注)
|
||||||
func (bot *CQBot) CQSetGroupCard(groupId, userId int64, card string) MSG {
|
//
|
||||||
if g := bot.Client.FindGroup(groupId); g != nil {
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_card-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%90%8D%E7%89%87%E7%BE%A4%E5%A4%87%E6%B3%A8
|
||||||
if m := g.FindMember(userId); m != nil {
|
func (bot *CQBot) CQSetGroupCard(groupID, userID int64, card string) MSG {
|
||||||
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
|
if m := g.FindMember(userID); m != nil {
|
||||||
m.EditCard(card)
|
m.EditCard(card)
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
@ -405,10 +442,12 @@ func (bot *CQBot) CQSetGroupCard(groupId, userId int64, card string) MSG {
|
|||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=set_group_special_title-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E7%BB%84%E4%B8%93%E5%B1%9E%E5%A4%B4%E8%A1%94
|
//CQSetGroupSpecialTitle : 设置群组专属头衔
|
||||||
func (bot *CQBot) CQSetGroupSpecialTitle(groupId, userId int64, title string) MSG {
|
//
|
||||||
if g := bot.Client.FindGroup(groupId); g != nil {
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_special_title-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E7%BB%84%E4%B8%93%E5%B1%9E%E5%A4%B4%E8%A1%94
|
||||||
if m := g.FindMember(userId); m != nil {
|
func (bot *CQBot) CQSetGroupSpecialTitle(groupID, userID int64, title string) MSG {
|
||||||
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
|
if m := g.FindMember(userID); m != nil {
|
||||||
m.EditSpecialTitle(title)
|
m.EditSpecialTitle(title)
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
@ -416,26 +455,34 @@ func (bot *CQBot) CQSetGroupSpecialTitle(groupId, userId int64, title string) MS
|
|||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQSetGroupName(groupId int64, name string) MSG {
|
//CQSetGroupName : 设置群名
|
||||||
if g := bot.Client.FindGroup(groupId); g != nil {
|
//
|
||||||
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_name-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%90%8D
|
||||||
|
func (bot *CQBot) CQSetGroupName(groupID int64, name string) MSG {
|
||||||
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
g.UpdateName(name)
|
g.UpdateName(name)
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQSetGroupMemo(groupId int64, msg string) MSG {
|
//CQSetGroupMemo : 扩展API-发送群公告
|
||||||
if g := bot.Client.FindGroup(groupId); g != nil {
|
//
|
||||||
|
//https://docs.go-cqhttp.org/api/#%E5%8F%91%E9%80%81%E7%BE%A4%E5%85%AC%E5%91%8A
|
||||||
|
func (bot *CQBot) CQSetGroupMemo(groupID int64, msg string) MSG {
|
||||||
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
g.UpdateMemo(msg)
|
g.UpdateMemo(msg)
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=set_group_kick-%E7%BE%A4%E7%BB%84%E8%B8%A2%E4%BA%BA
|
//CQSetGroupKick : 群组踢人
|
||||||
func (bot *CQBot) CQSetGroupKick(groupId, userId int64, msg string, block bool) MSG {
|
//
|
||||||
if g := bot.Client.FindGroup(groupId); g != nil {
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_kick-%E7%BE%A4%E7%BB%84%E8%B8%A2%E4%BA%BA
|
||||||
if m := g.FindMember(userId); m != nil {
|
func (bot *CQBot) CQSetGroupKick(groupID, userID int64, msg string, block bool) MSG {
|
||||||
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
|
if m := g.FindMember(userID); m != nil {
|
||||||
m.Kick(msg, block)
|
m.Kick(msg, block)
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
@ -443,10 +490,12 @@ func (bot *CQBot) CQSetGroupKick(groupId, userId int64, msg string, block bool)
|
|||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=set_group_ban-%E7%BE%A4%E7%BB%84%E5%8D%95%E4%BA%BA%E7%A6%81%E8%A8%80
|
//CQSetGroupBan : 群组单人禁言
|
||||||
func (bot *CQBot) CQSetGroupBan(groupId, userId int64, duration uint32) MSG {
|
//
|
||||||
if g := bot.Client.FindGroup(groupId); g != nil {
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_ban-%E7%BE%A4%E7%BB%84%E5%8D%95%E4%BA%BA%E7%A6%81%E8%A8%80
|
||||||
if m := g.FindMember(userId); m != nil {
|
func (bot *CQBot) CQSetGroupBan(groupID, userID int64, duration uint32) MSG {
|
||||||
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
|
if m := g.FindMember(userID); m != nil {
|
||||||
m.Mute(duration)
|
m.Mute(duration)
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
@ -454,27 +503,34 @@ func (bot *CQBot) CQSetGroupBan(groupId, userId int64, duration uint32) MSG {
|
|||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=set_group_whole_ban-%E7%BE%A4%E7%BB%84%E5%85%A8%E5%91%98%E7%A6%81%E8%A8%80
|
//CQSetGroupWholeBan : 群组全员禁言
|
||||||
func (bot *CQBot) CQSetGroupWholeBan(groupId int64, enable bool) MSG {
|
//
|
||||||
if g := bot.Client.FindGroup(groupId); g != nil {
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_whole_ban-%E7%BE%A4%E7%BB%84%E5%85%A8%E5%91%98%E7%A6%81%E8%A8%80
|
||||||
|
func (bot *CQBot) CQSetGroupWholeBan(groupID int64, enable bool) MSG {
|
||||||
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
g.MuteAll(enable)
|
g.MuteAll(enable)
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=set_group_leave-%E9%80%80%E5%87%BA%E7%BE%A4%E7%BB%84
|
//CQSetGroupLeave : 退出群组
|
||||||
func (bot *CQBot) CQSetGroupLeave(groupId int64) MSG {
|
//
|
||||||
if g := bot.Client.FindGroup(groupId); g != nil {
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_leave-%E9%80%80%E5%87%BA%E7%BE%A4%E7%BB%84
|
||||||
|
func (bot *CQBot) CQSetGroupLeave(groupID int64) MSG {
|
||||||
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
g.Quit()
|
g.Quit()
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQGetAtAllRemain(groupId int64) MSG {
|
//CQGetAtAllRemain : 扩展API-获取群 @全体成员 剩余次数
|
||||||
if g := bot.Client.FindGroup(groupId); g != nil {
|
//
|
||||||
i, err := bot.Client.GetAtAllRemain(groupId)
|
//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4-%E5%85%A8%E4%BD%93%E6%88%90%E5%91%98-%E5%89%A9%E4%BD%99%E6%AC%A1%E6%95%B0
|
||||||
|
func (bot *CQBot) CQGetAtAllRemain(groupID int64) MSG {
|
||||||
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
|
i, err := bot.Client.GetAtAllRemain(groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Failed(100, "GROUP_REMAIN_API_ERROR", err.Error())
|
return Failed(100, "GROUP_REMAIN_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
@ -483,7 +539,9 @@ func (bot *CQBot) CQGetAtAllRemain(groupId int64) MSG {
|
|||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=set_friend_add_request-%E5%A4%84%E7%90%86%E5%8A%A0%E5%A5%BD%E5%8F%8B%E8%AF%B7%E6%B1%82
|
//CQProcessFriendRequest : 处理加好友请求
|
||||||
|
//
|
||||||
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_friend_add_request-%E5%A4%84%E7%90%86%E5%8A%A0%E5%A5%BD%E5%8F%8B%E8%AF%B7%E6%B1%82
|
||||||
func (bot *CQBot) CQProcessFriendRequest(flag string, approve bool) MSG {
|
func (bot *CQBot) CQProcessFriendRequest(flag string, approve bool) MSG {
|
||||||
req, ok := bot.friendReqCache.Load(flag)
|
req, ok := bot.friendReqCache.Load(flag)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -497,7 +555,9 @@ func (bot *CQBot) CQProcessFriendRequest(flag string, approve bool) MSG {
|
|||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=set_group_add_request-%E5%A4%84%E7%90%86%E5%8A%A0%E7%BE%A4%E8%AF%B7%E6%B1%82%EF%BC%8F%E9%82%80%E8%AF%B7
|
//CQProcessGroupRequest : 处理加群请求/邀请
|
||||||
|
//
|
||||||
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_add_request-%E5%A4%84%E7%90%86%E5%8A%A0%E7%BE%A4%E8%AF%B7%E6%B1%82%E9%82%80%E8%AF%B7
|
||||||
func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bool) MSG {
|
func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bool) MSG {
|
||||||
msgs, err := bot.Client.GetGroupSystemMessages()
|
msgs, err := bot.Client.GetGroupSystemMessages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -539,52 +599,59 @@ func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bo
|
|||||||
return Failed(100, "FLAG_NOT_FOUND", "FLAG不存在")
|
return Failed(100, "FLAG_NOT_FOUND", "FLAG不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=delete_msg-%E6%92%A4%E5%9B%9E%E6%B6%88%E6%81%AF
|
//CQDeleteMessage : 撤回消息
|
||||||
func (bot *CQBot) CQDeleteMessage(messageId int32) MSG {
|
//
|
||||||
msg := bot.GetMessage(messageId)
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#delete_msg-%E6%92%A4%E5%9B%9E%E6%B6%88%E6%81%AF
|
||||||
|
func (bot *CQBot) CQDeleteMessage(messageID int32) MSG {
|
||||||
|
msg := bot.GetMessage(messageID)
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
return Failed(100, "MESSAGE_NOT_FOUND", "消息不存在")
|
return Failed(100, "MESSAGE_NOT_FOUND", "消息不存在")
|
||||||
}
|
}
|
||||||
if _, ok := msg["group"]; ok {
|
if _, ok := msg["group"]; ok {
|
||||||
if err := bot.Client.RecallGroupMessage(msg["group"].(int64), msg["message-id"].(int32), msg["internal-id"].(int32)); err != nil {
|
if err := bot.Client.RecallGroupMessage(msg["group"].(int64), msg["message-id"].(int32), msg["internal-id"].(int32)); err != nil {
|
||||||
log.Warnf("撤回 %v 失败: %v", messageId, err)
|
log.Warnf("撤回 %v 失败: %v", messageID, err)
|
||||||
return Failed(100, "RECALL_API_ERROR", err.Error())
|
return Failed(100, "RECALL_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if msg["sender"].(message.Sender).Uin != bot.Client.Uin {
|
if msg["sender"].(message.Sender).Uin != bot.Client.Uin {
|
||||||
log.Warnf("撤回 %v 失败: 好友会话无法撤回对方消息.", messageId)
|
log.Warnf("撤回 %v 失败: 好友会话无法撤回对方消息.", messageID)
|
||||||
return Failed(100, "CANNOT_RECALL_FRIEND_MSG", "无法撤回对方消息")
|
return Failed(100, "CANNOT_RECALL_FRIEND_MSG", "无法撤回对方消息")
|
||||||
}
|
}
|
||||||
if err := bot.Client.RecallPrivateMessage(msg["target"].(int64), int64(msg["time"].(int32)), msg["message-id"].(int32), msg["internal-id"].(int32)); err != nil {
|
if err := bot.Client.RecallPrivateMessage(msg["target"].(int64), int64(msg["time"].(int32)), msg["message-id"].(int32), msg["internal-id"].(int32)); err != nil {
|
||||||
log.Warnf("撤回 %v 失败: %v", messageId, err)
|
log.Warnf("撤回 %v 失败: %v", messageID, err)
|
||||||
return Failed(100, "RECALL_API_ERROR", err.Error())
|
return Failed(100, "RECALL_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_admin-%E7%BE%A4%E7%BB%84%E8%AE%BE%E7%BD%AE%E7%AE%A1%E7%90%86%E5%91%98
|
//CQSetGroupAdmin : 群组设置管理员
|
||||||
func (bot *CQBot) CQSetGroupAdmin(groupId, userId int64, enable bool) MSG {
|
//
|
||||||
group := bot.Client.FindGroup(groupId)
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_admin-%E7%BE%A4%E7%BB%84%E8%AE%BE%E7%BD%AE%E7%AE%A1%E7%90%86%E5%91%98
|
||||||
|
func (bot *CQBot) CQSetGroupAdmin(groupID, userID int64, enable bool) MSG {
|
||||||
|
group := bot.Client.FindGroup(groupID)
|
||||||
if group == nil || group.OwnerUin != bot.Client.Uin {
|
if group == nil || group.OwnerUin != bot.Client.Uin {
|
||||||
return Failed(100, "PERMISSION_DENIED", "群不存在或权限不足")
|
return Failed(100, "PERMISSION_DENIED", "群不存在或权限不足")
|
||||||
}
|
}
|
||||||
mem := group.FindMember(userId)
|
mem := group.FindMember(userID)
|
||||||
if mem == nil {
|
if mem == nil {
|
||||||
return Failed(100, "GROUP_MEMBER_NOT_FOUND", "群成员不存在")
|
return Failed(100, "GROUP_MEMBER_NOT_FOUND", "群成员不存在")
|
||||||
}
|
}
|
||||||
mem.SetAdmin(enable)
|
mem.SetAdmin(enable)
|
||||||
t, err := bot.Client.GetGroupMembers(group)
|
t, err := bot.Client.GetGroupMembers(group)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("刷新群 %v 成员列表失败: %v", groupId, err)
|
log.Warnf("刷新群 %v 成员列表失败: %v", groupID, err)
|
||||||
return Failed(100, "GET_MEMBERS_API_ERROR", err.Error())
|
return Failed(100, "GET_MEMBERS_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
group.Members = t
|
group.Members = t
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQGetVipInfo(userId int64) MSG {
|
//CQGetVipInfo : 扩展API-获取VIP信息
|
||||||
vip, err := bot.Client.GetVipInfo(userId)
|
//
|
||||||
|
//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96vip%E4%BF%A1%E6%81%AF
|
||||||
|
func (bot *CQBot) CQGetVipInfo(userID int64) MSG {
|
||||||
|
vip, err := bot.Client.GetVipInfo(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Failed(100, "VIP_API_ERROR", err.Error())
|
return Failed(100, "VIP_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
@ -600,9 +667,11 @@ func (bot *CQBot) CQGetVipInfo(userId int64) MSG {
|
|||||||
return OK(msg)
|
return OK(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_honor_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E8%8D%A3%E8%AA%89%E4%BF%A1%E6%81%AF
|
//CQGetGroupHonorInfo : 获取群荣誉信息
|
||||||
func (bot *CQBot) CQGetGroupHonorInfo(groupId int64, t string) MSG {
|
//
|
||||||
msg := MSG{"group_id": groupId}
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_honor_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E8%8D%A3%E8%AA%89%E4%BF%A1%E6%81%AF
|
||||||
|
func (bot *CQBot) CQGetGroupHonorInfo(groupID int64, t string) MSG {
|
||||||
|
msg := MSG{"group_id": groupID}
|
||||||
convertMem := func(memList []client.HonorMemberInfo) (ret []MSG) {
|
convertMem := func(memList []client.HonorMemberInfo) (ret []MSG) {
|
||||||
for _, mem := range memList {
|
for _, mem := range memList {
|
||||||
ret = append(ret, MSG{
|
ret = append(ret, MSG{
|
||||||
@ -615,7 +684,7 @@ func (bot *CQBot) CQGetGroupHonorInfo(groupId int64, t string) MSG {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if t == "talkative" || t == "all" {
|
if t == "talkative" || t == "all" {
|
||||||
if honor, err := bot.Client.GetGroupHonorInfo(groupId, client.Talkative); err == nil {
|
if honor, err := bot.Client.GetGroupHonorInfo(groupID, client.Talkative); err == nil {
|
||||||
if honor.CurrentTalkative.Uin != 0 {
|
if honor.CurrentTalkative.Uin != 0 {
|
||||||
msg["current_talkative"] = MSG{
|
msg["current_talkative"] = MSG{
|
||||||
"user_id": honor.CurrentTalkative.Uin,
|
"user_id": honor.CurrentTalkative.Uin,
|
||||||
@ -629,25 +698,25 @@ func (bot *CQBot) CQGetGroupHonorInfo(groupId int64, t string) MSG {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if t == "performer" || t == "all" {
|
if t == "performer" || t == "all" {
|
||||||
if honor, err := bot.Client.GetGroupHonorInfo(groupId, client.Performer); err == nil {
|
if honor, err := bot.Client.GetGroupHonorInfo(groupID, client.Performer); err == nil {
|
||||||
msg["performer_lis"] = convertMem(honor.ActorList)
|
msg["performer_lis"] = convertMem(honor.ActorList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if t == "legend" || t == "all" {
|
if t == "legend" || t == "all" {
|
||||||
if honor, err := bot.Client.GetGroupHonorInfo(groupId, client.Legend); err == nil {
|
if honor, err := bot.Client.GetGroupHonorInfo(groupID, client.Legend); err == nil {
|
||||||
msg["legend_list"] = convertMem(honor.LegendList)
|
msg["legend_list"] = convertMem(honor.LegendList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if t == "strong_newbie" || t == "all" {
|
if t == "strong_newbie" || t == "all" {
|
||||||
if honor, err := bot.Client.GetGroupHonorInfo(groupId, client.StrongNewbie); err == nil {
|
if honor, err := bot.Client.GetGroupHonorInfo(groupID, client.StrongNewbie); err == nil {
|
||||||
msg["strong_newbie_list"] = convertMem(honor.StrongNewbieList)
|
msg["strong_newbie_list"] = convertMem(honor.StrongNewbieList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if t == "emotion" || t == "all" {
|
if t == "emotion" || t == "all" {
|
||||||
if honor, err := bot.Client.GetGroupHonorInfo(groupId, client.Emotion); err == nil {
|
if honor, err := bot.Client.GetGroupHonorInfo(groupID, client.Emotion); err == nil {
|
||||||
msg["emotion_list"] = convertMem(honor.EmotionList)
|
msg["emotion_list"] = convertMem(honor.EmotionList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -655,9 +724,11 @@ func (bot *CQBot) CQGetGroupHonorInfo(groupId int64, t string) MSG {
|
|||||||
return OK(msg)
|
return OK(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_stranger_info-%E8%8E%B7%E5%8F%96%E9%99%8C%E7%94%9F%E4%BA%BA%E4%BF%A1%E6%81%AF
|
//CQGetStrangerInfo : 获取陌生人信息
|
||||||
func (bot *CQBot) CQGetStrangerInfo(userId int64) MSG {
|
//
|
||||||
info, err := bot.Client.GetSummaryInfo(userId)
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_stranger_info-%E8%8E%B7%E5%8F%96%E9%99%8C%E7%94%9F%E4%BA%BA%E4%BF%A1%E6%81%AF
|
||||||
|
func (bot *CQBot) CQGetStrangerInfo(userID int64) MSG {
|
||||||
|
info, err := bot.Client.GetSummaryInfo(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Failed(100, "SUMMARY_API_ERROR", err.Error())
|
return Failed(100, "SUMMARY_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
@ -680,8 +751,9 @@ func (bot *CQBot) CQGetStrangerInfo(userId int64) MSG {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://cqhttp.cc/docs/4.15/#/API?id=-handle_quick_operation-%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%89%A7%E8%A1%8C%E5%BF%AB%E9%80%9F%E6%93%8D%E4%BD%9C
|
//CQHandleQuickOperation : 隐藏API-对事件执行快速操作
|
||||||
// https://github.com/richardchien/coolq-http-api/blob/master/src/cqhttp/plugins/web/http.cpp#L376
|
//
|
||||||
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/hidden.md#handle_quick_operation-%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%89%A7%E8%A1%8C%E5%BF%AB%E9%80%9F%E6%93%8D%E4%BD%9C
|
||||||
func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
||||||
postType := context.Get("post_type").Str
|
postType := context.Get("post_type").Str
|
||||||
switch postType {
|
switch postType {
|
||||||
@ -738,11 +810,15 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
|||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//CQGetImage : 获取图片(修改自OneBot)
|
||||||
|
//
|
||||||
|
//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E5%9B%BE%E7%89%87%E4%BF%A1%E6%81%AF
|
||||||
func (bot *CQBot) CQGetImage(file string) MSG {
|
func (bot *CQBot) CQGetImage(file string) MSG {
|
||||||
if !global.PathExists(path.Join(global.ImagePath, file)) {
|
if !global.PathExists(path.Join(global.ImagePath, file)) {
|
||||||
return Failed(100)
|
return Failed(100)
|
||||||
}
|
}
|
||||||
if b, err := ioutil.ReadFile(path.Join(global.ImagePath, file)); err == nil {
|
b, err := ioutil.ReadFile(path.Join(global.ImagePath, file))
|
||||||
|
if err == nil {
|
||||||
r := binary.NewReader(b)
|
r := binary.NewReader(b)
|
||||||
r.ReadBytes(16)
|
r.ReadBytes(16)
|
||||||
msg := MSG{
|
msg := MSG{
|
||||||
@ -758,11 +834,11 @@ func (bot *CQBot) CQGetImage(file string) MSG {
|
|||||||
}
|
}
|
||||||
msg["file"] = local
|
msg["file"] = local
|
||||||
return OK(msg)
|
return OK(msg)
|
||||||
} else {
|
|
||||||
return Failed(100, "LOAD_FILE_ERROR", err.Error())
|
|
||||||
}
|
}
|
||||||
|
return Failed(100, "LOAD_FILE_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//CQDownloadFile : 使用给定threadCount和给定headers下载给定url
|
||||||
func (bot *CQBot) CQDownloadFile(url string, headers map[string]string, threadCount int) MSG {
|
func (bot *CQBot) CQDownloadFile(url string, headers map[string]string, threadCount int) MSG {
|
||||||
hash := md5.Sum([]byte(url))
|
hash := md5.Sum([]byte(url))
|
||||||
file := path.Join(global.CachePath, hex.EncodeToString(hash[:])+".cache")
|
file := path.Join(global.CachePath, hex.EncodeToString(hash[:])+".cache")
|
||||||
@ -782,8 +858,11 @@ func (bot *CQBot) CQDownloadFile(url string, headers map[string]string, threadCo
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQGetForwardMessage(resId string) MSG {
|
//CQGetForwardMessage : 获取合并转发消息
|
||||||
m := bot.Client.GetForwardMessage(resId)
|
//
|
||||||
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_forward_msg-%E8%8E%B7%E5%8F%96%E5%90%88%E5%B9%B6%E8%BD%AC%E5%8F%91%E6%B6%88%E6%81%AF
|
||||||
|
func (bot *CQBot) CQGetForwardMessage(resID string) MSG {
|
||||||
|
m := bot.Client.GetForwardMessage(resID)
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
|
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
|
||||||
}
|
}
|
||||||
@ -804,8 +883,11 @@ func (bot *CQBot) CQGetForwardMessage(resId string) MSG {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQGetMessage(messageId int32) MSG {
|
//CQGetMessage : 获取消息
|
||||||
msg := bot.GetMessage(messageId)
|
//
|
||||||
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_msg-%E8%8E%B7%E5%8F%96%E6%B6%88%E6%81%AF
|
||||||
|
func (bot *CQBot) CQGetMessage(messageID int32) MSG {
|
||||||
|
msg := bot.GetMessage(messageID)
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
|
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
|
||||||
}
|
}
|
||||||
@ -813,7 +895,7 @@ func (bot *CQBot) CQGetMessage(messageId int32) MSG {
|
|||||||
gid, isGroup := msg["group"]
|
gid, isGroup := msg["group"]
|
||||||
raw := msg["message"].(string)
|
raw := msg["message"].(string)
|
||||||
return OK(MSG{
|
return OK(MSG{
|
||||||
"message_id": messageId,
|
"message_id": messageID,
|
||||||
"real_id": msg["message-id"],
|
"real_id": msg["message-id"],
|
||||||
"message_seq": msg["message-id"],
|
"message_seq": msg["message-id"],
|
||||||
"group": isGroup,
|
"group": isGroup,
|
||||||
@ -839,6 +921,9 @@ func (bot *CQBot) CQGetMessage(messageId int32) MSG {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//CQGetGroupSystemMessages : 扩展API-获取群文件系统消息
|
||||||
|
//
|
||||||
|
//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E7%B3%BB%E7%BB%9F%E6%B6%88%E6%81%AF
|
||||||
func (bot *CQBot) CQGetGroupSystemMessages() MSG {
|
func (bot *CQBot) CQGetGroupSystemMessages() MSG {
|
||||||
msg, err := bot.Client.GetGroupSystemMessages()
|
msg, err := bot.Client.GetGroupSystemMessages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -848,18 +933,21 @@ func (bot *CQBot) CQGetGroupSystemMessages() MSG {
|
|||||||
return OK(msg)
|
return OK(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQGetGroupMessageHistory(groupId int64, seq int64) MSG {
|
//CQGetGroupMessageHistory : 获取群消息历史记录
|
||||||
if g := bot.Client.FindGroup(groupId); g == nil {
|
//
|
||||||
|
//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%B6%88%E6%81%AF%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95
|
||||||
|
func (bot *CQBot) CQGetGroupMessageHistory(groupID int64, seq int64) MSG {
|
||||||
|
if g := bot.Client.FindGroup(groupID); g == nil {
|
||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
if seq == 0 {
|
if seq == 0 {
|
||||||
g, err := bot.Client.GetGroupInfo(groupId)
|
g, err := bot.Client.GetGroupInfo(groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Failed(100, "GROUP_INFO_API_ERROR", err.Error())
|
return Failed(100, "GROUP_INFO_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
seq = g.LastMsgSeq
|
seq = g.LastMsgSeq
|
||||||
}
|
}
|
||||||
msg, err := bot.Client.GetGroupMessages(groupId, int64(math.Max(float64(seq-19), 1)), seq)
|
msg, err := bot.Client.GetGroupMessages(groupID, int64(math.Max(float64(seq-19), 1)), seq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("获取群历史消息失败: %v", err)
|
log.Warnf("获取群历史消息失败: %v", err)
|
||||||
return Failed(100, "MESSAGES_API_ERROR", err.Error())
|
return Failed(100, "MESSAGES_API_ERROR", err.Error())
|
||||||
@ -879,6 +967,9 @@ func (bot *CQBot) CQGetGroupMessageHistory(groupId int64, seq int64) MSG {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//CQGetOnlineClients : 扩展API-获取当前账号在线客户端列表
|
||||||
|
//
|
||||||
|
//https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E8%B4%A6%E5%8F%B7%E5%9C%A8%E7%BA%BF%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%88%97%E8%A1%A8
|
||||||
func (bot *CQBot) CQGetOnlineClients(noCache bool) MSG {
|
func (bot *CQBot) CQGetOnlineClients(noCache bool) MSG {
|
||||||
if noCache {
|
if noCache {
|
||||||
if err := bot.Client.RefreshStatus(); err != nil {
|
if err := bot.Client.RefreshStatus(); err != nil {
|
||||||
@ -899,16 +990,25 @@ func (bot *CQBot) CQGetOnlineClients(noCache bool) MSG {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//CQCanSendImage : 检查是否可以发送图片(此处永远返回true)
|
||||||
|
//
|
||||||
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#can_send_image-%E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E5%8F%91%E9%80%81%E5%9B%BE%E7%89%87
|
||||||
func (bot *CQBot) CQCanSendImage() MSG {
|
func (bot *CQBot) CQCanSendImage() MSG {
|
||||||
return OK(MSG{"yes": true})
|
return OK(MSG{"yes": true})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//CQCanSendRecord : 检查是否可以发送语音(此处永远返回true)
|
||||||
|
//
|
||||||
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#can_send_record-%E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E5%8F%91%E9%80%81%E8%AF%AD%E9%9F%B3
|
||||||
func (bot *CQBot) CQCanSendRecord() MSG {
|
func (bot *CQBot) CQCanSendRecord() MSG {
|
||||||
return OK(MSG{"yes": true})
|
return OK(MSG{"yes": true})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQOcrImage(imageId string) MSG {
|
//CQOcrImage : 扩展API-图片OCR
|
||||||
img, err := bot.makeImageOrVideoElem(map[string]string{"file": imageId}, false, true)
|
//
|
||||||
|
//https://docs.go-cqhttp.org/api/#%E5%9B%BE%E7%89%87-ocr
|
||||||
|
func (bot *CQBot) CQOcrImage(imageID string) MSG {
|
||||||
|
img, err := bot.makeImageOrVideoElem(map[string]string{"file": imageID}, false, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("load image error: %v", err)
|
log.Warnf("load image error: %v", err)
|
||||||
return Failed(100, "LOAD_FILE_ERROR", err.Error())
|
return Failed(100, "LOAD_FILE_ERROR", err.Error())
|
||||||
@ -921,13 +1021,19 @@ func (bot *CQBot) CQOcrImage(imageId string) MSG {
|
|||||||
return OK(rsp)
|
return OK(rsp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//CQReloadEventFilter : 扩展API-重载事件过滤器
|
||||||
|
//
|
||||||
|
//https://docs.go-cqhttp.org/api/#%E9%87%8D%E8%BD%BD%E4%BA%8B%E4%BB%B6%E8%BF%87%E6%BB%A4%E5%99%A8
|
||||||
func (bot *CQBot) CQReloadEventFilter() MSG {
|
func (bot *CQBot) CQReloadEventFilter() MSG {
|
||||||
global.BootFilter()
|
global.BootFilter()
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQSetGroupPortrait(groupId int64, file, cache string) MSG {
|
//CQSetGroupPortrait : 扩展API-设置群头像
|
||||||
if g := bot.Client.FindGroup(groupId); g != nil {
|
//
|
||||||
|
//https://docs.go-cqhttp.org/api/#%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%A4%B4%E5%83%8F
|
||||||
|
func (bot *CQBot) CQSetGroupPortrait(groupID int64, file, cache string) MSG {
|
||||||
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
img, err := global.FindFile(file, cache, global.ImagePath)
|
img, err := global.FindFile(file, cache, global.ImagePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("set group portrait error: %v", err)
|
log.Warnf("set group portrait error: %v", err)
|
||||||
@ -939,11 +1045,14 @@ func (bot *CQBot) CQSetGroupPortrait(groupId int64, file, cache string) MSG {
|
|||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQSetGroupAnonymousBan(groupId int64, flag string, duration int32) MSG {
|
//CQSetGroupAnonymousBan : 群组匿名用户禁言
|
||||||
|
//
|
||||||
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_anonymous_ban-%E7%BE%A4%E7%BB%84%E5%8C%BF%E5%90%8D%E7%94%A8%E6%88%B7%E7%A6%81%E8%A8%80
|
||||||
|
func (bot *CQBot) CQSetGroupAnonymousBan(groupID int64, flag string, duration int32) MSG {
|
||||||
if flag == "" {
|
if flag == "" {
|
||||||
return Failed(100, "INVALID_FLAG", "无效的flag")
|
return Failed(100, "INVALID_FLAG", "无效的flag")
|
||||||
}
|
}
|
||||||
if g := bot.Client.FindGroup(groupId); g != nil {
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
s := strings.SplitN(flag, "|", 2)
|
s := strings.SplitN(flag, "|", 2)
|
||||||
if len(s) != 2 {
|
if len(s) != 2 {
|
||||||
return Failed(100, "INVALID_FLAG", "无效的flag")
|
return Failed(100, "INVALID_FLAG", "无效的flag")
|
||||||
@ -959,7 +1068,9 @@ func (bot *CQBot) CQSetGroupAnonymousBan(groupId int64, flag string, duration in
|
|||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_status-%E8%8E%B7%E5%8F%96%E8%BF%90%E8%A1%8C%E7%8A%B6%E6%80%81
|
//CQGetStatus : 获取运行状态
|
||||||
|
//
|
||||||
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_status-%E8%8E%B7%E5%8F%96%E8%BF%90%E8%A1%8C%E7%8A%B6%E6%80%81
|
||||||
func (bot *CQBot) CQGetStatus() MSG {
|
func (bot *CQBot) CQGetStatus() MSG {
|
||||||
return OK(MSG{
|
return OK(MSG{
|
||||||
"app_initialized": true,
|
"app_initialized": true,
|
||||||
@ -972,6 +1083,9 @@ func (bot *CQBot) CQGetStatus() MSG {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//CQGetVersionInfo : 获取版本信息
|
||||||
|
//
|
||||||
|
//https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_version_info-%E8%8E%B7%E5%8F%96%E7%89%88%E6%9C%AC%E4%BF%A1%E6%81%AF
|
||||||
func (bot *CQBot) CQGetVersionInfo() MSG {
|
func (bot *CQBot) CQGetVersionInfo() MSG {
|
||||||
wd, _ := os.Getwd()
|
wd, _ := os.Getwd()
|
||||||
return OK(MSG{
|
return OK(MSG{
|
||||||
@ -1001,10 +1115,12 @@ func (bot *CQBot) CQGetVersionInfo() MSG {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//OK 生成成功返回值
|
||||||
func OK(data interface{}) MSG {
|
func OK(data interface{}) MSG {
|
||||||
return MSG{"data": data, "retcode": 0, "status": "ok"}
|
return MSG{"data": data, "retcode": 0, "status": "ok"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Failed 生成失败返回值
|
||||||
func Failed(code int, msg ...string) MSG {
|
func Failed(code int, msg ...string) MSG {
|
||||||
m := ""
|
m := ""
|
||||||
w := ""
|
w := ""
|
||||||
@ -1017,9 +1133,9 @@ func Failed(code int, msg ...string) MSG {
|
|||||||
return MSG{"data": nil, "retcode": code, "msg": m, "wording": w, "status": "failed"}
|
return MSG{"data": nil, "retcode": code, "msg": m, "wording": w, "status": "failed"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertGroupMemberInfo(groupId int64, m *client.GroupMemberInfo) MSG {
|
func convertGroupMemberInfo(groupID int64, m *client.GroupMemberInfo) MSG {
|
||||||
return MSG{
|
return MSG{
|
||||||
"group_id": groupId,
|
"group_id": groupID,
|
||||||
"user_id": m.Uin,
|
"user_id": m.Uin,
|
||||||
"nickname": m.Nickname,
|
"nickname": m.Nickname,
|
||||||
"card": m.CardName,
|
"card": m.CardName,
|
||||||
|
@ -205,14 +205,14 @@ func GetGroupRootFiles(s *httpServer, c *gin.Context) {
|
|||||||
func GetGroupFilesByFolderId(s *httpServer, c *gin.Context) {
|
func GetGroupFilesByFolderId(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
folderId := getParam(c, "folder_id")
|
folderId := getParam(c, "folder_id")
|
||||||
c.JSON(200, s.bot.CQGetGroupFilesByFolderId(gid, folderId))
|
c.JSON(200, s.bot.CQGetGroupFilesByFolderID(gid, folderId))
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetGroupFileUrl(s *httpServer, c *gin.Context) {
|
func GetGroupFileUrl(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
fid := getParam(c, "file_id")
|
fid := getParam(c, "file_id")
|
||||||
busid, _ := strconv.ParseInt(getParam(c, "busid"), 10, 32)
|
busid, _ := strconv.ParseInt(getParam(c, "busid"), 10, 32)
|
||||||
c.JSON(200, s.bot.CQGetGroupFileUrl(gid, fid, int32(busid)))
|
c.JSON(200, s.bot.CQGetGroupFileURL(gid, fid, int32(busid)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendMessage(s *httpServer, c *gin.Context) {
|
func SendMessage(s *httpServer, c *gin.Context) {
|
||||||
|
@ -557,10 +557,10 @@ var wsAPI = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
|||||||
return bot.CQGetGroupRootFiles(p.Get("group_id").Int())
|
return bot.CQGetGroupRootFiles(p.Get("group_id").Int())
|
||||||
},
|
},
|
||||||
"get_group_files_by_folder": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"get_group_files_by_folder": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetGroupFilesByFolderId(p.Get("group_id").Int(), p.Get("folder_id").Str)
|
return bot.CQGetGroupFilesByFolderID(p.Get("group_id").Int(), p.Get("folder_id").Str)
|
||||||
},
|
},
|
||||||
"get_group_file_url": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"get_group_file_url": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetGroupFileUrl(p.Get("group_id").Int(), p.Get("file_id").Str, int32(p.Get("busid").Int()))
|
return bot.CQGetGroupFileURL(p.Get("group_id").Int(), p.Get("file_id").Str, int32(p.Get("busid").Int()))
|
||||||
},
|
},
|
||||||
"get_group_msg_history": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"get_group_msg_history": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetGroupMessageHistory(p.Get("group_id").Int(), p.Get("message_seq").Int())
|
return bot.CQGetGroupMessageHistory(p.Get("group_id").Int(), p.Get("message_seq").Int())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user