1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-06 20:13:50 +08:00

feature: group file api.

This commit is contained in:
Mrs4s 2020-11-07 14:50:10 +08:00
parent 6bb1f1603e
commit e2d2461595
4 changed files with 101 additions and 1 deletions

View File

@ -102,6 +102,59 @@ func (bot *CQBot) CQGetGroupMemberInfo(groupId, userId int64) MSG {
return OK(convertGroupMemberInfo(groupId, member))
}
func (bot *CQBot) CQGetGroupFileSystemInfo(groupId int64) MSG {
fs, err := bot.Client.GetGroupFileSystem(groupId)
if err != nil {
log.Errorf("获取群 %v 文件系统信息失败: %v", groupId, err)
return Failed(100)
}
return OK(fs)
}
func (bot *CQBot) CQGetGroupRootFiles(groupId int64) MSG {
fs, err := bot.Client.GetGroupFileSystem(groupId)
if err != nil {
log.Errorf("获取群 %v 文件系统信息失败: %v", groupId, err)
return Failed(100)
}
files, folders, err := fs.Root()
if err != nil {
log.Errorf("获取群 %v 根目录文件失败: %v", groupId, err)
return Failed(100)
}
return OK(MSG{
"files": files,
"folders": folders,
})
}
func (bot *CQBot) CQGetGroupFilesByFolderId(groupId int64, folderId string) MSG {
fs, err := bot.Client.GetGroupFileSystem(groupId)
if err != nil {
log.Errorf("获取群 %v 文件系统信息失败: %v", groupId, err)
return Failed(100)
}
files, folders, err := fs.GetFilesByFolder(folderId)
if err != nil {
log.Errorf("获取群 %v 根目录 %v 子文件失败: %v", groupId, folderId, err)
return Failed(100)
}
return OK(MSG{
"files": files,
"folders": folders,
})
}
func (bot *CQBot) CQGetGroupFileUrl(groupId int64, fileId string, busId int32) MSG {
url := bot.Client.GetGroupFileUrl(groupId, fileId, busId)
if url == "" {
return Failed(100)
}
return OK(MSG{
"url": url,
})
}
func (bot *CQBot) CQGetWordSlices(content string) MSG {
slices, err := bot.Client.GetWordSegmentation(content)
if err != nil {

View File

@ -289,7 +289,7 @@ func DecryptPwd(ePwd string, key []byte) string {
func checkUpdate() {
log.Infof("正在检查更新.")
if coolq.Version == "unknown" {
log.Warnf("检查更新失败: 使用的 Actions 测试版或自编译版本")
log.Warnf("检查更新失败: 使用的 Actions 测试版或自编译版本.")
return
}
var res string

View File

@ -191,6 +191,29 @@ func (s *httpServer) GetGroupMemberInfo(c *gin.Context) {
c.JSON(200, s.bot.CQGetGroupMemberInfo(gid, uid))
}
func (s *httpServer) GetGroupFileSystemInfo(c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
c.JSON(200, s.bot.CQGetGroupFileSystemInfo(gid))
}
func (s *httpServer) GetGroupRootFiles(c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
c.JSON(200, s.bot.CQGetGroupRootFiles(gid))
}
func (s *httpServer) GetGroupFilesByFolderId(c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
folderId := getParam(c, "folder_id")
c.JSON(200, s.bot.CQGetGroupFilesByFolderId(gid, folderId))
}
func (s *httpServer) GetGroupFileUrl(c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
fid := getParam(c, "file_id")
busid, _ := strconv.ParseInt(getParam(c, "busid"), 10, 32)
c.JSON(200, s.bot.CQGetGroupFileUrl(gid, fid, int32(busid)))
}
func (s *httpServer) SendMessage(c *gin.Context) {
if getParam(c, "message_type") == "private" {
s.SendPrivateMessage(c)
@ -459,6 +482,18 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
"get_group_member_info": func(s *httpServer, c *gin.Context) {
s.GetGroupMemberInfo(c)
},
"get_group_file_system_info": func(s *httpServer, c *gin.Context) {
s.GetGroupFileSystemInfo(c)
},
"get_group_root_files": func(s *httpServer, c *gin.Context) {
s.GetGroupRootFiles(c)
},
"get_group_files_by_folder": func(s *httpServer, c *gin.Context) {
s.GetGroupFilesByFolderId(c)
},
"get_group_file_url": func(s *httpServer, c *gin.Context) {
s.GetGroupFileUrl(c)
},
"send_msg": func(s *httpServer, c *gin.Context) {
s.SendMessage(c)
},

View File

@ -498,6 +498,18 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
"get_group_system_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetGroupSystemMessages()
},
"get_group_file_system_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetGroupFileSystemInfo(p.Get("group_id").Int())
},
"get_group_root_files": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetGroupRootFiles(p.Get("group_id").Int())
},
"get_group_files_by_folder": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetGroupFilesByFolderId(p.Get("group_id").Int(), p.Get("folder_id").Str)
},
"get_group_file_url": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetGroupFileUrl(p.Get("group_id").Int(), p.Get("file_id").Str, int32(p.Get("busid").Int()))
},
"_get_vip_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetVipInfo(p.Get("user_id").Int())
},