From 4c9f60da09b14fa8636887a945138b6fb3654554 Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Sun, 11 Oct 2020 10:39:33 +0800 Subject: [PATCH 01/17] update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 478327d..8a1febb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.14.7-alpine AS builder +FROM golang:1.15.2-alpine AS builder RUN go env -w GO111MODULE=auto \ && go env -w CGO_ENABLED=0 \ From cb9d872071620cd5881053ce8d8073d736a3b15a Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Sun, 15 Nov 2020 16:17:43 +0800 Subject: [PATCH 02/17] Fix ineffectual assignment. --- Dockerfile | 2 +- coolq/api.go | 3 +-- coolq/cqcode.go | 4 ++-- go.mod | 6 +++++- go.sum | 10 ++++++++++ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8a1febb..938abb2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.15.2-alpine AS builder +FROM golang:1.15.5-alpine AS builder RUN go env -w GO111MODULE=auto \ && go env -w CGO_ENABLED=0 \ diff --git a/coolq/api.go b/coolq/api.go index ffb9f82..f175050 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -516,12 +516,11 @@ func (bot *CQBot) CQSetGroupAdmin(groupId, userId int64, enable bool) MSG { } func (bot *CQBot) CQGetVipInfo(userId int64) MSG { - msg := MSG{} vip, err := bot.Client.GetVipInfo(userId) if err != nil { return Failed(100) } - msg = MSG{ + msg := MSG{ "user_id": vip.Uin, "nickname": vip.Name, "level": vip.Level, diff --git a/coolq/cqcode.go b/coolq/cqcode.go index b78b9c8..b3ffe85 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -104,7 +104,7 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M } for _, elem := range e { m := MSG{} - switch o := elem.(type) { + swiadd tch o := elem.(type) { case *message.TextElement: m = MSG{ "type": "text", @@ -195,7 +195,7 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M } } default: - continue + return } r = append(r, m) } diff --git a/go.mod b/go.mod index f5e3726..6f2fbe4 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,16 @@ module github.com/Mrs4s/go-cqhttp go 1.14 require ( - github.com/Mrs4s/MiraiGo v0.0.0-20201114110437-3d349df7362e + github.com/Mrs4s/MiraiGo v0.0.0-20201114160242-6b9dd7feaa20 github.com/dustin/go-humanize v1.0.0 + github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/getlantern/go-update v0.0.0-20190510022740-79c495ab728c github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9 // indirect github.com/gin-gonic/gin v1.6.3 github.com/gorilla/websocket v1.4.2 github.com/guonaihong/gout v0.1.3 + github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect + github.com/jonboulle/clockwork v0.2.2 // indirect github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect github.com/kr/binarydist v0.1.0 // indirect github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible @@ -19,6 +22,7 @@ require ( github.com/sirupsen/logrus v1.7.0 github.com/syndtr/goleveldb v1.0.0 github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 + github.com/tebeka/strftime v0.1.5 // indirect github.com/tidwall/gjson v1.6.3 github.com/wdvxdr1123/go-silk v0.0.0-20201007123416-b982fd3d91d6 github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189 diff --git a/go.sum b/go.sum index c984143..f240eb0 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ github.com/Mrs4s/MiraiGo v0.0.0-20201114105600-231b2d89dbb9 h1:evnR9D9rXcBTUzioF github.com/Mrs4s/MiraiGo v0.0.0-20201114105600-231b2d89dbb9/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs= github.com/Mrs4s/MiraiGo v0.0.0-20201114110437-3d349df7362e h1:cE3YcEtd9LWqtR4nyxciRg/qLaJ6jW9eO8I6ZW7oNDw= github.com/Mrs4s/MiraiGo v0.0.0-20201114110437-3d349df7362e/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs= +github.com/Mrs4s/MiraiGo v0.0.0-20201114160242-6b9dd7feaa20 h1:/9ewpT69zkqTuHvWiFKPZ7LiDflpbSuaFiUKloVBxYQ= +github.com/Mrs4s/MiraiGo v0.0.0-20201114160242-6b9dd7feaa20/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -14,6 +16,8 @@ github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4 github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 h1:Ghm4eQYC0nEPnSJdVkTrXpu9KtoVCSo1hg7mtI7G9KU= +github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239/go.mod h1:Gdwt2ce0yfBxPvZrHkprdPPTTS3N5rwmLE8T22KBXlw= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 h1:NRUJuo3v3WGC/g5YiyF790gut6oQr5f3FBI88Wv0dx4= github.com/getlantern/context v0.0.0-20190109183933-c447772a6520/go.mod h1:L+mq6/vvYHKjCX2oez0CgEAJmbq1fbb/oNJIWQkBybY= @@ -72,6 +76,10 @@ github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/guonaihong/gout v0.1.3 h1:BIiV6nnsA+R6dIB1P33uhCM8+TVAG3zHrXGZad7hDc8= github.com/guonaihong/gout v0.1.3/go.mod h1:vXvv5Kxr70eM5wrp4F0+t9lnLWmq+YPW2GByll2f/EA= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4= +github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag= +github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ= +github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA= @@ -118,6 +126,8 @@ github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFd github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 h1:J6v8awz+me+xeb/cUTotKgceAYouhIB3pjzgRd6IlGk= github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816/go.mod h1:tzym/CEb5jnFI+Q0k4Qq3+LvRF4gO3E2pxS8fHP8jcA= +github.com/tebeka/strftime v0.1.5 h1:1NQKN1NiQgkqd/2moD6ySP/5CoZQsKa1d3ZhJ44Jpmg= +github.com/tebeka/strftime v0.1.5/go.mod h1:29/OidkoWHdEKZqzyDLUyC+LmgDgdHo4WAFCDT7D/Ig= github.com/tidwall/gjson v1.6.1/go.mod h1:BaHyNc5bjzYkPqgLq7mdVzeiRtULKULXLgZFKsxEHI0= github.com/tidwall/gjson v1.6.3 h1:aHoiiem0dr7GHkW001T1SMTJ7X5PvyekH5WX0whWGnI= github.com/tidwall/gjson v1.6.3/go.mod h1:BaHyNc5bjzYkPqgLq7mdVzeiRtULKULXLgZFKsxEHI0= From 79ba9474a3947470c5a35147c039e1adf8605209 Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Sun, 15 Nov 2020 16:19:57 +0800 Subject: [PATCH 03/17] update --- coolq/cqcode.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index b3ffe85..658ee05 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -104,7 +104,7 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M } for _, elem := range e { m := MSG{} - swiadd tch o := elem.(type) { + switch o := elem.(type) { case *message.TextElement: m = MSG{ "type": "text", From 0f0f74ece893fefa5389cf09393201c77994a8e7 Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Mon, 16 Nov 2020 22:34:05 +0800 Subject: [PATCH 04/17] feather: use startup params to decrypt password --- main.go | 75 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 15 deletions(-) diff --git a/main.go b/main.go index 926f65b..fb2d1c3 100644 --- a/main.go +++ b/main.go @@ -2,17 +2,16 @@ package main import ( "bufio" + "context" "crypto/md5" "encoding/base64" "encoding/json" "fmt" - "github.com/Mrs4s/go-cqhttp/server" - "github.com/guonaihong/gout" - "github.com/tidwall/gjson" "io" "io/ioutil" "net/http" "os" + "os/exec" "os/signal" "path" "runtime" @@ -20,15 +19,19 @@ import ( "strings" "time" + "github.com/Mrs4s/go-cqhttp/server" + "github.com/guonaihong/gout" + "github.com/tidwall/gjson" + "github.com/Mrs4s/MiraiGo/binary" "github.com/Mrs4s/MiraiGo/client" "github.com/Mrs4s/go-cqhttp/coolq" "github.com/Mrs4s/go-cqhttp/global" "github.com/getlantern/go-update" - "github.com/lestrrat-go/file-rotatelogs" + rotatelogs "github.com/lestrrat-go/file-rotatelogs" "github.com/rifflock/lfshook" log "github.com/sirupsen/logrus" - "github.com/t-tomalak/logrus-easy-formatter" + easy "github.com/t-tomalak/logrus-easy-formatter" ) func init() { @@ -93,13 +96,26 @@ func init() { func main() { console := bufio.NewReader(os.Stdin) - + var strKey string arg := os.Args - if len(arg) > 1 && arg[1] == "update" { - if len(arg) > 2 { - selfUpdate(arg[2]) - } else { - selfUpdate("") + fmt.Println(arg) + if len(arg) > 1 { + for i := range arg { + switch arg[i] { + case "update": + if len(arg) > i+1 { + selfUpdate(arg[i+2]) + } else { + selfUpdate("") + } + case "key": + if len(arg) > i+1 { + b := []byte(arg[i+1]) + b = append(b, 13, 10) + strKey = string(b[:]) + fmt.Println(b) + } + } } } @@ -216,8 +232,24 @@ func main() { } } if conf.PasswordEncrypted != "" { - log.Infof("密码加密已启用, 请输入Key对密码进行解密以继续: (Enter 提交)") - strKey, _ := console.ReadString('\n') + if strKey == "" { + log.Infof("密码加密已启用, 请输入Key对密码进行解密以继续: (Enter 提交)") + ctx := context.Background() + go func(ctx context.Context) { + select { + case <-ctx.Done(): + return + case <-time.After(time.Second * 45): + log.Infof("解密key输入超时") + time.Sleep(3 * time.Second) + os.Exit(0) + } + }(ctx) + strKey, _ = console.ReadString('\n') + ctx.Done() + } else { + log.Infof("密码加密已启用, 使用运行时传递的参数进行解密,按 Ctrl+C 取消.") + } key := md5.Sum([]byte(strKey)) conf.Password = DecryptPwd(conf.PasswordEncrypted, key[:]) } @@ -284,10 +316,23 @@ func main() { } b := server.WebServer.Run(fmt.Sprintf("%s:%d", conf.WebUi.Host, conf.WebUi.WebUiPort), cli) c := server.Console + r := server.Restart go checkUpdate() signal.Notify(c, os.Interrupt, os.Kill) - <-c - b.Release() + select { + case <-c: + b.Release() + case <-r: + b.Release() + cmd := &exec.Cmd{ + Path: arg[0], + Args: arg[1:], + Stderr: os.Stderr, + Stdout: os.Stdout, + } + server.HttpServer.ShutDown() + cmd.Start() + } } func EncryptPwd(pwd string, key []byte) string { From 4a3288cb8d4b03fa22eb591c6279c8174237685c Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Mon, 16 Nov 2020 22:36:47 +0800 Subject: [PATCH 05/17] feather: add set_restart api support --- coolq/bot.go | 3 ++- coolq/cqcode.go | 11 ++++++----- coolq/event.go | 11 ++++++----- global/codec.go | 5 +++-- global/filter.go | 5 +++-- global/fs.go | 5 +++-- global/net.go | 3 ++- global/param.go | 3 ++- global/ratelimit.go | 1 + server/apiAdmin.go | 44 +++++++++++++++++++++++++++----------------- server/http.go | 24 +++++++++++++++++++++++- server/websocket.go | 15 +++++++++++++++ 12 files changed, 93 insertions(+), 37 deletions(-) diff --git a/coolq/bot.go b/coolq/bot.go index 1262b07..6ea59f6 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -5,12 +5,13 @@ import ( "encoding/gob" "encoding/json" "fmt" - "github.com/syndtr/goleveldb/leveldb" "hash/crc32" "path" "sync" "time" + "github.com/syndtr/goleveldb/leveldb" + "github.com/Mrs4s/MiraiGo/binary" "github.com/Mrs4s/MiraiGo/client" "github.com/Mrs4s/MiraiGo/message" diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 658ee05..3f864bb 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -8,11 +8,6 @@ import ( xml2 "encoding/xml" "errors" "fmt" - "github.com/Mrs4s/MiraiGo/binary" - "github.com/Mrs4s/MiraiGo/message" - "github.com/Mrs4s/go-cqhttp/global" - log "github.com/sirupsen/logrus" - "github.com/tidwall/gjson" "io/ioutil" "net/url" "path" @@ -20,6 +15,12 @@ import ( "runtime" "strconv" "strings" + + "github.com/Mrs4s/MiraiGo/binary" + "github.com/Mrs4s/MiraiGo/message" + "github.com/Mrs4s/go-cqhttp/global" + log "github.com/sirupsen/logrus" + "github.com/tidwall/gjson" ) var matchReg = regexp.MustCompile(`\[CQ:\w+?.*?]`) diff --git a/coolq/event.go b/coolq/event.go index 9d2e300..bbfa09f 100644 --- a/coolq/event.go +++ b/coolq/event.go @@ -2,16 +2,17 @@ package coolq import ( "encoding/hex" - "github.com/Mrs4s/MiraiGo/binary" - "github.com/Mrs4s/MiraiGo/client" - "github.com/Mrs4s/MiraiGo/message" - "github.com/Mrs4s/go-cqhttp/global" - log "github.com/sirupsen/logrus" "io/ioutil" "path" "strconv" "strings" "time" + + "github.com/Mrs4s/MiraiGo/binary" + "github.com/Mrs4s/MiraiGo/client" + "github.com/Mrs4s/MiraiGo/message" + "github.com/Mrs4s/go-cqhttp/global" + log "github.com/sirupsen/logrus" ) var format = "string" diff --git a/global/codec.go b/global/codec.go index b519b68..bc9b9e0 100644 --- a/global/codec.go +++ b/global/codec.go @@ -4,11 +4,12 @@ import ( "crypto/md5" "errors" "fmt" - log "github.com/sirupsen/logrus" - "github.com/wdvxdr1123/go-silk/silk" "io/ioutil" "path" "sync" + + log "github.com/sirupsen/logrus" + "github.com/wdvxdr1123/go-silk/silk" ) var codec silk.Encoder diff --git a/global/filter.go b/global/filter.go index b2ac4cb..f47f62e 100644 --- a/global/filter.go +++ b/global/filter.go @@ -1,11 +1,12 @@ package global import ( - log "github.com/sirupsen/logrus" - "github.com/tidwall/gjson" "io/ioutil" "regexp" "strings" + + log "github.com/sirupsen/logrus" + "github.com/tidwall/gjson" ) type Filter interface { diff --git a/global/fs.go b/global/fs.go index d8bccaf..10dc7a2 100644 --- a/global/fs.go +++ b/global/fs.go @@ -7,8 +7,6 @@ import ( "encoding/hex" "errors" "fmt" - "github.com/dustin/go-humanize" - log "github.com/sirupsen/logrus" "io/ioutil" "net" "net/url" @@ -17,6 +15,9 @@ import ( "runtime" "strconv" "strings" + + "github.com/dustin/go-humanize" + log "github.com/sirupsen/logrus" ) var ( diff --git a/global/net.go b/global/net.go index d30d796..1495fb1 100644 --- a/global/net.go +++ b/global/net.go @@ -4,11 +4,12 @@ import ( "bytes" "compress/gzip" "fmt" - "github.com/tidwall/gjson" "io/ioutil" "net/http" "strings" "time" + + "github.com/tidwall/gjson" ) var client = &http.Client{ diff --git a/global/param.go b/global/param.go index 5f01bea..7acd5eb 100644 --- a/global/param.go +++ b/global/param.go @@ -1,11 +1,12 @@ package global import ( - "github.com/tidwall/gjson" "math" "regexp" "strconv" "strings" + + "github.com/tidwall/gjson" ) var trueSet = map[string]struct{}{ diff --git a/global/ratelimit.go b/global/ratelimit.go index 79594be..b8bfb2a 100644 --- a/global/ratelimit.go +++ b/global/ratelimit.go @@ -2,6 +2,7 @@ package global import ( "context" + "golang.org/x/time/rate" ) diff --git a/server/apiAdmin.go b/server/apiAdmin.go index 3454273..6c14120 100644 --- a/server/apiAdmin.go +++ b/server/apiAdmin.go @@ -6,13 +6,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "github.com/Mrs4s/MiraiGo/client" - "github.com/Mrs4s/go-cqhttp/coolq" - "github.com/Mrs4s/go-cqhttp/global" - "github.com/gin-gonic/gin" - log "github.com/sirupsen/logrus" - "github.com/tidwall/gjson" - "github.com/yinghau76/go-ascii-art" "image" "io/ioutil" "net/http" @@ -21,12 +14,22 @@ import ( "strconv" "strings" "time" + + "github.com/Mrs4s/MiraiGo/client" + "github.com/Mrs4s/go-cqhttp/coolq" + "github.com/Mrs4s/go-cqhttp/global" + "github.com/gin-gonic/gin" + log "github.com/sirupsen/logrus" + "github.com/tidwall/gjson" + asciiart "github.com/yinghau76/go-ascii-art" ) var WebInput = make(chan string, 1) //长度1,用于阻塞 var Console = make(chan os.Signal, 1) +var Restart = make(chan struct{}, 1) + var JsonConfig *global.JsonConfig type webServer struct { @@ -41,16 +44,17 @@ var WebServer = &webServer{} // admin 子站的 路由映射 var HttpuriAdmin = map[string]func(s *webServer, c *gin.Context){ - "do_restart": AdminDoRestart, //热重启 - "get_web_write": AdminWebWrite, //获取是否验证码输入 - "do_web_write": AdminDoWebWrite, //web上进行输入操作 - "do_restart_docker": AdminDoRestartDocker, //直接停止(依赖supervisord/docker)重新拉起 - "do_config_base": AdminDoConfigBase, //修改config.json中的基础部分 - "do_config_http": AdminDoConfigHttp, //修改config.json的http部分 - "do_config_ws": AdminDoConfigWs, //修改config.json的正向ws部分 - "do_config_reverse": AdminDoConfigReverse, //修改config.json 中的反向ws部分 - "do_config_json": AdminDoConfigJson, //直接修改 config.json配置 - "get_config_json": AdminGetConfigJson, //拉取 当前的config.json配置 + "do_restart": AdminDoRestart, //热重启 + "do_process_restart": AdminProcessRestart, //进程重启 + "get_web_write": AdminWebWrite, //获取是否验证码输入 + "do_web_write": AdminDoWebWrite, //web上进行输入操作 + "do_restart_docker": AdminDoRestartDocker, //直接停止(依赖supervisord/docker)重新拉起 + "do_config_base": AdminDoConfigBase, //修改config.json中的基础部分 + "do_config_http": AdminDoConfigHttp, //修改config.json的http部分 + "do_config_ws": AdminDoConfigWs, //修改config.json的正向ws部分 + "do_config_reverse": AdminDoConfigReverse, //修改config.json 中的反向ws部分 + "do_config_json": AdminDoConfigJson, //直接修改 config.json配置 + "get_config_json": AdminGetConfigJson, //拉取 当前的config.json配置 } func Failed(code int, msg string) coolq.MSG { @@ -423,6 +427,12 @@ func AdminDoRestart(s *webServer, c *gin.Context) { return } +// 进程重启 +func AdminProcessRestart(s *webServer, c *gin.Context) { + Restart <- struct{}{} + c.JSON(200, coolq.OK(coolq.MSG{})) +} + // 冷重启 func AdminDoRestartDocker(s *webServer, c *gin.Context) { Console <- os.Kill diff --git a/server/http.go b/server/http.go index 8c12e43..5b58c7e 100644 --- a/server/http.go +++ b/server/http.go @@ -5,12 +5,14 @@ import ( "crypto/hmac" "crypto/sha1" "encoding/hex" - "github.com/guonaihong/gout/dataflow" "net/http" "os" "strconv" "strings" "time" + "unsafe" + + "github.com/guonaihong/gout/dataflow" "github.com/Mrs4s/go-cqhttp/coolq" "github.com/Mrs4s/go-cqhttp/global" @@ -343,6 +345,25 @@ func SetGroupLeave(s *httpServer, c *gin.Context) { c.JSON(200, s.bot.CQSetGroupLeave(gid)) } +func SetRestart(s *httpServer, c *gin.Context) { + d, t := getParamWithType(c, "delay") + if t == gjson.Null { + d = "0" + } + delay, err := strconv.ParseInt(d, 10, 64) + if err != nil || delay < 0 { + c.JSON(200, Failed(100, "Invalid delay")) + return + } + c.JSON(200, coolq.MSG{"data": nil, "retcode": 0, "status": "async"}) + go func(delay int64) { + var del *time.Duration = (*time.Duration)(unsafe.Pointer(&delay)) + time.Sleep(*del * time.Millisecond) + Restart <- struct{}{} + }(delay * time.Hour.Milliseconds()) + +} + func GetForwardMessage(s *httpServer, c *gin.Context) { resId := getParam(c, "message_id") c.JSON(200, s.bot.CQGetForwardMessage(resId)) @@ -488,6 +509,7 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){ "set_group_whole_ban": SetWholeBan, "set_group_name": SetGroupName, "set_group_admin": SetGroupAdmin, + "set_restart": SetRestart, "_send_group_notice": SendGroupNotice, "set_group_leave": SetGroupLeave, "get_image": GetImage, diff --git a/server/websocket.go b/server/websocket.go index 668ea00..b01fd21 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -8,6 +8,7 @@ import ( "strings" "sync" "time" + "unsafe" "github.com/Mrs4s/go-cqhttp/coolq" "github.com/Mrs4s/go-cqhttp/global" @@ -480,6 +481,20 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{ "get_group_honor_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { return bot.CQGetGroupHonorInfo(p.Get("group_id").Int(), p.Get("type").Str) }, + "set_restart": func(c *coolq.CQBot, p gjson.Result) coolq.MSG { + var delay int64 = 0 + delay = p.Get("delay").Int() + if delay < 0 { + return Failed(100, "Invalid delay") + } + defer func(delay int64) { + var del *time.Duration = (*time.Duration)(unsafe.Pointer(&delay)) + time.Sleep(*del * time.Millisecond) + Restart <- struct{}{} + }(delay * time.Hour.Milliseconds()) + return coolq.MSG{"data": nil, "retcode": 0, "status": "async"} + + }, "can_send_image": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG { return bot.CQCanSendImage() }, From 8900839018bda10668912c37e03f0eb998e16d75 Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Mon, 16 Nov 2020 23:51:45 +0800 Subject: [PATCH 06/17] Improved restart method --- main.go | 52 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index fb2d1c3..18f31cd 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ import ( "os/exec" "os/signal" "path" + "path/filepath" "runtime" "strconv" "strings" @@ -97,6 +98,7 @@ func init() { func main() { console := bufio.NewReader(os.Stdin) var strKey string + var isRestart bool = false arg := os.Args fmt.Println(arg) if len(arg) > 1 { @@ -113,8 +115,9 @@ func main() { b := []byte(arg[i+1]) b = append(b, 13, 10) strKey = string(b[:]) - fmt.Println(b) } + case "restart": + isRestart = true } } } @@ -253,8 +256,10 @@ func main() { key := md5.Sum([]byte(strKey)) conf.Password = DecryptPwd(conf.PasswordEncrypted, key[:]) } - log.Info("Bot将在5秒后登录并开始信息处理, 按 Ctrl+C 取消.") - time.Sleep(time.Second * 5) + if !isRestart { + log.Info("Bot将在5秒后登录并开始信息处理, 按 Ctrl+C 取消.") + time.Sleep(time.Second * 5) + } log.Info("开始尝试登录并同步消息...") log.Infof("使用协议: %v", func() string { switch client.SystemDeviceInfo.Protocol { @@ -323,15 +328,10 @@ func main() { case <-c: b.Release() case <-r: - b.Release() - cmd := &exec.Cmd{ - Path: arg[0], - Args: arg[1:], - Stderr: os.Stderr, - Stdout: os.Stdout, - } + log.Info("正在重启中...") server.HttpServer.ShutDown() - cmd.Start() + defer b.Release() + restart(arg) } } @@ -451,3 +451,33 @@ func selfUpdate(imageUrl string) { readLine() os.Exit(0) } + +func restart(Args []string) { + cmd := &exec.Cmd{} + if runtime.GOOS == "windows" { + file, err := exec.LookPath(Args[0]) + if err != nil { + log.Errorf("重启失败:%s", err.Error()) + return + } + path, err := filepath.Abs(file) + if err != nil { + log.Errorf("重启失败:%s", err.Error()) + } + Args = append([]string{"/c", "start ", path, "restart"}, Args[1:]...) + cmd = &exec.Cmd{ + Path: "cmd.exe", + Args: Args, + Stderr: os.Stderr, + Stdout: os.Stdout, + } + } else { + cmd = &exec.Cmd{ + Path: Args[0], + Args: Args, + Stderr: os.Stderr, + Stdout: os.Stdout, + } + } + cmd.Start() +} From 990e7744a397b766debf75a7706b5b8ff87e6ee7 Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Tue, 17 Nov 2020 00:13:14 +0800 Subject: [PATCH 07/17] Update docs --- README.md | 83 ++++----- docs/EventFilter.md | 20 +-- docs/adminApi.md | 104 +++++------ docs/config.md | 58 +++--- docs/cqhttp.md | 422 ++++++++++++++++++++++---------------------- docs/quick_start.md | 2 +- 6 files changed, 345 insertions(+), 344 deletions(-) diff --git a/README.md b/README.md index d6b5f59..a2a9b24 100644 --- a/README.md +++ b/README.md @@ -46,33 +46,34 @@ 已实现API ##### 注意: 部分API实现与CQHTTP原版略有差异,请参考文档 -| API | 功能 | -| ------------------------ | ------------------------------------------------------------ | -| /get_login_info | [获取登录号信息](https://cqhttp.cc/docs/4.15/#/API?id=get_login_info-获取登录号信息) | -| /get_friend_list | [获取好友列表](https://cqhttp.cc/docs/4.15/#/API?id=get_friend_list-获取好友列表) | -| /get_group_list | [获取群列表](https://cqhttp.cc/docs/4.15/#/API?id=get_group_list-获取群列表) | -| /get_group_info | [获取群信息](https://cqhttp.cc/docs/4.15/#/API?id=get_group_info-获取群信息) | -| /get_group_member_list | [获取群成员列表](https://cqhttp.cc/docs/4.15/#/API?id=get_group_member_list-获取群成员列表) | -| /get_group_member_info | [获取群成员信息](https://cqhttp.cc/docs/4.15/#/API?id=get_group_member_info-获取群成员信息) | -| /send_msg | [发送消息](https://cqhttp.cc/docs/4.15/#/API?id=send_msg-发送消息) | -| /send_group_msg | [发送群消息](https://cqhttp.cc/docs/4.15/#/API?id=send_group_msg-发送群消息) | -| /send_private_msg | [发送私聊消息](https://cqhttp.cc/docs/4.15/#/API?id=send_private_msg-发送私聊消息) | -| /delete_msg | [撤回信息](https://cqhttp.cc/docs/4.15/#/API?id=delete_msg-撤回消息) | -| /set_friend_add_request | [处理加好友请求](https://cqhttp.cc/docs/4.15/#/API?id=set_friend_add_request-处理加好友请求) | -| /set_group_add_request | [处理加群请求/邀请](https://cqhttp.cc/docs/4.15/#/API?id=set_group_add_request-处理加群请求/邀请) | -| /set_group_card | [设置群名片(群备注)](https://cqhttp.cc/docs/4.15/#/API?id=set_group_card-设置群名片(群备注)) | -| /set_group_special_title | [设置群组专属头衔](https://cqhttp.cc/docs/4.15/#/API?id=set_group_special_title-设置群组专属头衔) | -| /set_group_kick | [群组T人](https://cqhttp.cc/docs/4.15/#/API?id=set_group_kick-群组踢人) | -| /set_group_ban | [群组单人禁言](https://cqhttp.cc/docs/4.15/#/API?id=set_group_ban-群组单人禁言) | -| /set_group_whole_ban | [群组全员禁言](https://cqhttp.cc/docs/4.15/#/API?id=set_group_whole_ban-群组全员禁言) | -| /set_group_leave | [退出群组](https://cqhttp.cc/docs/4.15/#/API?id=set_group_leave-退出群组) | -| /set_group_name | 设置群组名(拓展API) | -| /get_image | 获取图片信息(拓展API) | -| /get_msg | [获取消息]() | -| /can_send_image | [检查是否可以发送图片](https://cqhttp.cc/docs/4.15/#/API?id=can_send_image-检查是否可以发送图片) | -| /can_send_record | [检查是否可以发送语音](https://cqhttp.cc/docs/4.15/#/API?id=can_send_record-检查是否可以发送语音) | -| /get_status | [获取插件运行状态](https://cqhttp.cc/docs/4.15/#/API?id=get_status-获取插件运行状态) | -| /get_version_info | [获取 酷Q 及 CQHTTP插件的版本信息](https://cqhttp.cc/docs/4.15/#/API?id=get_version_info-获取-酷q-及-cqhttp-插件的版本信息) | +| API | 功能 | +| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| /get_login_info | [获取登录号信息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_login_info-%E8%8E%B7%E5%8F%96%E7%99%BB%E5%BD%95%E5%8F%B7%E4%BF%A1%E6%81%AF) | +| /get_friend_list | [获取好友列表](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_friend_list-%E8%8E%B7%E5%8F%96%E5%A5%BD%E5%8F%8B%E5%88%97%E8%A1%A8) | +| /get_group_list | [获取群列表](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_list-%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%88%97%E8%A1%A8) | +| /get_group_info | [获取群信息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E4%BF%A1%E6%81%AF) | +| /get_group_member_list | [获取群成员列表](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_member_list-%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%88%90%E5%91%98%E5%88%97%E8%A1%A8) | +| /get_group_member_info | [获取群成员信息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_group_member_info-%E8%8E%B7%E5%8F%96%E7%BE%A4%E6%88%90%E5%91%98%E4%BF%A1%E6%81%AF) | +| /send_msg | [发送消息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#send_msg-%E5%8F%91%E9%80%81%E6%B6%88%E6%81%AF) | +| /send_group_msg | [发送群消息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#send_group_msg-%E5%8F%91%E9%80%81%E7%BE%A4%E6%B6%88%E6%81%AF) | +| /send_private_msg | [发送私聊消息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#send_private_msg-%E5%8F%91%E9%80%81%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF) | +| /delete_msg | [撤回信息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#delete_msg-%E6%92%A4%E5%9B%9E%E6%B6%88%E6%81%AF) | +| /set_friend_add_request | [处理加好友请求](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_friend_add_request-%E5%A4%84%E7%90%86%E5%8A%A0%E5%A5%BD%E5%8F%8B%E8%AF%B7%E6%B1%82) | +| /set_group_add_request | [处理加群请求/邀请](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_add_request-%E5%A4%84%E7%90%86%E5%8A%A0%E7%BE%A4%E8%AF%B7%E6%B1%82%E9%82%80%E8%AF%B7) | +| /set_group_card | [设置群名片(群备注)](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_card-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%90%8D%E7%89%87%E7%BE%A4%E5%A4%87%E6%B3%A8) | +| /set_group_special_title | [设置群组专属头衔](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_special_title-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E7%BB%84%E4%B8%93%E5%B1%9E%E5%A4%B4%E8%A1%94) | +| /set_group_kick | [群组T人](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_kick-%E7%BE%A4%E7%BB%84%E8%B8%A2%E4%BA%BA) | +| /set_group_ban | [群组单人禁言](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_ban-%E7%BE%A4%E7%BB%84%E5%8D%95%E4%BA%BA%E7%A6%81%E8%A8%80) | +| /set_group_whole_ban | [群组全员禁言](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_whole_ban-%E7%BE%A4%E7%BB%84%E5%85%A8%E5%91%98%E7%A6%81%E8%A8%80) | +| /set_group_leave | [退出群组](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_leave-%E9%80%80%E5%87%BA%E7%BE%A4%E7%BB%84) | +| /set_group_name | [设置群组名](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_group_name-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%90%8D) | +| /set_restart | [重启go-cqhttp](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#set_restart-%E9%87%8D%E5%90%AF-onebot-%E5%AE%9E%E7%8E%B0) | +| /get_image | [获取图片信息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_image-%E8%8E%B7%E5%8F%96%E5%9B%BE%E7%89%87) | +| /get_msg | [获取消息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_msg-%E8%8E%B7%E5%8F%96%E6%B6%88%E6%81%AF) | +| /can_send_image | [检查是否可以发送图片](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#can_send_image-%E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E5%8F%91%E9%80%81%E5%9B%BE%E7%89%87) | +| /can_send_record | [检查是否可以发送语音](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#can_send_record-%E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E5%8F%91%E9%80%81%E8%AF%AD%E9%9F%B3) | +| /get_status | [获取插件运行状态](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_status-%E8%8E%B7%E5%8F%96%E8%BF%90%E8%A1%8C%E7%8A%B6%E6%80%81) | +| /get_version_info | [获取 酷Q 及 CQHTTP插件的版本信息](https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_version_info-%E8%8E%B7%E5%8F%96%E7%89%88%E6%9C%AC%E4%BF%A1%E6%81%AF) | @@ -80,20 +81,20 @@ 已实现Event ##### 注意: 部分Event数据与CQHTTP原版略有差异,请参考文档 -| Event | -| ------------------------------------------------------------ | -| [私聊信息](https://cqhttp.cc/docs/4.15/#/Post?id=私聊消息) | -| [群消息](https://cqhttp.cc/docs/4.15/#/Post?id=群消息) | -| [群消息撤回(拓展Event)](docs/cqhttp.md#群消息撤回) | -| [好友消息撤回(拓展Event)](docs/cqhttp.md#好友消息撤回) | -| [群内提示事件(拓展Event)(龙王等事件)](docs/cqhttp.md#群内戳一戳) | -| [群管理员变动](https://cqhttp.cc/docs/4.15/#/Post?id=群管理员变动) | -| [群成员减少](https://cqhttp.cc/docs/4.15/#/Post?id=群成员减少) | -| [群成员增加](https://cqhttp.cc/docs/4.15/#/Post?id=群成员增加) | -| [群禁言](https://cqhttp.cc/docs/4.15/#/Post?id=群禁言) | -| [群文件上传](https://cqhttp.cc/docs/4.15/#/Post?id=群文件上传) | -| [加好友请求](https://cqhttp.cc/docs/4.15/#/Post?id=加好友请求) | -| [加群请求/邀请](https://cqhttp.cc/docs/4.15/#/Post?id=加群请求/邀请) | +| Event | +| ---------------------------------------------------------------------------------------------------------------------------------------------------- | +| [私聊信息](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/message.md#%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF) | +| [群消息](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/message.md#%E7%BE%A4%E6%B6%88%E6%81%AF) | +| [群消息撤回(拓展Event)](docs/cqhttp.md#群消息撤回) | +| [好友消息撤回(拓展Event)](docs/cqhttp.md#好友消息撤回) | +| [群内提示事件(拓展Event)(龙王等事件)](docs/cqhttp.md#群内戳一戳) | +| [群管理员变动](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E7%AE%A1%E7%90%86%E5%91%98%E5%8F%98%E5%8A%A8) | +| [群成员减少](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E6%88%90%E5%91%98%E5%87%8F%E5%B0%91) | +| [群成员增加](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E6%88%90%E5%91%98%E5%A2%9E%E5%8A%A0) | +| [群禁言](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E7%A6%81%E8%A8%80) | +| [群文件上传](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/notice.md#%E7%BE%A4%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0) | +| [加好友请求](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/request.md#%E5%8A%A0%E5%A5%BD%E5%8F%8B%E8%AF%B7%E6%B1%82) | +| [加群请求/邀请](https://github.com/howmanybots/onebot/blob/master/v11/specs/event/request.md#%E5%8A%A0%E7%BE%A4%E8%AF%B7%E6%B1%82%E9%82%80%E8%AF%B7) | diff --git a/docs/EventFilter.md b/docs/EventFilter.md index c9ccf05..2eb5f38 100644 --- a/docs/EventFilter.md +++ b/docs/EventFilter.md @@ -110,16 +110,16 @@ 下面列出所有运算符(「要求的参数类型」是指运算符的键所对应的值的类型,「可作用于的类型」是指在过滤时事件对象相应值的类型): -| 运算符 | 要求的参数类型 | 可作用于的类型 | -| ----- | ------------ | ----------- | -| `.not` | object | 任何 | -| `.and` | object | 若参数中全为运算符,则任何;若不全为运算符,则 object | -| `.or` | array(数组元素为 object) | 任何 | -| `.eq` | 任何 | 任何 | -| `.neq` | 任何 | 任何 | -| `.in` | string/array | 若参数为 string,则 string;若参数为 array,则任何 | -| `.contains` | string | string | -| `.regex` | string | string | +| 运算符 | 要求的参数类型 | 可作用于的类型 | +| ----------- | -------------------------- | ----------------------------------------------------- | +| `.not` | object | 任何 | +| `.and` | object | 若参数中全为运算符,则任何;若不全为运算符,则 object | +| `.or` | array(数组元素为 object) | 任何 | +| `.eq` | 任何 | 任何 | +| `.neq` | 任何 | 任何 | +| `.in` | string/array | 若参数为 string,则 string;若参数为 array,则任何 | +| `.contains` | string | string | +| `.regex` | string | string | ## 过滤时的事件数据对象 diff --git a/docs/adminApi.md b/docs/adminApi.md index def91f8..c82e9fe 100644 --- a/docs/adminApi.md +++ b/docs/adminApi.md @@ -6,9 +6,9 @@ 参数: -| 参数名 | 类型 | 说明 | -| ------ | ------ | ----------- | -| access_token | string | 校验口令,config.json中配置 | +| 参数名 | 类型 | 说明 | +| ------------ | ------ | --------------------------- | +| access_token | string | 校验口令,config.json中配置 | @@ -24,9 +24,9 @@ method:`POST/GET` 参数: -| 参数名 | 类型 | 说明 | -| ------ | ---- | ------------------------------------- | -| 无||| +| 参数名 | 类型 | 说明 | +| ------ | ---- | ---- | +| 无 | | | 返回: @@ -44,19 +44,19 @@ method: `GET` 参数: -| 参数名 | 类型 | 说明 | -| ------ | ------ | ----------- | -| 无||| +| 参数名 | 类型 | 说明 | +| ------ | ---- | ---- | +| 无 | | | 返回: ```json {"data": {"ispic": true,"picbase64":"xxxxx"}, "retcode": 0, "status": "ok"} ``` -| 参数名 | 类型 | 说明 | -| ------ | ------ | ----------- | -| ispic| bool| 是否是验证码类型 true是,false为不是(比如设备锁| -|picbas64| string| 验证码的base64编码内容,加上头,放入img标签即可显示| +| 参数名 | 类型 | 说明 | +| -------- | ------ | --------------------------------------------------- | +| ispic | bool | 是否是验证码类型 true是,false为不是(比如设备锁 | +| picbas64 | string | 验证码的base64编码内容,加上头,放入img标签即可显示 | ### admin/do_web_write @@ -67,9 +67,9 @@ method: `POST` formdata 参数: -| 参数名 | 类型 | 说明 | -| ------ | ------ | ----------- | -| input | string | 输入的内容 | +| 参数名 | 类型 | 说明 | +| ------ | ------ | ---------- | +| input | string | 输入的内容 | 返回: @@ -89,9 +89,9 @@ method: `POST` 参数: -| 参数名 |类型 | 说明 | -| ------ | ------ | -----------| -| 无 | | | +| 参数名 | 类型 | 说明 | +| ------ | ---- | ---- | +| 无 | | | 返回: @@ -108,12 +108,12 @@ method: `POST` formdata 参数: -| 参数名 | 类型 | 说明 | -| ------ | ------ | ------------------------------------------------------------ | -| uin | string | qq号 | -| password | string | qq密码 | -| enable_db | string | 是否启动数据库,填 'true' 或者 'false' | -| access_token | string | 授权 token | +| 参数名 | 类型 | 说明 | +| ------------ | ------ | ------------------------------------- | +| uin | string | qq号 | +| password | string | qq密码 | +| enable_db | string | 是否启动数据库,填 'true' 或者 'false' | +| access_token | string | 授权 token | 返回: @@ -130,14 +130,14 @@ method: `POST` formdata 参数: -| 参数名 | 类型 | 说明 | -| ------ | ------ | ------------------------------------------------------------ | -| port | string | 服务端口 | -| host | string | 服务监听地址 | -| enable | string | 是否启用 ,填 'true' 或者 'false' | -| timeout | string | http请求超时时间 | -| post_url | string | post上报地址 不需要就填空字符串,或者不填| -| post_secret | string | post上报的secret 不需要就填空字符串,或者不填 | +| 参数名 | 类型 | 说明 | +| ----------- | ------ | --------------------------------------------- | +| port | string | 服务端口 | +| host | string | 服务监听地址 | +| enable | string | 是否启用 ,填 'true' 或者 'false' | +| timeout | string | http请求超时时间 | +| post_url | string | post上报地址 不需要就填空字符串,或者不填 | +| post_secret | string | post上报的secret 不需要就填空字符串,或者不填 | 返回: @@ -154,11 +154,11 @@ method: `POST` formdata 参数: -| 参数名 | 类型 | 说明 | -| ------ | ------ | ------------------------------------------------------------ | -| port | string | 服务端口 | -| host | string | 服务监听地址 | -| enable | string | 是否启用 ,填 'true' 或者 'false' | +| 参数名 | 类型 | 说明 | +| ------ | ------ | -------------------------------- | +| port | string | 服务端口 | +| host | string | 服务监听地址 | +| enable | string | 是否启用 ,填 'true' 或者 'false' | 返回: @@ -175,11 +175,11 @@ method: `POST` formdata 参数: -| 参数名 | 类型 | 说明 | -| ------ | ------ | ------------------------------------------------------------ | -| port | string | 服务端口 | -| host | string | 服务监听地址 | -| enable | string | 是否启用 ,填 'true' 或者 'false' | +| 参数名 | 类型 | 说明 | +| ------ | ------ | -------------------------------- | +| port | string | 服务端口 | +| host | string | 服务监听地址 | +| enable | string | 是否启用 ,填 'true' 或者 'false' | 返回: @@ -196,9 +196,9 @@ method: `POST` formdata 参数: -| 参数名 | 类型 | 说明 | -| ------ | ------ | ------------------------------------------------------------ | -| json | string | 完整的config.json的配合,json字符串 | +| 参数名 | 类型 | 说明 | +| ------ | ------ | ----------------------------------- | +| json | string | 完整的config.json的配合,json字符串 | 返回: @@ -215,9 +215,9 @@ method: `GET` 参数: -| 参数名 | 类型 | 说明 | -| ------ | ------ | ------------------------------------------------------------ | -| 无 | | | +| 参数名 | 类型 | 说明 | +| ------ | ---- | ---- | +| 无 | | | 返回: @@ -226,7 +226,7 @@ method: `GET` {"data": {"config":"xxxx"}, "retcode": 0, "status": "ok"} ``` -| 参数名 | 类型 | 说明 | -| ------ | ------ | ------------------------------------------------------------ | -| config | string | 完整的config.json的配合,json字符串 | +| 参数名 | 类型 | 说明 | +| ------ | ------ | ----------------------------------- | +| config | string | 完整的config.json的配合,json字符串 | diff --git a/docs/config.md b/docs/config.md index 3f4a94d..4201ef0 100644 --- a/docs/config.md +++ b/docs/config.md @@ -61,29 +61,29 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为: } ```` -| 字段 | 类型 | 说明 | -| ------------------ | -------- | ------------------------------------------------------------------- | -| uin | int64 | 登录用QQ号 | -| password | string | 登录用密码 | -| encrypt_password | bool | 是否对密码进行加密. | -| password_encrypted | string | 加密后的密码(请勿修改) | -| enable_db | bool | 是否开启内置数据库, 关闭后将无法使用 **回复/撤回** 等上下文相关接口 | -| access_token | string | 同CQHTTP的 `access_token` 用于身份验证 | -| relogin | bool | 是否自动重新登录 | -| relogin_delay | int | 重登录延时(秒) | -| max_relogin_times | uint | 最大重登录次数,若0则不设置上限 | -| _rate_limit | bool | 是否启用API调用限速 | -| frequency | float64 | 1s内能调用API的次数 | -| bucket_size | int | 令牌桶的大小,默认为1,修改此值可允许一定程度内连续调用api | -| post_message_format | string | 上报信息类型 | -| ignore_invalid_cqcode| bool | 是否忽略错误的CQ码 | -| force_fragmented | bool | 是否强制分片发送群长消息 | -| use_sso_address | bool | 是否使用服务器下发的地址 | -| heartbeat_interval | int64 | 心跳间隔时间,单位秒。小于0则关闭心跳,等于0使用默认值(5秒) | -| http_config | object | HTTP API配置 | -| ws_config | object | Websocket API 配置 | -| ws_reverse_servers | object[] | 反向 Websocket API 配置 | -| log_level | string | 指定日志收集级别,将收集的日志单独存放到固定文件中,便于查看日志线索 当前支持 warn,error| +| 字段 | 类型 | 说明 | +| --------------------- | -------- | ---------------------------------------------------------------------------------------- | +| uin | int64 | 登录用QQ号 | +| password | string | 登录用密码 | +| encrypt_password | bool | 是否对密码进行加密. | +| password_encrypted | string | 加密后的密码(请勿修改) | +| enable_db | bool | 是否开启内置数据库, 关闭后将无法使用 **回复/撤回** 等上下文相关接口 | +| access_token | string | 同CQHTTP的 `access_token` 用于身份验证 | +| relogin | bool | 是否自动重新登录 | +| relogin_delay | int | 重登录延时(秒) | +| max_relogin_times | uint | 最大重登录次数,若0则不设置上限 | +| _rate_limit | bool | 是否启用API调用限速 | +| frequency | float64 | 1s内能调用API的次数 | +| bucket_size | int | 令牌桶的大小,默认为1,修改此值可允许一定程度内连续调用api | +| post_message_format | string | 上报信息类型 | +| ignore_invalid_cqcode | bool | 是否忽略错误的CQ码 | +| force_fragmented | bool | 是否强制分片发送群长消息 | +| use_sso_address | bool | 是否使用服务器下发的地址 | +| heartbeat_interval | int64 | 心跳间隔时间,单位秒。小于0则关闭心跳,等于0使用默认值(5秒) | +| http_config | object | HTTP API配置 | +| ws_config | object | Websocket API 配置 | +| ws_reverse_servers | object[] | 反向 Websocket API 配置 | +| log_level | string | 指定日志收集级别,将收集的日志单独存放到固定文件中,便于查看日志线索 当前支持 warn,error | > 注: 开启密码加密后程序将在每次启动时要求输入解密密钥, 密钥错误会导致登录时提示密码错误. > 解密后密码将储存在内存中,用于自动重连等功能. 所以此加密并不能防止内存读取. @@ -110,12 +110,12 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为: 在大部分情况下 我们只需要关心 `protocol` 字段: -| 值 | 类型 | 限制 | -| ---- | ------------- | ----------------------------------------------------- | -| 0 | iPad | 无 | -| 1 | Android Phone | 无 | -| 2 | Android Watch | 无法接收 `group_notify` 事件、无法接收口令红包、无法接收撤回消息 | -| 3 | MacOS | 无 | +| 值 | 类型 | 限制 | +| --- | ------------- | ---------------------------------------------------------------- | +| 0 | iPad | 无 | +| 1 | Android Phone | 无 | +| 2 | Android Watch | 无法接收 `group_notify` 事件、无法接收口令红包、无法接收撤回消息 | +| 3 | MacOS | 无 | > 注意, 根据协议的不同, 各类消息有所限制 diff --git a/docs/cqhttp.md b/docs/cqhttp.md index 396bd05..bfa3206 100644 --- a/docs/cqhttp.md +++ b/docs/cqhttp.md @@ -6,24 +6,24 @@ ### 图片 -| 参数名 | 可能的值 | 说明 | -| --- | --- | --- | -| `file` | - | 图片文件名 | -| `type` | `flash`,`show` | 图片类型,`flash` 表示闪照,`show` 表示秀图,默认普通图片 | -| `url` | - | 图片 URL | -| `cache` | `0` `1` | 只在通过网络 URL 发送时有效,表示是否使用已缓存的文件,默认 `1` | -| `id` | - | 发送秀图时的特效id,默认为40000 | +| 参数名 | 可能的值 | 说明 | +| ------- | --------------- | --------------------------------------------------------------- | +| `file` | - | 图片文件名 | +| `type` | `flash`,`show` | 图片类型,`flash` 表示闪照,`show` 表示秀图,默认普通图片 | +| `url` | - | 图片 URL | +| `cache` | `0` `1` | 只在通过网络 URL 发送时有效,表示是否使用已缓存的文件,默认 `1` | +| `id` | - | 发送秀图时的特效id,默认为40000 | 可用的特效ID: -| id |类型 | -| --- |-------| -| 40000 | 普通 | -| 40001 | 幻影 | -| 40002 | 抖动 | -| 40003 | 生日 | -| 40004 | 爱你 | -| 40005 | 征友 | +| id | 类型 | +| ----- | ---- | +| 40000 | 普通 | +| 40001 | 幻影 | +| 40002 | 抖动 | +| 40003 | 生日 | +| 40004 | 爱你 | +| 40005 | 征友 | ### 回复 @@ -64,9 +64,9 @@ Type: `poke` 参数: -| 参数名 | 类型 | 说明 | -| ------ | ------ | ----------- | -| qq | int64 | 需要戳的成员 | +| 参数名 | 类型 | 说明 | +| ------ | ----- | ------------ | +| qq | int64 | 需要戳的成员 | 示例: `[CQ:poke,qq=123456]` @@ -80,29 +80,29 @@ Type: `gift` 参数: -| 参数名 |类型 | 说明 | -| ------ | ------ | -----------| -| qq | int64 | 接收礼物的成员 | -| id | int | 礼物的类型 | +| 参数名 | 类型 | 说明 | +| ------ | ----- | -------------- | +| qq | int64 | 接收礼物的成员 | +| id | int | 礼物的类型 | 目前支持的礼物ID: -| id |类型 | -| ---| ---------| -| 0 | 甜Wink | -| 1 | 快乐肥宅水| -| 2 | 幸运手链 | -| 3 | 卡布奇诺 | -| 4 | 猫咪手表 | -| 5 | 绒绒手套 | -| 6 | 彩虹糖果 | -| 7 | 坚强 | -| 8 | 告白话筒 | -| 9 | 牵你的手 | -| 10 | 可爱猫咪 | -| 11 | 神秘面具 | -| 12 | 我超忙的 | -| 13 | 爱心口罩 | +| id | 类型 | +| --- | ---------- | +| 0 | 甜Wink | +| 1 | 快乐肥宅水 | +| 2 | 幸运手链 | +| 3 | 卡布奇诺 | +| 4 | 猫咪手表 | +| 5 | 绒绒手套 | +| 6 | 彩虹糖果 | +| 7 | 坚强 | +| 8 | 告白话筒 | +| 9 | 牵你的手 | +| 10 | 可爱猫咪 | +| 11 | 神秘面具 | +| 12 | 我超忙的 | +| 13 | 爱心口罩 | @@ -116,8 +116,8 @@ Type: `forward` 参数: -| 参数名 | 类型 | 说明 | -| ------ | ------ | ------------------------------------------------------------ | +| 参数名 | 类型 | 说明 | +| ------ | ------ | ------------------------------------------------------------- | | id | string | 合并转发ID, 需要通过 `/get_forward_msg` API获取转发的具体内容 | 示例: `[CQ:forward,id=xxxx]` @@ -130,12 +130,12 @@ Type: `node` 参数: -| 参数名 | 类型 | 说明 | 特殊说明 | -| ------- | ------- | -------------- | ------------------------------------------------------------ | +| 参数名 | 类型 | 说明 | 特殊说明 | +| ------- | ------- | -------------- | -------------------------------------------------------------------------------------- | | id | int32 | 转发消息id | 直接引用他人的消息合并转发, 实际查看顺序为原消息发送顺序 **与下面的自定义消息二选一** | -| name | string | 发送者显示名字 | 用于自定义消息 (自定义消息并合并转发,实际查看顺序为自定义消息段顺序) | -| uin | int64 | 发送者QQ号 | 用于自定义消息 | -| content | message | 具体消息 | 用于自定义消息 **不支持转发套娃,不支持引用回复** | +| name | string | 发送者显示名字 | 用于自定义消息 (自定义消息并合并转发,实际查看顺序为自定义消息段顺序) | +| uin | int64 | 发送者QQ号 | 用于自定义消息 | +| content | message | 具体消息 | 用于自定义消息 **不支持转发套娃,不支持引用回复** | 特殊说明: **需要使用单独的API `/send_group_forward_msg` 发送,并且由于消息段较为复杂,仅支持Array形式入参。 如果引用消息和自定义消息同时出现,实际查看顺序将取消息段顺序. 另外按 [CQHTTP](https://cqhttp.cc/docs/4.15/#/Message?id=格式) 文档说明, `data` 应全为字符串, 但由于需要接收`message` 类型的消息, 所以 *仅限此Type的content字段* 支持Array套娃** @@ -217,10 +217,10 @@ Type: `xml` 参数: -| 参数名 | 类型 | 说明 | -| ------ | ------ | ------------------------------------------------------------ | -| data | string | xml内容,xml中的value部分,记得实体化处理| -| resid | int32 | 可以不填| +| 参数名 | 类型 | 说明 | +| ------ | ------ | ----------------------------------------- | +| data | string | xml内容,xml中的value部分,记得实体化处理 | +| resid | int32 | 可以不填 | 示例: `[CQ:xml,data=xxxx]` @@ -266,10 +266,10 @@ Type: `json` 参数: -| 参数名 | 类型 | 说明 | -| ------ | ------ | ------------------------------------------------------------ | -| data | string | json内容,json的所有字符串记得实体化处理| -| resid | int32 | 默认不填为0,走小程序通道,填了走富文本通道发送| +| 参数名 | 类型 | 说明 | +| ------ | ------ | ----------------------------------------------- | +| data | string | json内容,json的所有字符串记得实体化处理 | +| resid | int32 | 默认不填为0,走小程序通道,填了走富文本通道发送 | json中的字符串需要进行转义: @@ -299,15 +299,15 @@ Type: `cardimage` 参数: -| 参数名 | 类型 | 说明 | -| ------ | ------ | ------------------------------------------------------------ | -| file | string | 和image的file字段对齐,支持也是一样的| -| minwidth | int64 | 默认不填为400,最小width| -| minheight | int64 | 默认不填为400,最小height| -| maxwidth | int64 | 默认不填为500,最大width| -| maxheight | int64 | 默认不填为1000,最大height| -| source | string | 分享来源的名称,可以留空| -| icon | string | 分享来源的icon图标url,可以留空| +| 参数名 | 类型 | 说明 | +| --------- | ------ | ------------------------------------- | +| file | string | 和image的file字段对齐,支持也是一样的 | +| minwidth | int64 | 默认不填为400,最小width | +| minheight | int64 | 默认不填为400,最小height | +| maxwidth | int64 | 默认不填为500,最大width | +| maxheight | int64 | 默认不填为1000,最大height | +| source | string | 分享来源的名称,可以留空 | +| icon | string | 分享来源的icon图标url,可以留空 | 示例cardimage 的cq码: @@ -325,9 +325,9 @@ Type: `tts` 参数: -| 参数名 | 类型 | 说明 | -| ------ | ------ | ----------- | -| text | string | 内容 | +| 参数名 | 类型 | 说明 | +| ------ | ------ | ---- | +| text | string | 内容 | 示例: `[CQ:tts,text=这是一条测试消息]` @@ -339,10 +339,10 @@ Type: `tts` **参数** -| 字段 | 类型 | 说明 | -| -------- | ------ | ---- | -| group_id | int64 | 群号 | -| group_name | string | 新名 | +| 字段 | 类型 | 说明 | +| ---------- | ------ | ---- | +| group_id | int64 | 群号 | +| group_name | string | 新名 | ### 设置群头像 @@ -350,11 +350,11 @@ Type: `tts` **参数** -| 字段 | 类型 | 说明 | -| -------- | ------ | ---- | -| group_id | int64 | 群号 | -| file | string | 图片文件名 | -| cache | int | 表示是否使用已缓存的文件 | +| 字段 | 类型 | 说明 | +| -------- | ------ | ------------------------ | +| group_id | int64 | 群号 | +| file | string | 图片文件名 | +| cache | int | 表示是否使用已缓存的文件 | [1]`file` 参数支持以下几种格式: @@ -468,15 +468,15 @@ Type: `tts` **参数** -| 字段 | 类型 | 说明 | -| ------------ | ------ | ------ | +| 字段 | 类型 | 说明 | +| --------- | ------ | ---- | | `content` | string | 内容 | **响应数据** -| 字段 | 类型 | 说明 | -| ---------- | ----------------- | -------- | -| `slices` | string[] | 词组 | +| 字段 | 类型 | 说明 | +| -------- | -------- | ---- | +| `slices` | string[] | 词组 | ### 图片OCR @@ -486,24 +486,24 @@ Type: `tts` **参数** - | 字段 | 类型 | 说明 | - | ------------ | ------ | ------ | + | 字段 | 类型 | 说明 | + | ------- | ------ | ------ | | `image` | string | 图片ID | **响应数据** - | 字段 | 类型 | 说明 | - | ---------- | ----------------- | -------- | - | `texts` | TextDetection[] | OCR结果 | - | `language` | string | 语言 | + | 字段 | 类型 | 说明 | + | ---------- | --------------- | ------- | + | `texts` | TextDetection[] | OCR结果 | + | `language` | string | 语言 | **TextDetection** - | 字段 | 类型 | 说明 | - | ---------- | ----------------- | -------- | - | `text` | string | 文本 | - | `confidence`| int32 | 置信度 | - | `coordinates` | vector2 | 坐标 | + | 字段 | 类型 | 说明 | + | ------------- | ------- | ------ | + | `text` | string | 文本 | + | `confidence` | int32 | 置信度 | + | `coordinates` | vector2 | 坐标 | ### 获取群系统消息 @@ -512,37 +512,37 @@ Type: `tts` **响应数据** - | 字段 | 类型 | 说明 | - | ---------- | ----------------- | -------- | - | `invited_requests` | InvitedRequest[] | 邀请消息列表 | - | `join_requests` | JoinRequest[] | 进群消息列表 | + | 字段 | 类型 | 说明 | + | ------------------ | ---------------- | ------------ | + | `invited_requests` | InvitedRequest[] | 邀请消息列表 | + | `join_requests` | JoinRequest[] | 进群消息列表 | > 注意: 如果列表不存在任何消息, 将返回 `null` **InvitedRequest** - | 字段 | 类型 | 说明 | - | ---------- | ----------------- | -------- | - | `request_id` | int64 | 请求ID | - | `invitor_uin` | int64 | 邀请者 | - | `invitor_nick` | string | 邀请者昵称 | - | `group_id` | int64 | 群号 | - | `group_name` | string | 群名 | - | `checked` | bool | 是否已被处理| - | `actor` | int64 | 处理者, 未处理为0 | + | 字段 | 类型 | 说明 | + | -------------- | ------ | ----------------- | + | `request_id` | int64 | 请求ID | + | `invitor_uin` | int64 | 邀请者 | + | `invitor_nick` | string | 邀请者昵称 | + | `group_id` | int64 | 群号 | + | `group_name` | string | 群名 | + | `checked` | bool | 是否已被处理 | + | `actor` | int64 | 处理者, 未处理为0 | **JoinRequest** - | 字段 | 类型 | 说明 | - | ---------- | ----------------- | -------- | - | `request_id` | int64 | 请求ID | - | `requester_uin` | int64 | 请求者ID | - | `requester_nick` | string | 请求者昵称 | - | `message` | string | 验证消息 | - | `group_id` | int64 | 群号 | - | `group_name` | string | 群名 | - | `checked` | bool | 是否已被处理| - | `actor` | int64 | 处理者, 未处理为0 | + | 字段 | 类型 | 说明 | + | ---------------- | ------ | ----------------- | + | `request_id` | int64 | 请求ID | + | `requester_uin` | int64 | 请求者ID | + | `requester_nick` | string | 请求者昵称 | + | `message` | string | 验证消息 | + | `group_id` | int64 | 群号 | + | `group_name` | string | 群名 | + | `checked` | bool | 是否已被处理 | + | `actor` | int64 | 处理者, 未处理为0 | ### 获取群文件系统信息 @@ -550,18 +550,18 @@ Type: `tts` **参数** - | 字段 | 类型 | 说明 | - | ------------ | ------ | ------ | + | 字段 | 类型 | 说明 | + | ---------- | ----- | ---- | | `group_id` | int64 | 群号 | **响应数据** - | 字段 | 类型 | 说明 | - | ---------- | ----------------- | -------- | - | `file_count` | int32 | 文件总数 | - | `limit_count` | int32 | 文件上限 | - | `used_space` | int64 | 已使用空间 | - | `total_space` | int64 | 空间上限 | + | 字段 | 类型 | 说明 | + | ------------- | ----- | ---------- | + | `file_count` | int32 | 文件总数 | + | `limit_count` | int32 | 文件上限 | + | `used_space` | int64 | 已使用空间 | + | `total_space` | int64 | 空间上限 | ### 获取群根目录文件列表 @@ -571,16 +571,16 @@ Type: `tts` **参数** - | 字段 | 类型 | 说明 | - | ------------ | ------ | ------ | + | 字段 | 类型 | 说明 | + | ---------- | ----- | ---- | | `group_id` | int64 | 群号 | **响应数据** - | 字段 | 类型 | 说明 | - | ---------- | ----------------- | -------- | - | `files` | File[] | 文件列表 | - | `folders` | Folder[] | 文件夹列表 | + | 字段 | 类型 | 说明 | + | --------- | -------- | ---------- | + | `files` | File[] | 文件列表 | + | `folders` | Folder[] | 文件夹列表 | ### 获取群子目录文件列表 @@ -590,17 +590,17 @@ Type: `tts` **参数** - | 字段 | 类型 | 说明 | - | ------------ | ------ | ------ | - | `group_id` | int64 | 群号 | + | 字段 | 类型 | 说明 | + | ----------- | ------ | --------------------------- | + | `group_id` | int64 | 群号 | | `folder_id` | string | 文件夹ID 参考 `Folder` 对象 | **响应数据** - | 字段 | 类型 | 说明 | - | ---------- | ----------------- | -------- | - | `files` | File[] | 文件列表 | - | `folders` | Folder[] | 文件夹列表 | + | 字段 | 类型 | 说明 | + | --------- | -------- | ---------- | + | `files` | File[] | 文件列表 | + | `folders` | Folder[] | 文件夹列表 | ### 获取群文件资源链接 @@ -610,43 +610,43 @@ Type: `tts` **参数** - | 字段 | 类型 | 说明 | - | ------------ | ------ | ------ | - | `group_id` | int64 | 群号 | - | `file_id` | string | 文件ID 参考 `File` 对象 | - | `busid` | int32 | 文件类型 参考 `File` 对象 | + | 字段 | 类型 | 说明 | + | ---------- | ------ | ------------------------- | + | `group_id` | int64 | 群号 | + | `file_id` | string | 文件ID 参考 `File` 对象 | + | `busid` | int32 | 文件类型 参考 `File` 对象 | **响应数据** - | 字段 | 类型 | 说明 | - | ---------- | ----------------- | -------- | - | `url` | string | 文件下载链接 | + | 字段 | 类型 | 说明 | + | ----- | ------ | ------------ | + | `url` | string | 文件下载链接 | **File** - | 字段 | 类型 | 说明 | - | ---------- | ----------------- | -------- | - | `file_id` | string | 文件ID | - | `file_name` | string | 文件名 | - | `busid` | int32 | 文件类型 | - | `file_size` | int64 | 文件大小 | - | `upload_time` | int64 | 上传时间 | - | `dead_time` | int64 | 过期时间,永久文件恒为0 | - | `modify_time` | int64 | 最后修改时间 | - | `download_times` | int32 | 下载次数 | - | `uploader` | int64 | 上传者ID | - | `uploader_name` | string | 上传者名字 | + | 字段 | 类型 | 说明 | + | ---------------- | ------ | ---------------------- | + | `file_id` | string | 文件ID | + | `file_name` | string | 文件名 | + | `busid` | int32 | 文件类型 | + | `file_size` | int64 | 文件大小 | + | `upload_time` | int64 | 上传时间 | + | `dead_time` | int64 | 过期时间,永久文件恒为0 | + | `modify_time` | int64 | 最后修改时间 | + | `download_times` | int32 | 下载次数 | + | `uploader` | int64 | 上传者ID | + | `uploader_name` | string | 上传者名字 | **Folder** - | 字段 | 类型 | 说明 | - | ---------- | ----------------- | -------- | - | `folder_id` | string | 文件夹ID | - | `folder_name` | string | 文件名 | - | `create_time` | int64 | 创建时间 | - | `creator` | int64 | 创建者 | - | `creator_name` | string | 创建者名字 | - | `total_file_count` | int32 | 子文件数量 | + | 字段 | 类型 | 说明 | + | ------------------ | ------ | ---------- | + | `folder_id` | string | 文件夹ID | + | `folder_name` | string | 文件名 | + | `create_time` | int64 | 创建时间 | + | `creator` | int64 | 创建者 | + | `creator_name` | string | 创建者名字 | + | `total_file_count` | int32 | 子文件数量 | ## 事件 @@ -667,12 +667,12 @@ Type: `tts` **上报数据** -| 字段 | 类型 | 可能的值 | 说明 | -| ------------- | ------ | -------------- | -------------- | -| `post_type` | string | `notice` | 上报类型 | -| `notice_type` | string | `friend_recall`| 消息类型 | -| `user_id` | int64 | | 好友id | -| `message_id` | int64 | | 被撤回的消息id | +| 字段 | 类型 | 可能的值 | 说明 | +| ------------- | ------ | --------------- | -------------- | +| `post_type` | string | `notice` | 上报类型 | +| `notice_type` | string | `friend_recall` | 消息类型 | +| `user_id` | int64 | | 好友id | +| `message_id` | int64 | | 被撤回的消息id | #### 群内戳一戳 @@ -680,14 +680,14 @@ Type: `tts` **上报数据** -| 字段 | 类型 | 可能的值 | 说明 | -| ------------- | ------ | -------------- | -------------- | -| `post_type` | string | `notice` | 上报类型 | -| `notice_type` | string | `notify` | 消息类型 | -| `group_id` | int64 | | 群号 | -| `sub_type` | string | `poke` | 提示类型 | -| `user_id` | int64 | | 发送者id | -| `target_id` | int64 | | 被戳者id | +| 字段 | 类型 | 可能的值 | 说明 | +| ------------- | ------ | -------- | -------- | +| `post_type` | string | `notice` | 上报类型 | +| `notice_type` | string | `notify` | 消息类型 | +| `group_id` | int64 | | 群号 | +| `sub_type` | string | `poke` | 提示类型 | +| `user_id` | int64 | | 发送者id | +| `target_id` | int64 | | 被戳者id | #### 群红包运气王提示 @@ -695,14 +695,14 @@ Type: `tts` **上报数据** -| 字段 | 类型 | 可能的值 | 说明 | -| ------------- | ------ | -------------- | -------------- | -| `post_type` | string | `notice` | 上报类型 | -| `notice_type` | string | `notify` | 消息类型 | -| `group_id` | int64 | | 群号 | -| `sub_type` | string | `lucky_king` | 提示类型 | -| `user_id` | int64 | | 红包发送者id | -| `target_id` | int64 | | 运气王id | +| 字段 | 类型 | 可能的值 | 说明 | +| ------------- | ------ | ------------ | ------------ | +| `post_type` | string | `notice` | 上报类型 | +| `notice_type` | string | `notify` | 消息类型 | +| `group_id` | int64 | | 群号 | +| `sub_type` | string | `lucky_king` | 提示类型 | +| `user_id` | int64 | | 红包发送者id | +| `target_id` | int64 | | 运气王id | #### 群成员荣誉变更提示 @@ -710,14 +710,14 @@ Type: `tts` **上报数据** -| 字段 | 类型 | 可能的值 | 说明 | -| ------------- | ------ | -------------- | -------------- | -| `post_type` | string | `notice` | 上报类型 | -| `notice_type` | string | `notify` | 消息类型 | -| `group_id` | int64 | | 群号 | -| `sub_type` | string | `honor` | 提示类型 | -| `user_id` | int64 | | 成员id | -| `honor_type` | string | `talkative:龙王` `performer:群聊之火` `emotion:快乐源泉` | 荣誉类型 | +| 字段 | 类型 | 可能的值 | 说明 | +| ------------- | ------ | -------------------------------------------------------- | -------- | +| `post_type` | string | `notice` | 上报类型 | +| `notice_type` | string | `notify` | 消息类型 | +| `group_id` | int64 | | 群号 | +| `sub_type` | string | `honor` | 提示类型 | +| `user_id` | int64 | | 成员id | +| `honor_type` | string | `talkative:龙王` `performer:群聊之火` `emotion:快乐源泉` | 荣誉类型 | #### 群成员名片更新 @@ -725,14 +725,14 @@ Type: `tts` **上报数据** -| 字段 | 类型 | 可能的值 | 说明 | -| ------------- | ------ | -------------- | -------------- | -| `post_type` | string | `notice` | 上报类型 | -| `notice_type` | string | `group_card` | 消息类型 | -| `group_id` | int64 | | 群号 | -| `user_id` | int64 | | 成员id | -| `card_new` | int64 | | 新名片 | -| `card_old` | int64 | | 旧名片 | +| 字段 | 类型 | 可能的值 | 说明 | +| ------------- | ------ | ------------ | -------- | +| `post_type` | string | `notice` | 上报类型 | +| `notice_type` | string | `group_card` | 消息类型 | +| `group_id` | int64 | | 群号 | +| `user_id` | int64 | | 成员id | +| `card_new` | int64 | | 新名片 | +| `card_old` | int64 | | 旧名片 | > PS: 当名片为空时 `card_xx` 字段为空字符串, 并不是昵称 @@ -740,17 +740,17 @@ Type: `tts` **上报数据** -| 字段 | 类型 | 可能的值 | 说明 | -| ------------- | ------ | -------------- | -------------- | -| `post_type` | string | `notice` | 上报类型 | -| `notice_type` | string | `offline_file` | 消息类型 | -| `user_id` | int64 | | 发送者id | -| `file` | object | | 文件数据 | +| 字段 | 类型 | 可能的值 | 说明 | +| ------------- | ------ | -------------- | -------- | +| `post_type` | string | `notice` | 上报类型 | +| `notice_type` | string | `offline_file` | 消息类型 | +| `user_id` | int64 | | 发送者id | +| `file` | object | | 文件数据 | **file object** -| 字段 | 类型 | 可能的值 | 说明 | -| ------------- | ------ | -------------- | -------------- | -| `name` | string | | 文件名 | -| `size` | int64 | | 文件大小 | -| `url` | string | | 下载链接 | \ No newline at end of file +| 字段 | 类型 | 可能的值 | 说明 | +| ------ | ------ | -------- | -------- | +| `name` | string | | 文件名 | +| `size` | int64 | | 文件大小 | +| `url` | string | | 下载链接 | \ No newline at end of file diff --git a/docs/quick_start.md b/docs/quick_start.md index 67fcbab..778a533 100644 --- a/docs/quick_start.md +++ b/docs/quick_start.md @@ -117,7 +117,7 @@ enable ws?(Y/n) *注:可以使用*`go env -w GOPROXY=https://goproxy.cn,direct`*来加速国内依赖安装速度* -*注:此时构建后的文件名为*`main`(Linux)或`main.exe`(Windows) +*注:此时构建后的文件名为*`go-cqhttp`(Linux)或`go-cqhttp.exe`(Windows) ## 更新 From 28f1594539eac276f088831e97aa5cf1ce9426c6 Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Tue, 17 Nov 2020 00:24:25 +0800 Subject: [PATCH 08/17] feather: faststart --- main.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 18f31cd..01d9ac8 100644 --- a/main.go +++ b/main.go @@ -98,7 +98,7 @@ func init() { func main() { console := bufio.NewReader(os.Stdin) var strKey string - var isRestart bool = false + var isFastStart bool = false arg := os.Args fmt.Println(arg) if len(arg) > 1 { @@ -116,8 +116,8 @@ func main() { b = append(b, 13, 10) strKey = string(b[:]) } - case "restart": - isRestart = true + case "faststart": + isFastStart = true } } } @@ -256,7 +256,7 @@ func main() { key := md5.Sum([]byte(strKey)) conf.Password = DecryptPwd(conf.PasswordEncrypted, key[:]) } - if !isRestart { + if !isFastStart { log.Info("Bot将在5秒后登录并开始信息处理, 按 Ctrl+C 取消.") time.Sleep(time.Second * 5) } @@ -464,7 +464,7 @@ func restart(Args []string) { if err != nil { log.Errorf("重启失败:%s", err.Error()) } - Args = append([]string{"/c", "start ", path, "restart"}, Args[1:]...) + Args = append([]string{"/c", "start ", path, "faststart"}, Args[1:]...) cmd = &exec.Cmd{ Path: "cmd.exe", Args: Args, @@ -472,6 +472,7 @@ func restart(Args []string) { Stdout: os.Stdout, } } else { + Args = append(Args, "faststart") cmd = &exec.Cmd{ Path: Args[0], Args: Args, From f87b5c8215a632b07f5f00e5cdd8694100c5848e Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Tue, 17 Nov 2020 00:26:51 +0800 Subject: [PATCH 09/17] Fix seflUpdate --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 01d9ac8..d932616 100644 --- a/main.go +++ b/main.go @@ -106,7 +106,7 @@ func main() { switch arg[i] { case "update": if len(arg) > i+1 { - selfUpdate(arg[i+2]) + selfUpdate(arg[i+1]) } else { selfUpdate("") } From e053da62e195cdb551c8172a4ca0bcb7f22085c2 Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Tue, 17 Nov 2020 01:23:44 +0800 Subject: [PATCH 10/17] Update adminApi.md --- docs/adminApi.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/adminApi.md b/docs/adminApi.md index c82e9fe..374bfd1 100644 --- a/docs/adminApi.md +++ b/docs/adminApi.md @@ -87,6 +87,25 @@ method: `POST` formdata method: `POST` +参数: + +| 参数名 | 类型 | 说明 | +| ------ | ---- | ---- | +| 无 | | | + +返回: + +```json +{"data": {}, "retcode": 0, "status": "ok"} +``` + +### admin/do_process_restart + +> 冷重启 + +method: `POST` + + 参数: | 参数名 | 类型 | 说明 | From e9b39f3379837ef9f641bb14549e60758f0c9e51 Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Tue, 17 Nov 2020 01:24:16 +0800 Subject: [PATCH 11/17] =?UTF-8?q?Fix:=20set=5Frestart=20delay=E4=B8=8D?= =?UTF-8?q?=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/http.go | 13 +++---------- server/websocket.go | 6 +++--- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/server/http.go b/server/http.go index 5b58c7e..a3b0ae2 100644 --- a/server/http.go +++ b/server/http.go @@ -5,6 +5,7 @@ import ( "crypto/hmac" "crypto/sha1" "encoding/hex" + "fmt" "net/http" "os" "strconv" @@ -346,21 +347,13 @@ func SetGroupLeave(s *httpServer, c *gin.Context) { } func SetRestart(s *httpServer, c *gin.Context) { - d, t := getParamWithType(c, "delay") - if t == gjson.Null { - d = "0" - } - delay, err := strconv.ParseInt(d, 10, 64) - if err != nil || delay < 0 { - c.JSON(200, Failed(100, "Invalid delay")) - return - } + delay, _ := strconv.ParseInt(getParam(c, "delay"), 10, 64) c.JSON(200, coolq.MSG{"data": nil, "retcode": 0, "status": "async"}) go func(delay int64) { var del *time.Duration = (*time.Duration)(unsafe.Pointer(&delay)) time.Sleep(*del * time.Millisecond) Restart <- struct{}{} - }(delay * time.Hour.Milliseconds()) + }(delay) } diff --git a/server/websocket.go b/server/websocket.go index b01fd21..24865f7 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -485,13 +485,13 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{ var delay int64 = 0 delay = p.Get("delay").Int() if delay < 0 { - return Failed(100, "Invalid delay") + delay = 0 } defer func(delay int64) { var del *time.Duration = (*time.Duration)(unsafe.Pointer(&delay)) - time.Sleep(*del * time.Millisecond) + time.Sleep(*del * time.Microsecond) Restart <- struct{}{} - }(delay * time.Hour.Milliseconds()) + }(delay) return coolq.MSG{"data": nil, "retcode": 0, "status": "async"} }, From e9a03b68b5123ee810778000f80c55fcaf2d745a Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Tue, 17 Nov 2020 01:26:13 +0800 Subject: [PATCH 12/17] delete test function --- main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/main.go b/main.go index d932616..b09ece5 100644 --- a/main.go +++ b/main.go @@ -100,7 +100,6 @@ func main() { var strKey string var isFastStart bool = false arg := os.Args - fmt.Println(arg) if len(arg) > 1 { for i := range arg { switch arg[i] { From 0fc004077b1d40e22eef90942853eb764edcf95e Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Tue, 17 Nov 2020 01:30:05 +0800 Subject: [PATCH 13/17] delete unused import --- server/http.go | 1 - 1 file changed, 1 deletion(-) diff --git a/server/http.go b/server/http.go index a3b0ae2..ac83dd7 100644 --- a/server/http.go +++ b/server/http.go @@ -5,7 +5,6 @@ import ( "crypto/hmac" "crypto/sha1" "encoding/hex" - "fmt" "net/http" "os" "strconv" From 7f3e58f97a4efb793ff107042a53d5246a5f5e68 Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Tue, 17 Nov 2020 01:45:14 +0800 Subject: [PATCH 14/17] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7365a7f..7c7a90c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: - uses: actions/checkout@v2 - name: Setup Go environment - uses: actions/setup-go@v2.1.1 + uses: actions/setup-go@v2.1.3 with: go-version: 1.15 From 8f34003c6f5070ab0253740439483f14ae51a626 Mon Sep 17 00:00:00 2001 From: Ink33 <51873347+Ink-33@users.noreply.github.com> Date: Tue, 17 Nov 2020 13:53:46 +0800 Subject: [PATCH 15/17] Update websocket.go --- server/websocket.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/websocket.go b/server/websocket.go index 24865f7..f0accec 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -8,7 +8,6 @@ import ( "strings" "sync" "time" - "unsafe" "github.com/Mrs4s/go-cqhttp/coolq" "github.com/Mrs4s/go-cqhttp/global" @@ -488,8 +487,7 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{ delay = 0 } defer func(delay int64) { - var del *time.Duration = (*time.Duration)(unsafe.Pointer(&delay)) - time.Sleep(*del * time.Microsecond) + time.Sleep(time.Duration(delay) * time.Milliseconds) Restart <- struct{}{} }(delay) return coolq.MSG{"data": nil, "retcode": 0, "status": "async"} From beb1a2883a90499359253fca74c4f004b94c9d3d Mon Sep 17 00:00:00 2001 From: Ink33 <51873347+Ink-33@users.noreply.github.com> Date: Tue, 17 Nov 2020 13:57:28 +0800 Subject: [PATCH 16/17] Update websocket.go --- server/websocket.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/websocket.go b/server/websocket.go index f0accec..5de0e49 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -487,7 +487,7 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{ delay = 0 } defer func(delay int64) { - time.Sleep(time.Duration(delay) * time.Milliseconds) + time.Sleep(time.Duration(delay) * time.Millisecond) Restart <- struct{}{} }(delay) return coolq.MSG{"data": nil, "retcode": 0, "status": "async"} From da2e34aaa5664486a601f9f50808181b1902f911 Mon Sep 17 00:00:00 2001 From: Ink33 <51873347+Ink-33@users.noreply.github.com> Date: Tue, 17 Nov 2020 13:58:23 +0800 Subject: [PATCH 17/17] Update http.go --- server/http.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/http.go b/server/http.go index ac83dd7..f79d443 100644 --- a/server/http.go +++ b/server/http.go @@ -10,7 +10,6 @@ import ( "strconv" "strings" "time" - "unsafe" "github.com/guonaihong/gout/dataflow" @@ -349,8 +348,7 @@ func SetRestart(s *httpServer, c *gin.Context) { delay, _ := strconv.ParseInt(getParam(c, "delay"), 10, 64) c.JSON(200, coolq.MSG{"data": nil, "retcode": 0, "status": "async"}) go func(delay int64) { - var del *time.Duration = (*time.Duration)(unsafe.Pointer(&delay)) - time.Sleep(*del * time.Millisecond) + time.Sleep(time.Duration(delay) * time.Millisecond) Restart <- struct{}{} }(delay)