Skip to content

Commit

Permalink
Merge pull request #4 from FloatTech/dev
Browse files Browse the repository at this point in the history
v1.0.0-rc2
  • Loading branch information
fumiama authored Jun 13, 2022
2 parents f39f68f + acdd864 commit c0b19e8
Show file tree
Hide file tree
Showing 57 changed files with 2,129 additions and 1,569 deletions.
24 changes: 6 additions & 18 deletions .github/ISSUE_TEMPLATE/bug-report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ body:
## 感谢您愿意填写错误回报!
## 以下是一些注意事项,请务必阅读让我们能够更容易处理
### ❗ | 确定没有相同问题的ISSUE已被提出. (教程: https://github.com/Mrs4s/go-cqhttp/issues/633)
### ❗ | 确定没有相同问题的ISSUE已被提出. (教程: https://forums.go-cqhttp.org/t/topic/141)
### 🌎| 请准确填写环境信息
### ❔ | 打开DEBUG模式复现,并提供出现问题前后至少 10 秒的完整日志内容。请自行删除日志内存在的个人信息及敏感内容。
### ⚠ | 如果涉及内存泄漏/CPU占用异常请打开DEBUG模式并下载pprof性能分析.
Expand All @@ -24,9 +24,11 @@ body:
attributes:
label: 请确保您已阅读以上注意事项,并勾选下方的确认框。
options:
- label: "我已经仔细阅读上述教程和 [\"提问前需知\"](https://github.com/Mrs4s/go-cqhttp/issues/633)"
- label: "我已经仔细阅读上述教程和 [\"提问前需知\"](https://forums.go-cqhttp.org/t/topic/141)"
required: true
- label: 我已知晓并同意,如果我不遵循以下格式提交 Issue,或者我使用的并非最新版本,或者我没有提供足够的环境信息,我的 Issue 可能会被无条件自动关闭或/并锁定。
- label: "我已经使用 [dev分支版本](https://github.com/Mrs4s/go-cqhttp/actions/workflows/ci.yml) 测试过,问题依旧存在。"
required: true
- label: "我已经在 [Issue Tracker](https://github.com/Mrs4s/go-cqhttp/issues) 中找过我要提出的问题,没有找到相同问题的ISSUE。"
required: true
- label: 我已知晓并同意,此处仅用于汇报程序中存在的问题。若这个 Issue 是关于其他非程序本身问题,则我的 Issue 可能会被无条件自动关闭或/并锁定。(这些问题应当在 Discussion 板块提出。)
required: true
Expand All @@ -39,24 +41,10 @@ body:
请根据实际使用环境修改以下信息。
# Env | go-cqhttp Version
- type: dropdown
- type: input
id: env-gocq-ver
attributes:
label: go-cqhttp 版本
description: 选择正在使用的版本 (未列出的版本为已不支持,请更新到最新版本。)
options:
- v1.0.0-beta8-fix1
- v1.0.0-beta8
- v1.0.0-beta7-fix2
- v1.0.0-beta7-fix1
- v1.0.0-beta7
- v1.0.0-beta6
- v1.0.0-beta5
- v1.0.0-beta4
- v1.0.0-beta3
- v1.0.0-beta2
- v1.0.0-beta1
- 更老的版本
validations:
required: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Setup Go environment
uses: actions/[email protected]
with:
go-version: 1.17
go-version: 1.18
- name: Cache downloaded module
uses: actions/cache@v2
with:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/golint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ jobs:
- name: Setup Go environment
uses: actions/[email protected]
with:
go-version: 1.17
go-version: 1.18

- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: latest

- name: Static Check
uses: dominikh/[email protected]
with:
install-go: false
version: "2022.1"

- name: Tests
run: |
go test $(go list ./...)
Expand Down
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.17'
go-version: '1.18'

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ session.token
device.json
data/
logs/
internal/btree/*.lock
internal/btree/*.db
33 changes: 13 additions & 20 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,28 @@ linters:
disable-all: true
fast: false
enable:
- bodyclose
- deadcode
- depguard
- dogsled
#- bodyclose
#- deadcode
#- depguard
#- dogsled
- gofmt
- goimports
- errcheck
- exportloopref
- exhaustive
- bidichk
#- funlen
#- goconst
- gocritic
#- gocyclo
- gofmt
- goimports
- goprintffuncname
#- gosec
- gosimple
#- gosimple
- govet
- ineffassign
#- misspell
- nolintlint
- rowserrcheck
- staticcheck
#- nolintlint
#- rowserrcheck
#- staticcheck
- structcheck
- stylecheck
- typecheck
#- stylecheck
- unconvert
- unparam
- unused
#- unparam
#- unused
- varcheck
- whitespace
- prealloc
Expand Down
3 changes: 3 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ env:
before:
hooks:
- go mod tidy
release:
draft: true
discussion_category_name: General
builds:
- id: nowin
env:
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.17-alpine AS builder
FROM golang:1.18-alpine AS builder

RUN go env -w GO111MODULE=auto \
&& go env -w CGO_ENABLED=0 \
Expand Down
1 change: 0 additions & 1 deletion cmd/gocq/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func PrintBanner() {
log.Info("当前版本:", base.Version)
if base.Debug {
log.SetLevel(log.DebugLevel)
log.SetReportCaller(true)
log.Warnf("已开启Debug模式.")
// log.Debugf("开发交流群: 192548878")
}
Expand Down
14 changes: 13 additions & 1 deletion cmd/gocq/base.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
package gocq

import (
"time"

"github.com/Mrs4s/go-cqhttp/global/terminal"
"github.com/Mrs4s/go-cqhttp/internal/base"
"github.com/Mrs4s/go-cqhttp/server"
log "github.com/sirupsen/logrus"
)

// InitBase 解析 flags 与配置文件到 base
func InitBase() {
base.Parse()
base.Init()
if !base.FastStart && terminal.RunningByDoubleClick() {
err := terminal.NoMoreDoubleClick()
if err != nil {
log.Errorf("遇到错误: %v", err)
time.Sleep(time.Second * 5)
}
return
}
switch {
case base.LittleH:
base.Help()
Expand All @@ -17,4 +28,5 @@ func InitBase() {
case base.LittleWD != "":
base.ResetWorkingDir()
}
base.Init()
}
23 changes: 0 additions & 23 deletions cmd/gocq/doubleclick.go

This file was deleted.

39 changes: 32 additions & 7 deletions cmd/gocq/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package gocq
import (
"bufio"
"bytes"
"image"
"image/png"
"os"
"strings"
"time"

qrcodeTerminal "github.com/Baozisoftware/qrcode-terminal-go"
"github.com/Mrs4s/MiraiGo/client"
"github.com/gocq/qrcode"
"github.com/mattn/go-colorable"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"

Expand Down Expand Up @@ -53,12 +54,36 @@ func commonLogin() error {
return loginResponseProcessor(res)
}

func qrcodeLogin() error {
rsp, err := cli.FetchQRCode()
func printQRCode(imgData []byte) {
const (
black = "\033[48;5;0m \033[0m"
white = "\033[48;5;7m \033[0m"
)
img, err := png.Decode(bytes.NewReader(imgData))
if err != nil {
return err
log.Panic(err)
}
data := img.(*image.Gray).Pix
bound := img.Bounds().Max.X
buf := make([]byte, 0, (bound*4+1)*(bound))
i := 0
for y := 0; y < bound; y++ {
i = y * bound
for x := 0; x < bound; x++ {
if data[i] != 255 {
buf = append(buf, white...)
} else {
buf = append(buf, black...)
}
i++
}
buf = append(buf, '\n')
}
fi, err := qrcode.Decode(bytes.NewReader(rsp.ImageData))
_, _ = colorable.NewColorableStdout().Write(buf)
}

func qrcodeLogin() error {
rsp, err := cli.FetchQRCodeCustomSize(1, 2, 1)
if err != nil {
return err
}
Expand All @@ -70,7 +95,7 @@ func qrcodeLogin() error {
log.Infof("请使用手机QQ扫描二维码 (qrcode.png) : ")
}
time.Sleep(time.Second)
qrcodeTerminal.New2(qrcodeTerminal.ConsoleColors.BrightBlack, qrcodeTerminal.ConsoleColors.BrightWhite, qrcodeTerminal.QRCodeRecoveryLevels.Low).Get(fi.Content).Print()
printQRCode(rsp.ImageData)
s, err := cli.QueryQRCodeStatus(rsp.Sig)
if err != nil {
return err
Expand Down
56 changes: 35 additions & 21 deletions cmd/gocq/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func Main() {
}
var times uint = 1 // 重试次数
var reLoginLock sync.Mutex
cli.OnDisconnected(func(q *client.QQClient, e *client.ClientDisconnectedEvent) {
cli.DisconnectedEvent.Subscribe(func(q *client.QQClient, e *client.ClientDisconnectedEvent) {
reLoginLock.Lock()
defer reLoginLock.Unlock()
times = 1
Expand Down Expand Up @@ -162,10 +162,9 @@ func Main() {
log.Info("资源初始化完成, 开始处理信息.")
log.Info("アトリは、高性能ですから!")

go selfupdate.CheckUpdate()
go func() {
time.Sleep(5 * time.Second)
go selfdiagnosis.NetworkDiagnosis(cli)
selfupdate.CheckUpdate()
selfdiagnosis.NetworkDiagnosis(cli)
}()

<-global.SetupMainSignalHandler()
Expand Down Expand Up @@ -204,6 +203,7 @@ func PasswordHashDecrypt(encryptedPasswordHash string, key []byte) ([]byte, erro

func newClient() *client.QQClient {
c := client.NewClientEmpty()
c.UseFragmentMessage = base.ForceFragmented
c.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) bool {
if !base.UseSSOAddress {
log.Infof("收到服务器地址更新通知, 根据配置文件已忽略.")
Expand All @@ -220,22 +220,36 @@ func newClient() *client.QQClient {
}
log.Infof("读取到 %v 个自定义地址.", len(addr))
}
c.OnLog(func(c *client.QQClient, e *client.LogEvent) {
switch e.Type {
case "INFO":
log.Info("Protocol -> " + e.Message)
case "ERROR":
log.Error("Protocol -> " + e.Message)
case "DEBUG":
log.Debug("Protocol -> " + e.Message)
case "DUMP":
if !global.PathExists(global.DumpsPath) {
_ = os.MkdirAll(global.DumpsPath, 0o755)
}
dumpFile := path.Join(global.DumpsPath, fmt.Sprintf("%v.dump", time.Now().Unix()))
log.Errorf("出现错误 %v. 详细信息已转储至文件 %v 请连同日志提交给开发者处理", e.Message, dumpFile)
_ = os.WriteFile(dumpFile, e.Dump, 0o644)
}
})
c.SetLogger(protocolLogger{})
return c
}

type protocolLogger struct{}

const fromProtocol = "Protocol -> "

func (p protocolLogger) Info(format string, arg ...any) {
log.Infof(fromProtocol+format, arg...)
}

func (p protocolLogger) Warning(format string, arg ...any) {
log.Warnf(fromProtocol+format, arg...)
}

func (p protocolLogger) Debug(format string, arg ...any) {
log.Debugf(fromProtocol+format, arg...)
}

func (p protocolLogger) Error(format string, arg ...any) {
log.Errorf(fromProtocol+format, arg...)
}

func (p protocolLogger) Dump(data []byte, format string, arg ...any) {
if !global.PathExists(global.DumpsPath) {
_ = os.MkdirAll(global.DumpsPath, 0o755)
}
dumpFile := path.Join(global.DumpsPath, fmt.Sprintf("%v.dump", time.Now().Unix()))
message := fmt.Sprintf(format, arg...)
log.Errorf("出现错误 %v. 详细信息已转储至文件 %v 请连同日志提交给开发者处理", message, dumpFile)
_ = os.WriteFile(dumpFile, data, 0o644)
}
Loading

0 comments on commit c0b19e8

Please sign in to comment.