Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrs4s committed Feb 9, 2022
2 parents f8fa906 + 4b3ae1c commit 54dbccf
Show file tree
Hide file tree
Showing 35 changed files with 1,151 additions and 745 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ on: [push, pull_request,workflow_dispatch]
env:
BINARY_PREFIX: "go-cqhttp_"
BINARY_SUFFIX: ""
COMMIT_ID: "${{ github.sha }}"
PR_PROMPT: "::warning:: Build artifact will not be uploaded due to the workflow is trigged by pull request."
LD_FLAGS: "-w -s"

jobs:
build:
Expand Down Expand Up @@ -46,6 +46,7 @@ jobs:
if $IS_PR ; then echo $PR_PROMPT; fi
export BINARY_NAME="$BINARY_PREFIX$GOOS_$GOARCH$BINARY_SUFFIX"
export CGO_ENABLED=0
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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/golint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ jobs:
if: ${{ github.event.pull_request }}
uses: reviewdog/action-suggester@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tool_name: golangci-lint
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ linters:
- errcheck
- exportloopref
- exhaustive
- bidichk
#- funlen
#- goconst
- gocritic
Expand Down
37 changes: 21 additions & 16 deletions cmd/api-generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ type Param struct {
}

type Router struct {
Func string
Path string
Aliases []string
Params []Param
Func string
Path []string
Params []Param
}

type generator struct {
Expand Down Expand Up @@ -53,9 +52,12 @@ func (g *generator) generate(routers []Router) {
}

func (g *generator) router(router Router) {
g.WriteString(`case ` + strconv.Quote(router.Path))
for _, alias := range router.Aliases {
g.WriteString(`, ` + strconv.Quote(alias))
g.WriteString(`case `)
for i, p := range router.Path {
if i != 0 {
g.WriteString(`, `)
}
g.WriteString(strconv.Quote(p))
}
g.WriteString(":\n")

Expand Down Expand Up @@ -92,10 +94,12 @@ func conv(v, t string) string {
return v + ".Bool()"
case "string":
return v + ".String()"
case "int32", "uint32", "int":
case "int32", "int":
return t + "(" + v + ".Int())"
case "uint64":
return v + ".Uint()"
case "uint32":
return "uint32(" + v + ".Uint())"
}
}

Expand All @@ -112,7 +116,7 @@ func main() {
for _, decl := range file.Decls {
switch decl := decl.(type) {
case *ast.FuncDecl:
if decl.Recv == nil {
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" {
Expand All @@ -137,12 +141,10 @@ func main() {
for _, comment := range decl.Doc.List {
annotation, args := match(comment.Text)
switch annotation {
case "":
continue
case "route":
router.Path = args
case "alias":
router.Aliases = append(router.Aliases, args)
for _, route := range strings.Split(args, ",") {
router.Path = append(router.Path, unquote(route))
}
case "default":
for name, value := range parseMap(args, "=") {
for i, p := range router.Params {
Expand All @@ -160,8 +162,11 @@ func main() {
}
}
}
sort.Slice(router.Path, func(i, j int) bool {
return router.Path[i] < router.Path[j]
})
}
if router.Path != "" {
if router.Path != nil {
routers = append(routers, router)
} else {
println(decl.Name.Name)
Expand All @@ -170,7 +175,7 @@ func main() {
}

sort.Slice(routers, func(i, j int) bool {
return routers[i].Path < routers[j].Path
return routers[i].Path[0] < routers[j].Path[0]
})

out := new(bytes.Buffer)
Expand Down
33 changes: 12 additions & 21 deletions cmd/gocq/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/md5"
"crypto/sha1"
"encoding/hex"
"fmt"
"os"
"path"
"sync"
Expand Down Expand Up @@ -114,8 +115,6 @@ func Main() {
byteKey = []byte(arg[p])
para.Hide(p)
}
case "faststart":
base.FastStart = true
}
}
}
Expand All @@ -133,9 +132,8 @@ func Main() {
log.SetLevel(log.DebugLevel)
log.SetReportCaller(true)
log.Warnf("已开启Debug模式.")
log.Debugf("开发交流群: 192548878")
// log.Debugf("开发交流群: 192548878")
}
log.Info("用户交流群: 721829413")
if !global.PathExists("device.json") {
log.Warn("虚拟设备信息不存在, 将自动生成随机设备.")
client.GenRandomDevice()
Expand Down Expand Up @@ -205,21 +203,7 @@ func Main() {
time.Sleep(time.Second * 5)
}
log.Info("开始尝试登录并同步消息...")
log.Infof("使用协议: %v", func() string {
switch client.SystemDeviceInfo.Protocol {
case client.IPad:
return "iPad"
case client.AndroidPhone:
return "Android Phone"
case client.AndroidWatch:
return "Android Watch"
case client.MacOS:
return "MacOS"
case client.QiDian:
return "企点"
}
return "未知"
}())
log.Infof("使用协议: %s", client.SystemDeviceInfo.Protocol)
cli = newClient()
isQRCodeLogin := (base.Account.Uin == 0 || len(base.Account.Password) == 0) && !base.Account.Encrypt
isTokenLogin := false
Expand Down Expand Up @@ -279,7 +263,7 @@ func Main() {
reLoginLock.Lock()
defer reLoginLock.Unlock()
times = 1
if cli.Online {
if cli.Online.Load() {
return
}
log.Warnf("Bot已离线: %v", e.Message)
Expand All @@ -299,7 +283,7 @@ func Main() {
} else {
time.Sleep(time.Second)
}
if cli.Online {
if cli.Online.Load() {
log.Infof("登录已完成")
break
}
Expand Down Expand Up @@ -407,6 +391,13 @@ func newClient() *client.QQClient {
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)
}
})
return c
Expand Down
Loading

0 comments on commit 54dbccf

Please sign in to comment.