mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-08 04:55:55 +08:00
coolq: support upload_private_file
pc client can't receive file sent by this api.
This commit is contained in:
parent
672dafdb9d
commit
86f5b7f5f5
24
coolq/api.go
24
coolq/api.go
@ -603,6 +603,30 @@ func (bot *CQBot) CQUploadGroupFile(groupID int64, file, name, folder string) gl
|
||||
return OK(nil)
|
||||
}
|
||||
|
||||
// CQUploadPrivateFile 扩展API-上传私聊文件
|
||||
//
|
||||
// @route(upload_private_file)
|
||||
func (bot *CQBot) CQUploadPrivateFile(userID int64, file, name string) global.MSG {
|
||||
target := message.Source{
|
||||
SourceType: message.SourcePrivate,
|
||||
PrimaryID: userID,
|
||||
}
|
||||
fileBody, err := os.Open(file)
|
||||
if err != nil {
|
||||
log.Warnf("上传私聊文件 %v 失败: %+v", file, err)
|
||||
return Failed(100, "OPEN_FILE_ERROR", "打开文件失败")
|
||||
}
|
||||
localFile := &client.LocalFile{
|
||||
FileName: name,
|
||||
Body: fileBody,
|
||||
}
|
||||
if err := bot.Client.UploadFile(target, localFile); err != nil {
|
||||
log.Warnf("上传私聊 %v 文件 %v 失败: %+v", userID, file, err)
|
||||
return Failed(100, "FILE_SYSTEM_UPLOAD_API_ERROR", err.Error())
|
||||
}
|
||||
return OK(nil)
|
||||
}
|
||||
|
||||
// CQGroupFileCreateFolder 拓展API-创建群文件文件夹
|
||||
//
|
||||
// @route(create_group_file_folder)
|
||||
|
2
go.mod
2
go.mod
@ -4,7 +4,7 @@ go 1.18
|
||||
|
||||
require (
|
||||
github.com/Microsoft/go-winio v0.5.1
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20220614093722-87ff2f95910c
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20220620032456-d09215e943bb
|
||||
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c
|
||||
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc
|
||||
github.com/fumiama/go-base16384 v1.5.2
|
||||
|
4
go.sum
4
go.sum
@ -1,7 +1,7 @@
|
||||
github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY=
|
||||
github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20220614093722-87ff2f95910c h1:LGJoAua1bYxx28255h02owv66v9eWkSwcZx/jEO79Z0=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20220614093722-87ff2f95910c/go.mod h1:mZp8Lt7uqLCUwSLouB2yuiP467Cwl4mnG9IMAaXUKA0=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20220620032456-d09215e943bb h1:UAfqKJ+xXbJObUQQAl1TYYwRcLBPYfy67D25lAD4Nl8=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20220620032456-d09215e943bb/go.mod h1:mZp8Lt7uqLCUwSLouB2yuiP467Cwl4mnG9IMAaXUKA0=
|
||||
github.com/RomiChan/protobuf v0.1.1-0.20220602121309-9e3b8cbefd7a h1:WIfEWYj82oEuPtm5pqlyQmCJCoiw00C6ugZFqHA0cC8=
|
||||
github.com/RomiChan/protobuf v0.1.1-0.20220602121309-9e3b8cbefd7a/go.mod h1:2Ie+hdBFQpQFDHfeklgxoFmQRCE7O+KwFpISeXq7OwA=
|
||||
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c h1:cNPOdTNiVwxLpROLjXCgbIPvdkE+BwvxDvgmdYmWx6Q=
|
||||
|
@ -362,6 +362,11 @@ func (c *Caller) call(action string, version uint16, p Getter) global.MSG {
|
||||
p2 := p.Get("name").String()
|
||||
p3 := p.Get("folder").String()
|
||||
return c.bot.CQUploadGroupFile(p0, p1, p2, p3)
|
||||
case "upload_private_file":
|
||||
p0 := p.Get("user_id").Int()
|
||||
p1 := p.Get("file").String()
|
||||
p2 := p.Get("name").String()
|
||||
return c.bot.CQUploadPrivateFile(p0, p1, p2)
|
||||
}
|
||||
return coolq.Failed(404, "API_NOT_FOUND", "API不存在")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user