mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 03:23:49 +08:00
style: move coolq.MSG to global package
This commit is contained in:
parent
6d19f07eb4
commit
efdd6bd16a
234
coolq/api.go
234
coolq/api.go
@ -41,16 +41,16 @@ func init() {
|
|||||||
// CQGetLoginInfo 获取登录号信息
|
// CQGetLoginInfo 获取登录号信息
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1I
|
// https://git.io/Jtz1I
|
||||||
func (bot *CQBot) CQGetLoginInfo() MSG {
|
func (bot *CQBot) CQGetLoginInfo() global.MSG {
|
||||||
return OK(MSG{"user_id": bot.Client.Uin, "nickname": bot.Client.Nickname})
|
return OK(global.MSG{"user_id": bot.Client.Uin, "nickname": bot.Client.Nickname})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CQGetQiDianAccountInfo 获取企点账号信息
|
// CQGetQiDianAccountInfo 获取企点账号信息
|
||||||
func (bot *CQBot) CQGetQiDianAccountInfo() MSG {
|
func (bot *CQBot) CQGetQiDianAccountInfo() global.MSG {
|
||||||
if bot.Client.QiDian == nil {
|
if bot.Client.QiDian == nil {
|
||||||
return Failed(100, "QIDIAN_PROTOCOL_REQUEST", "请使用企点协议")
|
return Failed(100, "QIDIAN_PROTOCOL_REQUEST", "请使用企点协议")
|
||||||
}
|
}
|
||||||
return OK(MSG{
|
return OK(global.MSG{
|
||||||
"master_id": bot.Client.QiDian.MasterUin,
|
"master_id": bot.Client.QiDian.MasterUin,
|
||||||
"ext_name": bot.Client.QiDian.ExtName,
|
"ext_name": bot.Client.QiDian.ExtName,
|
||||||
"create_time": bot.Client.QiDian.CreateTime,
|
"create_time": bot.Client.QiDian.CreateTime,
|
||||||
@ -60,10 +60,10 @@ func (bot *CQBot) CQGetQiDianAccountInfo() MSG {
|
|||||||
// CQGetFriendList 获取好友列表
|
// CQGetFriendList 获取好友列表
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1L
|
// https://git.io/Jtz1L
|
||||||
func (bot *CQBot) CQGetFriendList() MSG {
|
func (bot *CQBot) CQGetFriendList() global.MSG {
|
||||||
fs := make([]MSG, 0, len(bot.Client.FriendList))
|
fs := make([]global.MSG, 0, len(bot.Client.FriendList))
|
||||||
for _, f := range bot.Client.FriendList {
|
for _, f := range bot.Client.FriendList {
|
||||||
fs = append(fs, MSG{
|
fs = append(fs, global.MSG{
|
||||||
"nickname": f.Nickname,
|
"nickname": f.Nickname,
|
||||||
"remark": f.Remark,
|
"remark": f.Remark,
|
||||||
"user_id": f.Uin,
|
"user_id": f.Uin,
|
||||||
@ -75,15 +75,15 @@ func (bot *CQBot) CQGetFriendList() MSG {
|
|||||||
// CQGetUnidirectionalFriendList 获取单向好友列表
|
// CQGetUnidirectionalFriendList 获取单向好友列表
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
func (bot *CQBot) CQGetUnidirectionalFriendList() MSG {
|
func (bot *CQBot) CQGetUnidirectionalFriendList() global.MSG {
|
||||||
list, err := bot.Client.GetUnidirectionalFriendList()
|
list, err := bot.Client.GetUnidirectionalFriendList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取单向好友列表时出现错误: %v", err)
|
log.Errorf("获取单向好友列表时出现错误: %v", err)
|
||||||
return Failed(100, "API_ERROR", err.Error())
|
return Failed(100, "API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
fs := make([]MSG, 0, len(list))
|
fs := make([]global.MSG, 0, len(list))
|
||||||
for _, f := range list {
|
for _, f := range list {
|
||||||
fs = append(fs, MSG{
|
fs = append(fs, global.MSG{
|
||||||
"nickname": f.Nickname,
|
"nickname": f.Nickname,
|
||||||
"user_id": f.Uin,
|
"user_id": f.Uin,
|
||||||
"source": f.Source,
|
"source": f.Source,
|
||||||
@ -95,7 +95,7 @@ func (bot *CQBot) CQGetUnidirectionalFriendList() MSG {
|
|||||||
// CQDeleteUnidirectionalFriend 删除单向好友
|
// CQDeleteUnidirectionalFriend 删除单向好友
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
func (bot *CQBot) CQDeleteUnidirectionalFriend(uin int64) MSG {
|
func (bot *CQBot) CQDeleteUnidirectionalFriend(uin int64) global.MSG {
|
||||||
list, err := bot.Client.GetUnidirectionalFriendList()
|
list, err := bot.Client.GetUnidirectionalFriendList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取单向好友列表时出现错误: %v", err)
|
log.Errorf("获取单向好友列表时出现错误: %v", err)
|
||||||
@ -116,7 +116,7 @@ func (bot *CQBot) CQDeleteUnidirectionalFriend(uin int64) MSG {
|
|||||||
// CQDeleteFriend 删除好友
|
// CQDeleteFriend 删除好友
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
func (bot *CQBot) CQDeleteFriend(uin int64) MSG {
|
func (bot *CQBot) CQDeleteFriend(uin int64) global.MSG {
|
||||||
if bot.Client.FindFriend(uin) == nil {
|
if bot.Client.FindFriend(uin) == nil {
|
||||||
return Failed(100, "FRIEND_NOT_FOUND", "好友不存在")
|
return Failed(100, "FRIEND_NOT_FOUND", "好友不存在")
|
||||||
}
|
}
|
||||||
@ -130,13 +130,13 @@ func (bot *CQBot) CQDeleteFriend(uin int64) MSG {
|
|||||||
// CQGetGroupList 获取群列表
|
// CQGetGroupList 获取群列表
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1t
|
// https://git.io/Jtz1t
|
||||||
func (bot *CQBot) CQGetGroupList(noCache bool) MSG {
|
func (bot *CQBot) CQGetGroupList(noCache bool) global.MSG {
|
||||||
gs := make([]MSG, 0, len(bot.Client.GroupList))
|
gs := make([]global.MSG, 0, len(bot.Client.GroupList))
|
||||||
if noCache {
|
if noCache {
|
||||||
_ = bot.Client.ReloadGroupList()
|
_ = bot.Client.ReloadGroupList()
|
||||||
}
|
}
|
||||||
for _, g := range bot.Client.GroupList {
|
for _, g := range bot.Client.GroupList {
|
||||||
gs = append(gs, MSG{
|
gs = append(gs, global.MSG{
|
||||||
"group_id": g.Code,
|
"group_id": g.Code,
|
||||||
"group_name": g.Name,
|
"group_name": g.Name,
|
||||||
"group_memo": g.Memo,
|
"group_memo": g.Memo,
|
||||||
@ -152,7 +152,7 @@ func (bot *CQBot) CQGetGroupList(noCache bool) MSG {
|
|||||||
// CQGetGroupInfo 获取群信息
|
// CQGetGroupInfo 获取群信息
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1O
|
// https://git.io/Jtz1O
|
||||||
func (bot *CQBot) CQGetGroupInfo(groupID int64, noCache bool) MSG {
|
func (bot *CQBot) CQGetGroupInfo(groupID int64, noCache bool) global.MSG {
|
||||||
group := bot.Client.FindGroup(groupID)
|
group := bot.Client.FindGroup(groupID)
|
||||||
if group == nil || noCache {
|
if group == nil || noCache {
|
||||||
group, _ = bot.Client.GetGroupInfo(groupID)
|
group, _ = bot.Client.GetGroupInfo(groupID)
|
||||||
@ -165,7 +165,7 @@ func (bot *CQBot) CQGetGroupInfo(groupID int64, noCache bool) MSG {
|
|||||||
}
|
}
|
||||||
for _, g := range info {
|
for _, g := range info {
|
||||||
if g.Code == groupID {
|
if g.Code == groupID {
|
||||||
return OK(MSG{
|
return OK(global.MSG{
|
||||||
"group_id": g.Code,
|
"group_id": g.Code,
|
||||||
"group_name": g.Name,
|
"group_name": g.Name,
|
||||||
"group_memo": g.Memo,
|
"group_memo": g.Memo,
|
||||||
@ -177,7 +177,7 @@ func (bot *CQBot) CQGetGroupInfo(groupID int64, noCache bool) MSG {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return OK(MSG{
|
return OK(global.MSG{
|
||||||
"group_id": group.Code,
|
"group_id": group.Code,
|
||||||
"group_name": group.Name,
|
"group_name": group.Name,
|
||||||
"group_memo": group.Memo,
|
"group_memo": group.Memo,
|
||||||
@ -193,7 +193,7 @@ func (bot *CQBot) CQGetGroupInfo(groupID int64, noCache bool) MSG {
|
|||||||
// CQGetGroupMemberList 获取群成员列表
|
// CQGetGroupMemberList 获取群成员列表
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz13
|
// https://git.io/Jtz13
|
||||||
func (bot *CQBot) CQGetGroupMemberList(groupID int64, noCache bool) MSG {
|
func (bot *CQBot) CQGetGroupMemberList(groupID int64, noCache bool) global.MSG {
|
||||||
group := bot.Client.FindGroup(groupID)
|
group := bot.Client.FindGroup(groupID)
|
||||||
if group == nil {
|
if group == nil {
|
||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
@ -206,7 +206,7 @@ func (bot *CQBot) CQGetGroupMemberList(groupID int64, noCache bool) MSG {
|
|||||||
}
|
}
|
||||||
group.Members = t
|
group.Members = t
|
||||||
}
|
}
|
||||||
members := make([]MSG, 0, len(group.Members))
|
members := make([]global.MSG, 0, len(group.Members))
|
||||||
for _, m := range group.Members {
|
for _, m := range group.Members {
|
||||||
members = append(members, convertGroupMemberInfo(groupID, m))
|
members = append(members, convertGroupMemberInfo(groupID, m))
|
||||||
}
|
}
|
||||||
@ -216,7 +216,7 @@ func (bot *CQBot) CQGetGroupMemberList(groupID int64, noCache bool) MSG {
|
|||||||
// CQGetGroupMemberInfo 获取群成员信息
|
// CQGetGroupMemberInfo 获取群成员信息
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1s
|
// https://git.io/Jtz1s
|
||||||
func (bot *CQBot) CQGetGroupMemberInfo(groupID, userID int64, noCache bool) MSG {
|
func (bot *CQBot) CQGetGroupMemberInfo(groupID, userID int64, noCache bool) global.MSG {
|
||||||
group := bot.Client.FindGroup(groupID)
|
group := bot.Client.FindGroup(groupID)
|
||||||
if group == nil {
|
if group == nil {
|
||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
@ -241,7 +241,7 @@ func (bot *CQBot) CQGetGroupMemberInfo(groupID, userID int64, noCache bool) MSG
|
|||||||
// CQGetGroupFileSystemInfo 扩展API-获取群文件系统信息
|
// CQGetGroupFileSystemInfo 扩展API-获取群文件系统信息
|
||||||
//
|
//
|
||||||
// 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
|
// 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 {
|
func (bot *CQBot) CQGetGroupFileSystemInfo(groupID int64) global.MSG {
|
||||||
fs, err := bot.Client.GetGroupFileSystem(groupID)
|
fs, err := bot.Client.GetGroupFileSystem(groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
|
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
|
||||||
@ -253,7 +253,7 @@ func (bot *CQBot) CQGetGroupFileSystemInfo(groupID int64) MSG {
|
|||||||
// CQGetGroupRootFiles 扩展API-获取群根目录文件列表
|
// CQGetGroupRootFiles 扩展API-获取群根目录文件列表
|
||||||
//
|
//
|
||||||
// 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
|
// 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 {
|
func (bot *CQBot) CQGetGroupRootFiles(groupID int64) global.MSG {
|
||||||
fs, err := bot.Client.GetGroupFileSystem(groupID)
|
fs, err := bot.Client.GetGroupFileSystem(groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
|
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
|
||||||
@ -264,7 +264,7 @@ func (bot *CQBot) CQGetGroupRootFiles(groupID int64) MSG {
|
|||||||
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(global.MSG{
|
||||||
"files": files,
|
"files": files,
|
||||||
"folders": folders,
|
"folders": folders,
|
||||||
})
|
})
|
||||||
@ -273,7 +273,7 @@ func (bot *CQBot) CQGetGroupRootFiles(groupID int64) MSG {
|
|||||||
// CQGetGroupFilesByFolderID 扩展API-获取群子目录文件列表
|
// CQGetGroupFilesByFolderID 扩展API-获取群子目录文件列表
|
||||||
//
|
//
|
||||||
// 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
|
// 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 {
|
func (bot *CQBot) CQGetGroupFilesByFolderID(groupID int64, folderID string) global.MSG {
|
||||||
fs, err := bot.Client.GetGroupFileSystem(groupID)
|
fs, err := bot.Client.GetGroupFileSystem(groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
|
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
|
||||||
@ -284,7 +284,7 @@ func (bot *CQBot) CQGetGroupFilesByFolderID(groupID int64, folderID string) MSG
|
|||||||
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(global.MSG{
|
||||||
"files": files,
|
"files": files,
|
||||||
"folders": folders,
|
"folders": folders,
|
||||||
})
|
})
|
||||||
@ -293,12 +293,12 @@ func (bot *CQBot) CQGetGroupFilesByFolderID(groupID int64, folderID string) MSG
|
|||||||
// CQGetGroupFileURL 扩展API-获取群文件资源链接
|
// CQGetGroupFileURL 扩展API-获取群文件资源链接
|
||||||
//
|
//
|
||||||
// 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
|
// 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 {
|
func (bot *CQBot) CQGetGroupFileURL(groupID int64, fileID string, busID int32) global.MSG {
|
||||||
url := bot.Client.GetGroupFileUrl(groupID, fileID, busID)
|
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")
|
||||||
}
|
}
|
||||||
return OK(MSG{
|
return OK(global.MSG{
|
||||||
"url": url,
|
"url": url,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -306,7 +306,7 @@ func (bot *CQBot) CQGetGroupFileURL(groupID int64, fileID string, busID int32) M
|
|||||||
// CQUploadGroupFile 扩展API-上传群文件
|
// CQUploadGroupFile 扩展API-上传群文件
|
||||||
//
|
//
|
||||||
// https://docs.go-cqhttp.org/api/#%E4%B8%8A%E4%BC%A0%E7%BE%A4%E6%96%87%E4%BB%B6
|
// https://docs.go-cqhttp.org/api/#%E4%B8%8A%E4%BC%A0%E7%BE%A4%E6%96%87%E4%BB%B6
|
||||||
func (bot *CQBot) CQUploadGroupFile(groupID int64, file, name, folder string) MSG {
|
func (bot *CQBot) CQUploadGroupFile(groupID int64, file, name, folder string) global.MSG {
|
||||||
if !global.PathExists(file) {
|
if !global.PathExists(file) {
|
||||||
log.Errorf("上传群文件 %v 失败: 文件不存在", file)
|
log.Errorf("上传群文件 %v 失败: 文件不存在", file)
|
||||||
return Failed(100, "FILE_NOT_FOUND", "文件不存在")
|
return Failed(100, "FILE_NOT_FOUND", "文件不存在")
|
||||||
@ -329,7 +329,7 @@ func (bot *CQBot) CQUploadGroupFile(groupID int64, file, name, folder string) MS
|
|||||||
// CQGroupFileCreateFolder 拓展API-创建群文件文件夹
|
// CQGroupFileCreateFolder 拓展API-创建群文件文件夹
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
func (bot *CQBot) CQGroupFileCreateFolder(groupID int64, parentID, name string) MSG {
|
func (bot *CQBot) CQGroupFileCreateFolder(groupID int64, parentID, name string) global.MSG {
|
||||||
fs, err := bot.Client.GetGroupFileSystem(groupID)
|
fs, err := bot.Client.GetGroupFileSystem(groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
|
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
|
||||||
@ -345,7 +345,7 @@ func (bot *CQBot) CQGroupFileCreateFolder(groupID int64, parentID, name string)
|
|||||||
// CQGroupFileDeleteFolder 拓展API-删除群文件文件夹
|
// CQGroupFileDeleteFolder 拓展API-删除群文件文件夹
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
func (bot *CQBot) CQGroupFileDeleteFolder(groupID int64, id string) MSG {
|
func (bot *CQBot) CQGroupFileDeleteFolder(groupID int64, id string) global.MSG {
|
||||||
fs, err := bot.Client.GetGroupFileSystem(groupID)
|
fs, err := bot.Client.GetGroupFileSystem(groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
|
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
|
||||||
@ -361,7 +361,7 @@ func (bot *CQBot) CQGroupFileDeleteFolder(groupID int64, id string) MSG {
|
|||||||
// CQGroupFileDeleteFile 拓展API-删除群文件
|
// CQGroupFileDeleteFile 拓展API-删除群文件
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
func (bot *CQBot) CQGroupFileDeleteFile(groupID int64, id string, busID int32) MSG {
|
func (bot *CQBot) CQGroupFileDeleteFile(groupID int64, id string, busID int32) global.MSG {
|
||||||
fs, err := bot.Client.GetGroupFileSystem(groupID)
|
fs, err := bot.Client.GetGroupFileSystem(groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
|
log.Errorf("获取群 %v 文件系统信息失败: %v", groupID, err)
|
||||||
@ -377,7 +377,7 @@ func (bot *CQBot) CQGroupFileDeleteFile(groupID int64, id string, busID int32) M
|
|||||||
// CQGetWordSlices 隐藏API-获取中文分词
|
// 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
|
// 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) global.MSG {
|
||||||
slices, err := bot.Client.GetWordSegmentation(content)
|
slices, err := bot.Client.GetWordSegmentation(content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Failed(100, "WORD_SEGMENTATION_API_ERROR", err.Error())
|
return Failed(100, "WORD_SEGMENTATION_API_ERROR", err.Error())
|
||||||
@ -385,13 +385,13 @@ func (bot *CQBot) CQGetWordSlices(content string) MSG {
|
|||||||
for i := 0; i < len(slices); i++ {
|
for i := 0; i < len(slices); i++ {
|
||||||
slices[i] = strings.ReplaceAll(slices[i], "\u0000", "")
|
slices[i] = strings.ReplaceAll(slices[i], "\u0000", "")
|
||||||
}
|
}
|
||||||
return OK(MSG{"slices": slices})
|
return OK(global.MSG{"slices": slices})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CQSendGroupMessage 发送群消息
|
// CQSendGroupMessage 发送群消息
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1c
|
// https://git.io/Jtz1c
|
||||||
func (bot *CQBot) CQSendGroupMessage(groupID int64, m gjson.Result, autoEscape bool) MSG {
|
func (bot *CQBot) CQSendGroupMessage(groupID int64, m gjson.Result, autoEscape bool) global.MSG {
|
||||||
group := bot.Client.FindGroup(groupID)
|
group := bot.Client.FindGroup(groupID)
|
||||||
if group == nil {
|
if group == nil {
|
||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
@ -430,13 +430,13 @@ func (bot *CQBot) CQSendGroupMessage(groupID int64, m gjson.Result, autoEscape b
|
|||||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
|
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
|
||||||
}
|
}
|
||||||
log.Infof("发送群 %v(%v) 的消息: %v (%v)", group.Name, groupID, limitedString(m.String()), mid)
|
log.Infof("发送群 %v(%v) 的消息: %v (%v)", group.Name, groupID, limitedString(m.String()), mid)
|
||||||
return OK(MSG{"message_id": mid})
|
return OK(global.MSG{"message_id": mid})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CQSendGroupForwardMessage 扩展API-发送合并转发(群)
|
// 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
|
// 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 {
|
func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) global.MSG {
|
||||||
if m.Type != gjson.JSON {
|
if m.Type != gjson.JSON {
|
||||||
return Failed(100)
|
return Failed(100)
|
||||||
}
|
}
|
||||||
@ -558,7 +558,7 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
|
|||||||
log.Warnf("合并转发(群)消息发送失败: 账号可能被风控.")
|
log.Warnf("合并转发(群)消息发送失败: 账号可能被风控.")
|
||||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
|
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
|
||||||
}
|
}
|
||||||
return OK(MSG{
|
return OK(global.MSG{
|
||||||
"message_id": bot.InsertGroupMessage(ret),
|
"message_id": bot.InsertGroupMessage(ret),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -568,7 +568,7 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
|
|||||||
// CQSendPrivateMessage 发送私聊消息
|
// CQSendPrivateMessage 发送私聊消息
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1l
|
// https://git.io/Jtz1l
|
||||||
func (bot *CQBot) CQSendPrivateMessage(userID int64, groupID int64, m gjson.Result, autoEscape bool) MSG {
|
func (bot *CQBot) CQSendPrivateMessage(userID int64, groupID int64, m gjson.Result, autoEscape bool) global.MSG {
|
||||||
var elem []message.IMessageElement
|
var elem []message.IMessageElement
|
||||||
if m.Type == gjson.JSON {
|
if m.Type == gjson.JSON {
|
||||||
elem = bot.ConvertObjectMessage(m, false)
|
elem = bot.ConvertObjectMessage(m, false)
|
||||||
@ -588,13 +588,13 @@ func (bot *CQBot) CQSendPrivateMessage(userID int64, groupID int64, m gjson.Resu
|
|||||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
|
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
|
||||||
}
|
}
|
||||||
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(global.MSG{"message_id": mid})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CQSetGroupCard 设置群名片(群备注)
|
// CQSetGroupCard 设置群名片(群备注)
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1B
|
// https://git.io/Jtz1B
|
||||||
func (bot *CQBot) CQSetGroupCard(groupID, userID int64, card string) MSG {
|
func (bot *CQBot) CQSetGroupCard(groupID, userID int64, card string) global.MSG {
|
||||||
if g := bot.Client.FindGroup(groupID); g != nil {
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
if m := g.FindMember(userID); m != nil {
|
if m := g.FindMember(userID); m != nil {
|
||||||
m.EditCard(card)
|
m.EditCard(card)
|
||||||
@ -607,7 +607,7 @@ func (bot *CQBot) CQSetGroupCard(groupID, userID int64, card string) MSG {
|
|||||||
// CQSetGroupSpecialTitle 设置群组专属头衔
|
// CQSetGroupSpecialTitle 设置群组专属头衔
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz10
|
// https://git.io/Jtz10
|
||||||
func (bot *CQBot) CQSetGroupSpecialTitle(groupID, userID int64, title string) MSG {
|
func (bot *CQBot) CQSetGroupSpecialTitle(groupID, userID int64, title string) global.MSG {
|
||||||
if g := bot.Client.FindGroup(groupID); g != nil {
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
if m := g.FindMember(userID); m != nil {
|
if m := g.FindMember(userID); m != nil {
|
||||||
m.EditSpecialTitle(title)
|
m.EditSpecialTitle(title)
|
||||||
@ -620,7 +620,7 @@ func (bot *CQBot) CQSetGroupSpecialTitle(groupID, userID int64, title string) MS
|
|||||||
// CQSetGroupName 设置群名
|
// CQSetGroupName 设置群名
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz12
|
// https://git.io/Jtz12
|
||||||
func (bot *CQBot) CQSetGroupName(groupID int64, name string) MSG {
|
func (bot *CQBot) CQSetGroupName(groupID int64, name string) global.MSG {
|
||||||
if g := bot.Client.FindGroup(groupID); g != nil {
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
g.UpdateName(name)
|
g.UpdateName(name)
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
@ -631,7 +631,7 @@ func (bot *CQBot) CQSetGroupName(groupID int64, name string) MSG {
|
|||||||
// CQSetGroupMemo 扩展API-发送群公告
|
// CQSetGroupMemo 扩展API-发送群公告
|
||||||
//
|
//
|
||||||
// https://docs.go-cqhttp.org/api/#%E5%8F%91%E9%80%81%E7%BE%A4%E5%85%AC%E5%91%8A
|
// 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, img string) MSG {
|
func (bot *CQBot) CQSetGroupMemo(groupID int64, msg string, img string) global.MSG {
|
||||||
if g := bot.Client.FindGroup(groupID); g != nil {
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
if g.SelfPermission() == client.Member {
|
if g.SelfPermission() == client.Member {
|
||||||
return Failed(100, "PERMISSION_DENIED", "权限不足")
|
return Failed(100, "PERMISSION_DENIED", "权限不足")
|
||||||
@ -659,7 +659,7 @@ func (bot *CQBot) CQSetGroupMemo(groupID int64, msg string, img string) MSG {
|
|||||||
// CQSetGroupKick 群组踢人
|
// CQSetGroupKick 群组踢人
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1V
|
// https://git.io/Jtz1V
|
||||||
func (bot *CQBot) CQSetGroupKick(groupID, userID int64, msg string, block bool) MSG {
|
func (bot *CQBot) CQSetGroupKick(groupID, userID int64, msg string, block bool) global.MSG {
|
||||||
if g := bot.Client.FindGroup(groupID); g != nil {
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
if m := g.FindMember(userID); m != nil {
|
if m := g.FindMember(userID); m != nil {
|
||||||
err := m.Kick(msg, block)
|
err := m.Kick(msg, block)
|
||||||
@ -675,7 +675,7 @@ func (bot *CQBot) CQSetGroupKick(groupID, userID int64, msg string, block bool)
|
|||||||
// CQSetGroupBan 群组单人禁言
|
// CQSetGroupBan 群组单人禁言
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1w
|
// https://git.io/Jtz1w
|
||||||
func (bot *CQBot) CQSetGroupBan(groupID, userID int64, duration uint32) MSG {
|
func (bot *CQBot) CQSetGroupBan(groupID, userID int64, duration uint32) global.MSG {
|
||||||
if g := bot.Client.FindGroup(groupID); g != nil {
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
if m := g.FindMember(userID); m != nil {
|
if m := g.FindMember(userID); m != nil {
|
||||||
err := m.Mute(duration)
|
err := m.Mute(duration)
|
||||||
@ -694,7 +694,7 @@ func (bot *CQBot) CQSetGroupBan(groupID, userID int64, duration uint32) MSG {
|
|||||||
// CQSetGroupWholeBan 群组全员禁言
|
// CQSetGroupWholeBan 群组全员禁言
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1o
|
// https://git.io/Jtz1o
|
||||||
func (bot *CQBot) CQSetGroupWholeBan(groupID int64, enable bool) MSG {
|
func (bot *CQBot) CQSetGroupWholeBan(groupID int64, enable bool) global.MSG {
|
||||||
if g := bot.Client.FindGroup(groupID); g != nil {
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
g.MuteAll(enable)
|
g.MuteAll(enable)
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
@ -705,7 +705,7 @@ func (bot *CQBot) CQSetGroupWholeBan(groupID int64, enable bool) MSG {
|
|||||||
// CQSetGroupLeave 退出群组
|
// CQSetGroupLeave 退出群组
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1K
|
// https://git.io/Jtz1K
|
||||||
func (bot *CQBot) CQSetGroupLeave(groupID int64) MSG {
|
func (bot *CQBot) CQSetGroupLeave(groupID int64) global.MSG {
|
||||||
if g := bot.Client.FindGroup(groupID); g != nil {
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
g.Quit()
|
g.Quit()
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
@ -716,7 +716,7 @@ func (bot *CQBot) CQSetGroupLeave(groupID int64) MSG {
|
|||||||
// CQGetAtAllRemain 扩展API-获取群 @全体成员 剩余次数
|
// CQGetAtAllRemain 扩展API-获取群 @全体成员 剩余次数
|
||||||
//
|
//
|
||||||
// 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
|
// 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 {
|
func (bot *CQBot) CQGetAtAllRemain(groupID int64) global.MSG {
|
||||||
if g := bot.Client.FindGroup(groupID); g != nil {
|
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||||
i, err := bot.Client.GetAtAllRemain(groupID)
|
i, err := bot.Client.GetAtAllRemain(groupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -730,7 +730,7 @@ func (bot *CQBot) CQGetAtAllRemain(groupID int64) MSG {
|
|||||||
// CQProcessFriendRequest 处理加好友请求
|
// CQProcessFriendRequest 处理加好友请求
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz11
|
// https://git.io/Jtz11
|
||||||
func (bot *CQBot) CQProcessFriendRequest(flag string, approve bool) MSG {
|
func (bot *CQBot) CQProcessFriendRequest(flag string, approve bool) global.MSG {
|
||||||
req, ok := bot.friendReqCache.Load(flag)
|
req, ok := bot.friendReqCache.Load(flag)
|
||||||
if !ok {
|
if !ok {
|
||||||
return Failed(100, "FLAG_NOT_FOUND", "FLAG不存在")
|
return Failed(100, "FLAG_NOT_FOUND", "FLAG不存在")
|
||||||
@ -746,7 +746,7 @@ func (bot *CQBot) CQProcessFriendRequest(flag string, approve bool) MSG {
|
|||||||
// CQProcessGroupRequest 处理加群请求/邀请
|
// CQProcessGroupRequest 处理加群请求/邀请
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1D
|
// https://git.io/Jtz1D
|
||||||
func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bool) MSG {
|
func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bool) global.MSG {
|
||||||
msgs, err := bot.Client.GetGroupSystemMessages()
|
msgs, err := bot.Client.GetGroupSystemMessages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取群系统消息失败: %v", err)
|
log.Errorf("获取群系统消息失败: %v", err)
|
||||||
@ -790,7 +790,7 @@ func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bo
|
|||||||
// CQDeleteMessage 撤回消息
|
// CQDeleteMessage 撤回消息
|
||||||
//
|
//
|
||||||
// https:// git.io/Jtz1y
|
// https:// git.io/Jtz1y
|
||||||
func (bot *CQBot) CQDeleteMessage(messageID int32) MSG {
|
func (bot *CQBot) CQDeleteMessage(messageID int32) global.MSG {
|
||||||
msg := bot.GetMessage(messageID)
|
msg := bot.GetMessage(messageID)
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
return Failed(100, "MESSAGE_NOT_FOUND", "消息不存在")
|
return Failed(100, "MESSAGE_NOT_FOUND", "消息不存在")
|
||||||
@ -821,7 +821,7 @@ func (bot *CQBot) CQDeleteMessage(messageID int32) MSG {
|
|||||||
// CQSetGroupAdmin 群组设置管理员
|
// CQSetGroupAdmin 群组设置管理员
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1S
|
// https://git.io/Jtz1S
|
||||||
func (bot *CQBot) CQSetGroupAdmin(groupID, userID int64, enable bool) MSG {
|
func (bot *CQBot) CQSetGroupAdmin(groupID, userID int64, enable bool) global.MSG {
|
||||||
group := bot.Client.FindGroup(groupID)
|
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", "群不存在或权限不足")
|
||||||
@ -843,12 +843,12 @@ func (bot *CQBot) CQSetGroupAdmin(groupID, userID int64, enable bool) MSG {
|
|||||||
// CQGetVipInfo 扩展API-获取VIP信息
|
// CQGetVipInfo 扩展API-获取VIP信息
|
||||||
//
|
//
|
||||||
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96vip%E4%BF%A1%E6%81%AF
|
// 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 {
|
func (bot *CQBot) CQGetVipInfo(userID int64) global.MSG {
|
||||||
vip, err := bot.Client.GetVipInfo(userID)
|
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())
|
||||||
}
|
}
|
||||||
msg := MSG{
|
msg := global.MSG{
|
||||||
"user_id": vip.Uin,
|
"user_id": vip.Uin,
|
||||||
"nickname": vip.Name,
|
"nickname": vip.Name,
|
||||||
"level": vip.Level,
|
"level": vip.Level,
|
||||||
@ -863,11 +863,11 @@ func (bot *CQBot) CQGetVipInfo(userID int64) MSG {
|
|||||||
// CQGetGroupHonorInfo 获取群荣誉信息
|
// CQGetGroupHonorInfo 获取群荣誉信息
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1H
|
// https://git.io/Jtz1H
|
||||||
func (bot *CQBot) CQGetGroupHonorInfo(groupID int64, t string) MSG {
|
func (bot *CQBot) CQGetGroupHonorInfo(groupID int64, t string) global.MSG {
|
||||||
msg := MSG{"group_id": groupID}
|
msg := global.MSG{"group_id": groupID}
|
||||||
convertMem := func(memList []client.HonorMemberInfo) (ret []MSG) {
|
convertMem := func(memList []client.HonorMemberInfo) (ret []global.MSG) {
|
||||||
for _, mem := range memList {
|
for _, mem := range memList {
|
||||||
ret = append(ret, MSG{
|
ret = append(ret, global.MSG{
|
||||||
"user_id": mem.Uin,
|
"user_id": mem.Uin,
|
||||||
"nickname": mem.Name,
|
"nickname": mem.Name,
|
||||||
"avatar": mem.Avatar,
|
"avatar": mem.Avatar,
|
||||||
@ -879,7 +879,7 @@ func (bot *CQBot) CQGetGroupHonorInfo(groupID int64, t string) MSG {
|
|||||||
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"] = global.MSG{
|
||||||
"user_id": honor.CurrentTalkative.Uin,
|
"user_id": honor.CurrentTalkative.Uin,
|
||||||
"nickname": honor.CurrentTalkative.Name,
|
"nickname": honor.CurrentTalkative.Name,
|
||||||
"avatar": honor.CurrentTalkative.Avatar,
|
"avatar": honor.CurrentTalkative.Avatar,
|
||||||
@ -920,12 +920,12 @@ func (bot *CQBot) CQGetGroupHonorInfo(groupID int64, t string) MSG {
|
|||||||
// CQGetStrangerInfo 获取陌生人信息
|
// CQGetStrangerInfo 获取陌生人信息
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz17
|
// https://git.io/Jtz17
|
||||||
func (bot *CQBot) CQGetStrangerInfo(userID int64) MSG {
|
func (bot *CQBot) CQGetStrangerInfo(userID int64) global.MSG {
|
||||||
info, err := bot.Client.GetSummaryInfo(userID)
|
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())
|
||||||
}
|
}
|
||||||
return OK(MSG{
|
return OK(global.MSG{
|
||||||
"user_id": info.Uin,
|
"user_id": info.Uin,
|
||||||
"nickname": info.Nickname,
|
"nickname": info.Nickname,
|
||||||
"qid": info.Qid,
|
"qid": info.Qid,
|
||||||
@ -947,7 +947,7 @@ func (bot *CQBot) CQGetStrangerInfo(userID int64) MSG {
|
|||||||
// CQHandleQuickOperation 隐藏API-对事件执行快速操作
|
// CQHandleQuickOperation 隐藏API-对事件执行快速操作
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz15
|
// https://git.io/Jtz15
|
||||||
func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) global.MSG {
|
||||||
postType := context.Get("post_type").Str
|
postType := context.Get("post_type").Str
|
||||||
|
|
||||||
switch postType {
|
switch postType {
|
||||||
@ -962,11 +962,11 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
|||||||
at := operation.Get("at_sender").Bool() && !isAnonymous && msgType == "group"
|
at := operation.Get("at_sender").Bool() && !isAnonymous && msgType == "group"
|
||||||
if at && reply.IsArray() {
|
if at && reply.IsArray() {
|
||||||
// 在 reply 数组头部插入CQ码
|
// 在 reply 数组头部插入CQ码
|
||||||
replySegments := make([]MSG, 0)
|
replySegments := make([]global.MSG, 0)
|
||||||
segments := make([]MSG, 0)
|
segments := make([]global.MSG, 0)
|
||||||
segments = append(segments, MSG{
|
segments = append(segments, global.MSG{
|
||||||
"type": "at",
|
"type": "at",
|
||||||
"data": MSG{
|
"data": global.MSG{
|
||||||
"qq": context.Get("sender.user_id").Int(),
|
"qq": context.Get("sender.user_id").Int(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -1036,7 +1036,7 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
|||||||
// CQGetImage 获取图片(修改自OneBot)
|
// 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
|
// 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) global.MSG {
|
||||||
if !global.PathExists(path.Join(global.ImagePath, file)) {
|
if !global.PathExists(path.Join(global.ImagePath, file)) {
|
||||||
return Failed(100)
|
return Failed(100)
|
||||||
}
|
}
|
||||||
@ -1044,7 +1044,7 @@ func (bot *CQBot) CQGetImage(file string) MSG {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
r := binary.NewReader(b)
|
r := binary.NewReader(b)
|
||||||
r.ReadBytes(16)
|
r.ReadBytes(16)
|
||||||
msg := MSG{
|
msg := global.MSG{
|
||||||
"size": r.ReadInt32(),
|
"size": r.ReadInt32(),
|
||||||
"filename": r.ReadString(),
|
"filename": r.ReadString(),
|
||||||
"url": r.ReadString(),
|
"url": r.ReadString(),
|
||||||
@ -1067,7 +1067,7 @@ func (bot *CQBot) CQGetImage(file string) MSG {
|
|||||||
// CQDownloadFile 扩展API-下载文件到缓存目录
|
// CQDownloadFile 扩展API-下载文件到缓存目录
|
||||||
//
|
//
|
||||||
// https://docs.go-cqhttp.org/api/#%E4%B8%8B%E8%BD%BD%E6%96%87%E4%BB%B6%E5%88%B0%E7%BC%93%E5%AD%98%E7%9B%AE%E5%BD%95
|
// https://docs.go-cqhttp.org/api/#%E4%B8%8B%E8%BD%BD%E6%96%87%E4%BB%B6%E5%88%B0%E7%BC%93%E5%AD%98%E7%9B%AE%E5%BD%95
|
||||||
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) global.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")
|
||||||
if global.PathExists(file) {
|
if global.PathExists(file) {
|
||||||
@ -1081,7 +1081,7 @@ func (bot *CQBot) CQDownloadFile(url string, headers map[string]string, threadCo
|
|||||||
return Failed(100, "DOWNLOAD_FILE_ERROR", err.Error())
|
return Failed(100, "DOWNLOAD_FILE_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
abs, _ := filepath.Abs(file)
|
abs, _ := filepath.Abs(file)
|
||||||
return OK(MSG{
|
return OK(global.MSG{
|
||||||
"file": abs,
|
"file": abs,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1089,16 +1089,16 @@ func (bot *CQBot) CQDownloadFile(url string, headers map[string]string, threadCo
|
|||||||
// CQGetForwardMessage 获取合并转发消息
|
// CQGetForwardMessage 获取合并转发消息
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1F
|
// https://git.io/Jtz1F
|
||||||
func (bot *CQBot) CQGetForwardMessage(resID string) MSG {
|
func (bot *CQBot) CQGetForwardMessage(resID string) global.MSG {
|
||||||
m := bot.Client.GetForwardMessage(resID)
|
m := bot.Client.GetForwardMessage(resID)
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
|
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
|
||||||
}
|
}
|
||||||
r := make([]MSG, 0, len(m.Nodes))
|
r := make([]global.MSG, 0, len(m.Nodes))
|
||||||
for _, n := range m.Nodes {
|
for _, n := range m.Nodes {
|
||||||
bot.checkMedia(n.Message)
|
bot.checkMedia(n.Message)
|
||||||
r = append(r, MSG{
|
r = append(r, global.MSG{
|
||||||
"sender": MSG{
|
"sender": global.MSG{
|
||||||
"user_id": n.SenderId,
|
"user_id": n.SenderId,
|
||||||
"nickname": n.SenderName,
|
"nickname": n.SenderName,
|
||||||
},
|
},
|
||||||
@ -1106,7 +1106,7 @@ func (bot *CQBot) CQGetForwardMessage(resID string) MSG {
|
|||||||
"content": ToFormattedMessage(n.Message, 0, false),
|
"content": ToFormattedMessage(n.Message, 0, false),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return OK(MSG{
|
return OK(global.MSG{
|
||||||
"messages": r,
|
"messages": r,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1114,7 +1114,7 @@ func (bot *CQBot) CQGetForwardMessage(resID string) MSG {
|
|||||||
// CQGetMessage 获取消息
|
// CQGetMessage 获取消息
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1b
|
// https://git.io/Jtz1b
|
||||||
func (bot *CQBot) CQGetMessage(messageID int32) MSG {
|
func (bot *CQBot) CQGetMessage(messageID int32) global.MSG {
|
||||||
msg := bot.GetMessage(messageID)
|
msg := bot.GetMessage(messageID)
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
|
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
|
||||||
@ -1122,7 +1122,7 @@ func (bot *CQBot) CQGetMessage(messageID int32) MSG {
|
|||||||
sender := msg["sender"].(message.Sender)
|
sender := msg["sender"].(message.Sender)
|
||||||
gid, isGroup := msg["group"]
|
gid, isGroup := msg["group"]
|
||||||
raw := msg["message"].(string)
|
raw := msg["message"].(string)
|
||||||
return OK(MSG{
|
return OK(global.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"],
|
||||||
@ -1134,7 +1134,7 @@ func (bot *CQBot) CQGetMessage(messageID int32) MSG {
|
|||||||
}
|
}
|
||||||
return "private"
|
return "private"
|
||||||
}(),
|
}(),
|
||||||
"sender": MSG{
|
"sender": global.MSG{
|
||||||
"user_id": sender.Uin,
|
"user_id": sender.Uin,
|
||||||
"nickname": sender.Nickname,
|
"nickname": sender.Nickname,
|
||||||
},
|
},
|
||||||
@ -1152,7 +1152,7 @@ func (bot *CQBot) CQGetMessage(messageID int32) MSG {
|
|||||||
// CQGetGroupSystemMessages 扩展API-获取群文件系统消息
|
// 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
|
// 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() global.MSG {
|
||||||
msg, err := bot.Client.GetGroupSystemMessages()
|
msg, err := bot.Client.GetGroupSystemMessages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("获取群系统消息失败: %v", err)
|
log.Warnf("获取群系统消息失败: %v", err)
|
||||||
@ -1164,7 +1164,7 @@ func (bot *CQBot) CQGetGroupSystemMessages() MSG {
|
|||||||
// CQGetGroupMessageHistory 获取群消息历史记录
|
// CQGetGroupMessageHistory 获取群消息历史记录
|
||||||
//
|
//
|
||||||
// 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
|
// 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 {
|
func (bot *CQBot) CQGetGroupMessageHistory(groupID int64, seq int64) global.MSG {
|
||||||
if g := bot.Client.FindGroup(groupID); g == nil {
|
if g := bot.Client.FindGroup(groupID); g == nil {
|
||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
@ -1180,7 +1180,7 @@ func (bot *CQBot) CQGetGroupMessageHistory(groupID int64, seq int64) MSG {
|
|||||||
log.Warnf("获取群历史消息失败: %v", err)
|
log.Warnf("获取群历史消息失败: %v", err)
|
||||||
return Failed(100, "MESSAGES_API_ERROR", err.Error())
|
return Failed(100, "MESSAGES_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
ms := make([]MSG, 0, len(msg))
|
ms := make([]global.MSG, 0, len(msg))
|
||||||
for _, m := range msg {
|
for _, m := range msg {
|
||||||
id := m.Id
|
id := m.Id
|
||||||
bot.checkMedia(m.Elements)
|
bot.checkMedia(m.Elements)
|
||||||
@ -1191,7 +1191,7 @@ func (bot *CQBot) CQGetGroupMessageHistory(groupID int64, seq int64) MSG {
|
|||||||
t["message_id"] = id
|
t["message_id"] = id
|
||||||
ms = append(ms, t)
|
ms = append(ms, t)
|
||||||
}
|
}
|
||||||
return OK(MSG{
|
return OK(global.MSG{
|
||||||
"messages": ms,
|
"messages": ms,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1199,22 +1199,22 @@ func (bot *CQBot) CQGetGroupMessageHistory(groupID int64, seq int64) MSG {
|
|||||||
// CQGetOnlineClients 扩展API-获取当前账号在线客户端列表
|
// 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
|
// 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) global.MSG {
|
||||||
if noCache {
|
if noCache {
|
||||||
if err := bot.Client.RefreshStatus(); err != nil {
|
if err := bot.Client.RefreshStatus(); err != nil {
|
||||||
log.Warnf("刷新客户端状态时出现问题 %v", err)
|
log.Warnf("刷新客户端状态时出现问题 %v", err)
|
||||||
return Failed(100, "REFRESH_STATUS_ERROR", err.Error())
|
return Failed(100, "REFRESH_STATUS_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
d := make([]MSG, 0, len(bot.Client.OnlineClients))
|
d := make([]global.MSG, 0, len(bot.Client.OnlineClients))
|
||||||
for _, oc := range bot.Client.OnlineClients {
|
for _, oc := range bot.Client.OnlineClients {
|
||||||
d = append(d, MSG{
|
d = append(d, global.MSG{
|
||||||
"app_id": oc.AppId,
|
"app_id": oc.AppId,
|
||||||
"device_name": oc.DeviceName,
|
"device_name": oc.DeviceName,
|
||||||
"device_kind": oc.DeviceKind,
|
"device_kind": oc.DeviceKind,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return OK(MSG{
|
return OK(global.MSG{
|
||||||
"clients": d,
|
"clients": d,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1222,21 +1222,21 @@ func (bot *CQBot) CQGetOnlineClients(noCache bool) MSG {
|
|||||||
// CQCanSendImage 检查是否可以发送图片(此处永远返回true)
|
// CQCanSendImage 检查是否可以发送图片(此处永远返回true)
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1N
|
// https://git.io/Jtz1N
|
||||||
func (bot *CQBot) CQCanSendImage() MSG {
|
func (bot *CQBot) CQCanSendImage() global.MSG {
|
||||||
return OK(MSG{"yes": true})
|
return OK(global.MSG{"yes": true})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CQCanSendRecord 检查是否可以发送语音(此处永远返回true)
|
// CQCanSendRecord 检查是否可以发送语音(此处永远返回true)
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1x
|
// https://git.io/Jtz1x
|
||||||
func (bot *CQBot) CQCanSendRecord() MSG {
|
func (bot *CQBot) CQCanSendRecord() global.MSG {
|
||||||
return OK(MSG{"yes": true})
|
return OK(global.MSG{"yes": true})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CQOcrImage 扩展API-图片OCR
|
// CQOcrImage 扩展API-图片OCR
|
||||||
//
|
//
|
||||||
// https://docs.go-cqhttp.org/api/#%E5%9B%BE%E7%89%87-ocr
|
// https://docs.go-cqhttp.org/api/#%E5%9B%BE%E7%89%87-ocr
|
||||||
func (bot *CQBot) CQOcrImage(imageID string) MSG {
|
func (bot *CQBot) CQOcrImage(imageID string) global.MSG {
|
||||||
img, err := bot.makeImageOrVideoElem(map[string]string{"file": imageID}, false, true)
|
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)
|
||||||
@ -1253,7 +1253,7 @@ func (bot *CQBot) CQOcrImage(imageID string) MSG {
|
|||||||
// CQSetGroupPortrait 扩展API-设置群头像
|
// CQSetGroupPortrait 扩展API-设置群头像
|
||||||
//
|
//
|
||||||
// https://docs.go-cqhttp.org/api/#%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%A4%B4%E5%83%8F
|
// 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 {
|
func (bot *CQBot) CQSetGroupPortrait(groupID int64, file, cache string) global.MSG {
|
||||||
if g := bot.Client.FindGroup(groupID); g != nil {
|
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 {
|
||||||
@ -1269,7 +1269,7 @@ func (bot *CQBot) CQSetGroupPortrait(groupID int64, file, cache string) MSG {
|
|||||||
// CQSetGroupAnonymousBan 群组匿名用户禁言
|
// CQSetGroupAnonymousBan 群组匿名用户禁言
|
||||||
//
|
//
|
||||||
// https://git.io/Jtz1p
|
// https://git.io/Jtz1p
|
||||||
func (bot *CQBot) CQSetGroupAnonymousBan(groupID int64, flag string, duration int32) MSG {
|
func (bot *CQBot) CQSetGroupAnonymousBan(groupID int64, flag string, duration int32) global.MSG {
|
||||||
if flag == "" {
|
if flag == "" {
|
||||||
return Failed(100, "INVALID_FLAG", "无效的flag")
|
return Failed(100, "INVALID_FLAG", "无效的flag")
|
||||||
}
|
}
|
||||||
@ -1292,8 +1292,8 @@ func (bot *CQBot) CQSetGroupAnonymousBan(groupID int64, flag string, duration in
|
|||||||
// CQGetStatus 获取运行状态
|
// CQGetStatus 获取运行状态
|
||||||
//
|
//
|
||||||
// https://git.io/JtzMe
|
// https://git.io/JtzMe
|
||||||
func (bot *CQBot) CQGetStatus() MSG {
|
func (bot *CQBot) CQGetStatus() global.MSG {
|
||||||
return OK(MSG{
|
return OK(global.MSG{
|
||||||
"app_initialized": true,
|
"app_initialized": true,
|
||||||
"app_enabled": true,
|
"app_enabled": true,
|
||||||
"plugins_good": nil,
|
"plugins_good": nil,
|
||||||
@ -1307,7 +1307,7 @@ func (bot *CQBot) CQGetStatus() MSG {
|
|||||||
// CQSetEssenceMessage 扩展API-设置精华消息
|
// CQSetEssenceMessage 扩展API-设置精华消息
|
||||||
//
|
//
|
||||||
// https://docs.go-cqhttp.org/api/#%E8%AE%BE%E7%BD%AE%E7%B2%BE%E5%8D%8E%E6%B6%88%E6%81%AF
|
// https://docs.go-cqhttp.org/api/#%E8%AE%BE%E7%BD%AE%E7%B2%BE%E5%8D%8E%E6%B6%88%E6%81%AF
|
||||||
func (bot *CQBot) CQSetEssenceMessage(messageID int32) MSG {
|
func (bot *CQBot) CQSetEssenceMessage(messageID int32) global.MSG {
|
||||||
msg := bot.GetMessage(messageID)
|
msg := bot.GetMessage(messageID)
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
return Failed(100, "MESSAGE_NOT_FOUND", "消息不存在")
|
return Failed(100, "MESSAGE_NOT_FOUND", "消息不存在")
|
||||||
@ -1327,7 +1327,7 @@ func (bot *CQBot) CQSetEssenceMessage(messageID int32) MSG {
|
|||||||
// CQDeleteEssenceMessage 扩展API-移出精华消息
|
// CQDeleteEssenceMessage 扩展API-移出精华消息
|
||||||
//
|
//
|
||||||
// https://docs.go-cqhttp.org/api/#%E7%A7%BB%E5%87%BA%E7%B2%BE%E5%8D%8E%E6%B6%88%E6%81%AF
|
// https://docs.go-cqhttp.org/api/#%E7%A7%BB%E5%87%BA%E7%B2%BE%E5%8D%8E%E6%B6%88%E6%81%AF
|
||||||
func (bot *CQBot) CQDeleteEssenceMessage(messageID int32) MSG {
|
func (bot *CQBot) CQDeleteEssenceMessage(messageID int32) global.MSG {
|
||||||
msg := bot.GetMessage(messageID)
|
msg := bot.GetMessage(messageID)
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
return Failed(100, "MESSAGE_NOT_FOUND", "消息不存在")
|
return Failed(100, "MESSAGE_NOT_FOUND", "消息不存在")
|
||||||
@ -1347,7 +1347,7 @@ func (bot *CQBot) CQDeleteEssenceMessage(messageID int32) MSG {
|
|||||||
// CQGetEssenceMessageList 扩展API-获取精华消息列表
|
// CQGetEssenceMessageList 扩展API-获取精华消息列表
|
||||||
//
|
//
|
||||||
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%B2%BE%E5%8D%8E%E6%B6%88%E6%81%AF%E5%88%97%E8%A1%A8
|
// https://docs.go-cqhttp.org/api/#%E8%8E%B7%E5%8F%96%E7%B2%BE%E5%8D%8E%E6%B6%88%E6%81%AF%E5%88%97%E8%A1%A8
|
||||||
func (bot *CQBot) CQGetEssenceMessageList(groupCode int64) MSG {
|
func (bot *CQBot) CQGetEssenceMessageList(groupCode int64) global.MSG {
|
||||||
g := bot.Client.FindGroup(groupCode)
|
g := bot.Client.FindGroup(groupCode)
|
||||||
if g == nil {
|
if g == nil {
|
||||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
@ -1356,9 +1356,9 @@ func (bot *CQBot) CQGetEssenceMessageList(groupCode int64) MSG {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return Failed(100, "GET_ESSENCE_LIST_FOUND", err.Error())
|
return Failed(100, "GET_ESSENCE_LIST_FOUND", err.Error())
|
||||||
}
|
}
|
||||||
list := make([]MSG, 0, len(msgList))
|
list := make([]global.MSG, 0, len(msgList))
|
||||||
for _, m := range msgList {
|
for _, m := range msgList {
|
||||||
msg := MSG{
|
msg := global.MSG{
|
||||||
"sender_nick": m.SenderNick,
|
"sender_nick": m.SenderNick,
|
||||||
"sender_time": m.SenderTime,
|
"sender_time": m.SenderTime,
|
||||||
"operator_time": m.AddDigestTime,
|
"operator_time": m.AddDigestTime,
|
||||||
@ -1375,8 +1375,8 @@ func (bot *CQBot) CQGetEssenceMessageList(groupCode int64) MSG {
|
|||||||
// CQCheckURLSafely 扩展API-检查链接安全性
|
// CQCheckURLSafely 扩展API-检查链接安全性
|
||||||
//
|
//
|
||||||
// https://docs.go-cqhttp.org/api/#%E6%A3%80%E6%9F%A5%E9%93%BE%E6%8E%A5%E5%AE%89%E5%85%A8%E6%80%A7
|
// https://docs.go-cqhttp.org/api/#%E6%A3%80%E6%9F%A5%E9%93%BE%E6%8E%A5%E5%AE%89%E5%85%A8%E6%80%A7
|
||||||
func (bot *CQBot) CQCheckURLSafely(url string) MSG {
|
func (bot *CQBot) CQCheckURLSafely(url string) global.MSG {
|
||||||
return OK(MSG{
|
return OK(global.MSG{
|
||||||
"level": bot.Client.CheckUrlSafely(url),
|
"level": bot.Client.CheckUrlSafely(url),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1384,9 +1384,9 @@ func (bot *CQBot) CQCheckURLSafely(url string) MSG {
|
|||||||
// CQGetVersionInfo 获取版本信息
|
// CQGetVersionInfo 获取版本信息
|
||||||
//
|
//
|
||||||
// https://git.io/JtwUs
|
// https://git.io/JtwUs
|
||||||
func (bot *CQBot) CQGetVersionInfo() MSG {
|
func (bot *CQBot) CQGetVersionInfo() global.MSG {
|
||||||
wd, _ := os.Getwd()
|
wd, _ := os.Getwd()
|
||||||
return OK(MSG{
|
return OK(global.MSG{
|
||||||
"app_name": "go-cqhttp",
|
"app_name": "go-cqhttp",
|
||||||
"app_version": Version,
|
"app_version": Version,
|
||||||
"app_full_name": fmt.Sprintf("go-cqhttp-%s_%s_%s-%s", Version, runtime.GOOS, runtime.GOARCH, runtime.Version()),
|
"app_full_name": fmt.Sprintf("go-cqhttp-%s_%s_%s-%s", Version, runtime.GOOS, runtime.GOARCH, runtime.Version()),
|
||||||
@ -1422,19 +1422,19 @@ func (bot *CQBot) CQGetVersionInfo() MSG {
|
|||||||
// CQGetModelShow 获取在线机型
|
// CQGetModelShow 获取在线机型
|
||||||
//
|
//
|
||||||
// https://club.vip.qq.com/onlinestatus/set
|
// https://club.vip.qq.com/onlinestatus/set
|
||||||
func (bot *CQBot) CQGetModelShow(modelName string) MSG {
|
func (bot *CQBot) CQGetModelShow(modelName string) global.MSG {
|
||||||
variants, err := bot.Client.GetModelShow(modelName)
|
variants, err := bot.Client.GetModelShow(modelName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Failed(100, "GET_MODEL_SHOW_API_ERROR", "无法获取在线机型")
|
return Failed(100, "GET_MODEL_SHOW_API_ERROR", "无法获取在线机型")
|
||||||
}
|
}
|
||||||
a := make([]MSG, 0, len(variants))
|
a := make([]global.MSG, 0, len(variants))
|
||||||
for _, v := range variants {
|
for _, v := range variants {
|
||||||
a = append(a, MSG{
|
a = append(a, global.MSG{
|
||||||
"model_show": v.ModelShow,
|
"model_show": v.ModelShow,
|
||||||
"need_pay": v.NeedPay,
|
"need_pay": v.NeedPay,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return OK(MSG{
|
return OK(global.MSG{
|
||||||
"variants": a,
|
"variants": a,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -1442,7 +1442,7 @@ func (bot *CQBot) CQGetModelShow(modelName string) MSG {
|
|||||||
// CQSetModelShow 设置在线机型
|
// CQSetModelShow 设置在线机型
|
||||||
//
|
//
|
||||||
// https://club.vip.qq.com/onlinestatus/set
|
// https://club.vip.qq.com/onlinestatus/set
|
||||||
func (bot *CQBot) CQSetModelShow(modelName string, modelShow string) MSG {
|
func (bot *CQBot) CQSetModelShow(modelName string, modelShow string) global.MSG {
|
||||||
err := bot.Client.SetModelShow(modelName, modelShow)
|
err := bot.Client.SetModelShow(modelName, modelShow)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Failed(100, "SET_MODEL_SHOW_API_ERROR", "无法设置在线机型")
|
return Failed(100, "SET_MODEL_SHOW_API_ERROR", "无法设置在线机型")
|
||||||
@ -1451,7 +1451,7 @@ func (bot *CQBot) CQSetModelShow(modelName string, modelShow string) MSG {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CQMarkMessageAsRead 标记消息已读
|
// CQMarkMessageAsRead 标记消息已读
|
||||||
func (bot *CQBot) CQMarkMessageAsRead(msgID int32) MSG {
|
func (bot *CQBot) CQMarkMessageAsRead(msgID int32) global.MSG {
|
||||||
m := bot.GetMessage(msgID)
|
m := bot.GetMessage(msgID)
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
|
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
|
||||||
@ -1468,12 +1468,12 @@ func (bot *CQBot) CQMarkMessageAsRead(msgID int32) MSG {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OK 生成成功返回值
|
// OK 生成成功返回值
|
||||||
func OK(data interface{}) MSG {
|
func OK(data interface{}) global.MSG {
|
||||||
return MSG{"data": data, "retcode": 0, "status": "ok"}
|
return global.MSG{"data": data, "retcode": 0, "status": "ok"}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Failed 生成失败返回值
|
// Failed 生成失败返回值
|
||||||
func Failed(code int, msg ...string) MSG {
|
func Failed(code int, msg ...string) global.MSG {
|
||||||
m := ""
|
m := ""
|
||||||
w := ""
|
w := ""
|
||||||
if len(msg) > 0 {
|
if len(msg) > 0 {
|
||||||
@ -1482,11 +1482,11 @@ func Failed(code int, msg ...string) MSG {
|
|||||||
if len(msg) > 1 {
|
if len(msg) > 1 {
|
||||||
w = msg[1]
|
w = msg[1]
|
||||||
}
|
}
|
||||||
return MSG{"data": nil, "retcode": code, "msg": m, "wording": w, "status": "failed"}
|
return global.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) global.MSG {
|
||||||
return MSG{
|
return global.MSG{
|
||||||
"group_id": groupID,
|
"group_id": groupID,
|
||||||
"user_id": m.Uin,
|
"user_id": m.Uin,
|
||||||
"nickname": m.Nickname,
|
"nickname": m.Nickname,
|
||||||
|
31
coolq/bot.go
31
coolq/bot.go
@ -41,12 +41,9 @@ type CQBot struct {
|
|||||||
tempSessionCache sync.Map
|
tempSessionCache sync.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
// MSG 消息Map
|
|
||||||
type MSG map[string]interface{}
|
|
||||||
|
|
||||||
// Event 事件
|
// Event 事件
|
||||||
type Event struct {
|
type Event struct {
|
||||||
RawMsg MSG
|
RawMsg global.MSG
|
||||||
|
|
||||||
once sync.Once
|
once sync.Once
|
||||||
buffer *bytes.Buffer
|
buffer *bytes.Buffer
|
||||||
@ -165,7 +162,7 @@ func NewQQBot(cli *client.QQClient, conf *config.Config) *CQBot {
|
|||||||
t := time.NewTicker(time.Second * time.Duration(i))
|
t := time.NewTicker(time.Second * time.Duration(i))
|
||||||
for {
|
for {
|
||||||
<-t.C
|
<-t.C
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"time": time.Now().Unix(),
|
"time": time.Now().Unix(),
|
||||||
"self_id": bot.Client.Uin,
|
"self_id": bot.Client.Uin,
|
||||||
"post_type": "meta_event",
|
"post_type": "meta_event",
|
||||||
@ -186,9 +183,9 @@ func (bot *CQBot) OnEventPush(f func(e *Event)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetMessage 获取给定消息id对应的消息
|
// GetMessage 获取给定消息id对应的消息
|
||||||
func (bot *CQBot) GetMessage(mid int32) MSG {
|
func (bot *CQBot) GetMessage(mid int32) global.MSG {
|
||||||
if bot.db != nil {
|
if bot.db != nil {
|
||||||
m := MSG{}
|
m := global.MSG{}
|
||||||
data, err := bot.db.Get(binary.ToBytes(mid), nil)
|
data, err := bot.db.Get(binary.ToBytes(mid), nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = gob.NewDecoder(bytes.NewReader(data)).Decode(&m)
|
err = gob.NewDecoder(bytes.NewReader(data)).Decode(&m)
|
||||||
@ -400,7 +397,7 @@ func (bot *CQBot) SendPrivateMessage(target int64, groupID int64, m *message.Sen
|
|||||||
|
|
||||||
// InsertGroupMessage 群聊消息入数据库
|
// InsertGroupMessage 群聊消息入数据库
|
||||||
func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
|
func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
|
||||||
val := MSG{
|
val := global.MSG{
|
||||||
"message-id": m.Id,
|
"message-id": m.Id,
|
||||||
"internal-id": m.InternalId,
|
"internal-id": m.InternalId,
|
||||||
"group": m.GroupCode,
|
"group": m.GroupCode,
|
||||||
@ -427,7 +424,7 @@ func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
|
|||||||
|
|
||||||
// InsertPrivateMessage 私聊消息入数据库
|
// InsertPrivateMessage 私聊消息入数据库
|
||||||
func (bot *CQBot) InsertPrivateMessage(m *message.PrivateMessage) int32 {
|
func (bot *CQBot) InsertPrivateMessage(m *message.PrivateMessage) int32 {
|
||||||
val := MSG{
|
val := global.MSG{
|
||||||
"message-id": m.Id,
|
"message-id": m.Id,
|
||||||
"internal-id": m.InternalId,
|
"internal-id": m.InternalId,
|
||||||
"target": m.Target,
|
"target": m.Target,
|
||||||
@ -453,7 +450,7 @@ func (bot *CQBot) InsertPrivateMessage(m *message.PrivateMessage) int32 {
|
|||||||
|
|
||||||
// InsertTempMessage 临时消息入数据库
|
// InsertTempMessage 临时消息入数据库
|
||||||
func (bot *CQBot) InsertTempMessage(target int64, m *message.TempMessage) int32 {
|
func (bot *CQBot) InsertTempMessage(target int64, m *message.TempMessage) int32 {
|
||||||
val := MSG{
|
val := global.MSG{
|
||||||
"message-id": m.Id,
|
"message-id": m.Id,
|
||||||
// FIXME(InsertTempMessage) InternalId missing
|
// FIXME(InsertTempMessage) InternalId missing
|
||||||
"from-group": m.GroupCode,
|
"from-group": m.GroupCode,
|
||||||
@ -491,7 +488,7 @@ func (bot *CQBot) Release() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) dispatchEventMessage(m MSG) {
|
func (bot *CQBot) dispatchEventMessage(m global.MSG) {
|
||||||
bot.lock.RLock()
|
bot.lock.RLock()
|
||||||
defer bot.lock.RUnlock()
|
defer bot.lock.RUnlock()
|
||||||
|
|
||||||
@ -519,9 +516,9 @@ func (bot *CQBot) dispatchEventMessage(m MSG) {
|
|||||||
global.PutBuffer(event.buffer)
|
global.PutBuffer(event.buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) MSG {
|
func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) global.MSG {
|
||||||
cqm := ToStringMessage(m.Elements, m.GroupCode, true)
|
cqm := ToStringMessage(m.Elements, m.GroupCode, true)
|
||||||
gm := MSG{
|
gm := global.MSG{
|
||||||
"anonymous": nil,
|
"anonymous": nil,
|
||||||
"font": 0,
|
"font": 0,
|
||||||
"group_id": m.GroupCode,
|
"group_id": m.GroupCode,
|
||||||
@ -536,7 +533,7 @@ func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) MSG {
|
|||||||
}(),
|
}(),
|
||||||
"raw_message": cqm,
|
"raw_message": cqm,
|
||||||
"self_id": bot.Client.Uin,
|
"self_id": bot.Client.Uin,
|
||||||
"sender": MSG{
|
"sender": global.MSG{
|
||||||
"age": 0,
|
"age": 0,
|
||||||
"area": "",
|
"area": "",
|
||||||
"level": "",
|
"level": "",
|
||||||
@ -548,12 +545,12 @@ func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) MSG {
|
|||||||
"user_id": m.Sender.Uin,
|
"user_id": m.Sender.Uin,
|
||||||
}
|
}
|
||||||
if m.Sender.IsAnonymous() {
|
if m.Sender.IsAnonymous() {
|
||||||
gm["anonymous"] = MSG{
|
gm["anonymous"] = global.MSG{
|
||||||
"flag": m.Sender.AnonymousInfo.AnonymousId + "|" + m.Sender.AnonymousInfo.AnonymousNick,
|
"flag": m.Sender.AnonymousInfo.AnonymousId + "|" + m.Sender.AnonymousInfo.AnonymousNick,
|
||||||
"id": m.Sender.Uin,
|
"id": m.Sender.Uin,
|
||||||
"name": m.Sender.AnonymousInfo.AnonymousNick,
|
"name": m.Sender.AnonymousInfo.AnonymousNick,
|
||||||
}
|
}
|
||||||
gm["sender"].(MSG)["nickname"] = "匿名消息"
|
gm["sender"].(global.MSG)["nickname"] = "匿名消息"
|
||||||
gm["sub_type"] = "anonymous"
|
gm["sub_type"] = "anonymous"
|
||||||
} else {
|
} else {
|
||||||
group := bot.Client.FindGroup(m.GroupCode)
|
group := bot.Client.FindGroup(m.GroupCode)
|
||||||
@ -571,7 +568,7 @@ func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) MSG {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ms := gm["sender"].(MSG)
|
ms := gm["sender"].(global.MSG)
|
||||||
switch mem.Permission {
|
switch mem.Permission {
|
||||||
case client.Owner:
|
case client.Owner:
|
||||||
ms["role"] = "owner"
|
ms["role"] = "owner"
|
||||||
|
@ -124,8 +124,8 @@ func (e *PokeElement) Type() message.ElementType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ToArrayMessage 将消息元素数组转为MSG数组以用于消息上报
|
// ToArrayMessage 将消息元素数组转为MSG数组以用于消息上报
|
||||||
func ToArrayMessage(e []message.IMessageElement, groupID int64) (r []MSG) {
|
func ToArrayMessage(e []message.IMessageElement, groupID int64) (r []global.MSG) {
|
||||||
r = make([]MSG, 0, len(e))
|
r = make([]global.MSG, 0, len(e))
|
||||||
m := &message.SendingMessage{Elements: e}
|
m := &message.SendingMessage{Elements: e}
|
||||||
reply := m.FirstOrNil(func(e message.IMessageElement) bool {
|
reply := m.FirstOrNil(func(e message.IMessageElement) bool {
|
||||||
_, ok := e.(*message.ReplyElement)
|
_, ok := e.(*message.ReplyElement)
|
||||||
@ -138,7 +138,7 @@ func ToArrayMessage(e []message.IMessageElement, groupID int64) (r []MSG) {
|
|||||||
rid = replyElem.Sender
|
rid = replyElem.Sender
|
||||||
}
|
}
|
||||||
if ExtraReplyData {
|
if ExtraReplyData {
|
||||||
r = append(r, MSG{
|
r = append(r, global.MSG{
|
||||||
"type": "reply",
|
"type": "reply",
|
||||||
"data": map[string]string{
|
"data": map[string]string{
|
||||||
"id": strconv.FormatInt(int64(toGlobalID(rid, replyElem.ReplySeq)), 10),
|
"id": strconv.FormatInt(int64(toGlobalID(rid, replyElem.ReplySeq)), 10),
|
||||||
@ -149,14 +149,14 @@ func ToArrayMessage(e []message.IMessageElement, groupID int64) (r []MSG) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
r = append(r, MSG{
|
r = append(r, global.MSG{
|
||||||
"type": "reply",
|
"type": "reply",
|
||||||
"data": map[string]string{"id": strconv.FormatInt(int64(toGlobalID(rid, replyElem.ReplySeq)), 10)},
|
"data": map[string]string{"id": strconv.FormatInt(int64(toGlobalID(rid, replyElem.ReplySeq)), 10)},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, elem := range e {
|
for i, elem := range e {
|
||||||
var m MSG
|
var m global.MSG
|
||||||
switch o := elem.(type) {
|
switch o := elem.(type) {
|
||||||
case *message.ReplyElement:
|
case *message.ReplyElement:
|
||||||
if RemoveReplyAt && i+1 < len(e) {
|
if RemoveReplyAt && i+1 < len(e) {
|
||||||
@ -166,49 +166,49 @@ func ToArrayMessage(e []message.IMessageElement, groupID int64) (r []MSG) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case *message.TextElement:
|
case *message.TextElement:
|
||||||
m = MSG{
|
m = global.MSG{
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"data": map[string]string{"text": o.Content},
|
"data": map[string]string{"text": o.Content},
|
||||||
}
|
}
|
||||||
case *message.LightAppElement:
|
case *message.LightAppElement:
|
||||||
m = MSG{
|
m = global.MSG{
|
||||||
"type": "json",
|
"type": "json",
|
||||||
"data": map[string]string{"data": o.Content},
|
"data": map[string]string{"data": o.Content},
|
||||||
}
|
}
|
||||||
case *message.AtElement:
|
case *message.AtElement:
|
||||||
if o.Target == 0 {
|
if o.Target == 0 {
|
||||||
m = MSG{
|
m = global.MSG{
|
||||||
"type": "at",
|
"type": "at",
|
||||||
"data": map[string]string{"qq": "all"},
|
"data": map[string]string{"qq": "all"},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
m = MSG{
|
m = global.MSG{
|
||||||
"type": "at",
|
"type": "at",
|
||||||
"data": map[string]string{"qq": strconv.FormatInt(o.Target, 10)},
|
"data": map[string]string{"qq": strconv.FormatInt(o.Target, 10)},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case *message.RedBagElement:
|
case *message.RedBagElement:
|
||||||
m = MSG{
|
m = global.MSG{
|
||||||
"type": "redbag",
|
"type": "redbag",
|
||||||
"data": map[string]string{"title": o.Title},
|
"data": map[string]string{"title": o.Title},
|
||||||
}
|
}
|
||||||
case *message.ForwardElement:
|
case *message.ForwardElement:
|
||||||
m = MSG{
|
m = global.MSG{
|
||||||
"type": "forward",
|
"type": "forward",
|
||||||
"data": map[string]string{"id": o.ResId},
|
"data": map[string]string{"id": o.ResId},
|
||||||
}
|
}
|
||||||
case *message.FaceElement:
|
case *message.FaceElement:
|
||||||
m = MSG{
|
m = global.MSG{
|
||||||
"type": "face",
|
"type": "face",
|
||||||
"data": map[string]string{"id": strconv.FormatInt(int64(o.Index), 10)},
|
"data": map[string]string{"id": strconv.FormatInt(int64(o.Index), 10)},
|
||||||
}
|
}
|
||||||
case *message.VoiceElement:
|
case *message.VoiceElement:
|
||||||
m = MSG{
|
m = global.MSG{
|
||||||
"type": "record",
|
"type": "record",
|
||||||
"data": map[string]string{"file": o.Name, "url": o.Url},
|
"data": map[string]string{"file": o.Name, "url": o.Url},
|
||||||
}
|
}
|
||||||
case *message.ShortVideoElement:
|
case *message.ShortVideoElement:
|
||||||
m = MSG{
|
m = global.MSG{
|
||||||
"type": "video",
|
"type": "video",
|
||||||
"data": map[string]string{"file": o.Name, "url": o.Url},
|
"data": map[string]string{"file": o.Name, "url": o.Url},
|
||||||
}
|
}
|
||||||
@ -221,7 +221,7 @@ func ToArrayMessage(e []message.IMessageElement, groupID int64) (r []MSG) {
|
|||||||
data["type"] = "show"
|
data["type"] = "show"
|
||||||
data["id"] = strconv.FormatInt(int64(o.EffectID), 10)
|
data["id"] = strconv.FormatInt(int64(o.EffectID), 10)
|
||||||
}
|
}
|
||||||
m = MSG{
|
m = global.MSG{
|
||||||
"type": "image",
|
"type": "image",
|
||||||
"data": data,
|
"data": data,
|
||||||
}
|
}
|
||||||
@ -230,18 +230,18 @@ func ToArrayMessage(e []message.IMessageElement, groupID int64) (r []MSG) {
|
|||||||
if o.Flash {
|
if o.Flash {
|
||||||
data["type"] = "flash"
|
data["type"] = "flash"
|
||||||
}
|
}
|
||||||
m = MSG{
|
m = global.MSG{
|
||||||
"type": "image",
|
"type": "image",
|
||||||
"data": data,
|
"data": data,
|
||||||
}
|
}
|
||||||
case *message.ServiceElement:
|
case *message.ServiceElement:
|
||||||
if isOk := strings.Contains(o.Content, "<?xml"); isOk {
|
if isOk := strings.Contains(o.Content, "<?xml"); isOk {
|
||||||
m = MSG{
|
m = global.MSG{
|
||||||
"type": "xml",
|
"type": "xml",
|
||||||
"data": map[string]string{"data": o.Content, "resid": strconv.FormatInt(int64(o.Id), 10)},
|
"data": map[string]string{"data": o.Content, "resid": strconv.FormatInt(int64(o.Id), 10)},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
m = MSG{
|
m = global.MSG{
|
||||||
"type": "json",
|
"type": "json",
|
||||||
"data": map[string]string{"data": o.Content, "resid": strconv.FormatInt(int64(o.Id), 10)},
|
"data": map[string]string{"data": o.Content, "resid": strconv.FormatInt(int64(o.Id), 10)},
|
||||||
}
|
}
|
||||||
@ -379,7 +379,7 @@ func (bot *CQBot) ConvertStringMessage(raw string, isGroup bool) (r []message.IM
|
|||||||
switch {
|
switch {
|
||||||
case customText != "":
|
case customText != "":
|
||||||
var elem *message.ReplyElement
|
var elem *message.ReplyElement
|
||||||
var org MSG
|
var org global.MSG
|
||||||
sender, senderErr := strconv.ParseInt(d["qq"], 10, 64)
|
sender, senderErr := strconv.ParseInt(d["qq"], 10, 64)
|
||||||
if senderErr != nil && err != nil {
|
if senderErr != nil && err != nil {
|
||||||
log.Warnf("警告: 自定义 Reply 元素中必须包含 Uin 或 id")
|
log.Warnf("警告: 自定义 Reply 元素中必须包含 Uin 或 id")
|
||||||
@ -551,7 +551,7 @@ func (bot *CQBot) ConvertObjectMessage(m gjson.Result, isGroup bool) (r []messag
|
|||||||
switch {
|
switch {
|
||||||
case customText != "":
|
case customText != "":
|
||||||
var elem *message.ReplyElement
|
var elem *message.ReplyElement
|
||||||
var org MSG
|
var org global.MSG
|
||||||
sender, senderErr := strconv.ParseInt(e.Get("data.[user_id,qq]").String(), 10, 64)
|
sender, senderErr := strconv.ParseInt(e.Get("data.[user_id,qq]").String(), 10, 64)
|
||||||
if senderErr != nil && err != nil {
|
if senderErr != nil && err != nil {
|
||||||
log.Warnf("警告: 自定义 Reply 元素中必须包含 user_id 或 id")
|
log.Warnf("警告: 自定义 Reply 元素中必须包含 user_id 或 id")
|
||||||
|
@ -41,7 +41,7 @@ func (bot *CQBot) privateMessageEvent(c *client.QQClient, m *message.PrivateMess
|
|||||||
id = bot.InsertPrivateMessage(m)
|
id = bot.InsertPrivateMessage(m)
|
||||||
}
|
}
|
||||||
log.Infof("收到好友 %v(%v) 的消息: %v (%v)", m.Sender.DisplayName(), m.Sender.Uin, cqm, id)
|
log.Infof("收到好友 %v(%v) 的消息: %v (%v)", m.Sender.DisplayName(), m.Sender.Uin, cqm, id)
|
||||||
fm := MSG{
|
fm := global.MSG{
|
||||||
"post_type": func() string {
|
"post_type": func() string {
|
||||||
if m.Sender.Uin == bot.Client.Uin {
|
if m.Sender.Uin == bot.Client.Uin {
|
||||||
return "message_sent"
|
return "message_sent"
|
||||||
@ -58,7 +58,7 @@ func (bot *CQBot) privateMessageEvent(c *client.QQClient, m *message.PrivateMess
|
|||||||
"font": 0,
|
"font": 0,
|
||||||
"self_id": c.Uin,
|
"self_id": c.Uin,
|
||||||
"time": time.Now().Unix(),
|
"time": time.Now().Unix(),
|
||||||
"sender": MSG{
|
"sender": global.MSG{
|
||||||
"user_id": m.Sender.Uin,
|
"user_id": m.Sender.Uin,
|
||||||
"nickname": m.Sender.Nickname,
|
"nickname": m.Sender.Nickname,
|
||||||
"sex": "unknown",
|
"sex": "unknown",
|
||||||
@ -73,12 +73,12 @@ func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage)
|
|||||||
for _, elem := range m.Elements {
|
for _, elem := range m.Elements {
|
||||||
if file, ok := elem.(*message.GroupFileElement); ok {
|
if file, ok := elem.(*message.GroupFileElement); ok {
|
||||||
log.Infof("群 %v(%v) 内 %v(%v) 上传了文件: %v", m.GroupName, m.GroupCode, m.Sender.DisplayName(), m.Sender.Uin, file.Name)
|
log.Infof("群 %v(%v) 内 %v(%v) 上传了文件: %v", m.GroupName, m.GroupCode, m.Sender.DisplayName(), m.Sender.Uin, file.Name)
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"post_type": "notice",
|
"post_type": "notice",
|
||||||
"notice_type": "group_upload",
|
"notice_type": "group_upload",
|
||||||
"group_id": m.GroupCode,
|
"group_id": m.GroupCode,
|
||||||
"user_id": m.Sender.Uin,
|
"user_id": m.Sender.Uin,
|
||||||
"file": MSG{
|
"file": global.MSG{
|
||||||
"id": file.Path,
|
"id": file.Path,
|
||||||
"name": file.Name,
|
"name": file.Name,
|
||||||
"size": file.Size,
|
"size": file.Size,
|
||||||
@ -115,7 +115,7 @@ func (bot *CQBot) tempMessageEvent(c *client.QQClient, e *client.TempMessageEven
|
|||||||
id = bot.InsertTempMessage(m.Sender.Uin, m)
|
id = bot.InsertTempMessage(m.Sender.Uin, m)
|
||||||
}
|
}
|
||||||
log.Infof("收到来自群 %v(%v) 内 %v(%v) 的临时会话消息: %v", m.GroupName, m.GroupCode, m.Sender.DisplayName(), m.Sender.Uin, cqm)
|
log.Infof("收到来自群 %v(%v) 内 %v(%v) 的临时会话消息: %v", m.GroupName, m.GroupCode, m.Sender.DisplayName(), m.Sender.Uin, cqm)
|
||||||
tm := MSG{
|
tm := global.MSG{
|
||||||
"post_type": "message",
|
"post_type": "message",
|
||||||
"message_type": "private",
|
"message_type": "private",
|
||||||
"sub_type": "group",
|
"sub_type": "group",
|
||||||
@ -127,7 +127,7 @@ func (bot *CQBot) tempMessageEvent(c *client.QQClient, e *client.TempMessageEven
|
|||||||
"font": 0,
|
"font": 0,
|
||||||
"self_id": c.Uin,
|
"self_id": c.Uin,
|
||||||
"time": time.Now().Unix(),
|
"time": time.Now().Unix(),
|
||||||
"sender": MSG{
|
"sender": global.MSG{
|
||||||
"user_id": m.Sender.Uin,
|
"user_id": m.Sender.Uin,
|
||||||
"group_id": m.GroupCode,
|
"group_id": m.GroupCode,
|
||||||
"nickname": m.Sender.Nickname,
|
"nickname": m.Sender.Nickname,
|
||||||
@ -158,7 +158,7 @@ func (bot *CQBot) groupMutedEvent(c *client.QQClient, e *client.GroupMuteEvent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"post_type": "notice",
|
"post_type": "notice",
|
||||||
"duration": e.Time,
|
"duration": e.Time,
|
||||||
"group_id": e.GroupCode,
|
"group_id": e.GroupCode,
|
||||||
@ -181,7 +181,7 @@ func (bot *CQBot) groupRecallEvent(c *client.QQClient, e *client.GroupMessageRec
|
|||||||
gid := toGlobalID(e.GroupCode, e.MessageId)
|
gid := toGlobalID(e.GroupCode, e.MessageId)
|
||||||
log.Infof("群 %v 内 %v 撤回了 %v 的消息: %v.",
|
log.Infof("群 %v 内 %v 撤回了 %v 的消息: %v.",
|
||||||
formatGroupName(g), formatMemberName(g.FindMember(e.OperatorUin)), formatMemberName(g.FindMember(e.AuthorUin)), gid)
|
formatGroupName(g), formatMemberName(g.FindMember(e.OperatorUin)), formatMemberName(g.FindMember(e.AuthorUin)), gid)
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"post_type": "notice",
|
"post_type": "notice",
|
||||||
"group_id": e.GroupCode,
|
"group_id": e.GroupCode,
|
||||||
"notice_type": "group_recall",
|
"notice_type": "group_recall",
|
||||||
@ -200,7 +200,7 @@ func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.INotifyEvent) {
|
|||||||
sender := group.FindMember(notify.Sender)
|
sender := group.FindMember(notify.Sender)
|
||||||
receiver := group.FindMember(notify.Receiver)
|
receiver := group.FindMember(notify.Receiver)
|
||||||
log.Infof("群 %v 内 %v 戳了戳 %v", formatGroupName(group), formatMemberName(sender), formatMemberName(receiver))
|
log.Infof("群 %v 内 %v 戳了戳 %v", formatGroupName(group), formatMemberName(sender), formatMemberName(receiver))
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"post_type": "notice",
|
"post_type": "notice",
|
||||||
"group_id": group.Code,
|
"group_id": group.Code,
|
||||||
"notice_type": "notify",
|
"notice_type": "notify",
|
||||||
@ -215,7 +215,7 @@ func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.INotifyEvent) {
|
|||||||
sender := group.FindMember(notify.Sender)
|
sender := group.FindMember(notify.Sender)
|
||||||
luckyKing := group.FindMember(notify.LuckyKing)
|
luckyKing := group.FindMember(notify.LuckyKing)
|
||||||
log.Infof("群 %v 内 %v 的红包被抢完, %v 是运气王", formatGroupName(group), formatMemberName(sender), formatMemberName(luckyKing))
|
log.Infof("群 %v 内 %v 的红包被抢完, %v 是运气王", formatGroupName(group), formatMemberName(sender), formatMemberName(luckyKing))
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"post_type": "notice",
|
"post_type": "notice",
|
||||||
"group_id": group.Code,
|
"group_id": group.Code,
|
||||||
"notice_type": "notify",
|
"notice_type": "notify",
|
||||||
@ -228,7 +228,7 @@ func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.INotifyEvent) {
|
|||||||
})
|
})
|
||||||
case *client.MemberHonorChangedNotifyEvent:
|
case *client.MemberHonorChangedNotifyEvent:
|
||||||
log.Info(notify.Content())
|
log.Info(notify.Content())
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"post_type": "notice",
|
"post_type": "notice",
|
||||||
"group_id": group.Code,
|
"group_id": group.Code,
|
||||||
"notice_type": "notify",
|
"notice_type": "notify",
|
||||||
@ -264,7 +264,7 @@ func (bot *CQBot) friendNotifyEvent(c *client.QQClient, e client.INotifyEvent) {
|
|||||||
} else {
|
} else {
|
||||||
log.Infof("好友 %v 戳了戳你.", friend.Nickname)
|
log.Infof("好友 %v 戳了戳你.", friend.Nickname)
|
||||||
}
|
}
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"post_type": "notice",
|
"post_type": "notice",
|
||||||
"notice_type": "notify",
|
"notice_type": "notify",
|
||||||
"sub_type": "poke",
|
"sub_type": "poke",
|
||||||
@ -281,7 +281,7 @@ func (bot *CQBot) memberTitleUpdatedEvent(c *client.QQClient, e *client.MemberSp
|
|||||||
group := c.FindGroup(e.GroupCode)
|
group := c.FindGroup(e.GroupCode)
|
||||||
mem := group.FindMember(e.Uin)
|
mem := group.FindMember(e.Uin)
|
||||||
log.Infof("群 %v(%v) 内成员 %v(%v) 获得了新的头衔: %v", group.Name, group.Code, mem.DisplayName(), mem.Uin, e.NewTitle)
|
log.Infof("群 %v(%v) 内成员 %v(%v) 获得了新的头衔: %v", group.Name, group.Code, mem.DisplayName(), mem.Uin, e.NewTitle)
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"post_type": "notice",
|
"post_type": "notice",
|
||||||
"notice_type": "notify",
|
"notice_type": "notify",
|
||||||
"sub_type": "title",
|
"sub_type": "title",
|
||||||
@ -301,7 +301,7 @@ func (bot *CQBot) friendRecallEvent(c *client.QQClient, e *client.FriendMessageR
|
|||||||
} else {
|
} else {
|
||||||
log.Infof("好友 %v 撤回了消息: %v", e.FriendUin, gid)
|
log.Infof("好友 %v 撤回了消息: %v", e.FriendUin, gid)
|
||||||
}
|
}
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"post_type": "notice",
|
"post_type": "notice",
|
||||||
"notice_type": "friend_recall",
|
"notice_type": "friend_recall",
|
||||||
"self_id": c.Uin,
|
"self_id": c.Uin,
|
||||||
@ -317,11 +317,11 @@ func (bot *CQBot) offlineFileEvent(c *client.QQClient, e *client.OfflineFileEven
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infof("好友 %v(%v) 发送了离线文件 %v", f.Nickname, f.Uin, e.FileName)
|
log.Infof("好友 %v(%v) 发送了离线文件 %v", f.Nickname, f.Uin, e.FileName)
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"post_type": "notice",
|
"post_type": "notice",
|
||||||
"notice_type": "offline_file",
|
"notice_type": "offline_file",
|
||||||
"user_id": e.Sender,
|
"user_id": e.Sender,
|
||||||
"file": MSG{
|
"file": global.MSG{
|
||||||
"name": e.FileName,
|
"name": e.FileName,
|
||||||
"size": e.FileSize,
|
"size": e.FileSize,
|
||||||
"url": e.DownloadUrl,
|
"url": e.DownloadUrl,
|
||||||
@ -352,7 +352,7 @@ func (bot *CQBot) memberPermissionChangedEvent(c *client.QQClient, e *client.Mem
|
|||||||
}
|
}
|
||||||
return "unset"
|
return "unset"
|
||||||
}()
|
}()
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"post_type": "notice",
|
"post_type": "notice",
|
||||||
"notice_type": "group_admin",
|
"notice_type": "group_admin",
|
||||||
"sub_type": st,
|
"sub_type": st,
|
||||||
@ -365,7 +365,7 @@ func (bot *CQBot) memberPermissionChangedEvent(c *client.QQClient, e *client.Mem
|
|||||||
|
|
||||||
func (bot *CQBot) memberCardUpdatedEvent(c *client.QQClient, e *client.MemberCardUpdatedEvent) {
|
func (bot *CQBot) memberCardUpdatedEvent(c *client.QQClient, e *client.MemberCardUpdatedEvent) {
|
||||||
log.Infof("群 %v 的 %v 更新了名片 %v -> %v", formatGroupName(e.Group), formatMemberName(e.Member), e.OldCard, e.Member.CardName)
|
log.Infof("群 %v 的 %v 更新了名片 %v -> %v", formatGroupName(e.Group), formatMemberName(e.Member), e.OldCard, e.Member.CardName)
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"post_type": "notice",
|
"post_type": "notice",
|
||||||
"notice_type": "group_card",
|
"notice_type": "group_card",
|
||||||
"group_id": e.Group.Code,
|
"group_id": e.Group.Code,
|
||||||
@ -395,7 +395,7 @@ func (bot *CQBot) friendRequestEvent(c *client.QQClient, e *client.NewFriendRequ
|
|||||||
log.Infof("收到来自 %v(%v) 的好友请求: %v", e.RequesterNick, e.RequesterUin, e.Message)
|
log.Infof("收到来自 %v(%v) 的好友请求: %v", e.RequesterNick, e.RequesterUin, e.Message)
|
||||||
flag := strconv.FormatInt(e.RequestId, 10)
|
flag := strconv.FormatInt(e.RequestId, 10)
|
||||||
bot.friendReqCache.Store(flag, e)
|
bot.friendReqCache.Store(flag, e)
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"post_type": "request",
|
"post_type": "request",
|
||||||
"request_type": "friend",
|
"request_type": "friend",
|
||||||
"user_id": e.RequesterUin,
|
"user_id": e.RequesterUin,
|
||||||
@ -409,7 +409,7 @@ func (bot *CQBot) friendRequestEvent(c *client.QQClient, e *client.NewFriendRequ
|
|||||||
func (bot *CQBot) friendAddedEvent(c *client.QQClient, e *client.NewFriendEvent) {
|
func (bot *CQBot) friendAddedEvent(c *client.QQClient, e *client.NewFriendEvent) {
|
||||||
log.Infof("添加了新好友: %v(%v)", e.Friend.Nickname, e.Friend.Uin)
|
log.Infof("添加了新好友: %v(%v)", e.Friend.Nickname, e.Friend.Uin)
|
||||||
bot.tempSessionCache.Delete(e.Friend.Uin)
|
bot.tempSessionCache.Delete(e.Friend.Uin)
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"post_type": "notice",
|
"post_type": "notice",
|
||||||
"notice_type": "friend_add",
|
"notice_type": "friend_add",
|
||||||
"self_id": c.Uin,
|
"self_id": c.Uin,
|
||||||
@ -421,7 +421,7 @@ func (bot *CQBot) friendAddedEvent(c *client.QQClient, e *client.NewFriendEvent)
|
|||||||
func (bot *CQBot) groupInvitedEvent(c *client.QQClient, e *client.GroupInvitedRequest) {
|
func (bot *CQBot) groupInvitedEvent(c *client.QQClient, e *client.GroupInvitedRequest) {
|
||||||
log.Infof("收到来自群 %v(%v) 内用户 %v(%v) 的加群邀请.", e.GroupName, e.GroupCode, e.InvitorNick, e.InvitorUin)
|
log.Infof("收到来自群 %v(%v) 内用户 %v(%v) 的加群邀请.", e.GroupName, e.GroupCode, e.InvitorNick, e.InvitorUin)
|
||||||
flag := strconv.FormatInt(e.RequestId, 10)
|
flag := strconv.FormatInt(e.RequestId, 10)
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"post_type": "request",
|
"post_type": "request",
|
||||||
"request_type": "group",
|
"request_type": "group",
|
||||||
"sub_type": "invite",
|
"sub_type": "invite",
|
||||||
@ -437,7 +437,7 @@ func (bot *CQBot) groupInvitedEvent(c *client.QQClient, e *client.GroupInvitedRe
|
|||||||
func (bot *CQBot) groupJoinReqEvent(c *client.QQClient, e *client.UserJoinGroupRequest) {
|
func (bot *CQBot) groupJoinReqEvent(c *client.QQClient, e *client.UserJoinGroupRequest) {
|
||||||
log.Infof("群 %v(%v) 收到来自用户 %v(%v) 的加群请求.", e.GroupName, e.GroupCode, e.RequesterNick, e.RequesterUin)
|
log.Infof("群 %v(%v) 收到来自用户 %v(%v) 的加群请求.", e.GroupName, e.GroupCode, e.RequesterNick, e.RequesterUin)
|
||||||
flag := strconv.FormatInt(e.RequestId, 10)
|
flag := strconv.FormatInt(e.RequestId, 10)
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"post_type": "request",
|
"post_type": "request",
|
||||||
"request_type": "group",
|
"request_type": "group",
|
||||||
"sub_type": "add",
|
"sub_type": "add",
|
||||||
@ -456,11 +456,11 @@ func (bot *CQBot) otherClientStatusChangedEvent(c *client.QQClient, e *client.Ot
|
|||||||
} else {
|
} else {
|
||||||
log.Infof("Bot 账号在客户端 %v (%v) 登出.", e.Client.DeviceName, e.Client.DeviceKind)
|
log.Infof("Bot 账号在客户端 %v (%v) 登出.", e.Client.DeviceName, e.Client.DeviceKind)
|
||||||
}
|
}
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"post_type": "notice",
|
"post_type": "notice",
|
||||||
"notice_type": "client_status",
|
"notice_type": "client_status",
|
||||||
"online": e.Online,
|
"online": e.Online,
|
||||||
"client": MSG{
|
"client": global.MSG{
|
||||||
"app_id": e.Client.AppId,
|
"app_id": e.Client.AppId,
|
||||||
"device_name": e.Client.DeviceName,
|
"device_name": e.Client.DeviceName,
|
||||||
"device_kind": e.Client.DeviceKind,
|
"device_kind": e.Client.DeviceKind,
|
||||||
@ -493,7 +493,7 @@ func (bot *CQBot) groupEssenceMsg(c *client.QQClient, e *client.GroupDigestEvent
|
|||||||
if e.OperatorUin == bot.Client.Uin {
|
if e.OperatorUin == bot.Client.Uin {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(global.MSG{
|
||||||
"post_type": "notice",
|
"post_type": "notice",
|
||||||
"group_id": e.GroupCode,
|
"group_id": e.GroupCode,
|
||||||
"notice_type": "essence",
|
"notice_type": "essence",
|
||||||
@ -511,8 +511,8 @@ func (bot *CQBot) groupEssenceMsg(c *client.QQClient, e *client.GroupDigestEvent
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) groupIncrease(groupCode, operatorUin, userUin int64) MSG {
|
func (bot *CQBot) groupIncrease(groupCode, operatorUin, userUin int64) global.MSG {
|
||||||
return MSG{
|
return global.MSG{
|
||||||
"post_type": "notice",
|
"post_type": "notice",
|
||||||
"notice_type": "group_increase",
|
"notice_type": "group_increase",
|
||||||
"group_id": groupCode,
|
"group_id": groupCode,
|
||||||
@ -524,8 +524,8 @@ func (bot *CQBot) groupIncrease(groupCode, operatorUin, userUin int64) MSG {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) groupDecrease(groupCode, userUin int64, operator *client.GroupMemberInfo) MSG {
|
func (bot *CQBot) groupDecrease(groupCode, userUin int64, operator *client.GroupMemberInfo) global.MSG {
|
||||||
return MSG{
|
return global.MSG{
|
||||||
"post_type": "notice",
|
"post_type": "notice",
|
||||||
"notice_type": "group_decrease",
|
"notice_type": "group_decrease",
|
||||||
"group_id": groupCode,
|
"group_id": groupCode,
|
||||||
|
@ -14,6 +14,9 @@ import (
|
|||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// MSG 消息Map
|
||||||
|
type MSG map[string]interface{}
|
||||||
|
|
||||||
// EnsureBool 判断给定的p是否可表示为合法Bool类型,否则返回defaultVal
|
// EnsureBool 判断给定的p是否可表示为合法Bool类型,否则返回defaultVal
|
||||||
//
|
//
|
||||||
// 支持的合法类型有
|
// 支持的合法类型有
|
||||||
|
1
go.mod
1
go.mod
@ -44,6 +44,7 @@ require (
|
|||||||
github.com/tidwall/match v1.0.3 // indirect
|
github.com/tidwall/match v1.0.3 // indirect
|
||||||
github.com/tidwall/pretty v1.1.0 // indirect
|
github.com/tidwall/pretty v1.1.0 // indirect
|
||||||
github.com/willf/bitset v1.2.0 // indirect
|
github.com/willf/bitset v1.2.0 // indirect
|
||||||
|
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect
|
||||||
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125 // indirect
|
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125 // indirect
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -136,6 +136,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
|
|||||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
|
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
|
||||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
|
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs=
|
||||||
|
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
|
||||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
|
136
server/api.go
136
server/api.go
@ -13,56 +13,56 @@ type resultGetter interface {
|
|||||||
Get(string) gjson.Result
|
Get(string) gjson.Result
|
||||||
}
|
}
|
||||||
|
|
||||||
type handler func(action string, p resultGetter) coolq.MSG
|
type handler func(action string, p resultGetter) global.MSG
|
||||||
|
|
||||||
type apiCaller struct {
|
type apiCaller struct {
|
||||||
bot *coolq.CQBot
|
bot *coolq.CQBot
|
||||||
handlers []handler
|
handlers []handler
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLoginInfo(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
|
func getLoginInfo(bot *coolq.CQBot, _ resultGetter) global.MSG {
|
||||||
return bot.CQGetLoginInfo()
|
return bot.CQGetLoginInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getQiDianAccountInfo(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
|
func getQiDianAccountInfo(bot *coolq.CQBot, _ resultGetter) global.MSG {
|
||||||
return bot.CQGetQiDianAccountInfo()
|
return bot.CQGetQiDianAccountInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFriendList(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
|
func getFriendList(bot *coolq.CQBot, _ resultGetter) global.MSG {
|
||||||
return bot.CQGetFriendList()
|
return bot.CQGetFriendList()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUnidirectionalFriendList(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
|
func getUnidirectionalFriendList(bot *coolq.CQBot, _ resultGetter) global.MSG {
|
||||||
return bot.CQGetUnidirectionalFriendList()
|
return bot.CQGetUnidirectionalFriendList()
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteFriend(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func deleteFriend(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQDeleteFriend(p.Get("[user_id,id].0").Int())
|
return bot.CQDeleteFriend(p.Get("[user_id,id].0").Int())
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteUnidirectionalFriend(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func deleteUnidirectionalFriend(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQDeleteUnidirectionalFriend(p.Get("user_id").Int())
|
return bot.CQDeleteUnidirectionalFriend(p.Get("user_id").Int())
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGroupList(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getGroupList(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGetGroupList(p.Get("no_cache").Bool())
|
return bot.CQGetGroupList(p.Get("no_cache").Bool())
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGroupInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getGroupInfo(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGetGroupInfo(p.Get("group_id").Int(), p.Get("no_cache").Bool())
|
return bot.CQGetGroupInfo(p.Get("group_id").Int(), p.Get("no_cache").Bool())
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGroupMemberList(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getGroupMemberList(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGetGroupMemberList(p.Get("group_id").Int(), p.Get("no_cache").Bool())
|
return bot.CQGetGroupMemberList(p.Get("group_id").Int(), p.Get("no_cache").Bool())
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGroupMemberInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getGroupMemberInfo(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGetGroupMemberInfo(
|
return bot.CQGetGroupMemberInfo(
|
||||||
p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("no_cache").Bool(),
|
p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("no_cache").Bool(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func sendMSG(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
autoEscape := global.EnsureBool(p.Get("auto_escape"), false)
|
autoEscape := global.EnsureBool(p.Get("auto_escape"), false)
|
||||||
if p.Get("message_type").Str == "private" {
|
if p.Get("message_type").Str == "private" {
|
||||||
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("group_id").Int(), p.Get("message"), autoEscape)
|
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("group_id").Int(), p.Get("message"), autoEscape)
|
||||||
@ -76,28 +76,28 @@ func sendMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
|||||||
if p.Get("group_id").Int() != 0 {
|
if p.Get("group_id").Int() != 0 {
|
||||||
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"), autoEscape)
|
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"), autoEscape)
|
||||||
}
|
}
|
||||||
return coolq.MSG{}
|
return global.MSG{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendGroupMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func sendGroupMSG(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"),
|
return bot.CQSendGroupMessage(p.Get("group_id").Int(), p.Get("message"),
|
||||||
global.EnsureBool(p.Get("auto_escape"), false))
|
global.EnsureBool(p.Get("auto_escape"), false))
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendGroupForwardMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func sendGroupForwardMSG(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQSendGroupForwardMessage(p.Get("group_id").Int(), p.Get("messages"))
|
return bot.CQSendGroupForwardMessage(p.Get("group_id").Int(), p.Get("messages"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendPrivateMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func sendPrivateMSG(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("group_id").Int(), p.Get("message"),
|
return bot.CQSendPrivateMessage(p.Get("user_id").Int(), p.Get("group_id").Int(), p.Get("message"),
|
||||||
global.EnsureBool(p.Get("auto_escape"), false))
|
global.EnsureBool(p.Get("auto_escape"), false))
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func deleteMSG(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQDeleteMessage(int32(p.Get("message_id").Int()))
|
return bot.CQDeleteMessage(int32(p.Get("message_id").Int()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func setFriendAddRequest(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func setFriendAddRequest(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
apr := true
|
apr := true
|
||||||
if p.Get("approve").Exists() {
|
if p.Get("approve").Exists() {
|
||||||
apr = p.Get("approve").Bool()
|
apr = p.Get("approve").Bool()
|
||||||
@ -105,7 +105,7 @@ func setFriendAddRequest(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
|||||||
return bot.CQProcessFriendRequest(p.Get("flag").Str, apr)
|
return bot.CQProcessFriendRequest(p.Get("flag").Str, apr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setGroupAddRequest(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func setGroupAddRequest(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
subType := p.Get("sub_type").Str
|
subType := p.Get("sub_type").Str
|
||||||
apr := true
|
apr := true
|
||||||
if subType == "" {
|
if subType == "" {
|
||||||
@ -117,19 +117,19 @@ func setGroupAddRequest(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
|||||||
return bot.CQProcessGroupRequest(p.Get("flag").Str, subType, p.Get("reason").Str, apr)
|
return bot.CQProcessGroupRequest(p.Get("flag").Str, subType, p.Get("reason").Str, apr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setGroupCard(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func setGroupCard(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQSetGroupCard(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("card").Str)
|
return bot.CQSetGroupCard(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("card").Str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setGroupSpecialTitle(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func setGroupSpecialTitle(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQSetGroupSpecialTitle(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("special_title").Str)
|
return bot.CQSetGroupSpecialTitle(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("special_title").Str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setGroupKick(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func setGroupKick(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQSetGroupKick(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("message").Str, p.Get("reject_add_request").Bool())
|
return bot.CQSetGroupKick(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("message").Str, p.Get("reject_add_request").Bool())
|
||||||
}
|
}
|
||||||
|
|
||||||
func setGroupBan(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func setGroupBan(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQSetGroupBan(p.Get("group_id").Int(), p.Get("user_id").Int(), func() uint32 {
|
return bot.CQSetGroupBan(p.Get("group_id").Int(), p.Get("user_id").Int(), func() uint32 {
|
||||||
if p.Get("duration").Exists() {
|
if p.Get("duration").Exists() {
|
||||||
return uint32(p.Get("duration").Int())
|
return uint32(p.Get("duration").Int())
|
||||||
@ -138,7 +138,7 @@ func setGroupBan(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
|||||||
}())
|
}())
|
||||||
}
|
}
|
||||||
|
|
||||||
func setGroupWholeBan(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func setGroupWholeBan(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQSetGroupWholeBan(p.Get("group_id").Int(), func() bool {
|
return bot.CQSetGroupWholeBan(p.Get("group_id").Int(), func() bool {
|
||||||
if p.Get("enable").Exists() {
|
if p.Get("enable").Exists() {
|
||||||
return p.Get("enable").Bool()
|
return p.Get("enable").Bool()
|
||||||
@ -147,11 +147,11 @@ func setGroupWholeBan(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
|||||||
}())
|
}())
|
||||||
}
|
}
|
||||||
|
|
||||||
func setGroupName(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func setGroupName(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQSetGroupName(p.Get("group_id").Int(), p.Get("group_name").Str)
|
return bot.CQSetGroupName(p.Get("group_id").Int(), p.Get("group_name").Str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setGroupAdmin(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func setGroupAdmin(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQSetGroupAdmin(p.Get("group_id").Int(), p.Get("user_id").Int(), func() bool {
|
return bot.CQSetGroupAdmin(p.Get("group_id").Int(), p.Get("user_id").Int(), func() bool {
|
||||||
if p.Get("enable").Exists() {
|
if p.Get("enable").Exists() {
|
||||||
return p.Get("enable").Bool()
|
return p.Get("enable").Bool()
|
||||||
@ -160,19 +160,19 @@ func setGroupAdmin(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
|||||||
}())
|
}())
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendGroupNotice(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func sendGroupNotice(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQSetGroupMemo(p.Get("group_id").Int(), p.Get("content").Str, p.Get("image").String())
|
return bot.CQSetGroupMemo(p.Get("group_id").Int(), p.Get("content").Str, p.Get("image").String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func setGroupLeave(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func setGroupLeave(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQSetGroupLeave(p.Get("group_id").Int())
|
return bot.CQSetGroupLeave(p.Get("group_id").Int())
|
||||||
}
|
}
|
||||||
|
|
||||||
func getImage(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getImage(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGetImage(p.Get("file").Str)
|
return bot.CQGetImage(p.Get("file").Str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getForwardMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getForwardMSG(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
id := p.Get("message_id").Str
|
id := p.Get("message_id").Str
|
||||||
if id == "" {
|
if id == "" {
|
||||||
id = p.Get("id").Str
|
id = p.Get("id").Str
|
||||||
@ -180,11 +180,11 @@ func getForwardMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
|||||||
return bot.CQGetForwardMessage(id)
|
return bot.CQGetForwardMessage(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getMSG(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGetMessage(int32(p.Get("message_id").Int()))
|
return bot.CQGetMessage(int32(p.Get("message_id").Int()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func downloadFile(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func downloadFile(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
headers := map[string]string{}
|
headers := map[string]string{}
|
||||||
headersToken := p.Get("headers")
|
headersToken := p.Get("headers")
|
||||||
if headersToken.IsArray() {
|
if headersToken.IsArray() {
|
||||||
@ -207,11 +207,11 @@ func downloadFile(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
|||||||
return bot.CQDownloadFile(p.Get("url").Str, headers, int(p.Get("thread_count").Int()))
|
return bot.CQDownloadFile(p.Get("url").Str, headers, int(p.Get("thread_count").Int()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGroupHonorInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getGroupHonorInfo(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGetGroupHonorInfo(p.Get("group_id").Int(), p.Get("type").Str)
|
return bot.CQGetGroupHonorInfo(p.Get("group_id").Int(), p.Get("type").Str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setRestart(_ *coolq.CQBot, _ resultGetter) coolq.MSG {
|
func setRestart(_ *coolq.CQBot, _ resultGetter) global.MSG {
|
||||||
/*
|
/*
|
||||||
var delay int64
|
var delay int64
|
||||||
delay = p.Get("delay").Int()
|
delay = p.Get("delay").Int()
|
||||||
@ -223,115 +223,115 @@ func setRestart(_ *coolq.CQBot, _ resultGetter) coolq.MSG {
|
|||||||
Restart <- struct{}{}
|
Restart <- struct{}{}
|
||||||
}(delay)
|
}(delay)
|
||||||
*/
|
*/
|
||||||
return coolq.MSG{"data": nil, "retcode": 99, "msg": "restart un-supported now", "wording": "restart函数暂不兼容", "status": "failed"}
|
return global.MSG{"data": nil, "retcode": 99, "msg": "restart un-supported now", "wording": "restart函数暂不兼容", "status": "failed"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func canSendImage(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
|
func canSendImage(bot *coolq.CQBot, _ resultGetter) global.MSG {
|
||||||
return bot.CQCanSendImage()
|
return bot.CQCanSendImage()
|
||||||
}
|
}
|
||||||
|
|
||||||
func canSendRecord(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
|
func canSendRecord(bot *coolq.CQBot, _ resultGetter) global.MSG {
|
||||||
return bot.CQCanSendRecord()
|
return bot.CQCanSendRecord()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStrangerInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getStrangerInfo(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGetStrangerInfo(p.Get("user_id").Int())
|
return bot.CQGetStrangerInfo(p.Get("user_id").Int())
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStatus(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
|
func getStatus(bot *coolq.CQBot, _ resultGetter) global.MSG {
|
||||||
return bot.CQGetStatus()
|
return bot.CQGetStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getVersionInfo(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
|
func getVersionInfo(bot *coolq.CQBot, _ resultGetter) global.MSG {
|
||||||
return bot.CQGetVersionInfo()
|
return bot.CQGetVersionInfo()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGroupSystemMSG(bot *coolq.CQBot, _ resultGetter) coolq.MSG {
|
func getGroupSystemMSG(bot *coolq.CQBot, _ resultGetter) global.MSG {
|
||||||
return bot.CQGetGroupSystemMessages()
|
return bot.CQGetGroupSystemMessages()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGroupFileSystemInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getGroupFileSystemInfo(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGetGroupFileSystemInfo(p.Get("group_id").Int())
|
return bot.CQGetGroupFileSystemInfo(p.Get("group_id").Int())
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGroupRootFiles(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getGroupRootFiles(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGetGroupRootFiles(p.Get("group_id").Int())
|
return bot.CQGetGroupRootFiles(p.Get("group_id").Int())
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGroupFilesByFolder(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getGroupFilesByFolder(bot *coolq.CQBot, p resultGetter) global.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)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGroupFileURL(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getGroupFileURL(bot *coolq.CQBot, p resultGetter) global.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()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func uploadGroupFile(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func uploadGroupFile(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQUploadGroupFile(p.Get("group_id").Int(), p.Get("file").Str, p.Get("name").Str, p.Get("folder").Str)
|
return bot.CQUploadGroupFile(p.Get("group_id").Int(), p.Get("file").Str, p.Get("name").Str, p.Get("folder").Str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func groupFileCreateFolder(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func groupFileCreateFolder(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGroupFileCreateFolder(p.Get("group_id").Int(), p.Get("folder_id").Str, p.Get("name").Str)
|
return bot.CQGroupFileCreateFolder(p.Get("group_id").Int(), p.Get("folder_id").Str, p.Get("name").Str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteGroupFolder(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func deleteGroupFolder(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGroupFileDeleteFolder(p.Get("group_id").Int(), p.Get("folder_id").Str)
|
return bot.CQGroupFileDeleteFolder(p.Get("group_id").Int(), p.Get("folder_id").Str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteGroupFile(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func deleteGroupFile(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGroupFileDeleteFile(p.Get("group_id").Int(), p.Get("file_id").Str, int32(p.Get("bus_id").Int()))
|
return bot.CQGroupFileDeleteFile(p.Get("group_id").Int(), p.Get("file_id").Str, int32(p.Get("bus_id").Int()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGroupMsgHistory(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getGroupMsgHistory(bot *coolq.CQBot, p resultGetter) global.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())
|
||||||
}
|
}
|
||||||
|
|
||||||
func getVipInfo(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getVipInfo(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGetVipInfo(p.Get("user_id").Int())
|
return bot.CQGetVipInfo(p.Get("user_id").Int())
|
||||||
}
|
}
|
||||||
|
|
||||||
func reloadEventFilter(_ *coolq.CQBot, p resultGetter) coolq.MSG {
|
func reloadEventFilter(_ *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
addFilter(p.Get("file").String())
|
addFilter(p.Get("file").String())
|
||||||
return coolq.OK(nil)
|
return coolq.OK(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGroupAtAllRemain(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getGroupAtAllRemain(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGetAtAllRemain(p.Get("group_id").Int())
|
return bot.CQGetAtAllRemain(p.Get("group_id").Int())
|
||||||
}
|
}
|
||||||
|
|
||||||
func ocrImage(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func ocrImage(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQOcrImage(p.Get("image").Str)
|
return bot.CQOcrImage(p.Get("image").Str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getOnlineClients(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getOnlineClients(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGetOnlineClients(p.Get("no_cache").Bool())
|
return bot.CQGetOnlineClients(p.Get("no_cache").Bool())
|
||||||
}
|
}
|
||||||
|
|
||||||
func getWordSlices(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getWordSlices(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGetWordSlices(p.Get("content").Str)
|
return bot.CQGetWordSlices(p.Get("content").Str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setGroupPortrait(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func setGroupPortrait(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQSetGroupPortrait(p.Get("group_id").Int(), p.Get("file").String(), p.Get("cache").String())
|
return bot.CQSetGroupPortrait(p.Get("group_id").Int(), p.Get("file").String(), p.Get("cache").String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func setEssenceMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func setEssenceMSG(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQSetEssenceMessage(int32(p.Get("message_id").Int()))
|
return bot.CQSetEssenceMessage(int32(p.Get("message_id").Int()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteEssenceMSG(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func deleteEssenceMSG(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQDeleteEssenceMessage(int32(p.Get("message_id").Int()))
|
return bot.CQDeleteEssenceMessage(int32(p.Get("message_id").Int()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func getEssenceMsgList(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getEssenceMsgList(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGetEssenceMessageList(p.Get("group_id").Int())
|
return bot.CQGetEssenceMessageList(p.Get("group_id").Int())
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkURLSafely(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func checkURLSafely(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQCheckURLSafely(p.Get("url").String())
|
return bot.CQCheckURLSafely(p.Get("url").String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func setGroupAnonymousBan(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func setGroupAnonymousBan(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
obj := p.Get("anonymous")
|
obj := p.Get("anonymous")
|
||||||
flag := p.Get("anonymous_flag")
|
flag := p.Get("anonymous_flag")
|
||||||
if !flag.Exists() {
|
if !flag.Exists() {
|
||||||
@ -346,24 +346,24 @@ func setGroupAnonymousBan(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
|||||||
return bot.CQSetGroupAnonymousBan(p.Get("group_id").Int(), flag.String(), int32(p.Get("duration").Int()))
|
return bot.CQSetGroupAnonymousBan(p.Get("group_id").Int(), flag.String(), int32(p.Get("duration").Int()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleQuickOperation(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func handleQuickOperation(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQHandleQuickOperation(p.Get("context"), p.Get("operation"))
|
return bot.CQHandleQuickOperation(p.Get("context"), p.Get("operation"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func getModelShow(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func getModelShow(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQGetModelShow(p.Get("model").String())
|
return bot.CQGetModelShow(p.Get("model").String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func setModelShow(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func setModelShow(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQSetModelShow(p.Get("model").String(), p.Get("model_show").String())
|
return bot.CQSetModelShow(p.Get("model").String(), p.Get("model_show").String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func markMSGAsRead(bot *coolq.CQBot, p resultGetter) coolq.MSG {
|
func markMSGAsRead(bot *coolq.CQBot, p resultGetter) global.MSG {
|
||||||
return bot.CQMarkMessageAsRead(int32(p.Get("message_id").Int()))
|
return bot.CQMarkMessageAsRead(int32(p.Get("message_id").Int()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// API 是go-cqhttp当前支持的所有api的映射表
|
// API 是go-cqhttp当前支持的所有api的映射表
|
||||||
var API = map[string]func(*coolq.CQBot, resultGetter) coolq.MSG{
|
var API = map[string]func(*coolq.CQBot, resultGetter) global.MSG{
|
||||||
"get_login_info": getLoginInfo,
|
"get_login_info": getLoginInfo,
|
||||||
"get_friend_list": getFriendList,
|
"get_friend_list": getFriendList,
|
||||||
"get_unidirectional_friend_list": getUnidirectionalFriendList,
|
"get_unidirectional_friend_list": getUnidirectionalFriendList,
|
||||||
@ -430,7 +430,7 @@ var API = map[string]func(*coolq.CQBot, resultGetter) coolq.MSG{
|
|||||||
"mark_msg_as_read": markMSGAsRead,
|
"mark_msg_as_read": markMSGAsRead,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *apiCaller) callAPI(action string, p resultGetter) coolq.MSG {
|
func (api *apiCaller) callAPI(action string, p resultGetter) global.MSG {
|
||||||
for _, fn := range api.handlers {
|
for _, fn := range api.handlers {
|
||||||
if ret := fn(action, p); ret != nil {
|
if ret := fn(action, p); ret != nil {
|
||||||
return ret
|
return ret
|
||||||
|
@ -23,7 +23,7 @@ var (
|
|||||||
|
|
||||||
func rateLimit(frequency float64, bucketSize int) handler {
|
func rateLimit(frequency float64, bucketSize int) handler {
|
||||||
limiter := rate.NewLimiter(rate.Limit(frequency), bucketSize)
|
limiter := rate.NewLimiter(rate.Limit(frequency), bucketSize)
|
||||||
return func(_ string, _ resultGetter) coolq.MSG {
|
return func(_ string, _ resultGetter) global.MSG {
|
||||||
_ = limiter.Wait(context.Background())
|
_ = limiter.Wait(context.Background())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ func longPolling(bot *coolq.CQBot, maxSize int) handler {
|
|||||||
}
|
}
|
||||||
cond.Signal()
|
cond.Signal()
|
||||||
})
|
})
|
||||||
return func(action string, p resultGetter) coolq.MSG {
|
return func(action string, p resultGetter) global.MSG {
|
||||||
if action != "get_updates" {
|
if action != "get_updates" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user