mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-06-30 11:53:25 +00:00
Compare commits
113 Commits
v0.9.31-fi
...
v0.9.36
Author | SHA1 | Date | |
---|---|---|---|
99a68b144b | |||
569b89a117 | |||
690384a9a3 | |||
20f2290ba4 | |||
fc2fc3494e | |||
5664567685 | |||
13a0a0cfd1 | |||
86e98c8287 | |||
7b831cfa1e | |||
05f2503631 | |||
e398dc2e02 | |||
4b32b30f89 | |||
17ea1e54bd | |||
68a41d4543 | |||
73774681af | |||
f258b010b9 | |||
a1e19bb66e | |||
e32137ceeb | |||
9dc519ff77 | |||
3d5cec13d0 | |||
6ea4bd829e | |||
6e3501a6f8 | |||
289b96f187 | |||
aa77810491 | |||
474de6ad3d | |||
cbbe196f26 | |||
00783380b7 | |||
4ef476cb67 | |||
d50442b85f | |||
370e08ad7e | |||
627924fbf9 | |||
c492465480 | |||
d84b7c423a | |||
1af61737dc | |||
f789609a23 | |||
9a4b284559 | |||
37abe25cd6 | |||
e8e78b596d | |||
054ad47da9 | |||
e694e8b482 | |||
d07e1ee77a | |||
818cecc279 | |||
950011b694 | |||
53b857b721 | |||
26372c0939 | |||
e6de0c33cd | |||
302ae89a75 | |||
d8b9eb611f | |||
35a1a0f8b5 | |||
7cd6475c6b | |||
b3c4cecdac | |||
469054e5a3 | |||
14278190e3 | |||
cc6c042516 | |||
abd32556cb | |||
de1cd8b314 | |||
4883c05d67 | |||
1f20f26c49 | |||
12ac895b21 | |||
70e8ea07bd | |||
947d165ac5 | |||
93d0d87fbb | |||
1fbaa6107d | |||
a4ec4077e2 | |||
8a75a6e95a | |||
d63d10b69e | |||
dfeadef1a2 | |||
b23f68e746 | |||
c5a5f71664 | |||
6973a10b4b | |||
3468c38fbc | |||
d76bcfb1f0 | |||
716c38bab4 | |||
03518b4823 | |||
09eeff3ce6 | |||
6599bf6aa6 | |||
ffb2faeae7 | |||
71e3e97aeb | |||
dcb708e3e3 | |||
b9fb833af4 | |||
b93df0250d | |||
33d64b6e27 | |||
7f831cf856 | |||
7a713c9327 | |||
28d536a3af | |||
375fdc8dca | |||
d1c6053df8 | |||
143d5ef8ab | |||
439c3422fb | |||
2c7b56a79c | |||
1549ef4a32 | |||
4ad684061b | |||
c7e6457e9e | |||
9d5842f09b | |||
b6f3c300ab | |||
2057e769da | |||
0ea85e2fab | |||
36b081eeec | |||
2a044a62d2 | |||
e0ffb98665 | |||
861bcf30b1 | |||
56d7815f6a | |||
59934982b9 | |||
09c4801b56 | |||
f1f58b4072 | |||
86c2f3cb11 | |||
03c3340954 | |||
64b1a223cc | |||
b2be595fb8 | |||
22225f2b74 | |||
eb3d7434cc | |||
8f7f207891 | |||
83e0aaa0f8 |
15
.github/ISSUE_TEMPLATE/bug--.md
vendored
15
.github/ISSUE_TEMPLATE/bug--.md
vendored
@ -7,11 +7,20 @@ assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!--
|
||||
在提出ISSUE前,希望您能花费一定的时间执行以下几个步骤以方便我们定位BUG.
|
||||
1: 确定没有相同问题的ISSUE已被提出.
|
||||
2: 准确填写环境信息.
|
||||
3: 最好能打开DEBUG模式并复现相关问题.
|
||||
4: 如果涉及内存泄漏/CPU占用异常请打开DEBUG模式并下载pprof性能分析.
|
||||
-->
|
||||
|
||||
**环境信息**
|
||||
请根据实际使用环境修改以下信息
|
||||
go-cqhttp版本: v0.9.10
|
||||
运行环境: windows_amd64
|
||||
连接方式: 反向WS
|
||||
go-cqhttp版本:
|
||||
运行环境:
|
||||
连接方式:
|
||||
使用协议:
|
||||
|
||||
**bug内容**
|
||||
请在这里详细描述bug的内容
|
||||
|
@ -2,14 +2,15 @@ FROM golang:1.15.5-alpine AS builder
|
||||
|
||||
RUN go env -w GO111MODULE=auto \
|
||||
&& go env -w CGO_ENABLED=0 \
|
||||
&& mkdir /build
|
||||
&& go env -w GOPROXY=https://goproxy.cn,direct
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
COPY ./ .
|
||||
|
||||
RUN cd /build \
|
||||
&& go build -ldflags "-s -w -extldflags '-static'" -o cqhttp
|
||||
RUN set -ex \
|
||||
&& cd /build \
|
||||
&& go build -ldflags "-s -w -extldflags '-static'" -o cqhttp
|
||||
|
||||
FROM alpine:latest
|
||||
|
||||
|
321
README.md
321
README.md
@ -1,113 +1,282 @@
|
||||
<p align="center">
|
||||
<a href="https://ishkong.github.io/go-cqhttp-docs/"><img src="https://i.loli.net/2020/12/20/qSLMDWxiocRQgu6.jpg" width="200" height="200" alt="go-cqhttp"></a>
|
||||
</p>
|
||||
|
||||
<div align="center">
|
||||
|
||||
# go-cqhttp
|
||||
使用 [mirai](https://github.com/mamoe/mirai) 以及 [MiraiGo](https://github.com/Mrs4s/MiraiGo) 开发的cqhttp golang原生实现, 并在[cqhttp原版](https://github.com/richardchien/coolq-http-api)的基础上做了部分修改和拓展.
|
||||
文档暂时可查看 `docs` 目录, 目前还在撰写中.
|
||||
|
||||
测试版可前往 Release 下载
|
||||
_✨ 基于 [Mirai](https://github.com/mamoe/mirai) 以及 [MiraiGo](https://github.com/Mrs4s/MiraiGo) 的 [cqhttp](https://github.com/howmanybots/onebot/blob/master/README.md) golang 原生实现 ✨_
|
||||
|
||||
# 兼容性
|
||||
</div>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://raw.githubusercontent.com/Mrs4s/go-cqhttp/master/LICENSE">
|
||||
<img src="https://img.shields.io/github/license/Mrs4s/go-cqhttp" alt="license">
|
||||
</a>
|
||||
<a href="https://github.com/Mrs4s/go-cqhttp/releases">
|
||||
<img src="https://img.shields.io/github/v/release/Mrs4s/go-cqhttp?color=blueviolet&include_prereleases" alt="release">
|
||||
</a>
|
||||
<a href="https://github.com/howmanybots/onebot/blob/master/README.md">
|
||||
<img src="https://img.shields.io/badge/OneBot-v11-blue?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABABAMAAABYR2ztAAAAIVBMVEUAAAAAAAADAwMHBwceHh4UFBQNDQ0ZGRkoKCgvLy8iIiLWSdWYAAAAAXRSTlMAQObYZgAAAQVJREFUSMftlM0RgjAQhV+0ATYK6i1Xb+iMd0qgBEqgBEuwBOxU2QDKsjvojQPvkJ/ZL5sXkgWrFirK4MibYUdE3OR2nEpuKz1/q8CdNxNQgthZCXYVLjyoDQftaKuniHHWRnPh2GCUetR2/9HsMAXyUT4/3UHwtQT2AggSCGKeSAsFnxBIOuAggdh3AKTL7pDuCyABcMb0aQP7aM4AnAbc/wHwA5D2wDHTTe56gIIOUA/4YYV2e1sg713PXdZJAuncdZMAGkAukU9OAn40O849+0ornPwT93rphWF0mgAbauUrEOthlX8Zu7P5A6kZyKCJy75hhw1Mgr9RAUvX7A3csGqZegEdniCx30c3agAAAABJRU5ErkJggg==" alt="cqhttp">
|
||||
</a>
|
||||
<a href="https://github.com/Mrs4s/go-cqhttp/actions">
|
||||
<img src="https://github.com/Mrs4s/go-cqhttp/workflows/CI/badge.svg" alt="action">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="http://ishkong.github.io/go-cqhttp-docs">文档</a>
|
||||
·
|
||||
<a href="https://github.com/Mrs4s/go-cqhttp/releases">下载</a>
|
||||
·
|
||||
<a href="https://ishkong.github.io/go-cqhttp-docs/guide/quick_start.html">开始使用</a>
|
||||
</p>
|
||||
|
||||
---
|
||||
|
||||
go-cqhttp 在[原版 cqhttp](https://github.com/richardchien/coolq-http-api)的基础上做了部分修改和拓展.
|
||||
|
||||
---
|
||||
|
||||
## 兼容性
|
||||
|
||||
### 接口
|
||||
|
||||
#### 接口
|
||||
- [x] HTTP API
|
||||
- [x] 反向HTTP POST
|
||||
- [x] 正向Websocket
|
||||
- [x] 反向Websocket
|
||||
- [x] 反向 HTTP POST
|
||||
- [x] 正向 Websocket
|
||||
- [x] 反向 Websocket
|
||||
|
||||
#### 拓展支持
|
||||
> 拓展API可前往 [文档](docs/cqhttp.md) 查看
|
||||
- [x] HTTP POST多点上报
|
||||
- [x] 反向WS多点连接
|
||||
### 拓展支持
|
||||
|
||||
> 拓展 API 可前往 [文档](docs/cqhttp.md) 查看
|
||||
|
||||
- [x] HTTP POST 多点上报
|
||||
- [x] 反向 WS 多点连接
|
||||
- [x] 修改群名
|
||||
- [x] 消息撤回事件
|
||||
- [x] 解析/发送 回复消息
|
||||
- [x] 解析/发送 合并转发
|
||||
- [ ] 使用代理请求网络图片
|
||||
- [x] 使用代理请求网络图片
|
||||
|
||||
### 实现
|
||||
|
||||
#### 实现
|
||||
<details>
|
||||
<summary>已实现CQ码</summary>
|
||||
|
||||
- [CQ:image]
|
||||
- [CQ:record]
|
||||
- [CQ:video]
|
||||
- [CQ:face]
|
||||
- [CQ:at]
|
||||
- [CQ:share]
|
||||
- [CQ:reply]
|
||||
- [CQ:forward]
|
||||
- [CQ:node]
|
||||
- [CQ:gift]
|
||||
- [CQ:redbag]
|
||||
- [CQ:tts]
|
||||
- [CQ:music]
|
||||
#### 符合 Onebot 标准的 CQ 码
|
||||
|
||||
| CQ 码 | 功能 |
|
||||
| ------------ | --------------------------- |
|
||||
| [CQ:face] | [QQ 表情] |
|
||||
| [CQ:record] | [语音] |
|
||||
| [CQ:video] | [短视频] |
|
||||
| [CQ:at] | [@某人] |
|
||||
| [CQ:share] | [链接分享] |
|
||||
| [CQ:music] | [音乐分享] [音乐自定义分享] |
|
||||
| [CQ:reply] | [回复] |
|
||||
| [CQ:forward] | [合并转发] |
|
||||
| [CQ:node] | [合并转发节点] |
|
||||
| [CQ:xml] | [XML 消息] |
|
||||
| [CQ:json] | [JSON 消息] |
|
||||
|
||||
[qq 表情]: https://github.com/howmanybots/onebot/blob/master/v11/specs/message/segment.md#qq-%E8%A1%A8%E6%83%85
|
||||
[语音]: https://github.com/howmanybots/onebot/blob/master/v11/specs/message/segment.md#%E8%AF%AD%E9%9F%B3
|
||||
[短视频]: https://github.com/howmanybots/onebot/blob/master/v11/specs/message/segment.md#%E7%9F%AD%E8%A7%86%E9%A2%91
|
||||
[@某人]: https://github.com/howmanybots/onebot/blob/master/v11/specs/message/segment.md#%E6%9F%90%E4%BA%BA
|
||||
[链接分享]: https://github.com/howmanybots/onebot/blob/master/v11/specs/message/segment.md#%E9%93%BE%E6%8E%A5%E5%88%86%E4%BA%AB
|
||||
[音乐分享]: https://github.com/howmanybots/onebot/blob/master/v11/specs/message/segment.md#%E9%9F%B3%E4%B9%90%E5%88%86%E4%BA%AB-
|
||||
[音乐自定义分享]: https://github.com/howmanybots/onebot/blob/master/v11/specs/message/segment.md#%E9%9F%B3%E4%B9%90%E8%87%AA%E5%AE%9A%E4%B9%89%E5%88%86%E4%BA%AB-
|
||||
[回复]: https://github.com/howmanybots/onebot/blob/master/v11/specs/message/segment.md#%E5%9B%9E%E5%A4%8D
|
||||
[合并转发]: https://github.com/howmanybots/onebot/blob/master/v11/specs/message/segment.md#%E5%90%88%E5%B9%B6%E8%BD%AC%E5%8F%91-
|
||||
[合并转发节点]: https://github.com/howmanybots/onebot/blob/master/v11/specs/message/segment.md#%E5%90%88%E5%B9%B6%E8%BD%AC%E5%8F%91%E8%8A%82%E7%82%B9-
|
||||
[xml 消息]: https://github.com/howmanybots/onebot/blob/master/v11/specs/message/segment.md#xml-%E6%B6%88%E6%81%AF
|
||||
[json 消息]: https://github.com/howmanybots/onebot/blob/master/v11/specs/message/segment.md#json-%E6%B6%88%E6%81%AF
|
||||
|
||||
#### 拓展 CQ 码及与 Onebot 标准有略微差异的 CQ 码
|
||||
|
||||
| 拓展 CQ 码 | 功能 |
|
||||
| -------------- | --------------------------------- |
|
||||
| [CQ:image] | [图片] |
|
||||
| [CQ:redbag] | [红包] |
|
||||
| [CQ:poke] | [戳一戳] |
|
||||
| [CQ:gift] | [礼物] |
|
||||
| [CQ:node] | [合并转发消息节点] |
|
||||
| [CQ:cardimage] | [一种 xml 的图片消息(装逼大图)] |
|
||||
| [CQ:tts] | [文本转语音] |
|
||||
|
||||
[图片]: docs/cqhttp.md#%E5%9B%BE%E7%89%87
|
||||
[红包]: docs/cqhttp.md#%E7%BA%A2%E5%8C%85
|
||||
[戳一戳]: docs/cqhttp.md#%E6%88%B3%E4%B8%80%E6%88%B3
|
||||
[礼物]: docs/cqhttp.md#%E7%A4%BC%E7%89%A9
|
||||
[合并转发消息节点]: docs/cqhttp.md#%E5%90%88%E5%B9%B6%E8%BD%AC%E5%8F%91%E6%B6%88%E6%81%AF%E8%8A%82%E7%82%B9
|
||||
[一种 xml 的图片消息(装逼大图)]: docs/cqhttp.md#cardimage-%E4%B8%80%E7%A7%8Dxml%E7%9A%84%E5%9B%BE%E7%89%87%E6%B6%88%E6%81%AF%E8%A3%85%E9%80%BC%E5%A4%A7%E5%9B%BE
|
||||
[文本转语音]: docs/cqhttp.md#%E6%96%87%E6%9C%AC%E8%BD%AC%E8%AF%AD%E9%9F%B3
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>已实现API</summary>
|
||||
|
||||
##### 注意: 部分API实现与CQHTTP原版略有差异,请参考文档
|
||||
| API | 功能 |
|
||||
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| /get_login_info | [获取登录号信息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_login_info-%E8%8E%B7%E5%8F%96%E7%99%BB%E5%BD%95%E5%8F%B7%E4%BF%A1%E6%81%AF) |
|
||||
| /get_friend_list | [获取好友列表](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_friend_list-%E8%8E%B7%E5%8F%96%E5%A5%BD%E5%8F%8B%E5%88%97%E8%A1%A8) |
|
||||
| /get_group_list | [获取群列表](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_list-%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%88%97%E8%A1%A8) |
|
||||
| /get_group_info | [获取群信息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E4%BF%A1%E6%81%AF) |
|
||||
| /get_group_member_list | [获取群成员列表](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_member_list-%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%88%90%E5%91%98%E5%88%97%E8%A1%A8) |
|
||||
| /get_group_member_info | [获取群成员信息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_member_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%88%90%E5%91%98%E4%BF%A1%E6%81%AF) |
|
||||
| /send_msg | [发送消息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#send_msg-%E5%8F%91%E9%80%81%E6%B6%88%E6%81%AF) |
|
||||
| /send_group_msg | [发送群消息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#send_group_msg-%E5%8F%91%E9%80%81%E7%BE%A4%E6%B6%88%E6%81%AF) |
|
||||
| /send_private_msg | [发送私聊消息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#send_private_msg-%E5%8F%91%E9%80%81%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF) |
|
||||
| /delete_msg | [撤回信息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#delete_msg-%E6%92%A4%E5%9B%9E%E6%B6%88%E6%81%AF) |
|
||||
| /set_friend_add_request | [处理加好友请求](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_friend_add_request-%E5%A4%84%E7%90%86%E5%8A%A0%E5%A5%BD%E5%8F%8B%E8%AF%B7%E6%B1%82) |
|
||||
| /set_group_add_request | [处理加群请求/邀请](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_add_request-%E5%A4%84%E7%90%86%E5%8A%A0%E7%BE%A4%E8%AF%B7%E6%B1%82%E9%82%80%E8%AF%B7) |
|
||||
| /set_group_card | [设置群名片(群备注)](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_card-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%90%8D%E7%89%87%E7%BE%A4%E5%A4%87%E6%B3%A8) |
|
||||
| /set_group_special_title | [设置群组专属头衔](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_special_title-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E7%BB%84%E4%B8%93%E5%B1%9E%E5%A4%B4%E8%A1%94) |
|
||||
| /set_group_kick | [群组T人](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_kick-%E7%BE%A4%E7%BB%84%E8%B8%A2%E4%BA%BA) |
|
||||
| /set_group_ban | [群组单人禁言](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_ban-%E7%BE%A4%E7%BB%84%E5%8D%95%E4%BA%BA%E7%A6%81%E8%A8%80) |
|
||||
| /set_group_whole_ban | [群组全员禁言](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_whole_ban-%E7%BE%A4%E7%BB%84%E5%85%A8%E5%91%98%E7%A6%81%E8%A8%80) |
|
||||
| /set_group_leave | [退出群组](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_leave-%E9%80%80%E5%87%BA%E7%BE%A4%E7%BB%84) |
|
||||
| /set_group_name | [设置群组名](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_name-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%90%8D) |
|
||||
| /set_restart | [重启go-cqhttp](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_restart-%E9%87%8D%E5%90%AF-onebot-%E5%AE%9E%E7%8E%B0) |
|
||||
| /get_image | [获取图片信息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_image-%E8%8E%B7%E5%8F%96%E5%9B%BE%E7%89%87) |
|
||||
| /get_msg | [获取消息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_msg-%E8%8E%B7%E5%8F%96%E6%B6%88%E6%81%AF) |
|
||||
| /can_send_image | [检查是否可以发送图片](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#can_send_image-%E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E5%8F%91%E9%80%81%E5%9B%BE%E7%89%87) |
|
||||
| /can_send_record | [检查是否可以发送语音](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#can_send_record-%E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E5%8F%91%E9%80%81%E8%AF%AD%E9%9F%B3) |
|
||||
| /get_status | [获取插件运行状态](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_status-%E8%8E%B7%E5%8F%96%E8%BF%90%E8%A1%8C%E7%8A%B6%E6%80%81) |
|
||||
| /get_version_info | [获取 酷Q 及 CQHTTP插件的版本信息](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) |
|
||||
#### 符合 Onebot 标准的 API
|
||||
|
||||
| API | 功能 |
|
||||
| ------------------------ | ---------------------- |
|
||||
| /send_private_msg | [发送私聊消息] |
|
||||
| /send_group_msg | [发送群消息] |
|
||||
| /send_msg | [发送消息] |
|
||||
| /delete_msg | [撤回信息] |
|
||||
| /set_group_kick | [群组踢人] |
|
||||
| /set_group_ban | [群组单人禁言] |
|
||||
| /set_group_whole_ban | [群组全员禁言] |
|
||||
| /set_group_admin | [群组设置管理员] |
|
||||
| /set_group_card | [设置群名片(群备注)] |
|
||||
| /set_group_name | [设置群名] |
|
||||
| /set_group_leave | [退出群组] |
|
||||
| /set_group_special_title | [设置群组专属头衔] |
|
||||
| /set_friend_add_request | [处理加好友请求] |
|
||||
| /set_group_add_request | [处理加群请求/邀请] |
|
||||
| /get_login_info | [获取登录号信息] |
|
||||
| /get_stranger_info | [获取陌生人信息] |
|
||||
| /get_friend_list | [获取好友列表] |
|
||||
| /get_group_info | [获取群信息] |
|
||||
| /get_group_list | [获取群列表] |
|
||||
| /get_group_member_info | [获取群成员信息] |
|
||||
| /get_group_member_list | [获取群成员列表] |
|
||||
| /get_group_honor_info | [获取群荣誉信息] |
|
||||
| /can_send_image | [检查是否可以发送图片] |
|
||||
| /can_send_record | [检查是否可以发送语音] |
|
||||
| /get_version_info | [获取版本信息] |
|
||||
| /set_restart | [重启 go-cqhttp] |
|
||||
| /.handle_quick_operation | [对事件执行快速操作] |
|
||||
|
||||
[发送私聊消息]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#send_private_msg-%E5%8F%91%E9%80%81%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF
|
||||
[发送群消息]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#send_group_msg-%E5%8F%91%E9%80%81%E7%BE%A4%E6%B6%88%E6%81%AF
|
||||
[发送消息]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#send_msg-%E5%8F%91%E9%80%81%E6%B6%88%E6%81%AF
|
||||
[撤回信息]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#delete_msg-%E6%92%A4%E5%9B%9E%E6%B6%88%E6%81%AF
|
||||
[群组踢人]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_kick-%E7%BE%A4%E7%BB%84%E8%B8%A2%E4%BA%BA
|
||||
[群组单人禁言]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_ban-%E7%BE%A4%E7%BB%84%E5%8D%95%E4%BA%BA%E7%A6%81%E8%A8%80
|
||||
[群组全员禁言]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_whole_ban-%E7%BE%A4%E7%BB%84%E5%85%A8%E5%91%98%E7%A6%81%E8%A8%80
|
||||
[群组设置管理员]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_admin-%E7%BE%A4%E7%BB%84%E8%AE%BE%E7%BD%AE%E7%AE%A1%E7%90%86%E5%91%98
|
||||
[设置群名片(群备注)]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_card-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%90%8D%E7%89%87%E7%BE%A4%E5%A4%87%E6%B3%A8
|
||||
[设置群名]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_name-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%90%8D
|
||||
[退出群组]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_leave-%E9%80%80%E5%87%BA%E7%BE%A4%E7%BB%84
|
||||
[设置群组专属头衔]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_special_title-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E7%BB%84%E4%B8%93%E5%B1%9E%E5%A4%B4%E8%A1%94
|
||||
[处理加好友请求]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_friend_add_request-%E5%A4%84%E7%90%86%E5%8A%A0%E5%A5%BD%E5%8F%8B%E8%AF%B7%E6%B1%82
|
||||
[处理加群请求/邀请]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_add_request-%E5%A4%84%E7%90%86%E5%8A%A0%E7%BE%A4%E8%AF%B7%E6%B1%82%E9%82%80%E8%AF%B7
|
||||
[获取登录号信息]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_login_info-%E8%8E%B7%E5%8F%96%E7%99%BB%E5%BD%95%E5%8F%B7%E4%BF%A1%E6%81%AF
|
||||
[获取陌生人信息]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_stranger_info-%E8%8E%B7%E5%8F%96%E9%99%8C%E7%94%9F%E4%BA%BA%E4%BF%A1%E6%81%AF
|
||||
[获取好友列表]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_friend_list-%E8%8E%B7%E5%8F%96%E5%A5%BD%E5%8F%8B%E5%88%97%E8%A1%A8
|
||||
[获取群信息]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E4%BF%A1%E6%81%AF
|
||||
[获取群列表]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_list-%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%88%97%E8%A1%A8
|
||||
[获取群成员信息]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_member_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%88%90%E5%91%98%E4%BF%A1%E6%81%AF
|
||||
[获取群成员列表]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_member_list-%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%88%90%E5%91%98%E5%88%97%E8%A1%A8
|
||||
[获取群荣誉信息]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_honor_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E8%8D%A3%E8%AA%89%E4%BF%A1%E6%81%AF
|
||||
[检查是否可以发送图片]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#can_send_image-%E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E5%8F%91%E9%80%81%E5%9B%BE%E7%89%87
|
||||
[检查是否可以发送语音]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#can_send_record-%E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E5%8F%91%E9%80%81%E8%AF%AD%E9%9F%B3
|
||||
[获取版本信息]: 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
|
||||
[重启 go-cqhttp]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_restart-%E9%87%8D%E5%90%AF-onebot-%E5%AE%9E%E7%8E%B0
|
||||
[对事件执行快速操作]: https://github.com/howmanybots/onebot/blob/master/v11/specs/api/hidden.md#handle_quick_operation-%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%89%A7%E8%A1%8C%E5%BF%AB%E9%80%9F%E6%93%8D%E4%BD%9C
|
||||
|
||||
#### 拓展 API 及与 Onebot 标准有略微差异的 API
|
||||
|
||||
| 拓展 API | 功能 |
|
||||
| --------------------------- | ---------------------- |
|
||||
| /set_group_portrait | [设置群头像] |
|
||||
| /get_image | [获取图片信息] |
|
||||
| /get_msg | [获取消息] |
|
||||
| /get_forward_msg | [获取合并转发内容] |
|
||||
| /send_group_forward_msg | [发送合并转发(群)] |
|
||||
| /.get_word_slices | [获取中文分词] |
|
||||
| /.ocr_image | [图片 OCR] |
|
||||
| /get_group_system_msg | [获取群系统消息] |
|
||||
| /get_group_file_system_info | [获取群文件系统信息] |
|
||||
| /get_group_root_files | [获取群根目录文件列表] |
|
||||
| /get_group_files_by_folder | [获取群子目录文件列表] |
|
||||
| /get_group_file_url | [获取群文件资源链接] |
|
||||
| /get_status | [获取状态] |
|
||||
|
||||
[设置群头像]: docs/cqhttp.md#%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%A4%B4%E5%83%8F
|
||||
[获取图片信息]: docs/cqhttp.md#%E8%8E%B7%E5%8F%96%E5%9B%BE%E7%89%87%E4%BF%A1%E6%81%AF
|
||||
[获取消息]: docs/cqhttp.md#%E8%8E%B7%E5%8F%96%E6%B6%88%E6%81%AF
|
||||
[获取合并转发内容]: docs/cqhttp.md#%E8%8E%B7%E5%8F%96%E5%90%88%E5%B9%B6%E8%BD%AC%E5%8F%91%E5%86%85%E5%AE%B9
|
||||
[发送合并转发(群)]: docs/cqhttp.md#%E5%8F%91%E9%80%81%E5%90%88%E5%B9%B6%E8%BD%AC%E5%8F%91%E7%BE%A4
|
||||
[获取中文分词]: docs/cqhttp.md#%E8%8E%B7%E5%8F%96%E4%B8%AD%E6%96%87%E5%88%86%E8%AF%8D
|
||||
[图片 ocr]: docs/cqhttp.md#%E5%9B%BE%E7%89%87ocr
|
||||
[获取群系统消息]: docs/cqhttp.md#%E8%8E%B7%E5%8F%96%E7%BE%A4%E7%B3%BB%E7%BB%9F%E6%B6%88%E6%81%AF
|
||||
[获取群文件系统信息]: docs/cqhttp.md#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F%E4%BF%A1%E6%81%AF
|
||||
[获取群根目录文件列表]: docs/cqhttp.md#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%A0%B9%E7%9B%AE%E5%BD%95%E6%96%87%E4%BB%B6%E5%88%97%E8%A1%A8
|
||||
[获取群子目录文件列表]: docs/cqhttp.md#%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%AD%90%E7%9B%AE%E5%BD%95%E6%96%87%E4%BB%B6%E5%88%97%E8%A1%A8
|
||||
[获取群文件资源链接]: docs/cqhttp.md#%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%96%87%E4%BB%B6%E8%B5%84%E6%BA%90%E9%93%BE%E6%8E%A5
|
||||
[获取状态]: docs/cqhttp.md#%E8%8E%B7%E5%8F%96%E7%8A%B6%E6%80%81
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>已实现Event</summary>
|
||||
|
||||
##### 注意: 部分Event数据与CQHTTP原版略有差异,请参考文档
|
||||
| Event |
|
||||
| ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [私聊信息](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/message.md#%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF) |
|
||||
| [群消息](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/message.md#%E7%BE%A4%E6%B6%88%E6%81%AF) |
|
||||
| [群消息撤回(拓展Event)](docs/cqhttp.md#群消息撤回) |
|
||||
| [好友消息撤回(拓展Event)](docs/cqhttp.md#好友消息撤回) |
|
||||
| [群内提示事件(拓展Event)(龙王等事件)](docs/cqhttp.md#群内戳一戳) |
|
||||
| [群管理员变动](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E7%AE%A1%E7%90%86%E5%91%98%E5%8F%98%E5%8A%A8) |
|
||||
| [群成员减少](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E6%88%90%E5%91%98%E5%87%8F%E5%B0%91) |
|
||||
| [群成员增加](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E6%88%90%E5%91%98%E5%A2%9E%E5%8A%A0) |
|
||||
| [群禁言](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E7%A6%81%E8%A8%80) |
|
||||
| [群文件上传](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0) |
|
||||
| [加好友请求](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/request.md#%E5%8A%A0%E5%A5%BD%E5%8F%8B%E8%AF%B7%E6%B1%82) |
|
||||
| [加群请求/邀请](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/request.md#%E5%8A%A0%E7%BE%A4%E8%AF%B7%E6%B1%82%E9%82%80%E8%AF%B7) |
|
||||
#### 符合 Onebot 标准的 Event(部分 Event 比 Onebot 标准多上报几个字段,不影响使用)
|
||||
|
||||
| 事件类型 | Event |
|
||||
| -------- | ---------------- |
|
||||
| 消息事件 | [私聊信息] |
|
||||
| 消息事件 | [群消息] |
|
||||
| 通知事件 | [群文件上传] |
|
||||
| 通知事件 | [群管理员变动] |
|
||||
| 通知事件 | [群成员减少] |
|
||||
| 通知事件 | [群成员增加] |
|
||||
| 通知事件 | [群禁言] |
|
||||
| 通知事件 | [好友添加] |
|
||||
| 通知事件 | [群消息撤回] |
|
||||
| 通知事件 | [好友消息撤回] |
|
||||
| 通知事件 | [群内戳一戳] |
|
||||
| 通知事件 | [群红包运气王] |
|
||||
| 通知事件 | [群成员荣誉变更] |
|
||||
| 请求事件 | [加好友请求] |
|
||||
| 请求事件 | [加群请求/邀请] |
|
||||
|
||||
[私聊信息]: https://github.com/howmanybots/onebot/blob/master/v11/specs/event/message.md#%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF
|
||||
[群消息]: https://github.com/howmanybots/onebot/blob/master/v11/specs/event/message.md#%E7%BE%A4%E6%B6%88%E6%81%AF
|
||||
[群文件上传]: https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0
|
||||
[群管理员变动]: https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E7%AE%A1%E7%90%86%E5%91%98%E5%8F%98%E5%8A%A8
|
||||
[群成员减少]: https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E6%88%90%E5%91%98%E5%87%8F%E5%B0%91
|
||||
[群成员增加]: https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E6%88%90%E5%91%98%E5%A2%9E%E5%8A%A0
|
||||
[群禁言]: https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E7%A6%81%E8%A8%80
|
||||
[好友添加]: https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E5%A5%BD%E5%8F%8B%E6%B7%BB%E5%8A%A0
|
||||
[群消息撤回]: https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E6%B6%88%E6%81%AF%E6%92%A4%E5%9B%9E
|
||||
[好友消息撤回]: https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E5%A5%BD%E5%8F%8B%E6%B6%88%E6%81%AF%E6%92%A4%E5%9B%9E
|
||||
[群内戳一戳]: https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E5%86%85%E6%88%B3%E4%B8%80%E6%88%B3
|
||||
[群红包运气王]: https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E7%BA%A2%E5%8C%85%E8%BF%90%E6%B0%94%E7%8E%8B
|
||||
[群成员荣誉变更]: https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E6%88%90%E5%91%98%E8%8D%A3%E8%AA%89%E5%8F%98%E6%9B%B4
|
||||
[加好友请求]: https://github.com/howmanybots/onebot/blob/master/v11/specs/event/request.md#%E5%8A%A0%E5%A5%BD%E5%8F%8B%E8%AF%B7%E6%B1%82
|
||||
[加群请求/邀请]: https://github.com/howmanybots/onebot/blob/master/v11/specs/event/request.md#%E5%8A%A0%E7%BE%A4%E8%AF%B7%E6%B1%82%E9%82%80%E8%AF%B7
|
||||
|
||||
#### 拓展 Event
|
||||
|
||||
| 事件类型 | 拓展 Event |
|
||||
| -------- | ---------------- |
|
||||
| 通知事件 | [好友戳一戳] |
|
||||
| 通知事件 | [群成员名片更新] |
|
||||
| 通知事件 | [接收到离线文件] |
|
||||
|
||||
[好友戳一戳]: docs/cqhttp.md#%E5%A5%BD%E5%8F%8B%E6%88%B3%E4%B8%80%E6%88%B3
|
||||
[群成员名片更新]: docs/cqhttp.md#%E7%BE%A4%E6%88%90%E5%91%98%E5%90%8D%E7%89%87%E6%9B%B4%E6%96%B0
|
||||
[接收到离线文件]: docs/cqhttp.md#%E6%8E%A5%E6%94%B6%E5%88%B0%E7%A6%BB%E7%BA%BF%E6%96%87%E4%BB%B6
|
||||
|
||||
</details>
|
||||
|
||||
# 关于ISSUE
|
||||
## 关于 ISSUE
|
||||
|
||||
以下ISSUE会被直接关闭
|
||||
- 提交BUG不使用Template
|
||||
以下 ISSUE 会被直接关闭
|
||||
|
||||
- 提交 BUG 不使用 Template
|
||||
- 询问已知问题
|
||||
- 提问找不到重点
|
||||
- 重复提问
|
||||
|
||||
> 请注意, 开发者并没有义务回复您的问题. 您应该具备基本的提问技巧。
|
||||
|
||||
# 性能
|
||||
## 性能
|
||||
|
||||
在关闭数据库的情况下, 加载25个好友128个群运行24小时后内存使用为10MB左右. 开启数据库后内存使用将根据消息量增加10-20MB, 如果系统内存小于128M建议关闭数据库使用.
|
||||
在关闭数据库的情况下, 加载 25 个好友 128 个群运行 24 小时后内存使用为 10MB 左右. 开启数据库后内存使用将根据消息量增加 10-20MB, 如果系统内存小于 128M 建议关闭数据库使用.
|
||||
|
227
coolq/api.go
227
coolq/api.go
@ -55,10 +55,17 @@ func (bot *CQBot) CQGetGroupList(noCache bool) MSG {
|
||||
}
|
||||
|
||||
// https://cqhttp.cc/docs/4.15/#/API?id=get_group_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E4%BF%A1%E6%81%AF
|
||||
func (bot *CQBot) CQGetGroupInfo(groupId int64) MSG {
|
||||
func (bot *CQBot) CQGetGroupInfo(groupId int64, noCache bool) MSG {
|
||||
group := bot.Client.FindGroup(groupId)
|
||||
if group == nil {
|
||||
return Failed(100)
|
||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||
}
|
||||
if noCache {
|
||||
var err error
|
||||
group, err = bot.Client.GetGroupInfo(groupId)
|
||||
if err != nil {
|
||||
return Failed(100, "GET_GROUP_INFO_API_ERROR", err.Error())
|
||||
}
|
||||
}
|
||||
return OK(MSG{
|
||||
"group_id": group.Code,
|
||||
@ -72,13 +79,13 @@ func (bot *CQBot) CQGetGroupInfo(groupId int64) MSG {
|
||||
func (bot *CQBot) CQGetGroupMemberList(groupId int64, noCache bool) MSG {
|
||||
group := bot.Client.FindGroup(groupId)
|
||||
if group == nil {
|
||||
return Failed(100)
|
||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||
}
|
||||
if noCache {
|
||||
t, err := bot.Client.GetGroupMembers(group)
|
||||
if err != nil {
|
||||
log.Warnf("刷新群 %v 成员列表失败: %v", groupId, err)
|
||||
return Failed(100)
|
||||
return Failed(100, "GET_MEMBERS_API_ERROR", err.Error())
|
||||
}
|
||||
group.Members = t
|
||||
}
|
||||
@ -93,11 +100,11 @@ func (bot *CQBot) CQGetGroupMemberList(groupId int64, noCache bool) MSG {
|
||||
func (bot *CQBot) CQGetGroupMemberInfo(groupId, userId int64) MSG {
|
||||
group := bot.Client.FindGroup(groupId)
|
||||
if group == nil {
|
||||
return Failed(100)
|
||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||
}
|
||||
member := group.FindMember(userId)
|
||||
if member == nil {
|
||||
return Failed(102)
|
||||
return Failed(100, "MEMBER_NOT_FOUND", "群员不存在")
|
||||
}
|
||||
return OK(convertGroupMemberInfo(groupId, member))
|
||||
}
|
||||
@ -106,7 +113,7 @@ 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 Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
||||
}
|
||||
return OK(fs)
|
||||
}
|
||||
@ -115,12 +122,12 @@ 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)
|
||||
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
||||
}
|
||||
files, folders, err := fs.Root()
|
||||
if err != nil {
|
||||
log.Errorf("获取群 %v 根目录文件失败: %v", groupId, err)
|
||||
return Failed(100)
|
||||
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
||||
}
|
||||
return OK(MSG{
|
||||
"files": files,
|
||||
@ -132,12 +139,12 @@ 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)
|
||||
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
||||
}
|
||||
files, folders, err := fs.GetFilesByFolder(folderId)
|
||||
if err != nil {
|
||||
log.Errorf("获取群 %v 根目录 %v 子文件失败: %v", groupId, folderId, err)
|
||||
return Failed(100)
|
||||
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
||||
}
|
||||
return OK(MSG{
|
||||
"files": files,
|
||||
@ -148,7 +155,7 @@ func (bot *CQBot) CQGetGroupFilesByFolderId(groupId int64, folderId string) MSG
|
||||
func (bot *CQBot) CQGetGroupFileUrl(groupId int64, fileId string, busId int32) MSG {
|
||||
url := bot.Client.GetGroupFileUrl(groupId, fileId, busId)
|
||||
if url == "" {
|
||||
return Failed(100)
|
||||
return Failed(100, "FILE_SYSTEM_API_ERROR")
|
||||
}
|
||||
return OK(MSG{
|
||||
"url": url,
|
||||
@ -158,7 +165,7 @@ func (bot *CQBot) CQGetGroupFileUrl(groupId int64, fileId string, busId int32) M
|
||||
func (bot *CQBot) CQGetWordSlices(content string) MSG {
|
||||
slices, err := bot.Client.GetWordSegmentation(content)
|
||||
if err != nil {
|
||||
return Failed(100)
|
||||
return Failed(100, "WORD_SEGMENTATION_API_ERROR", err.Error())
|
||||
}
|
||||
for i := 0; i < len(slices); i++ {
|
||||
slices[i] = strings.ReplaceAll(slices[i], "\u0000", "")
|
||||
@ -188,7 +195,7 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bo
|
||||
fixAt(elem)
|
||||
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
||||
if mid == -1 {
|
||||
return Failed(100)
|
||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
||||
}
|
||||
log.Infof("发送群 %v(%v) 的消息: %v (%v)", groupId, groupId, limitedString(m.String()), mid)
|
||||
return OK(MSG{"message_id": mid})
|
||||
@ -204,7 +211,7 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bo
|
||||
}
|
||||
if str == "" {
|
||||
log.Warnf("群消息发送失败: 信息为空. MSG: %v", i)
|
||||
return Failed(100)
|
||||
return Failed(100, "EMPTY_MSG_ERROR", "消息为空")
|
||||
}
|
||||
var elem []message.IMessageElement
|
||||
if autoEscape {
|
||||
@ -215,7 +222,7 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bo
|
||||
fixAt(elem)
|
||||
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
||||
if mid == -1 {
|
||||
return Failed(100)
|
||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
||||
}
|
||||
log.Infof("发送群 %v(%v) 的消息: %v (%v)", groupId, groupId, limitedString(str), mid)
|
||||
return OK(MSG{"message_id": mid})
|
||||
@ -225,7 +232,7 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
||||
if m.Type != gjson.JSON {
|
||||
return Failed(100)
|
||||
}
|
||||
var nodes []*message.ForwardNode
|
||||
var sendNodes []*message.ForwardNode
|
||||
ts := time.Now().Add(-time.Minute * 5)
|
||||
hasCustom := func() bool {
|
||||
for _, item := range m.Array() {
|
||||
@ -235,13 +242,14 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
||||
}
|
||||
return false
|
||||
}()
|
||||
convert := func(e gjson.Result) {
|
||||
var convert func(e gjson.Result) []*message.ForwardNode
|
||||
convert = func(e gjson.Result) (nodes []*message.ForwardNode) {
|
||||
if e.Get("type").Str != "node" {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
ts.Add(time.Second)
|
||||
if e.Get("data.id").Exists() {
|
||||
i, _ := strconv.Atoi(e.Get("data.id").Str)
|
||||
i, _ := strconv.Atoi(e.Get("data.id").String())
|
||||
m := bot.GetMessage(int32(i))
|
||||
if m != nil {
|
||||
sender := m["sender"].(message.Sender)
|
||||
@ -263,6 +271,30 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
||||
}
|
||||
uin, _ := strconv.ParseInt(e.Get("data.uin").Str, 10, 64)
|
||||
name := e.Get("data.name").Str
|
||||
c := e.Get("data.content")
|
||||
if c.IsArray() {
|
||||
flag := false
|
||||
c.ForEach(func(_, value gjson.Result) bool {
|
||||
if value.Get("type").String() == "node" {
|
||||
flag = true
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
if flag {
|
||||
var taowa []*message.ForwardNode
|
||||
for _, item := range c.Array() {
|
||||
taowa = append(taowa, convert(item)...)
|
||||
}
|
||||
nodes = append(nodes, &message.ForwardNode{
|
||||
SenderId: uin,
|
||||
SenderName: name,
|
||||
Time: int32(ts.Unix()),
|
||||
Message: []message.IMessageElement{bot.Client.UploadGroupForwardMessage(groupId, &message.ForwardMessage{Nodes: taowa})},
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
content := bot.ConvertObjectMessage(e.Get("data.content"), true)
|
||||
if uin != 0 && name != "" && len(content) > 0 {
|
||||
var newElem []message.IMessageElement
|
||||
@ -287,16 +319,17 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
||||
return
|
||||
}
|
||||
log.Warnf("警告: 非法 Forward node 将跳过")
|
||||
return
|
||||
}
|
||||
if m.IsArray() {
|
||||
for _, item := range m.Array() {
|
||||
convert(item)
|
||||
sendNodes = append(sendNodes, convert(item)...)
|
||||
}
|
||||
} else {
|
||||
convert(m)
|
||||
sendNodes = convert(m)
|
||||
}
|
||||
if len(nodes) > 0 {
|
||||
gm := bot.Client.SendGroupForwardMessage(groupId, &message.ForwardMessage{Nodes: nodes})
|
||||
if len(sendNodes) > 0 {
|
||||
gm := bot.Client.SendGroupForwardMessage(groupId, &message.ForwardMessage{Nodes: sendNodes})
|
||||
return OK(MSG{
|
||||
"message_id": ToGlobalId(groupId, gm.Id),
|
||||
})
|
||||
@ -312,7 +345,7 @@ func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}, autoEscape b
|
||||
elem := bot.ConvertObjectMessage(m, true)
|
||||
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
||||
if mid == -1 {
|
||||
return Failed(100)
|
||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
||||
}
|
||||
log.Infof("发送好友 %v(%v) 的消息: %v (%v)", userId, userId, limitedString(m.String()), mid)
|
||||
return OK(MSG{"message_id": mid})
|
||||
@ -327,7 +360,7 @@ func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}, autoEscape b
|
||||
str = s
|
||||
}
|
||||
if str == "" {
|
||||
return Failed(100)
|
||||
return Failed(100, "EMPTY_MSG_ERROR", "消息为空")
|
||||
}
|
||||
var elem []message.IMessageElement
|
||||
if autoEscape {
|
||||
@ -337,7 +370,7 @@ func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}, autoEscape b
|
||||
}
|
||||
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
||||
if mid == -1 {
|
||||
return Failed(100)
|
||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
||||
}
|
||||
log.Infof("发送好友 %v(%v) 的消息: %v (%v)", userId, userId, limitedString(str), mid)
|
||||
return OK(MSG{"message_id": mid})
|
||||
@ -351,7 +384,7 @@ func (bot *CQBot) CQSetGroupCard(groupId, userId int64, card string) MSG {
|
||||
return OK(nil)
|
||||
}
|
||||
}
|
||||
return Failed(100)
|
||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||
}
|
||||
|
||||
// https://cqhttp.cc/docs/4.15/#/API?id=set_group_special_title-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E7%BB%84%E4%B8%93%E5%B1%9E%E5%A4%B4%E8%A1%94
|
||||
@ -362,7 +395,7 @@ func (bot *CQBot) CQSetGroupSpecialTitle(groupId, userId int64, title string) MS
|
||||
return OK(nil)
|
||||
}
|
||||
}
|
||||
return Failed(100)
|
||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||
}
|
||||
|
||||
func (bot *CQBot) CQSetGroupName(groupId int64, name string) MSG {
|
||||
@ -370,7 +403,7 @@ func (bot *CQBot) CQSetGroupName(groupId int64, name string) MSG {
|
||||
g.UpdateName(name)
|
||||
return OK(nil)
|
||||
}
|
||||
return Failed(100)
|
||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||
}
|
||||
|
||||
func (bot *CQBot) CQSetGroupMemo(groupId int64, msg string) MSG {
|
||||
@ -378,18 +411,18 @@ func (bot *CQBot) CQSetGroupMemo(groupId int64, msg string) MSG {
|
||||
g.UpdateMemo(msg)
|
||||
return OK(nil)
|
||||
}
|
||||
return Failed(100)
|
||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||
}
|
||||
|
||||
// https://cqhttp.cc/docs/4.15/#/API?id=set_group_kick-%E7%BE%A4%E7%BB%84%E8%B8%A2%E4%BA%BA
|
||||
func (bot *CQBot) CQSetGroupKick(groupId, userId int64, msg string) MSG {
|
||||
func (bot *CQBot) CQSetGroupKick(groupId, userId int64, msg string, block bool) MSG {
|
||||
if g := bot.Client.FindGroup(groupId); g != nil {
|
||||
if m := g.FindMember(userId); m != nil {
|
||||
m.Kick(msg)
|
||||
m.Kick(msg, block)
|
||||
return OK(nil)
|
||||
}
|
||||
}
|
||||
return Failed(100)
|
||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||
}
|
||||
|
||||
// https://cqhttp.cc/docs/4.15/#/API?id=set_group_ban-%E7%BE%A4%E7%BB%84%E5%8D%95%E4%BA%BA%E7%A6%81%E8%A8%80
|
||||
@ -400,7 +433,7 @@ func (bot *CQBot) CQSetGroupBan(groupId, userId int64, duration uint32) MSG {
|
||||
return OK(nil)
|
||||
}
|
||||
}
|
||||
return Failed(100)
|
||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||
}
|
||||
|
||||
// https://cqhttp.cc/docs/4.15/#/API?id=set_group_whole_ban-%E7%BE%A4%E7%BB%84%E5%85%A8%E5%91%98%E7%A6%81%E8%A8%80
|
||||
@ -409,7 +442,7 @@ func (bot *CQBot) CQSetGroupWholeBan(groupId int64, enable bool) MSG {
|
||||
g.MuteAll(enable)
|
||||
return OK(nil)
|
||||
}
|
||||
return Failed(100)
|
||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||
}
|
||||
|
||||
// https://cqhttp.cc/docs/4.15/#/API?id=set_group_leave-%E9%80%80%E5%87%BA%E7%BE%A4%E7%BB%84
|
||||
@ -418,14 +451,25 @@ func (bot *CQBot) CQSetGroupLeave(groupId int64) MSG {
|
||||
g.Quit()
|
||||
return OK(nil)
|
||||
}
|
||||
return Failed(100)
|
||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||
}
|
||||
|
||||
func (bot *CQBot) CQGetAtAllRemain(groupId int64) MSG {
|
||||
if g := bot.Client.FindGroup(groupId); g != nil {
|
||||
i, err := bot.Client.GetAtAllRemain(groupId)
|
||||
if err != nil {
|
||||
return Failed(100, "GROUP_REMAIN_API_ERROR", err.Error())
|
||||
}
|
||||
return OK(i)
|
||||
}
|
||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||
}
|
||||
|
||||
// https://cqhttp.cc/docs/4.15/#/API?id=set_friend_add_request-%E5%A4%84%E7%90%86%E5%8A%A0%E5%A5%BD%E5%8F%8B%E8%AF%B7%E6%B1%82
|
||||
func (bot *CQBot) CQProcessFriendRequest(flag string, approve bool) MSG {
|
||||
req, ok := bot.friendReqCache.Load(flag)
|
||||
if !ok {
|
||||
return Failed(100)
|
||||
return Failed(100, "FLAG_NOT_FOUND", "FLAG不存在")
|
||||
}
|
||||
if approve {
|
||||
req.(*client.NewFriendRequest).Accept()
|
||||
@ -440,14 +484,14 @@ func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bo
|
||||
msgs, err := bot.Client.GetGroupSystemMessages()
|
||||
if err != nil {
|
||||
log.Errorf("获取群系统消息失败: %v", err)
|
||||
return Failed(100)
|
||||
return Failed(100, "SYSTEM_MSG_API_ERROR", err.Error())
|
||||
}
|
||||
if subType == "add" {
|
||||
for _, req := range msgs.JoinRequests {
|
||||
if strconv.FormatInt(req.RequestId, 10) == flag {
|
||||
if req.Checked {
|
||||
log.Errorf("处理群系统消息失败: 无法操作已处理的消息.")
|
||||
return Failed(100)
|
||||
return Failed(100, "FLAG_HAS_BEEN_CHECKED", "消息已被处理")
|
||||
}
|
||||
if approve {
|
||||
req.Accept()
|
||||
@ -462,7 +506,7 @@ func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bo
|
||||
if strconv.FormatInt(req.RequestId, 10) == flag {
|
||||
if req.Checked {
|
||||
log.Errorf("处理群系统消息失败: 无法操作已处理的消息.")
|
||||
return Failed(100)
|
||||
return Failed(100, "FLAG_HAS_BEEN_CHECKED", "消息已被处理")
|
||||
}
|
||||
if approve {
|
||||
req.Accept()
|
||||
@ -474,23 +518,29 @@ func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bo
|
||||
}
|
||||
}
|
||||
log.Errorf("处理群系统消息失败: 消息 %v 不存在.", flag)
|
||||
return Failed(100)
|
||||
return Failed(100, "FLAG_NOT_FOUND", "FLAG不存在")
|
||||
}
|
||||
|
||||
// https://cqhttp.cc/docs/4.15/#/API?id=delete_msg-%E6%92%A4%E5%9B%9E%E6%B6%88%E6%81%AF
|
||||
func (bot *CQBot) CQDeleteMessage(messageId int32) MSG {
|
||||
msg := bot.GetMessage(messageId)
|
||||
if msg == nil {
|
||||
return Failed(100)
|
||||
return Failed(100, "MESSAGE_NOT_FOUND", "消息不存在")
|
||||
}
|
||||
if _, ok := msg["group"]; ok {
|
||||
bot.Client.RecallGroupMessage(msg["group"].(int64), msg["message-id"].(int32), msg["internal-id"].(int32))
|
||||
if err := bot.Client.RecallGroupMessage(msg["group"].(int64), msg["message-id"].(int32), msg["internal-id"].(int32)); err != nil {
|
||||
log.Warnf("撤回 %v 失败: %v", messageId, err)
|
||||
return Failed(100, "RECALL_API_ERROR", err.Error())
|
||||
}
|
||||
} else {
|
||||
if msg["sender"].(message.Sender).Uin != bot.Client.Uin {
|
||||
log.Warnf("撤回 %v 失败: 好友会话无法撤回对方消息.")
|
||||
return Failed(100)
|
||||
log.Warnf("撤回 %v 失败: 好友会话无法撤回对方消息.", messageId)
|
||||
return Failed(100, "CANNOT_RECALL_FRIEND_MSG", "无法撤回对方消息")
|
||||
}
|
||||
if err := bot.Client.RecallPrivateMessage(msg["target"].(int64), int64(msg["time"].(int32)), msg["message-id"].(int32), msg["internal-id"].(int32)); err != nil {
|
||||
log.Warnf("撤回 %v 失败: %v", messageId, err)
|
||||
return Failed(100, "RECALL_API_ERROR", err.Error())
|
||||
}
|
||||
bot.Client.RecallPrivateMessage(msg["target"].(int64), int64(msg["time"].(int32)), msg["message-id"].(int32), msg["internal-id"].(int32))
|
||||
}
|
||||
return OK(nil)
|
||||
}
|
||||
@ -499,17 +549,17 @@ func (bot *CQBot) CQDeleteMessage(messageId int32) MSG {
|
||||
func (bot *CQBot) CQSetGroupAdmin(groupId, userId int64, enable bool) MSG {
|
||||
group := bot.Client.FindGroup(groupId)
|
||||
if group == nil || group.OwnerUin != bot.Client.Uin {
|
||||
return Failed(100)
|
||||
return Failed(100, "PERMISSION_DENIED", "群不存在或权限不足")
|
||||
}
|
||||
mem := group.FindMember(userId)
|
||||
if mem == nil {
|
||||
return Failed(100)
|
||||
return Failed(100, "GROUP_MEMBER_NOT_FOUND", "群成员不存在")
|
||||
}
|
||||
mem.SetAdmin(enable)
|
||||
t, err := bot.Client.GetGroupMembers(group)
|
||||
if err != nil {
|
||||
log.Warnf("刷新群 %v 成员列表失败: %v", groupId, err)
|
||||
return Failed(100)
|
||||
return Failed(100, "GET_MEMBERS_API_ERROR", err.Error())
|
||||
}
|
||||
group.Members = t
|
||||
return OK(nil)
|
||||
@ -518,7 +568,7 @@ func (bot *CQBot) CQSetGroupAdmin(groupId, userId int64, enable bool) MSG {
|
||||
func (bot *CQBot) CQGetVipInfo(userId int64) MSG {
|
||||
vip, err := bot.Client.GetVipInfo(userId)
|
||||
if err != nil {
|
||||
return Failed(100)
|
||||
return Failed(100, "VIP_API_ERROR", err.Error())
|
||||
}
|
||||
msg := MSG{
|
||||
"user_id": vip.Uin,
|
||||
@ -591,7 +641,7 @@ func (bot *CQBot) CQGetGroupHonorInfo(groupId int64, t string) MSG {
|
||||
func (bot *CQBot) CQGetStrangerInfo(userId int64) MSG {
|
||||
info, err := bot.Client.GetSummaryInfo(userId)
|
||||
if err != nil {
|
||||
return Failed(100)
|
||||
return Failed(100, "SUMMARY_API_ERROR", err.Error())
|
||||
}
|
||||
return OK(MSG{
|
||||
"user_id": info.Uin,
|
||||
@ -639,7 +689,7 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
||||
bot.CQDeleteMessage(int32(context.Get("message_id").Int()))
|
||||
}
|
||||
if operation.Get("kick").Bool() && !isAnonymous {
|
||||
bot.CQSetGroupKick(context.Get("group_id").Int(), context.Get("user_id").Int(), "")
|
||||
bot.CQSetGroupKick(context.Get("group_id").Int(), context.Get("user_id").Int(), "", operation.Get("reject_add_request").Bool())
|
||||
}
|
||||
if operation.Get("ban").Bool() {
|
||||
var duration uint32 = 30 * 60
|
||||
@ -686,14 +736,15 @@ func (bot *CQBot) CQGetImage(file string) MSG {
|
||||
}
|
||||
msg["file"] = local
|
||||
return OK(msg)
|
||||
} else {
|
||||
return Failed(100, "LOAD_FILE_ERROR", err.Error())
|
||||
}
|
||||
return Failed(100)
|
||||
}
|
||||
|
||||
func (bot *CQBot) CQGetForwardMessage(resId string) MSG {
|
||||
m := bot.Client.GetForwardMessage(resId)
|
||||
if m == nil {
|
||||
return Failed(100)
|
||||
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
|
||||
}
|
||||
r := make([]MSG, 0)
|
||||
for _, n := range m.Nodes {
|
||||
@ -715,20 +766,28 @@ func (bot *CQBot) CQGetForwardMessage(resId string) MSG {
|
||||
func (bot *CQBot) CQGetMessage(messageId int32) MSG {
|
||||
msg := bot.GetMessage(messageId)
|
||||
if msg == nil {
|
||||
return Failed(100)
|
||||
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
|
||||
}
|
||||
sender := msg["sender"].(message.Sender)
|
||||
_, group := msg["group"]
|
||||
gid, isGroup := msg["group"]
|
||||
raw := msg["message"].(string)
|
||||
return OK(MSG{
|
||||
"message_id": messageId,
|
||||
"real_id": msg["message-id"],
|
||||
"group": group,
|
||||
"group": isGroup,
|
||||
"group_id": gid,
|
||||
"sender": MSG{
|
||||
"user_id": sender.Uin,
|
||||
"nickname": sender.Nickname,
|
||||
},
|
||||
"time": msg["time"],
|
||||
"message": msg["message"],
|
||||
"time": msg["time"],
|
||||
"message_raw": raw,
|
||||
"message": ToFormattedMessage(bot.ConvertStringMessage(raw, isGroup), func() int64 {
|
||||
if isGroup {
|
||||
return gid.(int64)
|
||||
}
|
||||
return sender.Uin
|
||||
}(), false),
|
||||
})
|
||||
}
|
||||
|
||||
@ -736,7 +795,7 @@ func (bot *CQBot) CQGetGroupSystemMessages() MSG {
|
||||
msg, err := bot.Client.GetGroupSystemMessages()
|
||||
if err != nil {
|
||||
log.Warnf("获取群系统消息失败: %v", err)
|
||||
return Failed(100)
|
||||
return Failed(100, "SYSTEM_MSG_API_ERROR", err.Error())
|
||||
}
|
||||
return OK(msg)
|
||||
}
|
||||
@ -753,12 +812,12 @@ func (bot *CQBot) CQOcrImage(imageId string) MSG {
|
||||
img, err := bot.makeImageElem(map[string]string{"file": imageId}, true)
|
||||
if err != nil {
|
||||
log.Warnf("load image error: %v", err)
|
||||
return Failed(100)
|
||||
return Failed(100, "LOAD_FILE_ERROR", err.Error())
|
||||
}
|
||||
rsp, err := bot.Client.ImageOcr(img)
|
||||
if err != nil {
|
||||
log.Warnf("ocr image error: %v", err)
|
||||
return Failed(100)
|
||||
return Failed(100, "OCR_API_ERROR", err.Error())
|
||||
}
|
||||
return OK(rsp)
|
||||
}
|
||||
@ -773,14 +832,35 @@ func (bot *CQBot) CQSetGroupPortrait(groupId int64, file, cache string) MSG {
|
||||
img, err := global.FindFile(file, cache, global.IMAGE_PATH)
|
||||
if err != nil {
|
||||
log.Warnf("set group portrait error: %v", err)
|
||||
return Failed(100)
|
||||
return Failed(100, "LOAD_FILE_ERROR", err.Error())
|
||||
}
|
||||
g.UpdateGroupHeadPortrait(img)
|
||||
return OK(nil)
|
||||
}
|
||||
return Failed(100)
|
||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||
}
|
||||
|
||||
func (bot *CQBot) CQSetGroupAnonymousBan(groupId int64, flag string, duration int32) MSG {
|
||||
if flag == "" {
|
||||
return Failed(100, "INVALID_FLAG", "无效的flag")
|
||||
}
|
||||
if g := bot.Client.FindGroup(groupId); g != nil {
|
||||
s := strings.SplitN(flag, "|", 2)
|
||||
if len(s) != 2 {
|
||||
return Failed(100, "INVALID_FLAG", "无效的flag")
|
||||
}
|
||||
id := s[0]
|
||||
nick := s[1]
|
||||
if err := g.MuteAnonymous(id, nick, duration); err != nil {
|
||||
log.Warnf("anonymous ban error: %v", err)
|
||||
return Failed(100, "CALL_API_ERROR", err.Error())
|
||||
}
|
||||
return OK(nil)
|
||||
}
|
||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||
}
|
||||
|
||||
// https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_status-%E8%8E%B7%E5%8F%96%E8%BF%90%E8%A1%8C%E7%8A%B6%E6%80%81
|
||||
func (bot *CQBot) CQGetStatus() MSG {
|
||||
return OK(MSG{
|
||||
"app_initialized": true,
|
||||
@ -788,7 +868,8 @@ func (bot *CQBot) CQGetStatus() MSG {
|
||||
"plugins_good": nil,
|
||||
"app_good": true,
|
||||
"online": bot.Client.Online,
|
||||
"good": true,
|
||||
"good": bot.Client.Online,
|
||||
"stat": bot.Client.GetStatistics(),
|
||||
})
|
||||
}
|
||||
|
||||
@ -812,6 +893,8 @@ func (bot *CQBot) CQGetVersionInfo() MSG {
|
||||
return 1
|
||||
case client.AndroidWatch:
|
||||
return 2
|
||||
case client.MacOS:
|
||||
return 3
|
||||
default:
|
||||
return -1
|
||||
}
|
||||
@ -823,8 +906,16 @@ func OK(data interface{}) MSG {
|
||||
return MSG{"data": data, "retcode": 0, "status": "ok"}
|
||||
}
|
||||
|
||||
func Failed(code int) MSG {
|
||||
return MSG{"data": nil, "retcode": code, "status": "failed"}
|
||||
func Failed(code int, msg ...string) MSG {
|
||||
m := ""
|
||||
w := ""
|
||||
if len(msg) > 0 {
|
||||
m = msg[0]
|
||||
}
|
||||
if len(msg) > 1 {
|
||||
w = msg[1]
|
||||
}
|
||||
return MSG{"data": nil, "retcode": code, "msg": m, "wording": w, "status": "failed"}
|
||||
}
|
||||
|
||||
func convertGroupMemberInfo(groupId int64, m *client.GroupMemberInfo) MSG {
|
||||
|
30
coolq/bot.go
30
coolq/bot.go
@ -3,10 +3,10 @@ package coolq
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"path"
|
||||
"runtime/debug"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -17,10 +17,12 @@ import (
|
||||
"github.com/Mrs4s/MiraiGo/message"
|
||||
"github.com/Mrs4s/go-cqhttp/global"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
|
||||
type CQBot struct {
|
||||
Client *client.QQClient
|
||||
|
||||
@ -86,7 +88,7 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot {
|
||||
"self_id": bot.Client.Uin,
|
||||
"post_type": "meta_event",
|
||||
"meta_event_type": "heartbeat",
|
||||
"status": nil,
|
||||
"status": bot.CQGetStatus()["data"],
|
||||
"interval": 1000 * i,
|
||||
})
|
||||
}
|
||||
@ -220,7 +222,13 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int
|
||||
ret := bot.Client.SendGroupMessage(groupId, m, ForceFragmented)
|
||||
if ret == nil || ret.Id == -1 {
|
||||
log.Warnf("群消息发送失败: 账号可能被风控.")
|
||||
return -1
|
||||
if !ForceFragmented {
|
||||
log.Warnf("将尝试分片发送...")
|
||||
ret = bot.Client.SendGroupMessage(groupId, m, true)
|
||||
}
|
||||
if ret == nil || ret.Id == -1 {
|
||||
return -1
|
||||
}
|
||||
}
|
||||
return bot.InsertGroupMessage(ret)
|
||||
}
|
||||
@ -390,22 +398,24 @@ func (bot *CQBot) Release() {
|
||||
}
|
||||
|
||||
func (bot *CQBot) dispatchEventMessage(m MSG) {
|
||||
payload := gjson.Parse(m.ToJson())
|
||||
filter := global.EventFilter
|
||||
if filter != nil && (*filter).Eval(payload) == false {
|
||||
if global.EventFilter != nil && global.EventFilter.Eval(global.MSG(m)) == false {
|
||||
log.Debug("Event filtered!")
|
||||
return
|
||||
}
|
||||
for _, f := range bot.events {
|
||||
fn := f
|
||||
go func() {
|
||||
go func(fn func(MSG)) {
|
||||
defer func() {
|
||||
if pan := recover(); pan != nil {
|
||||
log.Warnf("处理事件 %v 时出现错误: %v \n%s", m, pan, debug.Stack())
|
||||
}
|
||||
}()
|
||||
start := time.Now()
|
||||
fn(m)
|
||||
end := time.Now()
|
||||
if end.Sub(start) > time.Second*5 {
|
||||
log.Debugf("警告: 事件处理耗时超过 5 秒 (%v), 请检查应用是否有堵塞.", end.Sub(start))
|
||||
}
|
||||
}()
|
||||
}(f)
|
||||
}
|
||||
}
|
||||
|
||||
|
183
coolq/cqcode.go
183
coolq/cqcode.go
@ -9,9 +9,10 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"math/rand"
|
||||
"net/url"
|
||||
"path"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -23,11 +24,14 @@ import (
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
/*
|
||||
var matchReg = regexp.MustCompile(`\[CQ:\w+?.*?]`)
|
||||
var typeReg = regexp.MustCompile(`\[CQ:(\w+)`)
|
||||
var paramReg = regexp.MustCompile(`,([\w\-.]+?)=([^,\]]+)`)
|
||||
*/
|
||||
|
||||
var IgnoreInvalidCQCode = false
|
||||
var SplitUrl = false
|
||||
|
||||
type PokeElement struct {
|
||||
Target int64
|
||||
@ -183,13 +187,37 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
|
||||
"data": map[string]string{"file": o.Filename, "url": o.Url},
|
||||
}
|
||||
}
|
||||
case *message.GroupImageElement:
|
||||
if ur {
|
||||
m = MSG{
|
||||
"type": "image",
|
||||
"data": map[string]string{"file": hex.EncodeToString(o.Md5) + ".image"},
|
||||
}
|
||||
} else {
|
||||
m = MSG{
|
||||
"type": "image",
|
||||
"data": map[string]string{"file": hex.EncodeToString(o.Md5) + ".image", "url": CQCodeEscapeText(o.Url)},
|
||||
}
|
||||
}
|
||||
case *message.FriendImageElement:
|
||||
if ur {
|
||||
m = MSG{
|
||||
"type": "image",
|
||||
"data": map[string]string{"file": hex.EncodeToString(o.Md5) + ".image"},
|
||||
}
|
||||
} else {
|
||||
m = MSG{
|
||||
"type": "image",
|
||||
"data": map[string]string{"file": hex.EncodeToString(o.Md5) + ".image", "url": CQCodeEscapeText(o.Url)},
|
||||
}
|
||||
}
|
||||
case *message.GroupFlashImgElement:
|
||||
return []MSG{MSG{
|
||||
return []MSG{{
|
||||
"type": "image",
|
||||
"data": map[string]string{"file": o.Filename, "type": "flash"},
|
||||
}}
|
||||
case *message.FriendFlashImgElement:
|
||||
return []MSG{MSG{
|
||||
return []MSG{{
|
||||
"type": "image",
|
||||
"data": map[string]string{"file": o.Filename, "type": "flash"},
|
||||
}}
|
||||
@ -262,9 +290,17 @@ func ToStringMessage(e []message.IMessageElement, code int64, raw ...bool) (r st
|
||||
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")
|
||||
if ur {
|
||||
r += fmt.Sprintf("[CQ:image,file=%s]", hex.EncodeToString(o.Md5)+".image")
|
||||
} else {
|
||||
r += fmt.Sprintf("[CQ:image,file=%s,url=%s]", hex.EncodeToString(o.Md5)+".image", CQCodeEscapeText(o.Url))
|
||||
}
|
||||
case *message.FriendImageElement:
|
||||
r += fmt.Sprintf("[CQ:image,file=%s]", hex.EncodeToString(o.Md5)+".image")
|
||||
if ur {
|
||||
r += fmt.Sprintf("[CQ:image,file=%s]", hex.EncodeToString(o.Md5)+".image")
|
||||
} else {
|
||||
r += fmt.Sprintf("[CQ:image,file=%s,url=%s]", hex.EncodeToString(o.Md5)+".image", CQCodeEscapeText(o.Url))
|
||||
}
|
||||
case *message.GroupFlashImgElement:
|
||||
return fmt.Sprintf("[CQ:image,type=flash,file=%s]", o.Filename)
|
||||
case *message.FriendFlashImgElement:
|
||||
@ -283,30 +319,74 @@ func ToStringMessage(e []message.IMessageElement, code int64, raw ...bool) (r st
|
||||
return
|
||||
}
|
||||
|
||||
func (bot *CQBot) ConvertStringMessage(m string, group bool) (r []message.IMessageElement) {
|
||||
i := matchReg.FindAllStringSubmatchIndex(m, -1)
|
||||
si := 0
|
||||
for _, idx := range i {
|
||||
if idx[0] > si {
|
||||
text := m[si:idx[0]]
|
||||
r = append(r, message.NewText(CQCodeUnescapeText(text)))
|
||||
func (bot *CQBot) ConvertStringMessage(msg string, group bool) (r []message.IMessageElement) {
|
||||
index := 0
|
||||
stat := 0
|
||||
rMsg := []rune(msg)
|
||||
var tempText, cqCode []rune
|
||||
hasNext := func() bool {
|
||||
return index < len(rMsg)
|
||||
}
|
||||
next := func() rune {
|
||||
r := rMsg[index]
|
||||
index++
|
||||
return r
|
||||
}
|
||||
move := func(steps int) {
|
||||
index += steps
|
||||
}
|
||||
peekN := func(count int) string {
|
||||
lastIdx := int(math.Min(float64(index+count), float64(len(rMsg))))
|
||||
return string(rMsg[index:lastIdx])
|
||||
}
|
||||
isCQCodeBegin := func(r rune) bool {
|
||||
return r == '[' && peekN(3) == "CQ:"
|
||||
}
|
||||
saveTempText := func() {
|
||||
if len(tempText) != 0 {
|
||||
if SplitUrl {
|
||||
for _, t := range global.SplitUrl(CQCodeUnescapeValue(string(tempText))) {
|
||||
r = append(r, message.NewText(t))
|
||||
}
|
||||
} else {
|
||||
r = append(r, message.NewText(CQCodeUnescapeValue(string(tempText))))
|
||||
}
|
||||
}
|
||||
code := m[idx[0]:idx[1]]
|
||||
si = idx[1]
|
||||
t := typeReg.FindAllStringSubmatch(code, -1)[0][1]
|
||||
ps := paramReg.FindAllStringSubmatch(code, -1)
|
||||
d := make(map[string]string)
|
||||
for _, p := range ps {
|
||||
d[p[1]] = CQCodeUnescapeValue(p[2])
|
||||
tempText = []rune{}
|
||||
cqCode = []rune{}
|
||||
}
|
||||
saveCQCode := func() {
|
||||
defer func() {
|
||||
cqCode = []rune{}
|
||||
tempText = []rune{}
|
||||
}()
|
||||
s := strings.SplitN(string(cqCode), ",", -1)
|
||||
if len(s) == 0 {
|
||||
return
|
||||
}
|
||||
if t == "reply" {
|
||||
t := s[0]
|
||||
params := make(map[string]string)
|
||||
for i := 1; i < len(s); i++ {
|
||||
p := s[i]
|
||||
p = strings.TrimSpace(p)
|
||||
if p == "" {
|
||||
continue
|
||||
}
|
||||
data := strings.SplitN(p, "=", 2)
|
||||
if len(data) == 2 {
|
||||
params[data[0]] = CQCodeUnescapeValue(data[1])
|
||||
} else {
|
||||
params[p] = ""
|
||||
}
|
||||
}
|
||||
if t == "reply" { // reply 特殊处理
|
||||
if len(r) > 0 {
|
||||
if _, ok := r[0].(*message.ReplyElement); ok {
|
||||
log.Warnf("警告: 一条信息只能包含一个 Reply 元素.")
|
||||
continue
|
||||
return
|
||||
}
|
||||
}
|
||||
mid, err := strconv.Atoi(d["id"])
|
||||
mid, err := strconv.Atoi(params["id"])
|
||||
if err == nil {
|
||||
org := bot.GetMessage(int32(mid))
|
||||
if org != nil {
|
||||
@ -318,19 +398,20 @@ func (bot *CQBot) ConvertStringMessage(m string, group bool) (r []message.IMessa
|
||||
Elements: bot.ConvertStringMessage(org["message"].(string), group),
|
||||
},
|
||||
}, r...)
|
||||
continue
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
elem, err := bot.ToElement(t, d, group)
|
||||
elem, err := bot.ToElement(t, params, group)
|
||||
if err != nil {
|
||||
org := "[" + string(cqCode) + "]"
|
||||
if !IgnoreInvalidCQCode {
|
||||
log.Warnf("转换CQ码 %v 到MiraiGo Element时出现错误: %v 将原样发送.", code, err)
|
||||
r = append(r, message.NewText(code))
|
||||
log.Warnf("转换CQ码 %v 时出现错误: %v 将原样发送.", org, err)
|
||||
r = append(r, message.NewText(org))
|
||||
} else {
|
||||
log.Warnf("转换CQ码 %v 到MiraiGo Element时出现错误: %v 将忽略.", code, err)
|
||||
log.Warnf("转换CQ码 %v 时出现错误: %v 将忽略.", org, err)
|
||||
}
|
||||
continue
|
||||
return
|
||||
}
|
||||
switch i := elem.(type) {
|
||||
case message.IMessageElement:
|
||||
@ -339,9 +420,32 @@ func (bot *CQBot) ConvertStringMessage(m string, group bool) (r []message.IMessa
|
||||
r = append(r, i...)
|
||||
}
|
||||
}
|
||||
if si != len(m) {
|
||||
r = append(r, message.NewText(CQCodeUnescapeText(m[si:])))
|
||||
for hasNext() {
|
||||
ch := next()
|
||||
switch stat {
|
||||
case 0:
|
||||
if isCQCodeBegin(ch) {
|
||||
saveTempText()
|
||||
tempText = append(tempText, []rune("[CQ:")...)
|
||||
move(3)
|
||||
stat = 1
|
||||
} else {
|
||||
tempText = append(tempText, ch)
|
||||
}
|
||||
case 1:
|
||||
if isCQCodeBegin(ch) {
|
||||
move(-1)
|
||||
stat = 0
|
||||
} else if ch == ']' {
|
||||
saveCQCode()
|
||||
stat = 0
|
||||
} else {
|
||||
cqCode = append(cqCode, ch)
|
||||
tempText = append(tempText, ch)
|
||||
}
|
||||
}
|
||||
}
|
||||
saveTempText()
|
||||
return
|
||||
}
|
||||
|
||||
@ -409,6 +513,13 @@ func (bot *CQBot) ConvertObjectMessage(m gjson.Result, group bool) (r []message.
|
||||
func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interface{}, err error) {
|
||||
switch t {
|
||||
case "text":
|
||||
if SplitUrl {
|
||||
var ret []message.IMessageElement
|
||||
for _, text := range global.SplitUrl(d["text"]) {
|
||||
ret = append(ret, message.NewText(text))
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
return message.NewText(d["text"]), nil
|
||||
case "image":
|
||||
img, err := bot.makeImageElem(d, group)
|
||||
@ -477,6 +588,9 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
|
||||
case "record":
|
||||
f := d["file"]
|
||||
data, err := global.FindFile(f, d["cache"], global.VOICE_PATH)
|
||||
if err == global.ErrSyntax {
|
||||
data, err = global.FindFile(f, d["cache"], global.VOICE_PATH_OLD)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -598,14 +712,12 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
|
||||
case "xml":
|
||||
resId := d["resid"]
|
||||
template := CQCodeEscapeValue(d["data"])
|
||||
//println(template)
|
||||
i, _ := strconv.ParseInt(resId, 10, 64)
|
||||
msg := message.NewRichXml(template, i)
|
||||
return msg, nil
|
||||
case "json":
|
||||
resId := d["resid"]
|
||||
i, _ := strconv.ParseInt(resId, 10, 64)
|
||||
log.Warnf("json msg=%s", d["data"])
|
||||
if i == 0 {
|
||||
//默认情况下走小程序通道
|
||||
msg := message.NewLightApp(CQCodeUnescapeValue(d["data"]))
|
||||
@ -723,6 +835,9 @@ func (bot *CQBot) makeImageElem(d map[string]string, group bool) (message.IMessa
|
||||
return message.NewImage(b), nil
|
||||
}
|
||||
rawPath := path.Join(global.IMAGE_PATH, f)
|
||||
if !global.PathExists(rawPath) && global.PathExists(path.Join(global.IMAGE_PATH_OLD, f)) {
|
||||
rawPath = path.Join(global.IMAGE_PATH_OLD, f)
|
||||
}
|
||||
if !global.PathExists(rawPath) && global.PathExists(rawPath+".cqimg") {
|
||||
rawPath += ".cqimg"
|
||||
}
|
||||
@ -771,7 +886,7 @@ func (bot *CQBot) makeImageElem(d map[string]string, group bool) (message.IMessa
|
||||
return nil, errors.New("invalid hash")
|
||||
}
|
||||
if group {
|
||||
rsp, err := bot.Client.QueryGroupImage(1, hash, size)
|
||||
rsp, err := bot.Client.QueryGroupImage(int64(rand.Uint32()), hash, size)
|
||||
if err != nil {
|
||||
if url != "" {
|
||||
return bot.makeImageElem(map[string]string{"file": url}, group)
|
||||
@ -780,7 +895,7 @@ func (bot *CQBot) makeImageElem(d map[string]string, group bool) (message.IMessa
|
||||
}
|
||||
return rsp, nil
|
||||
}
|
||||
rsp, err := bot.Client.QueryFriendImage(1, hash, size)
|
||||
rsp, err := bot.Client.QueryFriendImage(int64(rand.Uint32()), hash, size)
|
||||
if err != nil {
|
||||
if url != "" {
|
||||
return bot.makeImageElem(map[string]string{"file": url}, group)
|
||||
|
@ -114,9 +114,9 @@ func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage)
|
||||
}
|
||||
if m.Sender.IsAnonymous() {
|
||||
gm["anonymous"] = MSG{
|
||||
"flag": "",
|
||||
"id": 0,
|
||||
"name": m.Sender.Nickname,
|
||||
"flag": m.Sender.AnonymousInfo.AnonymousId + "|" + m.Sender.AnonymousInfo.AnonymousNick,
|
||||
"id": m.Sender.Uin,
|
||||
"name": m.Sender.AnonymousInfo.AnonymousNick,
|
||||
}
|
||||
gm["sender"].(MSG)["nickname"] = "匿名消息"
|
||||
gm["sub_type"] = "anonymous"
|
||||
|
@ -1,12 +1,22 @@
|
||||
# 事件过滤器
|
||||
|
||||
在go-cqhttp同级目录下新建`filter.json`文件即可开启事件过滤器,启动时会读取该文件中定义的过滤规则(使用 JSON 编写),若文件不存在,或过滤规则语法错误,则会暂停所有上报。
|
||||
在go-cqhttp同级目录下新建`filter.json`文件即可开启事件过滤器,启动时会读取该文件中定义的过滤规则(使用 JSON 编写),若文件不存在,或过滤规则语法错误,则不会启用事件过滤器。
|
||||
事件过滤器会处理所有事件(包括心跳事件在内的元事件),请谨慎使用!!
|
||||
|
||||
注意: 与客户端建立连接的握手事件**不会**经过事件过滤器
|
||||
|
||||
## 示例
|
||||
|
||||
这节首先给出一些示例,演示过滤器的基本用法,下一节将给出具体语法说明。
|
||||
|
||||
### 过滤所有事件
|
||||
|
||||
```json
|
||||
{
|
||||
".not": {}
|
||||
}
|
||||
```
|
||||
|
||||
### 只上报以「!!」开头的消息
|
||||
|
||||
```json
|
||||
@ -128,5 +138,5 @@
|
||||
|
||||
这里有几点需要注意:
|
||||
|
||||
- `message` 字段在运行过滤器时是消息段数组的形式(见 [消息格式]( https://github.com/howmanybots/onebot/blob/master/v11/specs/message/array.md ))
|
||||
- `message` 字段在运行过滤器时和上报信息类型相同(见 [消息格式]( https://github.com/howmanybots/onebot/blob/master/v11/specs/message/array.md ))
|
||||
- `raw_message` 字段为未经**CQ码**处理的原始消息字符串,这意味着其中可能会出现形如 `[CQ:face,id=123]` 的 CQ 码
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| ------------ | ------ | --------------------------- |
|
||||
| access_token | string | 校验口令,config.json中配置 |
|
||||
| access_token | string | 校验口令,config.hjson中配置 |
|
||||
|
||||
|
||||
|
||||
@ -209,7 +209,7 @@ method: `POST` formdata
|
||||
|
||||
### admin/do_config_json
|
||||
|
||||
> 直接修改 config.json配置
|
||||
> 直接修改 config.hjson配置
|
||||
|
||||
method: `POST` formdata
|
||||
|
||||
@ -217,7 +217,7 @@ method: `POST` formdata
|
||||
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| ------ | ------ | ----------------------------------- |
|
||||
| json | string | 完整的config.json的配合,json字符串 |
|
||||
| json | string | 完整的config.hjson的配合,json字符串 |
|
||||
|
||||
|
||||
返回:
|
||||
@ -228,7 +228,7 @@ method: `POST` formdata
|
||||
|
||||
### admin/get_config_json
|
||||
|
||||
> 获取当前 config.json配置
|
||||
> 获取当前 config.hjson配置
|
||||
|
||||
method: `GET`
|
||||
|
||||
@ -247,5 +247,5 @@ method: `GET`
|
||||
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| ------ | ------ | ----------------------------------- |
|
||||
| config | string | 完整的config.json的配合,json字符串 |
|
||||
| config | string | 完整的config.hjson的配合,json字符串 |
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
# 配置
|
||||
|
||||
go-cqhttp 包含 `config.json` 和 `device.json` 两个配置文件, 其中 `config.json` 为运行配置 `device.json` 为虚拟设备信息.
|
||||
go-cqhttp 包含 `config.hjson` 和 `device.json` 两个配置文件, 其中 `config.json` 为运行配置 `device.json` 为虚拟设备信息.
|
||||
|
||||
## 从原CQHTTP导入配置
|
||||
|
||||
@ -78,6 +78,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
|
||||
| post_message_format | string | 上报信息类型 |
|
||||
| ignore_invalid_cqcode | bool | 是否忽略错误的CQ码 |
|
||||
| force_fragmented | bool | 是否强制分片发送群长消息 |
|
||||
| fix_url | bool | 是否对链接的发送进行预处理, 可缓解链接信息被风控导致无法发送的情况, 但可能影响客户端着色(不影响内容)|
|
||||
| use_sso_address | bool | 是否使用服务器下发的地址 |
|
||||
| heartbeat_interval | int64 | 心跳间隔时间,单位秒。小于0则关闭心跳,等于0使用默认值(5秒) |
|
||||
| http_config | object | HTTP API配置 |
|
||||
@ -112,10 +113,10 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
|
||||
|
||||
| 值 | 类型 | 限制 |
|
||||
| --- | ------------- | ---------------------------------------------------------------- |
|
||||
| 0 | iPad | 无 |
|
||||
| 1 | Android Phone | 无法接收新版表情如 `/吃瓜 /汪汪`, 会自动转换为字符串 |
|
||||
| 2 | Android Watch | 除`Android Phone`的限制外, 无法接收 `notify` 事件、无法接收口令红包、无法接收撤回消息 |
|
||||
| 3 | MacOS | 无 |
|
||||
| 0 | iPad | 无 |
|
||||
| 1 | Android Phone | 无 |
|
||||
| 2 | Android Watch | 无法接收 `notify` 事件、无法接收口令红包、无法接收撤回消息 |
|
||||
| 3 | MacOS | 无 |
|
||||
|
||||
> 注意, 根据协议的不同, 各类消息有所限制
|
||||
|
||||
|
411
docs/cqhttp.md
411
docs/cqhttp.md
@ -2,10 +2,65 @@
|
||||
|
||||
由于部分 api 原版 CQHTTP 并未实现,go-cqhttp 修改并增加了一些拓展 api .
|
||||
|
||||
<details>
|
||||
<summary>目录</summary>
|
||||
<p>
|
||||
|
||||
##### CQCode
|
||||
- [图片](#图片)
|
||||
- [回复](#回复)
|
||||
- [红包](#红包)
|
||||
- [戳一戳](#戳一戳)
|
||||
- [礼物](#礼物)
|
||||
- [合并转发](#合并转发)
|
||||
- [合并转发消息节点](#合并转发消息节点)
|
||||
- [XML 消息](#xml-消息)
|
||||
- [JSON 消息](#json-消息)
|
||||
- [cardimage](#cardimage)
|
||||
- [文本转语音](#文本转语音)
|
||||
- [图片](#图片)
|
||||
|
||||
##### API
|
||||
- [设置群名](#设置群名)
|
||||
- [设置群头像](#设置群头像)
|
||||
- [获取图片信息](#获取图片信息)
|
||||
- [获取消息](#获取消息)
|
||||
- [获取合并转发内容](#获取合并转发内容)
|
||||
- [发送合并转发(群)](#发送合并转发(群))
|
||||
- [获取中文分词](#获取中文分词)
|
||||
- [图片OCR](#图片OCR)
|
||||
- [获取中文分词](#获取中文分词)
|
||||
- [获取群系统消息](#获取群文件系统信息)
|
||||
- [获取群文件系统信息](#获取群文件系统信息)
|
||||
- [获取群根目录文件列表](#获取群根目录文件列表)
|
||||
- [获取群子目录文件列表](#获取群子目录文件列表)
|
||||
- [获取群文件资源链接](#获取群文件资源链接)
|
||||
- [获取状态](#获取状态)
|
||||
- [获取群子目录文件列表](#设置群名)
|
||||
|
||||
##### 事件
|
||||
- [群消息撤回](#群消息撤回)
|
||||
- [好友消息撤回](#好友消息撤回)
|
||||
- [好友戳一戳](#好友戳一戳)
|
||||
- [群内戳一戳](#群内戳一戳)
|
||||
- [群红包运气王提示](#群红包运气王提示)
|
||||
- [群成员荣誉变更提示](#群成员荣誉变更提示)
|
||||
- [群成员名片更新](#群成员名片更新)
|
||||
- [接收到离线文件](#接收到离线文件)
|
||||
|
||||
</p>
|
||||
</details>
|
||||
|
||||
## CQCode
|
||||
|
||||
### 图片
|
||||
|
||||
Type : `image`
|
||||
|
||||
范围: **发送/接收**
|
||||
|
||||
参数:
|
||||
|
||||
| 参数名 | 可能的值 | 说明 |
|
||||
| ------- | --------------- | --------------------------------------------------------------- |
|
||||
| `file` | - | 图片文件名 |
|
||||
@ -25,6 +80,9 @@
|
||||
| 40004 | 爱你 |
|
||||
| 40005 | 征友 |
|
||||
|
||||
示例: `[CQ:image,file=http://baidu.com/1.jpg,type=show,id=40004]`
|
||||
|
||||
> 注意:图片总大小不能超过30MB,gif总帧数不能超过300帧
|
||||
|
||||
### 回复
|
||||
|
||||
@ -36,7 +94,7 @@ Type : `reply`
|
||||
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| ------ | ---- | ------------------------------------- |
|
||||
| id | int | 回复时所引用的消息id, 必须为本群消息. |
|
||||
| `id` | int | 回复时所引用的消息id, 必须为本群消息. |
|
||||
|
||||
示例: `[CQ:reply,id=123456]`
|
||||
|
||||
@ -48,9 +106,9 @@ Type: `redbag`
|
||||
|
||||
参数:
|
||||
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| ------ | ------ | ----------- |
|
||||
| title | string | 祝福语/口令 |
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| ------- | ------ | ----------- |
|
||||
| `title` | string | 祝福语/口令 |
|
||||
|
||||
示例: `[CQ:redbag,title=恭喜发财]`
|
||||
|
||||
@ -66,7 +124,7 @@ Type: `poke`
|
||||
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| ------ | ----- | ------------ |
|
||||
| qq | int64 | 需要戳的成员 |
|
||||
| `qq` | int64 | 需要戳的成员 |
|
||||
|
||||
示例: `[CQ:poke,qq=123456]`
|
||||
|
||||
@ -82,8 +140,8 @@ Type: `gift`
|
||||
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| ------ | ----- | -------------- |
|
||||
| qq | int64 | 接收礼物的成员 |
|
||||
| id | int | 礼物的类型 |
|
||||
| `qq` | int64 | 接收礼物的成员 |
|
||||
| `id` | int | 礼物的类型 |
|
||||
|
||||
目前支持的礼物ID:
|
||||
|
||||
@ -116,9 +174,9 @@ Type: `forward`
|
||||
|
||||
参数:
|
||||
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| ------ | ------ | ------------------------------------------------------------- |
|
||||
| id | string | 合并转发ID, 需要通过 `/get_forward_msg` API获取转发的具体内容 |
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| ------ | ------ | ------------------------------------------------------------ |
|
||||
| `id` | string | 合并转发ID, 需要通过 `/get_forward_msg` API获取转发的具体内容 |
|
||||
|
||||
示例: `[CQ:forward,id=xxxx]`
|
||||
|
||||
@ -130,12 +188,12 @@ Type: `node`
|
||||
|
||||
参数:
|
||||
|
||||
| 参数名 | 类型 | 说明 | 特殊说明 |
|
||||
| ------- | ------- | -------------- | -------------------------------------------------------------------------------------- |
|
||||
| id | int32 | 转发消息id | 直接引用他人的消息合并转发, 实际查看顺序为原消息发送顺序 **与下面的自定义消息二选一** |
|
||||
| name | string | 发送者显示名字 | 用于自定义消息 (自定义消息并合并转发,实际查看顺序为自定义消息段顺序) |
|
||||
| uin | int64 | 发送者QQ号 | 用于自定义消息 |
|
||||
| content | message | 具体消息 | 用于自定义消息 **不支持转发套娃,不支持引用回复** |
|
||||
| 参数名 | 类型 | 说明 | 特殊说明 |
|
||||
| --------- | ------- | -------------- | ------------------------------------------------------------ |
|
||||
| `id` | int32 | 转发消息id | 直接引用他人的消息合并转发, 实际查看顺序为原消息发送顺序 **与下面的自定义消息二选一** |
|
||||
| `name` | string | 发送者显示名字 | 用于自定义消息 (自定义消息并合并转发,实际查看顺序为自定义消息段顺序) |
|
||||
| `uin` | int64 | 发送者QQ号 | 用于自定义消息 |
|
||||
| `content` | message | 具体消息 | 用于自定义消息 **不支持引用回复** |
|
||||
|
||||
特殊说明: **需要使用单独的API `/send_group_forward_msg` 发送,并且由于消息段较为复杂,仅支持Array形式入参。 如果引用消息和自定义消息同时出现,实际查看顺序将取消息段顺序. 另外按 [CQHTTP](https://cqhttp.cc/docs/4.15/#/Message?id=格式) 文档说明, `data` 应全为字符串, 但由于需要接收`message` 类型的消息, 所以 *仅限此Type的content字段* 支持Array套娃**
|
||||
|
||||
@ -209,7 +267,7 @@ Type: `node`
|
||||
]
|
||||
````
|
||||
|
||||
### xml支持
|
||||
### XML 消息
|
||||
|
||||
Type: `xml`
|
||||
|
||||
@ -217,10 +275,10 @@ Type: `xml`
|
||||
|
||||
参数:
|
||||
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| ------ | ------ | ----------------------------------------- |
|
||||
| data | string | xml内容,xml中的value部分,记得实体化处理 |
|
||||
| resid | int32 | 可以不填 |
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| ------- | ------ | ----------------------------------------- |
|
||||
| `data` | string | xml内容,xml中的value部分,记得实体化处理 |
|
||||
| `resid` | int32 | 可以不填 |
|
||||
|
||||
示例: `[CQ:xml,data=xxxx]`
|
||||
|
||||
@ -258,7 +316,7 @@ Type: `xml`
|
||||
</msg>
|
||||
```
|
||||
|
||||
### json消息支持
|
||||
### JSON 消息
|
||||
|
||||
Type: `json`
|
||||
|
||||
@ -266,20 +324,20 @@ Type: `json`
|
||||
|
||||
参数:
|
||||
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| ------ | ------ | ----------------------------------------------- |
|
||||
| data | string | json内容,json的所有字符串记得实体化处理 |
|
||||
| resid | int32 | 默认不填为0,走小程序通道,填了走富文本通道发送 |
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| ------- | ------ | ----------------------------------------------- |
|
||||
| `data` | string | json内容,json的所有字符串记得实体化处理 |
|
||||
| `resid` | int32 | 默认不填为0,走小程序通道,填了走富文本通道发送 |
|
||||
|
||||
json中的字符串需要进行转义:
|
||||
|
||||
>","=>`,`、
|
||||
>","=> `,`
|
||||
|
||||
>"&"=> `&`、
|
||||
>"&"=> `&`
|
||||
|
||||
>"["=>`[`、
|
||||
>"["=> `[`
|
||||
|
||||
>"]"=>`]`、
|
||||
>"]"=> `]`
|
||||
|
||||
否则无法正确得到解析
|
||||
|
||||
@ -289,7 +347,8 @@ json中的字符串需要进行转义:
|
||||
```
|
||||
|
||||
|
||||
### cardimage 一种xml的图片消息(装逼大图)
|
||||
### cardimage
|
||||
一种xml的图片消息(装逼大图)
|
||||
|
||||
ps: xml 接口的消息都存在风控风险,请自行兼容发送失败后的处理(可以失败后走普通图片模式)
|
||||
|
||||
@ -299,15 +358,15 @@ Type: `cardimage`
|
||||
|
||||
参数:
|
||||
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| --------- | ------ | ------------------------------------- |
|
||||
| file | string | 和image的file字段对齐,支持也是一样的 |
|
||||
| minwidth | int64 | 默认不填为400,最小width |
|
||||
| minheight | int64 | 默认不填为400,最小height |
|
||||
| maxwidth | int64 | 默认不填为500,最大width |
|
||||
| maxheight | int64 | 默认不填为1000,最大height |
|
||||
| source | string | 分享来源的名称,可以留空 |
|
||||
| icon | string | 分享来源的icon图标url,可以留空 |
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| ----------- | ------ | ------------------------------------- |
|
||||
| `file` | string | 和image的file字段对齐,支持也是一样的 |
|
||||
| `minwidth` | int64 | 默认不填为400,最小width |
|
||||
| `minheight` | int64 | 默认不填为400,最小height |
|
||||
| `maxwidth` | int64 | 默认不填为500,最大width |
|
||||
| `maxheight` | int64 | 默认不填为1000,最大height |
|
||||
| `source` | string | 分享来源的名称,可以留空 |
|
||||
| `icon` | string | 分享来源的icon图标url,可以留空 |
|
||||
|
||||
|
||||
示例cardimage 的cq码:
|
||||
@ -327,7 +386,7 @@ Type: `tts`
|
||||
|
||||
| 参数名 | 类型 | 说明 |
|
||||
| ------ | ------ | ---- |
|
||||
| text | string | 内容 |
|
||||
| `text` | string | 内容 |
|
||||
|
||||
示例: `[CQ:tts,text=这是一条测试消息]`
|
||||
|
||||
@ -339,10 +398,10 @@ Type: `tts`
|
||||
|
||||
**参数**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ---------- | ------ | ---- |
|
||||
| group_id | int64 | 群号 |
|
||||
| group_name | string | 新名 |
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ------------ | ------ | ---- |
|
||||
| `group_id` | int64 | 群号 |
|
||||
| `group_name` | string | 新名 |
|
||||
|
||||
### 设置群头像
|
||||
|
||||
@ -350,11 +409,11 @@ Type: `tts`
|
||||
|
||||
**参数**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| -------- | ------ | ------------------------ |
|
||||
| group_id | int64 | 群号 |
|
||||
| file | string | 图片文件名 |
|
||||
| cache | int | 表示是否使用已缓存的文件 |
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ---------- | ------ | ------------------------ |
|
||||
| `group_id` | int64 | 群号 |
|
||||
| `file` | string | 图片文件名 |
|
||||
| `cache` | int | 表示是否使用已缓存的文件 |
|
||||
|
||||
[1]`file` 参数支持以下几种格式:
|
||||
|
||||
@ -486,24 +545,24 @@ Type: `tts`
|
||||
|
||||
**参数**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ------- | ------ | ------ |
|
||||
| `image` | string | 图片ID |
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ------- | ------ | ------ |
|
||||
| `image` | string | 图片ID |
|
||||
|
||||
**响应数据**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ---------- | --------------- | ------- |
|
||||
| `texts` | TextDetection[] | OCR结果 |
|
||||
| `language` | string | 语言 |
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ---------- | --------------- | ------- |
|
||||
| `texts` | TextDetection[] | OCR结果 |
|
||||
| `language` | string | 语言 |
|
||||
|
||||
**TextDetection**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ------------- | ------- | ------ |
|
||||
| `text` | string | 文本 |
|
||||
| `confidence` | int32 | 置信度 |
|
||||
| `coordinates` | vector2 | 坐标 |
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ------------- | ------- | ------ |
|
||||
| `text` | string | 文本 |
|
||||
| `confidence` | int32 | 置信度 |
|
||||
| `coordinates` | vector2 | 坐标 |
|
||||
|
||||
|
||||
### 获取群系统消息
|
||||
@ -512,37 +571,37 @@ Type: `tts`
|
||||
|
||||
**响应数据**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ------------------ | ---------------- | ------------ |
|
||||
| `invited_requests` | InvitedRequest[] | 邀请消息列表 |
|
||||
| `join_requests` | JoinRequest[] | 进群消息列表 |
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ------------------ | ---------------- | ------------ |
|
||||
| `invited_requests` | InvitedRequest[] | 邀请消息列表 |
|
||||
| `join_requests` | JoinRequest[] | 进群消息列表 |
|
||||
|
||||
> 注意: 如果列表不存在任何消息, 将返回 `null`
|
||||
|
||||
**InvitedRequest**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| -------------- | ------ | ----------------- |
|
||||
| `request_id` | int64 | 请求ID |
|
||||
| `invitor_uin` | int64 | 邀请者 |
|
||||
| `invitor_nick` | string | 邀请者昵称 |
|
||||
| `group_id` | int64 | 群号 |
|
||||
| `group_name` | string | 群名 |
|
||||
| `checked` | bool | 是否已被处理 |
|
||||
| `actor` | int64 | 处理者, 未处理为0 |
|
||||
| 字段 | 类型 | 说明 |
|
||||
| -------------- | ------ | ----------------- |
|
||||
| `request_id` | int64 | 请求ID |
|
||||
| `invitor_uin` | int64 | 邀请者 |
|
||||
| `invitor_nick` | string | 邀请者昵称 |
|
||||
| `group_id` | int64 | 群号 |
|
||||
| `group_name` | string | 群名 |
|
||||
| `checked` | bool | 是否已被处理 |
|
||||
| `actor` | int64 | 处理者, 未处理为0 |
|
||||
|
||||
**JoinRequest**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ---------------- | ------ | ----------------- |
|
||||
| `request_id` | int64 | 请求ID |
|
||||
| `requester_uin` | int64 | 请求者ID |
|
||||
| `requester_nick` | string | 请求者昵称 |
|
||||
| `message` | string | 验证消息 |
|
||||
| `group_id` | int64 | 群号 |
|
||||
| `group_name` | string | 群名 |
|
||||
| `checked` | bool | 是否已被处理 |
|
||||
| `actor` | int64 | 处理者, 未处理为0 |
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ---------------- | ------ | ----------------- |
|
||||
| `request_id` | int64 | 请求ID |
|
||||
| `requester_uin` | int64 | 请求者ID |
|
||||
| `requester_nick` | string | 请求者昵称 |
|
||||
| `message` | string | 验证消息 |
|
||||
| `group_id` | int64 | 群号 |
|
||||
| `group_name` | string | 群名 |
|
||||
| `checked` | bool | 是否已被处理 |
|
||||
| `actor` | int64 | 处理者, 未处理为0 |
|
||||
|
||||
### 获取群文件系统信息
|
||||
|
||||
@ -550,18 +609,18 @@ Type: `tts`
|
||||
|
||||
**参数**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ---------- | ----- | ---- |
|
||||
| `group_id` | int64 | 群号 |
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ---------- | ----- | ---- |
|
||||
| `group_id` | int64 | 群号 |
|
||||
|
||||
**响应数据**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ------------- | ----- | ---------- |
|
||||
| `file_count` | int32 | 文件总数 |
|
||||
| `limit_count` | int32 | 文件上限 |
|
||||
| `used_space` | int64 | 已使用空间 |
|
||||
| `total_space` | int64 | 空间上限 |
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ------------- | ----- | ---------- |
|
||||
| `file_count` | int32 | 文件总数 |
|
||||
| `limit_count` | int32 | 文件上限 |
|
||||
| `used_space` | int64 | 已使用空间 |
|
||||
| `total_space` | int64 | 空间上限 |
|
||||
|
||||
### 获取群根目录文件列表
|
||||
|
||||
@ -571,16 +630,16 @@ Type: `tts`
|
||||
|
||||
**参数**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ---------- | ----- | ---- |
|
||||
| `group_id` | int64 | 群号 |
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ---------- | ----- | ---- |
|
||||
| `group_id` | int64 | 群号 |
|
||||
|
||||
**响应数据**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| --------- | -------- | ---------- |
|
||||
| `files` | File[] | 文件列表 |
|
||||
| `folders` | Folder[] | 文件夹列表 |
|
||||
| 字段 | 类型 | 说明 |
|
||||
| --------- | -------- | ---------- |
|
||||
| `files` | File[] | 文件列表 |
|
||||
| `folders` | Folder[] | 文件夹列表 |
|
||||
|
||||
### 获取群子目录文件列表
|
||||
|
||||
@ -590,17 +649,17 @@ Type: `tts`
|
||||
|
||||
**参数**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ----------- | ------ | --------------------------- |
|
||||
| `group_id` | int64 | 群号 |
|
||||
| `folder_id` | string | 文件夹ID 参考 `Folder` 对象 |
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ----------- | ------ | --------------------------- |
|
||||
| `group_id` | int64 | 群号 |
|
||||
| `folder_id` | string | 文件夹ID 参考 `Folder` 对象 |
|
||||
|
||||
**响应数据**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| --------- | -------- | ---------- |
|
||||
| `files` | File[] | 文件列表 |
|
||||
| `folders` | Folder[] | 文件夹列表 |
|
||||
| 字段 | 类型 | 说明 |
|
||||
| --------- | -------- | ---------- |
|
||||
| `files` | File[] | 文件列表 |
|
||||
| `folders` | Folder[] | 文件夹列表 |
|
||||
|
||||
### 获取群文件资源链接
|
||||
|
||||
@ -610,47 +669,96 @@ Type: `tts`
|
||||
|
||||
**参数**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ---------- | ------ | ------------------------- |
|
||||
| `group_id` | int64 | 群号 |
|
||||
| `file_id` | string | 文件ID 参考 `File` 对象 |
|
||||
| `busid` | int32 | 文件类型 参考 `File` 对象 |
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ---------- | ------ | ------------------------- |
|
||||
| `group_id` | int64 | 群号 |
|
||||
| `file_id` | string | 文件ID 参考 `File` 对象 |
|
||||
| `busid` | int32 | 文件类型 参考 `File` 对象 |
|
||||
|
||||
**响应数据**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ----- | ------ | ------------ |
|
||||
| `url` | string | 文件下载链接 |
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ----- | ------ | ------------ |
|
||||
| `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 | 上传者名字 |
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ---------------- | ------ | ---------------------- |
|
||||
| `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 | 子文件数量 |
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ------------------ | ------ | ---------- |
|
||||
| `folder_id` | string | 文件夹ID |
|
||||
| `folder_name` | string | 文件名 |
|
||||
| `create_time` | int64 | 创建时间 |
|
||||
| `creator` | int64 | 创建者 |
|
||||
| `creator_name` | string | 创建者名字 |
|
||||
| `total_file_count` | int32 | 子文件数量 |
|
||||
|
||||
### 获取状态
|
||||
|
||||
终结点: `/get_status`
|
||||
|
||||
**响应数据**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ----------------- | ---------- | ------------------------------- |
|
||||
| `app_initialized` | bool | 原 `CQHTTP` 字段, 恒定为 `true` |
|
||||
| `app_enabled` | bool | 原 `CQHTTP` 字段, 恒定为 `true` |
|
||||
| `plugins_good` | bool | 原 `CQHTTP` 字段, 恒定为 `true` |
|
||||
| `app_good` | bool | 原 `CQHTTP` 字段, 恒定为 `true` |
|
||||
| `online` | bool | 表示BOT是否在线 |
|
||||
| `goold` | bool | 同 `online` |
|
||||
| `stat` | Statistics | 运行统计 |
|
||||
|
||||
**Statistics**
|
||||
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ------------------ | ------ | ---------------- |
|
||||
| `packet_received` | uint64 | 收到的数据包总数 |
|
||||
| `packet_sent` | uint64 | 发送的数据包总数 |
|
||||
| `packet_lost` | uint32 | 数据包丢失总数 |
|
||||
| `message_received` | uint64 | 接受信息总数 |
|
||||
| `message_sent` | uint64 | 发送信息总数 |
|
||||
| `disconnect_times` | uint32 | TCP链接断开次数 |
|
||||
| `lost_times` | uint32 | 账号掉线次数 |
|
||||
|
||||
> 注意: 所有统计信息都将在重启后重制
|
||||
|
||||
### 获取群@全体成员剩余次数
|
||||
|
||||
终结点: `/get_group_at_all_remain`
|
||||
|
||||
**参数**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ---------- | ------ | ------------------------- |
|
||||
| `group_id` | int64 | 群号 |
|
||||
|
||||
**响应数据**
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| ------------------------------- | ---------- | ------------------------------- |
|
||||
| `can_at_all` | bool | 是否可以@全体成员 |
|
||||
| `remain_at_all_count_for_group` | int16 | 群内所有管理当天剩余@全体成员次数 |
|
||||
| `remain_at_all_count_for_uin` | int16 | BOT当天剩余@全体成员次数 |
|
||||
|
||||
## 事件
|
||||
|
||||
#### 群消息撤回
|
||||
### 群消息撤回
|
||||
|
||||
**上报数据**
|
||||
|
||||
@ -663,7 +771,7 @@ Type: `tts`
|
||||
| `operator_id` | int64 | | 操作者id |
|
||||
| `message_id` | int64 | | 被撤回的消息id |
|
||||
|
||||
#### 好友消息撤回
|
||||
### 好友消息撤回
|
||||
|
||||
**上报数据**
|
||||
|
||||
@ -674,7 +782,22 @@ Type: `tts`
|
||||
| `user_id` | int64 | | 好友id |
|
||||
| `message_id` | int64 | | 被撤回的消息id |
|
||||
|
||||
#### 群内戳一戳
|
||||
## 好友戳一戳
|
||||
|
||||
**事件数据**
|
||||
|
||||
| 字段名 | 数据类型 | 可能的值 | 说明 |
|
||||
| ------------- | ------ | -------- | --- |
|
||||
| `post_type` | string | `notice` | 上报类型 |
|
||||
| `notice_type` | string | `notify` | 消息类型 |
|
||||
| `sub_type` | string | `poke` | 提示类型 |
|
||||
| `self_id` | int64 | | BOT QQ 号 |
|
||||
| `sender_id` | int64 | | 发送者 QQ 号 |
|
||||
| `user_id` | int64 | | 发送者 QQ 号 |
|
||||
| `target_id` | int64 | | 被戳者 QQ 号 |
|
||||
| `time` | int64 | | 时间 |
|
||||
|
||||
### 群内戳一戳
|
||||
|
||||
> 注意:此事件无法在平板和手表协议上触发
|
||||
|
||||
@ -689,7 +812,7 @@ Type: `tts`
|
||||
| `user_id` | int64 | | 发送者id |
|
||||
| `target_id` | int64 | | 被戳者id |
|
||||
|
||||
#### 群红包运气王提示
|
||||
### 群红包运气王提示
|
||||
|
||||
> 注意:此事件无法在平板和手表协议上触发
|
||||
|
||||
@ -704,7 +827,7 @@ Type: `tts`
|
||||
| `user_id` | int64 | | 红包发送者id |
|
||||
| `target_id` | int64 | | 运气王id |
|
||||
|
||||
#### 群成员荣誉变更提示
|
||||
### 群成员荣誉变更提示
|
||||
|
||||
> 注意:此事件无法在平板和手表协议上触发
|
||||
|
||||
@ -719,7 +842,7 @@ Type: `tts`
|
||||
| `user_id` | int64 | | 成员id |
|
||||
| `honor_type` | string | `talkative:龙王` `performer:群聊之火` `emotion:快乐源泉` | 荣誉类型 |
|
||||
|
||||
#### 群成员名片更新
|
||||
### 群成员名片更新
|
||||
|
||||
> 注意: 此事件不保证时效性,仅在收到消息时校验卡片
|
||||
|
||||
@ -736,7 +859,7 @@ Type: `tts`
|
||||
|
||||
> PS: 当名片为空时 `card_xx` 字段为空字符串, 并不是昵称
|
||||
|
||||
#### 接收到离线文件
|
||||
### 接收到离线文件
|
||||
|
||||
**上报数据**
|
||||
|
||||
|
@ -5,7 +5,7 @@ go-cqhttp 默认生成的文件树如下所示:
|
||||
````
|
||||
.
|
||||
├── go-cqhttp
|
||||
├── config.json
|
||||
├── config.hjson
|
||||
├── device.json
|
||||
├── logs
|
||||
│ └── xx-xx-xx.log
|
||||
@ -18,7 +18,7 @@ go-cqhttp 默认生成的文件树如下所示:
|
||||
| 文件 | 用途 |
|
||||
| ----------- | ------------------- |
|
||||
| go-cqhttp | go-cqhttp可执行文件 |
|
||||
| config.json | 运行配置文件 |
|
||||
| config.hjson | 运行配置文件 |
|
||||
| device.json | 虚拟设备配置文件 |
|
||||
| logs | 日志存放目录 |
|
||||
| data | 数据目录 |
|
||||
|
@ -28,8 +28,8 @@
|
||||
|
||||
1. 双击`go-cqhttp.exe`此时将提示
|
||||
```
|
||||
[WARNING]: 尝试加载配置文件 config.json 失败: 文件不存在
|
||||
[INFO]: 默认配置文件已生成,请编辑 config.json 后重启程序.
|
||||
[WARNING]: 尝试加载配置文件 config.hjson 失败: 文件不存在
|
||||
[INFO]: 默认配置文件已生成,请编辑 config.hjson 后重启程序.
|
||||
```
|
||||
2. 参照[config.md](https://github.com/Mrs4s/go-cqhttp/blob/master/docs/config.md)和你所用到的插件的 `README` 填入参数
|
||||
3. 再次双击`go-cqhttp.exe`
|
||||
@ -79,8 +79,8 @@ enable ws?(Y/n)
|
||||
2. `cd`到解压目录
|
||||
3. 输入 `./go-cqhttp`,`Enter`运行 ,此时将提示
|
||||
```
|
||||
[WARNING]: 尝试加载配置文件 config.json 失败: 文件不存在
|
||||
[INFO]: 默认配置文件已生成,请编辑 config.json 后重启程序.
|
||||
[WARNING]: 尝试加载配置文件 config.hjson 失败: 文件不存在
|
||||
[INFO]: 默认配置文件已生成,请编辑 config.hjson 后重启程序.
|
||||
```
|
||||
|
||||
4. 参照[config.md](https://github.com/Mrs4s/go-cqhttp/blob/master/docs/config.md)和你所用到的插件的 `README` 填入参数
|
||||
@ -103,6 +103,8 @@ enable ws?(Y/n)
|
||||
|
||||
如果出现`{"data":{"message_id":balabala},"retcode":0,"status":"ok"}`则证明已经成功配置HTTP
|
||||
|
||||
*注:请 连 中括号 也替换掉,就像这样:*`http://127.0.0.1:5700/send_private_msg?user_id=10001&message=ffeecoishp`
|
||||
|
||||
# 进阶指南
|
||||
|
||||
## 如何自己构建
|
||||
@ -117,13 +119,11 @@ enable ws?(Y/n)
|
||||
|
||||
*注:可以使用*`go env -w GOPROXY=https://goproxy.cn,direct`*来加速国内依赖安装速度*
|
||||
|
||||
*注:此时构建后的文件名为*`go-cqhttp`(Linux)或`go-cqhttp.exe`(Windows)
|
||||
|
||||
## 更新
|
||||
|
||||
### 方法一
|
||||
|
||||
从[release] (https://github.com/Mrs4s/go-cqhttp/releases)界面下载最新版本的go-cqhttp
|
||||
从[release](https://github.com/Mrs4s/go-cqhttp/releases)界面下载最新版本的go-cqhttp
|
||||
并替换之前的版本
|
||||
|
||||
### 方法二
|
||||
|
149
global/config.go
149
global/config.go
@ -1,14 +1,139 @@
|
||||
package global
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/hjson/hjson-go"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
|
||||
var DefaultConfigWithComments = `
|
||||
/*
|
||||
go-cqhttp 默认配置文件
|
||||
*/
|
||||
|
||||
{
|
||||
// QQ号
|
||||
uin: 0
|
||||
// QQ密码
|
||||
password: ""
|
||||
// 是否启用密码加密
|
||||
encrypt_password: false
|
||||
// 加密后的密码, 如未启用密码加密将为空, 请勿随意修改.
|
||||
password_encrypted: ""
|
||||
// 是否启用内置数据库
|
||||
// 启用将会增加10-20MB的内存占用和一定的磁盘空间
|
||||
// 关闭将无法使用 撤回 回复 get_msg 等上下文相关功能
|
||||
enable_db: true
|
||||
// 访问密钥, 强烈推荐在公网的服务器设置
|
||||
access_token: ""
|
||||
// 重连设置
|
||||
relogin: {
|
||||
// 是否启用自动重连
|
||||
// 如不启用掉线后将不会自动重连
|
||||
enabled: true
|
||||
// 重连延迟, 单位秒
|
||||
relogin_delay: 3
|
||||
// 最大重连次数, 0为无限制
|
||||
max_relogin_times: 0
|
||||
}
|
||||
// API限速设置
|
||||
// 该设置为全局生效
|
||||
// 原 cqhttp 虽然启用了 rate_limit 后缀, 但是基本没插件适配
|
||||
// 目前该限速设置为令牌桶算法, 请参考:
|
||||
// https://baike.baidu.com/item/%E4%BB%A4%E7%89%8C%E6%A1%B6%E7%AE%97%E6%B3%95/6597000?fr=aladdin
|
||||
_rate_limit: {
|
||||
// 是否启用限速
|
||||
enabled: false
|
||||
// 令牌回复频率, 单位秒
|
||||
frequency: 1
|
||||
// 令牌桶大小
|
||||
bucket_size: 1
|
||||
}
|
||||
// 是否忽略无效的CQ码
|
||||
// 如果为假将原样发送
|
||||
ignore_invalid_cqcode: false
|
||||
// 是否强制分片发送消息
|
||||
// 分片发送将会带来更快的速度
|
||||
// 但是兼容性会有些问题
|
||||
force_fragmented: false
|
||||
// 心跳频率, 单位秒
|
||||
// -1 为关闭心跳
|
||||
heartbeat_interval: 0
|
||||
// HTTP设置
|
||||
http_config: {
|
||||
// 是否启用正向HTTP服务器
|
||||
enabled: true
|
||||
// 服务端监听地址
|
||||
host: 0.0.0.0
|
||||
// 服务端监听端口
|
||||
port: 5700
|
||||
// 反向HTTP超时时间, 单位秒
|
||||
// 最小值为5,小于5将会忽略本项设置
|
||||
timeout: 0
|
||||
// 反向HTTP POST地址列表
|
||||
// 格式:
|
||||
// {
|
||||
// 地址: secret
|
||||
// }
|
||||
post_urls: {}
|
||||
}
|
||||
// 正向WS设置
|
||||
ws_config: {
|
||||
// 是否启用正向WS服务器
|
||||
enabled: true
|
||||
// 正向WS服务器监听地址
|
||||
host: 0.0.0.0
|
||||
// 正向WS服务器监听端口
|
||||
port: 6700
|
||||
}
|
||||
// 反向WS设置
|
||||
ws_reverse_servers: [
|
||||
// 可以添加多个反向WS推送
|
||||
{
|
||||
// 是否启用该推送
|
||||
enabled: false
|
||||
// 反向WS Universal 地址
|
||||
// 注意 设置了此项地址后下面两项将会被忽略
|
||||
// 留空请使用 ""
|
||||
reverse_url: ws://you_websocket_universal.server
|
||||
// 反向WS API 地址
|
||||
reverse_api_url: ws://you_websocket_api.server
|
||||
// 反向WS Event 地址
|
||||
reverse_event_url: ws://you_websocket_event.server
|
||||
// 重连间隔 单位毫秒
|
||||
reverse_reconnect_interval: 3000
|
||||
}
|
||||
]
|
||||
// 上报数据类型
|
||||
// 可选: string array
|
||||
post_message_format: string
|
||||
// 是否使用服务器下发的新地址进行重连
|
||||
// 注意, 此设置可能导致在海外服务器上连接情况更差
|
||||
use_sso_address: false
|
||||
// 是否启用 DEBUG
|
||||
debug: false
|
||||
// 日志等级
|
||||
log_level: ""
|
||||
// WebUi 设置
|
||||
web_ui: {
|
||||
// 是否启用 WebUi
|
||||
enabled: true
|
||||
// 监听地址
|
||||
host: 127.0.0.1
|
||||
// 监听端口
|
||||
web_ui_port: 9999
|
||||
// 是否接收来自web的输入
|
||||
web_input: false
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
type JsonConfig struct {
|
||||
Uin int64 `json:"uin"`
|
||||
Password string `json:"password"`
|
||||
@ -28,6 +153,8 @@ type JsonConfig struct {
|
||||
} `json:"_rate_limit"`
|
||||
IgnoreInvalidCQCode bool `json:"ignore_invalid_cqcode"`
|
||||
ForceFragmented bool `json:"force_fragmented"`
|
||||
FixUrl bool `json:"fix_url"`
|
||||
ProxyRewrite string `json:"proxy_rewrite"`
|
||||
HeartbeatInterval time.Duration `json:"heartbeat_interval"`
|
||||
HttpConfig *GoCQHttpConfig `json:"http_config"`
|
||||
WSConfig *GoCQWebsocketConfig `json:"ws_config"`
|
||||
@ -144,22 +271,30 @@ func Load(p string) *JsonConfig {
|
||||
log.Warnf("尝试加载配置文件 %v 失败: 文件不存在", p)
|
||||
return nil
|
||||
}
|
||||
c := JsonConfig{}
|
||||
err := json.Unmarshal([]byte(ReadAllText(p)), &c)
|
||||
var dat map[string]interface{}
|
||||
var c = JsonConfig{}
|
||||
err := hjson.Unmarshal([]byte(ReadAllText(p)), &dat)
|
||||
if err == nil {
|
||||
b, _ := json.Marshal(dat)
|
||||
err = json.Unmarshal(b, &c)
|
||||
}
|
||||
if err != nil {
|
||||
log.Warnf("尝试加载配置文件 %v 时出现错误: %v", p, err)
|
||||
log.Infoln("原文件已备份")
|
||||
os.Rename(p, p+".backup"+strconv.FormatInt(time.Now().Unix(), 10))
|
||||
_ = os.Rename(p, p+".backup"+strconv.FormatInt(time.Now().Unix(), 10))
|
||||
return nil
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c *JsonConfig) Save(p string) error {
|
||||
data, err := json.MarshalIndent(c, "", "\t")
|
||||
data, err := hjson.MarshalWithOptions(c, hjson.EncoderOptions{
|
||||
Eol: "\n",
|
||||
BracesSameLine: true,
|
||||
IndentBy: " ",
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
WriteAllText(p, string(data))
|
||||
return nil
|
||||
return WriteAllText(p, string(data))
|
||||
}
|
||||
|
117
global/filter.go
117
global/filter.go
@ -1,6 +1,7 @@
|
||||
package global
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"regexp"
|
||||
"strings"
|
||||
@ -9,17 +10,37 @@ import (
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
type Filter interface {
|
||||
Eval(payload gjson.Result) bool
|
||||
type MSG map[string]interface{}
|
||||
|
||||
func (m MSG) Get(s string) MSG {
|
||||
if v, ok := m[s]; ok {
|
||||
if msg, ok := v.(MSG); ok {
|
||||
return msg
|
||||
}
|
||||
return MSG{"__str__": v} // 用这个名字应该没问题吧
|
||||
}
|
||||
return MSG{}
|
||||
}
|
||||
|
||||
type OperationNode struct {
|
||||
func (m MSG) String() string {
|
||||
if str, ok := m["__str__"]; ok {
|
||||
return fmt.Sprint(str)
|
||||
}
|
||||
str, _ := json.MarshalToString(m)
|
||||
return str
|
||||
}
|
||||
|
||||
type Filter interface {
|
||||
Eval(payload MSG) bool
|
||||
}
|
||||
|
||||
type operationNode struct {
|
||||
key string
|
||||
filter Filter
|
||||
}
|
||||
|
||||
type NotOperator struct {
|
||||
operand_ Filter
|
||||
operand Filter
|
||||
}
|
||||
|
||||
func notOperatorConstruct(argument gjson.Result) *NotOperator {
|
||||
@ -27,16 +48,16 @@ func notOperatorConstruct(argument gjson.Result) *NotOperator {
|
||||
panic("the argument of 'not' operator must be an object")
|
||||
}
|
||||
op := new(NotOperator)
|
||||
op.operand_ = Generate("and", argument)
|
||||
op.operand = Generate("and", argument)
|
||||
return op
|
||||
}
|
||||
|
||||
func (notOperator NotOperator) Eval(payload gjson.Result) bool {
|
||||
return !(notOperator.operand_).Eval(payload)
|
||||
func (op *NotOperator) Eval(payload MSG) bool {
|
||||
return !op.operand.Eval(payload)
|
||||
}
|
||||
|
||||
type AndOperator struct {
|
||||
operands []OperationNode
|
||||
operands []operationNode
|
||||
}
|
||||
|
||||
func andOperatorConstruct(argument gjson.Result) *AndOperator {
|
||||
@ -51,26 +72,26 @@ func andOperatorConstruct(argument gjson.Result) *AndOperator {
|
||||
// "bar": "baz"
|
||||
// }
|
||||
opKey := key.Str[1:]
|
||||
op.operands = append(op.operands, OperationNode{"", Generate(opKey, value)})
|
||||
op.operands = append(op.operands, operationNode{"", Generate(opKey, value)})
|
||||
} else if value.IsObject() {
|
||||
// is an normal key with an object as the value
|
||||
// "foo": {
|
||||
// ".bar": "baz"
|
||||
// }
|
||||
opKey := key.String()
|
||||
op.operands = append(op.operands, OperationNode{opKey, Generate("and", value)})
|
||||
op.operands = append(op.operands, operationNode{opKey, Generate("and", value)})
|
||||
} else {
|
||||
// is an normal key with a non-object as the value
|
||||
// "foo": "bar"
|
||||
opKey := key.String()
|
||||
op.operands = append(op.operands, OperationNode{opKey, Generate("eq", value)})
|
||||
op.operands = append(op.operands, operationNode{opKey, Generate("eq", value)})
|
||||
}
|
||||
return true
|
||||
})
|
||||
return op
|
||||
}
|
||||
|
||||
func (andOperator *AndOperator) Eval(payload gjson.Result) bool {
|
||||
func (andOperator *AndOperator) Eval(payload MSG) bool {
|
||||
res := true
|
||||
for _, operand := range andOperator.operands {
|
||||
|
||||
@ -106,11 +127,10 @@ func orOperatorConstruct(argument gjson.Result) *OrOperator {
|
||||
return op
|
||||
}
|
||||
|
||||
func (orOperator OrOperator) Eval(payload gjson.Result) bool {
|
||||
func (op *OrOperator) Eval(payload MSG) bool {
|
||||
res := false
|
||||
for _, operand := range orOperator.operands {
|
||||
for _, operand := range op.operands {
|
||||
res = res || operand.Eval(payload)
|
||||
|
||||
if res == true {
|
||||
break
|
||||
}
|
||||
@ -119,35 +139,36 @@ func (orOperator OrOperator) Eval(payload gjson.Result) bool {
|
||||
}
|
||||
|
||||
type EqualOperator struct {
|
||||
value gjson.Result
|
||||
operand string
|
||||
}
|
||||
|
||||
func equalOperatorConstruct(argument gjson.Result) *EqualOperator {
|
||||
op := new(EqualOperator)
|
||||
op.value = argument
|
||||
op.operand = argument.String()
|
||||
return op
|
||||
}
|
||||
|
||||
func (equalOperator EqualOperator) Eval(payload gjson.Result) bool {
|
||||
return payload.String() == equalOperator.value.String()
|
||||
func (op *EqualOperator) Eval(payload MSG) bool {
|
||||
return payload.String() == op.operand
|
||||
}
|
||||
|
||||
type NotEqualOperator struct {
|
||||
value gjson.Result
|
||||
operand string
|
||||
}
|
||||
|
||||
func notEqualOperatorConstruct(argument gjson.Result) *NotEqualOperator {
|
||||
op := new(NotEqualOperator)
|
||||
op.value = argument
|
||||
op.operand = argument.String()
|
||||
return op
|
||||
}
|
||||
|
||||
func (notEqualOperator NotEqualOperator) Eval(payload gjson.Result) bool {
|
||||
return !(payload.String() == notEqualOperator.value.String())
|
||||
func (op *NotEqualOperator) Eval(payload MSG) bool {
|
||||
return !(payload.String() == op.operand)
|
||||
}
|
||||
|
||||
type InOperator struct {
|
||||
operand gjson.Result
|
||||
operandString string
|
||||
operandArray []string
|
||||
}
|
||||
|
||||
func inOperatorConstruct(argument gjson.Result) *InOperator {
|
||||
@ -155,20 +176,29 @@ func inOperatorConstruct(argument gjson.Result) *InOperator {
|
||||
panic("the argument of 'in' operator must be an array or a string")
|
||||
}
|
||||
op := new(InOperator)
|
||||
op.operand = argument
|
||||
if argument.IsArray() {
|
||||
op.operandArray = []string{}
|
||||
argument.ForEach(func(_, value gjson.Result) bool {
|
||||
op.operandArray = append(op.operandArray, value.String())
|
||||
return true
|
||||
})
|
||||
} else {
|
||||
op.operandString = argument.String()
|
||||
}
|
||||
return op
|
||||
}
|
||||
|
||||
func (inOperator InOperator) Eval(payload gjson.Result) bool {
|
||||
if inOperator.operand.IsArray() {
|
||||
res := false
|
||||
inOperator.operand.ForEach(func(key, value gjson.Result) bool {
|
||||
res = res || value.String() == payload.String()
|
||||
return true
|
||||
})
|
||||
return res
|
||||
func (op *InOperator) Eval(payload MSG) bool {
|
||||
payloadStr := payload.String()
|
||||
if op.operandArray != nil {
|
||||
for _, value := range op.operandArray {
|
||||
if value == payloadStr {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
return strings.Contains(inOperator.operand.String(), payload.String())
|
||||
return strings.Contains(op.operandString, payloadStr)
|
||||
}
|
||||
|
||||
type ContainsOperator struct {
|
||||
@ -184,15 +214,12 @@ func containsOperatorConstruct(argument gjson.Result) *ContainsOperator {
|
||||
return op
|
||||
}
|
||||
|
||||
func (containsOperator ContainsOperator) Eval(payload gjson.Result) bool {
|
||||
if payload.IsObject() || payload.IsArray() {
|
||||
return false
|
||||
}
|
||||
return strings.Contains(payload.String(), containsOperator.operand)
|
||||
func (op *ContainsOperator) Eval(payload MSG) bool {
|
||||
return strings.Contains(payload.String(), op.operand)
|
||||
}
|
||||
|
||||
type RegexOperator struct {
|
||||
regex string
|
||||
regex *regexp.Regexp
|
||||
}
|
||||
|
||||
func regexOperatorConstruct(argument gjson.Result) *RegexOperator {
|
||||
@ -200,12 +227,12 @@ func regexOperatorConstruct(argument gjson.Result) *RegexOperator {
|
||||
panic("the argument of 'regex' operator must be a string")
|
||||
}
|
||||
op := new(RegexOperator)
|
||||
op.regex = argument.String()
|
||||
op.regex = regexp.MustCompile(argument.String())
|
||||
return op
|
||||
}
|
||||
|
||||
func (containsOperator RegexOperator) Eval(payload gjson.Result) bool {
|
||||
matched, _ := regexp.MatchString(containsOperator.regex, payload.String())
|
||||
func (op *RegexOperator) Eval(payload MSG) bool {
|
||||
matched := op.regex.MatchString(payload.String())
|
||||
return matched
|
||||
}
|
||||
|
||||
@ -232,7 +259,7 @@ func Generate(opName string, argument gjson.Result) Filter {
|
||||
}
|
||||
}
|
||||
|
||||
var EventFilter = new(Filter)
|
||||
var EventFilter Filter = nil
|
||||
|
||||
func BootFilter() {
|
||||
defer func() {
|
||||
@ -247,6 +274,6 @@ func BootFilter() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
*EventFilter = Generate("and", gjson.ParseBytes(f))
|
||||
EventFilter = Generate("and", gjson.ParseBytes(f))
|
||||
}
|
||||
}
|
||||
|
18
global/fs.go
18
global/fs.go
@ -21,13 +21,17 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
IMAGE_PATH = path.Join("data", "images")
|
||||
VOICE_PATH = path.Join("data", "voices")
|
||||
VIDEO_PATH = path.Join("data", "videos")
|
||||
CACHE_PATH = path.Join("data", "cache")
|
||||
IMAGE_PATH = path.Join("data", "images")
|
||||
IMAGE_PATH_OLD = path.Join("data", "image")
|
||||
VOICE_PATH = path.Join("data", "voices")
|
||||
VOICE_PATH_OLD = path.Join("data", "record")
|
||||
VIDEO_PATH = path.Join("data", "videos")
|
||||
CACHE_PATH = path.Join("data", "cache")
|
||||
|
||||
HEADER_AMR = []byte("#!AMR")
|
||||
HEADER_SILK = []byte("\x02#!SILK_V3")
|
||||
|
||||
ErrSyntax = errors.New("syntax error")
|
||||
)
|
||||
|
||||
func PathExists(path string) bool {
|
||||
@ -43,8 +47,8 @@ func ReadAllText(path string) string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func WriteAllText(path, text string) {
|
||||
_ = ioutil.WriteFile(path, []byte(text), 0644)
|
||||
func WriteAllText(path, text string) error {
|
||||
return ioutil.WriteFile(path, []byte(text), 0644)
|
||||
}
|
||||
|
||||
func Check(err error) {
|
||||
@ -58,7 +62,7 @@ func IsAMRorSILK(b []byte) bool {
|
||||
}
|
||||
|
||||
func FindFile(f, cache, PATH string) (data []byte, err error) {
|
||||
data, err = nil, errors.New("syntax error")
|
||||
data, err = nil, ErrSyntax
|
||||
if strings.HasPrefix(f, "http") || strings.HasPrefix(f, "https") {
|
||||
if cache == "" {
|
||||
cache = "1"
|
||||
|
@ -4,8 +4,12 @@ import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"github.com/guonaihong/gout"
|
||||
"github.com/pkg/errors"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -14,8 +18,27 @@ import (
|
||||
|
||||
var client = &http.Client{
|
||||
Timeout: time.Second * 15,
|
||||
Transport: &http.Transport{
|
||||
Proxy: func(request *http.Request) (u *url.URL, e error) {
|
||||
if Proxy == "" {
|
||||
return http.ProxyFromEnvironment(request)
|
||||
}
|
||||
return url.Parse(Proxy)
|
||||
},
|
||||
DialContext: (&net.Dialer{
|
||||
Timeout: 30 * time.Second,
|
||||
KeepAlive: 30 * time.Second,
|
||||
}).DialContext,
|
||||
ForceAttemptHTTP2: true,
|
||||
MaxIdleConns: 100,
|
||||
IdleConnTimeout: 90 * time.Second,
|
||||
TLSHandshakeTimeout: 10 * time.Second,
|
||||
ExpectContinueTimeout: 1 * time.Second,
|
||||
},
|
||||
}
|
||||
|
||||
var Proxy string
|
||||
|
||||
func GetBytes(url string) ([]byte, error) {
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
@ -41,6 +64,26 @@ func GetBytes(url string) ([]byte, error) {
|
||||
return body, nil
|
||||
}
|
||||
|
||||
func GetSilderTicket(raw, version string) (string, error) {
|
||||
u, err := url.Parse(raw)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
q := u.Query()
|
||||
var rsp string
|
||||
if err = gout.GET(fmt.Sprintf("https://api.shkong.com/gocqhttpapi/silder/ticket?uin=%v&sid=%v&cap=%v", q["uin"][0], q["sid"][0], q["cap_cd"][0])).
|
||||
SetHeader(gout.H{"User-Agent": "go-cqhttp/" + version}).
|
||||
BindBody(&rsp).
|
||||
Do(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
g := gjson.Parse(rsp)
|
||||
if g.Get("error").Str != "" {
|
||||
return "", errors.New(g.Get("error").Str)
|
||||
}
|
||||
return g.Get("ticket").Str, nil
|
||||
}
|
||||
|
||||
func QQMusicSongInfo(id string) (gjson.Result, error) {
|
||||
d, err := GetBytes(`https://u.y.qq.com/cgi-bin/musicu.fcg?format=json&inCharset=utf8&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=0&data={%22comm%22:{%22ct%22:24,%22cv%22:0},%22songinfo%22:{%22method%22:%22get_song_detail_yqq%22,%22param%22:{%22song_type%22:0,%22song_mid%22:%22%22,%22song_id%22:` + id + `},%22module%22:%22music.pf_song_detail_svr%22}}`)
|
||||
if err != nil {
|
||||
|
@ -71,3 +71,23 @@ func VersionNameCompare(current, remote string) bool {
|
||||
}
|
||||
return len(cur) < len(re)
|
||||
}
|
||||
|
||||
func SplitUrl(s string) []string {
|
||||
reg := regexp.MustCompile(`[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?`)
|
||||
idx := reg.FindAllStringIndex(s, -1)
|
||||
if len(idx) == 0 {
|
||||
return []string{s}
|
||||
}
|
||||
var result []string
|
||||
last := 0
|
||||
for i := 0; i < len(idx); i++ {
|
||||
if len(idx[i]) != 2 {
|
||||
continue
|
||||
}
|
||||
m := int(math.Abs(float64(idx[i][0]-idx[i][1]))/1.5) + idx[i][0]
|
||||
result = append(result, s[last:m])
|
||||
last = m
|
||||
}
|
||||
result = append(result, s[last:])
|
||||
return result
|
||||
}
|
||||
|
18
go.mod
18
go.mod
@ -1,26 +1,30 @@
|
||||
module github.com/Mrs4s/go-cqhttp
|
||||
|
||||
go 1.14
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20201117154121-989187125900
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20201225164755-c519c532d0d5
|
||||
github.com/dustin/go-humanize v1.0.0
|
||||
github.com/getlantern/go-update v0.0.0-20190510022740-79c495ab728c
|
||||
github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9 // indirect
|
||||
github.com/gin-contrib/pprof v1.3.0
|
||||
github.com/gin-gonic/gin v1.6.3
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/guonaihong/gout v0.1.3
|
||||
github.com/guonaihong/gout v0.1.4
|
||||
github.com/hjson/hjson-go v3.1.0+incompatible
|
||||
github.com/json-iterator/go v1.1.10
|
||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
|
||||
github.com/kr/binarydist v0.1.0 // indirect
|
||||
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
|
||||
github.com/lestrrat-go/strftime v1.0.3 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
|
||||
github.com/sirupsen/logrus v1.7.0
|
||||
github.com/syndtr/goleveldb v1.0.0
|
||||
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
|
||||
github.com/tidwall/gjson v1.6.3
|
||||
github.com/wdvxdr1123/go-silk v0.0.0-20201007123416-b982fd3d91d6
|
||||
github.com/tidwall/gjson v1.6.7
|
||||
github.com/wdvxdr1123/go-silk v0.0.0-20201210140933-bcdbcb2f1093
|
||||
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
|
||||
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
|
||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324
|
||||
)
|
||||
|
68
go.sum
68
go.sum
@ -1,7 +1,8 @@
|
||||
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-20201117154121-989187125900 h1:xnx3dH7hgZ/Z4k33EhKzBmQhwASJ5bvsorqPhO0DWbc=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20201117154121-989187125900/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20201225164755-c519c532d0d5 h1:kvaZXnhjdOtRip6xlXu9hEyJhPzKs8ylrdE2eb+N4NQ=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20201225164755-c519c532d0d5/go.mod h1:7brUNAmygY22+PDCUiVT4MLeyvGHDBjW9f+67DKeHTw=
|
||||
github.com/a8m/syncmap v0.0.0-20200818084611-4bbbd178de97/go.mod h1:f3iF7/3t9i9hsYF8DPgT0XeIVyNzevhMCKf2445Q6pE=
|
||||
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/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@ -25,16 +26,17 @@ github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 h1:XYzSdCbkzOC0F
|
||||
github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55/go.mod h1:6mmzY2kW1TOOrVy+r41Za2MxXM+hhqTtY3oBKd2AgFA=
|
||||
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f h1:wrYrQttPS8FHIRSlsrcuKazukx/xqO/PpLZzZXsF+EA=
|
||||
github.com/getlantern/ops v0.0.0-20190325191751-d70cb0d6f85f/go.mod h1:D5ao98qkA6pxftxoqzibIBBrLSUli+kYnJqrgBf9cIA=
|
||||
github.com/gin-contrib/pprof v1.3.0 h1:G9eK6HnbkSqDZBYbzG4wrjCsA4e+cvYAHUZw6W+W9K0=
|
||||
github.com/gin-contrib/pprof v1.3.0/go.mod h1:waMjT1H9b179t3CxuG1cV3DHpga6ybizwfBaM5OXaB0=
|
||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||
github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do=
|
||||
github.com/gin-gonic/gin v1.6.0/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
|
||||
github.com/gin-gonic/gin v1.6.2/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
|
||||
github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
|
||||
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
|
||||
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||
github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM=
|
||||
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
|
||||
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
|
||||
github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=
|
||||
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
|
||||
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
|
||||
github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY=
|
||||
@ -65,17 +67,19 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/guonaihong/gout v0.1.3 h1:BIiV6nnsA+R6dIB1P33uhCM8+TVAG3zHrXGZad7hDc8=
|
||||
github.com/guonaihong/gout v0.1.3/go.mod h1:vXvv5Kxr70eM5wrp4F0+t9lnLWmq+YPW2GByll2f/EA=
|
||||
github.com/guonaihong/gout v0.1.4 h1:uBBoyztMX9okC27OQxqhn6bZ0ROkGyvnEIHwtp3TM4g=
|
||||
github.com/guonaihong/gout v0.1.4/go.mod h1:0rFYAYyzbcxEg11eY2qUbffJs7hHRPeugAnlVYSp8Ic=
|
||||
github.com/hjson/hjson-go v3.1.0+incompatible h1:DY/9yE8ey8Zv22bY+mHV1uk2yRy0h8tKhZ77hEdi0Aw=
|
||||
github.com/hjson/hjson-go v3.1.0+incompatible/go.mod h1:qsetwF8NlsTsOTwZTApNlTCerV+b2GjYRRcIk4JMFio=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
|
||||
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
|
||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/binarydist v0.1.0 h1:6kAoLA9FMMnNGSehX0s1PdjbEaACznAv/W219j2uvyo=
|
||||
github.com/kr/binarydist v0.1.0/go.mod h1:DY7S//GCoz1BCd0B0EVrinCKAZN3pXe+MDaIZbXQVgM=
|
||||
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
|
||||
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
|
||||
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
|
||||
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is=
|
||||
@ -83,10 +87,11 @@ github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkL
|
||||
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA=
|
||||
github.com/lestrrat-go/strftime v1.0.3 h1:qqOPU7y+TM8Y803I8fG9c/DyKG3xH/xkng6keC1015Q=
|
||||
github.com/lestrrat-go/strftime v1.0.3/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g=
|
||||
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
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=
|
||||
@ -114,55 +119,76 @@ github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFd
|
||||
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
|
||||
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 h1:J6v8awz+me+xeb/cUTotKgceAYouhIB3pjzgRd6IlGk=
|
||||
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816/go.mod h1:tzym/CEb5jnFI+Q0k4Qq3+LvRF4gO3E2pxS8fHP8jcA=
|
||||
github.com/tidwall/gjson v1.6.1/go.mod h1:BaHyNc5bjzYkPqgLq7mdVzeiRtULKULXLgZFKsxEHI0=
|
||||
github.com/tidwall/gjson v1.6.3 h1:aHoiiem0dr7GHkW001T1SMTJ7X5PvyekH5WX0whWGnI=
|
||||
github.com/tidwall/gjson v1.6.3/go.mod h1:BaHyNc5bjzYkPqgLq7mdVzeiRtULKULXLgZFKsxEHI0=
|
||||
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
|
||||
github.com/tidwall/gjson v1.6.7 h1:Mb1M9HZCRWEcXQ8ieJo7auYyyiSux6w9XN3AdTpxJrE=
|
||||
github.com/tidwall/gjson v1.6.7/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
|
||||
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
|
||||
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
|
||||
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
|
||||
github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
|
||||
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
|
||||
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
|
||||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
||||
github.com/wdvxdr1123/go-silk v0.0.0-20201007123416-b982fd3d91d6 h1:lX18MCdNzT2zIi7K02x4C5cPkDXpL+wCb1YTAMXjLWQ=
|
||||
github.com/wdvxdr1123/go-silk v0.0.0-20201007123416-b982fd3d91d6/go.mod h1:5q9LFlBr+yX/J8Jd/9wHdXwkkjFkNyQIS7kX2Lgx/Zs=
|
||||
github.com/wdvxdr1123/go-silk v0.0.0-20201210140933-bcdbcb2f1093 h1:t38EBwI2hFJz1sQJ402VqzdA3eMidkY1c3w/8z0SftA=
|
||||
github.com/wdvxdr1123/go-silk v0.0.0-20201210140933-bcdbcb2f1093/go.mod h1:5q9LFlBr+yX/J8Jd/9wHdXwkkjFkNyQIS7kX2Lgx/Zs=
|
||||
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189 h1:4UJw9if55Fu3HOwbfcaQlJ27p3oeJU2JZqoeT3ITJQk=
|
||||
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189/go.mod h1:rIrm5geMiBhPQkdfUm8gDFi/WiHneOp1i9KjmJqc+9I=
|
||||
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/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=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s=
|
||||
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
|
||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190501045030-23463209683d/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20201218024724-ae774e9781d2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
@ -183,8 +209,6 @@ google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
|
||||
gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
65
main.go
65
main.go
@ -2,10 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@ -23,18 +21,22 @@ import (
|
||||
"github.com/Mrs4s/go-cqhttp/server"
|
||||
"github.com/guonaihong/gout"
|
||||
"github.com/tidwall/gjson"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
|
||||
"github.com/Mrs4s/MiraiGo/binary"
|
||||
"github.com/Mrs4s/MiraiGo/client"
|
||||
"github.com/Mrs4s/go-cqhttp/coolq"
|
||||
"github.com/Mrs4s/go-cqhttp/global"
|
||||
"github.com/getlantern/go-update"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
||||
"github.com/rifflock/lfshook"
|
||||
log "github.com/sirupsen/logrus"
|
||||
easy "github.com/t-tomalak/logrus-easy-formatter"
|
||||
)
|
||||
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
|
||||
func init() {
|
||||
log.SetFormatter(&easy.Formatter{
|
||||
TimestampFormat: "2006-01-02 15:04:05",
|
||||
@ -66,7 +68,7 @@ func init() {
|
||||
}
|
||||
if global.PathExists("cqhttp.json") {
|
||||
log.Info("发现 cqhttp.json 将在五秒后尝试导入配置,按 Ctrl+C 取消.")
|
||||
log.Warn("警告: 该操作会删除 cqhttp.json 并覆盖 config.json 文件.")
|
||||
log.Warn("警告: 该操作会删除 cqhttp.json 并覆盖 config.hjson 文件.")
|
||||
time.Sleep(time.Second * 5)
|
||||
conf := global.CQHttpApiConfig{}
|
||||
if err := json.Unmarshal([]byte(global.ReadAllText("cqhttp.json")), &conf); err != nil {
|
||||
@ -88,17 +90,16 @@ func init() {
|
||||
goConf.ReverseServers[0].ReverseEventUrl = conf.WSReverseEventUrl
|
||||
goConf.ReverseServers[0].ReverseReconnectInterval = conf.WSReverseReconnectInterval
|
||||
}
|
||||
if err := goConf.Save("config.json"); err != nil {
|
||||
log.Fatalf("保存 config.json 时出现错误: %v", err)
|
||||
if err := goConf.Save("config.hjson"); err != nil {
|
||||
log.Fatalf("保存 config.hjson 时出现错误: %v", err)
|
||||
}
|
||||
_ = os.Remove("cqhttp.json")
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
console := bufio.NewReader(os.Stdin)
|
||||
var strKey string
|
||||
var isFastStart bool = false
|
||||
var byteKey []byte
|
||||
var isFastStart = false
|
||||
arg := os.Args
|
||||
if len(arg) > 1 {
|
||||
for i := range arg {
|
||||
@ -112,8 +113,7 @@ func main() {
|
||||
case "key":
|
||||
if len(arg) > i+1 {
|
||||
b := []byte(arg[i+1])
|
||||
b = append(b, 13, 10)
|
||||
strKey = string(b[:])
|
||||
byteKey = b
|
||||
}
|
||||
case "faststart":
|
||||
isFastStart = true
|
||||
@ -122,8 +122,10 @@ func main() {
|
||||
}
|
||||
|
||||
var conf *global.JsonConfig
|
||||
if global.PathExists("config.json") || os.Getenv("UIN") == "" {
|
||||
if global.PathExists("config.json") {
|
||||
conf = global.Load("config.json")
|
||||
_ = conf.Save("config.hjson")
|
||||
_ = os.Remove("config.json")
|
||||
} else if os.Getenv("UIN") != "" {
|
||||
log.Infof("将从环境变量加载配置.")
|
||||
uin, _ := strconv.ParseInt(os.Getenv("UIN"), 10, 64)
|
||||
@ -149,19 +151,21 @@ func main() {
|
||||
if post != "" {
|
||||
conf.HttpConfig.PostUrls[post] = os.Getenv("HTTP_SECRET")
|
||||
}
|
||||
} else {
|
||||
conf = global.Load("config.hjson")
|
||||
}
|
||||
if conf == nil {
|
||||
err := global.DefaultConfig().Save("config.json")
|
||||
err := global.WriteAllText("config.hjson", global.DefaultConfigWithComments)
|
||||
if err != nil {
|
||||
log.Fatalf("创建默认配置文件时出现错误: %v", err)
|
||||
return
|
||||
}
|
||||
log.Infof("默认配置文件已生成, 请编辑 config.json 后重启程序.")
|
||||
log.Infof("默认配置文件已生成, 请编辑 config.hjson 后重启程序.")
|
||||
time.Sleep(time.Second * 5)
|
||||
return
|
||||
}
|
||||
if conf.Uin == 0 || (conf.Password == "" && conf.PasswordEncrypted == "") {
|
||||
log.Warnf("请修改 config.json 以添加账号密码.")
|
||||
log.Warnf("请修改 config.hjson 以添加账号密码.")
|
||||
time.Sleep(time.Second * 5)
|
||||
return
|
||||
}
|
||||
@ -209,7 +213,12 @@ func main() {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
log.Warnf("已开启Debug模式.")
|
||||
log.Debugf("开发交流群: 192548878")
|
||||
server.Debug = true
|
||||
if conf.WebUi == nil || !conf.WebUi.Enabled {
|
||||
log.Warnf("警告: 在Debug模式下未启用WebUi服务, 将无法进行性能分析.")
|
||||
}
|
||||
}
|
||||
log.Info("用户交流群: 721829413")
|
||||
if !global.PathExists("device.json") {
|
||||
log.Warn("虚拟设备信息不存在, 将自动生成随机设备.")
|
||||
client.GenRandomDevice()
|
||||
@ -223,36 +232,36 @@ func main() {
|
||||
}
|
||||
if conf.EncryptPassword && conf.PasswordEncrypted == "" {
|
||||
log.Infof("密码加密已启用, 请输入Key对密码进行加密: (Enter 提交)")
|
||||
strKey, _ := console.ReadString('\n')
|
||||
key := md5.Sum([]byte(strKey))
|
||||
byteKey, _ := terminal.ReadPassword(int(os.Stdin.Fd()))
|
||||
key := md5.Sum(byteKey)
|
||||
if encrypted := EncryptPwd(conf.Password, key[:]); encrypted != "" {
|
||||
conf.Password = ""
|
||||
conf.PasswordEncrypted = encrypted
|
||||
_ = conf.Save("config.json")
|
||||
_ = conf.Save("config.hjson")
|
||||
} else {
|
||||
log.Warnf("加密时出现问题.")
|
||||
}
|
||||
}
|
||||
if conf.PasswordEncrypted != "" {
|
||||
if strKey == "" {
|
||||
if len(byteKey) == 0 {
|
||||
log.Infof("密码加密已启用, 请输入Key对密码进行解密以继续: (Enter 提交)")
|
||||
ctx := context.Background()
|
||||
go func(ctx context.Context) {
|
||||
cancel := make(chan struct{}, 1)
|
||||
go func() {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case <-cancel:
|
||||
return
|
||||
case <-time.After(time.Second * 45):
|
||||
log.Infof("解密key输入超时")
|
||||
time.Sleep(3 * time.Second)
|
||||
os.Exit(0)
|
||||
}
|
||||
}(ctx)
|
||||
strKey, _ = console.ReadString('\n')
|
||||
ctx.Done()
|
||||
}()
|
||||
byteKey, _ = terminal.ReadPassword(int(os.Stdin.Fd()))
|
||||
cancel <- struct{}{}
|
||||
} else {
|
||||
log.Infof("密码加密已启用, 使用运行时传递的参数进行解密,按 Ctrl+C 取消.")
|
||||
}
|
||||
key := md5.Sum([]byte(strKey))
|
||||
key := md5.Sum(byteKey)
|
||||
conf.Password = DecryptPwd(conf.PasswordEncrypted, key[:])
|
||||
}
|
||||
if !isFastStart {
|
||||
@ -314,10 +323,7 @@ func main() {
|
||||
if conf.WebUi.Host == "" {
|
||||
conf.WebUi.Host = "127.0.0.1"
|
||||
}
|
||||
confErr := conf.Save("config.json")
|
||||
if confErr != nil {
|
||||
log.Error("保存配置文件失败")
|
||||
}
|
||||
global.Proxy = conf.ProxyRewrite
|
||||
b := server.WebServer.Run(fmt.Sprintf("%s:%d", conf.WebUi.Host, conf.WebUi.WebUiPort), cli)
|
||||
c := server.Console
|
||||
r := server.Restart
|
||||
@ -328,7 +334,6 @@ func main() {
|
||||
b.Release()
|
||||
case <-r:
|
||||
log.Info("正在重启中...")
|
||||
server.HttpServer.ShutDown()
|
||||
defer b.Release()
|
||||
restart(arg)
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gin-contrib/pprof"
|
||||
"image"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@ -19,11 +19,14 @@ import (
|
||||
"github.com/Mrs4s/go-cqhttp/coolq"
|
||||
"github.com/Mrs4s/go-cqhttp/global"
|
||||
"github.com/gin-gonic/gin"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/gjson"
|
||||
asciiart "github.com/yinghau76/go-ascii-art"
|
||||
)
|
||||
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
|
||||
var WebInput = make(chan string, 1) //长度1,用于阻塞
|
||||
|
||||
var Console = make(chan os.Signal, 1)
|
||||
@ -75,7 +78,12 @@ func (s *webServer) Run(addr string, cli *client.QQClient) *coolq.CQBot {
|
||||
|
||||
go func() {
|
||||
//开启端口监听
|
||||
if s.Conf.WebUi.Enabled {
|
||||
if s.Conf.WebUi != nil && s.Conf.WebUi.Enabled {
|
||||
if Debug {
|
||||
pprof.Register(s.engine)
|
||||
log.Debugf("pprof 性能分析服务已启动在 http://%v/debug/pprof, 如果有任何性能问题请下载报告并提交给开发者", addr)
|
||||
time.Sleep(time.Second * 3)
|
||||
}
|
||||
log.Infof("Admin API 服务器已启动: %v", addr)
|
||||
err := s.engine.Run(addr)
|
||||
if err != nil {
|
||||
@ -110,27 +118,29 @@ func (s *webServer) Dologin() {
|
||||
cli := s.Cli
|
||||
cli.AllowSlider = true
|
||||
rsp, err := cli.Login()
|
||||
count := 0
|
||||
for {
|
||||
global.Check(err)
|
||||
var text string
|
||||
if !rsp.Success {
|
||||
switch rsp.Error {
|
||||
case client.SliderNeededError:
|
||||
if client.SystemDeviceInfo.Protocol == client.AndroidPhone {
|
||||
log.Warnf("警告: Android Phone 强制要求暂不支持的滑条验证码, 请开启设备锁或切换到Watch协议验证通过后再使用.")
|
||||
log.Infof("按 Enter 继续....")
|
||||
readLine()
|
||||
os.Exit(0)
|
||||
log.Warnf("正在处理滑条验证码, 这可能需要一段时间.")
|
||||
ticket, err := global.GetSilderTicket(rsp.VerifyUrl, coolq.Version)
|
||||
if err != nil {
|
||||
log.Warnf("处理滑条验证码时出现错误: %v 将尝试跳过.", err)
|
||||
cli.AllowSlider = false
|
||||
cli.Disconnect()
|
||||
rsp, err = cli.Login()
|
||||
continue
|
||||
}
|
||||
cli.AllowSlider = false
|
||||
cli.Disconnect()
|
||||
rsp, err = cli.Login()
|
||||
rsp, err = cli.SubmitTicket(ticket)
|
||||
continue
|
||||
case client.NeedCaptcha:
|
||||
_ = ioutil.WriteFile("captcha.jpg", rsp.CaptchaImage, 0644)
|
||||
img, _, _ := image.Decode(bytes.NewReader(rsp.CaptchaImage))
|
||||
fmt.Println(asciiart.New("image", img).Art)
|
||||
if conf.WebUi.WebInput {
|
||||
if conf.WebUi != nil && conf.WebUi.WebInput {
|
||||
log.Warnf("请输入验证码 (captcha.jpg): (http://%s:%d/admin/do_web_write 输入)", conf.WebUi.Host, conf.WebUi.WebUiPort)
|
||||
text = <-WebInput
|
||||
} else {
|
||||
@ -176,7 +186,7 @@ func (s *webServer) Dologin() {
|
||||
return
|
||||
case client.UnsafeDeviceError:
|
||||
log.Warnf("账号已开启设备锁,请前往 -> %v <- 验证并重启Bot.", rsp.VerifyUrl)
|
||||
if conf.WebUi.WebInput {
|
||||
if conf.WebUi != nil && conf.WebUi.WebInput {
|
||||
log.Infof(" (http://%s:%d/admin/do_web_write 确认后继续)....", conf.WebUi.Host, conf.WebUi.WebUiPort)
|
||||
text = <-WebInput
|
||||
} else {
|
||||
@ -191,6 +201,14 @@ func (s *webServer) Dologin() {
|
||||
if strings.Contains(msg, "版本") {
|
||||
msg = "密码错误或账号被冻结"
|
||||
}
|
||||
if strings.Contains(msg, "上网环境") && count < 5 {
|
||||
cli.Disconnect()
|
||||
rsp, err = cli.Login()
|
||||
count++
|
||||
log.Warnf("错误: 当前上网环境异常. 将更换服务器并重试. 如果频繁遇到此问题请打开设备锁.")
|
||||
time.Sleep(time.Second)
|
||||
continue
|
||||
}
|
||||
log.Warnf("登录失败: %v", msg)
|
||||
log.Infof("按 Enter 继续....")
|
||||
readLine()
|
||||
@ -222,6 +240,7 @@ func (s *webServer) Dologin() {
|
||||
global.BootFilter()
|
||||
global.InitCodec()
|
||||
coolq.IgnoreInvalidCQCode = conf.IgnoreInvalidCQCode
|
||||
coolq.SplitUrl = conf.FixUrl
|
||||
coolq.ForceFragmented = conf.ForceFragmented
|
||||
log.Info("资源初始化完成, 开始处理信息.")
|
||||
log.Info("アトリは、高性能ですから!")
|
||||
@ -283,7 +302,7 @@ func GetConf() *global.JsonConfig {
|
||||
if JsonConfig != nil {
|
||||
return JsonConfig
|
||||
}
|
||||
conf := global.Load("config.json")
|
||||
conf := global.Load("config.hjson")
|
||||
return conf
|
||||
}
|
||||
|
||||
@ -301,6 +320,10 @@ func AuthMiddleWare() gin.HandlerFunc {
|
||||
if c.Request.Method == "OPTIONS" {
|
||||
c.AbortWithStatus(http.StatusNoContent)
|
||||
}
|
||||
if strings.Contains(c.Request.URL.Path, "debug") {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
// 处理请求
|
||||
if c.Request.Method != "GET" && c.Request.Method != "POST" {
|
||||
log.Warnf("已拒绝客户端 %v 的请求: 方法错误", c.Request.RemoteAddr)
|
||||
@ -475,9 +498,9 @@ func AdminDoConfigBase(s *webServer, c *gin.Context) {
|
||||
conf.EnableDB = false
|
||||
}
|
||||
conf.AccessToken = c.PostForm("access_token")
|
||||
if err := conf.Save("config.json"); err != nil {
|
||||
log.Fatalf("保存 config.json 时出现错误: %v", err)
|
||||
c.JSON(200, Failed(502, "保存 config.json 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||
if err := conf.Save("config.hjson"); err != nil {
|
||||
log.Fatalf("保存 config.hjson 时出现错误: %v", err)
|
||||
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||
} else {
|
||||
JsonConfig = nil
|
||||
c.JSON(200, coolq.OK(coolq.MSG{}))
|
||||
@ -500,9 +523,9 @@ func AdminDoConfigHttp(s *webServer, c *gin.Context) {
|
||||
if c.PostForm("post_url") != "" {
|
||||
conf.HttpConfig.PostUrls[c.PostForm("post_url")] = c.PostForm("post_secret")
|
||||
}
|
||||
if err := conf.Save("config.json"); err != nil {
|
||||
log.Fatalf("保存 config.json 时出现错误: %v", err)
|
||||
c.JSON(200, Failed(502, "保存 config.json 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||
if err := conf.Save("config.hjson"); err != nil {
|
||||
log.Fatalf("保存 config.hjson 时出现错误: %v", err)
|
||||
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||
} else {
|
||||
JsonConfig = nil
|
||||
c.JSON(200, coolq.OK(coolq.MSG{}))
|
||||
@ -520,9 +543,9 @@ func AdminDoConfigWs(s *webServer, c *gin.Context) {
|
||||
} else {
|
||||
conf.WSConfig.Enabled = false
|
||||
}
|
||||
if err := conf.Save("config.json"); err != nil {
|
||||
log.Fatalf("保存 config.json 时出现错误: %v", err)
|
||||
c.JSON(200, Failed(502, "保存 config.json 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||
if err := conf.Save("config.hjson"); err != nil {
|
||||
log.Fatalf("保存 config.hjson 时出现错误: %v", err)
|
||||
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||
} else {
|
||||
JsonConfig = nil
|
||||
c.JSON(200, coolq.OK(coolq.MSG{}))
|
||||
@ -542,9 +565,9 @@ func AdminDoConfigReverse(s *webServer, c *gin.Context) {
|
||||
} else {
|
||||
conf.ReverseServers[0].Enabled = false
|
||||
}
|
||||
if err := conf.Save("config.json"); err != nil {
|
||||
log.Fatalf("保存 config.json 时出现错误: %v", err)
|
||||
c.JSON(200, Failed(502, "保存 config.json 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||
if err := conf.Save("config.hjson"); err != nil {
|
||||
log.Fatalf("保存 config.hjson 时出现错误: %v", err)
|
||||
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||
} else {
|
||||
JsonConfig = nil
|
||||
c.JSON(200, coolq.OK(coolq.MSG{}))
|
||||
@ -557,13 +580,13 @@ func AdminDoConfigJson(s *webServer, c *gin.Context) {
|
||||
Json := c.PostForm("json")
|
||||
err := json.Unmarshal([]byte(Json), &conf)
|
||||
if err != nil {
|
||||
log.Warnf("尝试加载配置文件 %v 时出现错误: %v", "config.json", err)
|
||||
c.JSON(200, Failed(502, "保存 config.json 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||
log.Warnf("尝试加载配置文件 %v 时出现错误: %v", "config.hjson", err)
|
||||
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||
return
|
||||
}
|
||||
if err := conf.Save("config.json"); err != nil {
|
||||
log.Fatalf("保存 config.json 时出现错误: %v", err)
|
||||
c.JSON(200, Failed(502, "保存 config.json 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||
if err := conf.Save("config.hjson"); err != nil {
|
||||
log.Fatalf("保存 config.hjson 时出现错误: %v", err)
|
||||
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||
} else {
|
||||
JsonConfig = nil
|
||||
c.JSON(200, coolq.OK(coolq.MSG{}))
|
||||
|
@ -35,6 +35,7 @@ type httpClient struct {
|
||||
}
|
||||
|
||||
var HttpServer = &httpServer{}
|
||||
var Debug = false
|
||||
|
||||
func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
@ -93,13 +94,6 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
|
||||
time.Sleep(time.Second * 5)
|
||||
os.Exit(1)
|
||||
}
|
||||
//err := s.engine.Run(addr)
|
||||
//if err != nil {
|
||||
// log.Error(err)
|
||||
// log.Infof("请检查端口是否被占用.")
|
||||
// time.Sleep(time.Second * 5)
|
||||
// os.Exit(1)
|
||||
//}
|
||||
}()
|
||||
}
|
||||
|
||||
@ -177,7 +171,8 @@ func GetGroupList(s *httpServer, c *gin.Context) {
|
||||
|
||||
func GetGroupInfo(s *httpServer, c *gin.Context) {
|
||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||
c.JSON(200, s.bot.CQGetGroupInfo(gid))
|
||||
nc := getParamOrDefault(c, "no_cache", "false")
|
||||
c.JSON(200, s.bot.CQGetGroupInfo(gid, nc == "true"))
|
||||
}
|
||||
|
||||
func GetGroupMemberList(s *httpServer, c *gin.Context) {
|
||||
@ -308,7 +303,8 @@ func SetGroupKick(s *httpServer, c *gin.Context) {
|
||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
||||
msg := getParam(c, "message")
|
||||
c.JSON(200, s.bot.CQSetGroupKick(gid, uid, msg))
|
||||
block := getParamOrDefault(c, "reject_add_request", "false")
|
||||
c.JSON(200, s.bot.CQSetGroupKick(gid, uid, msg, block == "true"))
|
||||
}
|
||||
|
||||
func SetGroupBan(s *httpServer, c *gin.Context) {
|
||||
@ -356,6 +352,9 @@ func SetRestart(s *httpServer, c *gin.Context) {
|
||||
|
||||
func GetForwardMessage(s *httpServer, c *gin.Context) {
|
||||
resId := getParam(c, "message_id")
|
||||
if resId == "" {
|
||||
resId = getParam(c, "id")
|
||||
}
|
||||
c.JSON(200, s.bot.CQGetForwardMessage(resId))
|
||||
}
|
||||
|
||||
@ -398,6 +397,25 @@ func GetStrangerInfo(s *httpServer, c *gin.Context) {
|
||||
c.JSON(200, s.bot.CQGetStrangerInfo(uid))
|
||||
}
|
||||
|
||||
func GetGroupAtAllRemain(s *httpServer, c *gin.Context) {
|
||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||
c.JSON(200, s.bot.CQGetAtAllRemain(gid))
|
||||
}
|
||||
|
||||
func SetGroupAnonymousBan(s *httpServer, c *gin.Context) {
|
||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||
d, _ := strconv.ParseInt(getParam(c, "duration"), 10, 64)
|
||||
flag := getParam(c, "flag")
|
||||
if flag == "" {
|
||||
flag = getParam(c, "anonymous_flag")
|
||||
}
|
||||
if flag == "" {
|
||||
o := gjson.Parse(getParam(c, "anonymous"))
|
||||
flag = o.Get("flag").String()
|
||||
}
|
||||
c.JSON(200, s.bot.CQSetGroupAnonymousBan(gid, flag, int32(d)))
|
||||
}
|
||||
|
||||
func HandleQuickOperation(s *httpServer, c *gin.Context) {
|
||||
if c.Request.Method != "POST" {
|
||||
c.AbortWithStatus(404)
|
||||
@ -515,8 +533,11 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
|
||||
"get_stranger_info": GetStrangerInfo,
|
||||
"reload_event_filter": ReloadEventFilter,
|
||||
"set_group_portrait": SetGroupPortrait,
|
||||
"set_group_anonymous_ban": SetGroupAnonymousBan,
|
||||
".handle_quick_operation": HandleQuickOperation,
|
||||
".ocr_image": OcrImage,
|
||||
"ocr_image": OcrImage,
|
||||
"get_group_at_all_remain": GetGroupAtAllRemain,
|
||||
".get_word_slices": GetWordSlices,
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -316,7 +317,7 @@ func (s *websocketServer) listenApi(c *websocketConn) {
|
||||
func (c *websocketConn) handleRequest(bot *coolq.CQBot, payload []byte) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
log.Printf("处置WS命令时发生无法恢复的异常:%v", err)
|
||||
log.Printf("处置WS命令时发生无法恢复的异常:%v\n%s", err, debug.Stack())
|
||||
c.Close()
|
||||
}
|
||||
}()
|
||||
@ -332,6 +333,14 @@ func (c *websocketConn) handleRequest(bot *coolq.CQBot, payload []byte) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
_ = c.WriteJSON(ret)
|
||||
} else {
|
||||
ret := coolq.Failed(1404, "API_NOT_FOUND", "API不存在")
|
||||
if j.Get("echo").Exists() {
|
||||
ret["echo"] = j.Get("echo").Value()
|
||||
}
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
_ = c.WriteJSON(ret)
|
||||
}
|
||||
}
|
||||
|
||||
@ -370,7 +379,7 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
||||
return bot.CQGetGroupList(p.Get("no_cache").Bool())
|
||||
},
|
||||
"get_group_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
return bot.CQGetGroupInfo(p.Get("group_id").Int())
|
||||
return bot.CQGetGroupInfo(p.Get("group_id").Int(), p.Get("no_cache").Bool())
|
||||
},
|
||||
"get_group_member_list": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
return bot.CQGetGroupMemberList(p.Get("group_id").Int(), p.Get("no_cache").Bool())
|
||||
@ -433,7 +442,7 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
||||
return bot.CQSetGroupSpecialTitle(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("special_title").Str)
|
||||
},
|
||||
"set_group_kick": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
return bot.CQSetGroupKick(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("message").Str)
|
||||
return bot.CQSetGroupKick(p.Get("group_id").Int(), p.Get("user_id").Int(), p.Get("message").Str, p.Get("reject_add_request").Bool())
|
||||
},
|
||||
"set_group_ban": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
return bot.CQSetGroupBan(p.Get("group_id").Int(), p.Get("user_id").Int(), func() uint32 {
|
||||
@ -472,7 +481,11 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
||||
return bot.CQGetImage(p.Get("file").Str)
|
||||
},
|
||||
"get_forward_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
return bot.CQGetForwardMessage(p.Get("message_id").Str)
|
||||
id := p.Get("message_id").Str
|
||||
if id == "" {
|
||||
id = p.Get("id").Str
|
||||
}
|
||||
return bot.CQGetForwardMessage(id)
|
||||
},
|
||||
"get_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
return bot.CQGetMessage(int32(p.Get("message_id").Int()))
|
||||
@ -532,12 +545,32 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
||||
".ocr_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
return bot.CQOcrImage(p.Get("image").Str)
|
||||
},
|
||||
"ocr_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
return bot.CQOcrImage(p.Get("image").Str)
|
||||
},
|
||||
"get_group_at_all_remain": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
return bot.CQGetAtAllRemain(p.Get("group_id").Int())
|
||||
},
|
||||
".get_word_slices": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
return bot.CQGetWordSlices(p.Get("content").Str)
|
||||
},
|
||||
"set_group_portrait": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
return bot.CQSetGroupPortrait(p.Get("group_id").Int(), p.Get("file").String(), p.Get("cache").String())
|
||||
},
|
||||
"set_group_anonymous_ban": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
obj := p.Get("anonymous")
|
||||
flag := p.Get("anonymous_flag")
|
||||
if !flag.Exists() {
|
||||
flag = p.Get("flag")
|
||||
}
|
||||
if !flag.Exists() && !obj.Exists() {
|
||||
return coolq.Failed(100, "FLAG_NOT_FOUND", "flag未找到")
|
||||
}
|
||||
if !flag.Exists() {
|
||||
flag = obj.Get("flag")
|
||||
}
|
||||
return bot.CQSetGroupAnonymousBan(p.Get("group_id").Int(), flag.String(), int32(p.Get("duration").Int()))
|
||||
},
|
||||
".handle_quick_operation": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
return bot.CQHandleQuickOperation(p.Get("context"), p.Get("operation"))
|
||||
},
|
||||
|
Reference in New Issue
Block a user