mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-06-30 11:53:25 +00:00
Compare commits
139 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 | |||
8f76558317 | |||
d94d389843 | |||
df0d5af07a | |||
277629e784 | |||
d66a99c5a3 | |||
55895e0de1 | |||
39da163641 | |||
1dbd72c138 | |||
31756e9e1d | |||
5ab713e7d3 | |||
b6eb559172 | |||
da2e34aaa5 | |||
beb1a2883a | |||
8f34003c6f | |||
7f3e58f97a | |||
0fc004077b | |||
e9a03b68b5 | |||
e9b39f3379 | |||
e053da62e1 | |||
f87b5c8215 | |||
28f1594539 | |||
990e7744a3 | |||
8900839018 | |||
4a3288cb8d | |||
0f0f74ece8 | |||
79ba9474a3 | |||
cb9d872071 | |||
4c3105fa24 | |||
a8176e69e6 | |||
afa356e551 | |||
a52ae1c828 | |||
b8ec05e1c1 | |||
2cbf23bceb | |||
3e5c2bc8e3 | |||
69a2360d02 | |||
5b0ede5346 | |||
80af002668 | |||
b3152bb514 | |||
9a018e2a47 | |||
998b8cb146 | |||
7e3f94ad2e | |||
f9dc22f2e5 | |||
0ce54ac21b | |||
06ac2fcb0c | |||
30f1f3199a | |||
535b4ee641 | |||
0ed6522535 | |||
3326660880 | |||
171aba527e | |||
d2bdf47bf8 | |||
4c2b56457e | |||
8b5d63e02c | |||
7dd0001dc8 | |||
7f9e4e6a20 | |||
f59ce1480e | |||
c2c7b96f1b | |||
c49c68891b | |||
5b394b7a78 | |||
0cc3d90581 | |||
f9c0b94af6 | |||
4c9f60da09 |
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -28,7 +28,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Setup Go environment
|
- name: Setup Go environment
|
||||||
uses: actions/setup-go@v2.1.1
|
uses: actions/setup-go@v2.1.3
|
||||||
with:
|
with:
|
||||||
go-version: 1.15
|
go-version: 1.15
|
||||||
|
|
||||||
|
4
.github/workflows/release.yml
vendored
4
.github/workflows/release.yml
vendored
@ -20,8 +20,8 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Set RELEASE_VERSION env
|
- name: Set RELEASE_VERSION env
|
||||||
run: echo ::set-env name=RELEASE_VERSION::${GITHUB_REF:10}
|
run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV
|
||||||
- uses: wangyoucao577/go-release-action@master
|
- uses: pcrbot/go-release-action@master
|
||||||
env:
|
env:
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
with:
|
with:
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
FROM golang:1.14.7-alpine AS builder
|
FROM golang:1.15.5-alpine AS builder
|
||||||
|
|
||||||
RUN go env -w GO111MODULE=auto \
|
RUN go env -w GO111MODULE=auto \
|
||||||
&& go env -w CGO_ENABLED=0 \
|
&& go env -w CGO_ENABLED=0 \
|
||||||
&& mkdir /build
|
&& go env -w GOPROXY=https://goproxy.cn,direct
|
||||||
|
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
|
|
||||||
COPY ./ .
|
COPY ./ .
|
||||||
|
|
||||||
RUN cd /build \
|
RUN set -ex \
|
||||||
&& go build -ldflags "-s -w -extldflags '-static'" -o cqhttp
|
&& cd /build \
|
||||||
|
&& go build -ldflags "-s -w -extldflags '-static'" -o cqhttp
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
|
239
README.md
239
README.md
@ -20,80 +20,205 @@
|
|||||||
- [x] 消息撤回事件
|
- [x] 消息撤回事件
|
||||||
- [x] 解析/发送 回复消息
|
- [x] 解析/发送 回复消息
|
||||||
- [x] 解析/发送 合并转发
|
- [x] 解析/发送 合并转发
|
||||||
- [ ] 使用代理请求网络图片
|
- [x] 使用代理请求网络图片
|
||||||
|
|
||||||
#### 实现
|
#### 实现
|
||||||
<details>
|
<details>
|
||||||
<summary>已实现CQ码</summary>
|
<summary>已实现CQ码</summary>
|
||||||
|
|
||||||
- [CQ:image]
|
##### 符合Onebot标准的CQ码
|
||||||
- [CQ:record]
|
| CQ码 | 功能 |
|
||||||
- [CQ:video]
|
| ------------ | ---------------------------- |
|
||||||
- [CQ:face]
|
| [CQ:face] | [QQ表情] |
|
||||||
- [CQ:at]
|
| [CQ:record] | [语音] |
|
||||||
- [CQ:share]
|
| [CQ:video] | [短视频] |
|
||||||
- [CQ:reply]
|
| [CQ:at] | [@某人] |
|
||||||
- [CQ:forward]
|
| [CQ:share] | [链接分享] |
|
||||||
- [CQ:node]
|
| [CQ:music] | [音乐分享] [音乐自定义分享] |
|
||||||
- [CQ:gift]
|
| [CQ:reply] | [回复] |
|
||||||
- [CQ:redbag]
|
| [CQ:forward] | [合并转发] |
|
||||||
- [CQ:tts]
|
| [CQ:node] | [合并转发节点] |
|
||||||
- [CQ:music]
|
| [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>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>已实现API</summary>
|
<summary>已实现API</summary>
|
||||||
|
|
||||||
##### 注意: 部分API实现与CQHTTP原版略有差异,请参考文档
|
##### 符合Onebot标准的API
|
||||||
| API | 功能 |
|
| API | 功能 |
|
||||||
| ------------------------ | ------------------------------------------------------------ |
|
| ------------------------ | ---------------------- |
|
||||||
| /get_login_info | [获取登录号信息](https://cqhttp.cc/docs/4.15/#/API?id=get_login_info-获取登录号信息) |
|
| /send_private_msg | [发送私聊消息] |
|
||||||
| /get_friend_list | [获取好友列表](https://cqhttp.cc/docs/4.15/#/API?id=get_friend_list-获取好友列表) |
|
| /send_group_msg | [发送群消息] |
|
||||||
| /get_group_list | [获取群列表](https://cqhttp.cc/docs/4.15/#/API?id=get_group_list-获取群列表) |
|
| /send_msg | [发送消息] |
|
||||||
| /get_group_info | [获取群信息](https://cqhttp.cc/docs/4.15/#/API?id=get_group_info-获取群信息) |
|
| /delete_msg | [撤回信息] |
|
||||||
| /get_group_member_list | [获取群成员列表](https://cqhttp.cc/docs/4.15/#/API?id=get_group_member_list-获取群成员列表) |
|
| /set_group_kick | [群组踢人] |
|
||||||
| /get_group_member_info | [获取群成员信息](https://cqhttp.cc/docs/4.15/#/API?id=get_group_member_info-获取群成员信息) |
|
| /set_group_ban | [群组单人禁言] |
|
||||||
| /send_msg | [发送消息](https://cqhttp.cc/docs/4.15/#/API?id=send_msg-发送消息) |
|
| /set_group_whole_ban | [群组全员禁言] |
|
||||||
| /send_group_msg | [发送群消息](https://cqhttp.cc/docs/4.15/#/API?id=send_group_msg-发送群消息) |
|
| /set_group_admin | [群组设置管理员] |
|
||||||
| /send_private_msg | [发送私聊消息](https://cqhttp.cc/docs/4.15/#/API?id=send_private_msg-发送私聊消息) |
|
| /set_group_card | [设置群名片(群备注)] |
|
||||||
| /delete_msg | [撤回信息](https://cqhttp.cc/docs/4.15/#/API?id=delete_msg-撤回消息) |
|
| /set_group_name | [设置群名] |
|
||||||
| /set_friend_add_request | [处理加好友请求](https://cqhttp.cc/docs/4.15/#/API?id=set_friend_add_request-处理加好友请求) |
|
| /set_group_leave | [退出群组] |
|
||||||
| /set_group_add_request | [处理加群请求/邀请](https://cqhttp.cc/docs/4.15/#/API?id=set_group_add_request-处理加群请求/邀请) |
|
| /set_group_special_title | [设置群组专属头衔] |
|
||||||
| /set_group_card | [设置群名片(群备注)](https://cqhttp.cc/docs/4.15/#/API?id=set_group_card-设置群名片(群备注)) |
|
| /set_friend_add_request | [处理加好友请求] |
|
||||||
| /set_group_special_title | [设置群组专属头衔](https://cqhttp.cc/docs/4.15/#/API?id=set_group_special_title-设置群组专属头衔) |
|
| /set_group_add_request | [处理加群请求/邀请] |
|
||||||
| /set_group_kick | [群组T人](https://cqhttp.cc/docs/4.15/#/API?id=set_group_kick-群组踢人) |
|
| /get_login_info | [获取登录号信息] |
|
||||||
| /set_group_ban | [群组单人禁言](https://cqhttp.cc/docs/4.15/#/API?id=set_group_ban-群组单人禁言) |
|
| /get_stranger_info | [获取陌生人信息] |
|
||||||
| /set_group_whole_ban | [群组全员禁言](https://cqhttp.cc/docs/4.15/#/API?id=set_group_whole_ban-群组全员禁言) |
|
| /get_friend_list | [获取好友列表] |
|
||||||
| /set_group_leave | [退出群组](https://cqhttp.cc/docs/4.15/#/API?id=set_group_leave-退出群组) |
|
| /get_group_info | [获取群信息] |
|
||||||
| /set_group_name | 设置群组名(拓展API) |
|
| /get_group_list | [获取群列表] |
|
||||||
| /get_image | 获取图片信息(拓展API) |
|
| /get_group_member_info | [获取群成员信息] |
|
||||||
| /get_msg | [获取消息]() | <!-- TODO 来人补个链接-->
|
| /get_group_member_list | [获取群成员列表] |
|
||||||
| /can_send_image | [检查是否可以发送图片](https://cqhttp.cc/docs/4.15/#/API?id=can_send_image-检查是否可以发送图片) |
|
| /get_group_honor_info | [获取群荣誉信息] |
|
||||||
| /can_send_record | [检查是否可以发送语音](https://cqhttp.cc/docs/4.15/#/API?id=can_send_record-检查是否可以发送语音) |
|
| /can_send_image | [检查是否可以发送图片] |
|
||||||
| /get_status | [获取插件运行状态](https://cqhttp.cc/docs/4.15/#/API?id=get_status-获取插件运行状态) |
|
| /can_send_record | [检查是否可以发送语音] |
|
||||||
| /get_version_info | [获取 酷Q 及 CQHTTP插件的版本信息](https://cqhttp.cc/docs/4.15/#/API?id=get_version_info-获取-酷q-及-cqhttp-插件的版本信息) |
|
| /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>
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>已实现Event</summary>
|
<summary>已实现Event</summary>
|
||||||
|
|
||||||
##### 注意: 部分Event数据与CQHTTP原版略有差异,请参考文档
|
##### 符合Onebot标准的Event(部分Event比Onebot标准多上报几个字段,不影响使用)
|
||||||
| Event |
|
| 事件类型 | Event |
|
||||||
| ------------------------------------------------------------ |
|
| -------- | ---------------- |
|
||||||
| [私聊信息](https://cqhttp.cc/docs/4.15/#/Post?id=私聊消息) |
|
| 消息事件 | [私聊信息] |
|
||||||
| [群消息](https://cqhttp.cc/docs/4.15/#/Post?id=群消息) |
|
| 消息事件 | [群消息] |
|
||||||
| [群消息撤回(拓展Event)](docs/cqhttp.md#群消息撤回) |
|
| 通知事件 | [群文件上传] |
|
||||||
| [好友消息撤回(拓展Event)](docs/cqhttp.md#好友消息撤回) |
|
| 通知事件 | [群管理员变动] |
|
||||||
| [群内提示事件(拓展Event)(龙王等事件)](docs/cqhttp.md#群内戳一戳) |
|
| 通知事件 | [群成员减少] |
|
||||||
| [群管理员变动](https://cqhttp.cc/docs/4.15/#/Post?id=群管理员变动) |
|
| 通知事件 | [群成员增加] |
|
||||||
| [群成员减少](https://cqhttp.cc/docs/4.15/#/Post?id=群成员减少) |
|
| 通知事件 | [群禁言] |
|
||||||
| [群成员增加](https://cqhttp.cc/docs/4.15/#/Post?id=群成员增加) |
|
| 通知事件 | [好友添加] |
|
||||||
| [群禁言](https://cqhttp.cc/docs/4.15/#/Post?id=群禁言) |
|
| 通知事件 | [群消息撤回] |
|
||||||
| [群文件上传](https://cqhttp.cc/docs/4.15/#/Post?id=群文件上传) |
|
| 通知事件 | [好友消息撤回] |
|
||||||
| [加好友请求](https://cqhttp.cc/docs/4.15/#/Post?id=加好友请求) |
|
| 通知事件 | [群内戳一戳] |
|
||||||
| [加群请求/邀请](https://cqhttp.cc/docs/4.15/#/Post?id=加群请求/邀请) |
|
| 通知事件 | [群红包运气王] |
|
||||||
|
| 通知事件 | [群成员荣誉变更] |
|
||||||
|
| 请求事件 | [加好友请求] |
|
||||||
|
| 请求事件 | [加群请求/邀请] |
|
||||||
|
|
||||||
|
[私聊信息]: 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>
|
</details>
|
||||||
|
|
||||||
|
158
coolq/api.go
158
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
|
// 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)
|
group := bot.Client.FindGroup(groupId)
|
||||||
if group == nil {
|
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{
|
return OK(MSG{
|
||||||
"group_id": group.Code,
|
"group_id": group.Code,
|
||||||
@ -72,13 +79,13 @@ func (bot *CQBot) CQGetGroupInfo(groupId int64) MSG {
|
|||||||
func (bot *CQBot) CQGetGroupMemberList(groupId int64, noCache bool) MSG {
|
func (bot *CQBot) CQGetGroupMemberList(groupId int64, noCache bool) MSG {
|
||||||
group := bot.Client.FindGroup(groupId)
|
group := bot.Client.FindGroup(groupId)
|
||||||
if group == nil {
|
if group == nil {
|
||||||
return Failed(100)
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
if noCache {
|
if noCache {
|
||||||
t, err := bot.Client.GetGroupMembers(group)
|
t, err := bot.Client.GetGroupMembers(group)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("刷新群 %v 成员列表失败: %v", groupId, err)
|
log.Warnf("刷新群 %v 成员列表失败: %v", groupId, err)
|
||||||
return Failed(100)
|
return Failed(100, "GET_MEMBERS_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
group.Members = t
|
group.Members = t
|
||||||
}
|
}
|
||||||
@ -93,11 +100,11 @@ func (bot *CQBot) CQGetGroupMemberList(groupId int64, noCache bool) MSG {
|
|||||||
func (bot *CQBot) CQGetGroupMemberInfo(groupId, userId int64) MSG {
|
func (bot *CQBot) CQGetGroupMemberInfo(groupId, userId int64) MSG {
|
||||||
group := bot.Client.FindGroup(groupId)
|
group := bot.Client.FindGroup(groupId)
|
||||||
if group == nil {
|
if group == nil {
|
||||||
return Failed(100)
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
member := group.FindMember(userId)
|
member := group.FindMember(userId)
|
||||||
if member == nil {
|
if member == nil {
|
||||||
return Failed(102)
|
return Failed(100, "MEMBER_NOT_FOUND", "群员不存在")
|
||||||
}
|
}
|
||||||
return OK(convertGroupMemberInfo(groupId, member))
|
return OK(convertGroupMemberInfo(groupId, member))
|
||||||
}
|
}
|
||||||
@ -106,7 +113,7 @@ func (bot *CQBot) CQGetGroupFileSystemInfo(groupId int64) MSG {
|
|||||||
fs, err := bot.Client.GetGroupFileSystem(groupId)
|
fs, err := bot.Client.GetGroupFileSystem(groupId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取群 %v 文件系统信息失败: %v", groupId, err)
|
log.Errorf("获取群 %v 文件系统信息失败: %v", groupId, err)
|
||||||
return Failed(100)
|
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
return OK(fs)
|
return OK(fs)
|
||||||
}
|
}
|
||||||
@ -115,12 +122,12 @@ func (bot *CQBot) CQGetGroupRootFiles(groupId int64) MSG {
|
|||||||
fs, err := bot.Client.GetGroupFileSystem(groupId)
|
fs, err := bot.Client.GetGroupFileSystem(groupId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取群 %v 文件系统信息失败: %v", groupId, err)
|
log.Errorf("获取群 %v 文件系统信息失败: %v", groupId, err)
|
||||||
return Failed(100)
|
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
files, folders, err := fs.Root()
|
files, folders, err := fs.Root()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取群 %v 根目录文件失败: %v", groupId, err)
|
log.Errorf("获取群 %v 根目录文件失败: %v", groupId, err)
|
||||||
return Failed(100)
|
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
return OK(MSG{
|
return OK(MSG{
|
||||||
"files": files,
|
"files": files,
|
||||||
@ -132,12 +139,12 @@ func (bot *CQBot) CQGetGroupFilesByFolderId(groupId int64, folderId string) MSG
|
|||||||
fs, err := bot.Client.GetGroupFileSystem(groupId)
|
fs, err := bot.Client.GetGroupFileSystem(groupId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取群 %v 文件系统信息失败: %v", groupId, err)
|
log.Errorf("获取群 %v 文件系统信息失败: %v", groupId, err)
|
||||||
return Failed(100)
|
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
files, folders, err := fs.GetFilesByFolder(folderId)
|
files, folders, err := fs.GetFilesByFolder(folderId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取群 %v 根目录 %v 子文件失败: %v", groupId, folderId, err)
|
log.Errorf("获取群 %v 根目录 %v 子文件失败: %v", groupId, folderId, err)
|
||||||
return Failed(100)
|
return Failed(100, "FILE_SYSTEM_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
return OK(MSG{
|
return OK(MSG{
|
||||||
"files": files,
|
"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 {
|
func (bot *CQBot) CQGetGroupFileUrl(groupId int64, fileId string, busId int32) MSG {
|
||||||
url := bot.Client.GetGroupFileUrl(groupId, fileId, busId)
|
url := bot.Client.GetGroupFileUrl(groupId, fileId, busId)
|
||||||
if url == "" {
|
if url == "" {
|
||||||
return Failed(100)
|
return Failed(100, "FILE_SYSTEM_API_ERROR")
|
||||||
}
|
}
|
||||||
return OK(MSG{
|
return OK(MSG{
|
||||||
"url": url,
|
"url": url,
|
||||||
@ -158,7 +165,7 @@ func (bot *CQBot) CQGetGroupFileUrl(groupId int64, fileId string, busId int32) M
|
|||||||
func (bot *CQBot) CQGetWordSlices(content string) MSG {
|
func (bot *CQBot) CQGetWordSlices(content string) MSG {
|
||||||
slices, err := bot.Client.GetWordSegmentation(content)
|
slices, err := bot.Client.GetWordSegmentation(content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Failed(100)
|
return Failed(100, "WORD_SEGMENTATION_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
for i := 0; i < len(slices); i++ {
|
for i := 0; i < len(slices); i++ {
|
||||||
slices[i] = strings.ReplaceAll(slices[i], "\u0000", "")
|
slices[i] = strings.ReplaceAll(slices[i], "\u0000", "")
|
||||||
@ -188,7 +195,7 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bo
|
|||||||
fixAt(elem)
|
fixAt(elem)
|
||||||
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
||||||
if mid == -1 {
|
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)
|
log.Infof("发送群 %v(%v) 的消息: %v (%v)", groupId, groupId, limitedString(m.String()), mid)
|
||||||
return OK(MSG{"message_id": mid})
|
return OK(MSG{"message_id": mid})
|
||||||
@ -204,7 +211,7 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bo
|
|||||||
}
|
}
|
||||||
if str == "" {
|
if str == "" {
|
||||||
log.Warnf("群消息发送失败: 信息为空. MSG: %v", i)
|
log.Warnf("群消息发送失败: 信息为空. MSG: %v", i)
|
||||||
return Failed(100)
|
return Failed(100, "EMPTY_MSG_ERROR", "消息为空")
|
||||||
}
|
}
|
||||||
var elem []message.IMessageElement
|
var elem []message.IMessageElement
|
||||||
if autoEscape {
|
if autoEscape {
|
||||||
@ -215,7 +222,7 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bo
|
|||||||
fixAt(elem)
|
fixAt(elem)
|
||||||
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
||||||
if mid == -1 {
|
if mid == -1 {
|
||||||
return Failed(100)
|
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
||||||
}
|
}
|
||||||
log.Infof("发送群 %v(%v) 的消息: %v (%v)", groupId, groupId, limitedString(str), mid)
|
log.Infof("发送群 %v(%v) 的消息: %v (%v)", groupId, groupId, limitedString(str), mid)
|
||||||
return OK(MSG{"message_id": mid})
|
return OK(MSG{"message_id": mid})
|
||||||
@ -312,7 +319,7 @@ func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}, autoEscape b
|
|||||||
elem := bot.ConvertObjectMessage(m, true)
|
elem := bot.ConvertObjectMessage(m, true)
|
||||||
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
||||||
if mid == -1 {
|
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)
|
log.Infof("发送好友 %v(%v) 的消息: %v (%v)", userId, userId, limitedString(m.String()), mid)
|
||||||
return OK(MSG{"message_id": mid})
|
return OK(MSG{"message_id": mid})
|
||||||
@ -327,7 +334,7 @@ func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}, autoEscape b
|
|||||||
str = s
|
str = s
|
||||||
}
|
}
|
||||||
if str == "" {
|
if str == "" {
|
||||||
return Failed(100)
|
return Failed(100, "EMPTY_MSG_ERROR", "消息为空")
|
||||||
}
|
}
|
||||||
var elem []message.IMessageElement
|
var elem []message.IMessageElement
|
||||||
if autoEscape {
|
if autoEscape {
|
||||||
@ -337,7 +344,7 @@ func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}, autoEscape b
|
|||||||
}
|
}
|
||||||
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
||||||
if mid == -1 {
|
if mid == -1 {
|
||||||
return Failed(100)
|
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
||||||
}
|
}
|
||||||
log.Infof("发送好友 %v(%v) 的消息: %v (%v)", userId, userId, limitedString(str), mid)
|
log.Infof("发送好友 %v(%v) 的消息: %v (%v)", userId, userId, limitedString(str), mid)
|
||||||
return OK(MSG{"message_id": mid})
|
return OK(MSG{"message_id": mid})
|
||||||
@ -351,7 +358,7 @@ func (bot *CQBot) CQSetGroupCard(groupId, userId int64, card string) MSG {
|
|||||||
return OK(nil)
|
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
|
// 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 +369,7 @@ func (bot *CQBot) CQSetGroupSpecialTitle(groupId, userId int64, title string) MS
|
|||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Failed(100)
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQSetGroupName(groupId int64, name string) MSG {
|
func (bot *CQBot) CQSetGroupName(groupId int64, name string) MSG {
|
||||||
@ -370,7 +377,7 @@ func (bot *CQBot) CQSetGroupName(groupId int64, name string) MSG {
|
|||||||
g.UpdateName(name)
|
g.UpdateName(name)
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
return Failed(100)
|
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQSetGroupMemo(groupId int64, msg string) MSG {
|
func (bot *CQBot) CQSetGroupMemo(groupId int64, msg string) MSG {
|
||||||
@ -378,18 +385,18 @@ func (bot *CQBot) CQSetGroupMemo(groupId int64, msg string) MSG {
|
|||||||
g.UpdateMemo(msg)
|
g.UpdateMemo(msg)
|
||||||
return OK(nil)
|
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
|
// 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 g := bot.Client.FindGroup(groupId); g != nil {
|
||||||
if m := g.FindMember(userId); m != nil {
|
if m := g.FindMember(userId); m != nil {
|
||||||
m.Kick(msg)
|
m.Kick(msg, block)
|
||||||
return OK(nil)
|
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
|
// 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 +407,7 @@ func (bot *CQBot) CQSetGroupBan(groupId, userId int64, duration uint32) MSG {
|
|||||||
return OK(nil)
|
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
|
// 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 +416,7 @@ func (bot *CQBot) CQSetGroupWholeBan(groupId int64, enable bool) MSG {
|
|||||||
g.MuteAll(enable)
|
g.MuteAll(enable)
|
||||||
return OK(nil)
|
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
|
// 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 +425,14 @@ func (bot *CQBot) CQSetGroupLeave(groupId int64) MSG {
|
|||||||
g.Quit()
|
g.Quit()
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
return Failed(100)
|
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
|
// 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 {
|
func (bot *CQBot) CQProcessFriendRequest(flag string, approve bool) MSG {
|
||||||
req, ok := bot.friendReqCache.Load(flag)
|
req, ok := bot.friendReqCache.Load(flag)
|
||||||
if !ok {
|
if !ok {
|
||||||
return Failed(100)
|
return Failed(100, "FLAG_NOT_FOUND", "FLAG不存在")
|
||||||
}
|
}
|
||||||
if approve {
|
if approve {
|
||||||
req.(*client.NewFriendRequest).Accept()
|
req.(*client.NewFriendRequest).Accept()
|
||||||
@ -440,14 +447,14 @@ func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bo
|
|||||||
msgs, err := bot.Client.GetGroupSystemMessages()
|
msgs, err := bot.Client.GetGroupSystemMessages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("获取群系统消息失败: %v", err)
|
log.Errorf("获取群系统消息失败: %v", err)
|
||||||
return Failed(100)
|
return Failed(100, "SYSTEM_MSG_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
if subType == "add" {
|
if subType == "add" {
|
||||||
for _, req := range msgs.JoinRequests {
|
for _, req := range msgs.JoinRequests {
|
||||||
if strconv.FormatInt(req.RequestId, 10) == flag {
|
if strconv.FormatInt(req.RequestId, 10) == flag {
|
||||||
if req.Checked {
|
if req.Checked {
|
||||||
log.Errorf("处理群系统消息失败: 无法操作已处理的消息.")
|
log.Errorf("处理群系统消息失败: 无法操作已处理的消息.")
|
||||||
return Failed(100)
|
return Failed(100, "FLAG_HAS_BEEN_CHECKED", "消息已被处理")
|
||||||
}
|
}
|
||||||
if approve {
|
if approve {
|
||||||
req.Accept()
|
req.Accept()
|
||||||
@ -462,7 +469,7 @@ func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bo
|
|||||||
if strconv.FormatInt(req.RequestId, 10) == flag {
|
if strconv.FormatInt(req.RequestId, 10) == flag {
|
||||||
if req.Checked {
|
if req.Checked {
|
||||||
log.Errorf("处理群系统消息失败: 无法操作已处理的消息.")
|
log.Errorf("处理群系统消息失败: 无法操作已处理的消息.")
|
||||||
return Failed(100)
|
return Failed(100, "FLAG_HAS_BEEN_CHECKED", "消息已被处理")
|
||||||
}
|
}
|
||||||
if approve {
|
if approve {
|
||||||
req.Accept()
|
req.Accept()
|
||||||
@ -474,23 +481,29 @@ func (bot *CQBot) CQProcessGroupRequest(flag, subType, reason string, approve bo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Errorf("处理群系统消息失败: 消息 %v 不存在.", flag)
|
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
|
// 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 {
|
func (bot *CQBot) CQDeleteMessage(messageId int32) MSG {
|
||||||
msg := bot.GetMessage(messageId)
|
msg := bot.GetMessage(messageId)
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
return Failed(100)
|
return Failed(100, "MESSAGE_NOT_FOUND", "消息不存在")
|
||||||
}
|
}
|
||||||
if _, ok := msg["group"]; ok {
|
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 {
|
} else {
|
||||||
if msg["sender"].(message.Sender).Uin != bot.Client.Uin {
|
if msg["sender"].(message.Sender).Uin != bot.Client.Uin {
|
||||||
log.Warnf("撤回 %v 失败: 好友会话无法撤回对方消息.")
|
log.Warnf("撤回 %v 失败: 好友会话无法撤回对方消息.", messageId)
|
||||||
return Failed(100)
|
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)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
@ -499,29 +512,28 @@ func (bot *CQBot) CQDeleteMessage(messageId int32) MSG {
|
|||||||
func (bot *CQBot) CQSetGroupAdmin(groupId, userId int64, enable bool) MSG {
|
func (bot *CQBot) CQSetGroupAdmin(groupId, userId int64, enable bool) MSG {
|
||||||
group := bot.Client.FindGroup(groupId)
|
group := bot.Client.FindGroup(groupId)
|
||||||
if group == nil || group.OwnerUin != bot.Client.Uin {
|
if group == nil || group.OwnerUin != bot.Client.Uin {
|
||||||
return Failed(100)
|
return Failed(100, "PERMISSION_DENIED", "群不存在或权限不足")
|
||||||
}
|
}
|
||||||
mem := group.FindMember(userId)
|
mem := group.FindMember(userId)
|
||||||
if mem == nil {
|
if mem == nil {
|
||||||
return Failed(100)
|
return Failed(100, "GROUP_MEMBER_NOT_FOUND", "群成员不存在")
|
||||||
}
|
}
|
||||||
mem.SetAdmin(enable)
|
mem.SetAdmin(enable)
|
||||||
t, err := bot.Client.GetGroupMembers(group)
|
t, err := bot.Client.GetGroupMembers(group)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("刷新群 %v 成员列表失败: %v", groupId, err)
|
log.Warnf("刷新群 %v 成员列表失败: %v", groupId, err)
|
||||||
return Failed(100)
|
return Failed(100, "GET_MEMBERS_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
group.Members = t
|
group.Members = t
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQGetVipInfo(userId int64) MSG {
|
func (bot *CQBot) CQGetVipInfo(userId int64) MSG {
|
||||||
msg := MSG{}
|
|
||||||
vip, err := bot.Client.GetVipInfo(userId)
|
vip, err := bot.Client.GetVipInfo(userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Failed(100)
|
return Failed(100, "VIP_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
msg = MSG{
|
msg := MSG{
|
||||||
"user_id": vip.Uin,
|
"user_id": vip.Uin,
|
||||||
"nickname": vip.Name,
|
"nickname": vip.Name,
|
||||||
"level": vip.Level,
|
"level": vip.Level,
|
||||||
@ -592,7 +604,7 @@ func (bot *CQBot) CQGetGroupHonorInfo(groupId int64, t string) MSG {
|
|||||||
func (bot *CQBot) CQGetStrangerInfo(userId int64) MSG {
|
func (bot *CQBot) CQGetStrangerInfo(userId int64) MSG {
|
||||||
info, err := bot.Client.GetSummaryInfo(userId)
|
info, err := bot.Client.GetSummaryInfo(userId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Failed(100)
|
return Failed(100, "SUMMARY_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
return OK(MSG{
|
return OK(MSG{
|
||||||
"user_id": info.Uin,
|
"user_id": info.Uin,
|
||||||
@ -640,7 +652,7 @@ func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
|||||||
bot.CQDeleteMessage(int32(context.Get("message_id").Int()))
|
bot.CQDeleteMessage(int32(context.Get("message_id").Int()))
|
||||||
}
|
}
|
||||||
if operation.Get("kick").Bool() && !isAnonymous {
|
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() {
|
if operation.Get("ban").Bool() {
|
||||||
var duration uint32 = 30 * 60
|
var duration uint32 = 30 * 60
|
||||||
@ -687,14 +699,15 @@ func (bot *CQBot) CQGetImage(file string) MSG {
|
|||||||
}
|
}
|
||||||
msg["file"] = local
|
msg["file"] = local
|
||||||
return OK(msg)
|
return OK(msg)
|
||||||
|
} else {
|
||||||
|
return Failed(100, "LOAD_FILE_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
return Failed(100)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) CQGetForwardMessage(resId string) MSG {
|
func (bot *CQBot) CQGetForwardMessage(resId string) MSG {
|
||||||
m := bot.Client.GetForwardMessage(resId)
|
m := bot.Client.GetForwardMessage(resId)
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return Failed(100)
|
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
|
||||||
}
|
}
|
||||||
r := make([]MSG, 0)
|
r := make([]MSG, 0)
|
||||||
for _, n := range m.Nodes {
|
for _, n := range m.Nodes {
|
||||||
@ -716,20 +729,27 @@ func (bot *CQBot) CQGetForwardMessage(resId string) MSG {
|
|||||||
func (bot *CQBot) CQGetMessage(messageId int32) MSG {
|
func (bot *CQBot) CQGetMessage(messageId int32) MSG {
|
||||||
msg := bot.GetMessage(messageId)
|
msg := bot.GetMessage(messageId)
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
return Failed(100)
|
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
|
||||||
}
|
}
|
||||||
sender := msg["sender"].(message.Sender)
|
sender := msg["sender"].(message.Sender)
|
||||||
_, group := msg["group"]
|
gid, isGroup := msg["group"]
|
||||||
|
raw := msg["message"].(string)
|
||||||
return OK(MSG{
|
return OK(MSG{
|
||||||
"message_id": messageId,
|
"message_id": messageId,
|
||||||
"real_id": msg["message-id"],
|
"real_id": msg["message-id"],
|
||||||
"group": group,
|
"group": isGroup,
|
||||||
|
"group_id": gid,
|
||||||
"sender": MSG{
|
"sender": MSG{
|
||||||
"user_id": sender.Uin,
|
"user_id": sender.Uin,
|
||||||
"nickname": sender.Nickname,
|
"nickname": sender.Nickname,
|
||||||
},
|
},
|
||||||
"time": msg["time"],
|
"time": msg["time"],
|
||||||
"message": msg["message"],
|
"message": ToFormattedMessage(bot.ConvertStringMessage(raw, isGroup), func() int64 {
|
||||||
|
if isGroup {
|
||||||
|
return gid.(int64)
|
||||||
|
}
|
||||||
|
return sender.Uin
|
||||||
|
}(), false),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -737,7 +757,7 @@ func (bot *CQBot) CQGetGroupSystemMessages() MSG {
|
|||||||
msg, err := bot.Client.GetGroupSystemMessages()
|
msg, err := bot.Client.GetGroupSystemMessages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("获取群系统消息失败: %v", err)
|
log.Warnf("获取群系统消息失败: %v", err)
|
||||||
return Failed(100)
|
return Failed(100, "SYSTEM_MSG_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
return OK(msg)
|
return OK(msg)
|
||||||
}
|
}
|
||||||
@ -754,12 +774,12 @@ func (bot *CQBot) CQOcrImage(imageId string) MSG {
|
|||||||
img, err := bot.makeImageElem(map[string]string{"file": imageId}, true)
|
img, err := bot.makeImageElem(map[string]string{"file": imageId}, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("load image error: %v", err)
|
log.Warnf("load image error: %v", err)
|
||||||
return Failed(100)
|
return Failed(100, "LOAD_FILE_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
rsp, err := bot.Client.ImageOcr(img)
|
rsp, err := bot.Client.ImageOcr(img)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("ocr image error: %v", err)
|
log.Warnf("ocr image error: %v", err)
|
||||||
return Failed(100)
|
return Failed(100, "OCR_API_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
return OK(rsp)
|
return OK(rsp)
|
||||||
}
|
}
|
||||||
@ -774,14 +794,15 @@ func (bot *CQBot) CQSetGroupPortrait(groupId int64, file, cache string) MSG {
|
|||||||
img, err := global.FindFile(file, cache, global.IMAGE_PATH)
|
img, err := global.FindFile(file, cache, global.IMAGE_PATH)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("set group portrait error: %v", err)
|
log.Warnf("set group portrait error: %v", err)
|
||||||
return Failed(100)
|
return Failed(100, "LOAD_FILE_ERROR", err.Error())
|
||||||
}
|
}
|
||||||
g.UpdateGroupHeadPortrait(img)
|
g.UpdateGroupHeadPortrait(img)
|
||||||
return OK(nil)
|
return OK(nil)
|
||||||
}
|
}
|
||||||
return Failed(100)
|
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 {
|
func (bot *CQBot) CQGetStatus() MSG {
|
||||||
return OK(MSG{
|
return OK(MSG{
|
||||||
"app_initialized": true,
|
"app_initialized": true,
|
||||||
@ -789,7 +810,8 @@ func (bot *CQBot) CQGetStatus() MSG {
|
|||||||
"plugins_good": nil,
|
"plugins_good": nil,
|
||||||
"app_good": true,
|
"app_good": true,
|
||||||
"online": bot.Client.Online,
|
"online": bot.Client.Online,
|
||||||
"good": true,
|
"good": bot.Client.Online,
|
||||||
|
"stat": bot.Client.GetStatistics(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -807,12 +829,14 @@ func (bot *CQBot) CQGetVersionInfo() MSG {
|
|||||||
"version": Version,
|
"version": Version,
|
||||||
"protocol": func() int {
|
"protocol": func() int {
|
||||||
switch client.SystemDeviceInfo.Protocol {
|
switch client.SystemDeviceInfo.Protocol {
|
||||||
case client.AndroidPad:
|
case client.IPad:
|
||||||
return 0
|
return 0
|
||||||
case client.AndroidPhone:
|
case client.AndroidPhone:
|
||||||
return 1
|
return 1
|
||||||
case client.AndroidWatch:
|
case client.AndroidWatch:
|
||||||
return 2
|
return 2
|
||||||
|
case client.MacOS:
|
||||||
|
return 3
|
||||||
default:
|
default:
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
@ -824,8 +848,16 @@ func OK(data interface{}) MSG {
|
|||||||
return MSG{"data": data, "retcode": 0, "status": "ok"}
|
return MSG{"data": data, "retcode": 0, "status": "ok"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Failed(code int) MSG {
|
func Failed(code int, msg ...string) MSG {
|
||||||
return MSG{"data": nil, "retcode": code, "status": "failed"}
|
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 {
|
func convertGroupMemberInfo(groupId int64, m *client.GroupMemberInfo) MSG {
|
||||||
|
38
coolq/bot.go
38
coolq/bot.go
@ -3,23 +3,26 @@ package coolq
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/syndtr/goleveldb/leveldb"
|
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
"path"
|
"path"
|
||||||
|
"runtime/debug"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/syndtr/goleveldb/leveldb"
|
||||||
|
|
||||||
"github.com/Mrs4s/MiraiGo/binary"
|
"github.com/Mrs4s/MiraiGo/binary"
|
||||||
"github.com/Mrs4s/MiraiGo/client"
|
"github.com/Mrs4s/MiraiGo/client"
|
||||||
"github.com/Mrs4s/MiraiGo/message"
|
"github.com/Mrs4s/MiraiGo/message"
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
|
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||||
|
|
||||||
type CQBot struct {
|
type CQBot struct {
|
||||||
Client *client.QQClient
|
Client *client.QQClient
|
||||||
|
|
||||||
@ -42,7 +45,7 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot {
|
|||||||
p := path.Join("data", "leveldb")
|
p := path.Join("data", "leveldb")
|
||||||
db, err := leveldb.OpenFile(p, nil)
|
db, err := leveldb.OpenFile(p, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("打开数据库失败, 如果频繁遇到此问题请清理 data/db 文件夹或关闭数据库功能。")
|
log.Fatalf("打开数据库失败, 如果频繁遇到此问题请清理 data/leveldb 文件夹或关闭数据库功能。")
|
||||||
}
|
}
|
||||||
bot.db = db
|
bot.db = db
|
||||||
gob.Register(message.Sender{})
|
gob.Register(message.Sender{})
|
||||||
@ -56,6 +59,7 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot {
|
|||||||
bot.Client.OnGroupMuted(bot.groupMutedEvent)
|
bot.Client.OnGroupMuted(bot.groupMutedEvent)
|
||||||
bot.Client.OnGroupMessageRecalled(bot.groupRecallEvent)
|
bot.Client.OnGroupMessageRecalled(bot.groupRecallEvent)
|
||||||
bot.Client.OnGroupNotify(bot.groupNotifyEvent)
|
bot.Client.OnGroupNotify(bot.groupNotifyEvent)
|
||||||
|
bot.Client.OnFriendNotify(bot.friendNotifyEvent)
|
||||||
bot.Client.OnFriendMessageRecalled(bot.friendRecallEvent)
|
bot.Client.OnFriendMessageRecalled(bot.friendRecallEvent)
|
||||||
bot.Client.OnReceivedOfflineFile(bot.offlineFileEvent)
|
bot.Client.OnReceivedOfflineFile(bot.offlineFileEvent)
|
||||||
bot.Client.OnJoinGroup(bot.joinGroupEvent)
|
bot.Client.OnJoinGroup(bot.joinGroupEvent)
|
||||||
@ -218,7 +222,13 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int
|
|||||||
ret := bot.Client.SendGroupMessage(groupId, m, ForceFragmented)
|
ret := bot.Client.SendGroupMessage(groupId, m, ForceFragmented)
|
||||||
if ret == nil || ret.Id == -1 {
|
if ret == nil || ret.Id == -1 {
|
||||||
log.Warnf("群消息发送失败: 账号可能被风控.")
|
log.Warnf("群消息发送失败: 账号可能被风控.")
|
||||||
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)
|
return bot.InsertGroupMessage(ret)
|
||||||
}
|
}
|
||||||
@ -235,6 +245,10 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in
|
|||||||
newElem = append(newElem, fm)
|
newElem = append(newElem, fm)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if i, ok := elem.(*PokeElement); ok {
|
||||||
|
bot.Client.SendFriendPoke(i.Target)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
if i, ok := elem.(*message.VoiceElement); ok {
|
if i, ok := elem.(*message.VoiceElement); ok {
|
||||||
fv, err := bot.Client.UploadPrivatePtt(target, i.Data)
|
fv, err := bot.Client.UploadPrivatePtt(target, i.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -384,22 +398,24 @@ func (bot *CQBot) Release() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) dispatchEventMessage(m MSG) {
|
func (bot *CQBot) dispatchEventMessage(m MSG) {
|
||||||
payload := gjson.Parse(m.ToJson())
|
if global.EventFilter != nil && global.EventFilter.Eval(global.MSG(m)) == false {
|
||||||
filter := global.EventFilter
|
|
||||||
if filter != nil && (*filter).Eval(payload) == false {
|
|
||||||
log.Debug("Event filtered!")
|
log.Debug("Event filtered!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, f := range bot.events {
|
for _, f := range bot.events {
|
||||||
fn := f
|
go func(fn func(MSG)) {
|
||||||
go func() {
|
defer func() {
|
||||||
|
if pan := recover(); pan != nil {
|
||||||
|
log.Warnf("处理事件 %v 时出现错误: %v \n%s", m, pan, debug.Stack())
|
||||||
|
}
|
||||||
|
}()
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
fn(m)
|
fn(m)
|
||||||
end := time.Now()
|
end := time.Now()
|
||||||
if end.Sub(start) > time.Second*5 {
|
if end.Sub(start) > time.Second*5 {
|
||||||
log.Debugf("警告: 事件处理耗时超过 5 秒 (%v), 请检查应用是否有堵塞.", end.Sub(start))
|
log.Debugf("警告: 事件处理耗时超过 5 秒 (%v), 请检查应用是否有堵塞.", end.Sub(start))
|
||||||
}
|
}
|
||||||
}()
|
}(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
248
coolq/cqcode.go
248
coolq/cqcode.go
@ -1,28 +1,33 @@
|
|||||||
package coolq
|
package coolq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
xml2 "encoding/xml"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"math"
|
||||||
|
"net/url"
|
||||||
|
"path"
|
||||||
|
"runtime"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Mrs4s/MiraiGo/binary"
|
"github.com/Mrs4s/MiraiGo/binary"
|
||||||
"github.com/Mrs4s/MiraiGo/message"
|
"github.com/Mrs4s/MiraiGo/message"
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
"io/ioutil"
|
|
||||||
"net/url"
|
|
||||||
"path"
|
|
||||||
"regexp"
|
|
||||||
"runtime"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
var matchReg = regexp.MustCompile(`\[CQ:\w+?.*?]`)
|
var matchReg = regexp.MustCompile(`\[CQ:\w+?.*?]`)
|
||||||
var typeReg = regexp.MustCompile(`\[CQ:(\w+)`)
|
var typeReg = regexp.MustCompile(`\[CQ:(\w+)`)
|
||||||
var paramReg = regexp.MustCompile(`,([\w\-.]+?)=([^,\]]+)`)
|
var paramReg = regexp.MustCompile(`,([\w\-.]+?)=([^,\]]+)`)
|
||||||
|
*/
|
||||||
|
|
||||||
var IgnoreInvalidCQCode = false
|
var IgnoreInvalidCQCode = false
|
||||||
|
|
||||||
@ -63,7 +68,7 @@ func (e *MusicElement) Type() message.ElementType {
|
|||||||
return message.Service
|
return message.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
var GiftId = []message.GroupGift{
|
var GiftId = [...]message.GroupGift{
|
||||||
message.SweetWink,
|
message.SweetWink,
|
||||||
message.HappyCola,
|
message.HappyCola,
|
||||||
message.LuckyBracelet,
|
message.LuckyBracelet,
|
||||||
@ -73,6 +78,11 @@ var GiftId = []message.GroupGift{
|
|||||||
message.RainbowCandy,
|
message.RainbowCandy,
|
||||||
message.Stronger,
|
message.Stronger,
|
||||||
message.LoveMicrophone,
|
message.LoveMicrophone,
|
||||||
|
message.HoldingYourHand,
|
||||||
|
message.CuteCat,
|
||||||
|
message.MysteryMask,
|
||||||
|
message.ImBusy,
|
||||||
|
message.LoveMask,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *PokeElement) Type() message.ElementType {
|
func (e *PokeElement) Type() message.ElementType {
|
||||||
@ -175,6 +185,40 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
|
|||||||
"data": map[string]string{"file": o.Filename, "url": o.Url},
|
"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{{
|
||||||
|
"type": "image",
|
||||||
|
"data": map[string]string{"file": o.Filename, "type": "flash"},
|
||||||
|
}}
|
||||||
|
case *message.FriendFlashImgElement:
|
||||||
|
return []MSG{{
|
||||||
|
"type": "image",
|
||||||
|
"data": map[string]string{"file": o.Filename, "type": "flash"},
|
||||||
|
}}
|
||||||
case *message.ServiceElement:
|
case *message.ServiceElement:
|
||||||
if isOk := strings.Contains(o.Content, "<?xml"); isOk {
|
if isOk := strings.Contains(o.Content, "<?xml"); isOk {
|
||||||
m = MSG{
|
m = MSG{
|
||||||
@ -244,9 +288,21 @@ 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))
|
r += fmt.Sprintf(`[CQ:image,file=%s,url=%s]`, o.Filename, CQCodeEscapeValue(o.Url))
|
||||||
}
|
}
|
||||||
case *message.GroupImageElement:
|
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:
|
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:
|
||||||
|
return fmt.Sprintf("[CQ:image,type=flash,file=%s]", o.Filename)
|
||||||
case *message.ServiceElement:
|
case *message.ServiceElement:
|
||||||
if isOk := strings.Contains(o.Content, "<?xml"); isOk {
|
if isOk := strings.Contains(o.Content, "<?xml"); isOk {
|
||||||
r += fmt.Sprintf(`[CQ:xml,data=%s,resid=%d]`, CQCodeEscapeValue(o.Content), o.Id)
|
r += fmt.Sprintf(`[CQ:xml,data=%s,resid=%d]`, CQCodeEscapeValue(o.Content), o.Id)
|
||||||
@ -261,30 +317,68 @@ func ToStringMessage(e []message.IMessageElement, code int64, raw ...bool) (r st
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) ConvertStringMessage(m string, group bool) (r []message.IMessageElement) {
|
func (bot *CQBot) ConvertStringMessage(msg string, group bool) (r []message.IMessageElement) {
|
||||||
i := matchReg.FindAllStringSubmatchIndex(m, -1)
|
index := 0
|
||||||
si := 0
|
stat := 0
|
||||||
for _, idx := range i {
|
rMsg := []rune(msg)
|
||||||
if idx[0] > si {
|
var tempText, cqCode []rune
|
||||||
text := m[si:idx[0]]
|
hasNext := func() bool {
|
||||||
r = append(r, message.NewText(CQCodeUnescapeText(text)))
|
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 {
|
||||||
|
r = append(r, message.NewText(CQCodeUnescapeValue(string(tempText))))
|
||||||
}
|
}
|
||||||
code := m[idx[0]:idx[1]]
|
tempText = []rune{}
|
||||||
si = idx[1]
|
cqCode = []rune{}
|
||||||
t := typeReg.FindAllStringSubmatch(code, -1)[0][1]
|
}
|
||||||
ps := paramReg.FindAllStringSubmatch(code, -1)
|
saveCQCode := func() {
|
||||||
d := make(map[string]string)
|
defer func() {
|
||||||
for _, p := range ps {
|
cqCode = []rune{}
|
||||||
d[p[1]] = CQCodeUnescapeValue(p[2])
|
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 len(r) > 0 {
|
||||||
if _, ok := r[0].(*message.ReplyElement); ok {
|
if _, ok := r[0].(*message.ReplyElement); ok {
|
||||||
log.Warnf("警告: 一条信息只能包含一个 Reply 元素.")
|
log.Warnf("警告: 一条信息只能包含一个 Reply 元素.")
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mid, err := strconv.Atoi(d["id"])
|
mid, err := strconv.Atoi(params["id"])
|
||||||
if err == nil {
|
if err == nil {
|
||||||
org := bot.GetMessage(int32(mid))
|
org := bot.GetMessage(int32(mid))
|
||||||
if org != nil {
|
if org != nil {
|
||||||
@ -296,25 +390,54 @@ func (bot *CQBot) ConvertStringMessage(m string, group bool) (r []message.IMessa
|
|||||||
Elements: bot.ConvertStringMessage(org["message"].(string), group),
|
Elements: bot.ConvertStringMessage(org["message"].(string), group),
|
||||||
},
|
},
|
||||||
}, r...)
|
}, r...)
|
||||||
continue
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elem, err := bot.ToElement(t, d, group)
|
elem, err := bot.ToElement(t, params, group)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
org := "[" + string(cqCode) + "]"
|
||||||
if !IgnoreInvalidCQCode {
|
if !IgnoreInvalidCQCode {
|
||||||
log.Warnf("转换CQ码 %v 到MiraiGo Element时出现错误: %v 将原样发送.", code, err)
|
log.Warnf("转换CQ码 %v 时出现错误: %v 将原样发送.", org, err)
|
||||||
r = append(r, message.NewText(code))
|
r = append(r, message.NewText(org))
|
||||||
} else {
|
} 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:
|
||||||
|
r = append(r, i)
|
||||||
|
case []message.IMessageElement:
|
||||||
|
r = append(r, i...)
|
||||||
}
|
}
|
||||||
r = append(r, elem)
|
|
||||||
}
|
}
|
||||||
if si != len(m) {
|
for hasNext() {
|
||||||
r = append(r, message.NewText(CQCodeUnescapeText(m[si:])))
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,7 +477,13 @@ func (bot *CQBot) ConvertObjectMessage(m gjson.Result, group bool) (r []message.
|
|||||||
log.Warnf("转换CQ码到MiraiGo Element时出现错误: %v 将忽略本段CQ码.", err)
|
log.Warnf("转换CQ码到MiraiGo Element时出现错误: %v 将忽略本段CQ码.", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r = append(r, elem)
|
switch i := elem.(type) {
|
||||||
|
case message.IMessageElement:
|
||||||
|
r = append(r, i)
|
||||||
|
case []message.IMessageElement:
|
||||||
|
r = append(r, i...)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if m.Type == gjson.String {
|
if m.Type == gjson.String {
|
||||||
return bot.ConvertStringMessage(m.Str, group)
|
return bot.ConvertStringMessage(m.Str, group)
|
||||||
@ -370,7 +499,10 @@ func (bot *CQBot) ConvertObjectMessage(m gjson.Result, group bool) (r []message.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m message.IMessageElement, err error) {
|
// ToElement 将解码后的CQCode转换为Element.
|
||||||
|
// 返回 interface{} 存在三种类型
|
||||||
|
// message.IMessageElement []message.IMessageElement nil
|
||||||
|
func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interface{}, err error) {
|
||||||
switch t {
|
switch t {
|
||||||
case "text":
|
case "text":
|
||||||
return message.NewText(d["text"]), nil
|
return message.NewText(d["text"]), nil
|
||||||
@ -413,9 +545,6 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m messag
|
|||||||
}
|
}
|
||||||
|
|
||||||
case "poke":
|
case "poke":
|
||||||
if !group {
|
|
||||||
return nil, errors.New("todo") // TODO: private poke
|
|
||||||
}
|
|
||||||
t, _ := strconv.ParseInt(d["qq"], 10, 64)
|
t, _ := strconv.ParseInt(d["qq"], 10, 64)
|
||||||
return &PokeElement{Target: t}, nil
|
return &PokeElement{Target: t}, nil
|
||||||
case "gift":
|
case "gift":
|
||||||
@ -424,7 +553,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m messag
|
|||||||
}
|
}
|
||||||
t, _ := strconv.ParseInt(d["qq"], 10, 64)
|
t, _ := strconv.ParseInt(d["qq"], 10, 64)
|
||||||
id, _ := strconv.Atoi(d["id"])
|
id, _ := strconv.Atoi(d["id"])
|
||||||
if id < 0 || id >= 9 {
|
if id < 0 || id >= 14 {
|
||||||
return nil, errors.New("invalid gift id")
|
return nil, errors.New("invalid gift id")
|
||||||
}
|
}
|
||||||
return &GiftElement{Target: t, GiftId: GiftId[id]}, nil
|
return &GiftElement{Target: t, GiftId: GiftId[id]}, nil
|
||||||
@ -554,7 +683,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m messag
|
|||||||
}}, nil
|
}}, nil
|
||||||
}
|
}
|
||||||
xml := fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="2" templateID="1" action="web" brief="[分享] %s" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="2"><audio cover="%s" src="%s"/><title>%s</title><summary>%s</summary></item><source name="音乐" icon="https://i.gtimg.cn/open/app_icon/01/07/98/56/1101079856_100_m.png" url="http://web.p.qq.com/qqmpmobile/aio/app.html?id=1101079856" action="app" a_actionData="com.tencent.qqmusic" i_actionData="tencent1101079856://" appid="1101079856" /></msg>`,
|
xml := fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="2" templateID="1" action="web" brief="[分享] %s" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="2"><audio cover="%s" src="%s"/><title>%s</title><summary>%s</summary></item><source name="音乐" icon="https://i.gtimg.cn/open/app_icon/01/07/98/56/1101079856_100_m.png" url="http://web.p.qq.com/qqmpmobile/aio/app.html?id=1101079856" action="app" a_actionData="com.tencent.qqmusic" i_actionData="tencent1101079856://" appid="1101079856" /></msg>`,
|
||||||
d["title"], d["url"], d["image"], d["audio"], d["title"], d["content"])
|
XmlEscape(d["title"]), d["url"], d["image"], d["audio"], XmlEscape(d["title"]), XmlEscape(d["content"]))
|
||||||
return &message.ServiceElement{
|
return &message.ServiceElement{
|
||||||
Id: 60,
|
Id: 60,
|
||||||
Content: xml,
|
Content: xml,
|
||||||
@ -565,14 +694,12 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m messag
|
|||||||
case "xml":
|
case "xml":
|
||||||
resId := d["resid"]
|
resId := d["resid"]
|
||||||
template := CQCodeEscapeValue(d["data"])
|
template := CQCodeEscapeValue(d["data"])
|
||||||
//println(template)
|
|
||||||
i, _ := strconv.ParseInt(resId, 10, 64)
|
i, _ := strconv.ParseInt(resId, 10, 64)
|
||||||
msg := message.NewRichXml(template, i)
|
msg := message.NewRichXml(template, i)
|
||||||
return msg, nil
|
return msg, nil
|
||||||
case "json":
|
case "json":
|
||||||
resId := d["resid"]
|
resId := d["resid"]
|
||||||
i, _ := strconv.ParseInt(resId, 10, 64)
|
i, _ := strconv.ParseInt(resId, 10, 64)
|
||||||
log.Warnf("json msg=%s", d["data"])
|
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
//默认情况下走小程序通道
|
//默认情况下走小程序通道
|
||||||
msg := message.NewLightApp(CQCodeUnescapeValue(d["data"]))
|
msg := message.NewLightApp(CQCodeUnescapeValue(d["data"]))
|
||||||
@ -604,13 +731,19 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m messag
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("send cardimage faild")
|
return nil, errors.New("send cardimage faild")
|
||||||
}
|
}
|
||||||
return bot.SendNewPic(img, source, icon, minWidth, minHeight, maxWidth, maxHeight, group)
|
return bot.makeShowPic(img, source, icon, minWidth, minHeight, maxWidth, maxHeight, group)
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("unsupported cq code: " + t)
|
return nil, errors.New("unsupported cq code: " + t)
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func XmlEscape(c string) string {
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
_ = xml2.EscapeText(buf, []byte(c))
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
func CQCodeEscapeText(raw string) string {
|
func CQCodeEscapeText(raw string) string {
|
||||||
ret := raw
|
ret := raw
|
||||||
ret = strings.ReplaceAll(ret, "&", "&")
|
ret = strings.ReplaceAll(ret, "&", "&")
|
||||||
@ -753,10 +886,10 @@ func (bot *CQBot) makeImageElem(d map[string]string, group bool) (message.IMessa
|
|||||||
return nil, errors.New("invalid image")
|
return nil, errors.New("invalid image")
|
||||||
}
|
}
|
||||||
|
|
||||||
//SendNewPic 一种xml 方式发送的群消息图片
|
//makeShowPic 一种xml 方式发送的群消息图片
|
||||||
func (bot *CQBot) SendNewPic(elem message.IMessageElement, source string, icon string, minWidth int64, minHeight int64, maxWidth int64, maxHeight int64, group bool) (*message.ServiceElement, error) {
|
func (bot *CQBot) makeShowPic(elem message.IMessageElement, source string, icon string, minWidth int64, minHeight int64, maxWidth int64, maxHeight int64, group bool) ([]message.IMessageElement, error) {
|
||||||
var xml string
|
xml := ""
|
||||||
xml = ""
|
var suf message.IMessageElement
|
||||||
if i, ok := elem.(*message.ImageElement); ok {
|
if i, ok := elem.(*message.ImageElement); ok {
|
||||||
if group == false {
|
if group == false {
|
||||||
gm, err := bot.Client.UploadPrivateImage(1, i.Data)
|
gm, err := bot.Client.UploadPrivateImage(1, i.Data)
|
||||||
@ -764,27 +897,32 @@ func (bot *CQBot) SendNewPic(elem message.IMessageElement, source string, icon s
|
|||||||
log.Warnf("警告: 好友消息 %v 消息图片上传失败: %v", 1, err)
|
log.Warnf("警告: 好友消息 %v 消息图片上传失败: %v", 1, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
suf = gm
|
||||||
xml = fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="5" templateID="12345" action="" brief="[分享]我看到一张很赞的图片,分享给你,快来看!" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="0" advertiser_id="0" aid="0"><image uuid="%x" md5="%x" GroupFiledid="0" filesize="%d" local_path="%s" minWidth="%d" minHeight="%d" maxWidth="%d" maxHeight="%d" /></item><source name="%s" icon="%s" action="" appid="-1" /></msg>`, "", gm.Md5, gm.Md5, len(i.Data), "", minWidth, minHeight, maxWidth, maxHeight, source, icon)
|
xml = fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="5" templateID="12345" action="" brief="[分享]我看到一张很赞的图片,分享给你,快来看!" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="0" advertiser_id="0" aid="0"><image uuid="%x" md5="%x" GroupFiledid="0" filesize="%d" local_path="%s" minWidth="%d" minHeight="%d" maxWidth="%d" maxHeight="%d" /></item><source name="%s" icon="%s" action="" appid="-1" /></msg>`, "", gm.Md5, gm.Md5, len(i.Data), "", minWidth, minHeight, maxWidth, maxHeight, source, icon)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
gm, err := bot.Client.UploadGroupImage(1, i.Data)
|
gm, err := bot.Client.UploadGroupImage(1, i.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("警告: 群 %v 消息图片上传失败: %v", 1, err)
|
log.Warnf("警告: 群 %v 消息图片上传失败: %v", 1, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
suf = gm
|
||||||
xml = fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="5" templateID="12345" action="" brief="[分享]我看到一张很赞的图片,分享给你,快来看!" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="0" advertiser_id="0" aid="0"><image uuid="%x" md5="%x" GroupFiledid="0" filesize="%d" local_path="%s" minWidth="%d" minHeight="%d" maxWidth="%d" maxHeight="%d" /></item><source name="%s" icon="%s" action="" appid="-1" /></msg>`, "", gm.Md5, gm.Md5, len(i.Data), "", minWidth, minHeight, maxWidth, maxHeight, source, icon)
|
xml = fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="5" templateID="12345" action="" brief="[分享]我看到一张很赞的图片,分享给你,快来看!" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="0" advertiser_id="0" aid="0"><image uuid="%x" md5="%x" GroupFiledid="0" filesize="%d" local_path="%s" minWidth="%d" minHeight="%d" maxWidth="%d" maxHeight="%d" /></item><source name="%s" icon="%s" action="" appid="-1" /></msg>`, "", gm.Md5, gm.Md5, len(i.Data), "", minWidth, minHeight, maxWidth, maxHeight, source, icon)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if i, ok := elem.(*message.GroupImageElement); ok {
|
if i, ok := elem.(*message.GroupImageElement); ok {
|
||||||
xml = fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="5" templateID="12345" action="" brief="[分享]我看到一张很赞的图片,分享给你,快来看!" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="0" advertiser_id="0" aid="0"><image uuid="%x" md5="%x" GroupFiledid="0" filesize="%d" local_path="%s" minWidth="%d" minHeight="%d" maxWidth="%d" maxHeight="%d" /></item><source name="%s" icon="%s" action="" appid="-1" /></msg>`, "", i.Md5, i.Md5, 0, "", minWidth, minHeight, maxWidth, maxHeight, source, icon)
|
xml = fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="5" templateID="12345" action="" brief="[分享]我看到一张很赞的图片,分享给你,快来看!" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="0" advertiser_id="0" aid="0"><image uuid="%x" md5="%x" GroupFiledid="0" filesize="%d" local_path="%s" minWidth="%d" minHeight="%d" maxWidth="%d" maxHeight="%d" /></item><source name="%s" icon="%s" action="" appid="-1" /></msg>`, "", i.Md5, i.Md5, 0, "", minWidth, minHeight, maxWidth, maxHeight, source, icon)
|
||||||
|
suf = i
|
||||||
}
|
}
|
||||||
if i, ok := elem.(*message.FriendImageElement); ok {
|
if i, ok := elem.(*message.FriendImageElement); ok {
|
||||||
xml = fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="5" templateID="12345" action="" brief="[分享]我看到一张很赞的图片,分享给你,快来看!" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="0" advertiser_id="0" aid="0"><image uuid="%x" md5="%x" GroupFiledid="0" filesize="%d" local_path="%s" minWidth="%d" minHeight="%d" maxWidth="%d" maxHeight="%d" /></item><source name="%s" icon="%s" action="" appid="-1" /></msg>`, "", i.Md5, i.Md5, 0, "", minWidth, minHeight, maxWidth, maxHeight, source, icon)
|
xml = fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8' standalone='yes' ?><msg serviceID="5" templateID="12345" action="" brief="[分享]我看到一张很赞的图片,分享给你,快来看!" sourceMsgId="0" url="%s" flag="0" adverSign="0" multiMsgFlag="0"><item layout="0" advertiser_id="0" aid="0"><image uuid="%x" md5="%x" GroupFiledid="0" filesize="%d" local_path="%s" minWidth="%d" minHeight="%d" maxWidth="%d" maxHeight="%d" /></item><source name="%s" icon="%s" action="" appid="-1" /></msg>`, "", i.Md5, i.Md5, 0, "", minWidth, minHeight, maxWidth, maxHeight, source, icon)
|
||||||
|
suf = i
|
||||||
}
|
}
|
||||||
if xml != "" {
|
if xml != "" {
|
||||||
log.Warn(xml)
|
//log.Warn(xml)
|
||||||
XmlMsg := message.NewRichXml(xml, 5)
|
ret := []message.IMessageElement{suf}
|
||||||
return XmlMsg, nil
|
ret = append(ret, message.NewRichXml(xml, 5))
|
||||||
|
return ret, nil
|
||||||
}
|
}
|
||||||
return nil, errors.New("发送xml图片消息失败")
|
return nil, errors.New("生成xml图片消息失败")
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,17 @@ package coolq
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"github.com/Mrs4s/MiraiGo/binary"
|
|
||||||
"github.com/Mrs4s/MiraiGo/client"
|
|
||||||
"github.com/Mrs4s/MiraiGo/message"
|
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Mrs4s/MiraiGo/binary"
|
||||||
|
"github.com/Mrs4s/MiraiGo/client"
|
||||||
|
"github.com/Mrs4s/MiraiGo/message"
|
||||||
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var format = "string"
|
var format = "string"
|
||||||
@ -167,13 +168,24 @@ func (bot *CQBot) tempMessageEvent(c *client.QQClient, m *message.TempMessage) {
|
|||||||
|
|
||||||
func (bot *CQBot) groupMutedEvent(c *client.QQClient, e *client.GroupMuteEvent) {
|
func (bot *CQBot) groupMutedEvent(c *client.QQClient, e *client.GroupMuteEvent) {
|
||||||
g := c.FindGroup(e.GroupCode)
|
g := c.FindGroup(e.GroupCode)
|
||||||
if e.Time > 0 {
|
if e.TargetUin == 0 {
|
||||||
log.Infof("群 %v 内 %v 被 %v 禁言了 %v秒.",
|
if e.Time != 0 {
|
||||||
formatGroupName(g), formatMemberName(g.FindMember(e.TargetUin)), formatMemberName(g.FindMember(e.OperatorUin)), e.Time)
|
log.Infof("群 %v 被 %v 开启全员禁言.",
|
||||||
|
formatGroupName(g), formatMemberName(g.FindMember(e.OperatorUin)))
|
||||||
|
} else {
|
||||||
|
log.Infof("群 %v 被 %v 解除全员禁言.",
|
||||||
|
formatGroupName(g), formatMemberName(g.FindMember(e.OperatorUin)))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Infof("群 %v 内 %v 被 %v 解除禁言.",
|
if e.Time > 0 {
|
||||||
formatGroupName(g), formatMemberName(g.FindMember(e.TargetUin)), formatMemberName(g.FindMember(e.OperatorUin)))
|
log.Infof("群 %v 内 %v 被 %v 禁言了 %v 秒.",
|
||||||
|
formatGroupName(g), formatMemberName(g.FindMember(e.TargetUin)), formatMemberName(g.FindMember(e.OperatorUin)), e.Time)
|
||||||
|
} else {
|
||||||
|
log.Infof("群 %v 内 %v 被 %v 解除禁言.",
|
||||||
|
formatGroupName(g), formatMemberName(g.FindMember(e.TargetUin)), formatMemberName(g.FindMember(e.OperatorUin)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(MSG{
|
||||||
"post_type": "notice",
|
"post_type": "notice",
|
||||||
"duration": e.Time,
|
"duration": e.Time,
|
||||||
@ -184,10 +196,10 @@ func (bot *CQBot) groupMutedEvent(c *client.QQClient, e *client.GroupMuteEvent)
|
|||||||
"user_id": e.TargetUin,
|
"user_id": e.TargetUin,
|
||||||
"time": time.Now().Unix(),
|
"time": time.Now().Unix(),
|
||||||
"sub_type": func() string {
|
"sub_type": func() string {
|
||||||
if e.Time > 0 {
|
if e.Time == 0 {
|
||||||
return "ban"
|
return "lift_ban"
|
||||||
}
|
}
|
||||||
return "lift_ban"
|
return "ban"
|
||||||
}(),
|
}(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -209,7 +221,7 @@ func (bot *CQBot) groupRecallEvent(c *client.QQClient, e *client.GroupMessageRec
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.IGroupNotifyEvent) {
|
func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.INotifyEvent) {
|
||||||
group := c.FindGroup(e.From())
|
group := c.FindGroup(e.From())
|
||||||
switch notify := e.(type) {
|
switch notify := e.(type) {
|
||||||
case *client.GroupPokeNotifyEvent:
|
case *client.GroupPokeNotifyEvent:
|
||||||
@ -268,6 +280,24 @@ func (bot *CQBot) groupNotifyEvent(c *client.QQClient, e client.IGroupNotifyEven
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bot *CQBot) friendNotifyEvent(c *client.QQClient, e client.INotifyEvent) {
|
||||||
|
friend := c.FindFriend(e.From())
|
||||||
|
switch notify := e.(type) {
|
||||||
|
case *client.FriendPokeNotifyEvent:
|
||||||
|
log.Infof("好友 %v 戳了戳你.", friend.Nickname)
|
||||||
|
bot.dispatchEventMessage(MSG{
|
||||||
|
"post_type": "notice",
|
||||||
|
"notice_type": "notify",
|
||||||
|
"sub_type": "poke",
|
||||||
|
"self_id": c.Uin,
|
||||||
|
"user_id": notify.Sender,
|
||||||
|
"sender_id": notify.Sender,
|
||||||
|
"target_id": notify.Receiver,
|
||||||
|
"time": time.Now().Unix(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (bot *CQBot) friendRecallEvent(c *client.QQClient, e *client.FriendMessageRecalledEvent) {
|
func (bot *CQBot) friendRecallEvent(c *client.QQClient, e *client.FriendMessageRecalledEvent) {
|
||||||
f := c.FindFriend(e.FriendUin)
|
f := c.FindFriend(e.FriendUin)
|
||||||
gid := ToGlobalId(e.FriendUin, e.MessageId)
|
gid := ToGlobalId(e.FriendUin, e.MessageId)
|
||||||
@ -498,6 +528,28 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement) {
|
|||||||
w.WriteString(i.Url)
|
w.WriteString(i.Url)
|
||||||
}), 0644)
|
}), 0644)
|
||||||
}
|
}
|
||||||
|
case *message.GroupFlashImgElement:
|
||||||
|
filename := hex.EncodeToString(i.Md5) + ".image"
|
||||||
|
if !global.PathExists(path.Join(global.IMAGE_PATH, filename)) {
|
||||||
|
_ = ioutil.WriteFile(path.Join(global.IMAGE_PATH, filename), binary.NewWriterF(func(w *binary.Writer) {
|
||||||
|
w.Write(i.Md5)
|
||||||
|
w.WriteUInt32(uint32(i.Size))
|
||||||
|
w.WriteString(i.Filename)
|
||||||
|
w.WriteString("")
|
||||||
|
}), 0644)
|
||||||
|
}
|
||||||
|
i.Filename = filename
|
||||||
|
case *message.FriendFlashImgElement:
|
||||||
|
filename := hex.EncodeToString(i.Md5) + ".image"
|
||||||
|
if !global.PathExists(path.Join(global.IMAGE_PATH, filename)) {
|
||||||
|
_ = ioutil.WriteFile(path.Join(global.IMAGE_PATH, filename), binary.NewWriterF(func(w *binary.Writer) {
|
||||||
|
w.Write(i.Md5)
|
||||||
|
w.WriteUInt32(uint32(i.Size))
|
||||||
|
w.WriteString(i.Filename)
|
||||||
|
w.WriteString("")
|
||||||
|
}), 0644)
|
||||||
|
}
|
||||||
|
i.Filename = filename
|
||||||
case *message.VoiceElement:
|
case *message.VoiceElement:
|
||||||
i.Name = strings.ReplaceAll(i.Name, "{", "")
|
i.Name = strings.ReplaceAll(i.Name, "{", "")
|
||||||
i.Name = strings.ReplaceAll(i.Name, "}", "")
|
i.Name = strings.ReplaceAll(i.Name, "}", "")
|
||||||
|
@ -1,12 +1,22 @@
|
|||||||
# 事件过滤器
|
# 事件过滤器
|
||||||
|
|
||||||
在go-cqhttp同级目录下新建`filter.json`文件即可开启事件过滤器,启动时会读取该文件中定义的过滤规则(使用 JSON 编写),若文件不存在,或过滤规则语法错误,则会暂停所有上报。
|
在go-cqhttp同级目录下新建`filter.json`文件即可开启事件过滤器,启动时会读取该文件中定义的过滤规则(使用 JSON 编写),若文件不存在,或过滤规则语法错误,则不会启用事件过滤器。
|
||||||
事件过滤器会处理所有事件(包括心跳事件在内的元事件),请谨慎使用!!
|
事件过滤器会处理所有事件(包括心跳事件在内的元事件),请谨慎使用!!
|
||||||
|
|
||||||
|
注意: 与客户端建立连接的握手事件**不会**经过事件过滤器
|
||||||
|
|
||||||
## 示例
|
## 示例
|
||||||
|
|
||||||
这节首先给出一些示例,演示过滤器的基本用法,下一节将给出具体语法说明。
|
这节首先给出一些示例,演示过滤器的基本用法,下一节将给出具体语法说明。
|
||||||
|
|
||||||
|
### 过滤所有事件
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
".not": {}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### 只上报以「!!」开头的消息
|
### 只上报以「!!」开头的消息
|
||||||
|
|
||||||
```json
|
```json
|
||||||
@ -110,16 +120,16 @@
|
|||||||
|
|
||||||
下面列出所有运算符(「要求的参数类型」是指运算符的键所对应的值的类型,「可作用于的类型」是指在过滤时事件对象相应值的类型):
|
下面列出所有运算符(「要求的参数类型」是指运算符的键所对应的值的类型,「可作用于的类型」是指在过滤时事件对象相应值的类型):
|
||||||
|
|
||||||
| 运算符 | 要求的参数类型 | 可作用于的类型 |
|
| 运算符 | 要求的参数类型 | 可作用于的类型 |
|
||||||
| ----- | ------------ | ----------- |
|
| ----------- | -------------------------- | ----------------------------------------------------- |
|
||||||
| `.not` | object | 任何 |
|
| `.not` | object | 任何 |
|
||||||
| `.and` | object | 若参数中全为运算符,则任何;若不全为运算符,则 object |
|
| `.and` | object | 若参数中全为运算符,则任何;若不全为运算符,则 object |
|
||||||
| `.or` | array(数组元素为 object) | 任何 |
|
| `.or` | array(数组元素为 object) | 任何 |
|
||||||
| `.eq` | 任何 | 任何 |
|
| `.eq` | 任何 | 任何 |
|
||||||
| `.neq` | 任何 | 任何 |
|
| `.neq` | 任何 | 任何 |
|
||||||
| `.in` | string/array | 若参数为 string,则 string;若参数为 array,则任何 |
|
| `.in` | string/array | 若参数为 string,则 string;若参数为 array,则任何 |
|
||||||
| `.contains` | string | string |
|
| `.contains` | string | string |
|
||||||
| `.regex` | string | string |
|
| `.regex` | string | string |
|
||||||
|
|
||||||
|
|
||||||
## 过滤时的事件数据对象
|
## 过滤时的事件数据对象
|
||||||
@ -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 码
|
- `raw_message` 字段为未经**CQ码**处理的原始消息字符串,这意味着其中可能会出现形如 `[CQ:face,id=123]` 的 CQ 码
|
||||||
|
127
docs/adminApi.md
127
docs/adminApi.md
@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | ----------- |
|
| ------------ | ------ | --------------------------- |
|
||||||
| access_token | string | 校验口令,config.json中配置 |
|
| access_token | string | 校验口令,config.hjson中配置 |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -24,9 +24,9 @@ method:`POST/GET`
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ---- | ------------------------------------- |
|
| ------ | ---- | ---- |
|
||||||
| 无|||
|
| 无 | | |
|
||||||
|
|
||||||
返回:
|
返回:
|
||||||
|
|
||||||
@ -44,19 +44,19 @@ method: `GET`
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | ----------- |
|
| ------ | ---- | ---- |
|
||||||
| 无|||
|
| 无 | | |
|
||||||
|
|
||||||
返回:
|
返回:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{"data": {"ispic": true,"picbase64":"xxxxx"}, "retcode": 0, "status": "ok"}
|
{"data": {"ispic": true,"picbase64":"xxxxx"}, "retcode": 0, "status": "ok"}
|
||||||
```
|
```
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | ----------- |
|
| -------- | ------ | --------------------------------------------------- |
|
||||||
| ispic| bool| 是否是验证码类型 true是,false为不是(比如设备锁|
|
| ispic | bool | 是否是验证码类型 true是,false为不是(比如设备锁 |
|
||||||
|picbas64| string| 验证码的base64编码内容,加上头,放入img标签即可显示|
|
| picbas64 | string | 验证码的base64编码内容,加上头,放入img标签即可显示 |
|
||||||
|
|
||||||
### admin/do_web_write
|
### admin/do_web_write
|
||||||
|
|
||||||
@ -67,9 +67,9 @@ method: `POST` formdata
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | ----------- |
|
| ------ | ------ | ---------- |
|
||||||
| input | string | 输入的类容 |
|
| input | string | 输入的内容 |
|
||||||
|
|
||||||
返回:
|
返回:
|
||||||
|
|
||||||
@ -89,9 +89,28 @@ method: `POST`
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 |类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | -----------|
|
| ------ | ---- | ---- |
|
||||||
| 无 | | |
|
| 无 | | |
|
||||||
|
|
||||||
|
返回:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{"data": {}, "retcode": 0, "status": "ok"}
|
||||||
|
```
|
||||||
|
|
||||||
|
### admin/do_process_restart
|
||||||
|
|
||||||
|
> 冷重启
|
||||||
|
|
||||||
|
method: `POST`
|
||||||
|
|
||||||
|
|
||||||
|
参数:
|
||||||
|
|
||||||
|
| 参数名 | 类型 | 说明 |
|
||||||
|
| ------ | ---- | ---- |
|
||||||
|
| 无 | | |
|
||||||
|
|
||||||
返回:
|
返回:
|
||||||
|
|
||||||
@ -108,12 +127,12 @@ method: `POST` formdata
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | ------------------------------------------------------------ |
|
| ------------ | ------ | ------------------------------------- |
|
||||||
| uin | string | qq号 |
|
| uin | string | qq号 |
|
||||||
| password | string | qq密码 |
|
| password | string | qq密码 |
|
||||||
| enable_db | string | 是否启动数据库,填 'true' 或者 'false' |
|
| enable_db | string | 是否启动数据库,填 'true' 或者 'false' |
|
||||||
| access_token | string | 授权 token |
|
| access_token | string | 授权 token |
|
||||||
|
|
||||||
返回:
|
返回:
|
||||||
|
|
||||||
@ -130,14 +149,14 @@ method: `POST` formdata
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | ------------------------------------------------------------ |
|
| ----------- | ------ | --------------------------------------------- |
|
||||||
| port | string | 服务端口 |
|
| port | string | 服务端口 |
|
||||||
| host | string | 服务监听地址 |
|
| host | string | 服务监听地址 |
|
||||||
| enable | string | 是否启用 ,填 'true' 或者 'false' |
|
| enable | string | 是否启用 ,填 'true' 或者 'false' |
|
||||||
| timeout | string | http请求超时时间 |
|
| timeout | string | http请求超时时间 |
|
||||||
| post_url | string | post上报地址 不需要就填空字符串,或者不填|
|
| post_url | string | post上报地址 不需要就填空字符串,或者不填 |
|
||||||
| post_secret | string | post上报的secret 不需要就填空字符串,或者不填 |
|
| post_secret | string | post上报的secret 不需要就填空字符串,或者不填 |
|
||||||
|
|
||||||
返回:
|
返回:
|
||||||
|
|
||||||
@ -154,11 +173,11 @@ method: `POST` formdata
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | ------------------------------------------------------------ |
|
| ------ | ------ | -------------------------------- |
|
||||||
| port | string | 服务端口 |
|
| port | string | 服务端口 |
|
||||||
| host | string | 服务监听地址 |
|
| host | string | 服务监听地址 |
|
||||||
| enable | string | 是否启用 ,填 'true' 或者 'false' |
|
| enable | string | 是否启用 ,填 'true' 或者 'false' |
|
||||||
|
|
||||||
|
|
||||||
返回:
|
返回:
|
||||||
@ -175,11 +194,11 @@ method: `POST` formdata
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | ------------------------------------------------------------ |
|
| ------ | ------ | -------------------------------- |
|
||||||
| port | string | 服务端口 |
|
| port | string | 服务端口 |
|
||||||
| host | string | 服务监听地址 |
|
| host | string | 服务监听地址 |
|
||||||
| enable | string | 是否启用 ,填 'true' 或者 'false' |
|
| enable | string | 是否启用 ,填 'true' 或者 'false' |
|
||||||
|
|
||||||
|
|
||||||
返回:
|
返回:
|
||||||
@ -190,15 +209,15 @@ method: `POST` formdata
|
|||||||
|
|
||||||
### admin/do_config_json
|
### admin/do_config_json
|
||||||
|
|
||||||
> 直接修改 config.json配置
|
> 直接修改 config.hjson配置
|
||||||
|
|
||||||
method: `POST` formdata
|
method: `POST` formdata
|
||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | ------------------------------------------------------------ |
|
| ------ | ------ | ----------------------------------- |
|
||||||
| json | string | 完整的config.json的配合,json字符串 |
|
| json | string | 完整的config.hjson的配合,json字符串 |
|
||||||
|
|
||||||
|
|
||||||
返回:
|
返回:
|
||||||
@ -209,15 +228,15 @@ method: `POST` formdata
|
|||||||
|
|
||||||
### admin/get_config_json
|
### admin/get_config_json
|
||||||
|
|
||||||
> 获取当前 config.json配置
|
> 获取当前 config.hjson配置
|
||||||
|
|
||||||
method: `GET`
|
method: `GET`
|
||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | ------------------------------------------------------------ |
|
| ------ | ---- | ---- |
|
||||||
| 无 | | |
|
| 无 | | |
|
||||||
|
|
||||||
|
|
||||||
返回:
|
返回:
|
||||||
@ -226,7 +245,7 @@ method: `GET`
|
|||||||
{"data": {"config":"xxxx"}, "retcode": 0, "status": "ok"}
|
{"data": {"config":"xxxx"}, "retcode": 0, "status": "ok"}
|
||||||
```
|
```
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | ------------------------------------------------------------ |
|
| ------ | ------ | ----------------------------------- |
|
||||||
| 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导入配置
|
## 从原CQHTTP导入配置
|
||||||
|
|
||||||
@ -36,6 +36,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
|
|||||||
"ignore_invalid_cqcode": false,
|
"ignore_invalid_cqcode": false,
|
||||||
"force_fragmented": true,
|
"force_fragmented": true,
|
||||||
"heartbeat_interval": 5,
|
"heartbeat_interval": 5,
|
||||||
|
"use_sso_address": false,
|
||||||
"http_config": {
|
"http_config": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"host": "0.0.0.0",
|
"host": "0.0.0.0",
|
||||||
@ -60,28 +61,29 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
|
|||||||
}
|
}
|
||||||
````
|
````
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ------------------ | -------- | ------------------------------------------------------------------- |
|
| --------------------- | -------- | ---------------------------------------------------------------------------------------- |
|
||||||
| uin | int64 | 登录用QQ号 |
|
| uin | int64 | 登录用QQ号 |
|
||||||
| password | string | 登录用密码 |
|
| password | string | 登录用密码 |
|
||||||
| encrypt_password | bool | 是否对密码进行加密. |
|
| encrypt_password | bool | 是否对密码进行加密. |
|
||||||
| password_encrypted | string | 加密后的密码(请勿修改) |
|
| password_encrypted | string | 加密后的密码(请勿修改) |
|
||||||
| enable_db | bool | 是否开启内置数据库, 关闭后将无法使用 **回复/撤回** 等上下文相关接口 |
|
| enable_db | bool | 是否开启内置数据库, 关闭后将无法使用 **回复/撤回** 等上下文相关接口 |
|
||||||
| access_token | string | 同CQHTTP的 `access_token` 用于身份验证 |
|
| access_token | string | 同CQHTTP的 `access_token` 用于身份验证 |
|
||||||
| relogin | bool | 是否自动重新登录 |
|
| relogin | bool | 是否自动重新登录 |
|
||||||
| relogin_delay | int | 重登录延时(秒) |
|
| relogin_delay | int | 重登录延时(秒) |
|
||||||
| max_relogin_times | uint | 最大重登录次数,若0则不设置上限 |
|
| max_relogin_times | uint | 最大重登录次数,若0则不设置上限 |
|
||||||
| _rate_limit | bool | 是否启用API调用限速 |
|
| _rate_limit | bool | 是否启用API调用限速 |
|
||||||
| frequency | float64 | 1s内能调用API的次数 |
|
| frequency | float64 | 1s内能调用API的次数 |
|
||||||
| bucket_size | int | 令牌桶的大小,默认为1,修改此值可允许一定程度内连续调用api |
|
| bucket_size | int | 令牌桶的大小,默认为1,修改此值可允许一定程度内连续调用api |
|
||||||
| post_message_format | string | 上报信息类型 |
|
| post_message_format | string | 上报信息类型 |
|
||||||
| ignore_invalid_cqcode| bool | 是否忽略错误的CQ码 |
|
| ignore_invalid_cqcode | bool | 是否忽略错误的CQ码 |
|
||||||
| force_fragmented | bool | 是否强制分片发送群长消息 |
|
| force_fragmented | bool | 是否强制分片发送群长消息 |
|
||||||
| heartbeat_interval | int64 | 心跳间隔时间,单位秒。小于0则关闭心跳,等于0使用默认值(5秒) |
|
| use_sso_address | bool | 是否使用服务器下发的地址 |
|
||||||
| http_config | object | HTTP API配置 |
|
| heartbeat_interval | int64 | 心跳间隔时间,单位秒。小于0则关闭心跳,等于0使用默认值(5秒) |
|
||||||
| ws_config | object | Websocket API 配置 |
|
| http_config | object | HTTP API配置 |
|
||||||
| ws_reverse_servers | object[] | 反向 Websocket API 配置 |
|
| ws_config | object | Websocket API 配置 |
|
||||||
| log_level | string | 指定日志收集级别,将收集的日志单独存放到固定文件中,便于查看日志线索 当前支持 warn,error|
|
| ws_reverse_servers | object[] | 反向 Websocket API 配置 |
|
||||||
|
| log_level | string | 指定日志收集级别,将收集的日志单独存放到固定文件中,便于查看日志线索 当前支持 warn,error |
|
||||||
|
|
||||||
> 注: 开启密码加密后程序将在每次启动时要求输入解密密钥, 密钥错误会导致登录时提示密码错误.
|
> 注: 开启密码加密后程序将在每次启动时要求输入解密密钥, 密钥错误会导致登录时提示密码错误.
|
||||||
> 解密后密码将储存在内存中,用于自动重连等功能. 所以此加密并不能防止内存读取.
|
> 解密后密码将储存在内存中,用于自动重连等功能. 所以此加密并不能防止内存读取.
|
||||||
@ -108,10 +110,23 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
|
|||||||
|
|
||||||
在大部分情况下 我们只需要关心 `protocol` 字段:
|
在大部分情况下 我们只需要关心 `protocol` 字段:
|
||||||
|
|
||||||
| 值 | 类型 | 限制 |
|
| 值 | 类型 | 限制 |
|
||||||
| ---- | ------------- | ----------------------------------------------------- |
|
| --- | ------------- | ---------------------------------------------------------------- |
|
||||||
| 0 | Android Pad | 无法接收 `group_notify` 事件、无法接收口令红包 |
|
| 0 | iPad | 无 |
|
||||||
| 1 | Android Phone | 无 |
|
| 1 | Android Phone | 无法接收新版表情如 `/吃瓜 /汪汪`, 会自动转换为字符串 |
|
||||||
| 2 | Android Watch | 除了 `Android Pad` 有的限制外还包括: 无法接收撤回消息 |
|
| 2 | Android Watch | 除`Android Phone`的限制外, 无法接收 `notify` 事件、无法接收口令红包、无法接收撤回消息 |
|
||||||
|
| 3 | MacOS | 无 |
|
||||||
|
|
||||||
> 注意, 根据协议的不同, 各类消息有所限制
|
> 注意, 根据协议的不同, 各类消息有所限制
|
||||||
|
|
||||||
|
## 自定义服务器IP
|
||||||
|
|
||||||
|
> 某些海外服务器使用默认地址可能会存在链路问题,此功能可以指定 go-cqhttp 连接哪些地址以达到最优化.
|
||||||
|
|
||||||
|
将文件 `address.txt` 创建到 `go-cqhttp` 工作目录, 并键入 `IP:PORT` 以换行符为分割即可.
|
||||||
|
|
||||||
|
示例:
|
||||||
|
````
|
||||||
|
1.1.1.1:53
|
||||||
|
1.1.2.2:8899
|
||||||
|
````
|
592
docs/cqhttp.md
592
docs/cqhttp.md
@ -2,28 +2,84 @@
|
|||||||
|
|
||||||
由于部分 api 原版 CQHTTP 并未实现,go-cqhttp 修改并增加了一些拓展 api .
|
由于部分 api 原版 CQHTTP 并未实现,go-cqhttp 修改并增加了一些拓展 api .
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>目录</summary>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
##### CQCode
|
||||||
|
- [图片](#图片)
|
||||||
|
- [回复](#回复)
|
||||||
|
- [红包](#红包)
|
||||||
|
- [戳一戳](#戳一戳)
|
||||||
|
- [礼物](#礼物)
|
||||||
|
- [合并转发](#合并转发)
|
||||||
|
- [合并转发消息节点](#合并转发消息节点)
|
||||||
|
- [XML 消息](#xml-消息)
|
||||||
|
- [JSON 消息](#json-消息)
|
||||||
|
- [cardimage](#cardimage)
|
||||||
|
- [文本转语音](#文本转语音)
|
||||||
|
- [图片](#图片)
|
||||||
|
|
||||||
|
##### API
|
||||||
|
- [设置群名](#设置群名)
|
||||||
|
- [设置群头像](#设置群头像)
|
||||||
|
- [获取图片信息](#获取图片信息)
|
||||||
|
- [获取消息](#获取消息)
|
||||||
|
- [获取合并转发内容](#获取合并转发内容)
|
||||||
|
- [发送合并转发(群)](#发送合并转发(群))
|
||||||
|
- [获取中文分词](#获取中文分词)
|
||||||
|
- [图片OCR](#图片OCR)
|
||||||
|
- [获取中文分词](#获取中文分词)
|
||||||
|
- [获取群系统消息](#获取群文件系统信息)
|
||||||
|
- [获取群文件系统信息](#获取群文件系统信息)
|
||||||
|
- [获取群根目录文件列表](#获取群根目录文件列表)
|
||||||
|
- [获取群子目录文件列表](#获取群子目录文件列表)
|
||||||
|
- [获取群文件资源链接](#获取群文件资源链接)
|
||||||
|
- [获取状态](#获取状态)
|
||||||
|
- [获取群子目录文件列表](#设置群名)
|
||||||
|
|
||||||
|
##### 事件
|
||||||
|
- [群消息撤回](#群消息撤回)
|
||||||
|
- [好友消息撤回](#好友消息撤回)
|
||||||
|
- [群内戳一戳](#群内戳一戳)
|
||||||
|
- [群红包运气王提示](#群红包运气王提示)
|
||||||
|
- [群成员荣誉变更提示](#群成员荣誉变更提示)
|
||||||
|
- [群成员名片更新](#群成员名片更新)
|
||||||
|
- [接收到离线文件](#接收到离线文件)
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</details>
|
||||||
|
|
||||||
## CQCode
|
## CQCode
|
||||||
|
|
||||||
### 图片
|
### 图片
|
||||||
|
|
||||||
| 参数名 | 可能的值 | 说明 |
|
Type : `image`
|
||||||
| --- | --- | --- |
|
|
||||||
| `file` | - | 图片文件名 |
|
范围: **发送/接收**
|
||||||
| `type` | `flash`,`show` | 图片类型,`flash` 表示闪照,`show` 表示秀图,默认普通图片 |
|
|
||||||
| `url` | - | 图片 URL |
|
参数:
|
||||||
| `cache` | `0` `1` | 只在通过网络 URL 发送时有效,表示是否使用已缓存的文件,默认 `1` |
|
|
||||||
| `id` | - | 发送秀图时的特效id,默认为40000 |
|
| 参数名 | 可能的值 | 说明 |
|
||||||
|
| ------- | --------------- | --------------------------------------------------------------- |
|
||||||
|
| `file` | - | 图片文件名 |
|
||||||
|
| `type` | `flash`,`show` | 图片类型,`flash` 表示闪照,`show` 表示秀图,默认普通图片 |
|
||||||
|
| `url` | - | 图片 URL |
|
||||||
|
| `cache` | `0` `1` | 只在通过网络 URL 发送时有效,表示是否使用已缓存的文件,默认 `1` |
|
||||||
|
| `id` | - | 发送秀图时的特效id,默认为40000 |
|
||||||
|
|
||||||
可用的特效ID:
|
可用的特效ID:
|
||||||
|
|
||||||
| id |类型 |
|
| id | 类型 |
|
||||||
| --- |-------|
|
| ----- | ---- |
|
||||||
| 40000 | 普通 |
|
| 40000 | 普通 |
|
||||||
| 40001 | 幻影 |
|
| 40001 | 幻影 |
|
||||||
| 40002 | 抖动 |
|
| 40002 | 抖动 |
|
||||||
| 40003 | 生日 |
|
| 40003 | 生日 |
|
||||||
| 40004 | 爱你 |
|
| 40004 | 爱你 |
|
||||||
| 40005 | 征友 |
|
| 40005 | 征友 |
|
||||||
|
|
||||||
|
示例: `[CQ:image,file=http://baidu.com/1.jpg,type=show,id=40004]`
|
||||||
|
|
||||||
|
|
||||||
### 回复
|
### 回复
|
||||||
@ -36,7 +92,7 @@ Type : `reply`
|
|||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ---- | ------------------------------------- |
|
| ------ | ---- | ------------------------------------- |
|
||||||
| id | int | 回复时所引用的消息id, 必须为本群消息. |
|
| `id` | int | 回复时所引用的消息id, 必须为本群消息. |
|
||||||
|
|
||||||
示例: `[CQ:reply,id=123456]`
|
示例: `[CQ:reply,id=123456]`
|
||||||
|
|
||||||
@ -48,9 +104,9 @@ Type: `redbag`
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | ----------- |
|
| ------- | ------ | ----------- |
|
||||||
| title | string | 祝福语/口令 |
|
| `title` | string | 祝福语/口令 |
|
||||||
|
|
||||||
示例: `[CQ:redbag,title=恭喜发财]`
|
示例: `[CQ:redbag,title=恭喜发财]`
|
||||||
|
|
||||||
@ -64,9 +120,9 @@ Type: `poke`
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | ----------- |
|
| ------ | ----- | ------------ |
|
||||||
| qq | int64 | 需要戳的成员 |
|
| `qq` | int64 | 需要戳的成员 |
|
||||||
|
|
||||||
示例: `[CQ:poke,qq=123456]`
|
示例: `[CQ:poke,qq=123456]`
|
||||||
|
|
||||||
@ -80,24 +136,30 @@ Type: `gift`
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 |类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | -----------|
|
| ------ | ----- | -------------- |
|
||||||
| qq | int64 | 接收礼物的成员 |
|
| `qq` | int64 | 接收礼物的成员 |
|
||||||
| id | int | 礼物的类型 |
|
| `id` | int | 礼物的类型 |
|
||||||
|
|
||||||
目前支持的礼物ID:
|
目前支持的礼物ID:
|
||||||
|
|
||||||
| id |类型 |
|
| id | 类型 |
|
||||||
| ---| ---------|
|
| --- | ---------- |
|
||||||
| 0 | 甜Wink |
|
| 0 | 甜Wink |
|
||||||
| 1 | 快乐肥宅水|
|
| 1 | 快乐肥宅水 |
|
||||||
| 2 | 幸运手链 |
|
| 2 | 幸运手链 |
|
||||||
| 3 | 卡布奇诺 |
|
| 3 | 卡布奇诺 |
|
||||||
| 4 | 猫咪手表 |
|
| 4 | 猫咪手表 |
|
||||||
| 5 | 绒绒手套 |
|
| 5 | 绒绒手套 |
|
||||||
| 6 | 彩虹糖果 |
|
| 6 | 彩虹糖果 |
|
||||||
| 7 | 坚强 |
|
| 7 | 坚强 |
|
||||||
| 8 | 告白话筒 |
|
| 8 | 告白话筒 |
|
||||||
|
| 9 | 牵你的手 |
|
||||||
|
| 10 | 可爱猫咪 |
|
||||||
|
| 11 | 神秘面具 |
|
||||||
|
| 12 | 我超忙的 |
|
||||||
|
| 13 | 爱心口罩 |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
示例: `[CQ:gift,qq=123456,id=8]`
|
示例: `[CQ:gift,qq=123456,id=8]`
|
||||||
@ -112,7 +174,7 @@ Type: `forward`
|
|||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | ------------------------------------------------------------ |
|
| ------ | ------ | ------------------------------------------------------------ |
|
||||||
| id | string | 合并转发ID, 需要通过 `/get_forward_msg` API获取转发的具体内容 |
|
| `id` | string | 合并转发ID, 需要通过 `/get_forward_msg` API获取转发的具体内容 |
|
||||||
|
|
||||||
示例: `[CQ:forward,id=xxxx]`
|
示例: `[CQ:forward,id=xxxx]`
|
||||||
|
|
||||||
@ -124,12 +186,12 @@ Type: `node`
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 | 特殊说明 |
|
| 参数名 | 类型 | 说明 | 特殊说明 |
|
||||||
| ------- | ------- | -------------- | ------------------------------------------------------------ |
|
| --------- | ------- | -------------- | ------------------------------------------------------------ |
|
||||||
| id | int32 | 转发消息id | 直接引用他人的消息合并转发, 实际查看顺序为原消息发送顺序 **与下面的自定义消息二选一** |
|
| `id` | int32 | 转发消息id | 直接引用他人的消息合并转发, 实际查看顺序为原消息发送顺序 **与下面的自定义消息二选一** |
|
||||||
| name | string | 发送者显示名字 | 用于自定义消息 (自定义消息并合并转发,实际查看顺序为自定义消息段顺序) |
|
| `name` | string | 发送者显示名字 | 用于自定义消息 (自定义消息并合并转发,实际查看顺序为自定义消息段顺序) |
|
||||||
| uin | int64 | 发送者QQ号 | 用于自定义消息 |
|
| `uin` | int64 | 发送者QQ号 | 用于自定义消息 |
|
||||||
| content | message | 具体消息 | 用于自定义消息 **不支持转发套娃,不支持引用回复** |
|
| `content` | message | 具体消息 | 用于自定义消息 **不支持转发套娃,不支持引用回复** |
|
||||||
|
|
||||||
特殊说明: **需要使用单独的API `/send_group_forward_msg` 发送,并且由于消息段较为复杂,仅支持Array形式入参。 如果引用消息和自定义消息同时出现,实际查看顺序将取消息段顺序. 另外按 [CQHTTP](https://cqhttp.cc/docs/4.15/#/Message?id=格式) 文档说明, `data` 应全为字符串, 但由于需要接收`message` 类型的消息, 所以 *仅限此Type的content字段* 支持Array套娃**
|
特殊说明: **需要使用单独的API `/send_group_forward_msg` 发送,并且由于消息段较为复杂,仅支持Array形式入参。 如果引用消息和自定义消息同时出现,实际查看顺序将取消息段顺序. 另外按 [CQHTTP](https://cqhttp.cc/docs/4.15/#/Message?id=格式) 文档说明, `data` 应全为字符串, 但由于需要接收`message` 类型的消息, 所以 *仅限此Type的content字段* 支持Array套娃**
|
||||||
|
|
||||||
@ -203,7 +265,7 @@ Type: `node`
|
|||||||
]
|
]
|
||||||
````
|
````
|
||||||
|
|
||||||
### xml支持
|
### XML 消息
|
||||||
|
|
||||||
Type: `xml`
|
Type: `xml`
|
||||||
|
|
||||||
@ -211,10 +273,10 @@ Type: `xml`
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | ------------------------------------------------------------ |
|
| ------- | ------ | ----------------------------------------- |
|
||||||
| data | string | xml内容,xml中的value部分,记得实体化处理|
|
| `data` | string | xml内容,xml中的value部分,记得实体化处理 |
|
||||||
| resid | int32 | 可以不填|
|
| `resid` | int32 | 可以不填 |
|
||||||
|
|
||||||
示例: `[CQ:xml,data=xxxx]`
|
示例: `[CQ:xml,data=xxxx]`
|
||||||
|
|
||||||
@ -252,7 +314,7 @@ Type: `xml`
|
|||||||
</msg>
|
</msg>
|
||||||
```
|
```
|
||||||
|
|
||||||
### json消息支持
|
### JSON 消息
|
||||||
|
|
||||||
Type: `json`
|
Type: `json`
|
||||||
|
|
||||||
@ -260,20 +322,20 @@ Type: `json`
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | ------------------------------------------------------------ |
|
| ------- | ------ | ----------------------------------------------- |
|
||||||
| data | string | json内容,json的所有字符串记得实体化处理|
|
| `data` | string | json内容,json的所有字符串记得实体化处理 |
|
||||||
| resid | int32 | 默认不填为0,走小程序通道,填了走富文本通道发送|
|
| `resid` | int32 | 默认不填为0,走小程序通道,填了走富文本通道发送 |
|
||||||
|
|
||||||
json中的字符串需要进行转义:
|
json中的字符串需要进行转义:
|
||||||
|
|
||||||
>","=>`,`、
|
>","=> `,`
|
||||||
|
|
||||||
>"&"=> `&`、
|
>"&"=> `&`
|
||||||
|
|
||||||
>"["=>`[`、
|
>"["=> `[`
|
||||||
|
|
||||||
>"]"=>`]`、
|
>"]"=> `]`
|
||||||
|
|
||||||
否则无法正确得到解析
|
否则无法正确得到解析
|
||||||
|
|
||||||
@ -283,7 +345,8 @@ json中的字符串需要进行转义:
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### cardimage 一种xml的图片消息(装逼大图)
|
### cardimage
|
||||||
|
一种xml的图片消息(装逼大图)
|
||||||
|
|
||||||
ps: xml 接口的消息都存在风控风险,请自行兼容发送失败后的处理(可以失败后走普通图片模式)
|
ps: xml 接口的消息都存在风控风险,请自行兼容发送失败后的处理(可以失败后走普通图片模式)
|
||||||
|
|
||||||
@ -293,15 +356,15 @@ Type: `cardimage`
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | ------------------------------------------------------------ |
|
| ----------- | ------ | ------------------------------------- |
|
||||||
| file | string | 和image的file字段对齐,支持也是一样的|
|
| `file` | string | 和image的file字段对齐,支持也是一样的 |
|
||||||
| minwidth | int64 | 默认不填为400,最小width|
|
| `minwidth` | int64 | 默认不填为400,最小width |
|
||||||
| minheight | int64 | 默认不填为400,最小height|
|
| `minheight` | int64 | 默认不填为400,最小height |
|
||||||
| maxwidth | int64 | 默认不填为500,最大width|
|
| `maxwidth` | int64 | 默认不填为500,最大width |
|
||||||
| maxheight | int64 | 默认不填为1000,最大height|
|
| `maxheight` | int64 | 默认不填为1000,最大height |
|
||||||
| source | string | 分享来源的名称,可以留空|
|
| `source` | string | 分享来源的名称,可以留空 |
|
||||||
| icon | string | 分享来源的icon图标url,可以留空|
|
| `icon` | string | 分享来源的icon图标url,可以留空 |
|
||||||
|
|
||||||
|
|
||||||
示例cardimage 的cq码:
|
示例cardimage 的cq码:
|
||||||
@ -319,9 +382,9 @@ Type: `tts`
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ------ | ----------- |
|
| ------ | ------ | ---- |
|
||||||
| text | string | 内容 |
|
| `text` | string | 内容 |
|
||||||
|
|
||||||
示例: `[CQ:tts,text=这是一条测试消息]`
|
示例: `[CQ:tts,text=这是一条测试消息]`
|
||||||
|
|
||||||
@ -333,10 +396,10 @@ Type: `tts`
|
|||||||
|
|
||||||
**参数**
|
**参数**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| -------- | ------ | ---- |
|
| ------------ | ------ | ---- |
|
||||||
| group_id | int64 | 群号 |
|
| `group_id` | int64 | 群号 |
|
||||||
| group_name | string | 新名 |
|
| `group_name` | string | 新名 |
|
||||||
|
|
||||||
### 设置群头像
|
### 设置群头像
|
||||||
|
|
||||||
@ -344,11 +407,11 @@ Type: `tts`
|
|||||||
|
|
||||||
**参数**
|
**参数**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| -------- | ------ | ---- |
|
| ---------- | ------ | ------------------------ |
|
||||||
| group_id | int64 | 群号 |
|
| `group_id` | int64 | 群号 |
|
||||||
| file | string | 图片文件名 |
|
| `file` | string | 图片文件名 |
|
||||||
| cache | int | 表示是否使用已缓存的文件 |
|
| `cache` | int | 表示是否使用已缓存的文件 |
|
||||||
|
|
||||||
[1]`file` 参数支持以下几种格式:
|
[1]`file` 参数支持以下几种格式:
|
||||||
|
|
||||||
@ -462,15 +525,15 @@ Type: `tts`
|
|||||||
|
|
||||||
**参数**
|
**参数**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ------------ | ------ | ------ |
|
| --------- | ------ | ---- |
|
||||||
| `content` | string | 内容 |
|
| `content` | string | 内容 |
|
||||||
|
|
||||||
**响应数据**
|
**响应数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ----------------- | -------- |
|
| -------- | -------- | ---- |
|
||||||
| `slices` | string[] | 词组 |
|
| `slices` | string[] | 词组 |
|
||||||
|
|
||||||
### 图片OCR
|
### 图片OCR
|
||||||
|
|
||||||
@ -479,26 +542,26 @@ Type: `tts`
|
|||||||
终结点: `/.ocr_image`
|
终结点: `/.ocr_image`
|
||||||
|
|
||||||
**参数**
|
**参数**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ------------ | ------ | ------ |
|
| ------- | ------ | ------ |
|
||||||
| `image` | string | 图片ID |
|
| `image` | string | 图片ID |
|
||||||
|
|
||||||
**响应数据**
|
**响应数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ----------------- | -------- |
|
| ---------- | --------------- | ------- |
|
||||||
| `texts` | TextDetection[] | OCR结果 |
|
| `texts` | TextDetection[] | OCR结果 |
|
||||||
| `language` | string | 语言 |
|
| `language` | string | 语言 |
|
||||||
|
|
||||||
**TextDetection**
|
**TextDetection**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ----------------- | -------- |
|
| ------------- | ------- | ------ |
|
||||||
| `text` | string | 文本 |
|
| `text` | string | 文本 |
|
||||||
| `confidence`| int32 | 置信度 |
|
| `confidence` | int32 | 置信度 |
|
||||||
| `coordinates` | vector2 | 坐标 |
|
| `coordinates` | vector2 | 坐标 |
|
||||||
|
|
||||||
|
|
||||||
### 获取群系统消息
|
### 获取群系统消息
|
||||||
|
|
||||||
@ -506,56 +569,56 @@ Type: `tts`
|
|||||||
|
|
||||||
**响应数据**
|
**响应数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ----------------- | -------- |
|
| ------------------ | ---------------- | ------------ |
|
||||||
| `invited_requests` | InvitedRequest[] | 邀请消息列表 |
|
| `invited_requests` | InvitedRequest[] | 邀请消息列表 |
|
||||||
| `join_requests` | JoinRequest[] | 进群消息列表 |
|
| `join_requests` | JoinRequest[] | 进群消息列表 |
|
||||||
|
|
||||||
> 注意: 如果列表不存在任何消息, 将返回 `null`
|
> 注意: 如果列表不存在任何消息, 将返回 `null`
|
||||||
|
|
||||||
**InvitedRequest**
|
**InvitedRequest**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ----------------- | -------- |
|
| -------------- | ------ | ----------------- |
|
||||||
| `request_id` | int64 | 请求ID |
|
| `request_id` | int64 | 请求ID |
|
||||||
| `invitor_uin` | int64 | 邀请者 |
|
| `invitor_uin` | int64 | 邀请者 |
|
||||||
| `invitor_nick` | string | 邀请者昵称 |
|
| `invitor_nick` | string | 邀请者昵称 |
|
||||||
| `group_id` | int64 | 群号 |
|
| `group_id` | int64 | 群号 |
|
||||||
| `group_name` | string | 群名 |
|
| `group_name` | string | 群名 |
|
||||||
| `checked` | bool | 是否已被处理|
|
| `checked` | bool | 是否已被处理 |
|
||||||
| `actor` | int64 | 处理者, 未处理为0 |
|
| `actor` | int64 | 处理者, 未处理为0 |
|
||||||
|
|
||||||
**JoinRequest**
|
**JoinRequest**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ----------------- | -------- |
|
| ---------------- | ------ | ----------------- |
|
||||||
| `request_id` | int64 | 请求ID |
|
| `request_id` | int64 | 请求ID |
|
||||||
| `requester_uin` | int64 | 请求者ID |
|
| `requester_uin` | int64 | 请求者ID |
|
||||||
| `requester_nick` | string | 请求者昵称 |
|
| `requester_nick` | string | 请求者昵称 |
|
||||||
| `message` | string | 验证消息 |
|
| `message` | string | 验证消息 |
|
||||||
| `group_id` | int64 | 群号 |
|
| `group_id` | int64 | 群号 |
|
||||||
| `group_name` | string | 群名 |
|
| `group_name` | string | 群名 |
|
||||||
| `checked` | bool | 是否已被处理|
|
| `checked` | bool | 是否已被处理 |
|
||||||
| `actor` | int64 | 处理者, 未处理为0 |
|
| `actor` | int64 | 处理者, 未处理为0 |
|
||||||
|
|
||||||
### 获取群文件系统信息
|
### 获取群文件系统信息
|
||||||
|
|
||||||
终结点: `/get_group_file_system_info`
|
终结点: `/get_group_file_system_info`
|
||||||
|
|
||||||
**参数**
|
**参数**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ------------ | ------ | ------ |
|
| ---------- | ----- | ---- |
|
||||||
| `group_id` | int64 | 群号 |
|
| `group_id` | int64 | 群号 |
|
||||||
|
|
||||||
**响应数据**
|
**响应数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ----------------- | -------- |
|
| ------------- | ----- | ---------- |
|
||||||
| `file_count` | int32 | 文件总数 |
|
| `file_count` | int32 | 文件总数 |
|
||||||
| `limit_count` | int32 | 文件上限 |
|
| `limit_count` | int32 | 文件上限 |
|
||||||
| `used_space` | int64 | 已使用空间 |
|
| `used_space` | int64 | 已使用空间 |
|
||||||
| `total_space` | int64 | 空间上限 |
|
| `total_space` | int64 | 空间上限 |
|
||||||
|
|
||||||
### 获取群根目录文件列表
|
### 获取群根目录文件列表
|
||||||
|
|
||||||
@ -564,18 +627,18 @@ Type: `tts`
|
|||||||
终结点: `/get_group_root_files`
|
终结点: `/get_group_root_files`
|
||||||
|
|
||||||
**参数**
|
**参数**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ------------ | ------ | ------ |
|
| ---------- | ----- | ---- |
|
||||||
| `group_id` | int64 | 群号 |
|
| `group_id` | int64 | 群号 |
|
||||||
|
|
||||||
**响应数据**
|
**响应数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ----------------- | -------- |
|
| --------- | -------- | ---------- |
|
||||||
| `files` | File[] | 文件列表 |
|
| `files` | File[] | 文件列表 |
|
||||||
| `folders` | Folder[] | 文件夹列表 |
|
| `folders` | Folder[] | 文件夹列表 |
|
||||||
|
|
||||||
### 获取群子目录文件列表
|
### 获取群子目录文件列表
|
||||||
|
|
||||||
> `File` 和 `Folder` 对象信息请参考最下方
|
> `File` 和 `Folder` 对象信息请参考最下方
|
||||||
@ -583,19 +646,19 @@ Type: `tts`
|
|||||||
终结点: `/get_group_files_by_folder`
|
终结点: `/get_group_files_by_folder`
|
||||||
|
|
||||||
**参数**
|
**参数**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ------------ | ------ | ------ |
|
| ----------- | ------ | --------------------------- |
|
||||||
| `group_id` | int64 | 群号 |
|
| `group_id` | int64 | 群号 |
|
||||||
| `folder_id` | string | 文件夹ID 参考 `Folder` 对象 |
|
| `folder_id` | string | 文件夹ID 参考 `Folder` 对象 |
|
||||||
|
|
||||||
**响应数据**
|
**响应数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ----------------- | -------- |
|
| --------- | -------- | ---------- |
|
||||||
| `files` | File[] | 文件列表 |
|
| `files` | File[] | 文件列表 |
|
||||||
| `folders` | Folder[] | 文件夹列表 |
|
| `folders` | Folder[] | 文件夹列表 |
|
||||||
|
|
||||||
### 获取群文件资源链接
|
### 获取群文件资源链接
|
||||||
|
|
||||||
> `File` 和 `Folder` 对象信息请参考最下方
|
> `File` 和 `Folder` 对象信息请参考最下方
|
||||||
@ -603,48 +666,79 @@ Type: `tts`
|
|||||||
终结点: `/get_group_file_url`
|
终结点: `/get_group_file_url`
|
||||||
|
|
||||||
**参数**
|
**参数**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ------------ | ------ | ------ |
|
| ---------- | ------ | ------------------------- |
|
||||||
| `group_id` | int64 | 群号 |
|
| `group_id` | int64 | 群号 |
|
||||||
| `file_id` | string | 文件ID 参考 `File` 对象 |
|
| `file_id` | string | 文件ID 参考 `File` 对象 |
|
||||||
| `busid` | int32 | 文件类型 参考 `File` 对象 |
|
| `busid` | int32 | 文件类型 参考 `File` 对象 |
|
||||||
|
|
||||||
**响应数据**
|
**响应数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ----------------- | -------- |
|
| ----- | ------ | ------------ |
|
||||||
| `url` | string | 文件下载链接 |
|
| `url` | string | 文件下载链接 |
|
||||||
|
|
||||||
**File**
|
**File**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ----------------- | -------- |
|
| ---------------- | ------ | ---------------------- |
|
||||||
| `file_id` | string | 文件ID |
|
| `file_id` | string | 文件ID |
|
||||||
| `file_name` | string | 文件名 |
|
| `file_name` | string | 文件名 |
|
||||||
| `busid` | int32 | 文件类型 |
|
| `busid` | int32 | 文件类型 |
|
||||||
| `file_size` | int64 | 文件大小 |
|
| `file_size` | int64 | 文件大小 |
|
||||||
| `upload_time` | int64 | 上传时间 |
|
| `upload_time` | int64 | 上传时间 |
|
||||||
| `dead_time` | int64 | 过期时间,永久文件恒为0 |
|
| `dead_time` | int64 | 过期时间,永久文件恒为0 |
|
||||||
| `modify_time` | int64 | 最后修改时间 |
|
| `modify_time` | int64 | 最后修改时间 |
|
||||||
| `download_times` | int32 | 下载次数 |
|
| `download_times` | int32 | 下载次数 |
|
||||||
| `uploader` | int64 | 上传者ID |
|
| `uploader` | int64 | 上传者ID |
|
||||||
| `uploader_name` | string | 上传者名字 |
|
| `uploader_name` | string | 上传者名字 |
|
||||||
|
|
||||||
**Folder**
|
**Folder**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ----------------- | -------- |
|
| ------------------ | ------ | ---------- |
|
||||||
| `folder_id` | string | 文件夹ID |
|
| `folder_id` | string | 文件夹ID |
|
||||||
| `folder_name` | string | 文件名 |
|
| `folder_name` | string | 文件名 |
|
||||||
| `create_time` | int64 | 创建时间 |
|
| `create_time` | int64 | 创建时间 |
|
||||||
| `creator` | int64 | 创建者 |
|
| `creator` | int64 | 创建者 |
|
||||||
| `creator_name` | string | 创建者名字 |
|
| `creator_name` | string | 创建者名字 |
|
||||||
| `total_file_count` | int32 | 子文件数量 |
|
| `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 | 账号掉线次数 |
|
||||||
|
|
||||||
|
> 注意: 所有统计信息都将在重启后重制
|
||||||
|
|
||||||
## 事件
|
## 事件
|
||||||
|
|
||||||
#### 群消息撤回
|
### 群消息撤回
|
||||||
|
|
||||||
**上报数据**
|
**上报数据**
|
||||||
|
|
||||||
@ -657,94 +751,94 @@ Type: `tts`
|
|||||||
| `operator_id` | int64 | | 操作者id |
|
| `operator_id` | int64 | | 操作者id |
|
||||||
| `message_id` | int64 | | 被撤回的消息id |
|
| `message_id` | int64 | | 被撤回的消息id |
|
||||||
|
|
||||||
#### 好友消息撤回
|
### 好友消息撤回
|
||||||
|
|
||||||
**上报数据**
|
**上报数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 可能的值 | 说明 |
|
| 字段 | 类型 | 可能的值 | 说明 |
|
||||||
| ------------- | ------ | -------------- | -------------- |
|
| ------------- | ------ | --------------- | -------------- |
|
||||||
| `post_type` | string | `notice` | 上报类型 |
|
| `post_type` | string | `notice` | 上报类型 |
|
||||||
| `notice_type` | string | `friend_recall`| 消息类型 |
|
| `notice_type` | string | `friend_recall` | 消息类型 |
|
||||||
| `user_id` | int64 | | 好友id |
|
| `user_id` | int64 | | 好友id |
|
||||||
| `message_id` | int64 | | 被撤回的消息id |
|
| `message_id` | int64 | | 被撤回的消息id |
|
||||||
|
|
||||||
#### 群内戳一戳
|
### 群内戳一戳
|
||||||
|
|
||||||
> 注意:此事件无法在平板和手表协议上触发
|
> 注意:此事件无法在平板和手表协议上触发
|
||||||
|
|
||||||
**上报数据**
|
**上报数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 可能的值 | 说明 |
|
| 字段 | 类型 | 可能的值 | 说明 |
|
||||||
| ------------- | ------ | -------------- | -------------- |
|
| ------------- | ------ | -------- | -------- |
|
||||||
| `post_type` | string | `notice` | 上报类型 |
|
| `post_type` | string | `notice` | 上报类型 |
|
||||||
| `notice_type` | string | `notify` | 消息类型 |
|
| `notice_type` | string | `notify` | 消息类型 |
|
||||||
| `group_id` | int64 | | 群号 |
|
| `group_id` | int64 | | 群号 |
|
||||||
| `sub_type` | string | `poke` | 提示类型 |
|
| `sub_type` | string | `poke` | 提示类型 |
|
||||||
| `user_id` | int64 | | 发送者id |
|
| `user_id` | int64 | | 发送者id |
|
||||||
| `target_id` | int64 | | 被戳者id |
|
| `target_id` | int64 | | 被戳者id |
|
||||||
|
|
||||||
#### 群红包运气王提示
|
### 群红包运气王提示
|
||||||
|
|
||||||
> 注意:此事件无法在平板和手表协议上触发
|
> 注意:此事件无法在平板和手表协议上触发
|
||||||
|
|
||||||
**上报数据**
|
**上报数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 可能的值 | 说明 |
|
| 字段 | 类型 | 可能的值 | 说明 |
|
||||||
| ------------- | ------ | -------------- | -------------- |
|
| ------------- | ------ | ------------ | ------------ |
|
||||||
| `post_type` | string | `notice` | 上报类型 |
|
| `post_type` | string | `notice` | 上报类型 |
|
||||||
| `notice_type` | string | `notify` | 消息类型 |
|
| `notice_type` | string | `notify` | 消息类型 |
|
||||||
| `group_id` | int64 | | 群号 |
|
| `group_id` | int64 | | 群号 |
|
||||||
| `sub_type` | string | `lucky_king` | 提示类型 |
|
| `sub_type` | string | `lucky_king` | 提示类型 |
|
||||||
| `user_id` | int64 | | 红包发送者id |
|
| `user_id` | int64 | | 红包发送者id |
|
||||||
| `target_id` | int64 | | 运气王id |
|
| `target_id` | int64 | | 运气王id |
|
||||||
|
|
||||||
#### 群成员荣誉变更提示
|
### 群成员荣誉变更提示
|
||||||
|
|
||||||
> 注意:此事件无法在平板和手表协议上触发
|
> 注意:此事件无法在平板和手表协议上触发
|
||||||
|
|
||||||
**上报数据**
|
**上报数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 可能的值 | 说明 |
|
| 字段 | 类型 | 可能的值 | 说明 |
|
||||||
| ------------- | ------ | -------------- | -------------- |
|
| ------------- | ------ | -------------------------------------------------------- | -------- |
|
||||||
| `post_type` | string | `notice` | 上报类型 |
|
| `post_type` | string | `notice` | 上报类型 |
|
||||||
| `notice_type` | string | `notify` | 消息类型 |
|
| `notice_type` | string | `notify` | 消息类型 |
|
||||||
| `group_id` | int64 | | 群号 |
|
| `group_id` | int64 | | 群号 |
|
||||||
| `sub_type` | string | `honor` | 提示类型 |
|
| `sub_type` | string | `honor` | 提示类型 |
|
||||||
| `user_id` | int64 | | 成员id |
|
| `user_id` | int64 | | 成员id |
|
||||||
| `honor_type` | string | `talkative:龙王` `performer:群聊之火` `emotion:快乐源泉` | 荣誉类型 |
|
| `honor_type` | string | `talkative:龙王` `performer:群聊之火` `emotion:快乐源泉` | 荣誉类型 |
|
||||||
|
|
||||||
#### 群成员名片更新
|
### 群成员名片更新
|
||||||
|
|
||||||
> 注意: 此事件不保证时效性,仅在收到消息时校验卡片
|
> 注意: 此事件不保证时效性,仅在收到消息时校验卡片
|
||||||
|
|
||||||
**上报数据**
|
**上报数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 可能的值 | 说明 |
|
| 字段 | 类型 | 可能的值 | 说明 |
|
||||||
| ------------- | ------ | -------------- | -------------- |
|
| ------------- | ------ | ------------ | -------- |
|
||||||
| `post_type` | string | `notice` | 上报类型 |
|
| `post_type` | string | `notice` | 上报类型 |
|
||||||
| `notice_type` | string | `group_card` | 消息类型 |
|
| `notice_type` | string | `group_card` | 消息类型 |
|
||||||
| `group_id` | int64 | | 群号 |
|
| `group_id` | int64 | | 群号 |
|
||||||
| `user_id` | int64 | | 成员id |
|
| `user_id` | int64 | | 成员id |
|
||||||
| `card_new` | int64 | | 新名片 |
|
| `card_new` | int64 | | 新名片 |
|
||||||
| `card_old` | int64 | | 旧名片 |
|
| `card_old` | int64 | | 旧名片 |
|
||||||
|
|
||||||
> PS: 当名片为空时 `card_xx` 字段为空字符串, 并不是昵称
|
> PS: 当名片为空时 `card_xx` 字段为空字符串, 并不是昵称
|
||||||
|
|
||||||
#### 接收到离线文件
|
### 接收到离线文件
|
||||||
|
|
||||||
**上报数据**
|
**上报数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 可能的值 | 说明 |
|
| 字段 | 类型 | 可能的值 | 说明 |
|
||||||
| ------------- | ------ | -------------- | -------------- |
|
| ------------- | ------ | -------------- | -------- |
|
||||||
| `post_type` | string | `notice` | 上报类型 |
|
| `post_type` | string | `notice` | 上报类型 |
|
||||||
| `notice_type` | string | `offline_file` | 消息类型 |
|
| `notice_type` | string | `offline_file` | 消息类型 |
|
||||||
| `user_id` | int64 | | 发送者id |
|
| `user_id` | int64 | | 发送者id |
|
||||||
| `file` | object | | 文件数据 |
|
| `file` | object | | 文件数据 |
|
||||||
|
|
||||||
**file object**
|
**file object**
|
||||||
|
|
||||||
| 字段 | 类型 | 可能的值 | 说明 |
|
| 字段 | 类型 | 可能的值 | 说明 |
|
||||||
| ------------- | ------ | -------------- | -------------- |
|
| ------ | ------ | -------- | -------- |
|
||||||
| `name` | string | | 文件名 |
|
| `name` | string | | 文件名 |
|
||||||
| `size` | int64 | | 文件大小 |
|
| `size` | int64 | | 文件大小 |
|
||||||
| `url` | string | | 下载链接 |
|
| `url` | string | | 下载链接 |
|
||||||
|
@ -5,7 +5,7 @@ go-cqhttp 默认生成的文件树如下所示:
|
|||||||
````
|
````
|
||||||
.
|
.
|
||||||
├── go-cqhttp
|
├── go-cqhttp
|
||||||
├── config.json
|
├── config.hjson
|
||||||
├── device.json
|
├── device.json
|
||||||
├── logs
|
├── logs
|
||||||
│ └── xx-xx-xx.log
|
│ └── xx-xx-xx.log
|
||||||
@ -18,7 +18,7 @@ go-cqhttp 默认生成的文件树如下所示:
|
|||||||
| 文件 | 用途 |
|
| 文件 | 用途 |
|
||||||
| ----------- | ------------------- |
|
| ----------- | ------------------- |
|
||||||
| go-cqhttp | go-cqhttp可执行文件 |
|
| go-cqhttp | go-cqhttp可执行文件 |
|
||||||
| config.json | 运行配置文件 |
|
| config.hjson | 运行配置文件 |
|
||||||
| device.json | 虚拟设备配置文件 |
|
| device.json | 虚拟设备配置文件 |
|
||||||
| logs | 日志存放目录 |
|
| logs | 日志存放目录 |
|
||||||
| data | 数据目录 |
|
| data | 数据目录 |
|
||||||
|
@ -28,8 +28,8 @@
|
|||||||
|
|
||||||
1. 双击`go-cqhttp.exe`此时将提示
|
1. 双击`go-cqhttp.exe`此时将提示
|
||||||
```
|
```
|
||||||
[WARNING]: 尝试加载配置文件 config.json 失败: 文件不存在
|
[WARNING]: 尝试加载配置文件 config.hjson 失败: 文件不存在
|
||||||
[INFO]: 默认配置文件已生成,请编辑 config.json 后重启程序.
|
[INFO]: 默认配置文件已生成,请编辑 config.hjson 后重启程序.
|
||||||
```
|
```
|
||||||
2. 参照[config.md](https://github.com/Mrs4s/go-cqhttp/blob/master/docs/config.md)和你所用到的插件的 `README` 填入参数
|
2. 参照[config.md](https://github.com/Mrs4s/go-cqhttp/blob/master/docs/config.md)和你所用到的插件的 `README` 填入参数
|
||||||
3. 再次双击`go-cqhttp.exe`
|
3. 再次双击`go-cqhttp.exe`
|
||||||
@ -79,8 +79,8 @@ enable ws?(Y/n)
|
|||||||
2. `cd`到解压目录
|
2. `cd`到解压目录
|
||||||
3. 输入 `./go-cqhttp`,`Enter`运行 ,此时将提示
|
3. 输入 `./go-cqhttp`,`Enter`运行 ,此时将提示
|
||||||
```
|
```
|
||||||
[WARNING]: 尝试加载配置文件 config.json 失败: 文件不存在
|
[WARNING]: 尝试加载配置文件 config.hjson 失败: 文件不存在
|
||||||
[INFO]: 默认配置文件已生成,请编辑 config.json 后重启程序.
|
[INFO]: 默认配置文件已生成,请编辑 config.hjson 后重启程序.
|
||||||
```
|
```
|
||||||
|
|
||||||
4. 参照[config.md](https://github.com/Mrs4s/go-cqhttp/blob/master/docs/config.md)和你所用到的插件的 `README` 填入参数
|
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
|
如果出现`{"data":{"message_id":balabala},"retcode":0,"status":"ok"}`则证明已经成功配置HTTP
|
||||||
|
|
||||||
|
*注:请 连 中括号 也替换掉,就像这样:*`http://127.0.0.1:5700/send_private_msg?user_id=10001&message=ffeecoishp`
|
||||||
|
|
||||||
# 进阶指南
|
# 进阶指南
|
||||||
|
|
||||||
## 如何自己构建
|
## 如何自己构建
|
||||||
@ -117,7 +119,29 @@ enable ws?(Y/n)
|
|||||||
|
|
||||||
*注:可以使用*`go env -w GOPROXY=https://goproxy.cn,direct`*来加速国内依赖安装速度*
|
*注:可以使用*`go env -w GOPROXY=https://goproxy.cn,direct`*来加速国内依赖安装速度*
|
||||||
|
|
||||||
*注:此时构建后的文件名为*`main`(Linux)或`main.exe`(Windows)
|
## 更新
|
||||||
|
|
||||||
|
### 方法一
|
||||||
|
|
||||||
|
从[release](https://github.com/Mrs4s/go-cqhttp/releases)界面下载最新版本的go-cqhttp
|
||||||
|
并替换之前的版本
|
||||||
|
|
||||||
|
### 方法二
|
||||||
|
|
||||||
|
使用更新参数,在命令行中打开go-cqhttp所在目录
|
||||||
|
#### windows
|
||||||
|
输入指令
|
||||||
|
`go-cqhttp.exe update`
|
||||||
|
|
||||||
|
如果在国内连接github下载速度可能很慢,可以使用镜像源下载
|
||||||
|
|
||||||
|
`go-cqhttp.exe update https://github.rc1844.workers.dev`
|
||||||
|
|
||||||
|
几个可用的镜像源
|
||||||
|
- `https://hub.fastgit.org`
|
||||||
|
- `https://github.com.cnpmjs.org`
|
||||||
|
- `https://github.bajins.com`
|
||||||
|
- `https://github.rc1844.workers.dev`
|
||||||
|
|
||||||
|
#### linux
|
||||||
|
方法与windows基本一致,将 `go-cqhttp.exe` 替换为 `./go-cqhttp`即可
|
||||||
|
@ -4,11 +4,12 @@ import (
|
|||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"github.com/wdvxdr1123/go-silk/silk"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path"
|
"path"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/wdvxdr1123/go-silk/silk"
|
||||||
)
|
)
|
||||||
|
|
||||||
var codec silk.Encoder
|
var codec silk.Encoder
|
||||||
|
149
global/config.go
149
global/config.go
@ -1,14 +1,139 @@
|
|||||||
package global
|
package global
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hjson/hjson-go"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
log "github.com/sirupsen/logrus"
|
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 {
|
type JsonConfig struct {
|
||||||
Uin int64 `json:"uin"`
|
Uin int64 `json:"uin"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
@ -28,11 +153,13 @@ type JsonConfig struct {
|
|||||||
} `json:"_rate_limit"`
|
} `json:"_rate_limit"`
|
||||||
IgnoreInvalidCQCode bool `json:"ignore_invalid_cqcode"`
|
IgnoreInvalidCQCode bool `json:"ignore_invalid_cqcode"`
|
||||||
ForceFragmented bool `json:"force_fragmented"`
|
ForceFragmented bool `json:"force_fragmented"`
|
||||||
|
ProxyRewrite string `json:"proxy_rewrite"`
|
||||||
HeartbeatInterval time.Duration `json:"heartbeat_interval"`
|
HeartbeatInterval time.Duration `json:"heartbeat_interval"`
|
||||||
HttpConfig *GoCQHttpConfig `json:"http_config"`
|
HttpConfig *GoCQHttpConfig `json:"http_config"`
|
||||||
WSConfig *GoCQWebsocketConfig `json:"ws_config"`
|
WSConfig *GoCQWebsocketConfig `json:"ws_config"`
|
||||||
ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"`
|
ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"`
|
||||||
PostMessageFormat string `json:"post_message_format"`
|
PostMessageFormat string `json:"post_message_format"`
|
||||||
|
UseSSOAddress bool `json:"use_sso_address"`
|
||||||
Debug bool `json:"debug"`
|
Debug bool `json:"debug"`
|
||||||
LogLevel string `json:"log_level"`
|
LogLevel string `json:"log_level"`
|
||||||
WebUi *GoCqWebUi `json:"web_ui"`
|
WebUi *GoCqWebUi `json:"web_ui"`
|
||||||
@ -143,22 +270,30 @@ func Load(p string) *JsonConfig {
|
|||||||
log.Warnf("尝试加载配置文件 %v 失败: 文件不存在", p)
|
log.Warnf("尝试加载配置文件 %v 失败: 文件不存在", p)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
c := JsonConfig{}
|
var dat map[string]interface{}
|
||||||
err := json.Unmarshal([]byte(ReadAllText(p)), &c)
|
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 {
|
if err != nil {
|
||||||
log.Warnf("尝试加载配置文件 %v 时出现错误: %v", p, err)
|
log.Warnf("尝试加载配置文件 %v 时出现错误: %v", p, err)
|
||||||
log.Infoln("原文件已备份")
|
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 nil
|
||||||
}
|
}
|
||||||
return &c
|
return &c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *JsonConfig) Save(p string) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
WriteAllText(p, string(data))
|
return WriteAllText(p, string(data))
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
122
global/filter.go
122
global/filter.go
@ -1,24 +1,46 @@
|
|||||||
package global
|
package global
|
||||||
|
|
||||||
import (
|
import (
|
||||||
log "github.com/sirupsen/logrus"
|
"fmt"
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Filter interface {
|
type MSG map[string]interface{}
|
||||||
Eval(payload gjson.Result) bool
|
|
||||||
|
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
|
key string
|
||||||
filter Filter
|
filter Filter
|
||||||
}
|
}
|
||||||
|
|
||||||
type NotOperator struct {
|
type NotOperator struct {
|
||||||
operand_ Filter
|
operand Filter
|
||||||
}
|
}
|
||||||
|
|
||||||
func notOperatorConstruct(argument gjson.Result) *NotOperator {
|
func notOperatorConstruct(argument gjson.Result) *NotOperator {
|
||||||
@ -26,16 +48,16 @@ func notOperatorConstruct(argument gjson.Result) *NotOperator {
|
|||||||
panic("the argument of 'not' operator must be an object")
|
panic("the argument of 'not' operator must be an object")
|
||||||
}
|
}
|
||||||
op := new(NotOperator)
|
op := new(NotOperator)
|
||||||
op.operand_ = Generate("and", argument)
|
op.operand = Generate("and", argument)
|
||||||
return op
|
return op
|
||||||
}
|
}
|
||||||
|
|
||||||
func (notOperator NotOperator) Eval(payload gjson.Result) bool {
|
func (op *NotOperator) Eval(payload MSG) bool {
|
||||||
return !(notOperator.operand_).Eval(payload)
|
return !op.operand.Eval(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
type AndOperator struct {
|
type AndOperator struct {
|
||||||
operands []OperationNode
|
operands []operationNode
|
||||||
}
|
}
|
||||||
|
|
||||||
func andOperatorConstruct(argument gjson.Result) *AndOperator {
|
func andOperatorConstruct(argument gjson.Result) *AndOperator {
|
||||||
@ -50,26 +72,26 @@ func andOperatorConstruct(argument gjson.Result) *AndOperator {
|
|||||||
// "bar": "baz"
|
// "bar": "baz"
|
||||||
// }
|
// }
|
||||||
opKey := key.Str[1:]
|
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() {
|
} else if value.IsObject() {
|
||||||
// is an normal key with an object as the value
|
// is an normal key with an object as the value
|
||||||
// "foo": {
|
// "foo": {
|
||||||
// ".bar": "baz"
|
// ".bar": "baz"
|
||||||
// }
|
// }
|
||||||
opKey := key.String()
|
opKey := key.String()
|
||||||
op.operands = append(op.operands, OperationNode{opKey, Generate("and", value)})
|
op.operands = append(op.operands, operationNode{opKey, Generate("and", value)})
|
||||||
} else {
|
} else {
|
||||||
// is an normal key with a non-object as the value
|
// is an normal key with a non-object as the value
|
||||||
// "foo": "bar"
|
// "foo": "bar"
|
||||||
opKey := key.String()
|
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 true
|
||||||
})
|
})
|
||||||
return op
|
return op
|
||||||
}
|
}
|
||||||
|
|
||||||
func (andOperator *AndOperator) Eval(payload gjson.Result) bool {
|
func (andOperator *AndOperator) Eval(payload MSG) bool {
|
||||||
res := true
|
res := true
|
||||||
for _, operand := range andOperator.operands {
|
for _, operand := range andOperator.operands {
|
||||||
|
|
||||||
@ -105,11 +127,10 @@ func orOperatorConstruct(argument gjson.Result) *OrOperator {
|
|||||||
return op
|
return op
|
||||||
}
|
}
|
||||||
|
|
||||||
func (orOperator OrOperator) Eval(payload gjson.Result) bool {
|
func (op *OrOperator) Eval(payload MSG) bool {
|
||||||
res := false
|
res := false
|
||||||
for _, operand := range orOperator.operands {
|
for _, operand := range op.operands {
|
||||||
res = res || operand.Eval(payload)
|
res = res || operand.Eval(payload)
|
||||||
|
|
||||||
if res == true {
|
if res == true {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -118,35 +139,36 @@ func (orOperator OrOperator) Eval(payload gjson.Result) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type EqualOperator struct {
|
type EqualOperator struct {
|
||||||
value gjson.Result
|
operand string
|
||||||
}
|
}
|
||||||
|
|
||||||
func equalOperatorConstruct(argument gjson.Result) *EqualOperator {
|
func equalOperatorConstruct(argument gjson.Result) *EqualOperator {
|
||||||
op := new(EqualOperator)
|
op := new(EqualOperator)
|
||||||
op.value = argument
|
op.operand = argument.String()
|
||||||
return op
|
return op
|
||||||
}
|
}
|
||||||
|
|
||||||
func (equalOperator EqualOperator) Eval(payload gjson.Result) bool {
|
func (op *EqualOperator) Eval(payload MSG) bool {
|
||||||
return payload.String() == equalOperator.value.String()
|
return payload.String() == op.operand
|
||||||
}
|
}
|
||||||
|
|
||||||
type NotEqualOperator struct {
|
type NotEqualOperator struct {
|
||||||
value gjson.Result
|
operand string
|
||||||
}
|
}
|
||||||
|
|
||||||
func notEqualOperatorConstruct(argument gjson.Result) *NotEqualOperator {
|
func notEqualOperatorConstruct(argument gjson.Result) *NotEqualOperator {
|
||||||
op := new(NotEqualOperator)
|
op := new(NotEqualOperator)
|
||||||
op.value = argument
|
op.operand = argument.String()
|
||||||
return op
|
return op
|
||||||
}
|
}
|
||||||
|
|
||||||
func (notEqualOperator NotEqualOperator) Eval(payload gjson.Result) bool {
|
func (op *NotEqualOperator) Eval(payload MSG) bool {
|
||||||
return !(payload.String() == notEqualOperator.value.String())
|
return !(payload.String() == op.operand)
|
||||||
}
|
}
|
||||||
|
|
||||||
type InOperator struct {
|
type InOperator struct {
|
||||||
operand gjson.Result
|
operandString string
|
||||||
|
operandArray []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func inOperatorConstruct(argument gjson.Result) *InOperator {
|
func inOperatorConstruct(argument gjson.Result) *InOperator {
|
||||||
@ -154,20 +176,29 @@ func inOperatorConstruct(argument gjson.Result) *InOperator {
|
|||||||
panic("the argument of 'in' operator must be an array or a string")
|
panic("the argument of 'in' operator must be an array or a string")
|
||||||
}
|
}
|
||||||
op := new(InOperator)
|
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
|
return op
|
||||||
}
|
}
|
||||||
|
|
||||||
func (inOperator InOperator) Eval(payload gjson.Result) bool {
|
func (op *InOperator) Eval(payload MSG) bool {
|
||||||
if inOperator.operand.IsArray() {
|
payloadStr := payload.String()
|
||||||
res := false
|
if op.operandArray != nil {
|
||||||
inOperator.operand.ForEach(func(key, value gjson.Result) bool {
|
for _, value := range op.operandArray {
|
||||||
res = res || value.String() == payload.String()
|
if value == payloadStr {
|
||||||
return true
|
return true
|
||||||
})
|
}
|
||||||
return res
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
return strings.Contains(inOperator.operand.String(), payload.String())
|
return strings.Contains(op.operandString, payloadStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContainsOperator struct {
|
type ContainsOperator struct {
|
||||||
@ -183,15 +214,12 @@ func containsOperatorConstruct(argument gjson.Result) *ContainsOperator {
|
|||||||
return op
|
return op
|
||||||
}
|
}
|
||||||
|
|
||||||
func (containsOperator ContainsOperator) Eval(payload gjson.Result) bool {
|
func (op *ContainsOperator) Eval(payload MSG) bool {
|
||||||
if payload.IsObject() || payload.IsArray() {
|
return strings.Contains(payload.String(), op.operand)
|
||||||
return false
|
|
||||||
}
|
|
||||||
return strings.Contains(payload.String(), containsOperator.operand)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type RegexOperator struct {
|
type RegexOperator struct {
|
||||||
regex string
|
regex *regexp.Regexp
|
||||||
}
|
}
|
||||||
|
|
||||||
func regexOperatorConstruct(argument gjson.Result) *RegexOperator {
|
func regexOperatorConstruct(argument gjson.Result) *RegexOperator {
|
||||||
@ -199,12 +227,12 @@ func regexOperatorConstruct(argument gjson.Result) *RegexOperator {
|
|||||||
panic("the argument of 'regex' operator must be a string")
|
panic("the argument of 'regex' operator must be a string")
|
||||||
}
|
}
|
||||||
op := new(RegexOperator)
|
op := new(RegexOperator)
|
||||||
op.regex = argument.String()
|
op.regex = regexp.MustCompile(argument.String())
|
||||||
return op
|
return op
|
||||||
}
|
}
|
||||||
|
|
||||||
func (containsOperator RegexOperator) Eval(payload gjson.Result) bool {
|
func (op *RegexOperator) Eval(payload MSG) bool {
|
||||||
matched, _ := regexp.MatchString(containsOperator.regex, payload.String())
|
matched := op.regex.MatchString(payload.String())
|
||||||
return matched
|
return matched
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +259,7 @@ func Generate(opName string, argument gjson.Result) Filter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var EventFilter = new(Filter)
|
var EventFilter Filter = nil
|
||||||
|
|
||||||
func BootFilter() {
|
func BootFilter() {
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -246,6 +274,6 @@ func BootFilter() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
} else {
|
} else {
|
||||||
*EventFilter = Generate("and", gjson.ParseBytes(f))
|
EventFilter = Generate("and", gjson.ParseBytes(f))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
45
global/fs.go
45
global/fs.go
@ -6,13 +6,18 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
log "github.com/sirupsen/logrus"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/dustin/go-humanize"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -38,8 +43,8 @@ func ReadAllText(path string) string {
|
|||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteAllText(path, text string) {
|
func WriteAllText(path, text string) error {
|
||||||
_ = ioutil.WriteFile(path, []byte(text), 0644)
|
return ioutil.WriteFile(path, []byte(text), 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Check(err error) {
|
func Check(err error) {
|
||||||
@ -107,3 +112,37 @@ func DelFile(path string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ReadAddrFile(path string) []*net.TCPAddr {
|
||||||
|
d, err := ioutil.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
str := string(d)
|
||||||
|
lines := strings.Split(str, "\n")
|
||||||
|
var ret []*net.TCPAddr
|
||||||
|
for _, l := range lines {
|
||||||
|
ip := strings.Split(strings.TrimSpace(l), ":")
|
||||||
|
if len(ip) == 2 {
|
||||||
|
port, _ := strconv.Atoi(ip[1])
|
||||||
|
ret = append(ret, &net.TCPAddr{IP: net.ParseIP(ip[0]), Port: port})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
type WriteCounter struct {
|
||||||
|
Total uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (wc *WriteCounter) Write(p []byte) (int, error) {
|
||||||
|
n := len(p)
|
||||||
|
wc.Total += uint64(n)
|
||||||
|
wc.PrintProgress()
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (wc WriteCounter) PrintProgress() {
|
||||||
|
fmt.Printf("\r%s", strings.Repeat(" ", 35))
|
||||||
|
fmt.Printf("\rDownloading... %s complete", humanize.Bytes(wc.Total))
|
||||||
|
}
|
||||||
|
@ -4,17 +4,40 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
var client = &http.Client{
|
var client = &http.Client{
|
||||||
Timeout: time.Second * 15,
|
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,
|
||||||
|
DualStack: true,
|
||||||
|
}).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) {
|
func GetBytes(url string) ([]byte, error) {
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package global
|
package global
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
"math"
|
"math"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
var trueSet = map[string]struct{}{
|
var trueSet = map[string]struct{}{
|
||||||
|
@ -2,6 +2,7 @@ package global
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"golang.org/x/time/rate"
|
"golang.org/x/time/rate"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
17
go.mod
17
go.mod
@ -1,21 +1,28 @@
|
|||||||
module github.com/Mrs4s/go-cqhttp
|
module github.com/Mrs4s/go-cqhttp
|
||||||
|
|
||||||
go 1.14
|
go 1.15
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20201105120358-ca72d542ca72
|
github.com/Mrs4s/MiraiGo v0.0.0-20201209180326-c07a8a9c8a83
|
||||||
|
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/gin-gonic/gin v1.6.3
|
||||||
github.com/gorilla/websocket v1.4.2
|
github.com/gorilla/websocket v1.4.2
|
||||||
github.com/guonaihong/gout v0.1.3
|
github.com/guonaihong/gout v0.1.3
|
||||||
|
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/file-rotatelogs v2.4.0+incompatible
|
||||||
github.com/lestrrat-go/strftime v1.0.3 // indirect
|
github.com/lestrrat-go/strftime v1.0.3 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
|
||||||
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
|
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
|
||||||
github.com/sirupsen/logrus v1.7.0
|
github.com/sirupsen/logrus v1.7.0
|
||||||
github.com/syndtr/goleveldb v1.0.0
|
github.com/syndtr/goleveldb v1.0.0
|
||||||
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
|
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
|
||||||
github.com/tidwall/gjson v1.6.1
|
github.com/tidwall/gjson v1.6.3
|
||||||
github.com/wdvxdr1123/go-silk v0.0.0-20201007123416-b982fd3d91d6
|
github.com/wdvxdr1123/go-silk v0.0.0-20201203155442-67728040c843
|
||||||
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
|
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
|
||||||
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
|
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
|
||||||
)
|
)
|
||||||
|
45
go.sum
45
go.sum
@ -1,17 +1,36 @@
|
|||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20201105120358-ca72d542ca72 h1:aiKVmrgZHXARnO6AYODwFf1JvTZr6OCl2pohepkkYKc=
|
github.com/Mrs4s/MiraiGo v0.0.0-20201209180326-c07a8a9c8a83 h1:9mCmMOTDlQ5reudlum8JAjmrsqSdG0692/BgOIuPIhs=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20201105120358-ca72d542ca72/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs=
|
github.com/Mrs4s/MiraiGo v0.0.0-20201209180326-c07a8a9c8a83/go.mod h1:J1zaJWyeX7hQIPpOobqb8opxTNPbguotudPPrHJMoDM=
|
||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
|
||||||
|
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||||
|
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 h1:NRUJuo3v3WGC/g5YiyF790gut6oQr5f3FBI88Wv0dx4=
|
||||||
|
github.com/getlantern/context v0.0.0-20190109183933-c447772a6520/go.mod h1:L+mq6/vvYHKjCX2oez0CgEAJmbq1fbb/oNJIWQkBybY=
|
||||||
|
github.com/getlantern/errors v1.0.1 h1:XukU2whlh7OdpxnkXhNH9VTLVz0EVPGKDV5K0oWhvzw=
|
||||||
|
github.com/getlantern/errors v1.0.1/go.mod h1:l+xpFBrCtDLpK9qNjxs+cHU6+BAdlBaxHqikB6Lku3A=
|
||||||
|
github.com/getlantern/go-update v0.0.0-20190510022740-79c495ab728c h1:mP9bsvdddRSMwqO+lmNuSrsH7nD2nBIz7af+e/4je4c=
|
||||||
|
github.com/getlantern/go-update v0.0.0-20190510022740-79c495ab728c/go.mod h1:goroSTghTcnjKaR2C8ovKWy1lEvRNfqHrW/kRJNMek0=
|
||||||
|
github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9 h1:8MYJU90rB1bsavemKSAuDKBjtAKo5xq95bEPOnzV7CE=
|
||||||
|
github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9/go.mod h1:ZyIjgH/1wTCl+B+7yH1DqrWp6MPJqESmwmEQ89ZfhvA=
|
||||||
|
github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7 h1:micT5vkcr9tOVk1FiH8SWKID8ultN44Z+yzd2y/Vyb0=
|
||||||
|
github.com/getlantern/hex v0.0.0-20190417191902-c6586a6fe0b7/go.mod h1:dD3CgOrwlzca8ed61CsZouQS5h5jIzkK9ZWrTcf0s+o=
|
||||||
|
github.com/getlantern/hidden v0.0.0-20190325191715-f02dbb02be55 h1:XYzSdCbkzOC0FDNrgJqGRo8PCMFOBFL9py72DRs7bmc=
|
||||||
|
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 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
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.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do=
|
||||||
|
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 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
|
||||||
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
|
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/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||||
@ -23,6 +42,8 @@ github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD87
|
|||||||
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
|
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=
|
github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY=
|
||||||
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
|
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
|
||||||
|
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
|
||||||
|
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
@ -49,10 +70,18 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U
|
|||||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
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 h1:BIiV6nnsA+R6dIB1P33uhCM8+TVAG3zHrXGZad7hDc8=
|
||||||
github.com/guonaihong/gout v0.1.3/go.mod h1:vXvv5Kxr70eM5wrp4F0+t9lnLWmq+YPW2GByll2f/EA=
|
github.com/guonaihong/gout v0.1.3/go.mod h1:vXvv5Kxr70eM5wrp4F0+t9lnLWmq+YPW2GByll2f/EA=
|
||||||
|
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/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.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.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/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.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 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
|
||||||
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
|
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
|
||||||
@ -64,13 +93,17 @@ github.com/lestrrat-go/strftime v1.0.3/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR7
|
|||||||
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
|
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 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
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/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/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 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||||
|
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
|
||||||
|
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
@ -90,8 +123,8 @@ github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFd
|
|||||||
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
|
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 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/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816/go.mod h1:tzym/CEb5jnFI+Q0k4Qq3+LvRF4gO3E2pxS8fHP8jcA=
|
||||||
github.com/tidwall/gjson v1.6.1 h1:LRbvNuNuvAiISWg6gxLEFuCe72UKy5hDqhxW/8183ws=
|
github.com/tidwall/gjson v1.6.3 h1:aHoiiem0dr7GHkW001T1SMTJ7X5PvyekH5WX0whWGnI=
|
||||||
github.com/tidwall/gjson v1.6.1/go.mod h1:BaHyNc5bjzYkPqgLq7mdVzeiRtULKULXLgZFKsxEHI0=
|
github.com/tidwall/gjson v1.6.3/go.mod h1:BaHyNc5bjzYkPqgLq7mdVzeiRtULKULXLgZFKsxEHI0=
|
||||||
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
|
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
|
||||||
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
|
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
|
||||||
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
|
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
|
||||||
@ -100,8 +133,8 @@ 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 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 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
|
||||||
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
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-20201203155442-67728040c843 h1:PRhoPwoTPcB9IDtAj7bEqeGS3SCxZ4xs7/IH35P24jQ=
|
||||||
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-20201203155442-67728040c843/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 h1:4UJw9if55Fu3HOwbfcaQlJ27p3oeJU2JZqoeT3ITJQk=
|
||||||
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189/go.mod h1:rIrm5geMiBhPQkdfUm8gDFi/WiHneOp1i9KjmJqc+9I=
|
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189/go.mod h1:rIrm5geMiBhPQkdfUm8gDFi/WiHneOp1i9KjmJqc+9I=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
239
main.go
239
main.go
@ -4,29 +4,38 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"os/signal"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/Mrs4s/go-cqhttp/server"
|
"github.com/Mrs4s/go-cqhttp/server"
|
||||||
"github.com/guonaihong/gout"
|
"github.com/guonaihong/gout"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"path"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/Mrs4s/MiraiGo/binary"
|
"github.com/Mrs4s/MiraiGo/binary"
|
||||||
"github.com/Mrs4s/MiraiGo/client"
|
"github.com/Mrs4s/MiraiGo/client"
|
||||||
"github.com/Mrs4s/go-cqhttp/coolq"
|
"github.com/Mrs4s/go-cqhttp/coolq"
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
"github.com/lestrrat-go/file-rotatelogs"
|
"github.com/getlantern/go-update"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
||||||
"github.com/rifflock/lfshook"
|
"github.com/rifflock/lfshook"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/t-tomalak/logrus-easy-formatter"
|
easy "github.com/t-tomalak/logrus-easy-formatter"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
log.SetFormatter(&easy.Formatter{
|
log.SetFormatter(&easy.Formatter{
|
||||||
TimestampFormat: "2006-01-02 15:04:05",
|
TimestampFormat: "2006-01-02 15:04:05",
|
||||||
@ -58,7 +67,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
if global.PathExists("cqhttp.json") {
|
if global.PathExists("cqhttp.json") {
|
||||||
log.Info("发现 cqhttp.json 将在五秒后尝试导入配置,按 Ctrl+C 取消.")
|
log.Info("发现 cqhttp.json 将在五秒后尝试导入配置,按 Ctrl+C 取消.")
|
||||||
log.Warn("警告: 该操作会删除 cqhttp.json 并覆盖 config.json 文件.")
|
log.Warn("警告: 该操作会删除 cqhttp.json 并覆盖 config.hjson 文件.")
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
conf := global.CQHttpApiConfig{}
|
conf := global.CQHttpApiConfig{}
|
||||||
if err := json.Unmarshal([]byte(global.ReadAllText("cqhttp.json")), &conf); err != nil {
|
if err := json.Unmarshal([]byte(global.ReadAllText("cqhttp.json")), &conf); err != nil {
|
||||||
@ -80,8 +89,8 @@ func init() {
|
|||||||
goConf.ReverseServers[0].ReverseEventUrl = conf.WSReverseEventUrl
|
goConf.ReverseServers[0].ReverseEventUrl = conf.WSReverseEventUrl
|
||||||
goConf.ReverseServers[0].ReverseReconnectInterval = conf.WSReverseReconnectInterval
|
goConf.ReverseServers[0].ReverseReconnectInterval = conf.WSReverseReconnectInterval
|
||||||
}
|
}
|
||||||
if err := goConf.Save("config.json"); err != nil {
|
if err := goConf.Save("config.hjson"); err != nil {
|
||||||
log.Fatalf("保存 config.json 时出现错误: %v", err)
|
log.Fatalf("保存 config.hjson 时出现错误: %v", err)
|
||||||
}
|
}
|
||||||
_ = os.Remove("cqhttp.json")
|
_ = os.Remove("cqhttp.json")
|
||||||
}
|
}
|
||||||
@ -89,9 +98,35 @@ func init() {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
console := bufio.NewReader(os.Stdin)
|
console := bufio.NewReader(os.Stdin)
|
||||||
|
var strKey string
|
||||||
|
var isFastStart bool = false
|
||||||
|
arg := os.Args
|
||||||
|
if len(arg) > 1 {
|
||||||
|
for i := range arg {
|
||||||
|
switch arg[i] {
|
||||||
|
case "update":
|
||||||
|
if len(arg) > i+1 {
|
||||||
|
selfUpdate(arg[i+1])
|
||||||
|
} else {
|
||||||
|
selfUpdate("")
|
||||||
|
}
|
||||||
|
case "key":
|
||||||
|
if len(arg) > i+1 {
|
||||||
|
b := []byte(arg[i+1])
|
||||||
|
b = append(b, 13, 10)
|
||||||
|
strKey = string(b[:])
|
||||||
|
}
|
||||||
|
case "faststart":
|
||||||
|
isFastStart = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var conf *global.JsonConfig
|
var conf *global.JsonConfig
|
||||||
if global.PathExists("config.json") || os.Getenv("UIN") == "" {
|
if global.PathExists("config.json") {
|
||||||
conf = global.Load("config.json")
|
conf = global.Load("config.json")
|
||||||
|
_ = conf.Save("config.hjson")
|
||||||
|
_ = os.Remove("config.json")
|
||||||
} else if os.Getenv("UIN") != "" {
|
} else if os.Getenv("UIN") != "" {
|
||||||
log.Infof("将从环境变量加载配置.")
|
log.Infof("将从环境变量加载配置.")
|
||||||
uin, _ := strconv.ParseInt(os.Getenv("UIN"), 10, 64)
|
uin, _ := strconv.ParseInt(os.Getenv("UIN"), 10, 64)
|
||||||
@ -117,19 +152,21 @@ func main() {
|
|||||||
if post != "" {
|
if post != "" {
|
||||||
conf.HttpConfig.PostUrls[post] = os.Getenv("HTTP_SECRET")
|
conf.HttpConfig.PostUrls[post] = os.Getenv("HTTP_SECRET")
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
conf = global.Load("config.hjson")
|
||||||
}
|
}
|
||||||
if conf == nil {
|
if conf == nil {
|
||||||
err := global.DefaultConfig().Save("config.json")
|
err := global.WriteAllText("config.hjson", global.DefaultConfigWithComments)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("创建默认配置文件时出现错误: %v", err)
|
log.Fatalf("创建默认配置文件时出现错误: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infof("默认配置文件已生成, 请编辑 config.json 后重启程序.")
|
log.Infof("默认配置文件已生成, 请编辑 config.hjson 后重启程序.")
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if conf.Uin == 0 || (conf.Password == "" && conf.PasswordEncrypted == "") {
|
if conf.Uin == 0 || (conf.Password == "" && conf.PasswordEncrypted == "") {
|
||||||
log.Warnf("请修改 config.json 以添加账号密码.")
|
log.Warnf("请修改 config.hjson 以添加账号密码.")
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -177,6 +214,10 @@ func main() {
|
|||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
log.Warnf("已开启Debug模式.")
|
log.Warnf("已开启Debug模式.")
|
||||||
log.Debugf("开发交流群: 192548878")
|
log.Debugf("开发交流群: 192548878")
|
||||||
|
server.Debug = true
|
||||||
|
if conf.WebUi == nil || !conf.WebUi.Enabled {
|
||||||
|
log.Warnf("警告: 在Debug模式下未启用WebUi服务, 将无法进行性能分析.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !global.PathExists("device.json") {
|
if !global.PathExists("device.json") {
|
||||||
log.Warn("虚拟设备信息不存在, 将自动生成随机设备.")
|
log.Warn("虚拟设备信息不存在, 将自动生成随机设备.")
|
||||||
@ -196,28 +237,48 @@ func main() {
|
|||||||
if encrypted := EncryptPwd(conf.Password, key[:]); encrypted != "" {
|
if encrypted := EncryptPwd(conf.Password, key[:]); encrypted != "" {
|
||||||
conf.Password = ""
|
conf.Password = ""
|
||||||
conf.PasswordEncrypted = encrypted
|
conf.PasswordEncrypted = encrypted
|
||||||
_ = conf.Save("config.json")
|
_ = conf.Save("config.hjson")
|
||||||
} else {
|
} else {
|
||||||
log.Warnf("加密时出现问题.")
|
log.Warnf("加密时出现问题.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if conf.PasswordEncrypted != "" {
|
if conf.PasswordEncrypted != "" {
|
||||||
log.Infof("密码加密已启用, 请输入Key对密码进行解密以继续: (Enter 提交)")
|
if strKey == "" {
|
||||||
strKey, _ := console.ReadString('\n')
|
log.Infof("密码加密已启用, 请输入Key对密码进行解密以继续: (Enter 提交)")
|
||||||
|
cancel := make(chan struct{}, 1)
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-cancel:
|
||||||
|
return
|
||||||
|
case <-time.After(time.Second * 45):
|
||||||
|
log.Infof("解密key输入超时")
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
strKey, _ = console.ReadString('\n')
|
||||||
|
cancel <- struct{}{}
|
||||||
|
} else {
|
||||||
|
log.Infof("密码加密已启用, 使用运行时传递的参数进行解密,按 Ctrl+C 取消.")
|
||||||
|
}
|
||||||
key := md5.Sum([]byte(strKey))
|
key := md5.Sum([]byte(strKey))
|
||||||
conf.Password = DecryptPwd(conf.PasswordEncrypted, key[:])
|
conf.Password = DecryptPwd(conf.PasswordEncrypted, key[:])
|
||||||
}
|
}
|
||||||
log.Info("Bot将在5秒后登录并开始信息处理, 按 Ctrl+C 取消.")
|
if !isFastStart {
|
||||||
time.Sleep(time.Second * 5)
|
log.Info("Bot将在5秒后登录并开始信息处理, 按 Ctrl+C 取消.")
|
||||||
|
time.Sleep(time.Second * 5)
|
||||||
|
}
|
||||||
log.Info("开始尝试登录并同步消息...")
|
log.Info("开始尝试登录并同步消息...")
|
||||||
log.Infof("使用协议: %v", func() string {
|
log.Infof("使用协议: %v", func() string {
|
||||||
switch client.SystemDeviceInfo.Protocol {
|
switch client.SystemDeviceInfo.Protocol {
|
||||||
case client.AndroidPad:
|
case client.IPad:
|
||||||
return "Android Pad"
|
return "iPad"
|
||||||
case client.AndroidPhone:
|
case client.AndroidPhone:
|
||||||
return "Android Phone"
|
return "Android Phone"
|
||||||
case client.AndroidWatch:
|
case client.AndroidWatch:
|
||||||
return "Android Watch"
|
return "Android Watch"
|
||||||
|
case client.MacOS:
|
||||||
|
return "MacOS"
|
||||||
}
|
}
|
||||||
return "未知"
|
return "未知"
|
||||||
}())
|
}())
|
||||||
@ -232,8 +293,21 @@ func main() {
|
|||||||
log.Debug("Protocol -> " + e.Message)
|
log.Debug("Protocol -> " + e.Message)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) {
|
if global.PathExists("address.txt") {
|
||||||
|
log.Infof("检测到 address.txt 文件. 将覆盖目标IP.")
|
||||||
|
addr := global.ReadAddrFile("address.txt")
|
||||||
|
if len(addr) > 0 {
|
||||||
|
cli.SetCustomServer(addr)
|
||||||
|
}
|
||||||
|
log.Infof("读取到 %v 个自定义地址.", len(addr))
|
||||||
|
}
|
||||||
|
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) bool {
|
||||||
|
if !conf.UseSSOAddress {
|
||||||
|
log.Infof("收到服务器地址更新通知, 根据配置文件已忽略.")
|
||||||
|
return false
|
||||||
|
}
|
||||||
log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. ")
|
log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. ")
|
||||||
|
return true
|
||||||
})
|
})
|
||||||
if conf.WebUi == nil {
|
if conf.WebUi == nil {
|
||||||
conf.WebUi = &global.GoCqWebUi{
|
conf.WebUi = &global.GoCqWebUi{
|
||||||
@ -249,16 +323,20 @@ func main() {
|
|||||||
if conf.WebUi.Host == "" {
|
if conf.WebUi.Host == "" {
|
||||||
conf.WebUi.Host = "127.0.0.1"
|
conf.WebUi.Host = "127.0.0.1"
|
||||||
}
|
}
|
||||||
confErr := conf.Save("config.json")
|
global.Proxy = conf.ProxyRewrite
|
||||||
if confErr != nil {
|
|
||||||
log.Error("保存配置文件失败")
|
|
||||||
}
|
|
||||||
b := server.WebServer.Run(fmt.Sprintf("%s:%d", conf.WebUi.Host, conf.WebUi.WebUiPort), cli)
|
b := server.WebServer.Run(fmt.Sprintf("%s:%d", conf.WebUi.Host, conf.WebUi.WebUiPort), cli)
|
||||||
c := server.Console
|
c := server.Console
|
||||||
|
r := server.Restart
|
||||||
go checkUpdate()
|
go checkUpdate()
|
||||||
signal.Notify(c, os.Interrupt, os.Kill)
|
signal.Notify(c, os.Interrupt, os.Kill)
|
||||||
<-c
|
select {
|
||||||
b.Release()
|
case <-c:
|
||||||
|
b.Release()
|
||||||
|
case <-r:
|
||||||
|
log.Info("正在重启中...")
|
||||||
|
defer b.Release()
|
||||||
|
restart(arg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func EncryptPwd(pwd string, key []byte) string {
|
func EncryptPwd(pwd string, key []byte) string {
|
||||||
@ -309,3 +387,102 @@ func checkUpdate() {
|
|||||||
}
|
}
|
||||||
log.Infof("检查更新完成. 当前已运行最新版本.")
|
log.Infof("检查更新完成. 当前已运行最新版本.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func selfUpdate(imageUrl string) {
|
||||||
|
console := bufio.NewReader(os.Stdin)
|
||||||
|
readLine := func() (str string) {
|
||||||
|
str, _ = console.ReadString('\n')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Infof("正在检查更新.")
|
||||||
|
var res string
|
||||||
|
if err := gout.GET("https://api.github.com/repos/Mrs4s/go-cqhttp/releases").BindBody(&res).Do(); err != nil {
|
||||||
|
log.Warnf("检查更新失败: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
detail := gjson.Parse(res)
|
||||||
|
if len(detail.Array()) < 1 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
info := detail.Array()[0]
|
||||||
|
version := info.Get("tag_name").Str
|
||||||
|
if coolq.Version != version {
|
||||||
|
log.Info("当前最新版本为 ", version)
|
||||||
|
log.Warn("是否更新(y/N): ")
|
||||||
|
r := strings.TrimSpace(readLine())
|
||||||
|
|
||||||
|
doUpdate := func() {
|
||||||
|
log.Info("正在更新,请稍等...")
|
||||||
|
url := fmt.Sprintf(
|
||||||
|
"%v/Mrs4s/go-cqhttp/releases/download/%v/go-cqhttp-%v-%v-%v",
|
||||||
|
func() string {
|
||||||
|
if imageUrl != "" {
|
||||||
|
return imageUrl
|
||||||
|
}
|
||||||
|
return "https://github.com"
|
||||||
|
}(),
|
||||||
|
version,
|
||||||
|
version,
|
||||||
|
runtime.GOOS,
|
||||||
|
runtime.GOARCH,
|
||||||
|
)
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
url = url + ".exe"
|
||||||
|
}
|
||||||
|
resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
log.Error("更新失败!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
wc := global.WriteCounter{}
|
||||||
|
err, _ = update.New().FromStream(io.TeeReader(resp.Body, &wc))
|
||||||
|
fmt.Println()
|
||||||
|
if err != nil {
|
||||||
|
log.Error("更新失败!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Info("更新完成!")
|
||||||
|
}
|
||||||
|
|
||||||
|
if r == "y" || r == "Y" {
|
||||||
|
doUpdate()
|
||||||
|
} else {
|
||||||
|
log.Warn("已取消更新!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Info("按 Enter 继续....")
|
||||||
|
readLine()
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func restart(Args []string) {
|
||||||
|
cmd := &exec.Cmd{}
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
file, err := exec.LookPath(Args[0])
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("重启失败:%s", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
path, err := filepath.Abs(file)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("重启失败:%s", err.Error())
|
||||||
|
}
|
||||||
|
Args = append([]string{"/c", "start ", path, "faststart"}, Args[1:]...)
|
||||||
|
cmd = &exec.Cmd{
|
||||||
|
Path: "cmd.exe",
|
||||||
|
Args: Args,
|
||||||
|
Stderr: os.Stderr,
|
||||||
|
Stdout: os.Stdout,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Args = append(Args, "faststart")
|
||||||
|
cmd = &exec.Cmd{
|
||||||
|
Path: Args[0],
|
||||||
|
Args: Args,
|
||||||
|
Stderr: os.Stderr,
|
||||||
|
Stdout: os.Stdout,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cmd.Start()
|
||||||
|
}
|
||||||
|
@ -4,15 +4,8 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Mrs4s/MiraiGo/client"
|
"github.com/gin-contrib/pprof"
|
||||||
"github.com/Mrs4s/go-cqhttp/coolq"
|
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
"github.com/yinghau76/go-ascii-art"
|
|
||||||
"image"
|
"image"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -21,12 +14,25 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Mrs4s/MiraiGo/client"
|
||||||
|
"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 WebInput = make(chan string, 1) //长度1,用于阻塞
|
||||||
|
|
||||||
var Console = make(chan os.Signal, 1)
|
var Console = make(chan os.Signal, 1)
|
||||||
|
|
||||||
|
var Restart = make(chan struct{}, 1)
|
||||||
|
|
||||||
var JsonConfig *global.JsonConfig
|
var JsonConfig *global.JsonConfig
|
||||||
|
|
||||||
type webServer struct {
|
type webServer struct {
|
||||||
@ -41,16 +47,17 @@ var WebServer = &webServer{}
|
|||||||
|
|
||||||
// admin 子站的 路由映射
|
// admin 子站的 路由映射
|
||||||
var HttpuriAdmin = map[string]func(s *webServer, c *gin.Context){
|
var HttpuriAdmin = map[string]func(s *webServer, c *gin.Context){
|
||||||
"do_restart": AdminDoRestart, //热重启
|
"do_restart": AdminDoRestart, //热重启
|
||||||
"get_web_write": AdminWebWrite, //获取是否验证码输入
|
"do_process_restart": AdminProcessRestart, //进程重启
|
||||||
"do_web_write": AdminDoWebWrite, //web上进行输入操作
|
"get_web_write": AdminWebWrite, //获取是否验证码输入
|
||||||
"do_restart_docker": AdminDoRestartDocker, //直接停止(依赖supervisord/docker)重新拉起
|
"do_web_write": AdminDoWebWrite, //web上进行输入操作
|
||||||
"do_config_base": AdminDoConfigBase, //修改config.json中的基础部分
|
"do_restart_docker": AdminDoRestartDocker, //直接停止(依赖supervisord/docker)重新拉起
|
||||||
"do_config_http": AdminDoConfigHttp, //修改config.json的http部分
|
"do_config_base": AdminDoConfigBase, //修改config.json中的基础部分
|
||||||
"do_config_ws": AdminDoConfigWs, //修改config.json的正向ws部分
|
"do_config_http": AdminDoConfigHttp, //修改config.json的http部分
|
||||||
"do_config_reverse": AdminDoConfigReverse, //修改config.json 中的反向ws部分
|
"do_config_ws": AdminDoConfigWs, //修改config.json的正向ws部分
|
||||||
"do_config_json": AdminDoConfigJson, //直接修改 config.json配置
|
"do_config_reverse": AdminDoConfigReverse, //修改config.json 中的反向ws部分
|
||||||
"get_config_json": AdminGetConfigJson, //拉取 当前的config.json配置
|
"do_config_json": AdminDoConfigJson, //直接修改 config.json配置
|
||||||
|
"get_config_json": AdminGetConfigJson, //拉取 当前的config.json配置
|
||||||
}
|
}
|
||||||
|
|
||||||
func Failed(code int, msg string) coolq.MSG {
|
func Failed(code int, msg string) coolq.MSG {
|
||||||
@ -71,7 +78,12 @@ func (s *webServer) Run(addr string, cli *client.QQClient) *coolq.CQBot {
|
|||||||
|
|
||||||
go func() {
|
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)
|
log.Infof("Admin API 服务器已启动: %v", addr)
|
||||||
err := s.engine.Run(addr)
|
err := s.engine.Run(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -106,6 +118,7 @@ func (s *webServer) Dologin() {
|
|||||||
cli := s.Cli
|
cli := s.Cli
|
||||||
cli.AllowSlider = true
|
cli.AllowSlider = true
|
||||||
rsp, err := cli.Login()
|
rsp, err := cli.Login()
|
||||||
|
count := 0
|
||||||
for {
|
for {
|
||||||
global.Check(err)
|
global.Check(err)
|
||||||
var text string
|
var text string
|
||||||
@ -126,7 +139,7 @@ func (s *webServer) Dologin() {
|
|||||||
_ = ioutil.WriteFile("captcha.jpg", rsp.CaptchaImage, 0644)
|
_ = ioutil.WriteFile("captcha.jpg", rsp.CaptchaImage, 0644)
|
||||||
img, _, _ := image.Decode(bytes.NewReader(rsp.CaptchaImage))
|
img, _, _ := image.Decode(bytes.NewReader(rsp.CaptchaImage))
|
||||||
fmt.Println(asciiart.New("image", img).Art)
|
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)
|
log.Warnf("请输入验证码 (captcha.jpg): (http://%s:%d/admin/do_web_write 输入)", conf.WebUi.Host, conf.WebUi.WebUiPort)
|
||||||
text = <-WebInput
|
text = <-WebInput
|
||||||
} else {
|
} else {
|
||||||
@ -172,7 +185,7 @@ func (s *webServer) Dologin() {
|
|||||||
return
|
return
|
||||||
case client.UnsafeDeviceError:
|
case client.UnsafeDeviceError:
|
||||||
log.Warnf("账号已开启设备锁,请前往 -> %v <- 验证并重启Bot.", rsp.VerifyUrl)
|
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)
|
log.Infof(" (http://%s:%d/admin/do_web_write 确认后继续)....", conf.WebUi.Host, conf.WebUi.WebUiPort)
|
||||||
text = <-WebInput
|
text = <-WebInput
|
||||||
} else {
|
} else {
|
||||||
@ -187,6 +200,14 @@ func (s *webServer) Dologin() {
|
|||||||
if strings.Contains(msg, "版本") {
|
if strings.Contains(msg, "版本") {
|
||||||
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.Warnf("登录失败: %v", msg)
|
||||||
log.Infof("按 Enter 继续....")
|
log.Infof("按 Enter 继续....")
|
||||||
readLine()
|
readLine()
|
||||||
@ -239,6 +260,7 @@ func (s *webServer) Dologin() {
|
|||||||
rsp, err := cli.Login()
|
rsp, err := cli.Login()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("重连失败: %v", err)
|
log.Errorf("重连失败: %v", err)
|
||||||
|
cli.Disconnect()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !rsp.Success {
|
if !rsp.Success {
|
||||||
@ -249,6 +271,7 @@ func (s *webServer) Dologin() {
|
|||||||
log.Fatalf("重连失败: 设备锁")
|
log.Fatalf("重连失败: 设备锁")
|
||||||
default:
|
default:
|
||||||
log.Errorf("重连失败: %v", rsp.ErrorMessage)
|
log.Errorf("重连失败: %v", rsp.ErrorMessage)
|
||||||
|
cli.Disconnect()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -277,7 +300,7 @@ func GetConf() *global.JsonConfig {
|
|||||||
if JsonConfig != nil {
|
if JsonConfig != nil {
|
||||||
return JsonConfig
|
return JsonConfig
|
||||||
}
|
}
|
||||||
conf := global.Load("config.json")
|
conf := global.Load("config.hjson")
|
||||||
return conf
|
return conf
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,6 +318,10 @@ func AuthMiddleWare() gin.HandlerFunc {
|
|||||||
if c.Request.Method == "OPTIONS" {
|
if c.Request.Method == "OPTIONS" {
|
||||||
c.AbortWithStatus(http.StatusNoContent)
|
c.AbortWithStatus(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
if strings.Contains(c.Request.URL.Path, "debug") {
|
||||||
|
c.Next()
|
||||||
|
return
|
||||||
|
}
|
||||||
// 处理请求
|
// 处理请求
|
||||||
if c.Request.Method != "GET" && c.Request.Method != "POST" {
|
if c.Request.Method != "GET" && c.Request.Method != "POST" {
|
||||||
log.Warnf("已拒绝客户端 %v 的请求: 方法错误", c.Request.RemoteAddr)
|
log.Warnf("已拒绝客户端 %v 的请求: 方法错误", c.Request.RemoteAddr)
|
||||||
@ -338,12 +365,14 @@ func (s *webServer) DoReLogin() { // TODO: 协议层的 ReLogin
|
|||||||
log.Info("开始尝试登录并同步消息...")
|
log.Info("开始尝试登录并同步消息...")
|
||||||
log.Infof("使用协议: %v", func() string {
|
log.Infof("使用协议: %v", func() string {
|
||||||
switch client.SystemDeviceInfo.Protocol {
|
switch client.SystemDeviceInfo.Protocol {
|
||||||
case client.AndroidPad:
|
case client.IPad:
|
||||||
return "Android Pad"
|
return "iPad"
|
||||||
case client.AndroidPhone:
|
case client.AndroidPhone:
|
||||||
return "Android Phone"
|
return "Android Phone"
|
||||||
case client.AndroidWatch:
|
case client.AndroidWatch:
|
||||||
return "Android Watch"
|
return "Android Watch"
|
||||||
|
case client.MacOS:
|
||||||
|
return "MacOS"
|
||||||
}
|
}
|
||||||
return "未知"
|
return "未知"
|
||||||
}())
|
}())
|
||||||
@ -357,8 +386,13 @@ func (s *webServer) DoReLogin() { // TODO: 协议层的 ReLogin
|
|||||||
log.Debug("Protocol -> " + e.Message)
|
log.Debug("Protocol -> " + e.Message)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) {
|
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) bool {
|
||||||
|
if !conf.UseSSOAddress {
|
||||||
|
log.Infof("收到服务器地址更新通知, 根据配置文件已忽略.")
|
||||||
|
return false
|
||||||
|
}
|
||||||
log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. ")
|
log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. ")
|
||||||
|
return true
|
||||||
})
|
})
|
||||||
s.Cli = cli
|
s.Cli = cli
|
||||||
s.Dologin()
|
s.Dologin()
|
||||||
@ -406,6 +440,7 @@ func (s *webServer) ReloadServer() {
|
|||||||
|
|
||||||
// 热重启
|
// 热重启
|
||||||
func AdminDoRestart(s *webServer, c *gin.Context) {
|
func AdminDoRestart(s *webServer, c *gin.Context) {
|
||||||
|
s.bot.Release()
|
||||||
s.bot = nil
|
s.bot = nil
|
||||||
s.Cli = nil
|
s.Cli = nil
|
||||||
s.DoReLogin()
|
s.DoReLogin()
|
||||||
@ -413,6 +448,12 @@ func AdminDoRestart(s *webServer, c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 进程重启
|
||||||
|
func AdminProcessRestart(s *webServer, c *gin.Context) {
|
||||||
|
Restart <- struct{}{}
|
||||||
|
c.JSON(200, coolq.OK(coolq.MSG{}))
|
||||||
|
}
|
||||||
|
|
||||||
// 冷重启
|
// 冷重启
|
||||||
func AdminDoRestartDocker(s *webServer, c *gin.Context) {
|
func AdminDoRestartDocker(s *webServer, c *gin.Context) {
|
||||||
Console <- os.Kill
|
Console <- os.Kill
|
||||||
@ -455,9 +496,9 @@ func AdminDoConfigBase(s *webServer, c *gin.Context) {
|
|||||||
conf.EnableDB = false
|
conf.EnableDB = false
|
||||||
}
|
}
|
||||||
conf.AccessToken = c.PostForm("access_token")
|
conf.AccessToken = c.PostForm("access_token")
|
||||||
if err := conf.Save("config.json"); err != nil {
|
if err := conf.Save("config.hjson"); err != nil {
|
||||||
log.Fatalf("保存 config.json 时出现错误: %v", err)
|
log.Fatalf("保存 config.hjson 时出现错误: %v", err)
|
||||||
c.JSON(200, Failed(502, "保存 config.json 时出现错误:"+fmt.Sprintf("%v", err)))
|
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||||
} else {
|
} else {
|
||||||
JsonConfig = nil
|
JsonConfig = nil
|
||||||
c.JSON(200, coolq.OK(coolq.MSG{}))
|
c.JSON(200, coolq.OK(coolq.MSG{}))
|
||||||
@ -480,9 +521,9 @@ func AdminDoConfigHttp(s *webServer, c *gin.Context) {
|
|||||||
if c.PostForm("post_url") != "" {
|
if c.PostForm("post_url") != "" {
|
||||||
conf.HttpConfig.PostUrls[c.PostForm("post_url")] = c.PostForm("post_secret")
|
conf.HttpConfig.PostUrls[c.PostForm("post_url")] = c.PostForm("post_secret")
|
||||||
}
|
}
|
||||||
if err := conf.Save("config.json"); err != nil {
|
if err := conf.Save("config.hjson"); err != nil {
|
||||||
log.Fatalf("保存 config.json 时出现错误: %v", err)
|
log.Fatalf("保存 config.hjson 时出现错误: %v", err)
|
||||||
c.JSON(200, Failed(502, "保存 config.json 时出现错误:"+fmt.Sprintf("%v", err)))
|
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||||
} else {
|
} else {
|
||||||
JsonConfig = nil
|
JsonConfig = nil
|
||||||
c.JSON(200, coolq.OK(coolq.MSG{}))
|
c.JSON(200, coolq.OK(coolq.MSG{}))
|
||||||
@ -500,9 +541,9 @@ func AdminDoConfigWs(s *webServer, c *gin.Context) {
|
|||||||
} else {
|
} else {
|
||||||
conf.WSConfig.Enabled = false
|
conf.WSConfig.Enabled = false
|
||||||
}
|
}
|
||||||
if err := conf.Save("config.json"); err != nil {
|
if err := conf.Save("config.hjson"); err != nil {
|
||||||
log.Fatalf("保存 config.json 时出现错误: %v", err)
|
log.Fatalf("保存 config.hjson 时出现错误: %v", err)
|
||||||
c.JSON(200, Failed(502, "保存 config.json 时出现错误:"+fmt.Sprintf("%v", err)))
|
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||||
} else {
|
} else {
|
||||||
JsonConfig = nil
|
JsonConfig = nil
|
||||||
c.JSON(200, coolq.OK(coolq.MSG{}))
|
c.JSON(200, coolq.OK(coolq.MSG{}))
|
||||||
@ -522,9 +563,9 @@ func AdminDoConfigReverse(s *webServer, c *gin.Context) {
|
|||||||
} else {
|
} else {
|
||||||
conf.ReverseServers[0].Enabled = false
|
conf.ReverseServers[0].Enabled = false
|
||||||
}
|
}
|
||||||
if err := conf.Save("config.json"); err != nil {
|
if err := conf.Save("config.hjson"); err != nil {
|
||||||
log.Fatalf("保存 config.json 时出现错误: %v", err)
|
log.Fatalf("保存 config.hjson 时出现错误: %v", err)
|
||||||
c.JSON(200, Failed(502, "保存 config.json 时出现错误:"+fmt.Sprintf("%v", err)))
|
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||||
} else {
|
} else {
|
||||||
JsonConfig = nil
|
JsonConfig = nil
|
||||||
c.JSON(200, coolq.OK(coolq.MSG{}))
|
c.JSON(200, coolq.OK(coolq.MSG{}))
|
||||||
@ -537,13 +578,13 @@ func AdminDoConfigJson(s *webServer, c *gin.Context) {
|
|||||||
Json := c.PostForm("json")
|
Json := c.PostForm("json")
|
||||||
err := json.Unmarshal([]byte(Json), &conf)
|
err := json.Unmarshal([]byte(Json), &conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("尝试加载配置文件 %v 时出现错误: %v", "config.json", err)
|
log.Warnf("尝试加载配置文件 %v 时出现错误: %v", "config.hjson", err)
|
||||||
c.JSON(200, Failed(502, "保存 config.json 时出现错误:"+fmt.Sprintf("%v", err)))
|
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := conf.Save("config.json"); err != nil {
|
if err := conf.Save("config.hjson"); err != nil {
|
||||||
log.Fatalf("保存 config.json 时出现错误: %v", err)
|
log.Fatalf("保存 config.hjson 时出现错误: %v", err)
|
||||||
c.JSON(200, Failed(502, "保存 config.json 时出现错误:"+fmt.Sprintf("%v", err)))
|
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||||
} else {
|
} else {
|
||||||
JsonConfig = nil
|
JsonConfig = nil
|
||||||
c.JSON(200, coolq.OK(coolq.MSG{}))
|
c.JSON(200, coolq.OK(coolq.MSG{}))
|
||||||
|
289
server/http.go
289
server/http.go
@ -5,13 +5,14 @@ import (
|
|||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"github.com/guonaihong/gout/dataflow"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/guonaihong/gout/dataflow"
|
||||||
|
|
||||||
"github.com/Mrs4s/go-cqhttp/coolq"
|
"github.com/Mrs4s/go-cqhttp/coolq"
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -34,6 +35,7 @@ type httpClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var HttpServer = &httpServer{}
|
var HttpServer = &httpServer{}
|
||||||
|
var Debug = false
|
||||||
|
|
||||||
func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
|
func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
@ -92,13 +94,6 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
|
|||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
//err := s.engine.Run(addr)
|
|
||||||
//if err != nil {
|
|
||||||
// log.Error(err)
|
|
||||||
// log.Infof("请检查端口是否被占用.")
|
|
||||||
// time.Sleep(time.Second * 5)
|
|
||||||
// os.Exit(1)
|
|
||||||
//}
|
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,78 +156,79 @@ func (s *httpServer) HandleActions(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetLoginInfo(c *gin.Context) {
|
func GetLoginInfo(s *httpServer, c *gin.Context) {
|
||||||
c.JSON(200, s.bot.CQGetLoginInfo())
|
c.JSON(200, s.bot.CQGetLoginInfo())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetFriendList(c *gin.Context) {
|
func GetFriendList(s *httpServer, c *gin.Context) {
|
||||||
c.JSON(200, s.bot.CQGetFriendList())
|
c.JSON(200, s.bot.CQGetFriendList())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetGroupList(c *gin.Context) {
|
func GetGroupList(s *httpServer, c *gin.Context) {
|
||||||
nc := getParamOrDefault(c, "no_cache", "false")
|
nc := getParamOrDefault(c, "no_cache", "false")
|
||||||
c.JSON(200, s.bot.CQGetGroupList(nc == "true"))
|
c.JSON(200, s.bot.CQGetGroupList(nc == "true"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetGroupInfo(c *gin.Context) {
|
func GetGroupInfo(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
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 (s *httpServer) GetGroupMemberList(c *gin.Context) {
|
func GetGroupMemberList(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
nc := getParamOrDefault(c, "no_cache", "false")
|
nc := getParamOrDefault(c, "no_cache", "false")
|
||||||
c.JSON(200, s.bot.CQGetGroupMemberList(gid, nc == "true"))
|
c.JSON(200, s.bot.CQGetGroupMemberList(gid, nc == "true"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetGroupMemberInfo(c *gin.Context) {
|
func GetGroupMemberInfo(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
||||||
c.JSON(200, s.bot.CQGetGroupMemberInfo(gid, uid))
|
c.JSON(200, s.bot.CQGetGroupMemberInfo(gid, uid))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetGroupFileSystemInfo(c *gin.Context) {
|
func GetGroupFileSystemInfo(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
c.JSON(200, s.bot.CQGetGroupFileSystemInfo(gid))
|
c.JSON(200, s.bot.CQGetGroupFileSystemInfo(gid))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetGroupRootFiles(c *gin.Context) {
|
func GetGroupRootFiles(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
c.JSON(200, s.bot.CQGetGroupRootFiles(gid))
|
c.JSON(200, s.bot.CQGetGroupRootFiles(gid))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetGroupFilesByFolderId(c *gin.Context) {
|
func GetGroupFilesByFolderId(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
folderId := getParam(c, "folder_id")
|
folderId := getParam(c, "folder_id")
|
||||||
c.JSON(200, s.bot.CQGetGroupFilesByFolderId(gid, folderId))
|
c.JSON(200, s.bot.CQGetGroupFilesByFolderId(gid, folderId))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetGroupFileUrl(c *gin.Context) {
|
func GetGroupFileUrl(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
fid := getParam(c, "file_id")
|
fid := getParam(c, "file_id")
|
||||||
busid, _ := strconv.ParseInt(getParam(c, "busid"), 10, 32)
|
busid, _ := strconv.ParseInt(getParam(c, "busid"), 10, 32)
|
||||||
c.JSON(200, s.bot.CQGetGroupFileUrl(gid, fid, int32(busid)))
|
c.JSON(200, s.bot.CQGetGroupFileUrl(gid, fid, int32(busid)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SendMessage(c *gin.Context) {
|
func SendMessage(s *httpServer, c *gin.Context) {
|
||||||
if getParam(c, "message_type") == "private" {
|
if getParam(c, "message_type") == "private" {
|
||||||
s.SendPrivateMessage(c)
|
SendPrivateMessage(s, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if getParam(c, "message_type") == "group" {
|
if getParam(c, "message_type") == "group" {
|
||||||
s.SendGroupMessage(c)
|
SendGroupMessage(s, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if getParam(c, "group_id") != "" {
|
if getParam(c, "group_id") != "" {
|
||||||
s.SendGroupMessage(c)
|
SendGroupMessage(s, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if getParam(c, "user_id") != "" {
|
if getParam(c, "user_id") != "" {
|
||||||
s.SendPrivateMessage(c)
|
SendPrivateMessage(s, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SendPrivateMessage(c *gin.Context) {
|
func SendPrivateMessage(s *httpServer, c *gin.Context) {
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
||||||
msg, t := getParamWithType(c, "message")
|
msg, t := getParamWithType(c, "message")
|
||||||
autoEscape := global.EnsureBool(getParam(c, "auto_escape"), false)
|
autoEscape := global.EnsureBool(getParam(c, "auto_escape"), false)
|
||||||
@ -243,7 +239,7 @@ func (s *httpServer) SendPrivateMessage(c *gin.Context) {
|
|||||||
c.JSON(200, s.bot.CQSendPrivateMessage(uid, msg, autoEscape))
|
c.JSON(200, s.bot.CQSendPrivateMessage(uid, msg, autoEscape))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SendGroupMessage(c *gin.Context) {
|
func SendGroupMessage(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
msg, t := getParamWithType(c, "message")
|
msg, t := getParamWithType(c, "message")
|
||||||
autoEscape := global.EnsureBool(getParam(c, "auto_escape"), false)
|
autoEscape := global.EnsureBool(getParam(c, "auto_escape"), false)
|
||||||
@ -254,34 +250,34 @@ func (s *httpServer) SendGroupMessage(c *gin.Context) {
|
|||||||
c.JSON(200, s.bot.CQSendGroupMessage(gid, msg, autoEscape))
|
c.JSON(200, s.bot.CQSendGroupMessage(gid, msg, autoEscape))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SendGroupForwardMessage(c *gin.Context) {
|
func SendGroupForwardMessage(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
msg := getParam(c, "messages")
|
msg := getParam(c, "messages")
|
||||||
c.JSON(200, s.bot.CQSendGroupForwardMessage(gid, gjson.Parse(msg)))
|
c.JSON(200, s.bot.CQSendGroupForwardMessage(gid, gjson.Parse(msg)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetImage(c *gin.Context) {
|
func GetImage(s *httpServer, c *gin.Context) {
|
||||||
file := getParam(c, "file")
|
file := getParam(c, "file")
|
||||||
c.JSON(200, s.bot.CQGetImage(file))
|
c.JSON(200, s.bot.CQGetImage(file))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetMessage(c *gin.Context) {
|
func GetMessage(s *httpServer, c *gin.Context) {
|
||||||
mid, _ := strconv.ParseInt(getParam(c, "message_id"), 10, 32)
|
mid, _ := strconv.ParseInt(getParam(c, "message_id"), 10, 32)
|
||||||
c.JSON(200, s.bot.CQGetMessage(int32(mid)))
|
c.JSON(200, s.bot.CQGetMessage(int32(mid)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetGroupHonorInfo(c *gin.Context) {
|
func GetGroupHonorInfo(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
c.JSON(200, s.bot.CQGetGroupHonorInfo(gid, getParam(c, "type")))
|
c.JSON(200, s.bot.CQGetGroupHonorInfo(gid, getParam(c, "type")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) ProcessFriendRequest(c *gin.Context) {
|
func ProcessFriendRequest(s *httpServer, c *gin.Context) {
|
||||||
flag := getParam(c, "flag")
|
flag := getParam(c, "flag")
|
||||||
approve := getParamOrDefault(c, "approve", "true")
|
approve := getParamOrDefault(c, "approve", "true")
|
||||||
c.JSON(200, s.bot.CQProcessFriendRequest(flag, approve == "true"))
|
c.JSON(200, s.bot.CQProcessFriendRequest(flag, approve == "true"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) ProcessGroupRequest(c *gin.Context) {
|
func ProcessGroupRequest(s *httpServer, c *gin.Context) {
|
||||||
flag := getParam(c, "flag")
|
flag := getParam(c, "flag")
|
||||||
subType := getParam(c, "sub_type")
|
subType := getParam(c, "sub_type")
|
||||||
if subType == "" {
|
if subType == "" {
|
||||||
@ -291,103 +287,114 @@ func (s *httpServer) ProcessGroupRequest(c *gin.Context) {
|
|||||||
c.JSON(200, s.bot.CQProcessGroupRequest(flag, subType, getParam(c, "reason"), approve == "true"))
|
c.JSON(200, s.bot.CQProcessGroupRequest(flag, subType, getParam(c, "reason"), approve == "true"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SetGroupCard(c *gin.Context) {
|
func SetGroupCard(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
||||||
c.JSON(200, s.bot.CQSetGroupCard(gid, uid, getParam(c, "card")))
|
c.JSON(200, s.bot.CQSetGroupCard(gid, uid, getParam(c, "card")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SetSpecialTitle(c *gin.Context) {
|
func SetSpecialTitle(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
||||||
c.JSON(200, s.bot.CQSetGroupSpecialTitle(gid, uid, getParam(c, "special_title")))
|
c.JSON(200, s.bot.CQSetGroupSpecialTitle(gid, uid, getParam(c, "special_title")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SetGroupKick(c *gin.Context) {
|
func SetGroupKick(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
||||||
msg := getParam(c, "message")
|
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 (s *httpServer) SetGroupBan(c *gin.Context) {
|
func SetGroupBan(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
||||||
i, _ := strconv.ParseInt(getParamOrDefault(c, "duration", "1800"), 10, 64)
|
i, _ := strconv.ParseInt(getParamOrDefault(c, "duration", "1800"), 10, 64)
|
||||||
c.JSON(200, s.bot.CQSetGroupBan(gid, uid, uint32(i)))
|
c.JSON(200, s.bot.CQSetGroupBan(gid, uid, uint32(i)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SetWholeBan(c *gin.Context) {
|
func SetWholeBan(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
c.JSON(200, s.bot.CQSetGroupWholeBan(gid, getParamOrDefault(c, "enable", "true") == "true"))
|
c.JSON(200, s.bot.CQSetGroupWholeBan(gid, getParamOrDefault(c, "enable", "true") == "true"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SetGroupName(c *gin.Context) {
|
func SetGroupName(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
c.JSON(200, s.bot.CQSetGroupName(gid, getParam(c, "group_name")))
|
c.JSON(200, s.bot.CQSetGroupName(gid, getParam(c, "group_name")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SetGroupAdmin(c *gin.Context) {
|
func SetGroupAdmin(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
||||||
c.JSON(200, s.bot.CQSetGroupAdmin(gid, uid, getParamOrDefault(c, "enable", "true") == "true"))
|
c.JSON(200, s.bot.CQSetGroupAdmin(gid, uid, getParamOrDefault(c, "enable", "true") == "true"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SendGroupNotice(c *gin.Context) {
|
func SendGroupNotice(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
c.JSON(200, s.bot.CQSetGroupMemo(gid, getParam(c, "content")))
|
c.JSON(200, s.bot.CQSetGroupMemo(gid, getParam(c, "content")))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SetGroupLeave(c *gin.Context) {
|
func SetGroupLeave(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
c.JSON(200, s.bot.CQSetGroupLeave(gid))
|
c.JSON(200, s.bot.CQSetGroupLeave(gid))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetForwardMessage(c *gin.Context) {
|
func SetRestart(s *httpServer, c *gin.Context) {
|
||||||
|
delay, _ := strconv.ParseInt(getParam(c, "delay"), 10, 64)
|
||||||
|
c.JSON(200, coolq.MSG{"data": nil, "retcode": 0, "status": "async"})
|
||||||
|
go func(delay int64) {
|
||||||
|
time.Sleep(time.Duration(delay) * time.Millisecond)
|
||||||
|
Restart <- struct{}{}
|
||||||
|
}(delay)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetForwardMessage(s *httpServer, c *gin.Context) {
|
||||||
resId := getParam(c, "message_id")
|
resId := getParam(c, "message_id")
|
||||||
c.JSON(200, s.bot.CQGetForwardMessage(resId))
|
c.JSON(200, s.bot.CQGetForwardMessage(resId))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetGroupSystemMessage(c *gin.Context) {
|
func GetGroupSystemMessage(s *httpServer, c *gin.Context) {
|
||||||
c.JSON(200, s.bot.CQGetGroupSystemMessages())
|
c.JSON(200, s.bot.CQGetGroupSystemMessages())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) DeleteMessage(c *gin.Context) {
|
func DeleteMessage(s *httpServer, c *gin.Context) {
|
||||||
mid, _ := strconv.ParseInt(getParam(c, "message_id"), 10, 32)
|
mid, _ := strconv.ParseInt(getParam(c, "message_id"), 10, 32)
|
||||||
c.JSON(200, s.bot.CQDeleteMessage(int32(mid)))
|
c.JSON(200, s.bot.CQDeleteMessage(int32(mid)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) CanSendImage(c *gin.Context) {
|
func CanSendImage(s *httpServer, c *gin.Context) {
|
||||||
c.JSON(200, s.bot.CQCanSendImage())
|
c.JSON(200, s.bot.CQCanSendImage())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) CanSendRecord(c *gin.Context) {
|
func CanSendRecord(s *httpServer, c *gin.Context) {
|
||||||
c.JSON(200, s.bot.CQCanSendRecord())
|
c.JSON(200, s.bot.CQCanSendRecord())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetStatus(c *gin.Context) {
|
func GetStatus(s *httpServer, c *gin.Context) {
|
||||||
c.JSON(200, s.bot.CQGetStatus())
|
c.JSON(200, s.bot.CQGetStatus())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetVersionInfo(c *gin.Context) {
|
func GetVersionInfo(s *httpServer, c *gin.Context) {
|
||||||
c.JSON(200, s.bot.CQGetVersionInfo())
|
c.JSON(200, s.bot.CQGetVersionInfo())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) ReloadEventFilter(c *gin.Context) {
|
func ReloadEventFilter(s *httpServer, c *gin.Context) {
|
||||||
c.JSON(200, s.bot.CQReloadEventFilter())
|
c.JSON(200, s.bot.CQReloadEventFilter())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetVipInfo(c *gin.Context) {
|
func GetVipInfo(s *httpServer, c *gin.Context) {
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
||||||
c.JSON(200, s.bot.CQGetVipInfo(uid))
|
c.JSON(200, s.bot.CQGetVipInfo(uid))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetStrangerInfo(c *gin.Context) {
|
func GetStrangerInfo(s *httpServer, c *gin.Context) {
|
||||||
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
|
||||||
c.JSON(200, s.bot.CQGetStrangerInfo(uid))
|
c.JSON(200, s.bot.CQGetStrangerInfo(uid))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) HandleQuickOperation(c *gin.Context) {
|
func HandleQuickOperation(s *httpServer, c *gin.Context) {
|
||||||
if c.Request.Method != "POST" {
|
if c.Request.Method != "POST" {
|
||||||
c.AbortWithStatus(404)
|
c.AbortWithStatus(404)
|
||||||
return
|
return
|
||||||
@ -398,17 +405,17 @@ func (s *httpServer) HandleQuickOperation(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) OcrImage(c *gin.Context) {
|
func OcrImage(s *httpServer, c *gin.Context) {
|
||||||
img := getParam(c, "image")
|
img := getParam(c, "image")
|
||||||
c.JSON(200, s.bot.CQOcrImage(img))
|
c.JSON(200, s.bot.CQOcrImage(img))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) GetWordSlices(c *gin.Context) {
|
func GetWordSlices(s *httpServer, c *gin.Context) {
|
||||||
content := getParam(c, "content")
|
content := getParam(c, "content")
|
||||||
c.JSON(200, s.bot.CQGetWordSlices(content))
|
c.JSON(200, s.bot.CQGetWordSlices(content))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) SetGroupPortrait(c *gin.Context) {
|
func SetGroupPortrait(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
file := getParam(c, "file")
|
file := getParam(c, "file")
|
||||||
cache := getParam(c, "cache")
|
cache := getParam(c, "cache")
|
||||||
@ -464,132 +471,50 @@ func getParamWithType(c *gin.Context, k string) (string, gjson.Type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var httpApi = map[string]func(s *httpServer, c *gin.Context){
|
var httpApi = map[string]func(s *httpServer, c *gin.Context){
|
||||||
"get_login_info": func(s *httpServer, c *gin.Context) {
|
"get_login_info": GetLoginInfo,
|
||||||
s.GetLoginInfo(c)
|
"get_friend_list": GetFriendList,
|
||||||
},
|
"get_group_list": GetGroupList,
|
||||||
"get_friend_list": func(s *httpServer, c *gin.Context) {
|
"get_group_info": GetGroupInfo,
|
||||||
s.GetFriendList(c)
|
"get_group_member_list": GetGroupMemberList,
|
||||||
},
|
"get_group_member_info": GetGroupMemberInfo,
|
||||||
"get_group_list": func(s *httpServer, c *gin.Context) {
|
"get_group_file_system_info": GetGroupFileSystemInfo,
|
||||||
s.GetGroupList(c)
|
"get_group_root_files": GetGroupRootFiles,
|
||||||
},
|
"get_group_files_by_folder": GetGroupFilesByFolderId,
|
||||||
"get_group_info": func(s *httpServer, c *gin.Context) {
|
"get_group_file_url": GetGroupFileUrl,
|
||||||
s.GetGroupInfo(c)
|
"send_msg": SendMessage,
|
||||||
},
|
"send_group_msg": SendGroupMessage,
|
||||||
"get_group_member_list": func(s *httpServer, c *gin.Context) {
|
"send_group_forward_msg": SendGroupForwardMessage,
|
||||||
s.GetGroupMemberList(c)
|
"send_private_msg": SendPrivateMessage,
|
||||||
},
|
"delete_msg": DeleteMessage,
|
||||||
"get_group_member_info": func(s *httpServer, c *gin.Context) {
|
"set_friend_add_request": ProcessFriendRequest,
|
||||||
s.GetGroupMemberInfo(c)
|
"set_group_add_request": ProcessGroupRequest,
|
||||||
},
|
"set_group_card": SetGroupCard,
|
||||||
"get_group_file_system_info": func(s *httpServer, c *gin.Context) {
|
"set_group_special_title": SetSpecialTitle,
|
||||||
s.GetGroupFileSystemInfo(c)
|
"set_group_kick": SetGroupKick,
|
||||||
},
|
"set_group_ban": SetGroupBan,
|
||||||
"get_group_root_files": func(s *httpServer, c *gin.Context) {
|
"set_group_whole_ban": SetWholeBan,
|
||||||
s.GetGroupRootFiles(c)
|
"set_group_name": SetGroupName,
|
||||||
},
|
"set_group_admin": SetGroupAdmin,
|
||||||
"get_group_files_by_folder": func(s *httpServer, c *gin.Context) {
|
"set_restart": SetRestart,
|
||||||
s.GetGroupFilesByFolderId(c)
|
"_send_group_notice": SendGroupNotice,
|
||||||
},
|
"set_group_leave": SetGroupLeave,
|
||||||
"get_group_file_url": func(s *httpServer, c *gin.Context) {
|
"get_image": GetImage,
|
||||||
s.GetGroupFileUrl(c)
|
"get_forward_msg": GetForwardMessage,
|
||||||
},
|
"get_msg": GetMessage,
|
||||||
"send_msg": func(s *httpServer, c *gin.Context) {
|
"get_group_system_msg": GetGroupSystemMessage,
|
||||||
s.SendMessage(c)
|
"get_group_honor_info": GetGroupHonorInfo,
|
||||||
},
|
"can_send_image": CanSendImage,
|
||||||
"send_group_msg": func(s *httpServer, c *gin.Context) {
|
"can_send_record": CanSendRecord,
|
||||||
s.SendGroupMessage(c)
|
"get_status": GetStatus,
|
||||||
},
|
"get_version_info": GetVersionInfo,
|
||||||
"send_group_forward_msg": func(s *httpServer, c *gin.Context) {
|
"_get_vip_info": GetVipInfo,
|
||||||
s.SendGroupForwardMessage(c)
|
"get_stranger_info": GetStrangerInfo,
|
||||||
},
|
"reload_event_filter": ReloadEventFilter,
|
||||||
"send_private_msg": func(s *httpServer, c *gin.Context) {
|
"set_group_portrait": SetGroupPortrait,
|
||||||
s.SendPrivateMessage(c)
|
".handle_quick_operation": HandleQuickOperation,
|
||||||
},
|
".ocr_image": OcrImage,
|
||||||
"delete_msg": func(s *httpServer, c *gin.Context) {
|
"ocr_image": OcrImage,
|
||||||
s.DeleteMessage(c)
|
".get_word_slices": GetWordSlices,
|
||||||
},
|
|
||||||
"set_friend_add_request": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.ProcessFriendRequest(c)
|
|
||||||
},
|
|
||||||
"set_group_add_request": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.ProcessGroupRequest(c)
|
|
||||||
},
|
|
||||||
"set_group_card": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.SetGroupCard(c)
|
|
||||||
},
|
|
||||||
"set_group_special_title": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.SetSpecialTitle(c)
|
|
||||||
},
|
|
||||||
"set_group_kick": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.SetGroupKick(c)
|
|
||||||
},
|
|
||||||
"set_group_ban": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.SetGroupBan(c)
|
|
||||||
},
|
|
||||||
"set_group_whole_ban": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.SetWholeBan(c)
|
|
||||||
},
|
|
||||||
"set_group_name": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.SetGroupName(c)
|
|
||||||
},
|
|
||||||
"set_group_admin": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.SetGroupAdmin(c)
|
|
||||||
},
|
|
||||||
"_send_group_notice": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.SendGroupNotice(c)
|
|
||||||
},
|
|
||||||
"set_group_leave": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.SetGroupLeave(c)
|
|
||||||
},
|
|
||||||
"get_image": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.GetImage(c)
|
|
||||||
},
|
|
||||||
"get_forward_msg": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.GetForwardMessage(c)
|
|
||||||
},
|
|
||||||
"get_msg": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.GetMessage(c)
|
|
||||||
},
|
|
||||||
"get_group_system_msg": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.GetGroupSystemMessage(c)
|
|
||||||
},
|
|
||||||
"get_group_honor_info": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.GetGroupHonorInfo(c)
|
|
||||||
},
|
|
||||||
"can_send_image": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.CanSendImage(c)
|
|
||||||
},
|
|
||||||
"can_send_record": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.CanSendRecord(c)
|
|
||||||
},
|
|
||||||
"get_status": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.GetStatus(c)
|
|
||||||
},
|
|
||||||
"get_version_info": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.GetVersionInfo(c)
|
|
||||||
},
|
|
||||||
"_get_vip_info": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.GetVipInfo(c)
|
|
||||||
},
|
|
||||||
"get_stranger_info": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.GetStrangerInfo(c)
|
|
||||||
},
|
|
||||||
"reload_event_filter": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.ReloadEventFilter(c)
|
|
||||||
},
|
|
||||||
"set_group_portrait": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.SetGroupPortrait(c)
|
|
||||||
},
|
|
||||||
".handle_quick_operation": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.HandleQuickOperation(c)
|
|
||||||
},
|
|
||||||
".ocr_image": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.OcrImage(c)
|
|
||||||
},
|
|
||||||
".get_word_slices": func(s *httpServer, c *gin.Context) {
|
|
||||||
s.GetWordSlices(c)
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *httpServer) ShutDown() {
|
func (s *httpServer) ShutDown() {
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"runtime/debug"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -316,7 +317,7 @@ func (s *websocketServer) listenApi(c *websocketConn) {
|
|||||||
func (c *websocketConn) handleRequest(bot *coolq.CQBot, payload []byte) {
|
func (c *websocketConn) handleRequest(bot *coolq.CQBot, payload []byte) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
log.Printf("处置WS命令时发生无法恢复的异常:%v", err)
|
log.Printf("处置WS命令时发生无法恢复的异常:%v\n%s", err, debug.Stack())
|
||||||
c.Close()
|
c.Close()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@ -370,7 +371,7 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
|||||||
return bot.CQGetGroupList(p.Get("no_cache").Bool())
|
return bot.CQGetGroupList(p.Get("no_cache").Bool())
|
||||||
},
|
},
|
||||||
"get_group_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"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 {
|
"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())
|
return bot.CQGetGroupMemberList(p.Get("group_id").Int(), p.Get("no_cache").Bool())
|
||||||
@ -433,7 +434,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)
|
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 {
|
"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 {
|
"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 {
|
return bot.CQSetGroupBan(p.Get("group_id").Int(), p.Get("user_id").Int(), func() uint32 {
|
||||||
@ -480,6 +481,19 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
|||||||
"get_group_honor_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"get_group_honor_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetGroupHonorInfo(p.Get("group_id").Int(), p.Get("type").Str)
|
return bot.CQGetGroupHonorInfo(p.Get("group_id").Int(), p.Get("type").Str)
|
||||||
},
|
},
|
||||||
|
"set_restart": func(c *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
|
var delay int64 = 0
|
||||||
|
delay = p.Get("delay").Int()
|
||||||
|
if delay < 0 {
|
||||||
|
delay = 0
|
||||||
|
}
|
||||||
|
defer func(delay int64) {
|
||||||
|
time.Sleep(time.Duration(delay) * time.Millisecond)
|
||||||
|
Restart <- struct{}{}
|
||||||
|
}(delay)
|
||||||
|
return coolq.MSG{"data": nil, "retcode": 0, "status": "async"}
|
||||||
|
|
||||||
|
},
|
||||||
"can_send_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"can_send_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQCanSendImage()
|
return bot.CQCanSendImage()
|
||||||
},
|
},
|
||||||
@ -519,6 +533,9 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
|||||||
".ocr_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
".ocr_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQOcrImage(p.Get("image").Str)
|
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_word_slices": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
".get_word_slices": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetWordSlices(p.Get("content").Str)
|
return bot.CQGetWordSlices(p.Get("content").Str)
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user