Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update version #8

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Build And Push Docker Image

on:
workflow_dispatch:
push:
# Sequence of patterns matched against refs/tags
tags:
Expand All @@ -13,7 +14,7 @@ jobs:
packages: write
contents: read
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set time zone
uses: szenius/[email protected]
with:
Expand All @@ -29,15 +30,15 @@ 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 }}
password: ${{ secrets.GITHUB_TOKEN }}

- 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 }}
Expand All @@ -51,14 +52,19 @@ jobs:
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}

- name: Set up QEMU
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: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.19'
go-version: '1.20'

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19-alpine AS builder
FROM golang:1.20-alpine AS builder

RUN go env -w GO111MODULE=on \
&& go env -w CGO_ENABLED=0 \
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
_✨ 基于 [Mirai](https://github.com/mamoe/mirai) 以及 [MiraiGo](https://github.com/Mrs4s/MiraiGo) 的 [OneBot](https://github.com/howmanybots/onebot/blob/master/README.md) Golang 原生实现 ✨_

_✨ 同时融合了[ZeroBot-Plugin](https://github.com/FloatTech/ZeroBot-Plugin) ✨_

<img align="center" src="https://counter.seku.su/cmoe?name=gocqzbp" alt="gocqzbp-counter">

</div>

Expand All @@ -21,7 +23,7 @@ _✨ 同时融合了[ZeroBot-Plugin](https://github.com/FloatTech/ZeroBot-Plugin
## 命令行参数
除与[go-cqhttp](https://github.com/Mrs4s/go-cqhttp)一致的参数外,还可以附加任意个数的qq号作为主人`SuperUser`,并使用`-n`参数指定昵称,使用`-p`参数指定指令前缀。
```bash
./gocqzbp [-D] [-c config.yml] [-d] [-h] [-n nickname] [-p prefix] [-l latency] [-r ringlen] [-x max process time] [-w] [-faststart] [key xxxx] qq1 qq2 qq3 ...
./gocqzbp [-D] [-c config.yml] [-d] [-faststart] [-h] [-l latency] [-m] [-n nickname] [-p prefix] [-r ringlen] [-update-protocol] [-w wd] [-x max process time] [key xxxx] qq1 qq2 qq3 ...

Options:
-D debug mode
Expand All @@ -33,12 +35,15 @@ Options:
-h this Help
-l uint
Response latency (ms). (default 233)
-m Don't mark message as read automatically
-n string
Set default nickname. (default "椛椛")
-p string
Set command prefix. (default "/")
-r uint
Receiving buffer ring size. (default 4096)
-update-protocol
update protocol
-w string
cover the working directory
-x uint
Expand Down
194 changes: 106 additions & 88 deletions bot.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion funcall.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/FloatTech/zbputils/driver"
"github.com/Mrs4s/go-cqhttp/coolq"
"github.com/Mrs4s/go-cqhttp/modules/api"
"github.com/Mrs4s/go-cqhttp/pkg/onebot"
"github.com/tidwall/gjson"
)

Expand All @@ -29,7 +30,7 @@ func (e *Event) RawMSG() driver.MSG {
type Caller api.Caller

func (c *Caller) Call(action string, p string) driver.MSG {
return (*api.Caller)(c).Call(action, gjson.Parse(p))
return (*api.Caller)(c).Call(action, onebot.V11, gjson.Parse(p))
}

func newcaller(bot driver.CQBot) driver.Caller {
Expand Down
83 changes: 43 additions & 40 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
module github.com/FloatTech/gocqzbp

go 1.19
go 1.20

require (
github.com/FloatTech/ZeroBot-Plugin v1.6.1-beta2
github.com/FloatTech/floatbox v0.0.0-20221210051813-4bd44af40c60
github.com/FloatTech/zbputils v1.6.1-0.20221212090658-d0de5338e354
github.com/Mrs4s/go-cqhttp v1.0.0-rc3
github.com/sirupsen/logrus v1.9.0
github.com/tidwall/gjson v1.14.4
github.com/wdvxdr1123/ZeroBot v1.6.6
github.com/FloatTech/ZeroBot-Plugin v1.7.3
github.com/FloatTech/floatbox v0.0.0-20230827160415-f0865337a824
github.com/FloatTech/zbputils v1.6.2-0.20230728081122-94d4d957f3bf
github.com/Mrs4s/go-cqhttp v1.1.1-0.20230831110153-f16d72f0ca48
github.com/sirupsen/logrus v1.9.3
github.com/tidwall/gjson v1.15.0
github.com/wdvxdr1123/ZeroBot v1.7.4
)

require (
github.com/Baidu-AIP/golang-sdk v1.1.1 // indirect
github.com/Coloured-glaze/gg v1.3.4 // indirect
github.com/FloatTech/AnimeAPI v1.6.1-0.20221214084932-8c0223841d43 // indirect
github.com/FloatTech/rendercard v0.0.2-0.20221128165614-a41216d2422e // indirect
github.com/FloatTech/sqlite v1.5.7 // indirect
github.com/FloatTech/AnimeAPI v1.6.1-0.20230827161910-7e6a3d93a0ba // indirect
github.com/FloatTech/gg v1.1.3-0.20230226151425-6ea91286ba08 // indirect
github.com/FloatTech/imgfactory v0.2.2-0.20230413152719-e101cc3606ef // indirect
github.com/FloatTech/rendercard v0.0.10-0.20230223064326-45d29fa4ede9 // indirect
github.com/FloatTech/sqlite v1.6.3 // indirect
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b // indirect
github.com/FloatTech/zbpctrl v1.5.3-0.20221210051848-740ab7bd6ec3 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/Mrs4s/MiraiGo v0.0.0-20221202060717-4658474c60dd // indirect
github.com/RomiChan/protobuf v0.0.0-20220624030127-3310cba9dbc0 // indirect
github.com/FloatTech/zbpctrl v1.5.3-0.20230514154630-b74e6fcca380 // indirect
github.com/Microsoft/go-winio v0.6.2-0.20230724192519-b29bbd58a65a // indirect
github.com/Mrs4s/MiraiGo v0.0.0-20230823050531-a8213e127b2b // indirect
github.com/RomiChan/protobuf v0.1.1-0.20230204044148-2ed269a2e54d // indirect
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e // indirect
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5 // indirect
github.com/antchfx/htmlquery v1.2.5 // indirect
github.com/antchfx/xpath v1.2.1 // indirect
github.com/corona10/goimagehash v1.1.0 // indirect
github.com/davidscholberg/go-durationfmt v0.0.0-20170122144659-64843a2083d3 // indirect
github.com/disintegration/imaging v1.6.2 // indirect
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4 // indirect
github.com/faiface/beep v1.1.0 // indirect
github.com/fumiama/ahsai v0.1.0 // indirect
github.com/fumiama/cron v1.3.0 // indirect
github.com/fumiama/go-base16384 v1.6.1 // indirect
github.com/fumiama/go-base16384 v1.7.0 // indirect
github.com/fumiama/go-hide-param v0.1.4 // indirect
github.com/fumiama/go-registry v0.2.5-0.20221121111817-44b0846bdce6 // indirect
github.com/fumiama/go-registry v0.2.6 // indirect
github.com/fumiama/go-simple-protobuf v0.1.0 // indirect
github.com/fumiama/gofastTEA v0.0.10 // indirect
github.com/fumiama/gotracemoe v0.0.3 // indirect
Expand All @@ -44,7 +46,7 @@ require (
github.com/fumiama/unibase2n v0.0.0-20221020155353-02876e777430 // indirect
github.com/gabriel-vasile/mimetype v1.0.4 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
Expand All @@ -60,54 +62,55 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible // indirect
github.com/lestrrat-go/strftime v1.0.6 // indirect
github.com/lucas-clemente/quic-go v0.31.1 // indirect
github.com/lithammer/fuzzysearch v1.1.5 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/marten-seemann/qpack v0.3.0 // indirect
github.com/marten-seemann/qtls-go1-18 v0.1.3 // indirect
github.com/marten-seemann/qtls-go1-19 v0.1.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mroth/weightedrand v1.0.0 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/onsi/ginkgo/v2 v2.2.0 // indirect
github.com/onsi/ginkgo/v2 v2.9.5 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pierrec/lz4/v4 v4.1.15 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkumza/numcn v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-20 v0.3.3 // indirect
github.com/quic-go/quic-go v0.38.1 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/segmentio/asm v1.2.0 // indirect
github.com/shirou/gopsutil/v3 v3.22.11 // indirect
github.com/shirou/gopsutil/v3 v3.23.1 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/wcharczuk/go-chart/v2 v2.1.0 // indirect
github.com/wdvxdr1123/go-silk v0.0.0-20220304095002-f67345df09ea // indirect
github.com/wdvxdr1123/go-silk v0.0.0-20210316130616-d47b553def60 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
gitlab.com/gomidi/midi/v2 v2.0.25 // indirect
golang.org/x/crypto v0.3.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect
golang.org/x/exp/shiny v0.0.0-20221126150942-6ab00d035af9 // indirect
golang.org/x/image v0.1.0 // indirect
golang.org/x/image v0.9.0 // indirect
golang.org/x/mobile v0.0.0-20201217150744-e6ae53a27f4f // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/term v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.2.0 // indirect
golang.org/x/tools v0.1.12 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.11.0 // indirect
gopkg.ilharper.com/x/isatty v1.1.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/libc v1.21.5 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.4.0 // indirect
modernc.org/sqlite v1.20.0 // indirect
)

replace github.com/Mrs4s/go-cqhttp => github.com/FloatTech/gocq v0.0.0-20221214085446-e283eb0b4d06

replace modernc.org/sqlite => github.com/fumiama/sqlite3 v1.20.0-with-win386

replace github.com/remyoudompheng/bigfft => github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b
91 changes: 8 additions & 83 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,93 +1,18 @@
package main

import (
"os"
"os/exec"
"time"

"github.com/sirupsen/logrus"

"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编码模块
)

var (
nofork = len(os.Args) > 1 && func() bool {
for i := len(os.Args) - 1; i >= 0; i-- {
if os.Args[i] == "nofork" {
if i == len(os.Args)-1 {
os.Args = os.Args[:i]
} else {
os.Args = append(os.Args[:i], os.Args[i+1:]...)
}
return true
}
}
return false
}()
norecover = len(os.Args) > 1 && func() bool {
for i := len(os.Args) - 1; i >= 0; i-- {
if os.Args[i] == "norecover" {
if i == len(os.Args)-1 {
os.Args = os.Args[:i]
} else {
os.Args = append(os.Args[:i], os.Args[i+1:]...)
}
return true
}
}
return false
}()
)

func main() {
gocq.InitLog()

switch {
case !nofork:
os.Args = append(os.Args, "nofork")
logrus.Infoln("主进程已启动, pid:", os.Getpid())
c := 16
for c > 0 {
err := runChild()
logrus.Errorln("子进程退出, 重启中:", err)
time.Sleep(time.Second)
if _, err = os.Stat(os.Args[0]); err != nil && (os.Args[0][0] == '.' || os.Args[0][0] == '/' || os.Args[0][1] == ':') {
logrus.Errorln("可执行文件被删除, 将使用自身进程作恢复处理, 如再崩溃则无法二次恢复")
break
}
c--
}
logrus.Errorln("到达重启次数上限, 将使用自身进程作恢复处理, 如再崩溃则无法二次恢复")
case !norecover:
defer func() {
logrus.Errorln("子进程退出:", recover())
os.Exit(1)
}()
}

logrus.Infoln("子进程已启动, pid:", os.Getpid())
gocq.InitCache()
gocq.InitDB()
gocq.PrintBanner()
gocq.LoadDevice()
gocq.CheckKey(gocq.ParseCommand())
gocq.Main()
}

func runChild() error {
cmd := exec.Command(os.Args[0], os.Args[1:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Start()
if err != nil {
cmd = exec.Command("./"+os.Args[0], os.Args[1:]...)
err = cmd.Start()
}
if err != nil {
panic(err)
}
return cmd.Wait()
gocq.PrepareData()
gocq.LoginInteract()
_ = terminal.DisableQuickEdit()
_ = terminal.EnableVT100()
gocq.WaitSignal()
_ = terminal.RestoreInputMode()
}