Skip to content

Commit

Permalink
coolq: support upload_private_file
Browse files Browse the repository at this point in the history
pc client can't receive file sent by this api.
  • Loading branch information
wdvxdr1123 committed Jun 20, 2022
1 parent 7349fd4 commit 23d594b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
24 changes: 24 additions & 0 deletions coolq/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
5 changes: 5 additions & 0 deletions modules/api/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 23d594b

Please sign in to comment.