mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-06-30 03:43:25 +00:00
Compare commits
154 Commits
onebot.v12
...
v1.2.0
Author | SHA1 | Date | |
---|---|---|---|
5cbbcda2c2 | |||
6ac7a8f0ae | |||
bd785d3894 | |||
642c74688c | |||
517d323953 | |||
07214e396e | |||
1c34643f4f | |||
f16d72f0ca | |||
9e6d7b7650 | |||
417a0f256a | |||
77b54fca20 | |||
fd6ef4a2b8 | |||
79a194fbb0 | |||
f8354ec082 | |||
d85d697fc2 | |||
da9f03fa47 | |||
977030e814 | |||
5db03c7092 | |||
3b99a825eb | |||
94a3ff5dae | |||
0714aac1f0 | |||
ca20a3d6bf | |||
ce119b7ddf | |||
a6fd7de65a | |||
8ea182a4c3 | |||
99cdf9247a | |||
837e163ef6 | |||
fe92bb54df | |||
7cae9829a8 | |||
3992dd40c5 | |||
1bd0bb9ae2 | |||
b8527721c2 | |||
14539adcb8 | |||
1911b5d245 | |||
75ad7aa45c | |||
cffdfd8181 | |||
99e5cb6c6b | |||
09ab2169d9 | |||
2b1d9c21cb | |||
998fda54a2 | |||
5cb8548487 | |||
88f5db89a8 | |||
7c813f8579 | |||
7adbbd6f81 | |||
04cbf7b5d7 | |||
dae03784cc | |||
f466ca7a72 | |||
13215f23c5 | |||
19dd37a938 | |||
a3ad233cd9 | |||
06461960a9 | |||
aa3a5d28da | |||
a4c131e04a | |||
526391e613 | |||
2901fd14bb | |||
16a2ff050e | |||
6cf8030d3c | |||
9c1390c75c | |||
b958046a27 | |||
19906eba36 | |||
8e6e79f734 | |||
9b9ecd6a41 | |||
c8e480d12f | |||
5bf64ee743 | |||
bad3c86912 | |||
2af55d6a67 | |||
42606a825d | |||
1ed675d5bf | |||
91b4394d9b | |||
0b90074a48 | |||
55cb80dccc | |||
54995fc101 | |||
8acc9f39c2 | |||
13325634c0 | |||
7b2d1fd573 | |||
637d46f282 | |||
1e42b2c450 | |||
749cde2a6d | |||
0f0e711111 | |||
233e276d6a | |||
1ab1cba84c | |||
268ac07271 | |||
c486c254d8 | |||
6ad62a2642 | |||
9762a66ba2 | |||
43c6e3dcf5 | |||
6a17c70689 | |||
d70d66d6d7 | |||
43ff36e3e8 | |||
008d546f1a | |||
82ecf19480 | |||
588728aa62 | |||
ddfe24f6db | |||
5d492c7b38 | |||
d77dc9ef64 | |||
98c2a2218a | |||
3ccc2c6087 | |||
e6e30c0a10 | |||
1815ed769d | |||
cc4a981c90 | |||
174d99f94b | |||
dd33cd9598 | |||
4ad7da7a9a | |||
73bd3c92f3 | |||
3a60e081f2 | |||
1d0b513b96 | |||
0312f05f6e | |||
b85c2ecb07 | |||
0b106d8ef5 | |||
40e4f40525 | |||
8124879c77 | |||
3f4630b6d1 | |||
6a291840d7 | |||
a0e3291725 | |||
069f9d1335 | |||
91facb54ce | |||
414f067431 | |||
a704009484 | |||
278d6260c8 | |||
485d5c0df9 | |||
e3fd0771ae | |||
8cb8428785 | |||
95adb403e9 | |||
84dcf46ae2 | |||
bef2ba6f08 | |||
04c4446496 | |||
c3840a5988 | |||
291942357b | |||
c24aa8d8a0 | |||
07b1e6b72e | |||
377d7af2c1 | |||
d867451ef6 | |||
c4d703dc86 | |||
dbddd18e3a | |||
1b8ebf55a5 | |||
63d9ffa90b | |||
2830676e3b | |||
ddd52ca933 | |||
72173337ae | |||
9b0fae6346 | |||
4ceacc38d5 | |||
1dba273b61 | |||
cb1604a098 | |||
0c9f7a1f8f | |||
edfcd41ed6 | |||
811cfdca98 | |||
0e5f3ed555 | |||
90fa530a02 | |||
c80adf5795 | |||
debc1ed1ae | |||
43dd9aa76d | |||
9c0525b3d4 | |||
cf717ad762 | |||
6b3aabd9af |
4
.github/ISSUE_TEMPLATE/bug-report.yaml
vendored
4
.github/ISSUE_TEMPLATE/bug-report.yaml
vendored
@ -101,11 +101,13 @@ body:
|
||||
label: 使用协议
|
||||
description: 选择使用的协议
|
||||
options:
|
||||
- 0 | iPad
|
||||
- 0 | Default
|
||||
- 1 | Android Phone
|
||||
- 2 | Android Watch
|
||||
- 3 | MacOS
|
||||
- 4 | 企点
|
||||
- 5 | iPad
|
||||
- 6 | aPad
|
||||
validations:
|
||||
required: true
|
||||
|
||||
|
20
.github/workflows/build_docker_image.yml
vendored
20
.github/workflows/build_docker_image.yml
vendored
@ -4,6 +4,7 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- 'master'
|
||||
- 'dev'
|
||||
# Sequence of patterns matched against refs/tags
|
||||
tags:
|
||||
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
|
||||
@ -20,10 +21,10 @@ jobs:
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set time zone
|
||||
uses: szenius/set-timezone@v1.0
|
||||
uses: szenius/set-timezone@v1.1
|
||||
with:
|
||||
timezoneLinux: "Asia/Shanghai"
|
||||
timezoneMacos: "Asia/Shanghai"
|
||||
@ -37,7 +38,7 @@ jobs:
|
||||
# password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Login to GHCR
|
||||
uses: docker/login-action@v1
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
@ -45,7 +46,7 @@ jobs:
|
||||
|
||||
- name: Extract metadata (tags, labels) for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v3
|
||||
uses: docker/metadata-action@v4
|
||||
with:
|
||||
images: |
|
||||
ghcr.io/${{ github.repository }}
|
||||
@ -61,16 +62,19 @@ jobs:
|
||||
type=semver,pattern={{major}}
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
uses: docker/setup-qemu-action@v2
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Build and push
|
||||
id: docker_build
|
||||
uses: docker/build-push-action@v2
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/s390x
|
||||
|
14
.github/workflows/ci.yml
vendored
14
.github/workflows/ci.yml
vendored
@ -24,18 +24,12 @@ jobs:
|
||||
goarch: "386"
|
||||
fail-fast: true
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup Go environment
|
||||
uses: actions/setup-go@v2.1.3
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
cache: true
|
||||
go-version: '1.20'
|
||||
- name: Cache downloaded module
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: |
|
||||
~/.cache/go-build
|
||||
~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ matrix.goos }}-${{ matrix.goarch }}-${{ hashFiles('**/go.sum') }}
|
||||
- name: Build binary file
|
||||
env:
|
||||
GOOS: ${{ matrix.goos }}
|
||||
@ -49,7 +43,7 @@ jobs:
|
||||
export LD_FLAGS="-w -s -X github.com/Mrs4s/go-cqhttp/internal/base.Version=${COMMIT_ID::7}"
|
||||
go build -o "output/$BINARY_NAME" -trimpath -ldflags "$LD_FLAGS" .
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v3
|
||||
if: ${{ !github.head_ref }}
|
||||
with:
|
||||
name: ${{ matrix.goos }}_${{ matrix.goarch }}
|
||||
|
21
.github/workflows/close_pr.yml
vendored
Normal file
21
.github/workflows/close_pr.yml
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
name: Check and Close Invalid PR
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [opened, reopened]
|
||||
|
||||
jobs:
|
||||
# This workflow closes invalid PR
|
||||
close_pr:
|
||||
# The type of runner that the job will run on
|
||||
runs-on: ubuntu-latest
|
||||
permissions: write-all
|
||||
|
||||
# Steps represent a sequence of tasks that will be executed as part of the job
|
||||
steps:
|
||||
- name: Close PR if it is not pointed to dev branch
|
||||
if: github.event.pull_request.base.ref != 'dev'
|
||||
uses: superbrothers/close-pull-request@v3
|
||||
with:
|
||||
# Optional. Post a issue comment just before closing a pull request.
|
||||
comment: "Invalid PR to `non-dev` branch `${{ github.event.pull_request.base.ref }}`."
|
6
.github/workflows/golint.yml
vendored
6
.github/workflows/golint.yml
vendored
@ -7,15 +7,15 @@ jobs:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Go environment
|
||||
uses: actions/setup-go@v2.1.3
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '1.20'
|
||||
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
with:
|
||||
version: latest
|
||||
|
||||
|
15
.github/workflows/release.yml
vendored
15
.github/workflows/release.yml
vendored
@ -1,4 +1,4 @@
|
||||
name: release
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
@ -10,20 +10,21 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2.3.4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
run: |
|
||||
git version
|
||||
git clone "${{ github.event.repository.html_url }}" /home/runner/work/go-cqhttp/go-cqhttp
|
||||
git checkout "${{ github.ref }}"
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '1.20'
|
||||
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
uses: goreleaser/goreleaser-action@v4
|
||||
with:
|
||||
version: latest
|
||||
args: release --rm-dist
|
||||
args: release --clean
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -12,6 +12,10 @@ internal/btree/*.db
|
||||
|
||||
# binary builds
|
||||
go-cqhttp
|
||||
*.exe
|
||||
|
||||
# macos
|
||||
.DS_Store
|
||||
|
||||
# windwos rc
|
||||
*.syso
|
||||
|
@ -56,6 +56,7 @@ run:
|
||||
skip-dirs:
|
||||
- db
|
||||
- cmd/api-generator
|
||||
- internal/encryption
|
||||
tests: true
|
||||
|
||||
# output configuration options
|
||||
|
@ -3,6 +3,9 @@ env:
|
||||
before:
|
||||
hooks:
|
||||
- go mod tidy
|
||||
- go install github.com/tc-hib/go-winres@latest
|
||||
- go generate winres/init.go
|
||||
- go-winres make
|
||||
release:
|
||||
draft: true
|
||||
discussion_category_name: General
|
||||
|
@ -21,7 +21,8 @@ RUN chmod +x /docker-entrypoint.sh && \
|
||||
ffmpeg \
|
||||
coreutils \
|
||||
shadow \
|
||||
su-exec && \
|
||||
su-exec \
|
||||
tzdata && \
|
||||
rm -rf /var/cache/apk/* && \
|
||||
mkdir -p /app && \
|
||||
mkdir -p /data && \
|
||||
@ -42,3 +43,4 @@ WORKDIR /data
|
||||
VOLUME [ "/data" ]
|
||||
|
||||
ENTRYPOINT [ "/docker-entrypoint.sh" ]
|
||||
CMD [ "/app/cqhttp" ]
|
||||
|
@ -1,6 +1,6 @@
|
||||
<p align="center">
|
||||
<a href="https://ishkong.github.io/go-cqhttp-docs/">
|
||||
<img src="https://user-images.githubusercontent.com/25968335/120111974-8abef880-c139-11eb-99cd-fa928348b198.png" width="200" height="200" alt="go-cqhttp">
|
||||
<img src="winres/icon.png" width="200" height="200" alt="go-cqhttp">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
@ -42,6 +42,10 @@ _✨ 基于 [Mirai](https://github.com/mamoe/mirai) 以及 [MiraiGo](https://git
|
||||
<a href="https://github.com/Mrs4s/go-cqhttp/blob/master/CONTRIBUTING.md">参与贡献</a>
|
||||
</p>
|
||||
|
||||
## 重要信息
|
||||
由于QQ官方针对协议库的围追堵截, 不断更新加密方案, 我们已无力继续维护此项目.
|
||||
建议Bot开发者尽快迁移至无头NTQQ项目 -> https://chronocat.vercel.app/blog/0050
|
||||
参考issue: https://github.com/Mrs4s/go-cqhttp/issues/2471
|
||||
|
||||
## 兼容性
|
||||
go-cqhttp 兼容 [OneBot-v11](https://github.com/botuniverse/onebot-11) 绝大多数内容,并在其基础上做了一些扩展,详情请看 go-cqhttp 的文档。
|
||||
|
@ -10,11 +10,17 @@ import (
|
||||
"go/token"
|
||||
"io"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var supported = flag.Bool("supported", false, "genRouter supported.go")
|
||||
var output = flag.String("o", "", "output file")
|
||||
var pkg = flag.String("pkg", "", "package name")
|
||||
var src = flag.String("path", "", "source file")
|
||||
|
||||
type Param struct {
|
||||
Name string
|
||||
Type string
|
||||
@ -23,7 +29,6 @@ type Param struct {
|
||||
|
||||
type Router struct {
|
||||
Func string
|
||||
Version []uint16
|
||||
Path []string
|
||||
PathV11 []string // v11 only
|
||||
PathV12 []string // v12 only
|
||||
@ -44,70 +49,43 @@ func (g *generator) WriteString(s string) {
|
||||
io.WriteString(g.out, s)
|
||||
}
|
||||
|
||||
func (g *generator) generate(routers []Router) {
|
||||
var actions []string // for onebot v12 get_supported_actions
|
||||
for _, router := range routers {
|
||||
if len(router.PathV12) > 0 {
|
||||
actions = append(actions, router.PathV12...)
|
||||
}
|
||||
if len(router.Path) > 0 {
|
||||
actions = append(actions, router.Path...)
|
||||
}
|
||||
}
|
||||
for i := range actions {
|
||||
actions[i] = `"` + actions[i] + `"`
|
||||
}
|
||||
func (g *generator) writef(format string, a ...any) {
|
||||
fmt.Fprintf(g.out, format, a...)
|
||||
}
|
||||
|
||||
// TODO: v12 和 all 的 switch-case 由常量改为数组寻址, 以利用 get_supported_actions
|
||||
func (g *generator) header() {
|
||||
g.WriteString("// Code generated by cmd/api-generator. DO NOT EDIT.\n\n")
|
||||
g.WriteString("package api\n\nimport (\n\n")
|
||||
g.writef("package %s\n\n", *pkg)
|
||||
}
|
||||
|
||||
func (g *generator) genRouter(routers []Router) {
|
||||
g.WriteString("import (\n\n")
|
||||
g.WriteString("\"github.com/Mrs4s/go-cqhttp/coolq\"\n")
|
||||
g.WriteString("\"github.com/Mrs4s/go-cqhttp/global\"\n")
|
||||
g.WriteString("\"github.com/Mrs4s/go-cqhttp/pkg/onebot\"\n")
|
||||
g.WriteString(")\n\n")
|
||||
g.WriteString(fmt.Sprintf(`func (c *Caller) call(action string, version uint16, p Getter) global.MSG {
|
||||
var converter coolq.IDConverter = func(id any) any {
|
||||
return coolq.ConvertIDWithVersion(id,version)
|
||||
}
|
||||
if version == 12 {
|
||||
if action == "get_supported_actions" {
|
||||
return coolq.OK([]string{%v})
|
||||
}
|
||||
g.WriteString(`func (c *Caller) call(action string, spec *onebot.Spec, p Getter) global.MSG {`)
|
||||
genVer := func(path int) {
|
||||
g.writef(`if spec.Version == %d {
|
||||
switch action {
|
||||
`, strings.Join(actions, ",")))
|
||||
`, path)
|
||||
for _, router := range routers {
|
||||
g.router(router, PathV12)
|
||||
g.router(router, path)
|
||||
}
|
||||
io.WriteString(g.out, `}}`)
|
||||
io.WriteString(g.out, "\n")
|
||||
g.WriteString(`if version == 11 {
|
||||
switch action {
|
||||
`)
|
||||
for _, router := range routers {
|
||||
g.router(router, PathV11)
|
||||
g.WriteString("}}\n")
|
||||
}
|
||||
io.WriteString(g.out, `}}`)
|
||||
io.WriteString(g.out, "\n")
|
||||
io.WriteString(g.out, "switch action {\n")
|
||||
genVer(PathV11)
|
||||
genVer(PathV12)
|
||||
// generic path
|
||||
g.WriteString("switch action {\n")
|
||||
for _, router := range routers {
|
||||
g.router(router, PathAll)
|
||||
}
|
||||
io.WriteString(g.out, `}`)
|
||||
io.WriteString(g.out, "\n")
|
||||
io.WriteString(g.out, "return coolq.Failed(404, \"API_NOT_FOUND\", \"API不存在\")}")
|
||||
g.WriteString("}\n")
|
||||
g.WriteString("return coolq.Failed(404, \"API_NOT_FOUND\", \"API不存在\")}")
|
||||
}
|
||||
|
||||
func (g *generator) router(router Router, pathVersion int) {
|
||||
/*
|
||||
checkVersion := func(v uint16) bool {
|
||||
for _, ver := range router.Version {
|
||||
if ver == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
*/
|
||||
|
||||
path := router.Path
|
||||
if pathVersion == PathV11 {
|
||||
path = router.PathV11
|
||||
@ -128,26 +106,17 @@ func (g *generator) router(router Router, pathVersion int) {
|
||||
}
|
||||
g.WriteString(":\n")
|
||||
|
||||
if len(router.Version) == 1 { // 目前来说只需要判断一个版本的情况
|
||||
check := make([]string, 0, len(router.Version))
|
||||
for _, ver := range router.Version {
|
||||
check = append(check, fmt.Sprintf("version != %v", ver))
|
||||
}
|
||||
fmt.Fprintf(g.out, "if %v {\n", strings.Join(check, " && "))
|
||||
fmt.Fprintf(g.out, "return coolq.Failed(405, \"VERSION_ERROR\", \"API版本不匹配\")}\n")
|
||||
}
|
||||
|
||||
for i, p := range router.Params {
|
||||
if p.Name == "version" || p.Name == "converter" {
|
||||
if p.Type == "*onebot.Spec" {
|
||||
continue
|
||||
}
|
||||
if p.Default == "" {
|
||||
v := "p.Get(" + strconv.Quote(p.Name) + ")"
|
||||
fmt.Fprintf(g.out, "p%d := %s\n", i, conv(v, p.Type))
|
||||
g.writef("p%d := %s\n", i, conv(v, p.Type))
|
||||
} else {
|
||||
fmt.Fprintf(g.out, "p%d := %s\n", i, p.Default)
|
||||
fmt.Fprintf(g.out, "if pt := p.Get(%s); pt.Exists() {\n", strconv.Quote(p.Name))
|
||||
fmt.Fprintf(g.out, "p%d = %s\n}\n", i, conv("pt", p.Type))
|
||||
g.writef("p%d := %s\n", i, p.Default)
|
||||
g.writef("if pt := p.Get(%s); pt.Exists() {\n", strconv.Quote(p.Name))
|
||||
g.writef("p%d = %s\n}\n", i, conv("pt", p.Type))
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,15 +125,11 @@ func (g *generator) router(router Router, pathVersion int) {
|
||||
if i != 0 {
|
||||
g.WriteString(", ")
|
||||
}
|
||||
if p.Name == "version" {
|
||||
fmt.Fprintf(g.out, "version")
|
||||
if p.Type == "*onebot.Spec" {
|
||||
g.WriteString("spec")
|
||||
continue
|
||||
}
|
||||
if p.Name == "converter" {
|
||||
fmt.Fprintf(g.out, "converter")
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(g.out, "p%d", i)
|
||||
g.writef("p%d", i)
|
||||
}
|
||||
g.WriteString(")\n")
|
||||
}
|
||||
@ -172,8 +137,8 @@ func (g *generator) router(router Router, pathVersion int) {
|
||||
func conv(v, t string) string {
|
||||
switch t {
|
||||
default:
|
||||
panic("unknown type: " + t)
|
||||
case "gjson.Result", "IDConverter":
|
||||
panic("unsupported type: " + t)
|
||||
case "gjson.Result", "*onebot.Spec":
|
||||
return v
|
||||
case "int64":
|
||||
return v + ".Int()"
|
||||
@ -194,7 +159,6 @@ func conv(v, t string) string {
|
||||
|
||||
func main() {
|
||||
var routers []Router
|
||||
src := flag.String("path", "", "source file")
|
||||
flag.Parse()
|
||||
fset := token.NewFileSet()
|
||||
for _, s := range strings.Split(*src, ",") {
|
||||
@ -206,23 +170,15 @@ func main() {
|
||||
for _, decl := range file.Decls {
|
||||
switch decl := decl.(type) {
|
||||
case *ast.FuncDecl:
|
||||
if !decl.Name.IsExported() || decl.Recv == nil {
|
||||
continue
|
||||
}
|
||||
if st, ok := decl.Recv.List[0].Type.(*ast.StarExpr); !ok || st.X.(*ast.Ident).Name != "CQBot" {
|
||||
if !decl.Name.IsExported() || decl.Recv == nil ||
|
||||
typeName(decl.Recv.List[0].Type) != "*CQBot" {
|
||||
continue
|
||||
}
|
||||
router := Router{Func: decl.Name.Name}
|
||||
|
||||
// compute params
|
||||
for _, p := range decl.Type.Params.List {
|
||||
var typ string
|
||||
switch t := p.Type.(type) {
|
||||
case *ast.Ident:
|
||||
typ = t.Name
|
||||
case *ast.SelectorExpr:
|
||||
typ = t.X.(*ast.Ident).Name + "." + t.Sel.Name
|
||||
}
|
||||
typ := typeName(p.Type)
|
||||
for _, name := range p.Names {
|
||||
router.Params = append(router.Params, Param{Name: snakecase(name.Name), Type: typ})
|
||||
}
|
||||
@ -259,13 +215,6 @@ func main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
case "version":
|
||||
version := strings.Split(args, ",")
|
||||
for _, v := range version {
|
||||
if i, err := strconv.ParseUint(v, 10, 16); err == nil {
|
||||
router.Version = append(router.Version, uint16(i))
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Slice(router.Path, func(i, j int) bool {
|
||||
return router.Path[i] < router.Path[j]
|
||||
@ -304,12 +253,17 @@ func main() {
|
||||
|
||||
out := new(bytes.Buffer)
|
||||
g := &generator{out: out}
|
||||
g.generate(routers)
|
||||
g.header()
|
||||
if *supported {
|
||||
g.genSupported(routers)
|
||||
} else {
|
||||
g.genRouter(routers)
|
||||
}
|
||||
source, err := format.Source(out.Bytes())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = os.WriteFile("api.go", source, 0o644)
|
||||
err = os.WriteFile(*output, source, 0o644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -328,7 +282,7 @@ func unquote(s string) string {
|
||||
func parseMap(input string, sep string) map[string]string {
|
||||
out := make(map[string]string)
|
||||
for _, arg := range strings.Split(input, ",") {
|
||||
k, v, ok := cut(arg, sep)
|
||||
k, v, ok := strings.Cut(arg, sep)
|
||||
if !ok {
|
||||
out[k] = "true"
|
||||
}
|
||||
@ -346,20 +300,13 @@ func match(text string) (string, string) {
|
||||
return "", ""
|
||||
}
|
||||
text = strings.Trim(text, "@)")
|
||||
cmd, args, ok := cut(text, "(")
|
||||
cmd, args, ok := strings.Cut(text, "(")
|
||||
if !ok {
|
||||
return "", ""
|
||||
}
|
||||
return cmd, unquote(args)
|
||||
}
|
||||
|
||||
func cut(s, sep string) (before, after string, found bool) {
|
||||
if i := strings.Index(s, sep); i >= 0 {
|
||||
return s[:i], s[i+len(sep):], true
|
||||
}
|
||||
return s, "", false
|
||||
}
|
||||
|
||||
// some abbreviations need translation before transforming ro snake case
|
||||
var replacer = strings.NewReplacer("ID", "Id")
|
||||
|
||||
@ -393,3 +340,16 @@ func convDefault(s string, t string) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func typeName(x ast.Node) string {
|
||||
switch x := x.(type) {
|
||||
case *ast.Ident:
|
||||
return x.Name
|
||||
case *ast.SelectorExpr:
|
||||
return typeName(x.X) + "." + x.Sel.Name
|
||||
case *ast.StarExpr:
|
||||
return "*" + typeName(x.X)
|
||||
default:
|
||||
panic("unhandled type: " + reflect.TypeOf(x).String())
|
||||
}
|
||||
}
|
||||
|
44
cmd/api-generator/supported.go
Normal file
44
cmd/api-generator/supported.go
Normal file
@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import "html/template"
|
||||
|
||||
func (g *generator) genSupported(routers []Router) {
|
||||
var v11, v12 []string // for onebot v12 get_supported_actions
|
||||
for _, router := range routers {
|
||||
if len(router.PathV11) > 0 {
|
||||
v11 = append(v11, router.PathV11...)
|
||||
}
|
||||
if len(router.PathV11) > 0 {
|
||||
v12 = append(v12, router.PathV12...)
|
||||
}
|
||||
if len(router.Path) > 0 {
|
||||
v11 = append(v11, router.Path...)
|
||||
v12 = append(v12, router.Path...)
|
||||
}
|
||||
}
|
||||
|
||||
type S struct {
|
||||
V11 []string
|
||||
V12 []string
|
||||
}
|
||||
|
||||
tmpl, err := template.New("").Parse(supportedTemplete)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = tmpl.Execute(g.out, &S{V11: v11, V12: v12})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
const supportedTemplete = `
|
||||
var supportedV11 = []string{
|
||||
{{range .V11}} "{{.}}",
|
||||
{{end}}
|
||||
}
|
||||
|
||||
var supportedV12 = []string{
|
||||
{{range .V12}} "{{.}}",
|
||||
{{end}}
|
||||
}`
|
@ -52,6 +52,7 @@ func readIfTTY(de string) (str string) {
|
||||
}
|
||||
|
||||
var cli *client.QQClient
|
||||
var device *client.DeviceInfo
|
||||
|
||||
// ErrSMSRequestError SMS请求出错
|
||||
var ErrSMSRequestError = errors.New("sms request error")
|
||||
@ -152,23 +153,15 @@ func loginResponseProcessor(res *client.LoginResponse) error {
|
||||
var text string
|
||||
switch res.Error {
|
||||
case client.SliderNeededError:
|
||||
log.Warnf("登录需要滑条验证码, 请选择验证方式: ")
|
||||
log.Warnf("1. 使用浏览器抓取滑条并登录")
|
||||
log.Warnf("2. 使用手机QQ扫码验证 (需要手Q和gocq在同一网络下).")
|
||||
log.Warn("请输入(1 - 2):")
|
||||
text = readIfTTY("1")
|
||||
if strings.Contains(text, "1") {
|
||||
log.Warnf("登录需要滑条验证码, 请验证后重试.")
|
||||
ticket := getTicket(res.VerifyUrl)
|
||||
if ticket == "" {
|
||||
log.Infof("按 Enter 继续....")
|
||||
readLine()
|
||||
os.Exit(0)
|
||||
}
|
||||
res, err = cli.SubmitTicket(ticket)
|
||||
continue
|
||||
}
|
||||
cli.Disconnect()
|
||||
cli.Release()
|
||||
cli = client.NewClientEmpty()
|
||||
return qrcodeLogin()
|
||||
case client.NeedCaptcha:
|
||||
log.Warnf("登录需要验证码.")
|
||||
_ = os.WriteFile("captcha.jpg", res.CaptchaImage, 0o644)
|
||||
@ -212,38 +205,45 @@ func loginResponseProcessor(res *client.LoginResponse) error {
|
||||
os.Exit(0)
|
||||
case client.OtherLoginError, client.UnknownLoginError, client.TooManySMSRequestError:
|
||||
msg := res.ErrorMessage
|
||||
if strings.Contains(msg, "版本") {
|
||||
msg = "密码错误或账号被冻结"
|
||||
} else if strings.Contains(msg, "冻结") {
|
||||
log.Fatalf("账号被冻结")
|
||||
log.Warnf("登录失败: %v Code: %v", msg, res.Code)
|
||||
switch res.Code {
|
||||
case 235:
|
||||
log.Warnf("设备信息被封禁, 请删除 device.json 后重试.")
|
||||
case 237:
|
||||
log.Warnf("登录过于频繁, 请在手机QQ登录并根据提示完成认证后等一段时间重试")
|
||||
case 45:
|
||||
log.Warnf("你的账号被限制登录, 请配置 SignServer 后重试")
|
||||
}
|
||||
log.Warnf("登录失败: %v", msg)
|
||||
log.Infof("按 Enter 或等待 5s 后继续....")
|
||||
readLineTimeout(time.Second * 5)
|
||||
log.Infof("按 Enter 继续....")
|
||||
readLine()
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getTicket(u string) (str string) {
|
||||
func getTicket(u string) string {
|
||||
log.Warnf("请选择提交滑块ticket方式:")
|
||||
log.Warnf("1. 自动提交")
|
||||
log.Warnf("2. 手动抓取提交")
|
||||
log.Warn("请输入(1 - 2):")
|
||||
text := readLine()
|
||||
id := utils.RandomString(8)
|
||||
log.Warnf("请前往该地址验证 -> %v <- 或输入手动抓取的 ticket:(Enter 提交)", strings.ReplaceAll(u, "https://ssl.captcha.qq.com/template/wireless_mqq_captcha.html?", fmt.Sprintf("https://captcha.go-cqhttp.org/captcha?id=%v&", id)))
|
||||
manual := make(chan string, 1)
|
||||
go func() {
|
||||
manual <- readLine()
|
||||
}()
|
||||
ticker := time.NewTicker(time.Second)
|
||||
defer ticker.Stop()
|
||||
auto := !strings.Contains(text, "2")
|
||||
if auto {
|
||||
u = strings.ReplaceAll(u, "https://ssl.captcha.qq.com/template/wireless_mqq_captcha.html?", fmt.Sprintf("https://captcha.go-cqhttp.org/captcha?id=%v&", id))
|
||||
}
|
||||
log.Warnf("请前往该地址验证 -> %v ", u)
|
||||
if !auto {
|
||||
log.Warn("请输入ticket: (Enter 提交)")
|
||||
return readLine()
|
||||
}
|
||||
|
||||
for count := 120; count > 0; count-- {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
str = fetchCaptcha(id)
|
||||
str := fetchCaptcha(id)
|
||||
if str != "" {
|
||||
return
|
||||
}
|
||||
case str = <-manual:
|
||||
return
|
||||
return str
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
log.Warnf("验证超时")
|
||||
return ""
|
||||
|
127
cmd/gocq/main.go
127
cmd/gocq/main.go
@ -14,9 +14,12 @@ import (
|
||||
|
||||
"github.com/Mrs4s/MiraiGo/binary"
|
||||
"github.com/Mrs4s/MiraiGo/client"
|
||||
"github.com/Mrs4s/MiraiGo/wrapper"
|
||||
para "github.com/fumiama/go-hide-param"
|
||||
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/gjson"
|
||||
"golang.org/x/crypto/pbkdf2"
|
||||
"golang.org/x/term"
|
||||
|
||||
@ -26,6 +29,7 @@ import (
|
||||
"github.com/Mrs4s/go-cqhttp/global/terminal"
|
||||
"github.com/Mrs4s/go-cqhttp/internal/base"
|
||||
"github.com/Mrs4s/go-cqhttp/internal/cache"
|
||||
"github.com/Mrs4s/go-cqhttp/internal/download"
|
||||
"github.com/Mrs4s/go-cqhttp/internal/selfdiagnosis"
|
||||
"github.com/Mrs4s/go-cqhttp/internal/selfupdate"
|
||||
"github.com/Mrs4s/go-cqhttp/modules/servers"
|
||||
@ -41,8 +45,12 @@ var allowStatus = [...]client.UserOnlineStatus{
|
||||
client.StatusGaming, client.StatusVacationing, client.StatusWatchingTV, client.StatusFitness,
|
||||
}
|
||||
|
||||
// Main 启动主程序
|
||||
func Main() {
|
||||
// InitBase 解析参数并检测
|
||||
//
|
||||
// 如果在 windows 下双击打开了程序,程序将在此函数释出脚本后终止;
|
||||
// 如果传入 -h 参数,程序将打印帮助后终止;
|
||||
// 如果传入 -d 参数,程序将在启动 daemon 后终止。
|
||||
func InitBase() {
|
||||
base.Parse()
|
||||
if !base.FastStart && terminal.RunningByDoubleClick() {
|
||||
err := terminal.NoMoreDoubleClick()
|
||||
@ -50,7 +58,7 @@ func Main() {
|
||||
log.Errorf("遇到错误: %v", err)
|
||||
time.Sleep(time.Second * 5)
|
||||
}
|
||||
return
|
||||
os.Exit(0)
|
||||
}
|
||||
switch {
|
||||
case base.LittleH:
|
||||
@ -65,7 +73,10 @@ func Main() {
|
||||
}
|
||||
}
|
||||
base.Init()
|
||||
}
|
||||
|
||||
// PrepareData 准备 log, 缓存, 数据库, 必须在 InitBase 之后执行
|
||||
func PrepareData() {
|
||||
rotateOptions := []rotatelogs.Option{
|
||||
rotatelogs.WithRotationTime(time.Hour * 24),
|
||||
}
|
||||
@ -95,13 +106,17 @@ func Main() {
|
||||
mkCacheDir(global.VideoPath, "视频")
|
||||
mkCacheDir(global.CachePath, "发送图片")
|
||||
mkCacheDir(path.Join(global.ImagePath, "guild-images"), "频道图片缓存")
|
||||
mkCacheDir(global.VersionsPath, "版本缓存")
|
||||
cache.Init()
|
||||
|
||||
db.Init()
|
||||
if err := db.Open(); err != nil {
|
||||
log.Fatalf("打开数据库失败: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// LoginInteract 登录交互, 可能需要键盘输入, 必须在 InitBase, PrepareData 之后执行
|
||||
func LoginInteract() {
|
||||
var byteKey []byte
|
||||
arg := os.Args
|
||||
if len(arg) > 1 {
|
||||
@ -138,37 +153,58 @@ func Main() {
|
||||
}
|
||||
if !global.PathExists("device.json") {
|
||||
log.Warn("虚拟设备信息不存在, 将自动生成随机设备.")
|
||||
client.GenRandomDevice()
|
||||
_ = os.WriteFile("device.json", client.SystemDeviceInfo.ToJson(), 0o644)
|
||||
device = client.GenRandomDevice()
|
||||
_ = os.WriteFile("device.json", device.ToJson(), 0o644)
|
||||
log.Info("已生成设备信息并保存到 device.json 文件.")
|
||||
} else {
|
||||
log.Info("将使用 device.json 内的设备信息运行Bot.")
|
||||
if err := client.SystemDeviceInfo.ReadJson([]byte(global.ReadAllText("device.json"))); err != nil {
|
||||
device = new(client.DeviceInfo)
|
||||
if err := device.ReadJson([]byte(global.ReadAllText("device.json"))); err != nil {
|
||||
log.Fatalf("加载设备信息失败: %v", err)
|
||||
}
|
||||
}
|
||||
signServer, err := getAvaliableSignServer() // 获取可用签名服务器
|
||||
if err != nil {
|
||||
log.Warn(err)
|
||||
}
|
||||
if signServer != nil && len(signServer.URL) > 1 {
|
||||
log.Infof("使用签名服务器:%v", signServer.URL)
|
||||
go signStartRefreshToken(base.Account.RefreshInterval) // 定时刷新 token
|
||||
wrapper.DandelionEnergy = energy
|
||||
wrapper.FekitGetSign = sign
|
||||
if !base.IsBelow110 {
|
||||
if !base.Account.AutoRegister {
|
||||
log.Warn("自动注册实例已关闭,请配置 sign-server 端自动注册实例以保持正常签名")
|
||||
}
|
||||
if !base.Account.AutoRefreshToken {
|
||||
log.Info("自动刷新 token 已关闭,token 过期后获取签名时将不会立即尝试刷新获取新 token")
|
||||
}
|
||||
} else {
|
||||
log.Warn("签名服务器版本 <= 1.1.0 ,无法使用刷新 token 等操作,建议使用 1.1.6 版本及以上签名服务器")
|
||||
}
|
||||
} else {
|
||||
log.Warnf("警告: 未配置签名服务器或签名服务器不可用, 这可能会导致登录 45 错误码或发送消息被风控")
|
||||
}
|
||||
|
||||
if base.Account.Encrypt {
|
||||
if !global.PathExists("password.encrypt") {
|
||||
if base.Account.Password == "" {
|
||||
log.Error("无法进行加密,请在配置文件中的添加密码后重新启动.")
|
||||
readLine()
|
||||
os.Exit(0)
|
||||
}
|
||||
} else {
|
||||
log.Infof("密码加密已启用, 请输入Key对密码进行加密: (Enter 提交)")
|
||||
byteKey, _ = term.ReadPassword(int(os.Stdin.Fd()))
|
||||
base.PasswordHash = md5.Sum([]byte(base.Account.Password))
|
||||
_ = os.WriteFile("password.encrypt", []byte(PasswordHashEncrypt(base.PasswordHash[:], byteKey)), 0o644)
|
||||
log.Info("密码已加密,为了您的账号安全,请删除配置文件中的密码后重新启动.")
|
||||
}
|
||||
readLine()
|
||||
os.Exit(0)
|
||||
} else {
|
||||
}
|
||||
if base.Account.Password != "" {
|
||||
log.Error("密码已加密,为了您的账号安全,请删除配置文件中的密码后重新启动.")
|
||||
readLine()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if len(byteKey) == 0 {
|
||||
log.Infof("密码加密已启用, 请输入Key对密码进行解密以继续: (Enter 提交)")
|
||||
cancel := make(chan struct{}, 1)
|
||||
@ -196,7 +232,6 @@ func Main() {
|
||||
log.Fatalf("加密存储的密码损坏,请尝试重新配置密码")
|
||||
}
|
||||
copy(base.PasswordHash[:], ph)
|
||||
}
|
||||
} else if len(base.Account.Password) > 0 {
|
||||
base.PasswordHash = md5.Sum([]byte(base.Account.Password))
|
||||
}
|
||||
@ -205,10 +240,27 @@ func Main() {
|
||||
time.Sleep(time.Second * 5)
|
||||
}
|
||||
log.Info("开始尝试登录并同步消息...")
|
||||
log.Infof("使用协议: %s", client.SystemDeviceInfo.Protocol)
|
||||
log.Infof("使用协议: %s", device.Protocol.Version())
|
||||
cli = newClient()
|
||||
cli.UseDevice(device)
|
||||
isQRCodeLogin := (base.Account.Uin == 0 || len(base.Account.Password) == 0) && !base.Account.Encrypt
|
||||
isTokenLogin := false
|
||||
|
||||
if isQRCodeLogin && cli.Device().Protocol != 2 {
|
||||
log.Warn("当前协议不支持二维码登录, 请配置账号密码登录.")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// 加载本地版本信息, 一般是在上次登录时保存的
|
||||
versionFile := path.Join(global.VersionsPath, fmt.Sprint(int(cli.Device().Protocol))+".json")
|
||||
if global.PathExists(versionFile) {
|
||||
b, err := os.ReadFile(versionFile)
|
||||
if err == nil {
|
||||
_ = cli.Device().Protocol.Version().UpdateFromJson(b)
|
||||
}
|
||||
log.Infof("从文件 %s 读取协议版本 %v.", versionFile, cli.Device().Protocol.Version())
|
||||
}
|
||||
|
||||
saveToken := func() {
|
||||
base.AccountToken = cli.GenToken()
|
||||
_ = os.WriteFile("session.token", base.AccountToken, 0o644)
|
||||
@ -239,6 +291,7 @@ func Main() {
|
||||
cli.Disconnect()
|
||||
cli.Release()
|
||||
cli = newClient()
|
||||
cli.UseDevice(device)
|
||||
} else {
|
||||
isTokenLogin = true
|
||||
}
|
||||
@ -248,6 +301,30 @@ func Main() {
|
||||
cli.Uin = base.Account.Uin
|
||||
cli.PasswordMd5 = base.PasswordHash
|
||||
}
|
||||
download.SetTimeout(time.Duration(base.HTTPTimeout) * time.Second)
|
||||
if !base.FastStart {
|
||||
log.Infof("正在检查协议更新...")
|
||||
currentVersionName := device.Protocol.Version().SortVersionName
|
||||
remoteVersion, err := getRemoteLatestProtocolVersion(int(device.Protocol.Version().Protocol))
|
||||
if err == nil {
|
||||
remoteVersionName := gjson.GetBytes(remoteVersion, "sort_version_name").String()
|
||||
if remoteVersionName != currentVersionName {
|
||||
switch {
|
||||
case !base.UpdateProtocol:
|
||||
log.Infof("检测到协议更新: %s -> %s", currentVersionName, remoteVersionName)
|
||||
log.Infof("如果登录时出现版本过低错误, 可尝试使用 -update-protocol 参数启动")
|
||||
case !isTokenLogin:
|
||||
_ = device.Protocol.Version().UpdateFromJson(remoteVersion)
|
||||
log.Infof("协议版本已更新: %s -> %s", currentVersionName, remoteVersionName)
|
||||
default:
|
||||
log.Infof("检测到协议更新: %s -> %s", currentVersionName, remoteVersionName)
|
||||
log.Infof("由于使用了会话缓存, 无法自动更新协议, 请删除缓存后重试")
|
||||
}
|
||||
}
|
||||
} else if err.Error() != "remote version unavailable" {
|
||||
log.Warnf("检查协议更新失败: %v", err)
|
||||
}
|
||||
}
|
||||
if !isTokenLogin {
|
||||
if !isQRCodeLogin {
|
||||
if err := commonLogin(); err != nil {
|
||||
@ -322,11 +399,16 @@ func Main() {
|
||||
base.Account.Status = 0
|
||||
}
|
||||
cli.SetOnlineStatus(allowStatus[base.Account.Status])
|
||||
|
||||
servers.Run(coolq.NewQQBot(cli))
|
||||
log.Info("资源初始化完成, 开始处理信息.")
|
||||
log.Info("アトリは、高性能ですから!")
|
||||
}
|
||||
|
||||
// WaitSignal 在新线程检查更新和网络并等待信号, 必须在 InitBase, PrepareData, LoginInteract 之后执行
|
||||
//
|
||||
// - 直接返回: os.Interrupt, syscall.SIGTERM
|
||||
// - dump stack: syscall.SIGQUIT, syscall.SIGUSR1
|
||||
func WaitSignal() {
|
||||
go func() {
|
||||
selfupdate.CheckUpdate()
|
||||
selfdiagnosis.NetworkDiagnosis(cli)
|
||||
@ -389,6 +471,23 @@ func newClient() *client.QQClient {
|
||||
return c
|
||||
}
|
||||
|
||||
var remoteVersions = map[int]string{
|
||||
1: "https://raw.githubusercontent.com/RomiChan/protocol-versions/master/android_phone.json",
|
||||
6: "https://raw.githubusercontent.com/RomiChan/protocol-versions/master/android_pad.json",
|
||||
}
|
||||
|
||||
func getRemoteLatestProtocolVersion(protocolType int) ([]byte, error) {
|
||||
url, ok := remoteVersions[protocolType]
|
||||
if !ok {
|
||||
return nil, errors.New("remote version unavailable")
|
||||
}
|
||||
response, err := download.Request{URL: url}.Bytes()
|
||||
if err != nil {
|
||||
return download.Request{URL: "https://ghproxy.com/" + url}.Bytes()
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
type protocolLogger struct{}
|
||||
|
||||
const fromProtocol = "Protocol -> "
|
||||
|
427
cmd/gocq/qsign.go
Normal file
427
cmd/gocq/qsign.go
Normal file
@ -0,0 +1,427 @@
|
||||
package gocq
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/Mrs4s/MiraiGo/utils"
|
||||
|
||||
"github.com/Mrs4s/go-cqhttp/global"
|
||||
"github.com/Mrs4s/go-cqhttp/internal/base"
|
||||
"github.com/Mrs4s/go-cqhttp/internal/download"
|
||||
"github.com/Mrs4s/go-cqhttp/modules/config"
|
||||
)
|
||||
|
||||
type currentSignServer atomic.Pointer[config.SignServer]
|
||||
|
||||
func (c *currentSignServer) get() *config.SignServer {
|
||||
if len(base.SignServers) == 1 {
|
||||
// 只配置了一个签名服务时不检查以及切换, 在get阶段返回,防止返回nil导致其他bug(可能)
|
||||
return &base.SignServers[0]
|
||||
}
|
||||
return (*atomic.Pointer[config.SignServer])(c).Load()
|
||||
}
|
||||
|
||||
func (c *currentSignServer) set(server *config.SignServer) {
|
||||
(*atomic.Pointer[config.SignServer])(c).Store(server)
|
||||
}
|
||||
|
||||
// 当前签名服务器
|
||||
var ss currentSignServer
|
||||
|
||||
// 失败计数
|
||||
type errconut atomic.Uintptr
|
||||
|
||||
func (ec *errconut) hasOver(count uintptr) bool {
|
||||
return (*atomic.Uintptr)(ec).Load() > count
|
||||
}
|
||||
|
||||
func (ec *errconut) inc() {
|
||||
(*atomic.Uintptr)(ec).Add(1)
|
||||
}
|
||||
|
||||
var errn errconut
|
||||
|
||||
// getAvaliableSignServer 获取可用的签名服务器,没有则返回空和相应错误
|
||||
func getAvaliableSignServer() (*config.SignServer, error) {
|
||||
cs := ss.get()
|
||||
if cs != nil {
|
||||
return cs, nil
|
||||
}
|
||||
if len(base.SignServers) == 0 {
|
||||
return nil, errors.New("no sign server configured")
|
||||
}
|
||||
maxCount := base.Account.MaxCheckCount
|
||||
if maxCount == 0 {
|
||||
if errn.hasOver(3) {
|
||||
log.Warn("已连续 3 次获取不到可用签名服务器,将固定使用主签名服务器")
|
||||
ss.set(&base.SignServers[0])
|
||||
return ss.get(), nil
|
||||
}
|
||||
} else if errn.hasOver(uintptr(maxCount)) {
|
||||
log.Fatalf("获取可用签名服务器失败次数超过 %v 次, 正在离线", maxCount)
|
||||
}
|
||||
if cs != nil && len(cs.URL) > 0 {
|
||||
log.Warnf("当前签名服务器 %v 不可用,正在查找可用服务器", cs.URL)
|
||||
}
|
||||
cs = asyncCheckServer(base.SignServers)
|
||||
if cs == nil {
|
||||
return nil, errors.New("no usable sign server")
|
||||
}
|
||||
return cs, nil
|
||||
}
|
||||
|
||||
func isServerAvaliable(signServer string) bool {
|
||||
resp, err := download.Request{
|
||||
Method: http.MethodGet,
|
||||
URL: signServer,
|
||||
}.WithTimeout(3 * time.Second).Bytes()
|
||||
if err == nil && gjson.GetBytes(resp, "code").Int() == 0 {
|
||||
return true
|
||||
}
|
||||
log.Warnf("签名服务器 %v 可能不可用,请求出现错误:%v", signServer, err)
|
||||
return false
|
||||
}
|
||||
|
||||
// asyncCheckServer 按同步顺序检查所有签名服务器直到找到可用的
|
||||
func asyncCheckServer(servers []config.SignServer) *config.SignServer {
|
||||
doRegister := sync.Once{}
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(len(servers))
|
||||
for i, s := range servers {
|
||||
go func(i int, server config.SignServer) {
|
||||
defer wg.Done()
|
||||
log.Infof("检查签名服务器:%v (%v/%v)", server.URL, i+1, len(servers))
|
||||
if len(server.URL) < 4 {
|
||||
return
|
||||
}
|
||||
if isServerAvaliable(server.URL) {
|
||||
doRegister.Do(func() {
|
||||
ss.set(&server)
|
||||
log.Infof("使用签名服务器 url=%v, key=%v, auth=%v", server.URL, server.Key, server.Authorization)
|
||||
if base.Account.AutoRegister {
|
||||
// 若配置了自动注册实例则在切换后注册实例,否则不需要注册,签名时由qsign自动注册
|
||||
signRegister(base.Account.Uin, device.AndroidId, device.Guid, device.QImei36, server.Key)
|
||||
}
|
||||
})
|
||||
}
|
||||
}(i, s)
|
||||
}
|
||||
wg.Wait()
|
||||
return ss.get()
|
||||
}
|
||||
|
||||
/*
|
||||
请求签名服务器
|
||||
|
||||
url: api + params 组合的字符串,无须包含签名服务器地址
|
||||
return: signServer, response, error
|
||||
*/
|
||||
func requestSignServer(method string, url string, headers map[string]string, body io.Reader) (string, []byte, error) {
|
||||
signServer, e := getAvaliableSignServer()
|
||||
if e != nil && len(signServer.URL) == 0 { // 没有可用的
|
||||
log.Warnf("获取可用签名服务器出错:%v, 将使用主签名服务器进行签名", e)
|
||||
errn.inc()
|
||||
signServer = &base.SignServers[0] // 没有获取到时使用第一个
|
||||
}
|
||||
if !strings.HasPrefix(url, signServer.URL) {
|
||||
url = strings.TrimSuffix(signServer.URL, "/") + "/" + strings.TrimPrefix(url, "/")
|
||||
}
|
||||
if headers == nil {
|
||||
headers = map[string]string{}
|
||||
}
|
||||
auth := signServer.Authorization
|
||||
if auth != "-" && auth != "" {
|
||||
headers["Authorization"] = auth
|
||||
}
|
||||
req := download.Request{
|
||||
Method: method,
|
||||
Header: headers,
|
||||
URL: url,
|
||||
Body: body,
|
||||
}.WithTimeout(time.Duration(base.SignServerTimeout) * time.Second)
|
||||
resp, err := req.Bytes()
|
||||
if err != nil {
|
||||
ss.set(nil) // 标记为不可用
|
||||
}
|
||||
return signServer.URL, resp, err
|
||||
}
|
||||
|
||||
func energy(uin uint64, id string, _ string, salt []byte) ([]byte, error) {
|
||||
url := "custom_energy" + fmt.Sprintf("?data=%v&salt=%v&uin=%v&android_id=%v&guid=%v",
|
||||
id, hex.EncodeToString(salt), uin, utils.B2S(device.AndroidId), hex.EncodeToString(device.Guid))
|
||||
if base.IsBelow110 {
|
||||
url = "custom_energy" + fmt.Sprintf("?data=%v&salt=%v", id, hex.EncodeToString(salt))
|
||||
}
|
||||
signServer, response, err := requestSignServer(http.MethodGet, url, nil, nil)
|
||||
if err != nil {
|
||||
log.Warnf("获取T544 sign时出现错误: %v. server: %v", err, signServer)
|
||||
return nil, err
|
||||
}
|
||||
data, err := hex.DecodeString(gjson.GetBytes(response, "data").String())
|
||||
if err != nil {
|
||||
log.Warnf("获取T544 sign时出现错误: %v (data: %v)", err, gjson.GetBytes(response, "data").String())
|
||||
return nil, err
|
||||
}
|
||||
if len(data) == 0 {
|
||||
log.Warnf("获取T544 sign时出现错误: %v.", "data is empty")
|
||||
return nil, errors.New("data is empty")
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// signSubmit
|
||||
// 提交回调 buffer
|
||||
func signSubmit(uin string, cmd string, callbackID int64, buffer []byte, t string) {
|
||||
buffStr := hex.EncodeToString(buffer)
|
||||
if base.Debug {
|
||||
tail := 64
|
||||
endl := "..."
|
||||
if len(buffStr) < tail {
|
||||
tail = len(buffStr)
|
||||
endl = "."
|
||||
}
|
||||
log.Debugf("submit (%v): uin=%v, cmd=%v, callbackID=%v, buffer=%v%s", t, uin, cmd, callbackID, buffStr[:tail], endl)
|
||||
}
|
||||
|
||||
signServer, _, err := requestSignServer(
|
||||
http.MethodGet,
|
||||
"submit"+fmt.Sprintf("?uin=%v&cmd=%v&callback_id=%v&buffer=%v",
|
||||
uin, cmd, callbackID, buffStr),
|
||||
nil, nil,
|
||||
)
|
||||
if err != nil {
|
||||
log.Warnf("提交 callback 时出现错误: %v. server: %v", err, signServer)
|
||||
}
|
||||
}
|
||||
|
||||
// signCallback
|
||||
// 刷新 token 和签名的回调
|
||||
func signCallback(uin string, results []gjson.Result, t string) {
|
||||
for { // 等待至在线
|
||||
if cli.Online.Load() {
|
||||
break
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
for _, result := range results {
|
||||
cmd := result.Get("cmd").String()
|
||||
callbackID := result.Get("callbackId").Int()
|
||||
body, _ := hex.DecodeString(result.Get("body").String())
|
||||
ret, err := cli.SendSsoPacket(cmd, body)
|
||||
if err != nil || len(ret) == 0 {
|
||||
log.Warnf("Callback error: %v, or response data is empty", err)
|
||||
continue // 发送 SsoPacket 出错或返回数据为空时跳过
|
||||
}
|
||||
signSubmit(uin, cmd, callbackID, ret, t)
|
||||
}
|
||||
}
|
||||
|
||||
func signRequset(seq uint64, uin string, cmd string, qua string, buff []byte) (sign []byte, extra []byte, token []byte, err error) {
|
||||
headers := map[string]string{"Content-Type": "application/x-www-form-urlencoded"}
|
||||
_, response, err := requestSignServer(
|
||||
http.MethodPost,
|
||||
"sign",
|
||||
headers,
|
||||
bytes.NewReader([]byte(fmt.Sprintf("uin=%v&qua=%s&cmd=%s&seq=%v&buffer=%v&android_id=%v&guid=%v",
|
||||
uin, qua, cmd, seq, hex.EncodeToString(buff), utils.B2S(device.AndroidId), hex.EncodeToString(device.Guid)))),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
sign, _ = hex.DecodeString(gjson.GetBytes(response, "data.sign").String())
|
||||
extra, _ = hex.DecodeString(gjson.GetBytes(response, "data.extra").String())
|
||||
token, _ = hex.DecodeString(gjson.GetBytes(response, "data.token").String())
|
||||
if !base.IsBelow110 {
|
||||
go signCallback(uin, gjson.GetBytes(response, "data.requestCallback").Array(), "sign")
|
||||
}
|
||||
return sign, extra, token, nil
|
||||
}
|
||||
|
||||
var registerLock sync.Mutex
|
||||
|
||||
func signRegister(uin int64, androidID, guid []byte, qimei36, key string) {
|
||||
if base.IsBelow110 {
|
||||
log.Warn("签名服务器版本低于1.1.0, 跳过实例注册")
|
||||
return
|
||||
}
|
||||
signServer, resp, err := requestSignServer(
|
||||
http.MethodGet,
|
||||
"register"+fmt.Sprintf("?uin=%v&android_id=%v&guid=%v&qimei36=%v&key=%s",
|
||||
uin, utils.B2S(androidID), hex.EncodeToString(guid), qimei36, key),
|
||||
nil, nil,
|
||||
)
|
||||
if err != nil {
|
||||
log.Warnf("注册QQ实例时出现错误: %v. server: %v", err, signServer)
|
||||
return
|
||||
}
|
||||
msg := gjson.GetBytes(resp, "msg")
|
||||
if gjson.GetBytes(resp, "code").Int() != 0 {
|
||||
log.Warnf("注册QQ实例时出现错误: %v. server: %v", msg, signServer)
|
||||
return
|
||||
}
|
||||
log.Infof("注册QQ实例 %v 成功: %v", uin, msg)
|
||||
}
|
||||
|
||||
func signRefreshToken(uin string) error {
|
||||
log.Info("正在刷新 token")
|
||||
_, resp, err := requestSignServer(
|
||||
http.MethodGet,
|
||||
"request_token?uin="+uin,
|
||||
nil, nil,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg := gjson.GetBytes(resp, "msg")
|
||||
code := gjson.GetBytes(resp, "code")
|
||||
if code.Int() != 0 {
|
||||
return errors.New("code=" + code.String() + ", msg: " + msg.String())
|
||||
}
|
||||
go signCallback(uin, gjson.GetBytes(resp, "data").Array(), "request token")
|
||||
return nil
|
||||
}
|
||||
|
||||
var missTokenCount = uint64(0)
|
||||
var lastToken = ""
|
||||
|
||||
func sign(seq uint64, uin string, cmd string, qua string, buff []byte) (sign []byte, extra []byte, token []byte, err error) {
|
||||
i := 0
|
||||
for {
|
||||
sign, extra, token, err = signRequset(seq, uin, cmd, qua, buff)
|
||||
cs := ss.get()
|
||||
if cs == nil {
|
||||
// 最好在请求后判断,否则若被设置为nil后不会再请求签名,
|
||||
// 导致在下一次有请求签名服务操作之前,ss无法更新
|
||||
err = errors.New("nil signserver")
|
||||
log.Warn("nil sign-server") // 返回的err并不会log出来,加条日志
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
log.Warnf("获取sso sign时出现错误: %v. server: %v", err, cs.URL)
|
||||
}
|
||||
if i > 0 {
|
||||
break
|
||||
}
|
||||
i++
|
||||
if (!base.IsBelow110) && base.Account.AutoRegister && err == nil && len(sign) == 0 {
|
||||
if registerLock.TryLock() { // 避免并发时多处同时销毁并重新注册
|
||||
log.Debugf("请求签名:cmd=%v, qua=%v, buff=%v", seq, cmd, hex.EncodeToString(buff))
|
||||
log.Debugf("返回结果:sign=%v, extra=%v, token=%v",
|
||||
hex.EncodeToString(sign), hex.EncodeToString(extra), hex.EncodeToString(token))
|
||||
log.Warn("获取签名为空,实例可能丢失,正在尝试重新注册")
|
||||
defer registerLock.Unlock()
|
||||
err := signServerDestroy(uin)
|
||||
if err != nil {
|
||||
log.Warnln(err) // 实例真的丢失时则必出错,或许应该不 return , 以重新获取本次签名
|
||||
// return nil, nil, nil, err
|
||||
}
|
||||
signRegister(base.Account.Uin, device.AndroidId, device.Guid, device.QImei36, cs.Key)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if (!base.IsBelow110) && base.Account.AutoRefreshToken && len(token) == 0 {
|
||||
log.Warnf("token 已过期, 总丢失 token 次数为 %v", atomic.AddUint64(&missTokenCount, 1))
|
||||
if registerLock.TryLock() {
|
||||
defer registerLock.Unlock()
|
||||
if err := signRefreshToken(uin); err != nil {
|
||||
log.Warnf("刷新 token 出现错误: %v. server: %v", err, cs.URL)
|
||||
} else {
|
||||
log.Info("刷新 token 成功")
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
if tokenString := hex.EncodeToString(token); lastToken != tokenString {
|
||||
log.Infof("token 已更新:%v -> %v", lastToken, tokenString)
|
||||
lastToken = tokenString
|
||||
}
|
||||
rule := base.Account.RuleChangeSignServer
|
||||
if (len(sign) == 0 && rule >= 1) || (len(token) == 0 && rule >= 2) {
|
||||
ss.set(nil)
|
||||
}
|
||||
return sign, extra, token, err
|
||||
}
|
||||
|
||||
func signServerDestroy(uin string) error {
|
||||
signServer, signVersion, err := signVersion()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "获取签名服务版本出现错误, server: %v", signServer)
|
||||
}
|
||||
if global.VersionNameCompare("v"+signVersion, "v1.1.6") {
|
||||
return errors.Errorf("当前签名服务器版本 %v 低于 1.1.6,无法使用 destroy 接口", signVersion)
|
||||
}
|
||||
cs := ss.get()
|
||||
if cs == nil {
|
||||
return errors.New("nil signserver")
|
||||
}
|
||||
signServer, resp, err := requestSignServer(
|
||||
http.MethodGet,
|
||||
"destroy"+fmt.Sprintf("?uin=%v&key=%v", uin, cs.Key),
|
||||
nil, nil,
|
||||
)
|
||||
if err != nil || gjson.GetBytes(resp, "code").Int() != 0 {
|
||||
return errors.Wrapf(err, "destroy 实例出现错误, server: %v", signServer)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func signVersion() (signServer string, version string, err error) {
|
||||
signServer, resp, err := requestSignServer(http.MethodGet, "", nil, nil)
|
||||
if err != nil {
|
||||
return signServer, "", err
|
||||
}
|
||||
if gjson.GetBytes(resp, "code").Int() == 0 {
|
||||
return signServer, gjson.GetBytes(resp, "data.version").String(), nil
|
||||
}
|
||||
return signServer, "", errors.New("empty version")
|
||||
}
|
||||
|
||||
// 定时刷新 token, interval 为间隔时间(分钟)
|
||||
func signStartRefreshToken(interval int64) {
|
||||
if interval <= 0 {
|
||||
log.Warn("定时刷新 token 已关闭")
|
||||
return
|
||||
}
|
||||
log.Infof("每 %v 分钟将刷新一次签名 token", interval)
|
||||
if interval < 10 {
|
||||
log.Warnf("间隔时间 %v 分钟较短,推荐 30~40 分钟", interval)
|
||||
}
|
||||
if interval > 60 {
|
||||
log.Warn("间隔时间不能超过 60 分钟,已自动设置为 60 分钟")
|
||||
interval = 60
|
||||
}
|
||||
t := time.NewTicker(time.Duration(interval) * time.Minute)
|
||||
qqstr := strconv.FormatInt(base.Account.Uin, 10)
|
||||
defer t.Stop()
|
||||
for range t.C {
|
||||
cs, master := ss.get(), &base.SignServers[0]
|
||||
if (cs == nil || cs.URL != master.URL) && isServerAvaliable(master.URL) {
|
||||
ss.set(master)
|
||||
log.Infof("主签名服务器可用,已切换至主签名服务器 %v", master.URL)
|
||||
}
|
||||
cs = ss.get()
|
||||
if cs == nil {
|
||||
log.Warn("无法获得可用签名服务器,停止 token 定时刷新")
|
||||
return
|
||||
}
|
||||
err := signRefreshToken(qqstr)
|
||||
if err != nil {
|
||||
log.Warnf("刷新 token 出现错误: %v. server: %v", err, cs.URL)
|
||||
}
|
||||
}
|
||||
}
|
114
coolq/api.go
114
coolq/api.go
@ -27,8 +27,10 @@ import (
|
||||
"github.com/Mrs4s/go-cqhttp/internal/base"
|
||||
"github.com/Mrs4s/go-cqhttp/internal/cache"
|
||||
"github.com/Mrs4s/go-cqhttp/internal/download"
|
||||
"github.com/Mrs4s/go-cqhttp/internal/msg"
|
||||
"github.com/Mrs4s/go-cqhttp/internal/param"
|
||||
"github.com/Mrs4s/go-cqhttp/modules/filter"
|
||||
"github.com/Mrs4s/go-cqhttp/pkg/onebot"
|
||||
)
|
||||
|
||||
type guildMemberPageToken struct {
|
||||
@ -327,13 +329,13 @@ func (bot *CQBot) CQGetTopicChannelFeeds(guildID, channelID uint64) global.MSG {
|
||||
//
|
||||
// https://git.io/Jtz1L
|
||||
// @route(get_friend_list)
|
||||
func (bot *CQBot) CQGetFriendList(version uint16) global.MSG {
|
||||
func (bot *CQBot) CQGetFriendList(spec *onebot.Spec) global.MSG {
|
||||
fs := make([]global.MSG, 0, len(bot.Client.FriendList))
|
||||
for _, f := range bot.Client.FriendList {
|
||||
fs = append(fs, global.MSG{
|
||||
"nickname": f.Nickname,
|
||||
"remark": f.Remark,
|
||||
"user_id": ConvertIDWithVersion(f.Uin, version),
|
||||
"user_id": spec.ConvertID(f.Uin),
|
||||
})
|
||||
}
|
||||
return OK(fs)
|
||||
@ -399,14 +401,14 @@ func (bot *CQBot) CQDeleteFriend(uin int64) global.MSG {
|
||||
//
|
||||
// https://git.io/Jtz1t
|
||||
// @route(get_group_list)
|
||||
func (bot *CQBot) CQGetGroupList(noCache bool, converter IDConverter) global.MSG {
|
||||
func (bot *CQBot) CQGetGroupList(noCache bool, spec *onebot.Spec) global.MSG {
|
||||
gs := make([]global.MSG, 0, len(bot.Client.GroupList))
|
||||
if noCache {
|
||||
_ = bot.Client.ReloadGroupList()
|
||||
}
|
||||
for _, g := range bot.Client.GroupList {
|
||||
gs = append(gs, global.MSG{
|
||||
"group_id": converter(g.Code),
|
||||
"group_id": spec.ConvertID(g.Code),
|
||||
"group_name": g.Name,
|
||||
"group_create_time": g.GroupCreateTime,
|
||||
"group_level": g.GroupLevel,
|
||||
@ -421,7 +423,7 @@ func (bot *CQBot) CQGetGroupList(noCache bool, converter IDConverter) global.MSG
|
||||
//
|
||||
// https://git.io/Jtz1O
|
||||
// @route(get_group_info)
|
||||
func (bot *CQBot) CQGetGroupInfo(groupID int64, noCache bool, converter IDConverter) global.MSG {
|
||||
func (bot *CQBot) CQGetGroupInfo(groupID int64, noCache bool, spec *onebot.Spec) global.MSG {
|
||||
group := bot.Client.FindGroup(groupID)
|
||||
if group == nil || noCache {
|
||||
group, _ = bot.Client.GetGroupInfo(groupID)
|
||||
@ -435,7 +437,7 @@ func (bot *CQBot) CQGetGroupInfo(groupID int64, noCache bool, converter IDConver
|
||||
for _, g := range info {
|
||||
if g.Code == groupID {
|
||||
return OK(global.MSG{
|
||||
"group_id": converter(g.Code),
|
||||
"group_id": spec.ConvertID(g.Code),
|
||||
"group_name": g.Name,
|
||||
"group_memo": g.Memo,
|
||||
"group_create_time": 0,
|
||||
@ -447,7 +449,7 @@ func (bot *CQBot) CQGetGroupInfo(groupID int64, noCache bool, converter IDConver
|
||||
}
|
||||
} else {
|
||||
return OK(global.MSG{
|
||||
"group_id": converter(group.Code),
|
||||
"group_id": spec.ConvertID(group.Code),
|
||||
"group_name": group.Name,
|
||||
"group_create_time": group.GroupCreateTime,
|
||||
"group_level": group.GroupLevel,
|
||||
@ -615,6 +617,7 @@ func (bot *CQBot) CQUploadPrivateFile(userID int64, file, name string) global.MS
|
||||
log.Warnf("上传私聊文件 %v 失败: %+v", file, err)
|
||||
return Failed(100, "OPEN_FILE_ERROR", "打开文件失败")
|
||||
}
|
||||
defer func() { _ = fileBody.Close() }()
|
||||
localFile := &client.LocalFile{
|
||||
FileName: name,
|
||||
Body: fileBody,
|
||||
@ -752,17 +755,17 @@ func (bot *CQBot) CQSendGroupMessage(groupID int64, m gjson.Result, autoEscape b
|
||||
|
||||
var elem []message.IMessageElement
|
||||
if m.Type == gjson.JSON {
|
||||
elem = bot.ConvertObjectMessage(m, message.SourceGroup)
|
||||
elem = bot.ConvertObjectMessage(onebot.V11, m, message.SourceGroup)
|
||||
} else {
|
||||
str := m.String()
|
||||
if str == "" {
|
||||
log.Warn("群消息发送失败: 信息为空.")
|
||||
log.Warnf("群 %v 消息发送失败: 信息为空.", groupID)
|
||||
return Failed(100, "EMPTY_MSG_ERROR", "消息为空")
|
||||
}
|
||||
if autoEscape {
|
||||
elem = []message.IMessageElement{message.NewText(str)}
|
||||
} else {
|
||||
elem = bot.ConvertStringMessage(str, message.SourceGroup)
|
||||
elem = bot.ConvertStringMessage(onebot.V11, str, message.SourceGroup)
|
||||
}
|
||||
}
|
||||
fixAt(elem)
|
||||
@ -806,7 +809,7 @@ func (bot *CQBot) CQSendGuildChannelMessage(guildID, channelID uint64, m gjson.R
|
||||
|
||||
var elem []message.IMessageElement
|
||||
if m.Type == gjson.JSON {
|
||||
elem = bot.ConvertObjectMessage(m, message.SourceGuildChannel)
|
||||
elem = bot.ConvertObjectMessage(onebot.V11, m, message.SourceGuildChannel)
|
||||
} else {
|
||||
str := m.String()
|
||||
if str == "" {
|
||||
@ -816,7 +819,7 @@ func (bot *CQBot) CQSendGuildChannelMessage(guildID, channelID uint64, m gjson.R
|
||||
if autoEscape {
|
||||
elem = []message.IMessageElement{message.NewText(str)}
|
||||
} else {
|
||||
elem = bot.ConvertStringMessage(str, message.SourceGuildChannel)
|
||||
elem = bot.ConvertStringMessage(onebot.V11, str, message.SourceGuildChannel)
|
||||
}
|
||||
}
|
||||
fixAt(elem)
|
||||
@ -850,7 +853,7 @@ func (bot *CQBot) uploadForwardElement(m gjson.Result, target int64, sourceType
|
||||
for i, elem := range elems {
|
||||
p := &elems[i]
|
||||
switch o := elem.(type) {
|
||||
case *LocalVideoElement:
|
||||
case *msg.LocalVideo:
|
||||
w.do(func() {
|
||||
gm, err := bot.uploadLocalVideo(source, o)
|
||||
if err != nil {
|
||||
@ -859,7 +862,7 @@ func (bot *CQBot) uploadForwardElement(m gjson.Result, target int64, sourceType
|
||||
*p = gm
|
||||
}
|
||||
})
|
||||
case *LocalImageElement:
|
||||
case *msg.LocalImage:
|
||||
w.do(func() {
|
||||
gm, err := bot.uploadLocalImage(source, o)
|
||||
if err != nil {
|
||||
@ -893,7 +896,7 @@ func (bot *CQBot) uploadForwardElement(m gjson.Result, target int64, sourceType
|
||||
SenderId: m.GetAttribute().SenderUin,
|
||||
SenderName: m.GetAttribute().SenderName,
|
||||
Time: int32(msgTime),
|
||||
Message: resolveElement(bot.ConvertContentMessage(m.GetContent(), mSource)),
|
||||
Message: resolveElement(bot.ConvertContentMessage(m.GetContent(), mSource, false)),
|
||||
}
|
||||
}
|
||||
log.Warnf("警告: 引用消息 %v 错误或数据库未开启.", e.Get("data.id").Str)
|
||||
@ -926,7 +929,7 @@ func (bot *CQBot) uploadForwardElement(m gjson.Result, target int64, sourceType
|
||||
}
|
||||
}
|
||||
}
|
||||
content := bot.ConvertObjectMessage(c, sourceType)
|
||||
content := bot.ConvertObjectMessage(onebot.V11, c, sourceType)
|
||||
if uin != 0 && name != "" && len(content) > 0 {
|
||||
return &message.ForwardNode{
|
||||
SenderId: uin,
|
||||
@ -968,17 +971,20 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) globa
|
||||
if m.Type != gjson.JSON {
|
||||
return Failed(100)
|
||||
}
|
||||
|
||||
source := message.Source{
|
||||
SourceType: message.SourcePrivate,
|
||||
PrimaryID: 0,
|
||||
}
|
||||
fe := bot.uploadForwardElement(m, groupID, message.SourceGroup)
|
||||
if fe == nil {
|
||||
return Failed(100, "EMPTY_NODES", "未找到任何可发送的合并转发信息")
|
||||
}
|
||||
ret := bot.Client.SendGroupForwardMessage(groupID, fe)
|
||||
if ret == nil || ret.Id == -1 {
|
||||
log.Warnf("合并转发(群)消息发送失败: 账号可能被风控.")
|
||||
log.Warnf("合并转发(群 %v)消息发送失败: 账号可能被风控.", groupID)
|
||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
|
||||
}
|
||||
mid := bot.InsertGroupMessage(ret)
|
||||
mid := bot.InsertGroupMessage(ret, source)
|
||||
log.Infof("发送群 %v(%v) 的合并转发消息: %v (%v)", groupID, groupID, limitedString(m.String()), mid)
|
||||
return OK(global.MSG{
|
||||
"message_id": mid,
|
||||
@ -1001,7 +1007,7 @@ func (bot *CQBot) CQSendPrivateForwardMessage(userID int64, m gjson.Result) glob
|
||||
}
|
||||
mid := bot.SendPrivateMessage(userID, 0, &message.SendingMessage{Elements: []message.IMessageElement{fe}})
|
||||
if mid == -1 {
|
||||
log.Warnf("合并转发(好友)消息发送失败: 账号可能被风控.")
|
||||
log.Warnf("合并转发(好友 %v)消息发送失败: 账号可能被风控.", userID)
|
||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
|
||||
}
|
||||
log.Infof("发送好友 %v(%v) 的合并转发消息: %v (%v)", userID, userID, limitedString(m.String()), mid)
|
||||
@ -1019,7 +1025,7 @@ func (bot *CQBot) CQSendPrivateForwardMessage(userID int64, m gjson.Result) glob
|
||||
func (bot *CQBot) CQSendPrivateMessage(userID int64, groupID int64, m gjson.Result, autoEscape bool) global.MSG {
|
||||
var elem []message.IMessageElement
|
||||
if m.Type == gjson.JSON {
|
||||
elem = bot.ConvertObjectMessage(m, message.SourcePrivate)
|
||||
elem = bot.ConvertObjectMessage(onebot.V11, m, message.SourcePrivate)
|
||||
} else {
|
||||
str := m.String()
|
||||
if str == "" {
|
||||
@ -1028,7 +1034,7 @@ func (bot *CQBot) CQSendPrivateMessage(userID int64, groupID int64, m gjson.Resu
|
||||
if autoEscape {
|
||||
elem = []message.IMessageElement{message.NewText(str)}
|
||||
} else {
|
||||
elem = bot.ConvertStringMessage(str, message.SourcePrivate)
|
||||
elem = bot.ConvertStringMessage(onebot.V11, str, message.SourcePrivate)
|
||||
}
|
||||
}
|
||||
mid := bot.SendPrivateMessage(userID, groupID, &message.SendingMessage{Elements: elem})
|
||||
@ -1107,17 +1113,17 @@ func (bot *CQBot) CQSetGroupMemo(groupID int64, msg, img string) global.MSG {
|
||||
if err != nil {
|
||||
return Failed(100, "IMAGE_NOT_FOUND", "图片未找到")
|
||||
}
|
||||
_, err = bot.Client.AddGroupNoticeWithPic(groupID, msg, data)
|
||||
noticeID, err := bot.Client.AddGroupNoticeWithPic(groupID, msg, data)
|
||||
if err != nil {
|
||||
return Failed(100, "SEND_NOTICE_ERROR", err.Error())
|
||||
}
|
||||
} else {
|
||||
_, err := bot.Client.AddGroupNoticeSimple(groupID, msg)
|
||||
return OK(global.MSG{"notice_id": noticeID})
|
||||
}
|
||||
noticeID, err := bot.Client.AddGroupNoticeSimple(groupID, msg)
|
||||
if err != nil {
|
||||
return Failed(100, "SEND_NOTICE_ERROR", err.Error())
|
||||
}
|
||||
}
|
||||
return OK(nil)
|
||||
return OK(global.MSG{"notice_id": noticeID})
|
||||
}
|
||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||
}
|
||||
@ -1146,14 +1152,16 @@ func (bot *CQBot) CQDelGroupMemo(groupID int64, fid string) global.MSG {
|
||||
// @rename(msg->message, block->reject_add_request)
|
||||
func (bot *CQBot) CQSetGroupKick(groupID int64, userID int64, msg string, block bool) global.MSG {
|
||||
if g := bot.Client.FindGroup(groupID); g != nil {
|
||||
if m := g.FindMember(userID); m != nil {
|
||||
m := g.FindMember(userID)
|
||||
if m == nil {
|
||||
return Failed(100, "MEMBER_NOT_FOUND", "人员不存在")
|
||||
}
|
||||
err := m.Kick(msg, block)
|
||||
if err != nil {
|
||||
return Failed(100, "NOT_MANAGEABLE", "机器人权限不足")
|
||||
}
|
||||
return OK(nil)
|
||||
}
|
||||
}
|
||||
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
|
||||
}
|
||||
|
||||
@ -1380,33 +1388,42 @@ func (bot *CQBot) CQGetGroupHonorInfo(groupID int64, t string) global.MSG {
|
||||
}
|
||||
}
|
||||
msg["talkative_list"] = convertMem(honor.TalkativeList)
|
||||
} else {
|
||||
log.Infof("获取群龙王出错:%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if t == "performer" || t == "all" {
|
||||
if honor, err := bot.Client.GetGroupHonorInfo(groupID, client.Performer); err == nil {
|
||||
msg["performer_lis"] = convertMem(honor.ActorList)
|
||||
msg["performer_list"] = convertMem(honor.ActorList)
|
||||
} else {
|
||||
log.Infof("获取群聊之火出错:%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if t == "legend" || t == "all" {
|
||||
if honor, err := bot.Client.GetGroupHonorInfo(groupID, client.Legend); err == nil {
|
||||
msg["legend_list"] = convertMem(honor.LegendList)
|
||||
} else {
|
||||
log.Infof("获取群聊炽焰出错:%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if t == "strong_newbie" || t == "all" {
|
||||
if honor, err := bot.Client.GetGroupHonorInfo(groupID, client.StrongNewbie); err == nil {
|
||||
msg["strong_newbie_list"] = convertMem(honor.StrongNewbieList)
|
||||
} else {
|
||||
log.Infof("获取冒尖小春笋出错:%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if t == "emotion" || t == "all" {
|
||||
if honor, err := bot.Client.GetGroupHonorInfo(groupID, client.Emotion); err == nil {
|
||||
msg["emotion_list"] = convertMem(honor.EmotionList)
|
||||
} else {
|
||||
log.Infof("获取快乐之源出错:%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return OK(msg)
|
||||
}
|
||||
|
||||
@ -1444,7 +1461,7 @@ func (bot *CQBot) CQGetStrangerInfo(userID int64) global.MSG {
|
||||
// CQHandleQuickOperation 隐藏API-对事件执行快速操作
|
||||
//
|
||||
// https://git.io/Jtz15
|
||||
// @route(".handle_quick_operation")
|
||||
// @route11(".handle_quick_operation")
|
||||
func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) global.MSG {
|
||||
postType := context.Get("post_type").Str
|
||||
|
||||
@ -1681,9 +1698,9 @@ func (bot *CQBot) CQGetMessage(messageID int32) global.MSG {
|
||||
switch o := msg.(type) {
|
||||
case *db.StoredGroupMessage:
|
||||
m["group_id"] = o.GroupCode
|
||||
m["message"] = ToFormattedMessage(bot.ConvertContentMessage(o.Content, message.SourceGroup), message.Source{SourceType: message.SourceGroup, PrimaryID: o.GroupCode})
|
||||
m["message"] = ToFormattedMessage(bot.ConvertContentMessage(o.Content, message.SourceGroup, false), message.Source{SourceType: message.SourceGroup, PrimaryID: o.GroupCode})
|
||||
case *db.StoredPrivateMessage:
|
||||
m["message"] = ToFormattedMessage(bot.ConvertContentMessage(o.Content, message.SourcePrivate), message.Source{SourceType: message.SourcePrivate})
|
||||
m["message"] = ToFormattedMessage(bot.ConvertContentMessage(o.Content, message.SourcePrivate, false), message.Source{SourceType: message.SourcePrivate})
|
||||
}
|
||||
return OK(m)
|
||||
}
|
||||
@ -1743,7 +1760,7 @@ func (bot *CQBot) CQGetGuildMessage(messageID string, noCache bool) global.MSG {
|
||||
"tiny_id": fU64(channelMsgByDB.Attribute.SenderTinyID),
|
||||
"nickname": channelMsgByDB.Attribute.SenderName,
|
||||
}
|
||||
m["message"] = ToFormattedMessage(bot.ConvertContentMessage(channelMsgByDB.Content, message.SourceGuildChannel), source)
|
||||
m["message"] = ToFormattedMessage(bot.ConvertContentMessage(channelMsgByDB.Content, message.SourceGuildChannel, false), source)
|
||||
}
|
||||
case message.SourceGuildDirect:
|
||||
// todo(mrs4s): 支持 direct 消息
|
||||
@ -1786,10 +1803,14 @@ func (bot *CQBot) CQGetGroupMessageHistory(groupID int64, seq int64) global.MSG
|
||||
log.Warnf("获取群历史消息失败: %v", err)
|
||||
return Failed(100, "MESSAGES_API_ERROR", err.Error())
|
||||
}
|
||||
source := message.Source{
|
||||
SourceType: message.SourcePrivate,
|
||||
PrimaryID: 0,
|
||||
}
|
||||
ms := make([]*event, 0, len(msg))
|
||||
for _, m := range msg {
|
||||
bot.checkMedia(m.Elements, groupID)
|
||||
id := bot.InsertGroupMessage(m)
|
||||
id := bot.InsertGroupMessage(m, source)
|
||||
t := bot.formatGroupMessage(m)
|
||||
t.Others["message_id"] = id
|
||||
ms = append(ms, t)
|
||||
@ -1845,7 +1866,11 @@ func (bot *CQBot) CQCanSendRecord() global.MSG {
|
||||
// @route(ocr_image,".ocr_image")
|
||||
// @rename(image_id->image)
|
||||
func (bot *CQBot) CQOcrImage(imageID string) global.MSG {
|
||||
img, err := bot.makeImageOrVideoElem(map[string]string{"file": imageID}, false, message.SourceGroup)
|
||||
// TODO: fix this
|
||||
var elem msg.Element
|
||||
elem.Type = "image"
|
||||
elem.Data = []msg.Pair{{K: "file", V: imageID}}
|
||||
img, err := bot.makeImageOrVideoElem(elem, false, message.SourceGroup)
|
||||
if err != nil {
|
||||
log.Warnf("load image error: %v", err)
|
||||
return Failed(100, "LOAD_FILE_ERROR", err.Error())
|
||||
@ -1902,8 +1927,8 @@ func (bot *CQBot) CQSetGroupAnonymousBan(groupID int64, flag string, duration in
|
||||
//
|
||||
// https://git.io/JtzMe
|
||||
// @route(get_status)
|
||||
func (bot *CQBot) CQGetStatus(version uint16) global.MSG {
|
||||
if version == 11 {
|
||||
func (bot *CQBot) CQGetStatus(spec *onebot.Spec) global.MSG {
|
||||
if spec.Version == 11 {
|
||||
return OK(global.MSG{
|
||||
"app_initialized": true,
|
||||
"app_enabled": true,
|
||||
@ -2005,14 +2030,14 @@ func (bot *CQBot) CQGetVersionInfo() global.MSG {
|
||||
"protocol_version": "v11",
|
||||
"coolq_directory": wd,
|
||||
"coolq_edition": "pro",
|
||||
"go-cqhttp": true,
|
||||
"go_cqhttp": true,
|
||||
"plugin_version": "4.15.0",
|
||||
"plugin_build_number": 99,
|
||||
"plugin_build_configuration": "release",
|
||||
"runtime_version": runtime.Version(),
|
||||
"runtime_os": runtime.GOOS,
|
||||
"version": base.Version,
|
||||
"protocol_name": client.SystemDeviceInfo.Protocol,
|
||||
"protocol_name": bot.Client.Device().Protocol,
|
||||
})
|
||||
}
|
||||
|
||||
@ -2105,6 +2130,13 @@ func (bot *CQBot) CQReloadEventFilter(file string) global.MSG {
|
||||
return OK(nil)
|
||||
}
|
||||
|
||||
// CQGetSupportedActions 获取支持的动作列表
|
||||
//
|
||||
// @route(get_supported_actions)
|
||||
func (bot *CQBot) CQGetSupportedActions(spec *onebot.Spec) global.MSG {
|
||||
return OK(spec.SupportedActions)
|
||||
}
|
||||
|
||||
// OK 生成成功返回值
|
||||
func OK(data any) global.MSG {
|
||||
return global.MSG{"data": data, "retcode": 0, "status": "ok", "message": ""}
|
||||
|
@ -3,9 +3,10 @@ package coolq
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/Mrs4s/go-cqhttp/global"
|
||||
"github.com/Mrs4s/go-cqhttp/internal/base"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
// CQGetVersion 获取版本信息 OneBotV12
|
||||
@ -27,6 +28,7 @@ func (bot *CQBot) CQGetVersion() global.MSG {
|
||||
//
|
||||
// @route12(send_message)
|
||||
// @rename(m->message)
|
||||
func (bot *CQBot) CQSendMessageV12(groupID, userID, detailType string, m gjson.Result) global.MSG {
|
||||
func (bot *CQBot) CQSendMessageV12(groupID, userID, detailType string, m gjson.Result) global.MSG { // nolint
|
||||
// TODO: implement
|
||||
return OK(nil)
|
||||
}
|
||||
|
54
coolq/bot.go
54
coolq/bot.go
@ -26,6 +26,8 @@ import (
|
||||
"github.com/Mrs4s/go-cqhttp/global"
|
||||
"github.com/Mrs4s/go-cqhttp/internal/base"
|
||||
"github.com/Mrs4s/go-cqhttp/internal/mime"
|
||||
"github.com/Mrs4s/go-cqhttp/internal/msg"
|
||||
"github.com/Mrs4s/go-cqhttp/pkg/onebot"
|
||||
)
|
||||
|
||||
// CQBot CQBot结构体,存储Bot实例相关配置
|
||||
@ -114,7 +116,7 @@ func NewQQBot(cli *client.QQClient) *CQBot {
|
||||
for {
|
||||
<-t.C
|
||||
bot.dispatchEvent("meta_event/heartbeat", global.MSG{
|
||||
"status": bot.CQGetStatus(11)["data"],
|
||||
"status": bot.CQGetStatus(onebot.V11)["data"],
|
||||
"interval": base.HeartbeatInterval.Milliseconds(),
|
||||
})
|
||||
}
|
||||
@ -146,7 +148,7 @@ func (w *worker) wait() {
|
||||
}
|
||||
|
||||
// uploadLocalImage 上传本地图片
|
||||
func (bot *CQBot) uploadLocalImage(target message.Source, img *LocalImageElement) (message.IMessageElement, error) {
|
||||
func (bot *CQBot) uploadLocalImage(target message.Source, img *msg.LocalImage) (message.IMessageElement, error) {
|
||||
if img.File != "" {
|
||||
f, err := os.Open(img.File)
|
||||
if err != nil {
|
||||
@ -171,7 +173,7 @@ func (bot *CQBot) uploadLocalImage(target message.Source, img *LocalImageElement
|
||||
}
|
||||
img.Stream = bytes.NewReader(stream.Bytes())
|
||||
}
|
||||
i, err := bot.Client.UploadImage(target, img.Stream, 4)
|
||||
i, err := bot.Client.UploadImage(target, img.Stream)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -186,20 +188,20 @@ func (bot *CQBot) uploadLocalImage(target message.Source, img *LocalImageElement
|
||||
}
|
||||
|
||||
// uploadLocalVideo 上传本地短视频至群聊
|
||||
func (bot *CQBot) uploadLocalVideo(target message.Source, v *LocalVideoElement) (*message.ShortVideoElement, error) {
|
||||
func (bot *CQBot) uploadLocalVideo(target message.Source, v *msg.LocalVideo) (*message.ShortVideoElement, error) {
|
||||
video, err := os.Open(v.File)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() { _ = video.Close() }()
|
||||
return bot.Client.UploadShortVideo(target, video, v.thumb, 4)
|
||||
return bot.Client.UploadShortVideo(target, video, v.Thumb)
|
||||
}
|
||||
|
||||
func removeLocalElement(elements []message.IMessageElement) []message.IMessageElement {
|
||||
var j int
|
||||
for i, e := range elements {
|
||||
switch e.(type) {
|
||||
case *LocalImageElement, *LocalVideoElement:
|
||||
case *msg.LocalImage, *msg.LocalVideo:
|
||||
case *message.VoiceElement: // 未上传的语音消息, 也删除
|
||||
case nil:
|
||||
default:
|
||||
@ -229,7 +231,7 @@ func (bot *CQBot) uploadMedia(target message.Source, elements []message.IMessage
|
||||
for i, m := range elements {
|
||||
p := &elements[i]
|
||||
switch e := m.(type) {
|
||||
case *LocalImageElement:
|
||||
case *msg.LocalImage:
|
||||
w.do(func() {
|
||||
m, err := bot.uploadLocalImage(target, e)
|
||||
if err != nil {
|
||||
@ -247,7 +249,7 @@ func (bot *CQBot) uploadMedia(target message.Source, elements []message.IMessage
|
||||
*p = m
|
||||
}
|
||||
})
|
||||
case *LocalVideoElement:
|
||||
case *msg.LocalVideo:
|
||||
w.do(func() {
|
||||
m, err := bot.uploadLocalVideo(target, e)
|
||||
if err != nil {
|
||||
@ -273,7 +275,7 @@ func (bot *CQBot) SendGroupMessage(groupID int64, m *message.SendingMessage) (in
|
||||
m.Elements = bot.uploadMedia(source, m.Elements)
|
||||
for _, e := range m.Elements {
|
||||
switch i := e.(type) {
|
||||
case *PokeElement:
|
||||
case *msg.Poke:
|
||||
if group != nil {
|
||||
if mem := group.FindMember(i.Target); mem != nil {
|
||||
mem.Poke()
|
||||
@ -286,7 +288,7 @@ func (bot *CQBot) SendGroupMessage(groupID int64, m *message.SendingMessage) (in
|
||||
log.Warnf("警告: 群 %v 富文本消息发送失败: %v", groupID, err)
|
||||
return -1, errors.Wrap(err, "send group music share error")
|
||||
}
|
||||
return bot.InsertGroupMessage(ret), nil
|
||||
return bot.InsertGroupMessage(ret, source), nil
|
||||
case *message.AtElement:
|
||||
if i.Target == 0 && group.SelfPermission() == client.Member {
|
||||
e = message.NewText("@全体成员")
|
||||
@ -295,17 +297,17 @@ func (bot *CQBot) SendGroupMessage(groupID int64, m *message.SendingMessage) (in
|
||||
newElem = append(newElem, e)
|
||||
}
|
||||
if len(newElem) == 0 {
|
||||
log.Warnf("群消息发送失败: 消息为空.")
|
||||
log.Warnf("群 %v 消息发送失败: 消息为空.", groupID)
|
||||
return -1, errors.New("empty message")
|
||||
}
|
||||
m.Elements = newElem
|
||||
bot.checkMedia(newElem, groupID)
|
||||
ret := bot.Client.SendGroupMessage(groupID, m)
|
||||
if ret == nil || ret.Id == -1 {
|
||||
log.Warnf("群消息发送失败: 账号可能被风控.")
|
||||
log.Warnf("群 %v 发送消息失败: 账号可能被风控.", groupID)
|
||||
return -1, errors.New("send group message failed: blocked by server")
|
||||
}
|
||||
return bot.InsertGroupMessage(ret), nil
|
||||
return bot.InsertGroupMessage(ret, source), nil
|
||||
}
|
||||
|
||||
// SendPrivateMessage 发送私聊消息
|
||||
@ -318,7 +320,7 @@ func (bot *CQBot) SendPrivateMessage(target int64, groupID int64, m *message.Sen
|
||||
m.Elements = bot.uploadMedia(source, m.Elements)
|
||||
for _, e := range m.Elements {
|
||||
switch i := e.(type) {
|
||||
case *PokeElement:
|
||||
case *msg.Poke:
|
||||
bot.Client.SendFriendPoke(i.Target)
|
||||
return 0
|
||||
case *message.MusicShareElement:
|
||||
@ -355,7 +357,7 @@ func (bot *CQBot) SendPrivateMessage(target int64, groupID int64, m *message.Sen
|
||||
case bot.Client.FindFriend(target) != nil: // 双向好友
|
||||
msg := bot.Client.SendPrivateMessage(target, m)
|
||||
if msg != nil {
|
||||
id = bot.InsertPrivateMessage(msg)
|
||||
id = bot.InsertPrivateMessage(msg, source)
|
||||
}
|
||||
case ok || groupID != 0: // 临时会话
|
||||
if !base.AllowTempSession {
|
||||
@ -393,7 +395,7 @@ func (bot *CQBot) SendPrivateMessage(target int64, groupID int64, m *message.Sen
|
||||
case unidirectionalFriendExists(): // 单向好友
|
||||
msg := bot.Client.SendPrivateMessage(target, m)
|
||||
if msg != nil {
|
||||
id = bot.InsertPrivateMessage(msg)
|
||||
id = bot.InsertPrivateMessage(msg, source)
|
||||
}
|
||||
default:
|
||||
nickname := "Unknown"
|
||||
@ -420,7 +422,7 @@ func (bot *CQBot) SendGuildChannelMessage(guildID, channelID uint64, m *message.
|
||||
bot.Client.SendGuildMusicShare(guildID, channelID, i)
|
||||
return "-1" // todo: fix this
|
||||
|
||||
case *message.VoiceElement, *PokeElement:
|
||||
case *message.VoiceElement, *msg.Poke:
|
||||
log.Warnf("警告: 频道暂不支持发送 %v 消息", i.Type().String())
|
||||
continue
|
||||
}
|
||||
@ -442,7 +444,7 @@ func (bot *CQBot) SendGuildChannelMessage(guildID, channelID uint64, m *message.
|
||||
}
|
||||
|
||||
// InsertGroupMessage 群聊消息入数据库
|
||||
func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
|
||||
func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage, source message.Source) int32 {
|
||||
t := &message.SendingMessage{Elements: m.Elements}
|
||||
replyElem := t.FirstOrNil(func(e message.IMessageElement) bool {
|
||||
_, ok := e.(*message.ReplyElement)
|
||||
@ -466,7 +468,7 @@ func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
|
||||
}
|
||||
return ""
|
||||
}(),
|
||||
Content: ToMessageContent(m.Elements),
|
||||
Content: ToMessageContent(m.Elements, source),
|
||||
}
|
||||
if replyElem != nil {
|
||||
reply := replyElem.(*message.ReplyElement)
|
||||
@ -474,7 +476,7 @@ func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
|
||||
msg.QuotedInfo = &db.QuotedInfo{
|
||||
PrevID: encodeMessageID(m.GroupCode, reply.ReplySeq),
|
||||
PrevGlobalID: db.ToGlobalID(m.GroupCode, reply.ReplySeq),
|
||||
QuotedContent: ToMessageContent(reply.Elements),
|
||||
QuotedContent: ToMessageContent(reply.Elements, source),
|
||||
}
|
||||
}
|
||||
if err := db.InsertGroupMessage(msg); err != nil {
|
||||
@ -485,7 +487,7 @@ func (bot *CQBot) InsertGroupMessage(m *message.GroupMessage) int32 {
|
||||
}
|
||||
|
||||
// InsertPrivateMessage 私聊消息入数据库
|
||||
func (bot *CQBot) InsertPrivateMessage(m *message.PrivateMessage) int32 {
|
||||
func (bot *CQBot) InsertPrivateMessage(m *message.PrivateMessage, source message.Source) int32 {
|
||||
t := &message.SendingMessage{Elements: m.Elements}
|
||||
replyElem := t.FirstOrNil(func(e message.IMessageElement) bool {
|
||||
_, ok := e.(*message.ReplyElement)
|
||||
@ -509,7 +511,7 @@ func (bot *CQBot) InsertPrivateMessage(m *message.PrivateMessage) int32 {
|
||||
return m.Sender.Uin
|
||||
}(),
|
||||
TargetUin: m.Target,
|
||||
Content: ToMessageContent(m.Elements),
|
||||
Content: ToMessageContent(m.Elements, source),
|
||||
}
|
||||
if replyElem != nil {
|
||||
reply := replyElem.(*message.ReplyElement)
|
||||
@ -517,7 +519,7 @@ func (bot *CQBot) InsertPrivateMessage(m *message.PrivateMessage) int32 {
|
||||
msg.QuotedInfo = &db.QuotedInfo{
|
||||
PrevID: encodeMessageID(reply.Sender, reply.ReplySeq),
|
||||
PrevGlobalID: db.ToGlobalID(reply.Sender, reply.ReplySeq),
|
||||
QuotedContent: ToMessageContent(reply.Elements),
|
||||
QuotedContent: ToMessageContent(reply.Elements, source),
|
||||
}
|
||||
}
|
||||
if err := db.InsertPrivateMessage(msg); err != nil {
|
||||
@ -560,6 +562,10 @@ func (bot *CQBot) InsertTempMessage(target int64, m *message.TempMessage) int32
|
||||
// InsertGuildChannelMessage 频道消息入数据库
|
||||
func (bot *CQBot) InsertGuildChannelMessage(m *message.GuildChannelMessage) string {
|
||||
id := encodeGuildMessageID(m.GuildId, m.ChannelId, m.Id, message.SourceGuildChannel)
|
||||
source := message.Source{
|
||||
SourceType: message.SourceGuildChannel,
|
||||
PrimaryID: int64(m.Sender.TinyId),
|
||||
}
|
||||
msg := &db.StoredGuildChannelMessage{
|
||||
ID: id,
|
||||
Attribute: &db.StoredGuildMessageAttribute{
|
||||
@ -571,7 +577,7 @@ func (bot *CQBot) InsertGuildChannelMessage(m *message.GuildChannelMessage) stri
|
||||
},
|
||||
GuildID: m.GuildId,
|
||||
ChannelID: m.ChannelId,
|
||||
Content: ToMessageContent(m.Elements),
|
||||
Content: ToMessageContent(m.Elements, source),
|
||||
}
|
||||
if err := db.InsertGuildChannelMessage(msg); err != nil {
|
||||
log.Warnf("记录聊天数据时出现错误: %v", err)
|
||||
|
@ -1,7 +1,6 @@
|
||||
package coolq
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -13,8 +12,6 @@ import (
|
||||
"github.com/Mrs4s/go-cqhttp/global"
|
||||
)
|
||||
|
||||
type IDConverter func(id any) any
|
||||
|
||||
func convertGroupMemberInfo(groupID int64, m *client.GroupMemberInfo) global.MSG {
|
||||
sex := "unknown"
|
||||
if m.Gender == 1 { // unknown = 0xff
|
||||
@ -95,7 +92,7 @@ func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) *event {
|
||||
"name": m.Sender.AnonymousInfo.AnonymousNick,
|
||||
}
|
||||
gm["sender"].(global.MSG)["nickname"] = "匿名消息"
|
||||
gm["sub_type"] = "anonymous"
|
||||
typ = "message/group/anonymous"
|
||||
} else {
|
||||
group := bot.Client.FindGroup(m.GroupCode)
|
||||
mem := group.FindMember(m.Sender.Uin)
|
||||
@ -223,10 +220,3 @@ func toStringMessage(m []message.IMessageElement, source message.Source) string
|
||||
func fU64(v uint64) string {
|
||||
return strconv.FormatUint(v, 10)
|
||||
}
|
||||
|
||||
func ConvertIDWithVersion(v any, version uint16) any {
|
||||
if version == 12 {
|
||||
return fmt.Sprint(v)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
998
coolq/cqcode.go
998
coolq/cqcode.go
File diff suppressed because it is too large
Load Diff
@ -1,79 +0,0 @@
|
||||
// Package cqcode provides CQCode util functions.
|
||||
package cqcode
|
||||
|
||||
import "strings"
|
||||
|
||||
// EscapeText 将字符串raw中部分字符转义
|
||||
//
|
||||
// - & -> &
|
||||
// - [ -> [
|
||||
// - ] -> ]
|
||||
func EscapeText(s string) string {
|
||||
count := strings.Count(s, "&")
|
||||
count += strings.Count(s, "[")
|
||||
count += strings.Count(s, "]")
|
||||
if count == 0 {
|
||||
return s
|
||||
}
|
||||
|
||||
// Apply replacements to buffer.
|
||||
var b strings.Builder
|
||||
b.Grow(len(s) + count*4)
|
||||
start := 0
|
||||
for i := 0; i < count; i++ {
|
||||
j := start
|
||||
for index, r := range s[start:] {
|
||||
if r == '&' || r == '[' || r == ']' {
|
||||
j += index
|
||||
break
|
||||
}
|
||||
}
|
||||
b.WriteString(s[start:j])
|
||||
switch s[j] {
|
||||
case '&':
|
||||
b.WriteString("&")
|
||||
case '[':
|
||||
b.WriteString("[")
|
||||
case ']':
|
||||
b.WriteString("]")
|
||||
}
|
||||
start = j + 1
|
||||
}
|
||||
b.WriteString(s[start:])
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// EscapeValue 将字符串value中部分字符转义
|
||||
//
|
||||
// - , -> ,
|
||||
// - & -> &
|
||||
// - [ -> [
|
||||
// - ] -> ]
|
||||
func EscapeValue(value string) string {
|
||||
ret := EscapeText(value)
|
||||
return strings.ReplaceAll(ret, ",", ",")
|
||||
}
|
||||
|
||||
// UnescapeText 将字符串content中部分字符反转义
|
||||
//
|
||||
// - & -> &
|
||||
// - [ -> [
|
||||
// - ] -> ]
|
||||
func UnescapeText(content string) string {
|
||||
ret := content
|
||||
ret = strings.ReplaceAll(ret, "[", "[")
|
||||
ret = strings.ReplaceAll(ret, "]", "]")
|
||||
ret = strings.ReplaceAll(ret, "&", "&")
|
||||
return ret
|
||||
}
|
||||
|
||||
// UnescapeValue 将字符串content中部分字符反转义
|
||||
//
|
||||
// - , -> ,
|
||||
// - & -> &
|
||||
// - [ -> [
|
||||
// - ] -> ]
|
||||
func UnescapeValue(content string) string {
|
||||
ret := strings.ReplaceAll(content, ",", ",")
|
||||
return UnescapeText(ret)
|
||||
}
|
@ -79,7 +79,7 @@ func (bot *CQBot) privateMessageEvent(_ *client.QQClient, m *message.PrivateMess
|
||||
PrimaryID: m.Sender.Uin,
|
||||
}
|
||||
cqm := toStringMessage(m.Elements, source)
|
||||
id := bot.InsertPrivateMessage(m)
|
||||
id := bot.InsertPrivateMessage(m, source)
|
||||
log.Infof("收到好友 %v(%v) 的消息: %v (%v)", m.Sender.DisplayName(), m.Sender.Uin, cqm, id)
|
||||
typ := "message/private/friend"
|
||||
if m.Sender.Uin == bot.Client.Uin {
|
||||
@ -118,7 +118,7 @@ func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage)
|
||||
"url": c.GetGroupFileUrl(m.GroupCode, file.Path, file.Busid),
|
||||
},
|
||||
})
|
||||
return
|
||||
// return
|
||||
}
|
||||
}
|
||||
source := message.Source{
|
||||
@ -126,7 +126,7 @@ func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage)
|
||||
PrimaryID: m.GroupCode,
|
||||
}
|
||||
cqm := toStringMessage(m.Elements, source)
|
||||
id := bot.InsertGroupMessage(m)
|
||||
id := bot.InsertGroupMessage(m, source)
|
||||
log.Infof("收到群 %v(%v) 内 %v(%v) 的消息: %v (%v)", m.GroupName, m.GroupCode, m.Sender.DisplayName(), m.Sender.Uin, cqm, id)
|
||||
gm := bot.formatGroupMessage(m)
|
||||
if gm == nil {
|
||||
@ -136,7 +136,7 @@ func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage)
|
||||
bot.dispatch(gm)
|
||||
}
|
||||
|
||||
func (bot *CQBot) tempMessageEvent(c *client.QQClient, e *client.TempMessageEvent) {
|
||||
func (bot *CQBot) tempMessageEvent(_ *client.QQClient, e *client.TempMessageEvent) {
|
||||
m := e.Message
|
||||
bot.checkMedia(m.Elements, m.Sender.Uin)
|
||||
source := message.Source{
|
||||
@ -475,6 +475,9 @@ func (bot *CQBot) offlineFileEvent(c *client.QQClient, e *client.OfflineFileEven
|
||||
}
|
||||
|
||||
func (bot *CQBot) joinGroupEvent(c *client.QQClient, group *client.GroupInfo) {
|
||||
if group == nil {
|
||||
return
|
||||
}
|
||||
log.Infof("Bot进入了群 %v.", formatGroupName(group))
|
||||
bot.dispatch(bot.groupIncrease(group.Code, 0, c.Uin))
|
||||
}
|
||||
@ -488,7 +491,7 @@ func (bot *CQBot) leaveGroupEvent(c *client.QQClient, e *client.GroupLeaveEvent)
|
||||
bot.dispatch(bot.groupDecrease(e.Group.Code, c.Uin, e.Operator))
|
||||
}
|
||||
|
||||
func (bot *CQBot) memberPermissionChangedEvent(c *client.QQClient, e *client.MemberPermissionChangedEvent) {
|
||||
func (bot *CQBot) memberPermissionChangedEvent(_ *client.QQClient, e *client.MemberPermissionChangedEvent) {
|
||||
st := "unset"
|
||||
if e.NewPermission == client.Administrator {
|
||||
st = "set"
|
||||
@ -499,7 +502,7 @@ func (bot *CQBot) memberPermissionChangedEvent(c *client.QQClient, e *client.Mem
|
||||
})
|
||||
}
|
||||
|
||||
func (bot *CQBot) memberCardUpdatedEvent(c *client.QQClient, e *client.MemberCardUpdatedEvent) {
|
||||
func (bot *CQBot) memberCardUpdatedEvent(_ *client.QQClient, e *client.MemberCardUpdatedEvent) {
|
||||
log.Infof("群 %v 的 %v 更新了名片 %v -> %v", formatGroupName(e.Group), formatMemberName(e.Member), e.OldCard, e.Member.CardName)
|
||||
bot.dispatchEvent("notice/group_card", global.MSG{
|
||||
"group_id": e.Group.Code,
|
||||
@ -523,7 +526,7 @@ func (bot *CQBot) memberLeaveEvent(_ *client.QQClient, e *client.MemberLeaveGrou
|
||||
bot.dispatch(bot.groupDecrease(e.Group.Code, e.Member.Uin, e.Operator))
|
||||
}
|
||||
|
||||
func (bot *CQBot) friendRequestEvent(c *client.QQClient, e *client.NewFriendRequest) {
|
||||
func (bot *CQBot) friendRequestEvent(_ *client.QQClient, e *client.NewFriendRequest) {
|
||||
log.Infof("收到来自 %v(%v) 的好友请求: %v", e.RequesterNick, e.RequesterUin, e.Message)
|
||||
flag := strconv.FormatInt(e.RequestId, 10)
|
||||
bot.friendReqCache.Store(flag, e)
|
||||
@ -534,7 +537,7 @@ func (bot *CQBot) friendRequestEvent(c *client.QQClient, e *client.NewFriendRequ
|
||||
})
|
||||
}
|
||||
|
||||
func (bot *CQBot) friendAddedEvent(c *client.QQClient, e *client.NewFriendEvent) {
|
||||
func (bot *CQBot) friendAddedEvent(_ *client.QQClient, e *client.NewFriendEvent) {
|
||||
log.Infof("添加了新好友: %v(%v)", e.Friend.Nickname, e.Friend.Uin)
|
||||
bot.tempSessionCache.Delete(e.Friend.Uin)
|
||||
bot.dispatchEvent("notice/friend_add", global.MSG{
|
||||
@ -542,7 +545,7 @@ func (bot *CQBot) friendAddedEvent(c *client.QQClient, e *client.NewFriendEvent)
|
||||
})
|
||||
}
|
||||
|
||||
func (bot *CQBot) groupInvitedEvent(c *client.QQClient, e *client.GroupInvitedRequest) {
|
||||
func (bot *CQBot) groupInvitedEvent(_ *client.QQClient, e *client.GroupInvitedRequest) {
|
||||
log.Infof("收到来自群 %v(%v) 内用户 %v(%v) 的加群邀请.", e.GroupName, e.GroupCode, e.InvitorNick, e.InvitorUin)
|
||||
flag := strconv.FormatInt(e.RequestId, 10)
|
||||
bot.dispatchEvent("request/group/invite", global.MSG{
|
||||
@ -554,7 +557,7 @@ func (bot *CQBot) groupInvitedEvent(c *client.QQClient, e *client.GroupInvitedRe
|
||||
})
|
||||
}
|
||||
|
||||
func (bot *CQBot) groupJoinReqEvent(c *client.QQClient, e *client.UserJoinGroupRequest) {
|
||||
func (bot *CQBot) groupJoinReqEvent(_ *client.QQClient, e *client.UserJoinGroupRequest) {
|
||||
log.Infof("群 %v(%v) 收到来自用户 %v(%v) 的加群请求.", e.GroupName, e.GroupCode, e.RequesterNick, e.RequesterUin)
|
||||
flag := strconv.FormatInt(e.RequestId, 10)
|
||||
bot.dispatchEvent("request/group/add", global.MSG{
|
||||
@ -566,7 +569,7 @@ func (bot *CQBot) groupJoinReqEvent(c *client.QQClient, e *client.UserJoinGroupR
|
||||
})
|
||||
}
|
||||
|
||||
func (bot *CQBot) otherClientStatusChangedEvent(c *client.QQClient, e *client.OtherClientStatusChangedEvent) {
|
||||
func (bot *CQBot) otherClientStatusChangedEvent(_ *client.QQClient, e *client.OtherClientStatusChangedEvent) {
|
||||
if e.Online {
|
||||
log.Infof("Bot 账号在客户端 %v (%v) 登录.", e.Client.DeviceName, e.Client.DeviceKind)
|
||||
} else {
|
||||
|
@ -11,10 +11,12 @@ import (
|
||||
|
||||
sql "github.com/FloatTech/sqlite"
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/Mrs4s/MiraiGo/binary"
|
||||
"github.com/Mrs4s/MiraiGo/utils"
|
||||
|
||||
"github.com/Mrs4s/go-cqhttp/db"
|
||||
)
|
||||
|
||||
@ -27,7 +29,7 @@ type database struct {
|
||||
// config mongodb 相关配置
|
||||
type config struct {
|
||||
Enable bool `yaml:"enable"`
|
||||
CacheTTL time.Duration `yaml:"cachettl"`
|
||||
CacheTTL string `yaml:"cachettl"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
@ -38,7 +40,11 @@ func init() {
|
||||
if !conf.Enable {
|
||||
return nil
|
||||
}
|
||||
return &database{db: new(sql.Sqlite), ttl: conf.CacheTTL}
|
||||
duration, err := time.ParseDuration(conf.CacheTTL)
|
||||
if err != nil {
|
||||
log.Fatalf("illegal ttl config: %v", err)
|
||||
}
|
||||
return &database{db: new(sql.Sqlite), ttl: duration}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -17,4 +17,4 @@ chown -R ${UID}:${GID} /app /data
|
||||
chmod +x /app/cqhttp
|
||||
|
||||
echo "Starting..."
|
||||
su-exec ${USER} /app/cqhttp
|
||||
su-exec ${USER} /app/cqhttp "$@"
|
||||
|
@ -33,9 +33,15 @@ func EncoderSilk(data []byte) ([]byte, error) {
|
||||
// EncodeMP4 将给定视频文件编码为MP4
|
||||
func EncodeMP4(src string, dst string) error { // -y 覆盖文件
|
||||
cmd1 := exec.Command("ffmpeg", "-i", src, "-y", "-c", "copy", "-map", "0", dst)
|
||||
if errors.Is(cmd1.Err, exec.ErrDot) {
|
||||
cmd1.Err = nil
|
||||
}
|
||||
err := cmd1.Run()
|
||||
if err != nil {
|
||||
cmd2 := exec.Command("ffmpeg", "-i", src, "-y", "-c:v", "h264", "-c:a", "mp3", dst)
|
||||
if errors.Is(cmd2.Err, exec.ErrDot) {
|
||||
cmd2.Err = nil
|
||||
}
|
||||
return errors.Wrap(cmd2.Run(), "convert mp4 failed")
|
||||
}
|
||||
return err
|
||||
@ -44,5 +50,8 @@ func EncodeMP4(src string, dst string) error { // -y 覆盖文件
|
||||
// ExtractCover 获取给定视频文件的Cover
|
||||
func ExtractCover(src string, target string) error {
|
||||
cmd := exec.Command("ffmpeg", "-i", src, "-y", "-ss", "0", "-frames:v", "1", target)
|
||||
if errors.Is(cmd.Err, exec.ErrDot) {
|
||||
cmd.Err = nil
|
||||
}
|
||||
return errors.Wrap(cmd.Run(), "extract video cover failed")
|
||||
}
|
||||
|
@ -27,6 +27,8 @@ const (
|
||||
VoicePath = "data/voices"
|
||||
// VideoPath go-cqhttp使用的视频缓存目录
|
||||
VideoPath = "data/videos"
|
||||
// VersionsPath go-cqhttp使用的版本信息目录
|
||||
VersionsPath = "data/versions"
|
||||
// CachePath go-cqhttp使用的缓存目录
|
||||
CachePath = "data/cache"
|
||||
// DumpsPath go-cqhttp使用错误转储目录
|
||||
|
@ -14,9 +14,9 @@ import (
|
||||
func SetupMainSignalHandler() <-chan struct{} {
|
||||
mainOnce.Do(func() {
|
||||
mainStopCh = make(chan struct{})
|
||||
mc := make(chan os.Signal, 3)
|
||||
mc := make(chan os.Signal, 4)
|
||||
closeOnce := sync.Once{}
|
||||
signal.Notify(mc, os.Interrupt, syscall.SIGTERM, syscall.SIGUSR1)
|
||||
signal.Notify(mc, os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGUSR1)
|
||||
go func() {
|
||||
for {
|
||||
switch <-mc {
|
||||
@ -24,7 +24,7 @@ func SetupMainSignalHandler() <-chan struct{} {
|
||||
closeOnce.Do(func() {
|
||||
close(mainStopCh)
|
||||
})
|
||||
case syscall.SIGUSR1:
|
||||
case syscall.SIGQUIT, syscall.SIGUSR1:
|
||||
dumpStack()
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +1,2 @@
|
||||
// Package terminal 包含用于检测在windows下是否通过双击运行go-cqhttp的函数
|
||||
// Package terminal 包含用于检测在windows下是否通过双击运行go-cqhttp, 禁用快速编辑, 启用VT100的函数
|
||||
package terminal
|
||||
|
@ -1,9 +1,8 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package terminal
|
||||
|
||||
// RunningByDoubleClick 检查是否通过双击直接运行,非Windows系统永远返回false
|
||||
// RunningByDoubleClick 检查是否通过双击直接运行,非Windows系统永远返回false
|
||||
func RunningByDoubleClick() bool {
|
||||
return false
|
||||
}
|
||||
|
@ -1,6 +1,3 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package terminal
|
||||
|
||||
import (
|
||||
|
13
global/terminal/quick_edit.go
Normal file
13
global/terminal/quick_edit.go
Normal file
@ -0,0 +1,13 @@
|
||||
//go:build !windows
|
||||
|
||||
package terminal
|
||||
|
||||
// RestoreInputMode 还原输入模式,非Windows系统永远返回nil
|
||||
func RestoreInputMode() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DisableQuickEdit 禁用快速编辑,非Windows系统永远返回nil
|
||||
func DisableQuickEdit() error {
|
||||
return nil
|
||||
}
|
44
global/terminal/quick_edit_windows.go
Normal file
44
global/terminal/quick_edit_windows.go
Normal file
@ -0,0 +1,44 @@
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
var inputmode uint32
|
||||
|
||||
// RestoreInputMode 还原输入模式
|
||||
func RestoreInputMode() error {
|
||||
if inputmode == 0 {
|
||||
return nil
|
||||
}
|
||||
stdin := windows.Handle(os.Stdin.Fd())
|
||||
return windows.SetConsoleMode(stdin, inputmode)
|
||||
}
|
||||
|
||||
// DisableQuickEdit 禁用快速编辑
|
||||
func DisableQuickEdit() error {
|
||||
stdin := windows.Handle(os.Stdin.Fd())
|
||||
|
||||
var mode uint32
|
||||
err := windows.GetConsoleMode(stdin, &mode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
inputmode = mode
|
||||
|
||||
mode &^= windows.ENABLE_QUICK_EDIT_MODE // 禁用快速编辑模式
|
||||
mode |= windows.ENABLE_EXTENDED_FLAGS // 启用扩展标志
|
||||
|
||||
mode &^= windows.ENABLE_MOUSE_INPUT // 禁用鼠标输入
|
||||
mode |= windows.ENABLE_PROCESSED_INPUT // 启用控制输入
|
||||
|
||||
mode &^= windows.ENABLE_INSERT_MODE // 禁用插入模式
|
||||
mode |= windows.ENABLE_ECHO_INPUT | windows.ENABLE_LINE_INPUT // 启用输入回显&逐行输入
|
||||
|
||||
mode &^= windows.ENABLE_WINDOW_INPUT // 禁用窗口输入
|
||||
mode &^= windows.ENABLE_VIRTUAL_TERMINAL_INPUT // 禁用虚拟终端输入
|
||||
|
||||
return windows.SetConsoleMode(stdin, mode)
|
||||
}
|
15
global/terminal/title.go
Normal file
15
global/terminal/title.go
Normal file
@ -0,0 +1,15 @@
|
||||
//go:build !windows
|
||||
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/Mrs4s/go-cqhttp/internal/base"
|
||||
)
|
||||
|
||||
// SetTitle 设置标题为 go-cqhttp `版本` `版权`
|
||||
func SetTitle() {
|
||||
fmt.Printf("\033]0;go-cqhttp "+base.Version+" © 2020 - %d Mrs4s"+"\007", time.Now().Year())
|
||||
}
|
29
global/terminal/title_windows.go
Normal file
29
global/terminal/title_windows.go
Normal file
@ -0,0 +1,29 @@
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
|
||||
"github.com/Mrs4s/go-cqhttp/internal/base"
|
||||
)
|
||||
|
||||
func setConsoleTitle(title string) error {
|
||||
p0, err := syscall.UTF16PtrFromString(title)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r1, _, err := windows.NewLazySystemDLL("kernel32.dll").NewProc("SetConsoleTitleW").Call(uintptr(unsafe.Pointer(p0)))
|
||||
if r1 == 0 {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetTitle 设置标题为 go-cqhttp `版本` `版权`
|
||||
func SetTitle() {
|
||||
_ = setConsoleTitle(fmt.Sprintf("go-cqhttp "+base.Version+" © 2020 - %d Mrs4s", time.Now().Year()))
|
||||
}
|
8
global/terminal/vt100.go
Normal file
8
global/terminal/vt100.go
Normal file
@ -0,0 +1,8 @@
|
||||
//go:build !windows
|
||||
|
||||
package terminal
|
||||
|
||||
// EnableVT100 启用颜色、控制字符,非Windows系统永远返回nil
|
||||
func EnableVT100() error {
|
||||
return nil
|
||||
}
|
23
global/terminal/vt100_windows.go
Normal file
23
global/terminal/vt100_windows.go
Normal file
@ -0,0 +1,23 @@
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// EnableVT100 启用颜色、控制字符
|
||||
func EnableVT100() error {
|
||||
stdout := windows.Handle(os.Stdout.Fd())
|
||||
|
||||
var mode uint32
|
||||
err := windows.GetConsoleMode(stdout, &mode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mode |= windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING // 启用虚拟终端处理
|
||||
mode |= windows.ENABLE_PROCESSED_OUTPUT // 启用处理后的输出
|
||||
|
||||
return windows.SetConsoleMode(stdout, mode)
|
||||
}
|
45
go.mod
45
go.mod
@ -3,28 +3,28 @@ module github.com/Mrs4s/go-cqhttp
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/FloatTech/sqlite v1.5.7
|
||||
github.com/Microsoft/go-winio v0.6.0
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20230213132655-3ff1fee1b645
|
||||
github.com/FloatTech/sqlite v1.6.3
|
||||
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20230823050531-a8213e127b2b
|
||||
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e
|
||||
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc
|
||||
github.com/fumiama/go-base16384 v1.6.1
|
||||
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5
|
||||
github.com/fumiama/go-base16384 v1.7.0
|
||||
github.com/fumiama/go-hide-param v0.1.4
|
||||
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
|
||||
github.com/mattn/go-colorable v0.1.13
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/segmentio/asm v1.2.0
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/stretchr/testify v1.8.1
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
|
||||
github.com/tidwall/gjson v1.14.4
|
||||
github.com/syndtr/goleveldb v1.0.0
|
||||
github.com/tidwall/gjson v1.15.0
|
||||
github.com/wdvxdr1123/go-silk v0.0.0-20210316130616-d47b553def60
|
||||
go.mongodb.org/mongo-driver v1.11.0
|
||||
golang.org/x/crypto v0.3.0
|
||||
golang.org/x/image v0.3.0
|
||||
golang.org/x/sys v0.2.0
|
||||
golang.org/x/term v0.2.0
|
||||
golang.org/x/time v0.2.0
|
||||
go.mongodb.org/mongo-driver v1.12.0
|
||||
golang.org/x/crypto v0.11.0
|
||||
golang.org/x/image v0.9.0
|
||||
golang.org/x/sys v0.10.0
|
||||
golang.org/x/term v0.10.0
|
||||
golang.org/x/time v0.3.0
|
||||
gopkg.ilharper.com/x/isatty v1.1.1
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
@ -39,22 +39,23 @@ require (
|
||||
github.com/jonboulle/clockwork v0.3.0 // indirect
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
|
||||
github.com/klauspost/compress v1.13.6 // indirect
|
||||
github.com/kr/pretty v0.3.1 // indirect
|
||||
github.com/lestrrat-go/strftime v1.0.6 // indirect
|
||||
github.com/mattn/go-isatty v0.0.16 // indirect
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
|
||||
github.com/pierrec/lz4/v4 v4.1.15 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.0 // indirect
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||
github.com/xdg-go/scram v1.1.1 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.3 // indirect
|
||||
github.com/xdg-go/scram v1.1.2 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
|
||||
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde // indirect
|
||||
golang.org/x/text v0.6.0 // indirect
|
||||
golang.org/x/tools v0.1.12 // indirect
|
||||
golang.org/x/mod v0.12.0 // indirect
|
||||
golang.org/x/sync v0.3.0 // indirect
|
||||
golang.org/x/text v0.11.0 // indirect
|
||||
golang.org/x/tools v0.11.0 // indirect
|
||||
lukechampine.com/uint128 v1.2.0 // indirect
|
||||
modernc.org/cc/v3 v3.40.0 // indirect
|
||||
modernc.org/ccgo/v3 v3.16.13 // indirect
|
||||
@ -66,5 +67,3 @@ require (
|
||||
modernc.org/strutil v1.1.3 // indirect
|
||||
modernc.org/token v1.0.1 // indirect
|
||||
)
|
||||
|
||||
replace github.com/remyoudompheng/bigfft => github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b
|
||||
|
162
go.sum
162
go.sum
@ -1,50 +1,42 @@
|
||||
github.com/FloatTech/sqlite v1.5.7 h1:Bvo4LSojcZ6dVtbHrkqvt6z4v8e+sj0G5PSUIvdawsk=
|
||||
github.com/FloatTech/sqlite v1.5.7/go.mod h1:zFbHzRfB+CJ+VidfjuVbrcin3DAz283F7hF1hIeHzpY=
|
||||
github.com/FloatTech/sqlite v1.6.3 h1:MQkqBNlkPuCoKQQgoNLuTL/2Ci3tBTFAnVYBdD0Wy4M=
|
||||
github.com/FloatTech/sqlite v1.6.3/go.mod h1:zFbHzRfB+CJ+VidfjuVbrcin3DAz283F7hF1hIeHzpY=
|
||||
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b h1:tvciXWq2nuvTbFeJGLDNIdRX3BI546D3O7k7vrVueZw=
|
||||
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
|
||||
github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
|
||||
github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20230213132655-3ff1fee1b645 h1:KHWuWmhF2nacb2mKqA3OJorerCEo9n6BNizMuBACa38=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20230213132655-3ff1fee1b645/go.mod h1:mU3fBFU+7eO0kaGes7YRKtzIDtwIU84nSSwTV7NK2b0=
|
||||
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a h1:aU1703IHxupjzipvhu16qYKLMR03e+8WuNR+JMsKfGU=
|
||||
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a/go.mod h1:OZqLNXdYJHmx7aqq/T6wAdFEdoGm5nmIfC4kU7M8P8o=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20230801023408-b4cd7e8f2149 h1:q9w4m+ps0gTyUHLObX6avawN1Rfn0GQwbmEKCZ6WrBo=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20230801023408-b4cd7e8f2149/go.mod h1:mU3fBFU+7eO0kaGes7YRKtzIDtwIU84nSSwTV7NK2b0=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20230823050531-a8213e127b2b h1:0GG6kDFgzie0HNdlkrgPwyX4WqUjckTP1xTM4cYaC2g=
|
||||
github.com/Mrs4s/MiraiGo v0.0.0-20230823050531-a8213e127b2b/go.mod h1:mU3fBFU+7eO0kaGes7YRKtzIDtwIU84nSSwTV7NK2b0=
|
||||
github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d h1:/Xuj3fIiMY2ls1TwvPKmaqQrtJsPY+c9s+0lOScVHd8=
|
||||
github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d/go.mod h1:2Ie+hdBFQpQFDHfeklgxoFmQRCE7O+KwFpISeXq7OwA=
|
||||
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e h1:wR3MXQ3VbUlPKOOUwLOYgh/QaJThBTYtsl673O3lqSA=
|
||||
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e/go.mod h1:vD7Ra3Q9onRtojoY5sMCLQ7JBgjUsrXDnDKyFxqpf9w=
|
||||
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc h1:AAx50/fb/xS4lvsdQg+bFbGvqSDhyV1MF+p2PLCamZ0=
|
||||
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc/go.mod h1:OMmITAib6POA37xCichWM0aRnoVpSMZO1rB/G01wrr0=
|
||||
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5 h1:bBmmB7he0iVN4m5mcehfheeRUEer/Avo4ujnxI3uCqs=
|
||||
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5/go.mod h1:0UcFaCkhp6vZw6l5Dpq0Dp673CoF9GdvA8lTfst0GiU=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
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/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b h1:Zt3pFQditAdWTHCOVkiloc9ZauBoWrb37guFV4iIRvE=
|
||||
github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/fumiama/go-base16384 v1.6.1 h1:4yb4JgmBJDnQtq3XGXXdLrVwEnRpjhMUt4eAcsNeA30=
|
||||
github.com/fumiama/go-base16384 v1.6.1/go.mod h1:OEn+947GV5gsbTAnyuUW/SrfxJYUdYupSIQXOuGOcXM=
|
||||
github.com/fumiama/go-base16384 v1.7.0 h1:6fep7XPQWxRlh4Hu+KsdH+6+YdUp+w6CwRXtMWSsXCA=
|
||||
github.com/fumiama/go-base16384 v1.7.0/go.mod h1:OEn+947GV5gsbTAnyuUW/SrfxJYUdYupSIQXOuGOcXM=
|
||||
github.com/fumiama/go-hide-param v0.1.4 h1:y7TRTzZMdCH9GOXnIzU3B+1BSkcmvejVGmGsz4t0DGU=
|
||||
github.com/fumiama/go-hide-param v0.1.4/go.mod h1:vJkQlJIEI56nIyp7tCQu1/2QOyKtZpudsnJkGk9U1aY=
|
||||
github.com/fumiama/imgsz v0.0.2 h1:fAkC0FnIscdKOXwAxlyw3EUba5NzxZdSxGaq3Uyfxak=
|
||||
github.com/fumiama/imgsz v0.0.2/go.mod h1:dR71mI3I2O5u6+PCpd47M9TZptzP+39tRBcbdIkoqM4=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
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.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/jonboulle/clockwork v0.3.0 h1:9BSCMi8C+0qdApAp4auwX0RkLGUjs956h0EkuQymUhg=
|
||||
github.com/jonboulle/clockwork v0.3.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
|
||||
@ -52,11 +44,10 @@ github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNU
|
||||
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
|
||||
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
|
||||
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
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/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkLibYKgg+SwmyFU9dF2hn6MdTj4=
|
||||
@ -71,141 +62,130 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
|
||||
github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI=
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
|
||||
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||
github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA=
|
||||
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
|
||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
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/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/pierrec/lz4/v4 v4.1.15 h1:MO0/ucJhngq7299dKLwIMtgTfbkoSPF6AoMYDd8Q4q0=
|
||||
github.com/pierrec/lz4/v4 v4.1.15/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
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/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys=
|
||||
github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
|
||||
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
|
||||
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
|
||||
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
|
||||
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
|
||||
github.com/tidwall/gjson v1.15.0 h1:5n/pM+v3r5ujuNl4YLZLsQ+UE5jlkLVm7jMzT5Mpolw=
|
||||
github.com/tidwall/gjson v1.15.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
|
||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/wdvxdr1123/go-silk v0.0.0-20210316130616-d47b553def60 h1:lRKf10iIOW0VsH5WDF621ihzR+R2wEBZVtNRHuLLCb4=
|
||||
github.com/wdvxdr1123/go-silk v0.0.0-20210316130616-d47b553def60/go.mod h1:ecFKZPX81BaB70I6ruUgEwYcDOtuNgJGnjdK+MIl5ko=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
||||
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||
github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E=
|
||||
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
|
||||
github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs=
|
||||
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
|
||||
github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY=
|
||||
github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4=
|
||||
github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8=
|
||||
github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM=
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
|
||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.mongodb.org/mongo-driver v1.11.0 h1:FZKhBSTydeuffHj9CBjXlR8vQLee1cQyTWYPA6/tqiE=
|
||||
go.mongodb.org/mongo-driver v1.11.0/go.mod h1:s7p5vEtfbeR1gYi6pnj3c3/urpbLv2T5Sfd6Rp2HBB8=
|
||||
go.mongodb.org/mongo-driver v1.12.0 h1:aPx33jmn/rQuJXPQLZQ8NtfPQG8CaqgLThFtqRb0PiE=
|
||||
go.mongodb.org/mongo-driver v1.12.0/go.mod h1:AZkxhPnFJUoH7kZlFkVKucV20K387miPfm7oimrSmK0=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A=
|
||||
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||
golang.org/x/image v0.3.0 h1:HTDXbdK9bjfSWkPzDJIw89W8CAtfFGduujWs33NLLsg=
|
||||
golang.org/x/image v0.3.0/go.mod h1:fXd9211C/0VTlYuAcOhW8dY/RtEJqODXOWBDpmYBf+A=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
|
||||
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
|
||||
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
|
||||
golang.org/x/image v0.9.0 h1:QrzfX26snvCM20hIhBwuHI/ThTg18b/+kcKdXHvnR+g=
|
||||
golang.org/x/image v0.9.0/go.mod h1:jtrku+n79PfroUbvDdeUWMAI+heR786BofxrbiSF+J0=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
|
||||
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde h1:ejfdSekXMDxDLbRrJMwUk6KnSLZ2McaUCVcIKM+N6jc=
|
||||
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
|
||||
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/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/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
|
||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
|
||||
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.2.0 h1:z85xZCsEl7bi/KwbNADeBYoOP0++7W1ipu+aGnpwzRM=
|
||||
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c=
|
||||
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
|
||||
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.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
|
||||
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/time v0.2.0 h1:52I/1L54xyEQAYdtcSuxtiT84KGYTBGXwayxmIpNJhE=
|
||||
golang.org/x/time v0.2.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
|
||||
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
|
||||
golang.org/x/time v0.3.0/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-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8=
|
||||
golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/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/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
gopkg.ilharper.com/x/isatty v1.1.1 h1:RAg32Pxq/nIK4AVtdm9RBqxsxZZX1uRKRSS21E5SHMk=
|
||||
gopkg.ilharper.com/x/isatty v1.1.1/go.mod h1:ofpv77Td5qQO6R1dmDd3oNt8TZdRo+l5gYAMxopRyS0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
||||
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/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
@ -37,6 +37,11 @@ var (
|
||||
LogColorful bool // 是否启用日志颜色
|
||||
FastStart bool // 是否为快速启动
|
||||
AllowTempSession bool // 是否允许发送临时会话信息
|
||||
UpdateProtocol bool // 是否更新协议
|
||||
SignServers []config.SignServer // 使用特定的服务器进行签名
|
||||
IsBelow110 bool // 签名服务器版本是否低于1.1.0及以下
|
||||
HTTPTimeout int // download 超时时间
|
||||
SignServerTimeout int // 签名服务器超时时间
|
||||
|
||||
PostFormat string // 上报格式 string or array
|
||||
Proxy string // 存储 proxy_rewrite,用于设置代理
|
||||
@ -60,6 +65,7 @@ func Parse() {
|
||||
flag.StringVar(&LittleWD, "w", "", "cover the working directory")
|
||||
d := flag.Bool("D", false, "debug mode")
|
||||
flag.BoolVar(&FastStart, "faststart", false, "skip waiting 5 seconds")
|
||||
flag.BoolVar(&UpdateProtocol, "update-protocol", false, "update protocol")
|
||||
flag.Parse()
|
||||
|
||||
if *d {
|
||||
@ -84,6 +90,10 @@ func Init() {
|
||||
ReportSelfMessage = conf.Message.ReportSelfMessage
|
||||
UseSSOAddress = conf.Account.UseSSOAddress
|
||||
AllowTempSession = conf.Account.AllowTempSession
|
||||
SignServers = conf.Account.SignServers
|
||||
IsBelow110 = conf.Account.IsBelow110
|
||||
HTTPTimeout = conf.Message.HTTPTimeout
|
||||
SignServerTimeout = int(conf.Account.SignServerTimeout)
|
||||
}
|
||||
{ // others
|
||||
Proxy = conf.Message.ProxyRewrite
|
||||
|
@ -4,6 +4,7 @@ package download
|
||||
import (
|
||||
"bufio"
|
||||
"compress/gzip"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@ -12,26 +13,47 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/RomiChan/syncx"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/Mrs4s/go-cqhttp/internal/base"
|
||||
)
|
||||
|
||||
var client = &http.Client{
|
||||
var client = newClient(time.Second * 15)
|
||||
var clients syncx.Map[time.Duration, *http.Client]
|
||||
|
||||
var clienth2 = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Proxy: func(request *http.Request) (u *url.URL, e error) {
|
||||
Proxy: func(request *http.Request) (*url.URL, error) {
|
||||
if base.Proxy == "" {
|
||||
return http.ProxyFromEnvironment(request)
|
||||
}
|
||||
return url.Parse(base.Proxy)
|
||||
},
|
||||
ForceAttemptHTTP2: false,
|
||||
MaxConnsPerHost: 0,
|
||||
MaxIdleConns: 0,
|
||||
ForceAttemptHTTP2: true,
|
||||
MaxIdleConnsPerHost: 999,
|
||||
},
|
||||
Timeout: time.Second * 15,
|
||||
}
|
||||
|
||||
func newClient(t time.Duration) *http.Client {
|
||||
return &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Proxy: func(request *http.Request) (*url.URL, error) {
|
||||
if base.Proxy == "" {
|
||||
return http.ProxyFromEnvironment(request)
|
||||
}
|
||||
return url.Parse(base.Proxy)
|
||||
},
|
||||
// Disable http2
|
||||
TLSNextProto: map[string]func(authority string, c *tls.Conn) http.RoundTripper{},
|
||||
MaxIdleConnsPerHost: 999,
|
||||
},
|
||||
Timeout: t,
|
||||
}
|
||||
}
|
||||
|
||||
// ErrOverSize 响应主体过大时返回此错误
|
||||
@ -40,15 +62,52 @@ var ErrOverSize = errors.New("oversize")
|
||||
// UserAgent HTTP请求时使用的UA
|
||||
const UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66"
|
||||
|
||||
// WithTimeout get a download instance with timeout t
|
||||
func (r Request) WithTimeout(t time.Duration) *Request {
|
||||
if c, ok := clients.Load(t); ok {
|
||||
r.custcli = c
|
||||
} else {
|
||||
c := newClient(t)
|
||||
clients.Store(t, c)
|
||||
r.custcli = c
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
// SetTimeout set internal/download client timeout
|
||||
func SetTimeout(t time.Duration) {
|
||||
if t == 0 {
|
||||
t = time.Second * 10
|
||||
}
|
||||
client.Timeout = t
|
||||
clienth2.Timeout = t
|
||||
}
|
||||
|
||||
// Request is a file download request
|
||||
type Request struct {
|
||||
Method string
|
||||
URL string
|
||||
Header map[string]string
|
||||
Limit int64
|
||||
Body io.Reader
|
||||
custcli *http.Client
|
||||
}
|
||||
|
||||
func (r Request) client() *http.Client {
|
||||
if r.custcli != nil {
|
||||
return r.custcli
|
||||
}
|
||||
if strings.Contains(r.URL, "go-cqhttp.org") {
|
||||
return clienth2
|
||||
}
|
||||
return client
|
||||
}
|
||||
|
||||
func (r Request) do() (*http.Response, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, r.URL, nil)
|
||||
if r.Method == "" {
|
||||
r.Method = http.MethodGet
|
||||
}
|
||||
req, err := http.NewRequest(r.Method, r.URL, r.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -58,7 +117,7 @@ func (r Request) do() (*http.Response, error) {
|
||||
req.Header.Set(k, v)
|
||||
}
|
||||
|
||||
return client.Do(req)
|
||||
return r.client().Do(req)
|
||||
}
|
||||
|
||||
func (r Request) body() (io.ReadCloser, error) {
|
||||
@ -79,23 +138,25 @@ func (r Request) body() (io.ReadCloser, error) {
|
||||
return resp.Body, err
|
||||
}
|
||||
|
||||
// Bytes 对给定URL发送Get请求,返回响应主体
|
||||
// Bytes 对给定URL发送请求,返回响应主体
|
||||
func (r Request) Bytes() ([]byte, error) {
|
||||
rd, err := r.body()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rd.Close()
|
||||
defer r.client().CloseIdleConnections()
|
||||
return io.ReadAll(rd)
|
||||
}
|
||||
|
||||
// JSON 发送GET请求, 并转换响应为JSON
|
||||
// JSON 发送请求, 并转换响应为JSON
|
||||
func (r Request) JSON() (gjson.Result, error) {
|
||||
rd, err := r.body()
|
||||
if err != nil {
|
||||
return gjson.Result{}, err
|
||||
}
|
||||
defer rd.Close()
|
||||
defer r.client().CloseIdleConnections()
|
||||
|
||||
var sb strings.Builder
|
||||
_, err = io.Copy(&sb, rd)
|
||||
@ -123,6 +184,7 @@ func (r Request) WriteToFile(path string) error {
|
||||
return err
|
||||
}
|
||||
defer rd.Close()
|
||||
defer r.client().CloseIdleConnections()
|
||||
return writeToFile(rd, path)
|
||||
}
|
||||
|
||||
@ -132,6 +194,7 @@ func (r Request) WriteToFileMultiThreading(path string, thread int) error {
|
||||
return r.WriteToFile(path)
|
||||
}
|
||||
|
||||
defer r.client().CloseIdleConnections()
|
||||
limit := r.Limit
|
||||
type BlockMetaData struct {
|
||||
BeginOffset int64
|
||||
|
@ -1,4 +1,5 @@
|
||||
package cqcode
|
||||
// Package msg 提供了go-cqhttp消息中间表示,CQ码处理等等
|
||||
package msg
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -8,16 +9,105 @@ import (
|
||||
"github.com/Mrs4s/MiraiGo/binary"
|
||||
)
|
||||
|
||||
// @@@ CQ码转义处理 @@@
|
||||
|
||||
// EscapeText 将字符串raw中部分字符转义
|
||||
//
|
||||
// - & -> &
|
||||
// - [ -> [
|
||||
// - ] -> ]
|
||||
func EscapeText(s string) string {
|
||||
count := strings.Count(s, "&")
|
||||
count += strings.Count(s, "[")
|
||||
count += strings.Count(s, "]")
|
||||
if count == 0 {
|
||||
return s
|
||||
}
|
||||
|
||||
// Apply replacements to buffer.
|
||||
var b strings.Builder
|
||||
b.Grow(len(s) + count*4)
|
||||
start := 0
|
||||
for i := 0; i < count; i++ {
|
||||
j := start
|
||||
for index, r := range s[start:] {
|
||||
if r == '&' || r == '[' || r == ']' {
|
||||
j += index
|
||||
break
|
||||
}
|
||||
}
|
||||
b.WriteString(s[start:j])
|
||||
switch s[j] {
|
||||
case '&':
|
||||
b.WriteString("&")
|
||||
case '[':
|
||||
b.WriteString("[")
|
||||
case ']':
|
||||
b.WriteString("]")
|
||||
}
|
||||
start = j + 1
|
||||
}
|
||||
b.WriteString(s[start:])
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// EscapeValue 将字符串value中部分字符转义
|
||||
//
|
||||
// - , -> ,
|
||||
// - & -> &
|
||||
// - [ -> [
|
||||
// - ] -> ]
|
||||
func EscapeValue(value string) string {
|
||||
ret := EscapeText(value)
|
||||
return strings.ReplaceAll(ret, ",", ",")
|
||||
}
|
||||
|
||||
// UnescapeText 将字符串content中部分字符反转义
|
||||
//
|
||||
// - & -> &
|
||||
// - [ -> [
|
||||
// - ] -> ]
|
||||
func UnescapeText(content string) string {
|
||||
ret := content
|
||||
ret = strings.ReplaceAll(ret, "[", "[")
|
||||
ret = strings.ReplaceAll(ret, "]", "]")
|
||||
ret = strings.ReplaceAll(ret, "&", "&")
|
||||
return ret
|
||||
}
|
||||
|
||||
// UnescapeValue 将字符串content中部分字符反转义
|
||||
//
|
||||
// - , -> ,
|
||||
// - & -> &
|
||||
// - [ -> [
|
||||
// - ] -> ]
|
||||
func UnescapeValue(content string) string {
|
||||
ret := strings.ReplaceAll(content, ",", ",")
|
||||
return UnescapeText(ret)
|
||||
}
|
||||
|
||||
// @@@ 消息中间表示 @@@
|
||||
|
||||
// Pair key value pair
|
||||
type Pair struct {
|
||||
K string
|
||||
V string
|
||||
}
|
||||
|
||||
// Element single message
|
||||
type Element struct {
|
||||
Type string
|
||||
Data []Pair
|
||||
}
|
||||
|
||||
// Pair key value pair
|
||||
type Pair struct {
|
||||
K string
|
||||
V string
|
||||
// Get 获取指定值
|
||||
func (e *Element) Get(k string) string {
|
||||
for _, datum := range e.Data {
|
||||
if datum.K == k {
|
||||
return datum.V
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// CQCode convert element to cqcode
|
||||
@ -60,7 +150,7 @@ func (e *Element) MarshalJSON() ([]byte, error) {
|
||||
buf.WriteByte('"')
|
||||
buf.WriteString(data.K)
|
||||
buf.WriteString(`":`)
|
||||
writeQuote(buf, data.V)
|
||||
buf.WriteString(QuoteJSON(data.V))
|
||||
}
|
||||
buf.WriteString(`}}`)
|
||||
}), nil
|
||||
@ -68,9 +158,10 @@ func (e *Element) MarshalJSON() ([]byte, error) {
|
||||
|
||||
const hex = "0123456789abcdef"
|
||||
|
||||
func writeQuote(b *bytes.Buffer, s string) {
|
||||
// QuoteJSON 按JSON转义为字符加上双引号
|
||||
func QuoteJSON(s string) string {
|
||||
i, j := 0, 0
|
||||
|
||||
var b strings.Builder
|
||||
b.WriteByte('"')
|
||||
for j < len(s) {
|
||||
c := s[j]
|
||||
@ -151,4 +242,5 @@ func writeQuote(b *bytes.Buffer, s string) {
|
||||
|
||||
b.WriteString(s[i:])
|
||||
b.WriteByte('"')
|
||||
return b.String()
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package cqcode
|
||||
package msg
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
@ -14,16 +13,14 @@ func jsonMarshal(s string) string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func Test_quote(t *testing.T) {
|
||||
func TestQuoteJSON(t *testing.T) {
|
||||
testcase := []string{
|
||||
"\u0005", // issue 1773
|
||||
"\v",
|
||||
}
|
||||
|
||||
for _, input := range testcase {
|
||||
var b bytes.Buffer
|
||||
writeQuote(&b, input)
|
||||
got := b.String()
|
||||
got := QuoteJSON(input)
|
||||
expected := jsonMarshal(input)
|
||||
if got != expected {
|
||||
t.Errorf("want %v but got %v", expected, got)
|
44
internal/msg/local.go
Normal file
44
internal/msg/local.go
Normal file
@ -0,0 +1,44 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/Mrs4s/MiraiGo/message"
|
||||
)
|
||||
|
||||
// Poke 拍一拍
|
||||
type Poke struct {
|
||||
Target int64
|
||||
}
|
||||
|
||||
// Type 获取元素类型ID
|
||||
func (e *Poke) Type() message.ElementType {
|
||||
// Make message.IMessageElement Happy
|
||||
return message.At
|
||||
}
|
||||
|
||||
// LocalImage 本地图片
|
||||
type LocalImage struct {
|
||||
Stream io.ReadSeeker
|
||||
File string
|
||||
URL string
|
||||
|
||||
Flash bool
|
||||
EffectID int32
|
||||
}
|
||||
|
||||
// Type implements the message.IMessageElement.
|
||||
func (e *LocalImage) Type() message.ElementType {
|
||||
return message.Image
|
||||
}
|
||||
|
||||
// LocalVideo 本地视频
|
||||
type LocalVideo struct {
|
||||
File string
|
||||
Thumb io.ReadSeeker
|
||||
}
|
||||
|
||||
// Type impl message.IMessageElement
|
||||
func (e *LocalVideo) Type() message.ElementType {
|
||||
return message.Video
|
||||
}
|
104
internal/msg/parse.go
Normal file
104
internal/msg/parse.go
Normal file
@ -0,0 +1,104 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
// ParseObject 将消息JSON对象转为消息元素数组
|
||||
func ParseObject(m gjson.Result) (r []Element) {
|
||||
convert := func(e gjson.Result) {
|
||||
var elem Element
|
||||
elem.Type = e.Get("type").Str
|
||||
e.Get("data").ForEach(func(key, value gjson.Result) bool {
|
||||
pair := Pair{K: key.Str, V: value.String()}
|
||||
elem.Data = append(elem.Data, pair)
|
||||
return true
|
||||
})
|
||||
r = append(r, elem)
|
||||
}
|
||||
|
||||
if m.IsArray() {
|
||||
m.ForEach(func(_, e gjson.Result) bool {
|
||||
convert(e)
|
||||
return true
|
||||
})
|
||||
}
|
||||
if m.IsObject() {
|
||||
convert(m)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func text(txt string) Element {
|
||||
return Element{
|
||||
Type: "text",
|
||||
Data: []Pair{
|
||||
{
|
||||
K: "text",
|
||||
V: txt,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// ParseString 将字符串(CQ码)转为消息元素数组
|
||||
func ParseString(raw string) (r []Element) {
|
||||
var elem Element
|
||||
for raw != "" {
|
||||
i := 0
|
||||
for i < len(raw) && !(raw[i] == '[' && i+4 < len(raw) && raw[i:i+4] == "[CQ:") {
|
||||
i++
|
||||
}
|
||||
if i > 0 {
|
||||
r = append(r, text(UnescapeText(raw[:i])))
|
||||
}
|
||||
|
||||
if i+4 > len(raw) {
|
||||
return
|
||||
}
|
||||
raw = raw[i+4:] // skip "[CQ:"
|
||||
i = 0
|
||||
for i < len(raw) && raw[i] != ',' && raw[i] != ']' {
|
||||
i++
|
||||
}
|
||||
if i+1 > len(raw) {
|
||||
return
|
||||
}
|
||||
elem.Type = raw[:i]
|
||||
elem.Data = nil // reset data
|
||||
raw = raw[i:]
|
||||
i = 0
|
||||
for {
|
||||
if raw[0] == ']' {
|
||||
r = append(r, elem)
|
||||
raw = raw[1:]
|
||||
break
|
||||
}
|
||||
raw = raw[1:]
|
||||
|
||||
for i < len(raw) && raw[i] != '=' {
|
||||
i++
|
||||
}
|
||||
if i+1 > len(raw) {
|
||||
return
|
||||
}
|
||||
key := raw[:i]
|
||||
raw = raw[i+1:] // skip "="
|
||||
i = 0
|
||||
for i < len(raw) && raw[i] != ',' && raw[i] != ']' {
|
||||
i++
|
||||
}
|
||||
|
||||
if i+1 > len(raw) {
|
||||
return
|
||||
}
|
||||
elem.Data = append(elem.Data, Pair{
|
||||
K: key,
|
||||
V: UnescapeValue(raw[:i]),
|
||||
})
|
||||
raw = raw[i:]
|
||||
i = 0
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
@ -1,22 +1,18 @@
|
||||
package coolq
|
||||
package msg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Mrs4s/MiraiGo/message"
|
||||
"github.com/Mrs4s/MiraiGo/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/Mrs4s/go-cqhttp/coolq/cqcode"
|
||||
)
|
||||
|
||||
var bot = CQBot{}
|
||||
|
||||
func TestCQBot_ConvertStringMessage(t *testing.T) {
|
||||
for _, v := range bot.ConvertStringMessage(`[CQ:face,id=115,text=111][CQ:face,id=217]] [CQ:text,text=123] [`, message.SourcePrivate) {
|
||||
func TestParseString(_ *testing.T) {
|
||||
// TODO: add more text
|
||||
for _, v := range ParseString(`[CQ:face,id=115,text=111][CQ:face,id=217]] [CQ:text,text=123] [`) {
|
||||
fmt.Println(v)
|
||||
}
|
||||
}
|
||||
@ -26,17 +22,18 @@ var (
|
||||
benchArray = gjson.Parse(`[{"type":"text","data":{"text":"asdfqwerqwerqwer"}},{"type":"face","data":{"id":"115","text":"111"}},{"type":"text","data":{"text":"asdfasdfasdfasdfasdfasdfasd"}},{"type":"face","data":{"id":"217"}},{"type":"text","data":{"text":"] "}},{"type":"text","data":{"text":"123"}},{"type":"text","data":{"text":" ["}}]`)
|
||||
)
|
||||
|
||||
func BenchmarkCQBot_ConvertStringMessage(b *testing.B) {
|
||||
func BenchmarkParseString(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
bot.ConvertStringMessage(bench, message.SourcePrivate)
|
||||
ParseString(bench)
|
||||
}
|
||||
b.SetBytes(int64(len(bench)))
|
||||
}
|
||||
|
||||
func BenchmarkCQBot_ConvertObjectMessage(b *testing.B) {
|
||||
func BenchmarkParseObject(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
bot.ConvertObjectMessage(benchArray, message.SourcePrivate)
|
||||
ParseObject(benchArray)
|
||||
}
|
||||
b.SetBytes(int64(len(benchArray.Raw)))
|
||||
}
|
||||
|
||||
const bText = `123456789[]&987654321[]&987654321[]&987654321[]&987654321[]&987654321[]&`
|
||||
@ -44,16 +41,7 @@ const bText = `123456789[]&987654321[]&987654321[]&987654321[]&987654321[]&98765
|
||||
func BenchmarkCQCodeEscapeText(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
ret := bText
|
||||
cqcode.EscapeText(ret)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCQCodeEscapeTextBefore(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
ret := bText
|
||||
ret = strings.ReplaceAll(ret, "&", "&")
|
||||
ret = strings.ReplaceAll(ret, "[", "[")
|
||||
strings.ReplaceAll(ret, "]", "]")
|
||||
EscapeText(ret)
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,6 +52,6 @@ func TestCQCodeEscapeText(t *testing.T) {
|
||||
ret = strings.ReplaceAll(ret, "&", "&")
|
||||
ret = strings.ReplaceAll(ret, "[", "[")
|
||||
ret = strings.ReplaceAll(ret, "]", "]")
|
||||
assert.Equal(t, ret, cqcode.EscapeText(rs))
|
||||
assert.Equal(t, ret, EscapeText(rs))
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package selfupdate
|
||||
|
||||
|
10
main.go
10
main.go
@ -3,6 +3,7 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/Mrs4s/go-cqhttp/cmd/gocq"
|
||||
"github.com/Mrs4s/go-cqhttp/global/terminal"
|
||||
|
||||
_ "github.com/Mrs4s/go-cqhttp/db/leveldb" // leveldb 数据库支持
|
||||
_ "github.com/Mrs4s/go-cqhttp/modules/silk" // silk编码模块
|
||||
@ -13,5 +14,12 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
gocq.Main()
|
||||
terminal.SetTitle()
|
||||
gocq.InitBase()
|
||||
gocq.PrepareData()
|
||||
gocq.LoginInteract()
|
||||
_ = terminal.DisableQuickEdit()
|
||||
_ = terminal.EnableVT100()
|
||||
gocq.WaitSignal()
|
||||
_ = terminal.RestoreInputMode()
|
||||
}
|
||||
|
@ -5,34 +5,16 @@ package api
|
||||
import (
|
||||
"github.com/Mrs4s/go-cqhttp/coolq"
|
||||
"github.com/Mrs4s/go-cqhttp/global"
|
||||
"github.com/Mrs4s/go-cqhttp/pkg/onebot"
|
||||
)
|
||||
|
||||
func (c *Caller) call(action string, version uint16, p Getter) global.MSG {
|
||||
var converter coolq.IDConverter = func(id any) any {
|
||||
return coolq.ConvertIDWithVersion(id, version)
|
||||
}
|
||||
if version == 12 {
|
||||
if action == "get_supported_actions" {
|
||||
return coolq.OK([]string{".get_word_slices", ".handle_quick_operation", ".ocr_image", "ocr_image", "_get_group_notice", "_get_model_show", "_send_group_notice", "_set_model_show", "check_url_safely", "create_group_file_folder", "create_guild_role", "delete_essence_msg", "delete_friend", "delete_group_file", "delete_group_folder", "delete_guild_role", "delete_msg", "delete_unidirectional_friend", "download_file", "get_essence_msg_list", "get_forward_msg", "get_friend_list", "get_group_at_all_remain", "get_group_file_system_info", "get_group_file_url", "get_group_files_by_folder", "get_group_honor_info", "get_group_info", "get_group_list", "get_group_member_info", "get_group_member_list", "get_group_msg_history", "get_group_root_files", "get_group_system_msg", "get_guild_channel_list", "get_guild_list", "get_guild_member_list", "get_guild_member_profile", "get_guild_meta_by_guest", "get_guild_msg", "get_guild_roles", "get_guild_service_profile", "get_image", "get_self_info", "get_msg", "get_online_clients", "get_status", "get_user_info", "get_topic_channel_feeds", "get_unidirectional_friend_list", "get_version", "mark_msg_as_read", "qidian_get_account_info", "reload_event_filter", "send_group_sign", "send_guild_channel_msg", "send_message", "set_essence_msg", "set_friend_add_request", "set_group_add_request", "set_group_admin", "set_group_anonymous_ban", "set_group_ban", "set_group_card", "set_group_kick", "set_group_leave", "set_group_name", "set_group_portrait", "set_group_special_title", "set_group_whole_ban", "set_guild_member_role", "set_qq_profile", "update_guild_role", "upload_group_file"})
|
||||
}
|
||||
switch action {
|
||||
case "get_self_info":
|
||||
return c.bot.CQGetLoginInfo()
|
||||
case "get_user_info":
|
||||
p0 := p.Get("user_id").Int()
|
||||
return c.bot.CQGetStrangerInfo(p0)
|
||||
case "get_version":
|
||||
return c.bot.CQGetVersion()
|
||||
case "send_message":
|
||||
p0 := p.Get("group_id").String()
|
||||
p1 := p.Get("user_id").String()
|
||||
p2 := p.Get("detail_type").String()
|
||||
p3 := p.Get("message")
|
||||
return c.bot.CQSendMessageV12(p0, p1, p2, p3)
|
||||
}
|
||||
}
|
||||
if version == 11 {
|
||||
func (c *Caller) call(action string, spec *onebot.Spec, p Getter) global.MSG {
|
||||
if spec.Version == 11 {
|
||||
switch action {
|
||||
case ".handle_quick_operation":
|
||||
p0 := p.Get("context")
|
||||
p1 := p.Get("operation")
|
||||
return c.bot.CQHandleQuickOperation(p0, p1)
|
||||
case "can_send_image":
|
||||
return c.bot.CQCanSendImage()
|
||||
case "can_send_record":
|
||||
@ -78,14 +60,27 @@ func (c *Caller) call(action string, version uint16, p Getter) global.MSG {
|
||||
return c.bot.CQSendPrivateMessage(p0, p1, p2, p3)
|
||||
}
|
||||
}
|
||||
if spec.Version == 12 {
|
||||
switch action {
|
||||
case "get_self_info":
|
||||
return c.bot.CQGetLoginInfo()
|
||||
case "get_user_info":
|
||||
p0 := p.Get("user_id").Int()
|
||||
return c.bot.CQGetStrangerInfo(p0)
|
||||
case "get_version":
|
||||
return c.bot.CQGetVersion()
|
||||
case "send_message":
|
||||
p0 := p.Get("group_id").String()
|
||||
p1 := p.Get("user_id").String()
|
||||
p2 := p.Get("detail_type").String()
|
||||
p3 := p.Get("message")
|
||||
return c.bot.CQSendMessageV12(p0, p1, p2, p3)
|
||||
}
|
||||
}
|
||||
switch action {
|
||||
case ".get_word_slices":
|
||||
p0 := p.Get("content").String()
|
||||
return c.bot.CQGetWordSlices(p0)
|
||||
case ".handle_quick_operation":
|
||||
p0 := p.Get("context")
|
||||
p1 := p.Get("operation")
|
||||
return c.bot.CQHandleQuickOperation(p0, p1)
|
||||
case ".ocr_image", "ocr_image":
|
||||
p0 := p.Get("image").String()
|
||||
return c.bot.CQOcrImage(p0)
|
||||
@ -160,7 +155,7 @@ func (c *Caller) call(action string, version uint16, p Getter) global.MSG {
|
||||
p0 := p.Get("[message_id,id].0").String()
|
||||
return c.bot.CQGetForwardMessage(p0)
|
||||
case "get_friend_list":
|
||||
return c.bot.CQGetFriendList(version)
|
||||
return c.bot.CQGetFriendList(spec)
|
||||
case "get_group_at_all_remain":
|
||||
p0 := p.Get("group_id").Int()
|
||||
return c.bot.CQGetAtAllRemain(p0)
|
||||
@ -183,10 +178,10 @@ func (c *Caller) call(action string, version uint16, p Getter) global.MSG {
|
||||
case "get_group_info":
|
||||
p0 := p.Get("group_id").Int()
|
||||
p1 := p.Get("no_cache").Bool()
|
||||
return c.bot.CQGetGroupInfo(p0, p1, converter)
|
||||
return c.bot.CQGetGroupInfo(p0, p1, spec)
|
||||
case "get_group_list":
|
||||
p0 := p.Get("no_cache").Bool()
|
||||
return c.bot.CQGetGroupList(p0, converter)
|
||||
return c.bot.CQGetGroupList(p0, spec)
|
||||
case "get_group_member_info":
|
||||
p0 := p.Get("group_id").Int()
|
||||
p1 := p.Get("user_id").Int()
|
||||
@ -241,7 +236,9 @@ func (c *Caller) call(action string, version uint16, p Getter) global.MSG {
|
||||
p0 := p.Get("no_cache").Bool()
|
||||
return c.bot.CQGetOnlineClients(p0)
|
||||
case "get_status":
|
||||
return c.bot.CQGetStatus(version)
|
||||
return c.bot.CQGetStatus(spec)
|
||||
case "get_supported_actions":
|
||||
return c.bot.CQGetSupportedActions(spec)
|
||||
case "get_topic_channel_feeds":
|
||||
p0 := p.Get("guild_id").Uint()
|
||||
p1 := p.Get("channel_id").Uint()
|
||||
|
@ -6,9 +6,10 @@ import (
|
||||
|
||||
"github.com/Mrs4s/go-cqhttp/coolq"
|
||||
"github.com/Mrs4s/go-cqhttp/global"
|
||||
"github.com/Mrs4s/go-cqhttp/pkg/onebot"
|
||||
)
|
||||
|
||||
//go:generate go run github.com/Mrs4s/go-cqhttp/cmd/api-generator -path=./../../coolq/api.go,./../../coolq/api_v12.go
|
||||
//go:generate go run ./../../cmd/api-generator -pkg api -path=./../../coolq/api.go,./../../coolq/api_v12.go -o api.go
|
||||
|
||||
// Getter 参数获取
|
||||
type Getter interface {
|
||||
@ -16,7 +17,7 @@ type Getter interface {
|
||||
}
|
||||
|
||||
// Handler 中间件
|
||||
type Handler func(action string, p Getter) global.MSG
|
||||
type Handler func(action string, spe *onebot.Spec, p Getter) global.MSG
|
||||
|
||||
// Caller api route caller
|
||||
type Caller struct {
|
||||
@ -25,13 +26,13 @@ type Caller struct {
|
||||
}
|
||||
|
||||
// Call specific API
|
||||
func (c *Caller) Call(action string, version uint16, p Getter) global.MSG {
|
||||
func (c *Caller) Call(action string, spec *onebot.Spec, p Getter) global.MSG {
|
||||
for _, fn := range c.handlers {
|
||||
if ret := fn(action, p); ret != nil {
|
||||
if ret := fn(action, spec, p); ret != nil {
|
||||
return ret
|
||||
}
|
||||
}
|
||||
return c.call(action, version, p)
|
||||
return c.call(action, spec, p)
|
||||
}
|
||||
|
||||
// Use add handlers to the API caller
|
||||
|
@ -35,6 +35,21 @@ type Account struct {
|
||||
ReLogin *Reconnect `yaml:"relogin"`
|
||||
UseSSOAddress bool `yaml:"use-sso-address"`
|
||||
AllowTempSession bool `yaml:"allow-temp-session"`
|
||||
SignServers []SignServer `yaml:"sign-servers"`
|
||||
RuleChangeSignServer int `yaml:"rule-change-sign-server"`
|
||||
MaxCheckCount uint `yaml:"max-check-count"`
|
||||
SignServerTimeout uint `yaml:"sign-server-timeout"`
|
||||
IsBelow110 bool `yaml:"is-below-110"`
|
||||
AutoRegister bool `yaml:"auto-register"`
|
||||
AutoRefreshToken bool `yaml:"auto-refresh-token"`
|
||||
RefreshInterval int64 `yaml:"refresh-interval"`
|
||||
}
|
||||
|
||||
// SignServer 签名服务器
|
||||
type SignServer struct {
|
||||
URL string `yaml:"url"`
|
||||
Key string `yaml:"key"`
|
||||
Authorization string `yaml:"authorization"`
|
||||
}
|
||||
|
||||
// Config 总配置文件
|
||||
@ -56,6 +71,7 @@ type Config struct {
|
||||
ExtraReplyData bool `yaml:"extra-reply-data"`
|
||||
SkipMimeScan bool `yaml:"skip-mime-scan"`
|
||||
ConvertWebpImage bool `yaml:"convert-webp-image"`
|
||||
HTTPTimeout int `yaml:"http-timeout"`
|
||||
} `yaml:"message"`
|
||||
|
||||
Output struct {
|
||||
|
@ -16,6 +16,57 @@ account: # 账号相关
|
||||
# 是否允许发送临时会话消息
|
||||
allow-temp-session: false
|
||||
|
||||
# 数据包的签名服务器列表,第一个作为主签名服务器,后续作为备用
|
||||
# 兼容 https://github.com/fuqiuluo/unidbg-fetch-qsign
|
||||
# 如果遇到 登录 45 错误, 或者发送信息风控的话需要填入一个或多个服务器
|
||||
# 不建议设置过多,设置主备各一个即可,超过 5 个只会取前五个
|
||||
# 示例:
|
||||
# sign-servers:
|
||||
# - url: 'http://127.0.0.1:8080' # 本地签名服务器
|
||||
# key: "114514" # 相应 key
|
||||
# authorization: "-" # authorization 内容, 依服务端设置
|
||||
# - url: 'https://signserver.example.com' # 线上签名服务器
|
||||
# key: "114514"
|
||||
# authorization: "-"
|
||||
# ...
|
||||
#
|
||||
# 服务器可使用docker在本地搭建或者使用他人开放的服务
|
||||
sign-servers:
|
||||
- url: '-' # 主签名服务器地址, 必填
|
||||
key: '114514' # 签名服务器所需要的apikey, 如果签名服务器的版本在1.1.0及以下则此项无效
|
||||
authorization: '-' # authorization 内容, 依服务端设置,如 'Bearer xxxx'
|
||||
- url: '-' # 备用
|
||||
key: '114514'
|
||||
authorization: '-'
|
||||
|
||||
# 判断签名服务不可用(需要切换)的额外规则
|
||||
# 0: 不设置 (此时仅在请求无法返回结果时判定为不可用)
|
||||
# 1: 在获取到的 sign 为空 (若选此建议关闭 auto-register,一般为实例未注册但是请求签名的情况)
|
||||
# 2: 在获取到的 sign 或 token 为空(若选此建议关闭 auto-refresh-token )
|
||||
rule-change-sign-server: 1
|
||||
|
||||
# 连续寻找可用签名服务器最大尝试次数
|
||||
# 为 0 时会在连续 3 次没有找到可用签名服务器后保持使用主签名服务器,不再尝试进行切换备用
|
||||
# 否则会在达到指定次数后 **退出** 主程序
|
||||
max-check-count: 0
|
||||
# 签名服务请求超时时间(s)
|
||||
sign-server-timeout: 60
|
||||
# 如果签名服务器的版本在1.1.0及以下, 请将下面的参数改成true
|
||||
# 建议使用 1.1.6 以上版本,低版本普遍半个月冻结一次
|
||||
is-below-110: false
|
||||
# 在实例可能丢失(获取到的签名为空)时是否尝试重新注册
|
||||
# 为 true 时,在签名服务不可用时可能每次发消息都会尝试重新注册并签名。
|
||||
# 为 false 时,将不会自动注册实例,在签名服务器重启或实例被销毁后需要重启 go-cqhttp 以获取实例
|
||||
# 否则后续消息将不会正常签名。关闭此项后可以考虑开启签名服务器端 auto_register 避免需要重启
|
||||
# 由于实现问题,当前建议关闭此项,推荐开启签名服务器的自动注册实例
|
||||
auto-register: false
|
||||
# 是否在 token 过期后立即自动刷新签名 token(在需要签名时才会检测到,主要防止 token 意外丢失)
|
||||
# 独立于定时刷新
|
||||
auto-refresh-token: false
|
||||
# 定时刷新 token 间隔时间,单位为分钟, 建议 30~40 分钟, 不可超过 60 分钟
|
||||
# 目前丢失token也不会有太大影响,可设置为 0 以关闭,推荐开启
|
||||
refresh-interval: 40
|
||||
|
||||
heartbeat:
|
||||
# 心跳频率, 单位秒
|
||||
# -1 为关闭心跳
|
||||
@ -45,6 +96,8 @@ message:
|
||||
skip-mime-scan: false
|
||||
# 是否自动转换 WebP 图片
|
||||
convert-webp-image: false
|
||||
# download 超时时间(s)
|
||||
http-timeout: 15
|
||||
|
||||
output:
|
||||
# 日志等级 trace,debug,info,warn,error
|
||||
|
@ -32,6 +32,9 @@ func encode(record []byte, tempName string) (silkWav []byte, err error) {
|
||||
// 2.转换pcm
|
||||
pcmPath := path.Join(silkCachePath, tempName+".pcm")
|
||||
cmd := exec.Command("ffmpeg", "-i", rawPath, "-f", "s16le", "-ar", "24000", "-ac", "1", pcmPath)
|
||||
if errors.Is(cmd.Err, exec.ErrDot) {
|
||||
cmd.Err = nil
|
||||
}
|
||||
if base.Debug {
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
78
pkg/onebot/attr.go
Normal file
78
pkg/onebot/attr.go
Normal file
@ -0,0 +1,78 @@
|
||||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package onebot
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// An Attr is a key-value pair.
|
||||
type Attr struct {
|
||||
Key string
|
||||
Value Value
|
||||
}
|
||||
|
||||
// String returns an Attr for a string value.
|
||||
func String(key, value string) Attr {
|
||||
return Attr{key, StringValue(value)}
|
||||
}
|
||||
|
||||
// Int64 returns an Attr for an int64.
|
||||
func Int64(key string, value int64) Attr {
|
||||
return Attr{key, Int64Value(value)}
|
||||
}
|
||||
|
||||
// Int converts an int to an int64 and returns
|
||||
// an Attr with that value.
|
||||
func Int(key string, value int) Attr {
|
||||
return Int64(key, int64(value))
|
||||
}
|
||||
|
||||
// Uint64 returns an Attr for a uint64.
|
||||
func Uint64(key string, v uint64) Attr {
|
||||
return Attr{key, Uint64Value(v)}
|
||||
}
|
||||
|
||||
// Float64 returns an Attr for a floating-point number.
|
||||
func Float64(key string, v float64) Attr {
|
||||
return Attr{key, Float64Value(v)}
|
||||
}
|
||||
|
||||
// Bool returns an Attr for a bool.
|
||||
func Bool(key string, v bool) Attr {
|
||||
return Attr{key, BoolValue(v)}
|
||||
}
|
||||
|
||||
// Time returns an Attr for a time.Time.
|
||||
// It discards the monotonic portion.
|
||||
func Time(key string, v time.Time) Attr {
|
||||
return Attr{key, TimeValue(v)}
|
||||
}
|
||||
|
||||
// Duration returns an Attr for a time.Duration.
|
||||
func Duration(key string, v time.Duration) Attr {
|
||||
return Attr{key, DurationValue(v)}
|
||||
}
|
||||
|
||||
// Group returns an Attr for a Group Value.
|
||||
// The caller must not subsequently mutate the
|
||||
// argument slice.
|
||||
//
|
||||
// Use Group to collect several Attrs under a single
|
||||
// key on a log line, or as the result of LogValue
|
||||
// in order to log a single value as multiple Attrs.
|
||||
func Group(key string, as ...Attr) Attr {
|
||||
return Attr{key, GroupValue(as...)}
|
||||
}
|
||||
|
||||
// Any returns an Attr for the supplied value.
|
||||
// See [Value.AnyValue] for how values are treated.
|
||||
func Any(key string, value any) Attr {
|
||||
return Attr{key, AnyValue(value)}
|
||||
}
|
||||
|
||||
func (a Attr) String() string {
|
||||
return a.Key + "=" + a.Value.String()
|
||||
}
|
31
pkg/onebot/kind_string.go
Normal file
31
pkg/onebot/kind_string.go
Normal file
@ -0,0 +1,31 @@
|
||||
// Code generated by "stringer -type=Kind -trimprefix=Kind"; DO NOT EDIT.
|
||||
|
||||
package onebot
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[KindAny-0]
|
||||
_ = x[KindBool-1]
|
||||
_ = x[KindDuration-2]
|
||||
_ = x[KindFloat64-3]
|
||||
_ = x[KindInt64-4]
|
||||
_ = x[KindString-5]
|
||||
_ = x[KindTime-6]
|
||||
_ = x[KindUint64-7]
|
||||
_ = x[KindGroup-8]
|
||||
}
|
||||
|
||||
const _Kind_name = "AnyBoolDurationFloat64Int64StringTimeUint64Group"
|
||||
|
||||
var _Kind_index = [...]uint8{0, 3, 7, 15, 22, 27, 33, 37, 43, 48}
|
||||
|
||||
func (i Kind) String() string {
|
||||
if i < 0 || i >= Kind(len(_Kind_index)-1) {
|
||||
return "Kind(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _Kind_name[_Kind_index[i]:_Kind_index[i+1]]
|
||||
}
|
41
pkg/onebot/onebot.go
Normal file
41
pkg/onebot/onebot.go
Normal file
@ -0,0 +1,41 @@
|
||||
package onebot
|
||||
|
||||
// Self 机器人自身标识
|
||||
//
|
||||
// https://12.onebot.dev/connect/data-protocol/basic-types/#_10
|
||||
type Self struct {
|
||||
Platform string `json:"platform"`
|
||||
UserID string `json:"user_id"`
|
||||
}
|
||||
|
||||
// Request 动作请求是应用端为了主动向 OneBot 实现请求服务而发送的数据
|
||||
//
|
||||
// https://12.onebot.dev/connect/data-protocol/action-request/
|
||||
type Request struct {
|
||||
Action string // 动作名称
|
||||
Params any // 动作参数
|
||||
Echo any // 每次请求的唯一标识
|
||||
}
|
||||
|
||||
// Response 动作响应是 OneBot 实现收到应用端的动作请求并处理完毕后,发回应用端的数据
|
||||
//
|
||||
// https://12.onebot.dev/connect/data-protocol/action-response/
|
||||
type Response struct {
|
||||
Status string `json:"status"` // 执行状态,必须是 ok、failed 中的一个
|
||||
Code int64 `json:"retcode"` // 返回码
|
||||
Data any `json:"data"` // 响应数据
|
||||
Message string `json:"message"` // 错误信息
|
||||
Echo any `json:"echo"` // 动作请求中的 echo 字段值
|
||||
}
|
||||
|
||||
// Event 事件
|
||||
//
|
||||
// https://12.onebot.dev/connect/data-protocol/event/
|
||||
type Event struct {
|
||||
ID string
|
||||
Time int64
|
||||
Type string
|
||||
DetailType string
|
||||
SubType string
|
||||
Self *Self
|
||||
}
|
32
pkg/onebot/spec.go
Normal file
32
pkg/onebot/spec.go
Normal file
@ -0,0 +1,32 @@
|
||||
// Package onebot defines onebot protocol struct and some spec info.
|
||||
package onebot
|
||||
|
||||
import "fmt"
|
||||
|
||||
//go:generate go run ./../../cmd/api-generator -pkg onebot -path=./../../coolq/api.go,./../../coolq/api_v12.go -supported -o supported.go
|
||||
|
||||
// Spec OneBot Specification
|
||||
type Spec struct {
|
||||
Version int // must be 11 or 12
|
||||
SupportedActions []string
|
||||
}
|
||||
|
||||
// V11 OneBot V11
|
||||
var V11 = &Spec{
|
||||
Version: 11,
|
||||
SupportedActions: supportedV11,
|
||||
}
|
||||
|
||||
// V12 OneBot V12
|
||||
var V12 = &Spec{
|
||||
Version: 12,
|
||||
SupportedActions: supportedV12,
|
||||
}
|
||||
|
||||
// ConvertID 根据版本转换ID
|
||||
func (s *Spec) ConvertID(id any) any {
|
||||
if s.Version == 12 {
|
||||
return fmt.Sprint(id)
|
||||
}
|
||||
return id
|
||||
}
|
169
pkg/onebot/supported.go
Normal file
169
pkg/onebot/supported.go
Normal file
@ -0,0 +1,169 @@
|
||||
// Code generated by cmd/api-generator. DO NOT EDIT.
|
||||
|
||||
package onebot
|
||||
|
||||
var supportedV11 = []string{
|
||||
".get_word_slices",
|
||||
".handle_quick_operation",
|
||||
".ocr_image",
|
||||
"ocr_image",
|
||||
"_del_group_notice",
|
||||
"_get_group_notice",
|
||||
"_get_model_show",
|
||||
"_send_group_notice",
|
||||
"_set_model_show",
|
||||
"can_send_image",
|
||||
"can_send_record",
|
||||
"check_url_safely",
|
||||
"create_group_file_folder",
|
||||
"create_guild_role",
|
||||
"delete_essence_msg",
|
||||
"delete_friend",
|
||||
"delete_group_file",
|
||||
"delete_group_folder",
|
||||
"delete_guild_role",
|
||||
"delete_msg",
|
||||
"delete_unidirectional_friend",
|
||||
"download_file",
|
||||
"get_essence_msg_list",
|
||||
"get_forward_msg",
|
||||
"get_friend_list",
|
||||
"get_group_at_all_remain",
|
||||
"get_group_file_system_info",
|
||||
"get_group_file_url",
|
||||
"get_group_files_by_folder",
|
||||
"get_group_honor_info",
|
||||
"get_group_info",
|
||||
"get_group_list",
|
||||
"get_group_member_info",
|
||||
"get_group_member_list",
|
||||
"get_group_msg_history",
|
||||
"get_group_root_files",
|
||||
"get_group_system_msg",
|
||||
"get_guild_channel_list",
|
||||
"get_guild_list",
|
||||
"get_guild_member_list",
|
||||
"get_guild_member_profile",
|
||||
"get_guild_meta_by_guest",
|
||||
"get_guild_msg",
|
||||
"get_guild_roles",
|
||||
"get_guild_service_profile",
|
||||
"get_image",
|
||||
"get_login_info",
|
||||
"get_msg",
|
||||
"get_online_clients",
|
||||
"get_status",
|
||||
"get_stranger_info",
|
||||
"get_supported_actions",
|
||||
"get_topic_channel_feeds",
|
||||
"get_unidirectional_friend_list",
|
||||
"get_version_info",
|
||||
"mark_msg_as_read",
|
||||
"qidian_get_account_info",
|
||||
"reload_event_filter",
|
||||
"send_forward_msg",
|
||||
"send_group_forward_msg",
|
||||
"send_group_msg",
|
||||
"send_group_sign",
|
||||
"send_guild_channel_msg",
|
||||
"send_msg",
|
||||
"send_private_forward_msg",
|
||||
"send_private_msg",
|
||||
"set_essence_msg",
|
||||
"set_friend_add_request",
|
||||
"set_group_add_request",
|
||||
"set_group_admin",
|
||||
"set_group_anonymous",
|
||||
"set_group_anonymous_ban",
|
||||
"set_group_ban",
|
||||
"set_group_card",
|
||||
"set_group_kick",
|
||||
"set_group_leave",
|
||||
"set_group_name",
|
||||
"set_group_portrait",
|
||||
"set_group_special_title",
|
||||
"set_group_whole_ban",
|
||||
"set_guild_member_role",
|
||||
"set_qq_profile",
|
||||
"update_guild_role",
|
||||
"upload_group_file",
|
||||
"upload_private_file",
|
||||
}
|
||||
|
||||
var supportedV12 = []string{
|
||||
".get_word_slices",
|
||||
".ocr_image",
|
||||
"ocr_image",
|
||||
"_del_group_notice",
|
||||
"_get_group_notice",
|
||||
"_get_model_show",
|
||||
"_send_group_notice",
|
||||
"_set_model_show",
|
||||
"check_url_safely",
|
||||
"create_group_file_folder",
|
||||
"create_guild_role",
|
||||
"delete_essence_msg",
|
||||
"delete_friend",
|
||||
"delete_group_file",
|
||||
"delete_group_folder",
|
||||
"delete_guild_role",
|
||||
"delete_msg",
|
||||
"delete_unidirectional_friend",
|
||||
"download_file",
|
||||
"get_essence_msg_list",
|
||||
"get_forward_msg",
|
||||
"get_friend_list",
|
||||
"get_group_at_all_remain",
|
||||
"get_group_file_system_info",
|
||||
"get_group_file_url",
|
||||
"get_group_files_by_folder",
|
||||
"get_group_honor_info",
|
||||
"get_group_info",
|
||||
"get_group_list",
|
||||
"get_group_member_info",
|
||||
"get_group_member_list",
|
||||
"get_group_msg_history",
|
||||
"get_group_root_files",
|
||||
"get_group_system_msg",
|
||||
"get_guild_channel_list",
|
||||
"get_guild_list",
|
||||
"get_guild_member_list",
|
||||
"get_guild_member_profile",
|
||||
"get_guild_meta_by_guest",
|
||||
"get_guild_msg",
|
||||
"get_guild_roles",
|
||||
"get_guild_service_profile",
|
||||
"get_image",
|
||||
"get_self_info",
|
||||
"get_msg",
|
||||
"get_online_clients",
|
||||
"get_status",
|
||||
"get_user_info",
|
||||
"get_supported_actions",
|
||||
"get_topic_channel_feeds",
|
||||
"get_unidirectional_friend_list",
|
||||
"mark_msg_as_read",
|
||||
"qidian_get_account_info",
|
||||
"reload_event_filter",
|
||||
"send_group_sign",
|
||||
"send_guild_channel_msg",
|
||||
"set_essence_msg",
|
||||
"set_friend_add_request",
|
||||
"set_group_add_request",
|
||||
"set_group_admin",
|
||||
"set_group_anonymous",
|
||||
"set_group_anonymous_ban",
|
||||
"set_group_ban",
|
||||
"set_group_card",
|
||||
"set_group_kick",
|
||||
"set_group_leave",
|
||||
"set_group_name",
|
||||
"set_group_portrait",
|
||||
"set_group_special_title",
|
||||
"set_group_whole_ban",
|
||||
"set_guild_member_role",
|
||||
"set_qq_profile",
|
||||
"update_guild_role",
|
||||
"upload_group_file",
|
||||
"upload_private_file",
|
||||
}
|
355
pkg/onebot/value.go
Normal file
355
pkg/onebot/value.go
Normal file
@ -0,0 +1,355 @@
|
||||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package onebot
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// A Value can represent any Go value, but unlike type any,
|
||||
// it can represent most small values without an allocation.
|
||||
// The zero Value corresponds to nil.
|
||||
type Value struct {
|
||||
_ [0]func() // disallow ==
|
||||
num uint64 // hold number value
|
||||
any any // hold Kind or other value
|
||||
}
|
||||
|
||||
type (
|
||||
stringptr *byte // used in Value.any when the Value is a string
|
||||
groupptr *Attr // used in Value.any when the Value is a []Attr
|
||||
)
|
||||
|
||||
//go:generate stringer -type=Kind -trimprefix=Kind
|
||||
|
||||
// Kind is the kind of Value.
|
||||
type Kind int
|
||||
|
||||
// Kind
|
||||
const (
|
||||
KindAny Kind = iota
|
||||
KindBool
|
||||
KindDuration
|
||||
KindFloat64
|
||||
KindInt64
|
||||
KindString
|
||||
KindTime
|
||||
KindUint64
|
||||
KindGroup
|
||||
)
|
||||
|
||||
// Unexported version of Kind, just so we can store Kinds in Values.
|
||||
// (No user-provided value has this type.)
|
||||
type kind Kind
|
||||
|
||||
// Kind returns v's Kind.
|
||||
func (v Value) Kind() Kind {
|
||||
switch x := v.any.(type) {
|
||||
case Kind:
|
||||
return x
|
||||
case stringptr:
|
||||
return KindString
|
||||
case timeLocation:
|
||||
return KindTime
|
||||
case groupptr:
|
||||
return KindGroup
|
||||
case kind: // a kind is just a wrapper for a Kind
|
||||
return KindAny
|
||||
default:
|
||||
return KindAny
|
||||
}
|
||||
}
|
||||
|
||||
//////////////// Constructors
|
||||
|
||||
// StringValue returns a new Value for a string.
|
||||
func StringValue(value string) Value {
|
||||
return Value{num: uint64(len(value)), any: stringptr(unsafe.StringData(value))}
|
||||
}
|
||||
|
||||
// IntValue returns a Value for an int.
|
||||
func IntValue(v int) Value {
|
||||
return Int64Value(int64(v))
|
||||
}
|
||||
|
||||
// Int64Value returns a Value for an int64.
|
||||
func Int64Value(v int64) Value {
|
||||
return Value{num: uint64(v), any: KindInt64}
|
||||
}
|
||||
|
||||
// Uint64Value returns a Value for a uint64.
|
||||
func Uint64Value(v uint64) Value {
|
||||
return Value{num: v, any: KindUint64}
|
||||
}
|
||||
|
||||
// Float64Value returns a Value for a floating-point number.
|
||||
func Float64Value(v float64) Value {
|
||||
return Value{num: math.Float64bits(v), any: KindFloat64}
|
||||
}
|
||||
|
||||
// BoolValue returns a Value for a bool.
|
||||
func BoolValue(v bool) Value {
|
||||
u := uint64(0)
|
||||
if v {
|
||||
u = 1
|
||||
}
|
||||
return Value{num: u, any: KindBool}
|
||||
}
|
||||
|
||||
// Unexported version of *time.Location, just so we can store *time.Locations in
|
||||
// Values. (No user-provided value has this type.)
|
||||
type timeLocation *time.Location
|
||||
|
||||
// TimeValue returns a Value for a time.Time.
|
||||
// It discards the monotonic portion.
|
||||
func TimeValue(v time.Time) Value {
|
||||
if v.IsZero() {
|
||||
// UnixNano on the zero time is undefined, so represent the zero time
|
||||
// with a nil *time.Location instead. time.Time.Location method never
|
||||
// returns nil, so a Value with any == timeLocation(nil) cannot be
|
||||
// mistaken for any other Value, time.Time or otherwise.
|
||||
return Value{any: timeLocation(nil)}
|
||||
}
|
||||
return Value{num: uint64(v.UnixNano()), any: timeLocation(v.Location())}
|
||||
}
|
||||
|
||||
// DurationValue returns a Value for a time.Duration.
|
||||
func DurationValue(v time.Duration) Value {
|
||||
return Value{num: uint64(v.Nanoseconds()), any: KindDuration}
|
||||
}
|
||||
|
||||
// GroupValue returns a new Value for a list of Attrs.
|
||||
// The caller must not subsequently mutate the argument slice.
|
||||
func GroupValue(as ...Attr) Value {
|
||||
return Value{num: uint64(len(as)), any: groupptr(unsafe.SliceData(as))}
|
||||
}
|
||||
|
||||
// AnyValue returns a Value for the supplied value.
|
||||
//
|
||||
// If the supplied value is of type Value, it is returned
|
||||
// unmodified.
|
||||
//
|
||||
// Given a value of one of Go's predeclared string, bool, or
|
||||
// (non-complex) numeric types, AnyValue returns a Value of kind
|
||||
// String, Bool, Uint64, Int64, or Float64. The width of the
|
||||
// original numeric type is not preserved.
|
||||
//
|
||||
// Given a time.Time or time.Duration value, AnyValue returns a Value of kind
|
||||
// KindTime or KindDuration. The monotonic time is not preserved.
|
||||
//
|
||||
// For nil, or values of all other types, including named types whose
|
||||
// underlying type is numeric, AnyValue returns a value of kind KindAny.
|
||||
func AnyValue(v any) Value {
|
||||
switch v := v.(type) {
|
||||
case string:
|
||||
return StringValue(v)
|
||||
case int:
|
||||
return Int64Value(int64(v))
|
||||
case uint:
|
||||
return Uint64Value(uint64(v))
|
||||
case int64:
|
||||
return Int64Value(v)
|
||||
case uint64:
|
||||
return Uint64Value(v)
|
||||
case bool:
|
||||
return BoolValue(v)
|
||||
case time.Duration:
|
||||
return DurationValue(v)
|
||||
case time.Time:
|
||||
return TimeValue(v)
|
||||
case uint8:
|
||||
return Uint64Value(uint64(v))
|
||||
case uint16:
|
||||
return Uint64Value(uint64(v))
|
||||
case uint32:
|
||||
return Uint64Value(uint64(v))
|
||||
case uintptr:
|
||||
return Uint64Value(uint64(v))
|
||||
case int8:
|
||||
return Int64Value(int64(v))
|
||||
case int16:
|
||||
return Int64Value(int64(v))
|
||||
case int32:
|
||||
return Int64Value(int64(v))
|
||||
case float64:
|
||||
return Float64Value(v)
|
||||
case float32:
|
||||
return Float64Value(float64(v))
|
||||
case []Attr:
|
||||
return GroupValue(v...)
|
||||
case Kind:
|
||||
return Value{any: kind(v)}
|
||||
case Value:
|
||||
return v
|
||||
default:
|
||||
return Value{any: v}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////// Accessors
|
||||
|
||||
// Any returns v's value as an any.
|
||||
func (v Value) Any() any {
|
||||
switch v.Kind() {
|
||||
case KindAny:
|
||||
if k, ok := v.any.(kind); ok {
|
||||
return Kind(k)
|
||||
}
|
||||
return v.any
|
||||
case KindGroup:
|
||||
return v.group()
|
||||
case KindInt64:
|
||||
return int64(v.num)
|
||||
case KindUint64:
|
||||
return v.num
|
||||
case KindFloat64:
|
||||
return v.float()
|
||||
case KindString:
|
||||
return v.str()
|
||||
case KindBool:
|
||||
return v.bool()
|
||||
case KindDuration:
|
||||
return v.duration()
|
||||
case KindTime:
|
||||
return v.time()
|
||||
default:
|
||||
panic(fmt.Sprintf("bad kind: %s", v.Kind()))
|
||||
}
|
||||
}
|
||||
|
||||
// String returns Value's value as a string, formatted like fmt.Sprint. Unlike
|
||||
// the methods Int64, Float64, and so on, which panic if v is of the
|
||||
// wrong kind, String never panics.
|
||||
func (v Value) String() string {
|
||||
if sp, ok := v.any.(stringptr); ok {
|
||||
return unsafe.String(sp, v.num)
|
||||
}
|
||||
var buf []byte
|
||||
return string(v.append(buf))
|
||||
}
|
||||
|
||||
func (v Value) str() string {
|
||||
return unsafe.String(v.any.(stringptr), v.num)
|
||||
}
|
||||
|
||||
// Int64 returns v's value as an int64. It panics
|
||||
// if v is not a signed integer.
|
||||
func (v Value) Int64() int64 {
|
||||
if g, w := v.Kind(), KindInt64; g != w {
|
||||
panic(fmt.Sprintf("Value kind is %s, not %s", g, w))
|
||||
}
|
||||
return int64(v.num)
|
||||
}
|
||||
|
||||
// Uint64 returns v's value as a uint64. It panics
|
||||
// if v is not an unsigned integer.
|
||||
func (v Value) Uint64() uint64 {
|
||||
if g, w := v.Kind(), KindUint64; g != w {
|
||||
panic(fmt.Sprintf("Value kind is %s, not %s", g, w))
|
||||
}
|
||||
return v.num
|
||||
}
|
||||
|
||||
// Bool returns v's value as a bool. It panics
|
||||
// if v is not a bool.
|
||||
func (v Value) Bool() bool {
|
||||
if g, w := v.Kind(), KindBool; g != w {
|
||||
panic(fmt.Sprintf("Value kind is %s, not %s", g, w))
|
||||
}
|
||||
return v.bool()
|
||||
}
|
||||
|
||||
func (v Value) bool() bool {
|
||||
return v.num == 1
|
||||
}
|
||||
|
||||
// Duration returns v's value as a time.Duration. It panics
|
||||
// if v is not a time.Duration.
|
||||
func (v Value) Duration() time.Duration {
|
||||
if g, w := v.Kind(), KindDuration; g != w {
|
||||
panic(fmt.Sprintf("Value kind is %s, not %s", g, w))
|
||||
}
|
||||
|
||||
return v.duration()
|
||||
}
|
||||
|
||||
func (v Value) duration() time.Duration {
|
||||
return time.Duration(int64(v.num))
|
||||
}
|
||||
|
||||
// Float64 returns v's value as a float64. It panics
|
||||
// if v is not a float64.
|
||||
func (v Value) Float64() float64 {
|
||||
if g, w := v.Kind(), KindFloat64; g != w {
|
||||
panic(fmt.Sprintf("Value kind is %s, not %s", g, w))
|
||||
}
|
||||
|
||||
return v.float()
|
||||
}
|
||||
|
||||
func (v Value) float() float64 {
|
||||
return math.Float64frombits(v.num)
|
||||
}
|
||||
|
||||
// Time returns v's value as a time.Time. It panics
|
||||
// if v is not a time.Time.
|
||||
func (v Value) Time() time.Time {
|
||||
if g, w := v.Kind(), KindTime; g != w {
|
||||
panic(fmt.Sprintf("Value kind is %s, not %s", g, w))
|
||||
}
|
||||
return v.time()
|
||||
}
|
||||
|
||||
func (v Value) time() time.Time {
|
||||
loc := v.any.(timeLocation)
|
||||
if loc == nil {
|
||||
return time.Time{}
|
||||
}
|
||||
return time.Unix(0, int64(v.num)).In(loc)
|
||||
}
|
||||
|
||||
// Group returns v's value as a []Attr.
|
||||
// It panics if v's Kind is not KindGroup.
|
||||
func (v Value) Group() []Attr {
|
||||
if sp, ok := v.any.(groupptr); ok {
|
||||
return unsafe.Slice(sp, v.num)
|
||||
}
|
||||
panic("Group: bad kind")
|
||||
}
|
||||
|
||||
func (v Value) group() []Attr {
|
||||
return unsafe.Slice((*Attr)(v.any.(groupptr)), v.num)
|
||||
}
|
||||
|
||||
// append appends a text representation of v to dst.
|
||||
// v is formatted as with fmt.Sprint.
|
||||
func (v Value) append(dst []byte) []byte {
|
||||
switch v.Kind() {
|
||||
case KindString:
|
||||
return append(dst, v.str()...)
|
||||
case KindInt64:
|
||||
return strconv.AppendInt(dst, int64(v.num), 10)
|
||||
case KindUint64:
|
||||
return strconv.AppendUint(dst, v.num, 10)
|
||||
case KindFloat64:
|
||||
return strconv.AppendFloat(dst, v.float(), 'g', -1, 64)
|
||||
case KindBool:
|
||||
return strconv.AppendBool(dst, v.bool())
|
||||
case KindDuration:
|
||||
return append(dst, v.duration().String()...)
|
||||
case KindTime:
|
||||
return append(dst, v.time().String()...)
|
||||
case KindGroup:
|
||||
return fmt.Append(dst, v.group())
|
||||
case KindAny:
|
||||
return fmt.Append(dst, v.any)
|
||||
default:
|
||||
panic(fmt.Sprintf("bad kind: %s", v.Kind()))
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
#!/bin/sh
|
||||
echo "Start GOCQHTTP~~~"
|
||||
|
||||
cp -f config.yml /tmp/config.yml
|
||||
cp -f device.json /tmp/device.json
|
||||
./go-cqhttp -w="/tmp/" faststart
|
||||
#!/usr/bin/env bash
|
||||
function index.main_handler() {
|
||||
echo "Start GOCQHTTP~~~"
|
||||
cp -f config.yml /tmp/config.yml
|
||||
cp -f device.json /tmp/device.json
|
||||
./go-cqhttp -w="/tmp/" faststart
|
||||
}
|
||||
index.main_handler
|
||||
|
@ -29,6 +29,7 @@ import (
|
||||
"github.com/Mrs4s/go-cqhttp/modules/api"
|
||||
"github.com/Mrs4s/go-cqhttp/modules/config"
|
||||
"github.com/Mrs4s/go-cqhttp/modules/filter"
|
||||
"github.com/Mrs4s/go-cqhttp/pkg/onebot"
|
||||
)
|
||||
|
||||
// HTTPServer HTTP通信相关配置
|
||||
@ -58,7 +59,7 @@ type httpServerPost struct {
|
||||
type httpServer struct {
|
||||
api *api.Caller
|
||||
accessToken string
|
||||
version uint16
|
||||
spec *onebot.Spec // onebot spec
|
||||
}
|
||||
|
||||
// HTTPClient 反向HTTP上报客户端
|
||||
@ -158,7 +159,7 @@ func (s *httpServer) ServeHTTP(writer http.ResponseWriter, request *http.Request
|
||||
switch request.Method {
|
||||
case http.MethodPost:
|
||||
// todo: msg pack
|
||||
if s.version == 12 && strings.Contains(contentType, "application/msgpack") {
|
||||
if s.spec.Version == 12 && strings.Contains(contentType, "application/msgpack") {
|
||||
log.Warnf("请求 %v 数据类型暂不支持: MsgPack", request.RequestURI)
|
||||
writer.WriteHeader(http.StatusUnsupportedMediaType)
|
||||
return
|
||||
@ -204,12 +205,12 @@ func (s *httpServer) ServeHTTP(writer http.ResponseWriter, request *http.Request
|
||||
if request.URL.Path == "/" {
|
||||
action := strings.TrimSuffix(ctx.Get("action").Str, "_async")
|
||||
log.Debugf("HTTPServer接收到API调用: %v", action)
|
||||
response = s.api.Call(action, s.version, ctx.Get("params"))
|
||||
response = s.api.Call(action, s.spec, ctx.Get("params"))
|
||||
} else {
|
||||
action := strings.TrimPrefix(request.URL.Path, "/")
|
||||
action = strings.TrimSuffix(action, "_async")
|
||||
log.Debugf("HTTPServer接收到API调用: %v", action)
|
||||
response = s.api.Call(action, s.version, &ctx)
|
||||
response = s.api.Call(action, s.spec, &ctx)
|
||||
}
|
||||
|
||||
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
@ -259,11 +260,15 @@ func runHTTP(bot *coolq.CQBot, node yaml.Node) {
|
||||
case conf.Disabled:
|
||||
return
|
||||
}
|
||||
if conf.Version != 11 && conf.Version != 12 {
|
||||
conf.Version = 11
|
||||
}
|
||||
network, addr := "tcp", conf.Address
|
||||
s := &httpServer{accessToken: conf.AccessToken, version: conf.Version}
|
||||
s := &httpServer{accessToken: conf.AccessToken}
|
||||
switch conf.Version {
|
||||
default:
|
||||
// default v11
|
||||
s.spec = onebot.V11
|
||||
case 12:
|
||||
s.spec = onebot.V12
|
||||
}
|
||||
switch {
|
||||
case conf.Address != "":
|
||||
uri, err := url.Parse(conf.Address)
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/Mrs4s/go-cqhttp/coolq"
|
||||
"github.com/Mrs4s/go-cqhttp/global"
|
||||
"github.com/Mrs4s/go-cqhttp/modules/api"
|
||||
"github.com/Mrs4s/go-cqhttp/pkg/onebot"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
@ -26,7 +27,7 @@ type MiddleWares struct {
|
||||
|
||||
func rateLimit(frequency float64, bucketSize int) api.Handler {
|
||||
limiter := rate.NewLimiter(rate.Limit(frequency), bucketSize)
|
||||
return func(_ string, _ api.Getter) global.MSG {
|
||||
return func(_ string, _ *onebot.Spec, _ api.Getter) global.MSG {
|
||||
_ = limiter.Wait(context.Background())
|
||||
return nil
|
||||
}
|
||||
@ -45,8 +46,11 @@ func longPolling(bot *coolq.CQBot, maxSize int) api.Handler {
|
||||
}
|
||||
cond.Signal()
|
||||
})
|
||||
return func(action string, p api.Getter) global.MSG {
|
||||
if action != "get_updates" {
|
||||
return func(action string, spec *onebot.Spec, p api.Getter) global.MSG {
|
||||
switch {
|
||||
case spec.Version == 11 && action == "get_updates": // ok
|
||||
case spec.Version == 12 && action == "get_latest_events": // ok
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
var (
|
||||
|
@ -25,6 +25,7 @@ import (
|
||||
"github.com/Mrs4s/go-cqhttp/modules/api"
|
||||
"github.com/Mrs4s/go-cqhttp/modules/config"
|
||||
"github.com/Mrs4s/go-cqhttp/modules/filter"
|
||||
"github.com/Mrs4s/go-cqhttp/pkg/onebot"
|
||||
)
|
||||
|
||||
type webSocketServer struct {
|
||||
@ -476,7 +477,7 @@ func (c *wsConn) handleRequest(_ *coolq.CQBot, payload []byte) {
|
||||
t := strings.TrimSuffix(j.Get("action").Str, "_async")
|
||||
params := j.Get("params")
|
||||
log.Debugf("WS接收到API调用: %v 参数: %v", t, params.Raw)
|
||||
ret := c.apiCaller.Call(t, 11, params)
|
||||
ret := c.apiCaller.Call(t, onebot.V11, params)
|
||||
if j.Get("echo").Exists() {
|
||||
ret["echo"] = j.Get("echo").Value()
|
||||
}
|
||||
|
1
winres/.gitignore
vendored
Normal file
1
winres/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
winres.json
|
118
winres/gen/json.go
Normal file
118
winres/gen/json.go
Normal file
@ -0,0 +1,118 @@
|
||||
// Package main generates winres.json
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Mrs4s/go-cqhttp/internal/base"
|
||||
)
|
||||
|
||||
const js = `{
|
||||
"RT_GROUP_ICON": {
|
||||
"APP": {
|
||||
"0000": [
|
||||
"icon.png",
|
||||
"icon16.png"
|
||||
]
|
||||
}
|
||||
},
|
||||
"RT_MANIFEST": {
|
||||
"#1": {
|
||||
"0409": {
|
||||
"identity": {
|
||||
"name": "go-cqhttp",
|
||||
"version": "%s"
|
||||
},
|
||||
"description": "",
|
||||
"minimum-os": "vista",
|
||||
"execution-level": "as invoker",
|
||||
"ui-access": false,
|
||||
"auto-elevate": false,
|
||||
"dpi-awareness": "system",
|
||||
"disable-theming": false,
|
||||
"disable-window-filtering": false,
|
||||
"high-resolution-scrolling-aware": false,
|
||||
"ultra-high-resolution-scrolling-aware": false,
|
||||
"long-path-aware": false,
|
||||
"printer-driver-isolation": false,
|
||||
"gdi-scaling": false,
|
||||
"segment-heap": false,
|
||||
"use-common-controls-v6": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"RT_VERSION": {
|
||||
"#1": {
|
||||
"0000": {
|
||||
"fixed": {
|
||||
"file_version": "%s",
|
||||
"product_version": "%s",
|
||||
"timestamp": "%s"
|
||||
},
|
||||
"info": {
|
||||
"0409": {
|
||||
"Comments": "Golang implementation of cqhttp.",
|
||||
"CompanyName": "Mrs4s",
|
||||
"FileDescription": "https://github.com/Mrs4s/go-cqhttp",
|
||||
"FileVersion": "%s",
|
||||
"InternalName": "",
|
||||
"LegalCopyright": "©️ 2020 - %d Mrs4s. All Rights Reserved.",
|
||||
"LegalTrademarks": "",
|
||||
"OriginalFilename": "GOCQHTTP.EXE",
|
||||
"PrivateBuild": "",
|
||||
"ProductName": "go-cqhttp",
|
||||
"ProductVersion": "%s",
|
||||
"SpecialBuild": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
const timeformat = `2006-01-02T15:04:05+08:00`
|
||||
|
||||
func main() {
|
||||
f, err := os.Create("winres.json")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer f.Close()
|
||||
v := ""
|
||||
if base.Version == "(devel)" {
|
||||
vartag := bytes.NewBuffer(nil)
|
||||
vartagcmd := exec.Command("git", "tag", "--sort=committerdate")
|
||||
vartagcmd.Stdout = vartag
|
||||
err = vartagcmd.Run()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
s := strings.Split(vartag.String(), "\n")
|
||||
v = s[len(s)-2]
|
||||
} else {
|
||||
v = base.Version
|
||||
}
|
||||
i := strings.Index(v, "-") // remove -rc / -beta
|
||||
if i <= 0 {
|
||||
i = len(v)
|
||||
}
|
||||
commitcnt := strings.Builder{}
|
||||
commitcnt.WriteString(v[1:i])
|
||||
commitcnt.WriteByte('.')
|
||||
commitcntcmd := exec.Command("git", "rev-list", "--count", "master")
|
||||
commitcntcmd.Stdout = &commitcnt
|
||||
err = commitcntcmd.Run()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fv := commitcnt.String()[:commitcnt.Len()-1]
|
||||
_, err = fmt.Fprintf(f, js, fv, fv, v, time.Now().Format(timeformat), fv, time.Now().Year(), v)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
BIN
winres/icon.png
Normal file
BIN
winres/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 82 KiB |
BIN
winres/icon16.png
Normal file
BIN
winres/icon16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
4
winres/init.go
Normal file
4
winres/init.go
Normal file
@ -0,0 +1,4 @@
|
||||
// Package winres 生成windows资源
|
||||
package winres
|
||||
|
||||
//go:generate go run github.com/Mrs4s/go-cqhttp/winres/gen
|
Reference in New Issue
Block a user