mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-04 19:17:37 +08:00
Merge remote-tracking branch 'upstream/master' into dev
This commit is contained in:
commit
13975c02df
30
coolq/api.go
30
coolq/api.go
@ -206,6 +206,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)
|
||||
}
|
||||
|
||||
// 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
|
||||
@ -1101,7 +1121,7 @@ func (bot *CQBot) CQGetStatus() MSG {
|
||||
|
||||
// CQSetEssenceMessage 设置精华消息
|
||||
//
|
||||
//
|
||||
//
|
||||
func (bot *CQBot) CQSetEssenceMessage(messageID int32) MSG {
|
||||
msg := bot.GetMessage(messageID)
|
||||
if msg == nil {
|
||||
@ -1167,9 +1187,15 @@ func (bot *CQBot) CQGetEssenceMessageList(groupCode int64) MSG {
|
||||
return OK(list)
|
||||
}
|
||||
|
||||
func (bot *CQBot) CQCheckUrlSafely(url string) MSG {
|
||||
return OK(MSG{
|
||||
"level": bot.Client.CheckUrlSafely(url),
|
||||
})
|
||||
}
|
||||
|
||||
// CQGetVersionInfo 获取版本信息
|
||||
//
|
||||
// https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_version_info-%E8%8E%B7%E5%8F%96%E7%89%88%E6%9C%AC%E4%BF%A1%E6%81%AF
|
||||
// https://git.io/JtwUs
|
||||
func (bot *CQBot) CQGetVersionInfo() MSG {
|
||||
wd, _ := os.Getwd()
|
||||
return OK(MSG{
|
||||
|
@ -846,6 +846,22 @@ Type: `tts`
|
||||
| `creator_name` | string | 创建者名字 |
|
||||
| `total_file_count` | int32 | 子文件数量 |
|
||||
|
||||
### 上传群文件
|
||||
|
||||
终结点: `/upload_group_file`
|
||||
|
||||
**参数**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ---------- | ------ | ------------------------- |
|
||||
| `group_id` | int64 | 群号 |
|
||||
| `file` | string | 本地文件路径 |
|
||||
| `name` | string | 储存名称 |
|
||||
| `folder` | string | 父目录ID |
|
||||
|
||||
> 在不提供 `folder` 参数的情况下默认上传到根目录
|
||||
> 只能上传本地文件, 需要上传 `http` 文件的话请先调用 `download_file` API下载
|
||||
|
||||
### 获取状态
|
||||
|
||||
终结点: `/get_status`
|
||||
@ -978,6 +994,22 @@ JSON数组:
|
||||
| `device_name` | string | 设备名称 |
|
||||
| `device_kind` | string | 设备类型 |
|
||||
|
||||
### 检查链接安全性
|
||||
|
||||
终结点:`/check_url_safely`
|
||||
|
||||
**参数**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ---------- | ------ | ------------------------- |
|
||||
| `url` | string | 需要检查的链接 |
|
||||
|
||||
**响应数据**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ---------- | ---------- | ------------ |
|
||||
| `level` | int | 安全等级, 1: 安全 2: 未知 3: 危险 |
|
||||
|
||||
### 获取用户VIP信息
|
||||
|
||||
终结点:`/_get_vip_info`
|
||||
|
4
go.mod
4
go.mod
@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20210204122237-7dcda89bd00e
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20210206134348-800bf525ed0e
|
||||
github.com/dustin/go-humanize v1.0.0
|
||||
github.com/gin-contrib/pprof v1.3.0
|
||||
github.com/gin-gonic/gin v1.6.3
|
||||
@ -23,7 +23,7 @@ require (
|
||||
github.com/lestrrat-go/strftime v1.0.4 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.1 // indirect
|
||||
github.com/nxadm/tail v1.4.6 // indirect
|
||||
github.com/nxadm/tail v1.4.8 // indirect
|
||||
github.com/onsi/ginkgo v1.15.0 // indirect
|
||||
github.com/onsi/gomega v1.10.5 // indirect
|
||||
github.com/pkg/errors v0.9.1
|
||||
|
11
go.sum
11
go.sum
@ -1,7 +1,7 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20210204122237-7dcda89bd00e h1:CxPsCMdqj6QlP2S7+EbXaY8I1ozAhGv48MmAUypxZ8A=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20210204122237-7dcda89bd00e/go.mod h1:yhqA0NyKxUf7I/0HR/1OMchveFggX8wde04gqdGrNfU=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20210206134348-800bf525ed0e h1:SnN+nyRdqN7sULnHUWCofP+Jxs3VJN/y8AlMpcz0nbk=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20210206134348-800bf525ed0e/go.mod h1:yhqA0NyKxUf7I/0HR/1OMchveFggX8wde04gqdGrNfU=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
@ -101,8 +101,8 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/nxadm/tail v1.4.6 h1:11TGpSHY7Esh/i/qnq02Jo5oVrI1Gue8Slbq0ujPZFQ=
|
||||
github.com/nxadm/tail v1.4.6/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||
@ -151,7 +151,6 @@ github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189/go.mod h1:r
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
@ -170,7 +169,6 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
|
||||
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/LtIxf46G4fxeEz5KJr9U=
|
||||
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew=
|
||||
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
@ -191,7 +189,6 @@ golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk=
|
||||
|
@ -217,6 +217,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)
|
||||
@ -503,6 +508,10 @@ func GetEssenceMsgList(s *httpServer, c *gin.Context) {
|
||||
c.JSON(200, s.bot.CQGetEssenceMessageList(gid))
|
||||
}
|
||||
|
||||
func CheckUrlSafely(s *httpServer, c *gin.Context) {
|
||||
c.JSON(200, s.bot.CQCheckUrlSafely(getParam(c, "url")))
|
||||
}
|
||||
|
||||
func getParamOrDefault(c *gin.Context, k, def string) string {
|
||||
r := getParam(c, k)
|
||||
if r != "" {
|
||||
@ -562,6 +571,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,
|
||||
@ -597,6 +607,7 @@ var httpAPI = map[string]func(s *httpServer, c *gin.Context){
|
||||
"set_group_portrait": SetGroupPortrait,
|
||||
"set_group_anonymous_ban": SetGroupAnonymousBan,
|
||||
"get_group_msg_history": GetGroupMessageHistory,
|
||||
"check_url_safely": CheckUrlSafely,
|
||||
"download_file": DownloadFile,
|
||||
".handle_quick_operation": HandleQuickOperation,
|
||||
".ocr_image": OcrImage,
|
||||
|
@ -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())
|
||||
},
|
||||
@ -598,6 +601,9 @@ var wsAPI = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
||||
"get_essence_msg_list": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
return bot.CQGetEssenceMessageList(p.Get("group_id").Int())
|
||||
},
|
||||
"check_url_safely": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
return bot.CQCheckUrlSafely(p.Get("url").String())
|
||||
},
|
||||
"set_group_anonymous_ban": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
obj := p.Get("anonymous")
|
||||
flag := p.Get("anonymous_flag")
|
||||
|
Loading…
x
Reference in New Issue
Block a user