1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-06-30 11:53:25 +00:00

Compare commits

..

13 Commits

Author SHA1 Message Date
d906bbf0ff doc update. 2020-11-07 15:04:27 +08:00
e2d2461595 feature: group file api. 2020-11-07 14:50:10 +08:00
6bb1f1603e feature: update check. 2020-11-07 13:59:43 +08:00
5e02883028 fix #381. 2020-11-07 13:19:37 +08:00
1f5c9acefb Merge branch 'master' into dev 2020-11-06 09:31:44 +08:00
36b235871f fix #397. 2020-11-06 09:18:20 +08:00
f675a70af3 update MiraiGo & log http post error details. 2020-11-05 20:33:06 +08:00
26afca1555 Merge pull request #387 from sam01101/patch-1
Updated README.md get_group_msg -> get_msg
2020-11-03 17:14:12 +08:00
76b793f119 Updated README.md get_group_msg -> get_msg 2020-11-02 16:27:00 +08:00
491bd2276e replace error msg. 2020-11-01 18:14:21 +08:00
3d81777ed1 clear code. 2020-10-30 09:23:58 +08:00
7b1f0d72eb Merge branch 'dev' of https://github.com/Mrs4s/go-cqhttp into dev 2020-10-28 11:53:04 +08:00
a0219d76ea fix empty friend message. 2020-10-28 11:52:47 +08:00
14 changed files with 303 additions and 14 deletions

View File

@ -68,7 +68,7 @@
| /set_group_leave | [退出群组](https://cqhttp.cc/docs/4.15/#/API?id=set_group_leave-退出群组) | | /set_group_leave | [退出群组](https://cqhttp.cc/docs/4.15/#/API?id=set_group_leave-退出群组) |
| /set_group_name | 设置群组名(拓展API) | | /set_group_name | 设置群组名(拓展API) |
| /get_image | 获取图片信息(拓展API) | | /get_image | 获取图片信息(拓展API) |
| /get_group_msg | 获取群组消息(拓展API) | | /get_msg | [获取消息]() | <!-- TODO 来人补个链接-->
| /can_send_image | [检查是否可以发送图片](https://cqhttp.cc/docs/4.15/#/API?id=can_send_image-检查是否可以发送图片) | | /can_send_image | [检查是否可以发送图片](https://cqhttp.cc/docs/4.15/#/API?id=can_send_image-检查是否可以发送图片) |
| /can_send_record | [检查是否可以发送语音](https://cqhttp.cc/docs/4.15/#/API?id=can_send_record-检查是否可以发送语音) | | /can_send_record | [检查是否可以发送语音](https://cqhttp.cc/docs/4.15/#/API?id=can_send_record-检查是否可以发送语音) |
| /get_status | [获取插件运行状态](https://cqhttp.cc/docs/4.15/#/API?id=get_status-获取插件运行状态) | | /get_status | [获取插件运行状态](https://cqhttp.cc/docs/4.15/#/API?id=get_status-获取插件运行状态) |

View File

@ -102,6 +102,59 @@ func (bot *CQBot) CQGetGroupMemberInfo(groupId, userId int64) MSG {
return OK(convertGroupMemberInfo(groupId, member)) 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 { func (bot *CQBot) CQGetWordSlices(content string) MSG {
slices, err := bot.Client.GetWordSegmentation(content) slices, err := bot.Client.GetWordSegmentation(content)
if err != nil { if err != nil {

View File

@ -214,6 +214,7 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int
return -1 return -1
} }
m.Elements = newElem m.Elements = newElem
bot.checkMedia(newElem)
ret := bot.Client.SendGroupMessage(groupId, m, ForceFragmented) ret := bot.Client.SendGroupMessage(groupId, m, ForceFragmented)
if ret == nil || ret.Id == -1 { if ret == nil || ret.Id == -1 {
log.Warnf("群消息发送失败: 账号可能被风控.") log.Warnf("群消息发送失败: 账号可能被风控.")
@ -294,7 +295,12 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in
} }
newElem = append(newElem, elem) newElem = append(newElem, elem)
} }
if len(newElem) == 0 {
log.Warnf("好友消息发送失败: 消息为空.")
return -1
}
m.Elements = newElem m.Elements = newElem
bot.checkMedia(newElem)
var id int32 = -1 var id int32 = -1
if bot.Client.FindFriend(target) != nil { // 双向好友 if bot.Client.FindFriend(target) != nil { // 双向好友
msg := bot.Client.SendPrivateMessage(target, m) msg := bot.Client.SendPrivateMessage(target, m)

View File

@ -243,6 +243,10 @@ func ToStringMessage(e []message.IMessageElement, code int64, raw ...bool) (r st
} else { } else {
r += fmt.Sprintf(`[CQ:image,file=%s,url=%s]`, o.Filename, CQCodeEscapeValue(o.Url)) r += fmt.Sprintf(`[CQ:image,file=%s,url=%s]`, o.Filename, CQCodeEscapeValue(o.Url))
} }
case *message.GroupImageElement:
r += fmt.Sprintf("[CQ:image,file=%s]", hex.EncodeToString(o.Md5)+".image")
case *message.FriendImageElement:
r += fmt.Sprintf("[CQ:image,file=%s]", hex.EncodeToString(o.Md5)+".image")
case *message.ServiceElement: case *message.ServiceElement:
if isOk := strings.Contains(o.Content, "<?xml"); isOk { if isOk := strings.Contains(o.Content, "<?xml"); isOk {
r += fmt.Sprintf(`[CQ:xml,data=%s,resid=%d]`, CQCodeEscapeValue(o.Content), o.Id) r += fmt.Sprintf(`[CQ:xml,data=%s,resid=%d]`, CQCodeEscapeValue(o.Content), o.Id)

View File

@ -478,6 +478,26 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement) {
}), 0644) }), 0644)
} }
i.Filename = filename i.Filename = filename
case *message.GroupImageElement:
filename := hex.EncodeToString(i.Md5) + ".image"
if !global.PathExists(path.Join(global.IMAGE_PATH, filename)) {
_ = ioutil.WriteFile(path.Join(global.IMAGE_PATH, filename), binary.NewWriterF(func(w *binary.Writer) {
w.Write(i.Md5)
w.WriteUInt32(uint32(i.Size))
w.WriteString(filename)
w.WriteString(i.Url)
}), 0644)
}
case *message.FriendImageElement:
filename := hex.EncodeToString(i.Md5) + ".image"
if !global.PathExists(path.Join(global.IMAGE_PATH, filename)) {
_ = ioutil.WriteFile(path.Join(global.IMAGE_PATH, filename), binary.NewWriterF(func(w *binary.Writer) {
w.Write(i.Md5)
w.WriteUInt32(uint32(0)) // 发送时会调用url, 大概没事
w.WriteString(filename)
w.WriteString(i.Url)
}), 0644)
}
case *message.VoiceElement: case *message.VoiceElement:
i.Name = strings.ReplaceAll(i.Name, "{", "") i.Name = strings.ReplaceAll(i.Name, "{", "")
i.Name = strings.ReplaceAll(i.Name, "}", "") i.Name = strings.ReplaceAll(i.Name, "}", "")

View File

@ -538,7 +538,109 @@ Type: `tts`
| `checked` | bool | 是否已被处理| | `checked` | bool | 是否已被处理|
| `actor` | int64 | 处理者, 未处理为0 | | `actor` | int64 | 处理者, 未处理为0 |
### 获取群文件系统信息
终结点: `/get_group_file_system_info`
**参数**
| 字段 | 类型 | 说明 |
| ------------ | ------ | ------ |
| `group_id` | int64 | 群号 |
**响应数据**
| 字段 | 类型 | 说明 |
| ---------- | ----------------- | -------- |
| `file_count` | int32 | 文件总数 |
| `limit_count` | int32 | 文件上限 |
| `used_space` | int64 | 已使用空间 |
| `total_space` | int64 | 空间上限 |
### 获取群根目录文件列表
> `File` 和 `Folder` 对象信息请参考最下方
终结点: `/get_group_root_files`
**参数**
| 字段 | 类型 | 说明 |
| ------------ | ------ | ------ |
| `group_id` | int64 | 群号 |
**响应数据**
| 字段 | 类型 | 说明 |
| ---------- | ----------------- | -------- |
| `files` | File[] | 文件列表 |
| `folders` | Folder[] | 文件夹列表 |
### 获取群子目录文件列表
> `File` 和 `Folder` 对象信息请参考最下方
终结点: `/get_group_files_by_folder`
**参数**
| 字段 | 类型 | 说明 |
| ------------ | ------ | ------ |
| `group_id` | int64 | 群号 |
| `folder_id` | string | 文件夹ID 参考 `Folder` 对象 |
**响应数据**
| 字段 | 类型 | 说明 |
| ---------- | ----------------- | -------- |
| `files` | File[] | 文件列表 |
| `folders` | Folder[] | 文件夹列表 |
### 获取群文件资源链接
> `File` 和 `Folder` 对象信息请参考最下方
终结点: `/get_group_file_url`
**参数**
| 字段 | 类型 | 说明 |
| ------------ | ------ | ------ |
| `group_id` | int64 | 群号 |
| `file_id` | string | 文件ID 参考 `File` 对象 |
| `busid` | int32 | 文件类型 参考 `File` 对象 |
**响应数据**
| 字段 | 类型 | 说明 |
| ---------- | ----------------- | -------- |
| `url` | string | 文件下载链接 |
**File**
| 字段 | 类型 | 说明 |
| ---------- | ----------------- | -------- |
| `file_id` | string | 文件ID |
| `file_name` | string | 文件名 |
| `busid` | int32 | 文件类型 |
| `file_size` | int64 | 文件大小 |
| `upload_time` | int64 | 上传时间 |
| `dead_time` | int64 | 过期时间,永久文件恒为0 |
| `modify_time` | int64 | 最后修改时间 |
| `download_times` | int32 | 下载次数 |
| `uploader` | int64 | 上传者ID |
| `uploader_name` | string | 上传者名字 |
**Folder**
| 字段 | 类型 | 说明 |
| ---------- | ----------------- | -------- |
| `folder_id` | string | 文件夹ID |
| `folder_name` | string | 文件名 |
| `create_time` | int64 | 创建时间 |
| `creator` | int64 | 创建者 |
| `creator_name` | string | 创建者名字 |
| `total_file_count` | int32 | 子文件数量 |
## 事件 ## 事件

View File

@ -131,7 +131,7 @@ func DefaultConfig() *JsonConfig {
}, },
WebUi: &GoCqWebUi{ WebUi: &GoCqWebUi{
Enabled: true, Enabled: true,
Host: "0.0.0.0", Host: "127.0.0.1",
WebInput: false, WebInput: false,
WebUiPort: 9999, WebUiPort: 9999,
}, },

View File

@ -2,6 +2,9 @@ package global
import ( import (
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"math"
"regexp"
"strconv"
"strings" "strings"
) )
@ -48,3 +51,22 @@ func EnsureBool(p interface{}, defaultVal bool) bool {
} }
return defaultVal return defaultVal
} }
// VersionNameCompare 检查版本名是否需要更新, 仅适用于 go-cqhttp 的版本命名规则
// 例: v0.9.29-fix2 == v0.9.29-fix2 -> false
// v0.9.29-fix1 < v0.9.29-fix2 -> true
// v0.9.29-fix2 > v0.9.29-fix1 -> false
// v0.9.29-fix2 < v0.9.30 -> true
func VersionNameCompare(current, remote string) bool {
sp := regexp.MustCompile(`[0-9]\d*`)
cur := sp.FindAllStringSubmatch(current, -1)
re := sp.FindAllStringSubmatch(remote, -1)
for i := 0; i < int(math.Min(float64(len(cur)), float64(len(re)))); i++ {
curSub, _ := strconv.Atoi(cur[i][0])
reSub, _ := strconv.Atoi(re[i][0])
if curSub < reSub {
return true
}
}
return len(cur) < len(re)
}

2
go.mod
View File

@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
go 1.14 go 1.14
require ( require (
github.com/Mrs4s/MiraiGo v0.0.0-20201027102621-5fa25a7f7434 github.com/Mrs4s/MiraiGo v0.0.0-20201105120358-ca72d542ca72
github.com/gin-gonic/gin v1.6.3 github.com/gin-gonic/gin v1.6.3
github.com/gorilla/websocket v1.4.2 github.com/gorilla/websocket v1.4.2
github.com/guonaihong/gout v0.1.3 github.com/guonaihong/gout v0.1.3

10
go.sum
View File

@ -1,9 +1,7 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 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/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Mrs4s/MiraiGo v0.0.0-20201025234014-8ece3a9dd803 h1:tRXLslHbNt4bd2wV+MIU2sqQME6UJfMYolYufhSRdg0= github.com/Mrs4s/MiraiGo v0.0.0-20201105120358-ca72d542ca72 h1:aiKVmrgZHXARnO6AYODwFf1JvTZr6OCl2pohepkkYKc=
github.com/Mrs4s/MiraiGo v0.0.0-20201025234014-8ece3a9dd803/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo= github.com/Mrs4s/MiraiGo v0.0.0-20201105120358-ca72d542ca72/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs=
github.com/Mrs4s/MiraiGo v0.0.0-20201027102621-5fa25a7f7434 h1:wb5EoWBj/ulZ30fBQA2KJ0IwVXcesu9aynCFdpRwS8M=
github.com/Mrs4s/MiraiGo v0.0.0-20201027102621-5fa25a7f7434/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= 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/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -36,8 +34,8 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=

29
main.go
View File

@ -7,6 +7,8 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/Mrs4s/go-cqhttp/server" "github.com/Mrs4s/go-cqhttp/server"
"github.com/guonaihong/gout"
"github.com/tidwall/gjson"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
@ -245,7 +247,7 @@ func main() {
conf.WebUi.WebUiPort = 9999 conf.WebUi.WebUiPort = 9999
} }
if conf.WebUi.Host == "" { if conf.WebUi.Host == "" {
conf.WebUi.Host = "0.0.0.0" conf.WebUi.Host = "127.0.0.1"
} }
confErr := conf.Save("config.json") confErr := conf.Save("config.json")
if confErr != nil { if confErr != nil {
@ -253,6 +255,7 @@ func main() {
} }
b := server.WebServer.Run(fmt.Sprintf("%s:%d", conf.WebUi.Host, conf.WebUi.WebUiPort), cli) b := server.WebServer.Run(fmt.Sprintf("%s:%d", conf.WebUi.Host, conf.WebUi.WebUiPort), cli)
c := server.Console c := server.Console
go checkUpdate()
signal.Notify(c, os.Interrupt, os.Kill) signal.Notify(c, os.Interrupt, os.Kill)
<-c <-c
b.Release() b.Release()
@ -282,3 +285,27 @@ func DecryptPwd(ePwd string, key []byte) string {
} }
return string(tea.Decrypt(encrypted)) return string(tea.Decrypt(encrypted))
} }
func checkUpdate() {
log.Infof("正在检查更新.")
if coolq.Version == "unknown" {
log.Warnf("检查更新失败: 使用的 Actions 测试版或自编译版本.")
return
}
var res string
if err := gout.GET("https://api.github.com/repos/Mrs4s/go-cqhttp/releases").BindBody(&res).Do(); err != nil {
log.Warnf("检查更新失败: %v", err)
return
}
detail := gjson.Parse(res)
if len(detail.Array()) < 1 {
return
}
info := detail.Array()[0]
if global.VersionNameCompare(coolq.Version, info.Get("tag_name").Str) {
log.Infof("当前有更新的 go-cqhttp 可供更新, 请前往 https://github.com/Mrs4s/go-cqhttp/releases 下载.")
log.Infof("当前版本: %v 最新版本: %v", coolq.Version, info.Get("tag_name").Str)
return
}
log.Infof("检查更新完成. 当前已运行最新版本.")
}

View File

@ -183,7 +183,11 @@ func (s *webServer) Dologin() {
os.Exit(0) os.Exit(0)
return return
case client.OtherLoginError, client.UnknownLoginError: case client.OtherLoginError, client.UnknownLoginError:
log.Warnf("登录失败: %v", rsp.ErrorMessage) msg := rsp.ErrorMessage
if strings.Contains(msg, "版本") {
msg = "密码错误或账号被冻结"
}
log.Warnf("登录失败: %v", msg)
log.Infof("按 Enter 继续....") log.Infof("按 Enter 继续....")
readLine() readLine()
os.Exit(0) os.Exit(0)
@ -225,8 +229,7 @@ func (s *webServer) Dologin() {
log.Warn("Bot已登录") log.Warn("Bot已登录")
return return
} }
if conf.ReLogin.MaxReloginTimes == 0 { if times > conf.ReLogin.MaxReloginTimes && conf.ReLogin.MaxReloginTimes != 0 {
} else if times > conf.ReLogin.MaxReloginTimes {
break break
} }
log.Warnf("Bot已离线 (%v),将在 %v 秒后尝试重连. 重连次数:%v", log.Warnf("Bot已离线 (%v),将在 %v 秒后尝试重连. 重连次数:%v",

View File

@ -5,6 +5,7 @@ import (
"crypto/hmac" "crypto/hmac"
"crypto/sha1" "crypto/sha1"
"encoding/hex" "encoding/hex"
"github.com/guonaihong/gout/dataflow"
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
@ -132,7 +133,13 @@ func (c *httpClient) onBotPushEvent(m coolq.MSG) {
return h return h
}()).SetTimeout(time.Second * time.Duration(c.timeout)).F().Retry().Attempt(5). }()).SetTimeout(time.Second * time.Duration(c.timeout)).F().Retry().Attempt(5).
WaitTime(time.Millisecond * 500).MaxWaitTime(time.Second * 5). WaitTime(time.Millisecond * 500).MaxWaitTime(time.Second * 5).
Do() Func(func(con *dataflow.Context) error {
if con.Error != nil {
log.Warnf("上报Event到 HTTP 服务器 %v 时出现错误: %v 将重试.", c.addr, con.Error)
return con.Error
}
return nil
}).Do()
if err != nil { if err != nil {
log.Warnf("上报Event数据 %v 到 %v 失败: %v", m.ToJson(), c.addr, err) log.Warnf("上报Event数据 %v 到 %v 失败: %v", m.ToJson(), c.addr, err)
return return
@ -184,6 +191,29 @@ func (s *httpServer) GetGroupMemberInfo(c *gin.Context) {
c.JSON(200, s.bot.CQGetGroupMemberInfo(gid, uid)) 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) { func (s *httpServer) SendMessage(c *gin.Context) {
if getParam(c, "message_type") == "private" { if getParam(c, "message_type") == "private" {
s.SendPrivateMessage(c) s.SendPrivateMessage(c)
@ -452,6 +482,18 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
"get_group_member_info": func(s *httpServer, c *gin.Context) { "get_group_member_info": func(s *httpServer, c *gin.Context) {
s.GetGroupMemberInfo(c) 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) { "send_msg": func(s *httpServer, c *gin.Context) {
s.SendMessage(c) 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 { "get_group_system_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetGroupSystemMessages() 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 { "_get_vip_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetVipInfo(p.Get("user_id").Int()) return bot.CQGetVipInfo(p.Get("user_id").Int())
}, },