1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-06-19 05:55:04 +08:00

feature upload_group_file.

This commit is contained in:
Mrs4s 2021-02-05 22:24:49 +08:00
parent 4445af6ff2
commit 307a09dd11
3 changed files with 29 additions and 0 deletions

View File

@ -181,6 +181,26 @@ func (bot *CQBot) CQGetGroupFileUrl(groupId int64, fileId string, busId int32) M
})
}
func (bot *CQBot) CQUploadGroupFile(groupId int64, file, name, folder string) MSG {
if !global.PathExists(file) {
log.Errorf("上传群文件 %v 失败: 文件不存在", file)
return Failed(100, "FILE_NOT_FOUND", "文件不存在")
}
fs, err := bot.Client.GetGroupFileSystem(groupId)
if err != nil {
log.Errorf("获取群 %v 文件系统信息失败: %v", groupId, err)
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
}
if folder == "" {
folder = "/"
}
if err = fs.UploadFile(file, name, folder); err != nil {
log.Errorf("上传群 %v 文件 %v 失败: %v", groupId, file, err)
return Failed(100, "FILE_SYSTEM_UPLOAD_API_ERROR", err.Error())
}
return OK(nil)
}
func (bot *CQBot) CQGetWordSlices(content string) MSG {
slices, err := bot.Client.GetWordSegmentation(content)
if err != nil {

View File

@ -215,6 +215,11 @@ func GetGroupFileUrl(s *httpServer, c *gin.Context) {
c.JSON(200, s.bot.CQGetGroupFileUrl(gid, fid, int32(busid)))
}
func UploadGroupFile(s *httpServer, c *gin.Context) {
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
c.JSON(200, s.bot.CQUploadGroupFile(gid, getParam(c, "file"), getParam(c, "name"), getParam(c, "folder")))
}
func SendMessage(s *httpServer, c *gin.Context) {
if getParam(c, "message_type") == "private" {
SendPrivateMessage(s, c)
@ -560,6 +565,7 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
"get_group_root_files": GetGroupRootFiles,
"get_group_files_by_folder": GetGroupFilesByFolderId,
"get_group_file_url": GetGroupFileUrl,
"upload_group_file": UploadGroupFile,
"get_essence_msg_list": GetEssenceMsgList,
"send_msg": SendMessage,
"send_group_msg": SendGroupMessage,

View File

@ -562,6 +562,9 @@ var wsAPI = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
"get_group_file_url": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetGroupFileUrl(p.Get("group_id").Int(), p.Get("file_id").Str, int32(p.Get("busid").Int()))
},
"upload_group_file": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQUploadGroupFile(p.Get("group_id").Int(), p.Get("file").Str, p.Get("name").Str, p.Get("folder").Str)
},
"get_group_msg_history": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetGroupMessageHistory(p.Get("group_id").Int(), p.Get("message_seq").Int())
},