mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-06-30 11:53:25 +00:00
Compare commits
89 Commits
v0.9.39-fi
...
v0.9.40-fi
Author | SHA1 | Date | |
---|---|---|---|
b1ca827187 | |||
c1a36caa99 | |||
e9b6e477f1 | |||
6d0a6c137d | |||
69703f560f | |||
580a5feabf | |||
5db56b99c6 | |||
e56a297437 | |||
f9d1cf93a2 | |||
916c79d2cf | |||
1dcfa0d025 | |||
d2be362f84 | |||
a0cdf2c410 | |||
8f8529af9e | |||
0afbe3d64a | |||
3851a60869 | |||
a9fb84eb47 | |||
56f648aaca | |||
945fbf6a2b | |||
185f11f6a0 | |||
8602490711 | |||
a1fb629798 | |||
396ce82baa | |||
2d90a16fbf | |||
afd0c8987d | |||
70a4d129c8 | |||
1ff9de190d | |||
569a718dc6 | |||
32771eb8b0 | |||
2ce0d145e8 | |||
02581ff8a9 | |||
ee0da0a14f | |||
71ce6f362f | |||
ce30d63907 | |||
19556cbab3 | |||
3bfdc4d8a2 | |||
fba4819adc | |||
e30e21e296 | |||
6e8ef3ef0f | |||
31cfb9283e | |||
0e71acaf38 | |||
879cbe4f19 | |||
775a210e3e | |||
f5bd4644fd | |||
e8129a7e57 | |||
adbe194e63 | |||
7e5b293d36 | |||
8dc2349a9b | |||
337b7fd134 | |||
967e79ecd1 | |||
cc14be66bd | |||
667ad8fbd6 | |||
1b3842fc98 | |||
203b68b740 | |||
eaf7067196 | |||
82bca7183d | |||
13975c02df | |||
d5c624d6f2 | |||
3bbcdc9171 | |||
c72bc3b1b0 | |||
22a02542af | |||
ff75b0a2a9 | |||
4a13f35003 | |||
8d0a0b7f4d | |||
4c570bdfe6 | |||
d4e8a3df4f | |||
307a09dd11 | |||
4445af6ff2 | |||
7b71cd9219 | |||
d291aa02fe | |||
dbd0f85025 | |||
0bacbde4d7 | |||
c92dd39191 | |||
7da1918c0c | |||
89d466d3e1 | |||
5b57aeb1d1 | |||
939307efc7 | |||
02446f7791 | |||
cff7ac8e0b | |||
6f5e582213 | |||
a74c623cc1 | |||
614109e116 | |||
6d5b0e01a2 | |||
f6e620b412 | |||
c918182dec | |||
c0a813a093 | |||
8b1d950a29 | |||
8b14409aaf | |||
464122af4a |
3
.github/ISSUE_TEMPLATE/bug--.md
vendored
3
.github/ISSUE_TEMPLATE/bug--.md
vendored
@ -13,8 +13,11 @@ assignees: ''
|
|||||||
2: 准确填写环境信息.
|
2: 准确填写环境信息.
|
||||||
3: 最好能打开DEBUG模式并复现相关问题.
|
3: 最好能打开DEBUG模式并复现相关问题.
|
||||||
4: 如果涉及内存泄漏/CPU占用异常请打开DEBUG模式并下载pprof性能分析.
|
4: 如果涉及内存泄漏/CPU占用异常请打开DEBUG模式并下载pprof性能分析.
|
||||||
|
注: 如果您不知道如何有效、精准地表述,我们建议您先阅读《提问的智慧》 -> https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
- [ ] 我已经阅读"提问前需知 [图+文]": `Mrs4s/go-cqhttp/issues/633`
|
||||||
|
|
||||||
**环境信息**
|
**环境信息**
|
||||||
请根据实际使用环境修改以下信息
|
请根据实际使用环境修改以下信息
|
||||||
go-cqhttp版本:
|
go-cqhttp版本:
|
||||||
|
20
.github/workflows/ci.yml
vendored
20
.github/workflows/ci.yml
vendored
@ -14,28 +14,23 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/amd64
|
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/amd64, darwin/arm64
|
||||||
goos: [linux, windows, darwin]
|
goos: [linux, windows, darwin]
|
||||||
goarch: ["386", amd64, arm, arm64]
|
goarch: ["386", amd64, arm, arm64]
|
||||||
exclude:
|
exclude:
|
||||||
- goos: darwin
|
- goos: darwin
|
||||||
goarch: arm
|
goarch: arm
|
||||||
- goos: darwin
|
|
||||||
goarch: arm64
|
|
||||||
- goos: darwin
|
- goos: darwin
|
||||||
goarch: "386"
|
goarch: "386"
|
||||||
- goos: windows
|
- goos: windows
|
||||||
goarch: arm64
|
goarch: arm64
|
||||||
fail-fast: true
|
fail-fast: true
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Setup Go environment
|
- name: Setup Go environment
|
||||||
uses: actions/setup-go@v2.1.3
|
uses: actions/setup-go@v2.1.3
|
||||||
with:
|
with:
|
||||||
go-version: 1.15
|
go-version: 1.16
|
||||||
|
|
||||||
- name: Build binary file
|
- name: Build binary file
|
||||||
env:
|
env:
|
||||||
GOOS: ${{ matrix.goos }}
|
GOOS: ${{ matrix.goos }}
|
||||||
@ -47,7 +42,6 @@ jobs:
|
|||||||
export BINARY_NAME="$BINARY_PREFIX$GOOS_$GOARCH$BINARY_SUFFIX"
|
export BINARY_NAME="$BINARY_PREFIX$GOOS_$GOARCH$BINARY_SUFFIX"
|
||||||
export CGO_ENABLED=0
|
export CGO_ENABLED=0
|
||||||
go build -o "output/$BINARY_NAME" -ldflags "$LD_FLAGS" .
|
go build -o "output/$BINARY_NAME" -ldflags "$LD_FLAGS" .
|
||||||
|
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
if: ${{ !github.head_ref }}
|
if: ${{ !github.head_ref }}
|
||||||
@ -55,4 +49,12 @@ jobs:
|
|||||||
name: ${{ matrix.goos }}_${{ matrix.goarch }}
|
name: ${{ matrix.goos }}_${{ matrix.goarch }}
|
||||||
path: output/
|
path: output/
|
||||||
|
|
||||||
|
golangci:
|
||||||
|
name: lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v2
|
||||||
|
with:
|
||||||
|
version: v1.29
|
||||||
|
6
.github/workflows/release.yml
vendored
6
.github/workflows/release.yml
vendored
@ -8,14 +8,12 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/386, darwin/amd64
|
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/386, darwin/amd64, darwin/arm64
|
||||||
goos: [linux, windows, darwin]
|
goos: [linux, windows, darwin]
|
||||||
goarch: ["386", amd64, arm, arm64]
|
goarch: ["386", amd64, arm, arm64]
|
||||||
exclude:
|
exclude:
|
||||||
- goos: darwin
|
- goos: darwin
|
||||||
goarch: arm
|
goarch: arm
|
||||||
- goos: darwin
|
|
||||||
goarch: arm64
|
|
||||||
- goos: darwin
|
- goos: darwin
|
||||||
goarch: "386"
|
goarch: "386"
|
||||||
- goos: windows
|
- goos: windows
|
||||||
@ -32,6 +30,6 @@ jobs:
|
|||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
goos: ${{ matrix.goos }}
|
goos: ${{ matrix.goos }}
|
||||||
goarch: ${{ matrix.goarch }}
|
goarch: ${{ matrix.goarch }}
|
||||||
goversion: "https://golang.org/dl/go1.15.3.linux-amd64.tar.gz"
|
goversion: "https://golang.org/dl/go1.16.linux-amd64.tar.gz"
|
||||||
ldflags: -w -s -X "github.com/Mrs4s/go-cqhttp/coolq.Version=${{ env.RELEASE_VERSION }}"
|
ldflags: -w -s -X "github.com/Mrs4s/go-cqhttp/coolq.Version=${{ env.RELEASE_VERSION }}"
|
||||||
|
|
||||||
|
18
README.md
18
README.md
@ -6,7 +6,8 @@
|
|||||||
|
|
||||||
# go-cqhttp
|
# go-cqhttp
|
||||||
|
|
||||||
_✨ 基于 [Mirai](https://github.com/mamoe/mirai) 以及 [MiraiGo](https://github.com/Mrs4s/MiraiGo) 的 [cqhttp](https://github.com/howmanybots/onebot/blob/master/README.md) golang 原生实现 ✨_
|
_✨ 基于 [Mirai](https://github.com/mamoe/mirai) 以及 [MiraiGo](https://github.com/Mrs4s/MiraiGo) 的 [OneBot](https://github.com/howmanybots/onebot/blob/master/README.md) Golang 原生实现 ✨_
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -23,23 +24,21 @@ _✨ 基于 [Mirai](https://github.com/mamoe/mirai) 以及 [MiraiGo](https://git
|
|||||||
<a href="https://github.com/Mrs4s/go-cqhttp/actions">
|
<a href="https://github.com/Mrs4s/go-cqhttp/actions">
|
||||||
<img src="https://github.com/Mrs4s/go-cqhttp/workflows/CI/badge.svg" alt="action">
|
<img src="https://github.com/Mrs4s/go-cqhttp/workflows/CI/badge.svg" alt="action">
|
||||||
</a>
|
</a>
|
||||||
|
<a href="https://goreportcard.com/report/github.com/Mrs4s/go-cqhttp">
|
||||||
|
<img src="https://goreportcard.com/badge/github.com/Mrs4s/go-cqhttp" alt="GoReportCard">
|
||||||
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="http://ishkong.github.io/go-cqhttp-docs">文档</a>
|
<a href="https://docs.go-cqhttp.org/">文档</a>
|
||||||
·
|
·
|
||||||
<a href="https://github.com/Mrs4s/go-cqhttp/releases">下载</a>
|
<a href="https://github.com/Mrs4s/go-cqhttp/releases">下载</a>
|
||||||
·
|
·
|
||||||
<a href="https://ishkong.github.io/go-cqhttp-docs/guide/quick_start.html">开始使用</a>
|
<a href="https://docs.go-cqhttp.org/guide/quick_start.html">开始使用</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
go-cqhttp 在[原版 cqhttp](https://github.com/richardchien/coolq-http-api)的基础上做了部分修改和拓展.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 兼容性
|
## 兼容性
|
||||||
|
go-cqhttp兼容[OneBot-v11](https://github.com/howmanybots/onebot/tree/master/v11/specs)绝大多数内容,并在其基础上做了一些扩展,详情请看go-cqhttp的文档
|
||||||
|
|
||||||
### 接口
|
### 接口
|
||||||
|
|
||||||
@ -276,6 +275,7 @@ go-cqhttp 在[原版 cqhttp](https://github.com/richardchien/coolq-http-api)的
|
|||||||
- 重复提问
|
- 重复提问
|
||||||
|
|
||||||
> 请注意, 开发者并没有义务回复您的问题. 您应该具备基本的提问技巧。
|
> 请注意, 开发者并没有义务回复您的问题. 您应该具备基本的提问技巧。
|
||||||
|
> 有关如何提问,请阅读[《提问的智慧》](https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md)
|
||||||
|
|
||||||
## 性能
|
## 性能
|
||||||
|
|
||||||
|
568
coolq/api.go
568
coolq/api.go
File diff suppressed because it is too large
Load Diff
88
coolq/bot.go
88
coolq/bot.go
@ -13,21 +13,19 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Mrs4s/MiraiGo/utils"
|
|
||||||
|
|
||||||
"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/MiraiGo/utils"
|
||||||
"github.com/Mrs4s/go-cqhttp/global"
|
"github.com/Mrs4s/go-cqhttp/global"
|
||||||
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/syndtr/goleveldb/leveldb"
|
||||||
)
|
)
|
||||||
|
|
||||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||||
|
|
||||||
|
// CQBot CQBot结构体,存储Bot实例相关配置
|
||||||
type CQBot struct {
|
type CQBot struct {
|
||||||
Client *client.QQClient
|
Client *client.QQClient
|
||||||
|
|
||||||
@ -38,10 +36,13 @@ type CQBot struct {
|
|||||||
oneWayMsgCache sync.Map
|
oneWayMsgCache sync.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MSG 消息Map
|
||||||
type MSG map[string]interface{}
|
type MSG map[string]interface{}
|
||||||
|
|
||||||
|
// ForceFragmented 是否启用强制分片
|
||||||
var ForceFragmented = false
|
var ForceFragmented = false
|
||||||
|
|
||||||
|
// NewQQBot 初始化一个QQBot实例
|
||||||
func NewQQBot(cli *client.QQClient, conf *global.JSONConfig) *CQBot {
|
func NewQQBot(cli *client.QQClient, conf *global.JSONConfig) *CQBot {
|
||||||
bot := &CQBot{
|
bot := &CQBot{
|
||||||
Client: cli,
|
Client: cli,
|
||||||
@ -60,6 +61,7 @@ func NewQQBot(cli *client.QQClient, conf *global.JSONConfig) *CQBot {
|
|||||||
}
|
}
|
||||||
bot.Client.OnPrivateMessage(bot.privateMessageEvent)
|
bot.Client.OnPrivateMessage(bot.privateMessageEvent)
|
||||||
bot.Client.OnGroupMessage(bot.groupMessageEvent)
|
bot.Client.OnGroupMessage(bot.groupMessageEvent)
|
||||||
|
bot.Client.OnSelfGroupMessage(bot.groupMessageEvent)
|
||||||
bot.Client.OnTempMessage(bot.tempMessageEvent)
|
bot.Client.OnTempMessage(bot.tempMessageEvent)
|
||||||
bot.Client.OnGroupMuted(bot.groupMutedEvent)
|
bot.Client.OnGroupMuted(bot.groupMutedEvent)
|
||||||
bot.Client.OnGroupMessageRecalled(bot.groupRecallEvent)
|
bot.Client.OnGroupMessageRecalled(bot.groupRecallEvent)
|
||||||
@ -78,6 +80,7 @@ func NewQQBot(cli *client.QQClient, conf *global.JSONConfig) *CQBot {
|
|||||||
bot.Client.OnGroupInvited(bot.groupInvitedEvent)
|
bot.Client.OnGroupInvited(bot.groupInvitedEvent)
|
||||||
bot.Client.OnUserWantJoinGroup(bot.groupJoinReqEvent)
|
bot.Client.OnUserWantJoinGroup(bot.groupJoinReqEvent)
|
||||||
bot.Client.OnOtherClientStatusChanged(bot.otherClientStatusChangedEvent)
|
bot.Client.OnOtherClientStatusChanged(bot.otherClientStatusChangedEvent)
|
||||||
|
bot.Client.OnGroupDigest(bot.groupEssenceMsg)
|
||||||
go func() {
|
go func() {
|
||||||
i := conf.HeartbeatInterval
|
i := conf.HeartbeatInterval
|
||||||
if i < 0 {
|
if i < 0 {
|
||||||
@ -102,10 +105,12 @@ func NewQQBot(cli *client.QQClient, conf *global.JSONConfig) *CQBot {
|
|||||||
return bot
|
return bot
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OnEventPush 注册事件上报函数
|
||||||
func (bot *CQBot) OnEventPush(f func(m MSG)) {
|
func (bot *CQBot) OnEventPush(f func(m MSG)) {
|
||||||
bot.events = append(bot.events, f)
|
bot.events = append(bot.events, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetMessage 获取给定消息id对应的消息
|
||||||
func (bot *CQBot) GetMessage(mid int32) MSG {
|
func (bot *CQBot) GetMessage(mid int32) MSG {
|
||||||
if bot.db != nil {
|
if bot.db != nil {
|
||||||
m := MSG{}
|
m := MSG{}
|
||||||
@ -123,6 +128,7 @@ func (bot *CQBot) GetMessage(mid int32) MSG {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UploadLocalImageAsGroup 上传本地图片至群聊
|
||||||
func (bot *CQBot) UploadLocalImageAsGroup(groupCode int64, img *LocalImageElement) (*message.GroupImageElement, error) {
|
func (bot *CQBot) UploadLocalImageAsGroup(groupCode int64, img *LocalImageElement) (*message.GroupImageElement, error) {
|
||||||
if img.Stream != nil {
|
if img.Stream != nil {
|
||||||
return bot.Client.UploadGroupImage(groupCode, img.Stream)
|
return bot.Client.UploadGroupImage(groupCode, img.Stream)
|
||||||
@ -130,6 +136,7 @@ func (bot *CQBot) UploadLocalImageAsGroup(groupCode int64, img *LocalImageElemen
|
|||||||
return bot.Client.UploadGroupImageByFile(groupCode, img.File)
|
return bot.Client.UploadGroupImageByFile(groupCode, img.File)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UploadLocalVideo 上传本地短视频至群聊
|
||||||
func (bot *CQBot) UploadLocalVideo(target int64, v *LocalVideoElement) (*message.ShortVideoElement, error) {
|
func (bot *CQBot) UploadLocalVideo(target int64, v *LocalVideoElement) (*message.ShortVideoElement, error) {
|
||||||
if v.File != "" {
|
if v.File != "" {
|
||||||
video, err := os.Open(v.File)
|
video, err := os.Open(v.File)
|
||||||
@ -146,9 +153,10 @@ func (bot *CQBot) UploadLocalVideo(target int64, v *LocalVideoElement) (*message
|
|||||||
return &v.ShortVideoElement, nil
|
return &v.ShortVideoElement, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) UploadLocalImageAsPrivate(userId int64, img *LocalImageElement) (*message.FriendImageElement, error) {
|
// UploadLocalImageAsPrivate 上传本地图片至私聊
|
||||||
|
func (bot *CQBot) UploadLocalImageAsPrivate(userID int64, img *LocalImageElement) (*message.FriendImageElement, error) {
|
||||||
if img.Stream != nil {
|
if img.Stream != nil {
|
||||||
return bot.Client.UploadPrivateImage(userId, img.Stream)
|
return bot.Client.UploadPrivateImage(userID, img.Stream)
|
||||||
}
|
}
|
||||||
// need update.
|
// need update.
|
||||||
f, err := os.Open(img.File)
|
f, err := os.Open(img.File)
|
||||||
@ -156,41 +164,42 @@ func (bot *CQBot) UploadLocalImageAsPrivate(userId int64, img *LocalImageElement
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
return bot.Client.UploadPrivateImage(userId, f)
|
return bot.Client.UploadPrivateImage(userID, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int32 {
|
// SendGroupMessage 发送群消息
|
||||||
|
func (bot *CQBot) SendGroupMessage(groupID int64, m *message.SendingMessage) int32 {
|
||||||
var newElem []message.IMessageElement
|
var newElem []message.IMessageElement
|
||||||
for _, elem := range m.Elements {
|
for _, elem := range m.Elements {
|
||||||
if i, ok := elem.(*LocalImageElement); ok {
|
if i, ok := elem.(*LocalImageElement); ok {
|
||||||
gm, err := bot.UploadLocalImageAsGroup(groupId, i)
|
gm, err := bot.UploadLocalImageAsGroup(groupID, i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("警告: 群 %v 消息图片上传失败: %v", groupId, err)
|
log.Warnf("警告: 群 %v 消息图片上传失败: %v", groupID, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
newElem = append(newElem, gm)
|
newElem = append(newElem, gm)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if i, ok := elem.(*message.VoiceElement); ok {
|
if i, ok := elem.(*message.VoiceElement); ok {
|
||||||
gv, err := bot.Client.UploadGroupPtt(groupId, bytes.NewReader(i.Data))
|
gv, err := bot.Client.UploadGroupPtt(groupID, bytes.NewReader(i.Data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("警告: 群 %v 消息语音上传失败: %v", groupId, err)
|
log.Warnf("警告: 群 %v 消息语音上传失败: %v", groupID, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
newElem = append(newElem, gv)
|
newElem = append(newElem, gv)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if i, ok := elem.(*LocalVideoElement); ok {
|
if i, ok := elem.(*LocalVideoElement); ok {
|
||||||
gv, err := bot.UploadLocalVideo(groupId, i)
|
gv, err := bot.UploadLocalVideo(groupID, i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("警告: 群 %v 消息短视频上传失败: %v", groupId, err)
|
log.Warnf("警告: 群 %v 消息短视频上传失败: %v", groupID, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
newElem = append(newElem, gv)
|
newElem = append(newElem, gv)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if i, ok := elem.(*PokeElement); ok {
|
if i, ok := elem.(*PokeElement); ok {
|
||||||
if group := bot.Client.FindGroup(groupId); group != nil {
|
if group := bot.Client.FindGroup(groupID); group != nil {
|
||||||
if mem := group.FindMember(i.Target); mem != nil {
|
if mem := group.FindMember(i.Target); mem != nil {
|
||||||
mem.Poke()
|
mem.Poke()
|
||||||
return 0
|
return 0
|
||||||
@ -198,13 +207,13 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if i, ok := elem.(*GiftElement); ok {
|
if i, ok := elem.(*GiftElement); ok {
|
||||||
bot.Client.SendGroupGift(uint64(groupId), uint64(i.Target), i.GiftId)
|
bot.Client.SendGroupGift(uint64(groupID), uint64(i.Target), i.GiftID)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
if i, ok := elem.(*message.MusicShareElement); ok {
|
if i, ok := elem.(*message.MusicShareElement); ok {
|
||||||
ret, err := bot.Client.SendGroupMusicShare(groupId, i)
|
ret, err := bot.Client.SendGroupMusicShare(groupID, i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("警告: 群 %v 富文本消息发送失败: %v", groupId, err)
|
log.Warnf("警告: 群 %v 富文本消息发送失败: %v", groupID, err)
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
return bot.InsertGroupMessage(ret)
|
return bot.InsertGroupMessage(ret)
|
||||||
@ -217,7 +226,7 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int
|
|||||||
}
|
}
|
||||||
m.Elements = newElem
|
m.Elements = newElem
|
||||||
bot.checkMedia(newElem)
|
bot.checkMedia(newElem)
|
||||||
ret := bot.Client.SendGroupMessage(groupId, m, ForceFragmented)
|
ret := bot.Client.SendGroupMessage(groupID, m, ForceFragmented)
|
||||||
if ret == nil || ret.Id == -1 {
|
if ret == nil || ret.Id == -1 {
|
||||||
log.Warnf("群消息发送失败: 账号可能被风控.")
|
log.Warnf("群消息发送失败: 账号可能被风控.")
|
||||||
return -1
|
return -1
|
||||||
@ -225,6 +234,7 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int
|
|||||||
return bot.InsertGroupMessage(ret)
|
return bot.InsertGroupMessage(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendPrivateMessage 发送私聊消息
|
||||||
func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) int32 {
|
func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) int32 {
|
||||||
var newElem []message.IMessageElement
|
var newElem []message.IMessageElement
|
||||||
for _, elem := range m.Elements {
|
for _, elem := range m.Elements {
|
||||||
@ -294,6 +304,7 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in
|
|||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InsertGroupMessage 群聊消息入数据库
|
||||||
func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
|
func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
|
||||||
val := MSG{
|
val := MSG{
|
||||||
"message-id": m.Id,
|
"message-id": m.Id,
|
||||||
@ -304,7 +315,7 @@ func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
|
|||||||
"time": m.Time,
|
"time": m.Time,
|
||||||
"message": ToStringMessage(m.Elements, m.GroupCode, true),
|
"message": ToStringMessage(m.Elements, m.GroupCode, true),
|
||||||
}
|
}
|
||||||
id := ToGlobalId(m.GroupCode, m.Id)
|
id := toGlobalID(m.GroupCode, m.Id)
|
||||||
if bot.db != nil {
|
if bot.db != nil {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
if err := gob.NewEncoder(buf).Encode(val); err != nil {
|
if err := gob.NewEncoder(buf).Encode(val); err != nil {
|
||||||
@ -319,6 +330,7 @@ func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
|
|||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InsertPrivateMessage 私聊消息入数据库
|
||||||
func (bot *CQBot) InsertPrivateMessage(m *message.PrivateMessage) int32 {
|
func (bot *CQBot) InsertPrivateMessage(m *message.PrivateMessage) int32 {
|
||||||
val := MSG{
|
val := MSG{
|
||||||
"message-id": m.Id,
|
"message-id": m.Id,
|
||||||
@ -328,7 +340,7 @@ func (bot *CQBot) InsertPrivateMessage(m *message.PrivateMessage) int32 {
|
|||||||
"time": m.Time,
|
"time": m.Time,
|
||||||
"message": ToStringMessage(m.Elements, m.Sender.Uin, true),
|
"message": ToStringMessage(m.Elements, m.Sender.Uin, true),
|
||||||
}
|
}
|
||||||
id := ToGlobalId(m.Sender.Uin, m.Id)
|
id := toGlobalID(m.Sender.Uin, m.Id)
|
||||||
if bot.db != nil {
|
if bot.db != nil {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
if err := gob.NewEncoder(buf).Encode(val); err != nil {
|
if err := gob.NewEncoder(buf).Encode(val); err != nil {
|
||||||
@ -343,10 +355,12 @@ func (bot *CQBot) InsertPrivateMessage(m *message.PrivateMessage) int32 {
|
|||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToGlobalId(code int64, msgId int32) int32 {
|
// toGlobalID 构建`code`-`msgID`的字符串并返回其CRC32 Checksum的值
|
||||||
return int32(crc32.ChecksumIEEE([]byte(fmt.Sprintf("%d-%d", code, msgId))))
|
func toGlobalID(code int64, msgID int32) int32 {
|
||||||
|
return int32(crc32.ChecksumIEEE([]byte(fmt.Sprintf("%d-%d", code, msgID))))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Release 释放Bot实例
|
||||||
func (bot *CQBot) Release() {
|
func (bot *CQBot) Release() {
|
||||||
if bot.db != nil {
|
if bot.db != nil {
|
||||||
_ = bot.db.Close()
|
_ = bot.db.Close()
|
||||||
@ -382,7 +396,12 @@ func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) MSG {
|
|||||||
"font": 0,
|
"font": 0,
|
||||||
"group_id": m.GroupCode,
|
"group_id": m.GroupCode,
|
||||||
"message": ToFormattedMessage(m.Elements, m.GroupCode, false),
|
"message": ToFormattedMessage(m.Elements, m.GroupCode, false),
|
||||||
"message_type": "group",
|
"message_type": func() string {
|
||||||
|
if m.Sender.Uin == bot.Client.Uin {
|
||||||
|
return "group_self"
|
||||||
|
}
|
||||||
|
return "group"
|
||||||
|
}(),
|
||||||
"message_seq": m.Id,
|
"message_seq": m.Id,
|
||||||
"post_type": "message",
|
"post_type": "message",
|
||||||
"raw_message": cqm,
|
"raw_message": cqm,
|
||||||
@ -407,7 +426,21 @@ func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) MSG {
|
|||||||
gm["sender"].(MSG)["nickname"] = "匿名消息"
|
gm["sender"].(MSG)["nickname"] = "匿名消息"
|
||||||
gm["sub_type"] = "anonymous"
|
gm["sub_type"] = "anonymous"
|
||||||
} else {
|
} else {
|
||||||
mem := bot.Client.FindGroup(m.GroupCode).FindMember(m.Sender.Uin)
|
group := bot.Client.FindGroup(m.GroupCode)
|
||||||
|
mem := group.FindMember(m.Sender.Uin)
|
||||||
|
if mem == nil {
|
||||||
|
log.Warnf("获取 %v 成员信息失败,尝试刷新成员列表", m.Sender.Uin)
|
||||||
|
t, err := bot.Client.GetGroupMembers(group)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("刷新群 %v 成员列表失败: %v", group.Uin, err)
|
||||||
|
return Failed(100, "GET_MEMBERS_API_ERROR", err.Error())
|
||||||
|
}
|
||||||
|
group.Members = t
|
||||||
|
mem = group.FindMember(m.Sender.Uin)
|
||||||
|
if mem != nil {
|
||||||
|
return Failed(100, "MEMBER_NOT_FOUND", "群员不存在")
|
||||||
|
}
|
||||||
|
}
|
||||||
ms := gm["sender"].(MSG)
|
ms := gm["sender"].(MSG)
|
||||||
ms["role"] = func() string {
|
ms["role"] = func() string {
|
||||||
switch mem.Permission {
|
switch mem.Permission {
|
||||||
@ -437,7 +470,8 @@ func formatMemberName(mem *client.GroupMemberInfo) string {
|
|||||||
return fmt.Sprintf("%s(%d)", mem.DisplayName(), mem.Uin)
|
return fmt.Sprintf("%s(%d)", mem.DisplayName(), mem.Uin)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MSG) ToJson() string {
|
// ToJSON 生成JSON字符串
|
||||||
|
func (m MSG) ToJSON() string {
|
||||||
b, _ := json.Marshal(m)
|
b, _ := json.Marshal(m)
|
||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
166
coolq/cqcode.go
166
coolq/cqcode.go
@ -34,43 +34,53 @@ var typeReg = regexp.MustCompile(`\[CQ:(\w+)`)
|
|||||||
var paramReg = regexp.MustCompile(`,([\w\-.]+?)=([^,\]]+)`)
|
var paramReg = regexp.MustCompile(`,([\w\-.]+?)=([^,\]]+)`)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// IgnoreInvalidCQCode 是否忽略无效CQ码
|
||||||
var IgnoreInvalidCQCode = false
|
var IgnoreInvalidCQCode = false
|
||||||
var SplitUrl = false
|
|
||||||
|
// SplitURL 是否分割URL
|
||||||
|
var SplitURL = false
|
||||||
|
|
||||||
const maxImageSize = 1024 * 1024 * 30 // 30MB
|
const maxImageSize = 1024 * 1024 * 30 // 30MB
|
||||||
const maxVideoSize = 1024 * 1024 * 100 // 100MB
|
const maxVideoSize = 1024 * 1024 * 100 // 100MB
|
||||||
|
// PokeElement 拍一拍
|
||||||
type PokeElement struct {
|
type PokeElement struct {
|
||||||
Target int64
|
Target int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GiftElement 礼物
|
||||||
type GiftElement struct {
|
type GiftElement struct {
|
||||||
Target int64
|
Target int64
|
||||||
GiftId message.GroupGift
|
GiftID message.GroupGift
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LocalImageElement 本地图片
|
||||||
type LocalImageElement struct {
|
type LocalImageElement struct {
|
||||||
message.ImageElement
|
message.ImageElement
|
||||||
Stream io.ReadSeeker
|
Stream io.ReadSeeker
|
||||||
File string
|
File string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LocalVoiceElement 本地语音
|
||||||
type LocalVoiceElement struct {
|
type LocalVoiceElement struct {
|
||||||
message.VoiceElement
|
message.VoiceElement
|
||||||
Stream io.ReadSeeker
|
Stream io.ReadSeeker
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LocalVideoElement 本地视频
|
||||||
type LocalVideoElement struct {
|
type LocalVideoElement struct {
|
||||||
message.ShortVideoElement
|
message.ShortVideoElement
|
||||||
File string
|
File string
|
||||||
thumb io.ReadSeeker
|
thumb io.ReadSeeker
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Type 获取元素类型ID
|
||||||
func (e *GiftElement) Type() message.ElementType {
|
func (e *GiftElement) Type() message.ElementType {
|
||||||
|
// Make message.IMessageElement Happy
|
||||||
return message.At
|
return message.At
|
||||||
}
|
}
|
||||||
|
|
||||||
var GiftId = [...]message.GroupGift{
|
// GiftID 礼物ID数组
|
||||||
|
var GiftID = [...]message.GroupGift{
|
||||||
message.SweetWink,
|
message.SweetWink,
|
||||||
message.HappyCola,
|
message.HappyCola,
|
||||||
message.LuckyBracelet,
|
message.LuckyBracelet,
|
||||||
@ -87,15 +97,18 @@ var GiftId = [...]message.GroupGift{
|
|||||||
message.LoveMask,
|
message.LoveMask,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Type 获取元素类型ID
|
||||||
func (e *PokeElement) Type() message.ElementType {
|
func (e *PokeElement) Type() message.ElementType {
|
||||||
|
// Make message.IMessageElement Happy
|
||||||
return message.At
|
return message.At
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []MSG) {
|
// ToArrayMessage 将消息元素数组转为MSG数组以用于消息上报
|
||||||
|
func ToArrayMessage(e []message.IMessageElement, id int64, isRaw ...bool) (r []MSG) {
|
||||||
r = []MSG{}
|
r = []MSG{}
|
||||||
ur := false
|
ur := false
|
||||||
if len(raw) != 0 {
|
if len(isRaw) != 0 {
|
||||||
ur = raw[0]
|
ur = isRaw[0]
|
||||||
}
|
}
|
||||||
m := &message.SendingMessage{Elements: e}
|
m := &message.SendingMessage{Elements: e}
|
||||||
reply := m.FirstOrNil(func(e message.IMessageElement) bool {
|
reply := m.FirstOrNil(func(e message.IMessageElement) bool {
|
||||||
@ -105,7 +118,7 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
|
|||||||
if reply != nil {
|
if reply != nil {
|
||||||
r = append(r, MSG{
|
r = append(r, MSG{
|
||||||
"type": "reply",
|
"type": "reply",
|
||||||
"data": map[string]string{"id": fmt.Sprint(ToGlobalId(code, reply.(*message.ReplyElement).ReplySeq))},
|
"data": map[string]string{"id": fmt.Sprint(toGlobalID(id, reply.(*message.ReplyElement).ReplySeq))},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
for _, elem := range e {
|
for _, elem := range e {
|
||||||
@ -242,10 +255,11 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToStringMessage(e []message.IMessageElement, code int64, raw ...bool) (r string) {
|
// ToStringMessage 将消息元素数组转为字符串以用于消息上报
|
||||||
|
func ToStringMessage(e []message.IMessageElement, id int64, isRaw ...bool) (r string) {
|
||||||
ur := false
|
ur := false
|
||||||
if len(raw) != 0 {
|
if len(isRaw) != 0 {
|
||||||
ur = raw[0]
|
ur = isRaw[0]
|
||||||
}
|
}
|
||||||
// 方便
|
// 方便
|
||||||
m := &message.SendingMessage{Elements: e}
|
m := &message.SendingMessage{Elements: e}
|
||||||
@ -254,7 +268,7 @@ func ToStringMessage(e []message.IMessageElement, code int64, raw ...bool) (r st
|
|||||||
return ok
|
return ok
|
||||||
})
|
})
|
||||||
if reply != nil {
|
if reply != nil {
|
||||||
r += fmt.Sprintf("[CQ:reply,id=%d]", ToGlobalId(code, reply.(*message.ReplyElement).ReplySeq))
|
r += fmt.Sprintf("[CQ:reply,id=%d]", toGlobalID(id, reply.(*message.ReplyElement).ReplySeq))
|
||||||
}
|
}
|
||||||
for _, elem := range e {
|
for _, elem := range e {
|
||||||
switch o := elem.(type) {
|
switch o := elem.(type) {
|
||||||
@ -320,7 +334,8 @@ func ToStringMessage(e []message.IMessageElement, code int64, raw ...bool) (r st
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) ConvertStringMessage(msg string, group bool) (r []message.IMessageElement) {
|
// ConvertStringMessage 将消息字符串转为消息元素数组
|
||||||
|
func (bot *CQBot) ConvertStringMessage(msg string, isGroup bool) (r []message.IMessageElement) {
|
||||||
index := 0
|
index := 0
|
||||||
stat := 0
|
stat := 0
|
||||||
rMsg := []rune(msg)
|
rMsg := []rune(msg)
|
||||||
@ -345,12 +360,12 @@ func (bot *CQBot) ConvertStringMessage(msg string, group bool) (r []message.IMes
|
|||||||
}
|
}
|
||||||
saveTempText := func() {
|
saveTempText := func() {
|
||||||
if len(tempText) != 0 {
|
if len(tempText) != 0 {
|
||||||
if SplitUrl {
|
if SplitURL {
|
||||||
for _, t := range global.SplitURL(CQCodeUnescapeValue(string(tempText))) {
|
for _, t := range global.SplitURL(CQCodeUnescapeText(string(tempText))) {
|
||||||
r = append(r, message.NewText(t))
|
r = append(r, message.NewText(t))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
r = append(r, message.NewText(CQCodeUnescapeValue(string(tempText))))
|
r = append(r, message.NewText(CQCodeUnescapeText(string(tempText))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tempText = []rune{}
|
tempText = []rune{}
|
||||||
@ -397,7 +412,7 @@ func (bot *CQBot) ConvertStringMessage(msg string, group bool) (r []message.IMes
|
|||||||
ReplySeq: org["message-id"].(int32),
|
ReplySeq: org["message-id"].(int32),
|
||||||
Sender: org["sender"].(message.Sender).Uin,
|
Sender: org["sender"].(message.Sender).Uin,
|
||||||
Time: org["time"].(int32),
|
Time: org["time"].(int32),
|
||||||
Elements: bot.ConvertStringMessage(org["message"].(string), group),
|
Elements: bot.ConvertStringMessage(org["message"].(string), isGroup),
|
||||||
},
|
},
|
||||||
}, r...)
|
}, r...)
|
||||||
return
|
return
|
||||||
@ -417,7 +432,7 @@ func (bot *CQBot) ConvertStringMessage(msg string, group bool) (r []message.IMes
|
|||||||
ReplySeq: int32(0),
|
ReplySeq: int32(0),
|
||||||
Sender: sender,
|
Sender: sender,
|
||||||
Time: int32(msgTime),
|
Time: int32(msgTime),
|
||||||
Elements: bot.ConvertStringMessage(customText, group),
|
Elements: bot.ConvertStringMessage(customText, isGroup),
|
||||||
},
|
},
|
||||||
}, r...)
|
}, r...)
|
||||||
return
|
return
|
||||||
@ -429,7 +444,7 @@ func (bot *CQBot) ConvertStringMessage(msg string, group bool) (r []message.IMes
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elem, err := bot.ToElement(t, params, group)
|
elem, err := bot.ToElement(t, params, isGroup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
org := "[CQ:" + string(cqCode) + "]"
|
org := "[CQ:" + string(cqCode) + "]"
|
||||||
if !IgnoreInvalidCQCode {
|
if !IgnoreInvalidCQCode {
|
||||||
@ -476,10 +491,11 @@ func (bot *CQBot) ConvertStringMessage(msg string, group bool) (r []message.IMes
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) ConvertObjectMessage(m gjson.Result, group bool) (r []message.IMessageElement) {
|
// ConvertObjectMessage 将消息JSON对象转为消息元素数组
|
||||||
|
func (bot *CQBot) ConvertObjectMessage(m gjson.Result, isGroup bool) (r []message.IMessageElement) {
|
||||||
convertElem := func(e gjson.Result) {
|
convertElem := func(e gjson.Result) {
|
||||||
t := e.Get("type").Str
|
t := e.Get("type").Str
|
||||||
if t == "reply" && group {
|
if t == "reply" && isGroup {
|
||||||
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 元素.")
|
||||||
@ -496,7 +512,7 @@ func (bot *CQBot) ConvertObjectMessage(m gjson.Result, group bool) (r []message.
|
|||||||
ReplySeq: org["message-id"].(int32),
|
ReplySeq: org["message-id"].(int32),
|
||||||
Sender: org["sender"].(message.Sender).Uin,
|
Sender: org["sender"].(message.Sender).Uin,
|
||||||
Time: org["time"].(int32),
|
Time: org["time"].(int32),
|
||||||
Elements: bot.ConvertStringMessage(org["message"].(string), group),
|
Elements: bot.ConvertStringMessage(org["message"].(string), isGroup),
|
||||||
},
|
},
|
||||||
}, r...)
|
}, r...)
|
||||||
return
|
return
|
||||||
@ -516,7 +532,7 @@ func (bot *CQBot) ConvertObjectMessage(m gjson.Result, group bool) (r []message.
|
|||||||
ReplySeq: int32(0),
|
ReplySeq: int32(0),
|
||||||
Sender: sender,
|
Sender: sender,
|
||||||
Time: int32(msgTime),
|
Time: int32(msgTime),
|
||||||
Elements: bot.ConvertStringMessage(customText, group),
|
Elements: bot.ConvertStringMessage(customText, isGroup),
|
||||||
},
|
},
|
||||||
}, r...)
|
}, r...)
|
||||||
return
|
return
|
||||||
@ -531,9 +547,9 @@ func (bot *CQBot) ConvertObjectMessage(m gjson.Result, group bool) (r []message.
|
|||||||
d[key.Str] = value.String()
|
d[key.Str] = value.String()
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
elem, err := bot.ToElement(t, d, group)
|
elem, err := bot.ToElement(t, d, isGroup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("转换CQ码到MiraiGo Element时出现错误: %v 将忽略本段CQ码.", err)
|
log.Warnf("转换CQ码 (%v) 到MiraiGo Element时出现错误: %v 将忽略本段CQ码.", e.Raw, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch i := elem.(type) {
|
switch i := elem.(type) {
|
||||||
@ -544,7 +560,7 @@ func (bot *CQBot) ConvertObjectMessage(m gjson.Result, group bool) (r []message.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if m.Type == gjson.String {
|
if m.Type == gjson.String {
|
||||||
return bot.ConvertStringMessage(m.Str, group)
|
return bot.ConvertStringMessage(m.Str, isGroup)
|
||||||
}
|
}
|
||||||
if m.IsArray() {
|
if m.IsArray() {
|
||||||
for _, e := range m.Array() {
|
for _, e := range m.Array() {
|
||||||
@ -558,12 +574,14 @@ func (bot *CQBot) ConvertObjectMessage(m gjson.Result, group bool) (r []message.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ToElement 将解码后的CQCode转换为Element.
|
// ToElement 将解码后的CQCode转换为Element.
|
||||||
|
//
|
||||||
// 返回 interface{} 存在三种类型
|
// 返回 interface{} 存在三种类型
|
||||||
|
//
|
||||||
// message.IMessageElement []message.IMessageElement nil
|
// message.IMessageElement []message.IMessageElement nil
|
||||||
func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interface{}, err error) {
|
func (bot *CQBot) ToElement(t string, d map[string]string, isGroup bool) (m interface{}, err error) {
|
||||||
switch t {
|
switch t {
|
||||||
case "text":
|
case "text":
|
||||||
if SplitUrl {
|
if SplitURL {
|
||||||
var ret []message.IMessageElement
|
var ret []message.IMessageElement
|
||||||
for _, text := range global.SplitURL(d["text"]) {
|
for _, text := range global.SplitURL(d["text"]) {
|
||||||
ret = append(ret, message.NewText(text))
|
ret = append(ret, message.NewText(text))
|
||||||
@ -572,7 +590,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
|
|||||||
}
|
}
|
||||||
return message.NewText(d["text"]), nil
|
return message.NewText(d["text"]), nil
|
||||||
case "image":
|
case "image":
|
||||||
img, err := bot.makeImageOrVideoElem(d, false, group)
|
img, err := bot.makeImageOrVideoElem(d, false, isGroup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -581,7 +599,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
|
|||||||
return img, nil
|
return img, nil
|
||||||
}
|
}
|
||||||
if i, ok := img.(*LocalImageElement); ok { // 秀图,闪照什么的就直接传了吧
|
if i, ok := img.(*LocalImageElement); ok { // 秀图,闪照什么的就直接传了吧
|
||||||
if group {
|
if isGroup {
|
||||||
img, err = bot.UploadLocalImageAsGroup(1, i)
|
img, err = bot.UploadLocalImageAsGroup(1, i)
|
||||||
} else {
|
} else {
|
||||||
img, err = bot.UploadLocalImageAsPrivate(1, i)
|
img, err = bot.UploadLocalImageAsPrivate(1, i)
|
||||||
@ -613,7 +631,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
|
|||||||
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":
|
||||||
if !group {
|
if !isGroup {
|
||||||
return nil, errors.New("private gift unsupported") // no free private gift
|
return nil, errors.New("private gift unsupported") // no free private gift
|
||||||
}
|
}
|
||||||
t, _ := strconv.ParseInt(d["qq"], 10, 64)
|
t, _ := strconv.ParseInt(d["qq"], 10, 64)
|
||||||
@ -621,7 +639,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
|
|||||||
if id < 0 || id >= 14 {
|
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
|
||||||
case "tts":
|
case "tts":
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
@ -679,7 +697,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
|
|||||||
mid := info.Get("track_info.mid").Str
|
mid := info.Get("track_info.mid").Str
|
||||||
albumMid := info.Get("track_info.album.mid").Str
|
albumMid := info.Get("track_info.album.mid").Str
|
||||||
pinfo, _ := global.GetBytes("http://u.y.qq.com/cgi-bin/musicu.fcg?g_tk=2034008533&uin=0&format=json&data={\"comm\":{\"ct\":23,\"cv\":0},\"url_mid\":{\"module\":\"vkey.GetVkeyServer\",\"method\":\"CgiGetVkey\",\"param\":{\"guid\":\"4311206557\",\"songmid\":[\"" + mid + "\"],\"songtype\":[0],\"uin\":\"0\",\"loginflag\":1,\"platform\":\"23\"}}}&_=1599039471576")
|
pinfo, _ := global.GetBytes("http://u.y.qq.com/cgi-bin/musicu.fcg?g_tk=2034008533&uin=0&format=json&data={\"comm\":{\"ct\":23,\"cv\":0},\"url_mid\":{\"module\":\"vkey.GetVkeyServer\",\"method\":\"CgiGetVkey\",\"param\":{\"guid\":\"4311206557\",\"songmid\":[\"" + mid + "\"],\"songtype\":[0],\"uin\":\"0\",\"loginflag\":1,\"platform\":\"23\"}}}&_=1599039471576")
|
||||||
jumpUrl := "https://i.y.qq.com/v8/playsong.html?platform=11&appshare=android_qq&appversion=10030010&hosteuin=oKnlNenz7i-s7c**&songmid=" + mid + "&type=0&appsongtype=1&_wv=1&source=qq&ADTAG=qfshare"
|
jumpURL := "https://i.y.qq.com/v8/playsong.html?platform=11&appshare=android_qq&appversion=10030010&hosteuin=oKnlNenz7i-s7c**&songmid=" + mid + "&type=0&appsongtype=1&_wv=1&source=qq&ADTAG=qfshare"
|
||||||
purl := gjson.ParseBytes(pinfo).Get("url_mid.data.midurlinfo.0.purl").Str
|
purl := gjson.ParseBytes(pinfo).Get("url_mid.data.midurlinfo.0.purl").Str
|
||||||
preview := "http://y.gtimg.cn/music/photo_new/T002R180x180M000" + albumMid + ".jpg"
|
preview := "http://y.gtimg.cn/music/photo_new/T002R180x180M000" + albumMid + ".jpg"
|
||||||
if len(aid) < 2 {
|
if len(aid) < 2 {
|
||||||
@ -693,7 +711,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
|
|||||||
MusicType: message.QQMusic,
|
MusicType: message.QQMusic,
|
||||||
Title: name,
|
Title: name,
|
||||||
Summary: content,
|
Summary: content,
|
||||||
Url: jumpUrl,
|
Url: jumpURL,
|
||||||
PictureUrl: preview,
|
PictureUrl: preview,
|
||||||
MusicUrl: purl,
|
MusicUrl: purl,
|
||||||
}, nil
|
}, nil
|
||||||
@ -707,9 +725,9 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
|
|||||||
return nil, errors.New("song not found")
|
return nil, errors.New("song not found")
|
||||||
}
|
}
|
||||||
name := info.Get("name").Str
|
name := info.Get("name").Str
|
||||||
jumpUrl := "https://y.music.163.com/m/song/" + d["id"]
|
jumpURL := "https://y.music.163.com/m/song/" + d["id"]
|
||||||
musicUrl := "http://music.163.com/song/media/outer/url?id=" + d["id"]
|
musicURL := "http://music.163.com/song/media/outer/url?id=" + d["id"]
|
||||||
picUrl := info.Get("album.picUrl").Str
|
picURL := info.Get("album.picUrl").Str
|
||||||
artistName := ""
|
artistName := ""
|
||||||
if info.Get("artists.0").Exists() {
|
if info.Get("artists.0").Exists() {
|
||||||
artistName = info.Get("artists.0.name").Str
|
artistName = info.Get("artists.0.name").Str
|
||||||
@ -718,9 +736,9 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
|
|||||||
MusicType: message.CloudMusic,
|
MusicType: message.CloudMusic,
|
||||||
Title: name,
|
Title: name,
|
||||||
Summary: artistName,
|
Summary: artistName,
|
||||||
Url: jumpUrl,
|
Url: jumpURL,
|
||||||
PictureUrl: picUrl,
|
PictureUrl: picURL,
|
||||||
MusicUrl: musicUrl,
|
MusicUrl: musicURL,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
if d["type"] == "custom" {
|
if d["type"] == "custom" {
|
||||||
@ -746,7 +764,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
|
|||||||
}, 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>`,
|
||||||
XmlEscape(d["title"]), d["url"], d["image"], d["audio"], XmlEscape(d["title"]), XmlEscape(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,
|
||||||
@ -755,21 +773,21 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
|
|||||||
}
|
}
|
||||||
return nil, errors.New("unsupported music type: " + d["type"])
|
return nil, errors.New("unsupported music type: " + d["type"])
|
||||||
case "xml":
|
case "xml":
|
||||||
resId := d["resid"]
|
resID := d["resid"]
|
||||||
template := CQCodeEscapeValue(d["data"])
|
template := CQCodeEscapeValue(d["data"])
|
||||||
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)
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
// 默认情况下走小程序通道
|
// 默认情况下走小程序通道
|
||||||
msg := message.NewLightApp(CQCodeUnescapeValue(d["data"]))
|
msg := message.NewLightApp(d["data"])
|
||||||
return msg, nil
|
return msg, nil
|
||||||
}
|
}
|
||||||
// resid不为0的情况下走富文本通道,后续补全透传service Id,此处暂时不处理 TODO
|
// resid不为0的情况下走富文本通道,后续补全透传service Id,此处暂时不处理 TODO
|
||||||
msg := message.NewRichJson(CQCodeUnescapeValue(d["data"]))
|
msg := message.NewRichJson(d["data"])
|
||||||
return msg, nil
|
return msg, nil
|
||||||
case "cardimage":
|
case "cardimage":
|
||||||
source := d["source"]
|
source := d["source"]
|
||||||
@ -790,17 +808,17 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
|
|||||||
if maxHeight == 0 {
|
if maxHeight == 0 {
|
||||||
maxHeight = 1000
|
maxHeight = 1000
|
||||||
}
|
}
|
||||||
img, err := bot.makeImageOrVideoElem(d, false, group)
|
img, err := bot.makeImageOrVideoElem(d, false, isGroup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("send cardimage faild")
|
return nil, errors.New("send cardimage faild")
|
||||||
}
|
}
|
||||||
return bot.makeShowPic(img, source, icon, minWidth, minHeight, maxWidth, maxHeight, group)
|
return bot.makeShowPic(img, source, icon, minWidth, minHeight, maxWidth, maxHeight, isGroup)
|
||||||
case "video":
|
case "video":
|
||||||
cache := d["cache"]
|
cache := d["cache"]
|
||||||
if cache == "" {
|
if cache == "" {
|
||||||
cache = "1"
|
cache = "1"
|
||||||
}
|
}
|
||||||
file, err := bot.makeImageOrVideoElem(d, true, group)
|
file, err := bot.makeImageOrVideoElem(d, true, isGroup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -848,12 +866,22 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func XmlEscape(c string) string {
|
// XMLEscape 将字符串c转义为XML字符串
|
||||||
|
func XMLEscape(c string) string {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
_ = xml2.EscapeText(buf, []byte(c))
|
_ = xml2.EscapeText(buf, []byte(c))
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*CQCodeEscapeText 将字符串raw中部分字符转义
|
||||||
|
|
||||||
|
& -> &
|
||||||
|
|
||||||
|
[ -> [
|
||||||
|
|
||||||
|
] -> ]
|
||||||
|
|
||||||
|
*/
|
||||||
func CQCodeEscapeText(raw string) string {
|
func CQCodeEscapeText(raw string) string {
|
||||||
ret := raw
|
ret := raw
|
||||||
ret = strings.ReplaceAll(ret, "&", "&")
|
ret = strings.ReplaceAll(ret, "&", "&")
|
||||||
@ -862,12 +890,32 @@ func CQCodeEscapeText(raw string) string {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*CQCodeEscapeValue 将字符串value中部分字符转义
|
||||||
|
|
||||||
|
, -> ,
|
||||||
|
|
||||||
|
& -> &
|
||||||
|
|
||||||
|
[ -> [
|
||||||
|
|
||||||
|
] -> ]
|
||||||
|
|
||||||
|
*/
|
||||||
func CQCodeEscapeValue(value string) string {
|
func CQCodeEscapeValue(value string) string {
|
||||||
ret := CQCodeEscapeText(value)
|
ret := CQCodeEscapeText(value)
|
||||||
ret = strings.ReplaceAll(ret, ",", ",")
|
ret = strings.ReplaceAll(ret, ",", ",")
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*CQCodeUnescapeText 将字符串content中部分字符反转义
|
||||||
|
|
||||||
|
& -> &
|
||||||
|
|
||||||
|
[ -> [
|
||||||
|
|
||||||
|
] -> ]
|
||||||
|
|
||||||
|
*/
|
||||||
func CQCodeUnescapeText(content string) string {
|
func CQCodeUnescapeText(content string) string {
|
||||||
ret := content
|
ret := content
|
||||||
ret = strings.ReplaceAll(ret, "[", "[")
|
ret = strings.ReplaceAll(ret, "[", "[")
|
||||||
@ -876,13 +924,24 @@ func CQCodeUnescapeText(content string) string {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*CQCodeUnescapeValue 将字符串content中部分字符反转义
|
||||||
|
|
||||||
|
, -> ,
|
||||||
|
|
||||||
|
& -> &
|
||||||
|
|
||||||
|
[ -> [
|
||||||
|
|
||||||
|
] -> ]
|
||||||
|
|
||||||
|
*/
|
||||||
func CQCodeUnescapeValue(content string) string {
|
func CQCodeUnescapeValue(content string) string {
|
||||||
ret := strings.ReplaceAll(content, ",", ",")
|
ret := strings.ReplaceAll(content, ",", ",")
|
||||||
ret = CQCodeUnescapeText(ret)
|
ret = CQCodeUnescapeText(ret)
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// 图片 elem 生成器,单独拎出来,用于公用
|
// makeImageOrVideoElem 图片 elem 生成器,单独拎出来,用于公用
|
||||||
func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (message.IMessageElement, error) {
|
func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (message.IMessageElement, error) {
|
||||||
f := d["file"]
|
f := d["file"]
|
||||||
if strings.HasPrefix(f, "http") || strings.HasPrefix(f, "https") {
|
if strings.HasPrefix(f, "http") || strings.HasPrefix(f, "https") {
|
||||||
@ -958,9 +1017,8 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
|
|||||||
Name: r.ReadString(),
|
Name: r.ReadString(),
|
||||||
Uuid: r.ReadAvailable(),
|
Uuid: r.ReadAvailable(),
|
||||||
}}, nil
|
}}, nil
|
||||||
} else {
|
|
||||||
return &LocalVideoElement{File: rawPath}, nil
|
|
||||||
}
|
}
|
||||||
|
return &LocalVideoElement{File: rawPath}, nil
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(f, "base64") {
|
if strings.HasPrefix(f, "base64") {
|
||||||
b, err := base64.StdEncoding.DecodeString(strings.ReplaceAll(f, "base64://", ""))
|
b, err := base64.StdEncoding.DecodeString(strings.ReplaceAll(f, "base64://", ""))
|
||||||
|
2
coolq/doc.go
Normal file
2
coolq/doc.go
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// Package coolq 包含CQBot实例,CQ码处理,消息发送,消息处理等的相关函数与结构体
|
||||||
|
package coolq
|
@ -23,11 +23,11 @@ func SetMessageFormat(f string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ToFormattedMessage 将给定[]message.IMessageElement转换为通过coolq.SetMessageFormat所定义的消息上报格式
|
// ToFormattedMessage 将给定[]message.IMessageElement转换为通过coolq.SetMessageFormat所定义的消息上报格式
|
||||||
func ToFormattedMessage(e []message.IMessageElement, id int64, raw ...bool) (r interface{}) {
|
func ToFormattedMessage(e []message.IMessageElement, id int64, isRaw ...bool) (r interface{}) {
|
||||||
if format == "string" {
|
if format == "string" {
|
||||||
r = ToStringMessage(e, id, raw...)
|
r = ToStringMessage(e, id, isRaw...)
|
||||||
} else if format == "array" {
|
} else if format == "array" {
|
||||||
r = ToArrayMessage(e, id, raw...)
|
r = ToArrayMessage(e, id, isRaw...)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ func (bot *CQBot) groupMutedEvent(c *client.QQClient, e *client.GroupMuteEvent)
|
|||||||
|
|
||||||
func (bot *CQBot) groupRecallEvent(c *client.QQClient, e *client.GroupMessageRecalledEvent) {
|
func (bot *CQBot) groupRecallEvent(c *client.QQClient, e *client.GroupMessageRecalledEvent) {
|
||||||
g := c.FindGroup(e.GroupCode)
|
g := c.FindGroup(e.GroupCode)
|
||||||
gid := ToGlobalId(e.GroupCode, e.MessageId)
|
gid := toGlobalID(e.GroupCode, e.MessageId)
|
||||||
log.Infof("群 %v 内 %v 撤回了 %v 的消息: %v.",
|
log.Infof("群 %v 内 %v 撤回了 %v 的消息: %v.",
|
||||||
formatGroupName(g), formatMemberName(g.FindMember(e.OperatorUin)), formatMemberName(g.FindMember(e.AuthorUin)), gid)
|
formatGroupName(g), formatMemberName(g.FindMember(e.OperatorUin)), formatMemberName(g.FindMember(e.AuthorUin)), gid)
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(MSG{
|
||||||
@ -258,7 +258,7 @@ func (bot *CQBot) friendNotifyEvent(c *client.QQClient, e client.INotifyEvent) {
|
|||||||
|
|
||||||
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)
|
||||||
if f != nil {
|
if f != nil {
|
||||||
log.Infof("好友 %v(%v) 撤回了消息: %v", f.Nickname, f.Uin, gid)
|
log.Infof("好友 %v(%v) 撤回了消息: %v", f.Nickname, f.Uin, gid)
|
||||||
} else {
|
} else {
|
||||||
@ -431,7 +431,47 @@ func (bot *CQBot) otherClientStatusChangedEvent(c *client.QQClient, e *client.Ot
|
|||||||
"self_id": c.Uin,
|
"self_id": c.Uin,
|
||||||
"time": time.Now().Unix(),
|
"time": time.Now().Unix(),
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bot *CQBot) groupEssenceMsg(c *client.QQClient, e *client.GroupDigestEvent) {
|
||||||
|
g := c.FindGroup(e.GroupCode)
|
||||||
|
gid := toGlobalID(e.GroupCode, e.MessageID)
|
||||||
|
if e.OperationType == 1 {
|
||||||
|
log.Infof(
|
||||||
|
"群 %v 内 %v 将 %v 的消息(%v)设为了精华消息.",
|
||||||
|
formatGroupName(g),
|
||||||
|
formatMemberName(g.FindMember(e.OperatorUin)),
|
||||||
|
formatMemberName(g.FindMember(e.SenderUin)),
|
||||||
|
gid,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
log.Infof(
|
||||||
|
"群 %v 内 %v 将 %v 的消息(%v)移出了精华消息.",
|
||||||
|
formatGroupName(g),
|
||||||
|
formatMemberName(g.FindMember(e.OperatorUin)),
|
||||||
|
formatMemberName(g.FindMember(e.SenderUin)),
|
||||||
|
gid,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if e.OperatorUin == bot.Client.Uin {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
bot.dispatchEventMessage(MSG{
|
||||||
|
"post_type": "notice",
|
||||||
|
"group_id": e.GroupCode,
|
||||||
|
"notice_type": "essence",
|
||||||
|
"sub_type": func() string {
|
||||||
|
if e.OperationType == 1 {
|
||||||
|
return "add"
|
||||||
|
}
|
||||||
|
return "delete"
|
||||||
|
}(),
|
||||||
|
"self_id": c.Uin,
|
||||||
|
"sender_id": e.SenderUin,
|
||||||
|
"operator_id": e.OperatorUin,
|
||||||
|
"time": time.Now().Unix(),
|
||||||
|
"message_id": gid,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bot *CQBot) groupIncrease(groupCode, operatorUin, userUin int64) MSG {
|
func (bot *CQBot) groupIncrease(groupCode, operatorUin, userUin int64) MSG {
|
||||||
|
162
docs/cqhttp.md
162
docs/cqhttp.md
@ -26,9 +26,9 @@
|
|||||||
- [获取图片信息](#获取图片信息)
|
- [获取图片信息](#获取图片信息)
|
||||||
- [获取消息](#获取消息)
|
- [获取消息](#获取消息)
|
||||||
- [获取合并转发内容](#获取合并转发内容)
|
- [获取合并转发内容](#获取合并转发内容)
|
||||||
- [发送合并转发(群)](#发送合并转发(群))
|
- [发送合并转发(群)](#发送合并转发群)
|
||||||
- [获取中文分词](#获取中文分词)
|
- [获取中文分词](#获取中文分词)
|
||||||
- [图片OCR](#图片OCR)
|
- [图片OCR](#图片ocr)
|
||||||
- [获取中文分词](#获取中文分词)
|
- [获取中文分词](#获取中文分词)
|
||||||
- [获取群系统消息](#获取群文件系统信息)
|
- [获取群系统消息](#获取群文件系统信息)
|
||||||
- [获取群文件系统信息](#获取群文件系统信息)
|
- [获取群文件系统信息](#获取群文件系统信息)
|
||||||
@ -36,9 +36,15 @@
|
|||||||
- [获取群子目录文件列表](#获取群子目录文件列表)
|
- [获取群子目录文件列表](#获取群子目录文件列表)
|
||||||
- [获取群文件资源链接](#获取群文件资源链接)
|
- [获取群文件资源链接](#获取群文件资源链接)
|
||||||
- [获取状态](#获取状态)
|
- [获取状态](#获取状态)
|
||||||
- [获取群子目录文件列表](#设置群名)
|
- [获取群@全体成员剩余次数](#获取群全体成员剩余次数)
|
||||||
- [获取用户VIP信息](#获取用户VIP信息)
|
- [下载文件到缓存目录](#下载文件到缓存目录)
|
||||||
|
- [获取群消息历史记录](#获取群消息历史记录)
|
||||||
|
- [设置群名](#设置群名)
|
||||||
|
- [获取用户VIP信息](#获取用户vip信息)
|
||||||
- [发送群公告](#发送群公告)
|
- [发送群公告](#发送群公告)
|
||||||
|
- [设置精华消息](#设置精华消息)
|
||||||
|
- [移出精华消息](#移出精华消息)
|
||||||
|
- [获取精华消息列表](#获取精华消息列表)
|
||||||
- [重载事件过滤器](#重载事件过滤器)
|
- [重载事件过滤器](#重载事件过滤器)
|
||||||
|
|
||||||
##### 事件
|
##### 事件
|
||||||
@ -50,6 +56,7 @@
|
|||||||
- [群成员荣誉变更提示](#群成员荣誉变更提示)
|
- [群成员荣誉变更提示](#群成员荣誉变更提示)
|
||||||
- [群成员名片更新](#群成员名片更新)
|
- [群成员名片更新](#群成员名片更新)
|
||||||
- [接收到离线文件](#接收到离线文件)
|
- [接收到离线文件](#接收到离线文件)
|
||||||
|
- [群精华消息](#精华消息)
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
</details>
|
</details>
|
||||||
@ -65,7 +72,7 @@ Type : `image`
|
|||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 可能的值 | 说明 |
|
| 参数名 | 可能的值 | 说明 |
|
||||||
| ------- | --------------- | --------------------------------------------------------------- |
|
| ------- | --------------- | ---------------------------------------------------------------------- |
|
||||||
| `file` | - | 图片文件名 |
|
| `file` | - | 图片文件名 |
|
||||||
| `type` | `flash`,`show` | 图片类型,`flash` 表示闪照,`show` 表示秀图,默认普通图片 |
|
| `type` | `flash`,`show` | 图片类型,`flash` 表示闪照,`show` 表示秀图,默认普通图片 |
|
||||||
| `url` | - | 图片 URL |
|
| `url` | - | 图片 URL |
|
||||||
@ -99,11 +106,11 @@ Type : `reply`
|
|||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------ | ---- | ------------------------------------- |
|
| ------ | ------ | --------------------------------------------------- |
|
||||||
| `id` | int | 回复时所引用的消息id, 必须为本群消息. |
|
| `id` | int | 回复时所引用的消息id, 必须为本群消息. |
|
||||||
| `text` | string | 自定义回复的信息 |
|
| `text` | string | 自定义回复的信息 |
|
||||||
| `qq` | int64 | 自定义回复时的自定义QQ, 如果使用自定义信息必须指定. |
|
| `qq` | int64 | 自定义回复时的自定义QQ, 如果使用自定义信息必须指定. |
|
||||||
| `time` | int64 | 自定义回复时的时间, 格式为Unix时间 |
|
| `time` | int64 | 可选. 自定义回复时的时间, 格式为Unix时间 |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -128,7 +135,7 @@ Type : `reply`
|
|||||||
```
|
```
|
||||||
|
|
||||||
| 参数名 | 收 | 发 | 可能的值 | 说明 |
|
| 参数名 | 收 | 发 | 可能的值 | 说明 |
|
||||||
| --- | --- | --- | --- | --- |
|
| ------ | --- | --- | ---------- | -------------------------------- |
|
||||||
| `type` | | ✓ | `qq` `163` | 分别表示使用 QQ 音乐、网易云音乐 |
|
| `type` | | ✓ | `qq` `163` | 分别表示使用 QQ 音乐、网易云音乐 |
|
||||||
| `id` | | ✓ | - | 歌曲 ID |
|
| `id` | | ✓ | - | 歌曲 ID |
|
||||||
|
|
||||||
@ -151,7 +158,7 @@ Type : `reply`
|
|||||||
```
|
```
|
||||||
|
|
||||||
| 参数名 | 收 | 发 | 可能的值 | 说明 |
|
| 参数名 | 收 | 发 | 可能的值 | 说明 |
|
||||||
| --- | --- | --- | --- | --- |
|
| --------- | --- | --- | ------------------------ | ----------------------------------------------------- |
|
||||||
| `type` | | ✓ | `custom` | 表示音乐自定义分享 |
|
| `type` | | ✓ | `custom` | 表示音乐自定义分享 |
|
||||||
| `subtype` | | ✓ | `qq,163,migu,kugou,kuwo` | 表示分享类型,不填写发送为xml卡片,推荐填写提高稳定性 |
|
| `subtype` | | ✓ | `qq,163,migu,kugou,kuwo` | 表示分享类型,不填写发送为xml卡片,推荐填写提高稳定性 |
|
||||||
| `url` | | ✓ | - | 点击后跳转目标 URL |
|
| `url` | | ✓ | - | 点击后跳转目标 URL |
|
||||||
@ -237,7 +244,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]`
|
||||||
@ -251,7 +258,7 @@ Type: `node`
|
|||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 | 特殊说明 |
|
| 参数名 | 类型 | 说明 | 特殊说明 |
|
||||||
| --------- | ------- | -------------- | ------------------------------------------------------------ |
|
| --------- | ------- | -------------- | -------------------------------------------------------------------------------------- |
|
||||||
| `id` | int32 | 转发消息id | 直接引用他人的消息合并转发, 实际查看顺序为原消息发送顺序 **与下面的自定义消息二选一** |
|
| `id` | int32 | 转发消息id | 直接引用他人的消息合并转发, 实际查看顺序为原消息发送顺序 **与下面的自定义消息二选一** |
|
||||||
| `name` | string | 发送者显示名字 | 用于自定义消息 (自定义消息并合并转发,实际查看顺序为自定义消息段顺序) |
|
| `name` | string | 发送者显示名字 | 用于自定义消息 (自定义消息并合并转发,实际查看顺序为自定义消息段顺序) |
|
||||||
| `uin` | int64 | 发送者QQ号 | 用于自定义消息 |
|
| `uin` | int64 | 发送者QQ号 | 用于自定义消息 |
|
||||||
@ -338,7 +345,7 @@ Type: `video`
|
|||||||
参数:
|
参数:
|
||||||
|
|
||||||
| 参数名 | 类型 | 说明 |
|
| 参数名 | 类型 | 说明 |
|
||||||
| ------- | ------ | ------------------------------------------------|
|
| ------- | ------- | ---------------------------------------------------------------------- |
|
||||||
| `file` | string | 支持http和file发送 |
|
| `file` | string | 支持http和file发送 |
|
||||||
| `cover` | string | 视频封面,支持http,file和base64发送,格式必须为jpg |
|
| `cover` | string | 视频封面,支持http,file和base64发送,格式必须为jpg |
|
||||||
| `c` | `2` `3` | 通过网络下载视频时的线程数, 默认单线程. (在资源不支持并发时会自动处理) |
|
| `c` | `2` `3` | 通过网络下载视频时的线程数, 默认单线程. (在资源不支持并发时会自动处理) |
|
||||||
@ -560,7 +567,7 @@ Type: `tts`
|
|||||||
|
|
||||||
响应示例
|
响应示例
|
||||||
|
|
||||||
````json
|
````json5
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"messages": [
|
"messages": [
|
||||||
@ -578,7 +585,7 @@ Type: `tts`
|
|||||||
"nickname": "发送者B",
|
"nickname": "发送者B",
|
||||||
"user_id": 10087
|
"user_id": 10087
|
||||||
},
|
},
|
||||||
"time": 1595694393
|
"time": 1595694393 // 可选
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -620,11 +627,63 @@ Type: `tts`
|
|||||||
| -------- | -------- | ---- |
|
| -------- | -------- | ---- |
|
||||||
| `slices` | string[] | 词组 |
|
| `slices` | string[] | 词组 |
|
||||||
|
|
||||||
|
### 设置精华消息
|
||||||
|
|
||||||
|
终结点: `/set_essence_msg`
|
||||||
|
|
||||||
|
**参数**
|
||||||
|
|
||||||
|
| 字段 | 类型 | 说明 |
|
||||||
|
| ------------ | ----- | ------ |
|
||||||
|
| `message_id` | int32 | 消息ID |
|
||||||
|
|
||||||
|
**响应数据**
|
||||||
|
|
||||||
|
无
|
||||||
|
|
||||||
|
### 移出精华消息
|
||||||
|
|
||||||
|
终结点: `/delete_essence_msg`
|
||||||
|
|
||||||
|
**参数**
|
||||||
|
|
||||||
|
| 字段 | 类型 | 说明 |
|
||||||
|
| ------------ | ----- | ------ |
|
||||||
|
| `message_id` | int32 | 消息ID |
|
||||||
|
|
||||||
|
**响应数据**
|
||||||
|
|
||||||
|
无
|
||||||
|
|
||||||
|
### 获取精华消息列表
|
||||||
|
|
||||||
|
终结点: `/get_essence_msg_list`
|
||||||
|
|
||||||
|
**参数**
|
||||||
|
|
||||||
|
| 字段 | 类型 | 说明 |
|
||||||
|
| ---------- | ----- | ---- |
|
||||||
|
| `group_id` | int64 | 群号 |
|
||||||
|
|
||||||
|
**响应数据**
|
||||||
|
|
||||||
|
响应内容为 JSON 数组,每个元素如下:
|
||||||
|
|
||||||
|
| 字段名 | 数据类型 | 说明 |
|
||||||
|
| --------------- | -------- | ------------ |
|
||||||
|
| `sender_id` | int64 | 发送者QQ 号 |
|
||||||
|
| `sender_nick` | string | 发送者昵称 |
|
||||||
|
| `sender_time` | int64 | 消息发送时间 |
|
||||||
|
| `operator_id` | int64 | 操作者QQ 号 |
|
||||||
|
| `operator_nick` | string | 操作者昵称 |
|
||||||
|
| `operator_time` | int64 | 精华设置时间 |
|
||||||
|
| `message_id` | int32 | 消息ID |
|
||||||
|
|
||||||
### 图片OCR
|
### 图片OCR
|
||||||
|
|
||||||
> 注意: 目前图片OCR接口仅支持接受的图片
|
> 注意: 目前图片OCR接口仅支持接受的图片
|
||||||
|
|
||||||
终结点: `/.ocr_image`
|
终结点: `/ocr_image`
|
||||||
|
|
||||||
**参数**
|
**参数**
|
||||||
|
|
||||||
@ -790,6 +849,22 @@ Type: `tts`
|
|||||||
| `creator_name` | string | 创建者名字 |
|
| `creator_name` | string | 创建者名字 |
|
||||||
| `total_file_count` | int32 | 子文件数量 |
|
| `total_file_count` | int32 | 子文件数量 |
|
||||||
|
|
||||||
|
### 上传群文件
|
||||||
|
|
||||||
|
终结点: `/upload_group_file`
|
||||||
|
|
||||||
|
**参数**
|
||||||
|
|
||||||
|
| 字段 | 类型 | 说明 |
|
||||||
|
| ---------- | ------ | ------------------------- |
|
||||||
|
| `group_id` | int64 | 群号 |
|
||||||
|
| `file` | string | 本地文件路径 |
|
||||||
|
| `name` | string | 储存名称 |
|
||||||
|
| `folder` | string | 父目录ID |
|
||||||
|
|
||||||
|
> 在不提供 `folder` 参数的情况下默认上传到根目录
|
||||||
|
> 只能上传本地文件, 需要上传 `http` 文件的话请先调用 `download_file` API下载
|
||||||
|
|
||||||
### 获取状态
|
### 获取状态
|
||||||
|
|
||||||
终结点: `/get_status`
|
终结点: `/get_status`
|
||||||
@ -828,13 +903,13 @@ Type: `tts`
|
|||||||
**参数**
|
**参数**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ------ | ------------------------- |
|
| ---------- | ----- | ---- |
|
||||||
| `group_id` | int64 | 群号 |
|
| `group_id` | int64 | 群号 |
|
||||||
|
|
||||||
**响应数据**
|
**响应数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ------------------------------- | ---------- | ------------------------------- |
|
| ------------------------------- | ----- | --------------------------------- |
|
||||||
| `can_at_all` | bool | 是否可以@全体成员 |
|
| `can_at_all` | bool | 是否可以@全体成员 |
|
||||||
| `remain_at_all_count_for_group` | int16 | 群内所有管理当天剩余@全体成员次数 |
|
| `remain_at_all_count_for_group` | int16 | 群内所有管理当天剩余@全体成员次数 |
|
||||||
| `remain_at_all_count_for_uin` | int16 | BOT当天剩余@全体成员次数 |
|
| `remain_at_all_count_for_uin` | int16 | BOT当天剩余@全体成员次数 |
|
||||||
@ -846,7 +921,7 @@ Type: `tts`
|
|||||||
**参数**
|
**参数**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ------ | ------------------------- |
|
| -------------- | --------------- | ------------ |
|
||||||
| `url` | string | 链接地址 |
|
| `url` | string | 链接地址 |
|
||||||
| `thread_count` | int32 | 下载线程数 |
|
| `thread_count` | int32 | 下载线程数 |
|
||||||
| `headers` | string or array | 自定义请求头 |
|
| `headers` | string or array | 自定义请求头 |
|
||||||
@ -873,7 +948,7 @@ JSON数组:
|
|||||||
**响应数据**
|
**响应数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ---------- | ------------ |
|
| ------ | ------ | -------------------- |
|
||||||
| `file` | string | 下载文件的*绝对路径* |
|
| `file` | string | 下载文件的*绝对路径* |
|
||||||
|
|
||||||
> 通过这个API下载的文件能直接放入CQ码作为图片或语音发送
|
> 通过这个API下载的文件能直接放入CQ码作为图片或语音发送
|
||||||
@ -886,14 +961,14 @@ JSON数组:
|
|||||||
**参数**
|
**参数**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ------ | ------------------------- |
|
| ------------- | ----- | ----------------------------------- |
|
||||||
| `message_seq` | int64 | 起始消息序号, 可通过 `get_msg` 获得 |
|
| `message_seq` | int64 | 起始消息序号, 可通过 `get_msg` 获得 |
|
||||||
| `group_id` | int64 | 群号 |
|
| `group_id` | int64 | 群号 |
|
||||||
|
|
||||||
**响应数据**
|
**响应数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ---------- | ------------ |
|
| ---------- | --------- | -------------------------- |
|
||||||
| `messages` | []Message | 从起始序号开始的前19条消息 |
|
| `messages` | []Message | 从起始序号开始的前19条消息 |
|
||||||
|
|
||||||
> 不提供起始序号将默认获取最新的消息
|
> 不提供起始序号将默认获取最新的消息
|
||||||
@ -905,23 +980,39 @@ JSON数组:
|
|||||||
**参数**
|
**参数**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ------ | ------------------------- |
|
| ---------- | ---- | ------------ |
|
||||||
| `no_cache` | bool | 是否无视缓存 |
|
| `no_cache` | bool | 是否无视缓存 |
|
||||||
|
|
||||||
**响应数据**
|
**响应数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ---------- | ------------ |
|
| --------- | -------- | -------------- |
|
||||||
| `clients` | []Device | 在线客户端列表 |
|
| `clients` | []Device | 在线客户端列表 |
|
||||||
|
|
||||||
**Device**
|
**Device**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ---------- | ---------- | ------------ |
|
| ------------- | ------ | -------- |
|
||||||
| `app_id` | int64 | 客户端ID |
|
| `app_id` | int64 | 客户端ID |
|
||||||
| `device_name` | string | 设备名称 |
|
| `device_name` | string | 设备名称 |
|
||||||
| `device_kind` | string | 设备类型 |
|
| `device_kind` | string | 设备类型 |
|
||||||
|
|
||||||
|
### 检查链接安全性
|
||||||
|
|
||||||
|
终结点:`/check_url_safely`
|
||||||
|
|
||||||
|
**参数**
|
||||||
|
|
||||||
|
| 字段 | 类型 | 说明 |
|
||||||
|
| ---------- | ------ | ------------------------- |
|
||||||
|
| `url` | string | 需要检查的链接 |
|
||||||
|
|
||||||
|
**响应数据**
|
||||||
|
|
||||||
|
| 字段 | 类型 | 说明 |
|
||||||
|
| ---------- | ---------- | ------------ |
|
||||||
|
| `level` | int | 安全等级, 1: 安全 2: 未知 3: 危险 |
|
||||||
|
|
||||||
### 获取用户VIP信息
|
### 获取用户VIP信息
|
||||||
|
|
||||||
终结点:`/_get_vip_info`
|
终结点:`/_get_vip_info`
|
||||||
@ -929,13 +1020,13 @@ JSON数组:
|
|||||||
**参数**
|
**参数**
|
||||||
|
|
||||||
| 字段名 | 数据类型 | 默认值 | 说明 |
|
| 字段名 | 数据类型 | 默认值 | 说明 |
|
||||||
| ----- | ------- | ----- | --- |
|
| --------- | -------- | ------ | ----- |
|
||||||
| `user_id` | int64 | | QQ 号 |
|
| `user_id` | int64 | | QQ 号 |
|
||||||
|
|
||||||
**响应数据**
|
**响应数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 说明 |
|
| 字段 | 类型 | 说明 |
|
||||||
| ------------------ | ------- | ---------- |
|
| ------------------ | ------- | ------------ |
|
||||||
| `user_id` | int64 | QQ 号 |
|
| `user_id` | int64 | QQ 号 |
|
||||||
| `nickname` | string | 用户昵称 |
|
| `nickname` | string | 用户昵称 |
|
||||||
| `level` | int64 | QQ 等级 |
|
| `level` | int64 | QQ 等级 |
|
||||||
@ -951,7 +1042,7 @@ JSON数组:
|
|||||||
**参数**
|
**参数**
|
||||||
|
|
||||||
| 字段名 | 数据类型 | 默认值 | 说明 |
|
| 字段名 | 数据类型 | 默认值 | 说明 |
|
||||||
| ---------- | ------- | ----- | ------ |
|
| ---------- | -------- | ------ | -------- |
|
||||||
| `group_id` | int64 | | 群号 |
|
| `group_id` | int64 | | 群号 |
|
||||||
| `content` | string | | 公告内容 |
|
| `content` | string | | 公告内容 |
|
||||||
|
|
||||||
@ -995,7 +1086,7 @@ JSON数组:
|
|||||||
**事件数据**
|
**事件数据**
|
||||||
|
|
||||||
| 字段名 | 数据类型 | 可能的值 | 说明 |
|
| 字段名 | 数据类型 | 可能的值 | 说明 |
|
||||||
| ------------- | ------ | -------- | --- |
|
| ------------- | -------- | -------- | ------------ |
|
||||||
| `post_type` | string | `notice` | 上报类型 |
|
| `post_type` | string | `notice` | 上报类型 |
|
||||||
| `notice_type` | string | `notify` | 消息类型 |
|
| `notice_type` | string | `notify` | 消息类型 |
|
||||||
| `sub_type` | string | `poke` | 提示类型 |
|
| `sub_type` | string | `poke` | 提示类型 |
|
||||||
@ -1091,8 +1182,21 @@ JSON数组:
|
|||||||
**上报数据**
|
**上报数据**
|
||||||
|
|
||||||
| 字段 | 类型 | 可能的值 | 说明 |
|
| 字段 | 类型 | 可能的值 | 说明 |
|
||||||
| ------------- | ------ | -------------- | -------- |
|
| ------------- | ------ | --------------- | ------------ |
|
||||||
| `post_type` | string | `notice` | 上报类型 |
|
| `post_type` | string | `notice` | 上报类型 |
|
||||||
| `notice_type` | string | `client_status` | 消息类型 |
|
| `notice_type` | string | `client_status` | 消息类型 |
|
||||||
| `client` | Device | | 客户端信息 |
|
| `client` | Device | | 客户端信息 |
|
||||||
| `online` | bool | | 当前是否在线 |
|
| `online` | bool | | 当前是否在线 |
|
||||||
|
|
||||||
|
### 精华消息
|
||||||
|
|
||||||
|
**上报数据**
|
||||||
|
|
||||||
|
| 字段 | 类型 | 可能的值 | 说明 |
|
||||||
|
| ------------- | ------ | -------------- | -------------------------- |
|
||||||
|
| `post_type` | string | `notice` | 上报类型 |
|
||||||
|
| `notice_type` | string | `essence` | 消息类型 |
|
||||||
|
| `sub_type` | string | `add`,`delete` | 添加为`add`,移出为`delete` |
|
||||||
|
| `sender_id` | int64 | | 消息发送者ID |
|
||||||
|
| `operator_id` | int64 | | 操作者ID |
|
||||||
|
| `message_id` | int32 | | 消息ID |
|
||||||
|
@ -9,26 +9,10 @@ import (
|
|||||||
|
|
||||||
"github.com/Mrs4s/go-cqhttp/global/codec"
|
"github.com/Mrs4s/go-cqhttp/global/codec"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var useSilkCodec = true
|
|
||||||
|
|
||||||
//InitCodec 初始化Silk编码器
|
|
||||||
func InitCodec() {
|
|
||||||
log.Info("正在加载silk编码器...")
|
|
||||||
err := codec.Init()
|
|
||||||
if err != nil {
|
|
||||||
log.Error(err)
|
|
||||||
useSilkCodec = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// EncoderSilk 将音频编码为Silk
|
// EncoderSilk 将音频编码为Silk
|
||||||
func EncoderSilk(data []byte) ([]byte, error) {
|
func EncoderSilk(data []byte) ([]byte, error) {
|
||||||
if !useSilkCodec {
|
|
||||||
return nil, errors.New("no silk encoder")
|
|
||||||
}
|
|
||||||
h := md5.New()
|
h := md5.New()
|
||||||
_, err := h.Write(data)
|
_, err := h.Write(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,67 +1,28 @@
|
|||||||
// +build linux windows darwin
|
// +build linux windows,!arm darwin,!arm64
|
||||||
// +build 386 amd64 arm arm64
|
// +build 386 amd64 arm arm64
|
||||||
|
|
||||||
|
// Package codec Slik编码核心模块
|
||||||
package codec
|
package codec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/pkg/errors"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/wdvxdr1123/go-silk"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
silkCachePath = "data/cache"
|
silkCachePath = "data/cache"
|
||||||
encoderPath = "codec"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func downloadCodec(url string) (err error) {
|
|
||||||
resp, err := http.Get(url)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = ioutil.WriteFile(getEncoderFilePath(), body, os.ModePerm)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func getEncoderFilePath() string {
|
|
||||||
encoderFile := path.Join(encoderPath, runtime.GOOS+"-"+runtime.GOARCH+"-encoder")
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
encoderFile = encoderFile + ".exe"
|
|
||||||
}
|
|
||||||
return encoderFile
|
|
||||||
}
|
|
||||||
|
|
||||||
//Init 下载Silk编码器
|
|
||||||
func Init() error {
|
|
||||||
if !fileExist(silkCachePath) {
|
|
||||||
_ = os.MkdirAll(silkCachePath, os.ModePerm)
|
|
||||||
}
|
|
||||||
if !fileExist(encoderPath) {
|
|
||||||
_ = os.MkdirAll(encoderPath, os.ModePerm)
|
|
||||||
}
|
|
||||||
p := getEncoderFilePath()
|
|
||||||
if !fileExist(p) {
|
|
||||||
if err := downloadCodec("https://cdn.jsdelivr.net/gh/wdvxdr1123/tosilk/codec/" + runtime.GOOS + "-" + runtime.GOARCH + "-encoder"); err != nil {
|
|
||||||
return errors.New("下载依赖失败")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
//EncodeToSilk 将音频编码为Silk
|
//EncodeToSilk 将音频编码为Silk
|
||||||
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
|
func EncodeToSilk(record []byte, tempName string, useCache bool) (silkWav []byte, err error) {
|
||||||
// 1. 写入缓存文件
|
// 1. 写入缓存文件
|
||||||
rawPath := path.Join(silkCachePath, tempName+".wav")
|
rawPath := path.Join(silkCachePath, tempName+".wav")
|
||||||
err := ioutil.WriteFile(rawPath, record, os.ModePerm)
|
err = ioutil.WriteFile(rawPath, record, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "write temp file error")
|
return nil, errors.Wrap(err, "write temp file error")
|
||||||
}
|
}
|
||||||
@ -76,22 +37,17 @@ func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error)
|
|||||||
defer os.Remove(pcmPath)
|
defer os.Remove(pcmPath)
|
||||||
|
|
||||||
// 3. 转silk
|
// 3. 转silk
|
||||||
|
pcm, err := ioutil.ReadFile(pcmPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "read pcm file err")
|
||||||
|
}
|
||||||
|
silkWav, err = silk.EncodePcmBuffToSilk(pcm, 24000, 24000, true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "silk encode error")
|
||||||
|
}
|
||||||
|
if useCache {
|
||||||
silkPath := path.Join(silkCachePath, tempName+".silk")
|
silkPath := path.Join(silkCachePath, tempName+".silk")
|
||||||
cmd = exec.Command(getEncoderFilePath(), pcmPath, silkPath, "-rate", "24000", "-quiet", "-tencent")
|
err = ioutil.WriteFile(silkPath, silkWav, 0666)
|
||||||
if err = cmd.Run(); err != nil {
|
|
||||||
return nil, errors.Wrap(err, "convert silk file error")
|
|
||||||
}
|
}
|
||||||
if !useCache {
|
return
|
||||||
defer os.Remove(silkPath)
|
|
||||||
}
|
|
||||||
return ioutil.ReadFile(silkPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FileExist 检查文件是否存在
|
|
||||||
func fileExist(path string) bool {
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
path = path + ".exe"
|
|
||||||
}
|
|
||||||
_, err := os.Lstat(path)
|
|
||||||
return !os.IsNotExist(err)
|
|
||||||
}
|
}
|
||||||
|
8
global/codec/codec_darwin_arm64.go
Normal file
8
global/codec/codec_darwin_arm64.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package codec
|
||||||
|
|
||||||
|
import "github.com/pkg/errors"
|
||||||
|
|
||||||
|
//EncodeToSilk 将音频编码为Silk
|
||||||
|
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
|
||||||
|
return nil, errors.New("not supported now")
|
||||||
|
}
|
@ -1,15 +1,10 @@
|
|||||||
// +build !386,!arm64,!amd64,!arm
|
// +build !arm,!arm64,!amd64,!386
|
||||||
|
|
||||||
package codec
|
package codec
|
||||||
|
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
//Init 下载silk编码器
|
|
||||||
func Init() error {
|
|
||||||
return errors.New("Unsupport arch now")
|
|
||||||
}
|
|
||||||
|
|
||||||
//EncodeToSilk 将音频编码为Silk
|
//EncodeToSilk 将音频编码为Silk
|
||||||
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
|
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
|
||||||
return nil, errors.New("Unsupport arch now")
|
return nil, errors.New("not supported now")
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,7 @@ package codec
|
|||||||
|
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
//Init 下载silk编码器
|
|
||||||
func Init() error {
|
|
||||||
return errors.New("not support now")
|
|
||||||
}
|
|
||||||
|
|
||||||
//EncodeToSilk 将音频编码为Silk
|
//EncodeToSilk 将音频编码为Silk
|
||||||
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
|
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
|
||||||
return nil, errors.New("not support now")
|
return nil, errors.New("not supported now")
|
||||||
}
|
}
|
||||||
|
8
global/codec/codec_windows_arm.go
Normal file
8
global/codec/codec_windows_arm.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package codec
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
//EncodeToSilk 将音频编码为Silk
|
||||||
|
func EncodeToSilk(record []byte, tempName string, useCache bool) ([]byte, error) {
|
||||||
|
return nil, errors.New("not supported now")
|
||||||
|
}
|
2
global/doc.go
Normal file
2
global/doc.go
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// Package global 包含文件下载,视频音频编码,本地文件缓存处理,消息过滤器,调用速率限制,gocq主配置等的相关函数与结构体
|
||||||
|
package global
|
@ -109,9 +109,9 @@ func andOperatorConstruct(argument gjson.Result) *AndOperator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Eval 对payload执行And过滤
|
// Eval 对payload执行And过滤
|
||||||
func (andOperator *AndOperator) Eval(payload MSG) bool {
|
func (op *AndOperator) Eval(payload MSG) bool {
|
||||||
res := true
|
res := true
|
||||||
for _, operand := range andOperator.operands {
|
for _, operand := range op.operands {
|
||||||
|
|
||||||
if len(operand.key) == 0 {
|
if len(operand.key) == 0 {
|
||||||
// is an operator
|
// is an operator
|
||||||
@ -291,7 +291,7 @@ func Generate(opName string, argument gjson.Result) Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// EventFilter 初始化一个nil过滤器
|
// EventFilter 初始化一个nil过滤器
|
||||||
var EventFilter Filter = nil
|
var EventFilter Filter
|
||||||
|
|
||||||
// BootFilter 启动事件过滤器
|
// BootFilter 启动事件过滤器
|
||||||
func BootFilter() {
|
func BootFilter() {
|
||||||
|
@ -2,14 +2,16 @@ package global
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// LocalHook logrus本地钩子
|
||||||
type LocalHook struct {
|
type LocalHook struct {
|
||||||
lock *sync.Mutex
|
lock *sync.Mutex
|
||||||
levels []logrus.Level // hook级别
|
levels []logrus.Level // hook级别
|
||||||
@ -18,7 +20,7 @@ type LocalHook struct {
|
|||||||
writer io.Writer // io
|
writer io.Writer // io
|
||||||
}
|
}
|
||||||
|
|
||||||
// ref: logrus/hooks.go. impl Hook interface
|
// Levels ref: logrus/hooks.go impl Hook interface
|
||||||
func (hook *LocalHook) Levels() []logrus.Level {
|
func (hook *LocalHook) Levels() []logrus.Level {
|
||||||
if len(hook.levels) == 0 {
|
if len(hook.levels) == 0 {
|
||||||
return logrus.AllLevels
|
return logrus.AllLevels
|
||||||
@ -61,6 +63,7 @@ func (hook *LocalHook) pathWrite(entry *logrus.Entry) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fire ref: logrus/hooks.go impl Hook interface
|
||||||
func (hook *LocalHook) Fire(entry *logrus.Entry) error {
|
func (hook *LocalHook) Fire(entry *logrus.Entry) error {
|
||||||
hook.lock.Lock()
|
hook.lock.Lock()
|
||||||
defer hook.lock.Unlock()
|
defer hook.lock.Unlock()
|
||||||
@ -76,6 +79,7 @@ func (hook *LocalHook) Fire(entry *logrus.Entry) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetFormatter 设置日志格式
|
||||||
func (hook *LocalHook) SetFormatter(formatter logrus.Formatter) {
|
func (hook *LocalHook) SetFormatter(formatter logrus.Formatter) {
|
||||||
hook.lock.Lock()
|
hook.lock.Lock()
|
||||||
defer hook.lock.Unlock()
|
defer hook.lock.Unlock()
|
||||||
@ -96,18 +100,21 @@ func (hook *LocalHook) SetFormatter(formatter logrus.Formatter) {
|
|||||||
hook.formatter = formatter
|
hook.formatter = formatter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetWriter 设置Writer
|
||||||
func (hook *LocalHook) SetWriter(writer io.Writer) {
|
func (hook *LocalHook) SetWriter(writer io.Writer) {
|
||||||
hook.lock.Lock()
|
hook.lock.Lock()
|
||||||
defer hook.lock.Unlock()
|
defer hook.lock.Unlock()
|
||||||
hook.writer = writer
|
hook.writer = writer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetPath 设置日志写入路径
|
||||||
func (hook *LocalHook) SetPath(path string) {
|
func (hook *LocalHook) SetPath(path string) {
|
||||||
hook.lock.Lock()
|
hook.lock.Lock()
|
||||||
defer hook.lock.Unlock()
|
defer hook.lock.Unlock()
|
||||||
hook.path = path
|
hook.path = path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewLocalHook 初始化本地日志钩子实现
|
||||||
func NewLocalHook(args interface{}, formatter logrus.Formatter, levels ...logrus.Level) *LocalHook {
|
func NewLocalHook(args interface{}, formatter logrus.Formatter, levels ...logrus.Level) *LocalHook {
|
||||||
hook := &LocalHook{
|
hook := &LocalHook{
|
||||||
lock: new(sync.Mutex),
|
lock: new(sync.Mutex),
|
||||||
@ -127,6 +134,11 @@ func NewLocalHook(args interface{}, formatter logrus.Formatter, levels ...logrus
|
|||||||
return hook
|
return hook
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetLogLevel 获取日志等级
|
||||||
|
//
|
||||||
|
// 可能的值有
|
||||||
|
//
|
||||||
|
// "trace","debug","info","warn","warn","error"
|
||||||
func GetLogLevel(level string) []logrus.Level {
|
func GetLogLevel(level string) []logrus.Level {
|
||||||
switch level {
|
switch level {
|
||||||
case "trace":
|
case "trace":
|
||||||
|
11
go.mod
11
go.mod
@ -1,9 +1,9 @@
|
|||||||
module github.com/Mrs4s/go-cqhttp
|
module github.com/Mrs4s/go-cqhttp
|
||||||
|
|
||||||
go 1.15
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20210201234941-c69e578d0815
|
github.com/Mrs4s/MiraiGo v0.0.0-20210219090120-c4288bd213f3
|
||||||
github.com/dustin/go-humanize v1.0.0
|
github.com/dustin/go-humanize v1.0.0
|
||||||
github.com/gin-contrib/pprof v1.3.0
|
github.com/gin-contrib/pprof v1.3.0
|
||||||
github.com/gin-gonic/gin v1.6.3
|
github.com/gin-gonic/gin v1.6.3
|
||||||
@ -19,9 +19,12 @@ require (
|
|||||||
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.7
|
github.com/tidwall/gjson v1.6.8
|
||||||
|
github.com/wdvxdr1123/go-silk v0.0.0-20210207032612-169bbdf8861d
|
||||||
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/crypto v0.0.0-20190308221718-c2843e01d9a2
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
|
||||||
|
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
|
||||||
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf
|
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf
|
||||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324
|
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324
|
||||||
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||||
)
|
)
|
||||||
|
53
go.sum
53
go.sum
@ -1,15 +1,19 @@
|
|||||||
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-20210201234941-c69e578d0815 h1:WW2YfA+0+LSa/0VlWVhnfrXXatcE09paHgPgfPxlIMk=
|
github.com/Mrs4s/MiraiGo v0.0.0-20210206134348-800bf525ed0e h1:SnN+nyRdqN7sULnHUWCofP+Jxs3VJN/y8AlMpcz0nbk=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20210201234941-c69e578d0815/go.mod h1:yhqA0NyKxUf7I/0HR/1OMchveFggX8wde04gqdGrNfU=
|
github.com/Mrs4s/MiraiGo v0.0.0-20210206134348-800bf525ed0e/go.mod h1:yhqA0NyKxUf7I/0HR/1OMchveFggX8wde04gqdGrNfU=
|
||||||
|
github.com/Mrs4s/MiraiGo v0.0.0-20210219090120-c4288bd213f3 h1:hsO/cT00Nxyi5FrnXImimBlcHKrdFh8yWEwp0OR88z8=
|
||||||
|
github.com/Mrs4s/MiraiGo v0.0.0-20210219090120-c4288bd213f3/go.mod h1:yhqA0NyKxUf7I/0HR/1OMchveFggX8wde04gqdGrNfU=
|
||||||
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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
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 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
|
||||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
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 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||||
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/gin-contrib/pprof v1.3.0 h1:G9eK6HnbkSqDZBYbzG4wrjCsA4e+cvYAHUZw6W+W9K0=
|
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/pprof v1.3.0/go.mod h1:waMjT1H9b179t3CxuG1cV3DHpga6ybizwfBaM5OXaB0=
|
||||||
@ -19,6 +23,7 @@ github.com/gin-gonic/gin v1.6.0/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwv
|
|||||||
github.com/gin-gonic/gin v1.6.2/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
|
github.com/gin-gonic/gin v1.6.2/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
|
||||||
github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
|
github.com/gin-gonic/gin v1.6.3 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 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
|
||||||
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=
|
||||||
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
|
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
|
||||||
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
|
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
|
||||||
@ -45,8 +50,10 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
|
|||||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
|
||||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
|
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
|
||||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||||
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=
|
||||||
@ -54,7 +61,9 @@ github.com/guonaihong/gout v0.1.4 h1:uBBoyztMX9okC27OQxqhn6bZ0ROkGyvnEIHwtp3TM4g
|
|||||||
github.com/guonaihong/gout v0.1.4/go.mod h1:0rFYAYyzbcxEg11eY2qUbffJs7hHRPeugAnlVYSp8Ic=
|
github.com/guonaihong/gout v0.1.4/go.mod h1:0rFYAYyzbcxEg11eY2qUbffJs7hHRPeugAnlVYSp8Ic=
|
||||||
github.com/hjson/hjson-go v3.1.0+incompatible h1:DY/9yE8ey8Zv22bY+mHV1uk2yRy0h8tKhZ77hEdi0Aw=
|
github.com/hjson/hjson-go v3.1.0+incompatible h1:DY/9yE8ey8Zv22bY+mHV1uk2yRy0h8tKhZ77hEdi0Aw=
|
||||||
github.com/hjson/hjson-go v3.1.0+incompatible/go.mod h1:qsetwF8NlsTsOTwZTApNlTCerV+b2GjYRRcIk4JMFio=
|
github.com/hjson/hjson-go v3.1.0+incompatible/go.mod h1:qsetwF8NlsTsOTwZTApNlTCerV+b2GjYRRcIk4JMFio=
|
||||||
|
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||||
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/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ=
|
||||||
github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
|
github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
|
||||||
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 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
|
||||||
@ -64,6 +73,7 @@ github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALr
|
|||||||
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/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=
|
||||||
|
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8=
|
||||||
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is=
|
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is=
|
||||||
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkLibYKgg+SwmyFU9dF2hn6MdTj4=
|
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkLibYKgg+SwmyFU9dF2hn6MdTj4=
|
||||||
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA=
|
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA=
|
||||||
@ -78,13 +88,18 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
|
|||||||
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 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
|
||||||
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 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
|
||||||
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/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=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
|
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk=
|
||||||
|
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||||
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
|
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM=
|
||||||
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||||
@ -92,13 +107,16 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
|||||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
|
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
|
||||||
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.7 h1:Mb1M9HZCRWEcXQ8ieJo7auYyyiSux6w9XN3AdTpxJrE=
|
github.com/tidwall/gjson v1.6.8 h1:CTmXMClGYPAmln7652e69B7OLXfTi5ABcPPwjIWUv7w=
|
||||||
github.com/tidwall/gjson v1.6.7/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
|
github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
|
||||||
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
|
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
|
||||||
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||||
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
|
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
|
||||||
@ -107,10 +125,14 @@ 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-20210207032612-169bbdf8861d h1:gJTKbjZtlMt/almOeFi/UpVtT3RHqRWscgEuDtnF5TU=
|
||||||
|
github.com/wdvxdr1123/go-silk v0.0.0-20210207032612-169bbdf8861d/go.mod h1:twOxzexmM2Il1ReUu1fB5tnUotOq/dp56xjk/ZHwb1I=
|
||||||
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 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
|
||||||
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=
|
||||||
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
|
||||||
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||||
@ -120,8 +142,11 @@ golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73r
|
|||||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA=
|
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA=
|
||||||
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=
|
||||||
|
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
@ -129,15 +154,21 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
|
|||||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20201126233918-771906719818 h1:f1CIuDlJhwANEC2MM87MBEVMr3jl5bifgsfj90XAF9c=
|
||||||
|
golang.org/x/sys v0.0.0-20201126233918-771906719818/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
|
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
|
||||||
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
|
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
|
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
|
||||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
@ -146,6 +177,8 @@ golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3
|
|||||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||||
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||||
@ -164,12 +197,24 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
|
|||||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
|
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
|
||||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
||||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||||
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
modernc.org/libc v1.7.6 h1:P0qDJAlSR6hSAuE8mQgz9eH/GzigfEd3IIn7HmTQgT0=
|
||||||
|
modernc.org/libc v1.7.6/go.mod h1:U1eq8YWr/Kc1RWCMFUWEdkTg8OTcfLw2kY8EDwl039w=
|
||||||
|
modernc.org/mathutil v1.1.1/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
|
||||||
|
modernc.org/mathutil v1.2.2 h1:+yFk8hBprV+4c0U9GjFtL+dV3N8hOJ8JCituQcMShFY=
|
||||||
|
modernc.org/mathutil v1.2.2/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
|
||||||
|
modernc.org/memory v1.0.4 h1:utMBrFcpnQDdNsmM6asmyH/FM9TqLPS7XF7otpJmrwM=
|
||||||
|
modernc.org/memory v1.0.4/go.mod h1:nV2OApxradM3/OVbs2/0OsP6nPfakXpi50C7dcoHXlc=
|
||||||
|
4
main.go
4
main.go
@ -143,7 +143,7 @@ func main() {
|
|||||||
|
|
||||||
if conf.Uin == 0 || (conf.Password == "" && conf.PasswordEncrypted == "") {
|
if conf.Uin == 0 || (conf.Password == "" && conf.PasswordEncrypted == "") {
|
||||||
log.Warnf("请修改 config.hjson 以添加账号密码.")
|
log.Warnf("请修改 config.hjson 以添加账号密码.")
|
||||||
if (!isFastStart) {
|
if !isFastStart {
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -509,7 +509,7 @@ func getConfig() *global.JSONConfig {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
log.Infof("默认配置文件已生成, 请编辑 config.hjson 后重启程序.")
|
log.Infof("默认配置文件已生成, 请编辑 config.hjson 后重启程序.")
|
||||||
if (!isFastStart) {
|
if !isFastStart {
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -30,12 +30,16 @@ import (
|
|||||||
|
|
||||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||||
|
|
||||||
|
// WebInput 网页输入channel
|
||||||
var WebInput = make(chan string, 1) //长度1,用于阻塞
|
var WebInput = make(chan string, 1) //长度1,用于阻塞
|
||||||
|
|
||||||
|
// Console 控制台channel
|
||||||
var Console = make(chan os.Signal, 1)
|
var Console = make(chan os.Signal, 1)
|
||||||
|
|
||||||
|
// Restart 重启信号监听channel
|
||||||
var Restart = make(chan struct{}, 1)
|
var Restart = make(chan struct{}, 1)
|
||||||
|
|
||||||
|
// JSONConfig go-cqhttp配置
|
||||||
var JSONConfig *global.JSONConfig
|
var JSONConfig *global.JSONConfig
|
||||||
|
|
||||||
type webServer struct {
|
type webServer struct {
|
||||||
@ -46,23 +50,25 @@ type webServer struct {
|
|||||||
Console *bufio.Reader
|
Console *bufio.Reader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WebServer Admin子站的Server
|
||||||
var WebServer = &webServer{}
|
var WebServer = &webServer{}
|
||||||
|
|
||||||
// admin 子站的 路由映射
|
// APIAdminRoutingTable Admin子站的路由映射
|
||||||
var HttpuriAdmin = map[string]func(s *webServer, c *gin.Context){
|
var APIAdminRoutingTable = map[string]func(s *webServer, c *gin.Context){
|
||||||
"do_restart": AdminDoRestart, //热重启
|
"do_restart": AdminDoRestart, //热重启
|
||||||
"do_process_restart": AdminProcessRestart, //进程重启
|
"do_process_restart": AdminProcessRestart, //进程重启
|
||||||
"get_web_write": AdminWebWrite, //获取是否验证码输入
|
"get_web_write": AdminWebWrite, //获取是否验证码输入
|
||||||
"do_web_write": AdminDoWebWrite, //web上进行输入操作
|
"do_web_write": AdminDoWebWrite, //web上进行输入操作
|
||||||
"do_restart_docker": AdminDoRestartDocker, //直接停止(依赖supervisord/docker)重新拉起
|
"do_restart_docker": AdminDoRestartDocker, //直接停止(依赖supervisord/docker)重新拉起
|
||||||
"do_config_base": AdminDoConfigBase, //修改config.json中的基础部分
|
"do_config_base": AdminDoConfigBase, //修改config.json中的基础部分
|
||||||
"do_config_http": AdminDoConfigHttp, //修改config.json的http部分
|
"do_config_http": AdminDoConfigHTTP, //修改config.json的http部分
|
||||||
"do_config_ws": AdminDoConfigWs, //修改config.json的正向ws部分
|
"do_config_ws": AdminDoConfigWS, //修改config.json的正向ws部分
|
||||||
"do_config_reverse": AdminDoConfigReverse, //修改config.json 中的反向ws部分
|
"do_config_reverse": AdminDoConfigReverseWS, //修改config.json 中的反向ws部分
|
||||||
"do_config_json": AdminDoConfigJson, //直接修改 config.json配置
|
"do_config_json": AdminDoConfigJSON, //直接修改 config.json配置
|
||||||
"get_config_json": AdminGetConfigJson, //拉取 当前的config.json配置
|
"get_config_json": AdminGetConfigJSON, //拉取 当前的config.json配置
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Failed 构建失败返回MSG
|
||||||
func Failed(code int, msg string) coolq.MSG {
|
func Failed(code int, msg string) coolq.MSG {
|
||||||
return coolq.MSG{"data": nil, "retcode": code, "status": "failed", "msg": msg}
|
return coolq.MSG{"data": nil, "retcode": code, "status": "failed", "msg": msg}
|
||||||
}
|
}
|
||||||
@ -111,224 +117,249 @@ func (s *webServer) Run(addr string, cli *client.QQClient) *coolq.CQBot {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *webServer) Dologin() {
|
// logincore 登录核心实现
|
||||||
|
func (s *webServer) logincore(relogin bool) {
|
||||||
|
|
||||||
s.Console = bufio.NewReader(os.Stdin)
|
s.Console = bufio.NewReader(os.Stdin)
|
||||||
readLine := func() (str string) {
|
readLine := func() (str string) {
|
||||||
str, _ = s.Console.ReadString('\n')
|
str, _ = s.Console.ReadString('\n')
|
||||||
str = strings.TrimSpace(str)
|
str = strings.TrimSpace(str)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
conf := GetConf()
|
|
||||||
cli := s.Cli
|
if s.Cli.Online {
|
||||||
cli.AllowSlider = true
|
log.Warn("Bot已登录")
|
||||||
rsp, err := cli.Login()
|
return
|
||||||
count := 0
|
}
|
||||||
for {
|
|
||||||
global.Check(err)
|
var times uint = 1 // 重试次数
|
||||||
|
for res, err := s.Cli.Login(); ; res, err = s.Cli.Login() {
|
||||||
|
|
||||||
var text string
|
var text string
|
||||||
if !rsp.Success {
|
count := 0
|
||||||
switch rsp.Error {
|
|
||||||
|
if res == nil {
|
||||||
|
goto Relogin
|
||||||
|
}
|
||||||
|
|
||||||
|
Again: // 不执行 s.Cli.Login() 的循环,适用输入验证码等更新 res 的操作
|
||||||
|
if err == nil && res.Success { // 登录成功
|
||||||
|
break
|
||||||
|
} else if err == client.ErrAlreadyOnline {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
switch res.Error {
|
||||||
case client.SliderNeededError:
|
case client.SliderNeededError:
|
||||||
log.Warnf("登录需要滑条验证码, 请选择解决方案: ")
|
log.Warnf("登录需要滑条验证码, 请选择解决方案: ")
|
||||||
log.Warnf("1. 自行抓包. (推荐)")
|
log.Warnf("1. 自行抓包. (推荐)")
|
||||||
log.Warnf("2. 使用Cef自动处理.")
|
log.Warnf("2. 使用Cef自动处理.")
|
||||||
log.Warnf("3. 不提交滑块并继续.(可能会导致上网环境异常错误)")
|
log.Warnf("3. 不提交滑块并继续.(可能会导致上网环境异常错误)")
|
||||||
log.Warnf("详细信息请参考文档 -> https://github.com/Mrs4s/go-cqhttp/blob/master/docs/slider.md <-")
|
log.Warnf("详细信息请参考文档 -> https://github.com/Mrs4s/go-cqhttp/blob/master/docs/slider.md <-")
|
||||||
log.Warn("请输入(1 - 3): ")
|
if s.Conf.WebUI != nil && s.Conf.WebUI.WebInput {
|
||||||
|
log.Warnf("请输入(1 - 3): (http://%s:%d/admin/do_web_write 输入)", s.Conf.WebUI.Host, s.Conf.WebUI.WebUIPort)
|
||||||
|
text = <-WebInput
|
||||||
|
} else {
|
||||||
|
log.Warn("请输入(1 - 3):")
|
||||||
text = readLine()
|
text = readLine()
|
||||||
|
}
|
||||||
if strings.Contains(text, "1") {
|
if strings.Contains(text, "1") {
|
||||||
log.Warnf("请用浏览器打开 -> %v <- 并获取Ticket.", rsp.VerifyUrl)
|
log.Warnf("请用浏览器打开 -> %v <- 并获取Ticket.", res.VerifyUrl)
|
||||||
|
if s.Conf.WebUI != nil && s.Conf.WebUI.WebInput {
|
||||||
|
log.Warnf("请输入Ticket: (http://%s:%d/admin/do_web_write 输入)", s.Conf.WebUI.Host, s.Conf.WebUI.WebUIPort)
|
||||||
|
text = <-WebInput
|
||||||
|
} else {
|
||||||
log.Warn("请输入Ticket: (Enter 提交)")
|
log.Warn("请输入Ticket: (Enter 提交)")
|
||||||
text = readLine()
|
text = readLine()
|
||||||
rsp, err = cli.SubmitTicket(strings.TrimSpace(text))
|
}
|
||||||
continue
|
res, err = s.Cli.SubmitTicket(strings.TrimSpace(text))
|
||||||
|
goto Again
|
||||||
}
|
}
|
||||||
if strings.Contains(text, "3") {
|
if strings.Contains(text, "3") {
|
||||||
cli.AllowSlider = false
|
s.Cli.AllowSlider = false
|
||||||
cli.Disconnect()
|
s.Cli.Disconnect()
|
||||||
rsp, err = cli.Login()
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
id := utils.RandomStringRange(6, "0123456789")
|
id := utils.RandomStringRange(6, "0123456789")
|
||||||
log.Warnf("滑块ID为 %v 请在30S内处理.", id)
|
log.Warnf("滑块ID为 %v 请在30S内处理.", id)
|
||||||
ticket, err := global.GetSliderTicket(rsp.VerifyUrl, id)
|
ticket, err := global.GetSliderTicket(res.VerifyUrl, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("错误: " + err.Error())
|
log.Warnf("错误: " + err.Error())
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
rsp, err = cli.SubmitTicket(ticket)
|
res, err = s.Cli.SubmitTicket(ticket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("错误: " + err.Error())
|
log.Warnf("错误: " + err.Error())
|
||||||
os.Exit(0)
|
continue // 尝试重新登录
|
||||||
}
|
}
|
||||||
continue
|
goto Again
|
||||||
case client.NeedCaptcha:
|
case client.NeedCaptcha:
|
||||||
_ = ioutil.WriteFile("captcha.jpg", rsp.CaptchaImage, 0644)
|
_ = ioutil.WriteFile("captcha.jpg", res.CaptchaImage, 0644)
|
||||||
img, _, _ := image.Decode(bytes.NewReader(rsp.CaptchaImage))
|
img, _, _ := image.Decode(bytes.NewReader(res.CaptchaImage))
|
||||||
fmt.Println(asciiart.New("image", img).Art)
|
fmt.Println(asciiart.New("image", img).Art)
|
||||||
if conf.WebUI != nil && conf.WebUI.WebInput {
|
if s.Conf.WebUI != nil && s.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 输入)", s.Conf.WebUI.Host, s.Conf.WebUI.WebUIPort)
|
||||||
text = <-WebInput
|
text = <-WebInput
|
||||||
} else {
|
} else {
|
||||||
log.Warn("请输入验证码 (captcha.jpg): (Enter 提交)")
|
log.Warn("请输入验证码 (captcha.jpg): (Enter 提交)")
|
||||||
text = readLine()
|
text = readLine()
|
||||||
}
|
}
|
||||||
rsp, err = cli.SubmitCaptcha(strings.ReplaceAll(text, "\n", ""), rsp.CaptchaSign)
|
|
||||||
global.DelFile("captcha.jpg")
|
global.DelFile("captcha.jpg")
|
||||||
continue
|
res, err = s.Cli.SubmitCaptcha(strings.ReplaceAll(text, "\n", ""), res.CaptchaSign)
|
||||||
|
goto Again
|
||||||
case client.SMSNeededError:
|
case client.SMSNeededError:
|
||||||
log.Warnf("账号已开启设备锁, 按下 Enter 向手机 %v 发送短信验证码.", rsp.SMSPhone)
|
if s.Conf.WebUI != nil && s.Conf.WebUI.WebInput {
|
||||||
|
log.Warnf("账号已开启设备锁, 已向手机 %v 发送短信验证码.", res.SMSPhone)
|
||||||
|
} else {
|
||||||
|
log.Warnf("账号已开启设备锁, 按下 Enter 向手机 %v 发送短信验证码.", res.SMSPhone)
|
||||||
readLine()
|
readLine()
|
||||||
if !cli.RequestSMS() {
|
}
|
||||||
|
if !s.Cli.RequestSMS() {
|
||||||
log.Warnf("发送验证码失败,可能是请求过于频繁.")
|
log.Warnf("发送验证码失败,可能是请求过于频繁.")
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
os.Exit(0)
|
continue
|
||||||
}
|
}
|
||||||
|
if s.Conf.WebUI != nil && s.Conf.WebUI.WebInput {
|
||||||
|
log.Warnf("请输入短信验证码: (http://%s:%d/admin/do_web_write 输入)", s.Conf.WebUI.Host, s.Conf.WebUI.WebUIPort)
|
||||||
|
text = <-WebInput
|
||||||
|
} else {
|
||||||
log.Warn("请输入短信验证码: (Enter 提交)")
|
log.Warn("请输入短信验证码: (Enter 提交)")
|
||||||
text = readLine()
|
text = readLine()
|
||||||
rsp, err = cli.SubmitSMS(strings.ReplaceAll(strings.ReplaceAll(text, "\n", ""), "\r", ""))
|
}
|
||||||
continue
|
res, err = s.Cli.SubmitSMS(strings.ReplaceAll(strings.ReplaceAll(text, "\n", ""), "\r", ""))
|
||||||
|
goto Again
|
||||||
case client.SMSOrVerifyNeededError:
|
case client.SMSOrVerifyNeededError:
|
||||||
log.Warnf("账号已开启设备锁,请选择验证方式:")
|
log.Warnf("账号已开启设备锁,请选择验证方式:")
|
||||||
log.Warnf("1. 向手机 %v 发送短信验证码", rsp.SMSPhone)
|
log.Warnf("1. 向手机 %v 发送短信验证码", res.SMSPhone)
|
||||||
log.Warnf("2. 使用手机QQ扫码验证.")
|
log.Warnf("2. 使用手机QQ扫码验证.")
|
||||||
log.Warn("请输入(1 - 2): ")
|
if s.Conf.WebUI != nil && s.Conf.WebUI.WebInput {
|
||||||
|
log.Warnf("请输入(1 - 2): (http://%s:%d/admin/do_web_write 输入)", s.Conf.WebUI.Host, s.Conf.WebUI.WebUIPort)
|
||||||
|
text = <-WebInput
|
||||||
|
} else {
|
||||||
|
log.Warn("请输入(1 - 2):")
|
||||||
text = readLine()
|
text = readLine()
|
||||||
|
}
|
||||||
if strings.Contains(text, "1") {
|
if strings.Contains(text, "1") {
|
||||||
if !cli.RequestSMS() {
|
if !s.Cli.RequestSMS() {
|
||||||
log.Warnf("发送验证码失败,可能是请求过于频繁.")
|
log.Warnf("发送验证码失败,可能是请求过于频繁.")
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
if s.Conf.WebUI != nil && s.Conf.WebUI.WebInput {
|
||||||
|
log.Warnf("请输入短信验证码: (http://%s:%d/admin/do_web_write 输入)....", s.Conf.WebUI.Host, s.Conf.WebUI.WebUIPort)
|
||||||
|
text = <-WebInput
|
||||||
|
} else {
|
||||||
log.Warn("请输入短信验证码: (Enter 提交)")
|
log.Warn("请输入短信验证码: (Enter 提交)")
|
||||||
text = readLine()
|
text = readLine()
|
||||||
rsp, err = cli.SubmitSMS(strings.ReplaceAll(strings.ReplaceAll(text, "\n", ""), "\r", ""))
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
log.Warnf("请前往 -> %v <- 验证并重启Bot.", rsp.VerifyUrl)
|
res, err = s.Cli.SubmitSMS(strings.ReplaceAll(strings.ReplaceAll(text, "\n", ""), "\r", ""))
|
||||||
|
goto Again
|
||||||
|
}
|
||||||
|
log.Warnf("请前往 -> %v <- 验证.", res.VerifyUrl)
|
||||||
log.Infof("按 Enter 继续....")
|
log.Infof("按 Enter 继续....")
|
||||||
readLine()
|
readLine()
|
||||||
os.Exit(0)
|
continue
|
||||||
return
|
|
||||||
case client.UnsafeDeviceError:
|
case client.UnsafeDeviceError:
|
||||||
log.Warnf("账号已开启设备锁,请前往 -> %v <- 验证并重启Bot.", rsp.VerifyUrl)
|
log.Warnf("账号已开启设备锁,请前往 -> %v <- 验证.", res.VerifyUrl)
|
||||||
if conf.WebUI != nil && conf.WebUI.WebInput {
|
if s.Conf.WebUI != nil && s.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 确认后继续)....", s.Conf.WebUI.Host, s.Conf.WebUI.WebUIPort)
|
||||||
text = <-WebInput
|
text = <-WebInput
|
||||||
} else {
|
} else {
|
||||||
log.Infof("按 Enter 继续....")
|
log.Infof("按 Enter 继续....")
|
||||||
readLine()
|
readLine()
|
||||||
}
|
}
|
||||||
log.Info(text)
|
log.Info(text)
|
||||||
os.Exit(0)
|
continue
|
||||||
return
|
|
||||||
case client.OtherLoginError, client.UnknownLoginError:
|
case client.OtherLoginError, client.UnknownLoginError:
|
||||||
msg := rsp.ErrorMessage
|
msg := res.ErrorMessage
|
||||||
if strings.Contains(msg, "版本") {
|
if strings.Contains(msg, "版本") {
|
||||||
msg = "密码错误或账号被冻结"
|
msg = "密码错误或账号被冻结"
|
||||||
}
|
}
|
||||||
if strings.Contains(msg, "上网环境") && count < 5 {
|
if strings.Contains(msg, "上网环境") && count < 5 {
|
||||||
cli.Disconnect()
|
s.Cli.Disconnect()
|
||||||
rsp, err = cli.Login()
|
|
||||||
count++
|
|
||||||
log.Warnf("错误: 当前上网环境异常. 将更换服务器并重试.")
|
log.Warnf("错误: 当前上网环境异常. 将更换服务器并重试.")
|
||||||
|
count++
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if strings.Contains(msg, "冻结") {
|
||||||
|
log.Fatalf("账号被冻结, 放弃重连")
|
||||||
|
}
|
||||||
log.Warnf("登录失败: %v", msg)
|
log.Warnf("登录失败: %v", msg)
|
||||||
log.Infof("按 Enter 继续....")
|
log.Infof("按 Enter 继续....")
|
||||||
readLine()
|
readLine()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
Relogin:
|
||||||
|
if relogin {
|
||||||
|
if times > s.Conf.ReLogin.MaxReloginTimes && s.Conf.ReLogin.MaxReloginTimes != 0 {
|
||||||
|
log.Fatal("重连失败: 重连次数达到设置的上限值")
|
||||||
|
s.bot.Release()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
log.Warnf("将在 %v 秒后尝试重连. 重连次数:%v", s.Conf.ReLogin.ReLoginDelay, times)
|
||||||
|
times++
|
||||||
|
time.Sleep(time.Second * time.Duration(s.Conf.ReLogin.ReLoginDelay))
|
||||||
|
s.Cli.Disconnect()
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
}
|
||||||
log.Infof("登录成功 欢迎使用: %v", cli.Nickname)
|
if relogin {
|
||||||
time.Sleep(time.Second)
|
log.Info("重连成功")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dologin 主程序登录
|
||||||
|
func (s *webServer) Dologin() {
|
||||||
|
|
||||||
|
s.Cli.AllowSlider = true
|
||||||
|
s.logincore(false)
|
||||||
|
log.Infof("登录成功 欢迎使用: %v", s.Cli.Nickname)
|
||||||
log.Info("开始加载好友列表...")
|
log.Info("开始加载好友列表...")
|
||||||
global.Check(cli.ReloadFriendList())
|
global.Check(s.Cli.ReloadFriendList())
|
||||||
log.Infof("共加载 %v 个好友.", len(cli.FriendList))
|
log.Infof("共加载 %v 个好友.", len(s.Cli.FriendList))
|
||||||
log.Infof("开始加载群列表...")
|
log.Infof("开始加载群列表...")
|
||||||
global.Check(cli.ReloadGroupList())
|
global.Check(s.Cli.ReloadGroupList())
|
||||||
log.Infof("共加载 %v 个群.", len(cli.GroupList))
|
log.Infof("共加载 %v 个群.", len(s.Cli.GroupList))
|
||||||
s.bot = coolq.NewQQBot(cli, conf)
|
s.bot = coolq.NewQQBot(s.Cli, s.Conf)
|
||||||
if conf.PostMessageFormat != "string" && conf.PostMessageFormat != "array" {
|
if s.Conf.PostMessageFormat != "string" && s.Conf.PostMessageFormat != "array" {
|
||||||
log.Warnf("post_message_format 配置错误, 将自动使用 string")
|
log.Warnf("post_message_format 配置错误, 将自动使用 string")
|
||||||
coolq.SetMessageFormat("string")
|
coolq.SetMessageFormat("string")
|
||||||
} else {
|
} else {
|
||||||
coolq.SetMessageFormat(conf.PostMessageFormat)
|
coolq.SetMessageFormat(s.Conf.PostMessageFormat)
|
||||||
}
|
}
|
||||||
if conf.RateLimit.Enabled {
|
if s.Conf.RateLimit.Enabled {
|
||||||
global.InitLimiter(conf.RateLimit.Frequency, conf.RateLimit.BucketSize)
|
global.InitLimiter(s.Conf.RateLimit.Frequency, s.Conf.RateLimit.BucketSize)
|
||||||
}
|
}
|
||||||
log.Info("正在加载事件过滤器.")
|
log.Info("正在加载事件过滤器.")
|
||||||
global.BootFilter()
|
global.BootFilter()
|
||||||
global.InitCodec()
|
coolq.IgnoreInvalidCQCode = s.Conf.IgnoreInvalidCQCode
|
||||||
coolq.IgnoreInvalidCQCode = conf.IgnoreInvalidCQCode
|
coolq.SplitURL = s.Conf.FixURL
|
||||||
coolq.SplitUrl = conf.FixURL
|
coolq.ForceFragmented = s.Conf.ForceFragmented
|
||||||
coolq.ForceFragmented = conf.ForceFragmented
|
|
||||||
log.Info("资源初始化完成, 开始处理信息.")
|
log.Info("资源初始化完成, 开始处理信息.")
|
||||||
log.Info("アトリは、高性能ですから!")
|
log.Info("アトリは、高性能ですから!")
|
||||||
cli.OnDisconnected(func(bot *client.QQClient, e *client.ClientDisconnectedEvent) {
|
|
||||||
if conf.ReLogin.Enabled {
|
s.Cli.OnDisconnected(func(q *client.QQClient, e *client.ClientDisconnectedEvent) {
|
||||||
conf.ReLogin.Enabled = false
|
if !s.Conf.ReLogin.Enabled {
|
||||||
defer func() { conf.ReLogin.Enabled = true }()
|
|
||||||
var times uint = 1
|
|
||||||
for {
|
|
||||||
if cli.Online {
|
|
||||||
log.Warn("Bot已登录")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if times > conf.ReLogin.MaxReloginTimes && conf.ReLogin.MaxReloginTimes != 0 {
|
log.Warnf("Bot已离线 (%v),尝试重连", e.Message)
|
||||||
break
|
s.logincore(true)
|
||||||
}
|
|
||||||
log.Warnf("Bot已离线 (%v),将在 %v 秒后尝试重连. 重连次数:%v",
|
|
||||||
e.Message, conf.ReLogin.ReLoginDelay, times)
|
|
||||||
times++
|
|
||||||
time.Sleep(time.Second * time.Duration(conf.ReLogin.ReLoginDelay))
|
|
||||||
rsp, err := cli.Login()
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("重连失败: %v", err)
|
|
||||||
cli.Disconnect()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if !rsp.Success {
|
|
||||||
switch rsp.Error {
|
|
||||||
case client.NeedCaptcha:
|
|
||||||
log.Fatalf("重连失败: 需要验证码. (验证码处理正在开发中)")
|
|
||||||
case client.UnsafeDeviceError:
|
|
||||||
log.Fatalf("重连失败: 设备锁")
|
|
||||||
default:
|
|
||||||
log.Errorf("重连失败: %v", rsp.ErrorMessage)
|
|
||||||
if strings.Contains(rsp.ErrorMessage, "冻结") {
|
|
||||||
log.Fatalf("账号被冻结, 放弃重连")
|
|
||||||
}
|
|
||||||
cli.Disconnect()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.Info("重连成功")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Fatal("重连失败: 重连次数达到设置的上限值")
|
|
||||||
}
|
|
||||||
s.bot.Release()
|
|
||||||
log.Fatalf("Bot已离线:%v", e.Message)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *webServer) admin(c *gin.Context) {
|
func (s *webServer) admin(c *gin.Context) {
|
||||||
action := c.Param("action")
|
action := c.Param("action")
|
||||||
log.Debugf("WebServer接收到cgi调用: %v", action)
|
log.Debugf("WebServer接收到cgi调用: %v", action)
|
||||||
if f, ok := HttpuriAdmin[action]; ok {
|
if f, ok := APIAdminRoutingTable[action]; ok {
|
||||||
f(s, c)
|
f(s, c)
|
||||||
} else {
|
} else {
|
||||||
c.JSON(200, coolq.Failed(404))
|
c.JSON(200, coolq.Failed(404))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取当前配置文件信息
|
// GetConf 获取当前配置文件信息
|
||||||
func GetConf() *global.JSONConfig {
|
func GetConf() *global.JSONConfig {
|
||||||
if JSONConfig != nil {
|
if JSONConfig != nil {
|
||||||
return JSONConfig
|
return JSONConfig
|
||||||
@ -337,7 +368,7 @@ func GetConf() *global.JSONConfig {
|
|||||||
return conf
|
return conf
|
||||||
}
|
}
|
||||||
|
|
||||||
// admin 控制器 登录验证
|
// AuthMiddleWare Admin控制器登录验证
|
||||||
func AuthMiddleWare() gin.HandlerFunc {
|
func AuthMiddleWare() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
conf := GetConf()
|
conf := GetConf()
|
||||||
@ -431,12 +462,13 @@ func (s *webServer) DoReLogin() { // TODO: 协议层的 ReLogin
|
|||||||
s.Dologin()
|
s.Dologin()
|
||||||
// 关闭之前的 server
|
// 关闭之前的 server
|
||||||
if OldConf.HTTPConfig != nil && OldConf.HTTPConfig.Enabled {
|
if OldConf.HTTPConfig != nil && OldConf.HTTPConfig.Enabled {
|
||||||
HttpServer.ShutDown()
|
cqHTTPServer.ShutDown()
|
||||||
}
|
}
|
||||||
// if OldConf.WSConfig != nil && OldConf.WSConfig.Enabled {
|
// if OldConf.WSConfig != nil && OldConf.WSConfig.Enabled {
|
||||||
// server.WsShutdown()
|
// server.WsShutdown()
|
||||||
// }
|
// }
|
||||||
// s.UpServer()
|
// s.UpServer()
|
||||||
|
|
||||||
s.ReloadServer()
|
s.ReloadServer()
|
||||||
s.Conf = conf
|
s.Conf = conf
|
||||||
}
|
}
|
||||||
@ -444,9 +476,9 @@ func (s *webServer) DoReLogin() { // TODO: 协议层的 ReLogin
|
|||||||
func (s *webServer) UpServer() {
|
func (s *webServer) UpServer() {
|
||||||
conf := GetConf()
|
conf := GetConf()
|
||||||
if conf.HTTPConfig != nil && conf.HTTPConfig.Enabled {
|
if conf.HTTPConfig != nil && conf.HTTPConfig.Enabled {
|
||||||
go HttpServer.Run(fmt.Sprintf("%s:%d", conf.HTTPConfig.Host, conf.HTTPConfig.Port), conf.AccessToken, s.bot)
|
go cqHTTPServer.Run(fmt.Sprintf("%s:%d", conf.HTTPConfig.Host, conf.HTTPConfig.Port), conf.AccessToken, s.bot)
|
||||||
for k, v := range conf.HTTPConfig.PostUrls {
|
for k, v := range conf.HTTPConfig.PostUrls {
|
||||||
NewHttpClient().Run(k, v, conf.HTTPConfig.Timeout, s.bot)
|
newHTTPClient().Run(k, v, conf.HTTPConfig.Timeout, s.bot)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if conf.WSConfig != nil && conf.WSConfig.Enabled {
|
if conf.WSConfig != nil && conf.WSConfig.Enabled {
|
||||||
@ -461,9 +493,9 @@ func (s *webServer) UpServer() {
|
|||||||
func (s *webServer) ReloadServer() {
|
func (s *webServer) ReloadServer() {
|
||||||
conf := GetConf()
|
conf := GetConf()
|
||||||
if conf.HTTPConfig != nil && conf.HTTPConfig.Enabled {
|
if conf.HTTPConfig != nil && conf.HTTPConfig.Enabled {
|
||||||
go HttpServer.Run(fmt.Sprintf("%s:%d", conf.HTTPConfig.Host, conf.HTTPConfig.Port), conf.AccessToken, s.bot)
|
go cqHTTPServer.Run(fmt.Sprintf("%s:%d", conf.HTTPConfig.Host, conf.HTTPConfig.Port), conf.AccessToken, s.bot)
|
||||||
for k, v := range conf.HTTPConfig.PostUrls {
|
for k, v := range conf.HTTPConfig.PostUrls {
|
||||||
NewHttpClient().Run(k, v, conf.HTTPConfig.Timeout, s.bot)
|
newHTTPClient().Run(k, v, conf.HTTPConfig.Timeout, s.bot)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, rc := range conf.ReverseServers {
|
for _, rc := range conf.ReverseServers {
|
||||||
@ -471,7 +503,7 @@ func (s *webServer) ReloadServer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 热重启
|
// AdminDoRestart 热重启
|
||||||
func AdminDoRestart(s *webServer, c *gin.Context) {
|
func AdminDoRestart(s *webServer, c *gin.Context) {
|
||||||
s.bot.Release()
|
s.bot.Release()
|
||||||
s.bot = nil
|
s.bot = nil
|
||||||
@ -480,19 +512,19 @@ func AdminDoRestart(s *webServer, c *gin.Context) {
|
|||||||
c.JSON(200, coolq.OK(coolq.MSG{}))
|
c.JSON(200, coolq.OK(coolq.MSG{}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 进程重启
|
// AdminProcessRestart 进程重启
|
||||||
func AdminProcessRestart(s *webServer, c *gin.Context) {
|
func AdminProcessRestart(s *webServer, c *gin.Context) {
|
||||||
Restart <- struct{}{}
|
Restart <- struct{}{}
|
||||||
c.JSON(200, coolq.OK(coolq.MSG{}))
|
c.JSON(200, coolq.OK(coolq.MSG{}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 冷重启
|
// AdminDoRestartDocker 冷重启
|
||||||
func AdminDoRestartDocker(s *webServer, c *gin.Context) {
|
func AdminDoRestartDocker(s *webServer, c *gin.Context) {
|
||||||
Console <- os.Kill
|
Console <- os.Kill
|
||||||
c.JSON(200, coolq.OK(coolq.MSG{}))
|
c.JSON(200, coolq.OK(coolq.MSG{}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// web输入 html 页面
|
// AdminWebWrite web输入html页面
|
||||||
func AdminWebWrite(s *webServer, c *gin.Context) {
|
func AdminWebWrite(s *webServer, c *gin.Context) {
|
||||||
pic := global.ReadAllText("captcha.jpg")
|
pic := global.ReadAllText("captcha.jpg")
|
||||||
var picbase64 string
|
var picbase64 string
|
||||||
@ -509,14 +541,14 @@ func AdminWebWrite(s *webServer, c *gin.Context) {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// web输入 处理
|
// AdminDoWebWrite web输入处理
|
||||||
func AdminDoWebWrite(s *webServer, c *gin.Context) {
|
func AdminDoWebWrite(s *webServer, c *gin.Context) {
|
||||||
input := c.PostForm("input")
|
input := c.PostForm("input")
|
||||||
WebInput <- input
|
WebInput <- input
|
||||||
c.JSON(200, coolq.OK(coolq.MSG{}))
|
c.JSON(200, coolq.OK(coolq.MSG{}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 普通配置修改
|
// AdminDoConfigBase 普通配置修改
|
||||||
func AdminDoConfigBase(s *webServer, c *gin.Context) {
|
func AdminDoConfigBase(s *webServer, c *gin.Context) {
|
||||||
conf := GetConf()
|
conf := GetConf()
|
||||||
conf.Uin, _ = strconv.ParseInt(c.PostForm("uin"), 10, 64)
|
conf.Uin, _ = strconv.ParseInt(c.PostForm("uin"), 10, 64)
|
||||||
@ -536,8 +568,8 @@ func AdminDoConfigBase(s *webServer, c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// http配置修改
|
// AdminDoConfigHTTP HTTP配置修改
|
||||||
func AdminDoConfigHttp(s *webServer, c *gin.Context) {
|
func AdminDoConfigHTTP(s *webServer, c *gin.Context) {
|
||||||
conf := GetConf()
|
conf := GetConf()
|
||||||
p, _ := strconv.ParseUint(c.PostForm("port"), 10, 16)
|
p, _ := strconv.ParseUint(c.PostForm("port"), 10, 16)
|
||||||
conf.HTTPConfig.Port = uint16(p)
|
conf.HTTPConfig.Port = uint16(p)
|
||||||
@ -561,8 +593,8 @@ func AdminDoConfigHttp(s *webServer, c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ws配置修改
|
// AdminDoConfigWS ws配置修改
|
||||||
func AdminDoConfigWs(s *webServer, c *gin.Context) {
|
func AdminDoConfigWS(s *webServer, c *gin.Context) {
|
||||||
conf := GetConf()
|
conf := GetConf()
|
||||||
p, _ := strconv.ParseUint(c.PostForm("port"), 10, 16)
|
p, _ := strconv.ParseUint(c.PostForm("port"), 10, 16)
|
||||||
conf.WSConfig.Port = uint16(p)
|
conf.WSConfig.Port = uint16(p)
|
||||||
@ -581,8 +613,8 @@ func AdminDoConfigWs(s *webServer, c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 反向ws配置修改
|
// AdminDoConfigReverseWS 反向ws配置修改
|
||||||
func AdminDoConfigReverse(s *webServer, c *gin.Context) {
|
func AdminDoConfigReverseWS(s *webServer, c *gin.Context) {
|
||||||
conf := GetConf()
|
conf := GetConf()
|
||||||
conf.ReverseServers[0].ReverseAPIURL = c.PostForm("reverse_api_url")
|
conf.ReverseServers[0].ReverseAPIURL = c.PostForm("reverse_api_url")
|
||||||
conf.ReverseServers[0].ReverseURL = c.PostForm("reverse_url")
|
conf.ReverseServers[0].ReverseURL = c.PostForm("reverse_url")
|
||||||
@ -603,11 +635,11 @@ func AdminDoConfigReverse(s *webServer, c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// config.json配置修改
|
// AdminDoConfigJSON config.hjson配置修改
|
||||||
func AdminDoConfigJson(s *webServer, c *gin.Context) {
|
func AdminDoConfigJSON(s *webServer, c *gin.Context) {
|
||||||
conf := GetConf()
|
conf := GetConf()
|
||||||
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.hjson", err)
|
log.Warnf("尝试加载配置文件 %v 时出现错误: %v", "config.hjson", err)
|
||||||
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
|
c.JSON(200, Failed(502, "保存 config.hjson 时出现错误:"+fmt.Sprintf("%v", err)))
|
||||||
@ -622,8 +654,8 @@ func AdminDoConfigJson(s *webServer, c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拉取config.json配置
|
// AdminGetConfigJSON 拉取config.hjson配置
|
||||||
func AdminGetConfigJson(s *webServer, c *gin.Context) {
|
func AdminGetConfigJSON(s *webServer, c *gin.Context) {
|
||||||
conf := GetConf()
|
conf := GetConf()
|
||||||
c.JSON(200, coolq.OK(coolq.MSG{"config": conf}))
|
c.JSON(200, coolq.OK(coolq.MSG{"config": conf}))
|
||||||
|
|
||||||
|
2
server/doc.go
Normal file
2
server/doc.go
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// Package server 包含Admin子站,HTTP,WebSocket,反向WebSocket请求处理的相关函数与结构体
|
||||||
|
package server
|
134
server/http.go
134
server/http.go
@ -24,7 +24,7 @@ import (
|
|||||||
type httpServer struct {
|
type httpServer struct {
|
||||||
engine *gin.Engine
|
engine *gin.Engine
|
||||||
bot *coolq.CQBot
|
bot *coolq.CQBot
|
||||||
Http *http.Server
|
HTTP *http.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
type httpClient struct {
|
type httpClient struct {
|
||||||
@ -34,7 +34,9 @@ type httpClient struct {
|
|||||||
timeout int32
|
timeout int32
|
||||||
}
|
}
|
||||||
|
|
||||||
var HttpServer = &httpServer{}
|
var cqHTTPServer = &httpServer{}
|
||||||
|
|
||||||
|
// Debug 是否启用Debug模式
|
||||||
var Debug = false
|
var Debug = false
|
||||||
|
|
||||||
func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
|
func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
|
||||||
@ -84,11 +86,11 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
|
|||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
log.Infof("CQ HTTP 服务器已启动: %v", addr)
|
log.Infof("CQ HTTP 服务器已启动: %v", addr)
|
||||||
s.Http = &http.Server{
|
s.HTTP = &http.Server{
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
Handler: s.engine,
|
Handler: s.engine,
|
||||||
}
|
}
|
||||||
if err := s.Http.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
if err := s.HTTP.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
log.Infof("HTTP 服务启动失败, 请检查端口是否被占用.")
|
log.Infof("HTTP 服务启动失败, 请检查端口是否被占用.")
|
||||||
log.Warnf("将在五秒后退出.")
|
log.Warnf("将在五秒后退出.")
|
||||||
@ -98,7 +100,7 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHttpClient() *httpClient {
|
func newHTTPClient() *httpClient {
|
||||||
return &httpClient{}
|
return &httpClient{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +125,7 @@ func (c *httpClient) onBotPushEvent(m coolq.MSG) {
|
|||||||
}
|
}
|
||||||
if c.secret != "" {
|
if c.secret != "" {
|
||||||
mac := hmac.New(sha1.New, []byte(c.secret))
|
mac := hmac.New(sha1.New, []byte(c.secret))
|
||||||
_, err := mac.Write([]byte(m.ToJson()))
|
_, err := mac.Write([]byte(m.ToJSON()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
return nil
|
return nil
|
||||||
@ -141,12 +143,12 @@ func (c *httpClient) onBotPushEvent(m coolq.MSG) {
|
|||||||
return nil
|
return nil
|
||||||
}).Do()
|
}).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("上报Event数据 %v 到 %v 失败: %v", m.ToJson(), c.addr, err)
|
log.Warnf("上报Event数据 %v 到 %v 失败: %v", m.ToJSON(), c.addr, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Debugf("上报Event数据 %v 到 %v", m.ToJson(), c.addr)
|
log.Debugf("上报Event数据 %v 到 %v", m.ToJSON(), c.addr)
|
||||||
if gjson.Valid(res) {
|
if gjson.Valid(res) {
|
||||||
c.bot.CQHandleQuickOperation(gjson.Parse(m.ToJson()), gjson.Parse(res))
|
c.bot.CQHandleQuickOperation(gjson.Parse(m.ToJSON()), gjson.Parse(res))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,67 +156,86 @@ func (s *httpServer) HandleActions(c *gin.Context) {
|
|||||||
global.RateLimit(context.Background())
|
global.RateLimit(context.Background())
|
||||||
action := strings.ReplaceAll(c.Param("action"), "_async", "")
|
action := strings.ReplaceAll(c.Param("action"), "_async", "")
|
||||||
log.Debugf("HTTPServer接收到API调用: %v", action)
|
log.Debugf("HTTPServer接收到API调用: %v", action)
|
||||||
if f, ok := httpApi[action]; ok {
|
if f, ok := httpAPI[action]; ok {
|
||||||
f(s, c)
|
f(s, c)
|
||||||
} else {
|
} else {
|
||||||
c.JSON(200, coolq.Failed(404))
|
c.JSON(200, coolq.Failed(404))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetLoginInfo 获取登录号信息
|
||||||
func GetLoginInfo(s *httpServer, c *gin.Context) {
|
func GetLoginInfo(s *httpServer, c *gin.Context) {
|
||||||
c.JSON(200, s.bot.CQGetLoginInfo())
|
c.JSON(200, s.bot.CQGetLoginInfo())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetFriendList 获取好友列表
|
||||||
func GetFriendList(s *httpServer, c *gin.Context) {
|
func GetFriendList(s *httpServer, c *gin.Context) {
|
||||||
c.JSON(200, s.bot.CQGetFriendList())
|
c.JSON(200, s.bot.CQGetFriendList())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGroupList 获取群列表
|
||||||
func GetGroupList(s *httpServer, 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"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGroupInfo 获取群信息
|
||||||
func GetGroupInfo(s *httpServer, 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)
|
||||||
nc := getParamOrDefault(c, "no_cache", "false")
|
nc := getParamOrDefault(c, "no_cache", "false")
|
||||||
c.JSON(200, s.bot.CQGetGroupInfo(gid, nc == "true"))
|
c.JSON(200, s.bot.CQGetGroupInfo(gid, nc == "true"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGroupMemberList 获取群成员列表
|
||||||
func GetGroupMemberList(s *httpServer, 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"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGroupMemberInfo 获取群成员信息
|
||||||
func GetGroupMemberInfo(s *httpServer, 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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGroupFileSystemInfo 扩展API-获取群文件系统信息
|
||||||
func GetGroupFileSystemInfo(s *httpServer, 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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGroupRootFiles 扩展API-获取群根目录文件列表
|
||||||
func GetGroupRootFiles(s *httpServer, 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 GetGroupFilesByFolderId(s *httpServer, c *gin.Context) {
|
// GetGroupFilesByFolderID 扩展API-获取群子目录文件列表
|
||||||
|
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 GetGroupFileUrl(s *httpServer, c *gin.Context) {
|
// GetGroupFileURL 扩展API-获取群文件资源链接
|
||||||
|
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)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UploadGroupFile 扩展API-上传群文件
|
||||||
|
func UploadGroupFile(s *httpServer, c *gin.Context) {
|
||||||
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
|
c.JSON(200, s.bot.CQUploadGroupFile(gid, getParam(c, "file"), getParam(c, "name"), getParam(c, "folder")))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendMessage 发送消息
|
||||||
|
//
|
||||||
|
// https://git.io/JtwTQ
|
||||||
func SendMessage(s *httpServer, c *gin.Context) {
|
func SendMessage(s *httpServer, c *gin.Context) {
|
||||||
if getParam(c, "message_type") == "private" {
|
if getParam(c, "message_type") == "private" {
|
||||||
SendPrivateMessage(s, c)
|
SendPrivateMessage(s, c)
|
||||||
@ -233,6 +254,7 @@ func SendMessage(s *httpServer, c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendPrivateMessage 发送私聊消息
|
||||||
func SendPrivateMessage(s *httpServer, 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")
|
||||||
@ -244,6 +266,7 @@ func SendPrivateMessage(s *httpServer, c *gin.Context) {
|
|||||||
c.JSON(200, s.bot.CQSendPrivateMessage(uid, msg, autoEscape))
|
c.JSON(200, s.bot.CQSendPrivateMessage(uid, msg, autoEscape))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendGroupMessage 发送群消息
|
||||||
func SendGroupMessage(s *httpServer, 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")
|
||||||
@ -255,33 +278,39 @@ func SendGroupMessage(s *httpServer, c *gin.Context) {
|
|||||||
c.JSON(200, s.bot.CQSendGroupMessage(gid, msg, autoEscape))
|
c.JSON(200, s.bot.CQSendGroupMessage(gid, msg, autoEscape))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendGroupForwardMessage 扩展API-发送合并转发(群)
|
||||||
func SendGroupForwardMessage(s *httpServer, 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)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetImage 获取图片(修改自OneBot)
|
||||||
func GetImage(s *httpServer, 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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetMessage 获取消息
|
||||||
func GetMessage(s *httpServer, 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)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGroupHonorInfo 获取群荣誉信息
|
||||||
func GetGroupHonorInfo(s *httpServer, 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")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProcessFriendRequest 处理加好友请求
|
||||||
func ProcessFriendRequest(s *httpServer, 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"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProcessGroupRequest 处理加群请求/邀请
|
||||||
func ProcessGroupRequest(s *httpServer, 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")
|
||||||
@ -292,18 +321,21 @@ func ProcessGroupRequest(s *httpServer, 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"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetGroupCard 设置群名片(群备注)
|
||||||
func SetGroupCard(s *httpServer, 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")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSpecialTitle 设置群组专属头衔
|
||||||
func SetSpecialTitle(s *httpServer, 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")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetGroupKick 群组踢人
|
||||||
func SetGroupKick(s *httpServer, 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)
|
||||||
@ -312,6 +344,7 @@ func SetGroupKick(s *httpServer, c *gin.Context) {
|
|||||||
c.JSON(200, s.bot.CQSetGroupKick(gid, uid, msg, block == "true"))
|
c.JSON(200, s.bot.CQSetGroupKick(gid, uid, msg, block == "true"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetGroupBan 群组单人禁言
|
||||||
func SetGroupBan(s *httpServer, 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)
|
||||||
@ -319,32 +352,40 @@ func SetGroupBan(s *httpServer, c *gin.Context) {
|
|||||||
c.JSON(200, s.bot.CQSetGroupBan(gid, uid, uint32(i)))
|
c.JSON(200, s.bot.CQSetGroupBan(gid, uid, uint32(i)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetWholeBan 群组全员禁言
|
||||||
func SetWholeBan(s *httpServer, 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"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetGroupName 设置群名
|
||||||
func SetGroupName(s *httpServer, 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")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetGroupAdmin 群组设置管理员
|
||||||
func SetGroupAdmin(s *httpServer, 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"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendGroupNotice 扩展API-发送群公告
|
||||||
func SendGroupNotice(s *httpServer, 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")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetGroupLeave 退出群组
|
||||||
func SetGroupLeave(s *httpServer, 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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetRestart 重启 OneBot 实现
|
||||||
|
//
|
||||||
|
// https://git.io/JtwkJ
|
||||||
func SetRestart(s *httpServer, c *gin.Context) {
|
func SetRestart(s *httpServer, c *gin.Context) {
|
||||||
delay, _ := strconv.ParseInt(getParam(c, "delay"), 10, 64)
|
delay, _ := strconv.ParseInt(getParam(c, "delay"), 10, 64)
|
||||||
c.JSON(200, coolq.MSG{"data": nil, "retcode": 0, "status": "async"})
|
c.JSON(200, coolq.MSG{"data": nil, "retcode": 0, "status": "async"})
|
||||||
@ -355,58 +396,70 @@ func SetRestart(s *httpServer, c *gin.Context) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetForwardMessage 获取合并转发消息
|
||||||
func GetForwardMessage(s *httpServer, c *gin.Context) {
|
func GetForwardMessage(s *httpServer, c *gin.Context) {
|
||||||
resId := getParam(c, "message_id")
|
resID := getParam(c, "message_id")
|
||||||
if resId == "" {
|
if resID == "" {
|
||||||
resId = getParam(c, "id")
|
resID = getParam(c, "id")
|
||||||
}
|
}
|
||||||
c.JSON(200, s.bot.CQGetForwardMessage(resId))
|
c.JSON(200, s.bot.CQGetForwardMessage(resID))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGroupSystemMessage 扩展API-获取群文件系统消息
|
||||||
func GetGroupSystemMessage(s *httpServer, c *gin.Context) {
|
func GetGroupSystemMessage(s *httpServer, c *gin.Context) {
|
||||||
c.JSON(200, s.bot.CQGetGroupSystemMessages())
|
c.JSON(200, s.bot.CQGetGroupSystemMessages())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteMessage 撤回消息
|
||||||
func DeleteMessage(s *httpServer, 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)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CanSendImage 检查是否可以发送图片(此处永远返回true)
|
||||||
func CanSendImage(s *httpServer, c *gin.Context) {
|
func CanSendImage(s *httpServer, c *gin.Context) {
|
||||||
c.JSON(200, s.bot.CQCanSendImage())
|
c.JSON(200, s.bot.CQCanSendImage())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CanSendRecord 检查是否可以发送语音(此处永远返回true)
|
||||||
func CanSendRecord(s *httpServer, c *gin.Context) {
|
func CanSendRecord(s *httpServer, c *gin.Context) {
|
||||||
c.JSON(200, s.bot.CQCanSendRecord())
|
c.JSON(200, s.bot.CQCanSendRecord())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetStatus 获取运行状态
|
||||||
func GetStatus(s *httpServer, c *gin.Context) {
|
func GetStatus(s *httpServer, c *gin.Context) {
|
||||||
c.JSON(200, s.bot.CQGetStatus())
|
c.JSON(200, s.bot.CQGetStatus())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetVersionInfo 获取版本信息
|
||||||
func GetVersionInfo(s *httpServer, c *gin.Context) {
|
func GetVersionInfo(s *httpServer, c *gin.Context) {
|
||||||
c.JSON(200, s.bot.CQGetVersionInfo())
|
c.JSON(200, s.bot.CQGetVersionInfo())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReloadEventFilter 扩展API-重载事件过滤器
|
||||||
func ReloadEventFilter(s *httpServer, c *gin.Context) {
|
func ReloadEventFilter(s *httpServer, c *gin.Context) {
|
||||||
c.JSON(200, s.bot.CQReloadEventFilter())
|
c.JSON(200, s.bot.CQReloadEventFilter())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetVipInfo 扩展API-获取VIP信息
|
||||||
func GetVipInfo(s *httpServer, 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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetStrangerInfo 获取陌生人信息
|
||||||
func GetStrangerInfo(s *httpServer, 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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGroupAtAllRemain 扩展API-获取群 @全体成员 剩余次数
|
||||||
func GetGroupAtAllRemain(s *httpServer, c *gin.Context) {
|
func GetGroupAtAllRemain(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.CQGetAtAllRemain(gid))
|
c.JSON(200, s.bot.CQGetAtAllRemain(gid))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetGroupAnonymousBan 群组匿名用户禁言
|
||||||
func SetGroupAnonymousBan(s *httpServer, c *gin.Context) {
|
func SetGroupAnonymousBan(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
d, _ := strconv.ParseInt(getParam(c, "duration"), 10, 64)
|
d, _ := strconv.ParseInt(getParam(c, "duration"), 10, 64)
|
||||||
@ -421,16 +474,19 @@ func SetGroupAnonymousBan(s *httpServer, c *gin.Context) {
|
|||||||
c.JSON(200, s.bot.CQSetGroupAnonymousBan(gid, flag, int32(d)))
|
c.JSON(200, s.bot.CQSetGroupAnonymousBan(gid, flag, int32(d)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetGroupMessageHistory 获取群消息历史记录
|
||||||
func GetGroupMessageHistory(s *httpServer, c *gin.Context) {
|
func GetGroupMessageHistory(s *httpServer, c *gin.Context) {
|
||||||
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
seq, _ := strconv.ParseInt(getParam(c, "message_seq"), 10, 64)
|
seq, _ := strconv.ParseInt(getParam(c, "message_seq"), 10, 64)
|
||||||
c.JSON(200, s.bot.CQGetGroupMessageHistory(gid, seq))
|
c.JSON(200, s.bot.CQGetGroupMessageHistory(gid, seq))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetOnlineClients 扩展API-获取当前账号在线客户端列表
|
||||||
func GetOnlineClients(s *httpServer, c *gin.Context) {
|
func GetOnlineClients(s *httpServer, c *gin.Context) {
|
||||||
c.JSON(200, s.bot.CQGetOnlineClients(getParamOrDefault(c, "no_cache", "false") == "true"))
|
c.JSON(200, s.bot.CQGetOnlineClients(getParamOrDefault(c, "no_cache", "false") == "true"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HandleQuickOperation 隐藏API-对事件执行快速操作
|
||||||
func HandleQuickOperation(s *httpServer, 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)
|
||||||
@ -442,6 +498,7 @@ func HandleQuickOperation(s *httpServer, c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DownloadFile 扩展API-下载文件到缓存目录
|
||||||
func DownloadFile(s *httpServer, c *gin.Context) {
|
func DownloadFile(s *httpServer, c *gin.Context) {
|
||||||
url := getParam(c, "url")
|
url := getParam(c, "url")
|
||||||
tc, _ := strconv.Atoi(getParam(c, "thread_count"))
|
tc, _ := strconv.Atoi(getParam(c, "thread_count"))
|
||||||
@ -469,16 +526,19 @@ func DownloadFile(s *httpServer, c *gin.Context) {
|
|||||||
c.JSON(200, s.bot.CQDownloadFile(url, headers, tc))
|
c.JSON(200, s.bot.CQDownloadFile(url, headers, tc))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OcrImage 扩展API-图片OCR
|
||||||
func OcrImage(s *httpServer, 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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetWordSlices 隐藏API-获取中文分词
|
||||||
func GetWordSlices(s *httpServer, 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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetGroupPortrait 扩展API-设置群头像
|
||||||
func SetGroupPortrait(s *httpServer, 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")
|
||||||
@ -486,6 +546,29 @@ func SetGroupPortrait(s *httpServer, c *gin.Context) {
|
|||||||
c.JSON(200, s.bot.CQSetGroupPortrait(gid, file, cache))
|
c.JSON(200, s.bot.CQSetGroupPortrait(gid, file, cache))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetEssenceMsg 扩展API-设置精华消息
|
||||||
|
func SetEssenceMsg(s *httpServer, c *gin.Context) {
|
||||||
|
mid, _ := strconv.ParseInt(getParam(c, "message_id"), 10, 64)
|
||||||
|
c.JSON(200, s.bot.CQSetEssenceMessage(int32(mid)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteEssenceMsg 扩展API-移出精华消息
|
||||||
|
func DeleteEssenceMsg(s *httpServer, c *gin.Context) {
|
||||||
|
mid, _ := strconv.ParseInt(getParam(c, "message_id"), 10, 64)
|
||||||
|
c.JSON(200, s.bot.CQDeleteEssenceMessage(int32(mid)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetEssenceMsgList 扩展API-获取精华消息列表
|
||||||
|
func GetEssenceMsgList(s *httpServer, c *gin.Context) {
|
||||||
|
gid, _ := strconv.ParseInt(getParam(c, "group_id"), 10, 64)
|
||||||
|
c.JSON(200, s.bot.CQGetEssenceMessageList(gid))
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckURLSafely 扩展API-检查链接安全性
|
||||||
|
func CheckURLSafely(s *httpServer, c *gin.Context) {
|
||||||
|
c.JSON(200, s.bot.CQCheckURLSafely(getParam(c, "url")))
|
||||||
|
}
|
||||||
|
|
||||||
func getParamOrDefault(c *gin.Context, k, def string) string {
|
func getParamOrDefault(c *gin.Context, k, def string) string {
|
||||||
r := getParam(c, k)
|
r := getParam(c, k)
|
||||||
if r != "" {
|
if r != "" {
|
||||||
@ -534,7 +617,7 @@ func getParamWithType(c *gin.Context, k string) (string, gjson.Type) {
|
|||||||
return "", gjson.Null
|
return "", gjson.Null
|
||||||
}
|
}
|
||||||
|
|
||||||
var httpApi = map[string]func(s *httpServer, c *gin.Context){
|
var httpAPI = map[string]func(s *httpServer, c *gin.Context){
|
||||||
"get_login_info": GetLoginInfo,
|
"get_login_info": GetLoginInfo,
|
||||||
"get_friend_list": GetFriendList,
|
"get_friend_list": GetFriendList,
|
||||||
"get_group_list": GetGroupList,
|
"get_group_list": GetGroupList,
|
||||||
@ -543,13 +626,16 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
|
|||||||
"get_group_member_info": GetGroupMemberInfo,
|
"get_group_member_info": GetGroupMemberInfo,
|
||||||
"get_group_file_system_info": GetGroupFileSystemInfo,
|
"get_group_file_system_info": GetGroupFileSystemInfo,
|
||||||
"get_group_root_files": GetGroupRootFiles,
|
"get_group_root_files": GetGroupRootFiles,
|
||||||
"get_group_files_by_folder": GetGroupFilesByFolderId,
|
"get_group_files_by_folder": GetGroupFilesByFolderID,
|
||||||
"get_group_file_url": GetGroupFileUrl,
|
"get_group_file_url": GetGroupFileURL,
|
||||||
|
"upload_group_file": UploadGroupFile,
|
||||||
|
"get_essence_msg_list": GetEssenceMsgList,
|
||||||
"send_msg": SendMessage,
|
"send_msg": SendMessage,
|
||||||
"send_group_msg": SendGroupMessage,
|
"send_group_msg": SendGroupMessage,
|
||||||
"send_group_forward_msg": SendGroupForwardMessage,
|
"send_group_forward_msg": SendGroupForwardMessage,
|
||||||
"send_private_msg": SendPrivateMessage,
|
"send_private_msg": SendPrivateMessage,
|
||||||
"delete_msg": DeleteMessage,
|
"delete_msg": DeleteMessage,
|
||||||
|
"delete_essence_msg": DeleteEssenceMsg,
|
||||||
"set_friend_add_request": ProcessFriendRequest,
|
"set_friend_add_request": ProcessFriendRequest,
|
||||||
"set_group_add_request": ProcessGroupRequest,
|
"set_group_add_request": ProcessGroupRequest,
|
||||||
"set_group_card": SetGroupCard,
|
"set_group_card": SetGroupCard,
|
||||||
@ -559,6 +645,7 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
|
|||||||
"set_group_whole_ban": SetWholeBan,
|
"set_group_whole_ban": SetWholeBan,
|
||||||
"set_group_name": SetGroupName,
|
"set_group_name": SetGroupName,
|
||||||
"set_group_admin": SetGroupAdmin,
|
"set_group_admin": SetGroupAdmin,
|
||||||
|
"set_essence_msg": SetEssenceMsg,
|
||||||
"set_restart": SetRestart,
|
"set_restart": SetRestart,
|
||||||
"_send_group_notice": SendGroupNotice,
|
"_send_group_notice": SendGroupNotice,
|
||||||
"set_group_leave": SetGroupLeave,
|
"set_group_leave": SetGroupLeave,
|
||||||
@ -577,6 +664,7 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
|
|||||||
"set_group_portrait": SetGroupPortrait,
|
"set_group_portrait": SetGroupPortrait,
|
||||||
"set_group_anonymous_ban": SetGroupAnonymousBan,
|
"set_group_anonymous_ban": SetGroupAnonymousBan,
|
||||||
"get_group_msg_history": GetGroupMessageHistory,
|
"get_group_msg_history": GetGroupMessageHistory,
|
||||||
|
"check_url_safely": CheckURLSafely,
|
||||||
"download_file": DownloadFile,
|
"download_file": DownloadFile,
|
||||||
".handle_quick_operation": HandleQuickOperation,
|
".handle_quick_operation": HandleQuickOperation,
|
||||||
".ocr_image": OcrImage,
|
".ocr_image": OcrImage,
|
||||||
@ -589,7 +677,7 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
|
|||||||
func (s *httpServer) ShutDown() {
|
func (s *httpServer) ShutDown() {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
if err := s.Http.Shutdown(ctx); err != nil {
|
if err := s.HTTP.Shutdown(ctx); err != nil {
|
||||||
log.Fatal("http Server Shutdown:", err)
|
log.Fatal("http Server Shutdown:", err)
|
||||||
}
|
}
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
|
@ -25,7 +25,7 @@ type webSocketServer struct {
|
|||||||
handshake string
|
handshake string
|
||||||
}
|
}
|
||||||
|
|
||||||
//WebSocketClient Websocket客户端实例
|
// WebSocketClient WebSocket客户端实例
|
||||||
type WebSocketClient struct {
|
type WebSocketClient struct {
|
||||||
conf *global.GoCQReverseWebSocketConfig
|
conf *global.GoCQReverseWebSocketConfig
|
||||||
token string
|
token string
|
||||||
@ -58,7 +58,7 @@ func (s *webSocketServer) Run(addr, authToken string, b *coolq.CQBot) {
|
|||||||
http.HandleFunc("/api", s.api)
|
http.HandleFunc("/api", s.api)
|
||||||
http.HandleFunc("/", s.any)
|
http.HandleFunc("/", s.any)
|
||||||
go func() {
|
go func() {
|
||||||
log.Infof("CQ Websocket 服务器已启动: %v", addr)
|
log.Infof("CQ WebSocket 服务器已启动: %v", addr)
|
||||||
log.Fatal(http.ListenAndServe(addr, nil))
|
log.Fatal(http.ListenAndServe(addr, nil))
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ func (c *WebSocketClient) Run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *WebSocketClient) connectAPI() {
|
func (c *WebSocketClient) connectAPI() {
|
||||||
log.Infof("开始尝试连接到反向Websocket API服务器: %v", c.conf.ReverseAPIURL)
|
log.Infof("开始尝试连接到反向WebSocket API服务器: %v", c.conf.ReverseAPIURL)
|
||||||
header := http.Header{
|
header := http.Header{
|
||||||
"X-Client-Role": []string{"API"},
|
"X-Client-Role": []string{"API"},
|
||||||
"X-Self-ID": []string{strconv.FormatInt(c.bot.Client.Uin, 10)},
|
"X-Self-ID": []string{strconv.FormatInt(c.bot.Client.Uin, 10)},
|
||||||
@ -98,20 +98,20 @@ func (c *WebSocketClient) connectAPI() {
|
|||||||
}
|
}
|
||||||
conn, _, err := websocket.DefaultDialer.Dial(c.conf.ReverseAPIURL, header)
|
conn, _, err := websocket.DefaultDialer.Dial(c.conf.ReverseAPIURL, header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("连接到反向Websocket API服务器 %v 时出现错误: %v", c.conf.ReverseAPIURL, err)
|
log.Warnf("连接到反向WebSocket API服务器 %v 时出现错误: %v", c.conf.ReverseAPIURL, err)
|
||||||
if c.conf.ReverseReconnectInterval != 0 {
|
if c.conf.ReverseReconnectInterval != 0 {
|
||||||
time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval))
|
time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval))
|
||||||
c.connectAPI()
|
c.connectAPI()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infof("已连接到反向Websocket API服务器 %v", c.conf.ReverseAPIURL)
|
log.Infof("已连接到反向WebSocket API服务器 %v", c.conf.ReverseAPIURL)
|
||||||
wrappedConn := &webSocketConn{Conn: conn}
|
wrappedConn := &webSocketConn{Conn: conn}
|
||||||
go c.listenAPI(wrappedConn, false)
|
go c.listenAPI(wrappedConn, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WebSocketClient) connectEvent() {
|
func (c *WebSocketClient) connectEvent() {
|
||||||
log.Infof("开始尝试连接到反向Websocket Event服务器: %v", c.conf.ReverseEventURL)
|
log.Infof("开始尝试连接到反向WebSocket Event服务器: %v", c.conf.ReverseEventURL)
|
||||||
header := http.Header{
|
header := http.Header{
|
||||||
"X-Client-Role": []string{"Event"},
|
"X-Client-Role": []string{"Event"},
|
||||||
"X-Self-ID": []string{strconv.FormatInt(c.bot.Client.Uin, 10)},
|
"X-Self-ID": []string{strconv.FormatInt(c.bot.Client.Uin, 10)},
|
||||||
@ -122,7 +122,7 @@ func (c *WebSocketClient) connectEvent() {
|
|||||||
}
|
}
|
||||||
conn, _, err := websocket.DefaultDialer.Dial(c.conf.ReverseEventURL, header)
|
conn, _, err := websocket.DefaultDialer.Dial(c.conf.ReverseEventURL, header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("连接到反向Websocket Event服务器 %v 时出现错误: %v", c.conf.ReverseEventURL, err)
|
log.Warnf("连接到反向WebSocket Event服务器 %v 时出现错误: %v", c.conf.ReverseEventURL, err)
|
||||||
if c.conf.ReverseReconnectInterval != 0 {
|
if c.conf.ReverseReconnectInterval != 0 {
|
||||||
time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval))
|
time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval))
|
||||||
c.connectEvent()
|
c.connectEvent()
|
||||||
@ -134,15 +134,15 @@ func (c *WebSocketClient) connectEvent() {
|
|||||||
c.bot.Client.Uin, time.Now().Unix())
|
c.bot.Client.Uin, time.Now().Unix())
|
||||||
err = conn.WriteMessage(websocket.TextMessage, []byte(handshake))
|
err = conn.WriteMessage(websocket.TextMessage, []byte(handshake))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("反向Websocket 握手时出现错误: %v", err)
|
log.Warnf("反向WebSocket 握手时出现错误: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("已连接到反向Websocket Event服务器 %v", c.conf.ReverseEventURL)
|
log.Infof("已连接到反向WebSocket Event服务器 %v", c.conf.ReverseEventURL)
|
||||||
c.eventConn = &webSocketConn{Conn: conn}
|
c.eventConn = &webSocketConn{Conn: conn}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WebSocketClient) connectUniversal() {
|
func (c *WebSocketClient) connectUniversal() {
|
||||||
log.Infof("开始尝试连接到反向Websocket Universal服务器: %v", c.conf.ReverseURL)
|
log.Infof("开始尝试连接到反向WebSocket Universal服务器: %v", c.conf.ReverseURL)
|
||||||
header := http.Header{
|
header := http.Header{
|
||||||
"X-Client-Role": []string{"Universal"},
|
"X-Client-Role": []string{"Universal"},
|
||||||
"X-Self-ID": []string{strconv.FormatInt(c.bot.Client.Uin, 10)},
|
"X-Self-ID": []string{strconv.FormatInt(c.bot.Client.Uin, 10)},
|
||||||
@ -153,7 +153,7 @@ func (c *WebSocketClient) connectUniversal() {
|
|||||||
}
|
}
|
||||||
conn, _, err := websocket.DefaultDialer.Dial(c.conf.ReverseURL, header)
|
conn, _, err := websocket.DefaultDialer.Dial(c.conf.ReverseURL, header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("连接到反向Websocket Universal服务器 %v 时出现错误: %v", c.conf.ReverseURL, err)
|
log.Warnf("连接到反向WebSocket Universal服务器 %v 时出现错误: %v", c.conf.ReverseURL, err)
|
||||||
if c.conf.ReverseReconnectInterval != 0 {
|
if c.conf.ReverseReconnectInterval != 0 {
|
||||||
time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval))
|
time.Sleep(time.Millisecond * time.Duration(c.conf.ReverseReconnectInterval))
|
||||||
c.connectUniversal()
|
c.connectUniversal()
|
||||||
@ -165,7 +165,7 @@ func (c *WebSocketClient) connectUniversal() {
|
|||||||
c.bot.Client.Uin, time.Now().Unix())
|
c.bot.Client.Uin, time.Now().Unix())
|
||||||
err = conn.WriteMessage(websocket.TextMessage, []byte(handshake))
|
err = conn.WriteMessage(websocket.TextMessage, []byte(handshake))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("反向Websocket 握手时出现错误: %v", err)
|
log.Warnf("反向WebSocket 握手时出现错误: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wrappedConn := &webSocketConn{Conn: conn}
|
wrappedConn := &webSocketConn{Conn: conn}
|
||||||
@ -195,7 +195,7 @@ func (c *WebSocketClient) listenAPI(conn *webSocketConn, u bool) {
|
|||||||
|
|
||||||
func (c *WebSocketClient) onBotPushEvent(m coolq.MSG) {
|
func (c *WebSocketClient) onBotPushEvent(m coolq.MSG) {
|
||||||
if c.eventConn != nil {
|
if c.eventConn != nil {
|
||||||
log.Debugf("向WS服务器 %v 推送Event: %v", c.eventConn.RemoteAddr().String(), m.ToJson())
|
log.Debugf("向WS服务器 %v 推送Event: %v", c.eventConn.RemoteAddr().String(), m.ToJSON())
|
||||||
conn := c.eventConn
|
conn := c.eventConn
|
||||||
conn.Lock()
|
conn.Lock()
|
||||||
defer conn.Unlock()
|
defer conn.Unlock()
|
||||||
@ -210,7 +210,7 @@ func (c *WebSocketClient) onBotPushEvent(m coolq.MSG) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if c.universalConn != nil {
|
if c.universalConn != nil {
|
||||||
log.Debugf("向WS服务器 %v 推送Event: %v", c.universalConn.RemoteAddr().String(), m.ToJson())
|
log.Debugf("向WS服务器 %v 推送Event: %v", c.universalConn.RemoteAddr().String(), m.ToJSON())
|
||||||
conn := c.universalConn
|
conn := c.universalConn
|
||||||
conn.Lock()
|
conn.Lock()
|
||||||
defer conn.Unlock()
|
defer conn.Unlock()
|
||||||
@ -230,7 +230,7 @@ func (s *webSocketServer) event(w http.ResponseWriter, r *http.Request) {
|
|||||||
if s.token != "" {
|
if s.token != "" {
|
||||||
if auth := r.URL.Query().Get("access_token"); auth != s.token {
|
if auth := r.URL.Query().Get("access_token"); auth != s.token {
|
||||||
if auth := strings.SplitN(r.Header.Get("Authorization"), " ", 2); len(auth) != 2 || auth[1] != s.token {
|
if auth := strings.SplitN(r.Header.Get("Authorization"), " ", 2); len(auth) != 2 || auth[1] != s.token {
|
||||||
log.Warnf("已拒绝 %v 的 Websocket 请求: Token鉴权失败", r.RemoteAddr)
|
log.Warnf("已拒绝 %v 的 WebSocket 请求: Token鉴权失败", r.RemoteAddr)
|
||||||
w.WriteHeader(401)
|
w.WriteHeader(401)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -238,17 +238,17 @@ func (s *webSocketServer) event(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
c, err := upgrader.Upgrade(w, r, nil)
|
c, err := upgrader.Upgrade(w, r, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("处理 Websocket 请求时出现错误: %v", err)
|
log.Warnf("处理 WebSocket 请求时出现错误: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = c.WriteMessage(websocket.TextMessage, []byte(s.handshake))
|
err = c.WriteMessage(websocket.TextMessage, []byte(s.handshake))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("Websocket 握手时出现错误: %v", err)
|
log.Warnf("WebSocket 握手时出现错误: %v", err)
|
||||||
c.Close()
|
c.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("接受 Websocket 连接: %v (/event)", r.RemoteAddr)
|
log.Infof("接受 WebSocket 连接: %v (/event)", r.RemoteAddr)
|
||||||
|
|
||||||
conn := &webSocketConn{Conn: c}
|
conn := &webSocketConn{Conn: c}
|
||||||
|
|
||||||
@ -261,7 +261,7 @@ func (s *webSocketServer) api(w http.ResponseWriter, r *http.Request) {
|
|||||||
if s.token != "" {
|
if s.token != "" {
|
||||||
if auth := r.URL.Query().Get("access_token"); auth != s.token {
|
if auth := r.URL.Query().Get("access_token"); auth != s.token {
|
||||||
if auth := strings.SplitN(r.Header.Get("Authorization"), " ", 2); len(auth) != 2 || auth[1] != s.token {
|
if auth := strings.SplitN(r.Header.Get("Authorization"), " ", 2); len(auth) != 2 || auth[1] != s.token {
|
||||||
log.Warnf("已拒绝 %v 的 Websocket 请求: Token鉴权失败", r.RemoteAddr)
|
log.Warnf("已拒绝 %v 的 WebSocket 请求: Token鉴权失败", r.RemoteAddr)
|
||||||
w.WriteHeader(401)
|
w.WriteHeader(401)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -269,10 +269,10 @@ func (s *webSocketServer) api(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
c, err := upgrader.Upgrade(w, r, nil)
|
c, err := upgrader.Upgrade(w, r, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("处理 Websocket 请求时出现错误: %v", err)
|
log.Warnf("处理 WebSocket 请求时出现错误: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infof("接受 Websocket 连接: %v (/api)", r.RemoteAddr)
|
log.Infof("接受 WebSocket 连接: %v (/api)", r.RemoteAddr)
|
||||||
conn := &webSocketConn{Conn: c}
|
conn := &webSocketConn{Conn: c}
|
||||||
go s.listenAPI(conn)
|
go s.listenAPI(conn)
|
||||||
}
|
}
|
||||||
@ -281,7 +281,7 @@ func (s *webSocketServer) any(w http.ResponseWriter, r *http.Request) {
|
|||||||
if s.token != "" {
|
if s.token != "" {
|
||||||
if auth := r.URL.Query().Get("access_token"); auth != s.token {
|
if auth := r.URL.Query().Get("access_token"); auth != s.token {
|
||||||
if auth := strings.SplitN(r.Header.Get("Authorization"), " ", 2); len(auth) != 2 || auth[1] != s.token {
|
if auth := strings.SplitN(r.Header.Get("Authorization"), " ", 2); len(auth) != 2 || auth[1] != s.token {
|
||||||
log.Warnf("已拒绝 %v 的 Websocket 请求: Token鉴权失败", r.RemoteAddr)
|
log.Warnf("已拒绝 %v 的 WebSocket 请求: Token鉴权失败", r.RemoteAddr)
|
||||||
w.WriteHeader(401)
|
w.WriteHeader(401)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -289,16 +289,16 @@ func (s *webSocketServer) any(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
c, err := upgrader.Upgrade(w, r, nil)
|
c, err := upgrader.Upgrade(w, r, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("处理 Websocket 请求时出现错误: %v", err)
|
log.Warnf("处理 WebSocket 请求时出现错误: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = c.WriteMessage(websocket.TextMessage, []byte(s.handshake))
|
err = c.WriteMessage(websocket.TextMessage, []byte(s.handshake))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("Websocket 握手时出现错误: %v", err)
|
log.Warnf("WebSocket 握手时出现错误: %v", err)
|
||||||
c.Close()
|
c.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infof("接受 Websocket 连接: %v (/)", r.RemoteAddr)
|
log.Infof("接受 WebSocket 连接: %v (/)", r.RemoteAddr)
|
||||||
conn := &webSocketConn{Conn: c}
|
conn := &webSocketConn{Conn: c}
|
||||||
s.eventConn = append(s.eventConn, conn)
|
s.eventConn = append(s.eventConn, conn)
|
||||||
s.listenAPI(conn)
|
s.listenAPI(conn)
|
||||||
@ -353,9 +353,9 @@ func (s *webSocketServer) onBotPushEvent(m coolq.MSG) {
|
|||||||
defer s.eventConnMutex.Unlock()
|
defer s.eventConnMutex.Unlock()
|
||||||
for i, l := 0, len(s.eventConn); i < l; i++ {
|
for i, l := 0, len(s.eventConn); i < l; i++ {
|
||||||
conn := s.eventConn[i]
|
conn := s.eventConn[i]
|
||||||
log.Debugf("向WS客户端 %v 推送Event: %v", conn.RemoteAddr().String(), m.ToJson())
|
log.Debugf("向WS客户端 %v 推送Event: %v", conn.RemoteAddr().String(), m.ToJSON())
|
||||||
conn.Lock()
|
conn.Lock()
|
||||||
if err := conn.WriteMessage(websocket.TextMessage, []byte(m.ToJson())); err != nil {
|
if err := conn.WriteMessage(websocket.TextMessage, []byte(m.ToJSON())); err != nil {
|
||||||
_ = conn.Close()
|
_ = conn.Close()
|
||||||
next := i + 1
|
next := i + 1
|
||||||
if next >= l {
|
if next >= l {
|
||||||
@ -557,10 +557,13 @@ var wsAPI = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
|||||||
return bot.CQGetGroupRootFiles(p.Get("group_id").Int())
|
return bot.CQGetGroupRootFiles(p.Get("group_id").Int())
|
||||||
},
|
},
|
||||||
"get_group_files_by_folder": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"get_group_files_by_folder": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetGroupFilesByFolderId(p.Get("group_id").Int(), p.Get("folder_id").Str)
|
return bot.CQGetGroupFilesByFolderID(p.Get("group_id").Int(), p.Get("folder_id").Str)
|
||||||
},
|
},
|
||||||
"get_group_file_url": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"get_group_file_url": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetGroupFileUrl(p.Get("group_id").Int(), p.Get("file_id").Str, int32(p.Get("busid").Int()))
|
return bot.CQGetGroupFileURL(p.Get("group_id").Int(), p.Get("file_id").Str, int32(p.Get("busid").Int()))
|
||||||
|
},
|
||||||
|
"upload_group_file": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
|
return bot.CQUploadGroupFile(p.Get("group_id").Int(), p.Get("file").Str, p.Get("name").Str, p.Get("folder").Str)
|
||||||
},
|
},
|
||||||
"get_group_msg_history": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"get_group_msg_history": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetGroupMessageHistory(p.Get("group_id").Int(), p.Get("message_seq").Int())
|
return bot.CQGetGroupMessageHistory(p.Get("group_id").Int(), p.Get("message_seq").Int())
|
||||||
@ -589,6 +592,18 @@ var wsAPI = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
|||||||
"set_group_portrait": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"set_group_portrait": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQSetGroupPortrait(p.Get("group_id").Int(), p.Get("file").String(), p.Get("cache").String())
|
return bot.CQSetGroupPortrait(p.Get("group_id").Int(), p.Get("file").String(), p.Get("cache").String())
|
||||||
},
|
},
|
||||||
|
"set_essence_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
|
return bot.CQSetEssenceMessage(int32(p.Get("message_id").Int()))
|
||||||
|
},
|
||||||
|
"delete_essence_msg": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
|
return bot.CQDeleteEssenceMessage(int32(p.Get("message_id").Int()))
|
||||||
|
},
|
||||||
|
"get_essence_msg_list": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
|
return bot.CQGetEssenceMessageList(p.Get("group_id").Int())
|
||||||
|
},
|
||||||
|
"check_url_safely": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
|
return bot.CQCheckURLSafely(p.Get("url").String())
|
||||||
|
},
|
||||||
"set_group_anonymous_ban": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
"set_group_anonymous_ban": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
obj := p.Get("anonymous")
|
obj := p.Get("anonymous")
|
||||||
flag := p.Get("anonymous_flag")
|
flag := p.Get("anonymous_flag")
|
||||||
|
Reference in New Issue
Block a user