From 174bb0bbe115427380cadc90e55acaf1c6e752db Mon Sep 17 00:00:00 2001 From: F0ur Date: Tue, 25 Aug 2020 15:17:20 +0800 Subject: [PATCH 01/23] feat(music): add netease(163) music for [CQ:music] --- coolq/cqcode.go | 32 +++++++++++++++++++++++++++----- global/net.go | 24 +++++++++++++++++------- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 4c5e8b42..f3a6fe67 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -6,11 +6,6 @@ import ( "encoding/hex" "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" @@ -18,6 +13,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+?.*?]`) @@ -453,6 +454,27 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message. SubType: "music", }, nil } + if d["type"] == "163" { + info, err := global.NeteaseMusicSongInfo(d["id"]) + if err != nil { + return nil, err + } + if !info.Exists() { + return nil, errors.New("song not found") + } + name := info.Get("name").Str + artistName := "" + if info.Get("artists.0").Exists() { + artistName = info.Get("artists.0.name").Str + } + xml := fmt.Sprintf(``, + name, d["id"], info.Get("album.picUrl").Str, d["id"], name, artistName) + return &message.ServiceElement{ + Id: 60, + Content: xml, + SubType: "music", + }, nil + } if d["type"] == "custom" { xml := fmt.Sprintf(``, d["title"], d["url"], d["image"], d["audio"], d["title"], d["content"]) diff --git a/global/net.go b/global/net.go index d3cf1a7f..e394efdd 100644 --- a/global/net.go +++ b/global/net.go @@ -3,12 +3,14 @@ package global import ( "bytes" "compress/gzip" - "github.com/Mrs4s/MiraiGo/message" - "github.com/tidwall/gjson" + "fmt" "io/ioutil" "net/http" "strconv" "strings" + + "github.com/Mrs4s/MiraiGo/message" + "github.com/tidwall/gjson" ) func GetBytes(url string) ([]byte, error) { @@ -44,12 +46,20 @@ func QQMusicSongInfo(id string) (gjson.Result, error) { return gjson.ParseBytes(d).Get("songinfo.data"), nil } -func NewXmlMsg(template string,ResId int64) *message.ServiceElement{ +func NeteaseMusicSongInfo(id string) (gjson.Result, error) { + d, err := GetBytes(fmt.Sprintf("http://music.163.com/api/song/detail/?id=%s&ids=%%5B%s%%5D", id, id)) + if err != nil { + return gjson.Result{}, err + } + return gjson.ParseBytes(d).Get("songs.0"), nil +} + +func NewXmlMsg(template string, ResId int64) *message.ServiceElement { var serviceid string - if ResId == 0{ - serviceid ="2" //默认值2 - }else{ - serviceid = strconv.FormatInt(ResId,10) + if ResId == 0 { + serviceid = "2" //默认值2 + } else { + serviceid = strconv.FormatInt(ResId, 10) } //println(serviceid) return &message.ServiceElement{ From bda02d895a08ed920aed4ceb56dac4abfdcf15b8 Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Tue, 25 Aug 2020 17:05:44 +0800 Subject: [PATCH 02/23] update MiraiGo. --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index ca481118..6694dd69 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp go 1.14 require ( - github.com/Mrs4s/MiraiGo v0.0.0-20200824164833-834baa5b6b58 + github.com/Mrs4s/MiraiGo v0.0.0-20200824170850-16fc454f752b github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/gin-gonic/gin v1.6.3 github.com/gorilla/websocket v1.4.2 diff --git a/go.sum b/go.sum index 0d18f626..148c90ae 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Mrs4s/MiraiGo v0.0.0-20200824164833-834baa5b6b58 h1:bQDlJSgZmQh9fOMF7yWwL6w2HDm2YUmJlW871WQ404U= github.com/Mrs4s/MiraiGo v0.0.0-20200824164833-834baa5b6b58/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM= +github.com/Mrs4s/MiraiGo v0.0.0-20200824170850-16fc454f752b h1:dYpx9kjDmSCVyu0Mr86GDou0Wz5iXYcMwYL52G5wz70= +github.com/Mrs4s/MiraiGo v0.0.0-20200824170850-16fc454f752b/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM= github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0= github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= From 02355db0f160c6018e45685c7987f2319db9e9e3 Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Tue, 25 Aug 2020 17:26:08 +0800 Subject: [PATCH 03/23] update config. close #190 --- coolq/bot.go | 4 +++- coolq/cqcode.go | 10 ++++++++-- docs/config.md | 33 ++++++++++++++++++++------------- global/config.go | 29 ++++++++++++++++------------- main.go | 2 ++ 5 files changed, 49 insertions(+), 29 deletions(-) diff --git a/coolq/bot.go b/coolq/bot.go index f0b21064..6f36aa2c 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -31,6 +31,8 @@ type CQBot struct { type MSG map[string]interface{} +var ForceFragmented = false + func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot { bot := &CQBot{ Client: cli, @@ -128,7 +130,7 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int newElem = append(newElem, elem) } m.Elements = newElem - ret := bot.Client.SendGroupMessage(groupId, m) + ret := bot.Client.SendGroupMessage(groupId, m, ForceFragmented) if ret == nil || ret.Id == -1 { log.Warnf("群消息发送失败: 账号可能被风控.") return -1 diff --git a/coolq/cqcode.go b/coolq/cqcode.go index f3a6fe67..726129d7 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -25,6 +25,8 @@ var matchReg = regexp.MustCompile(`\[CQ:\w+?.*?]`) var typeReg = regexp.MustCompile(`\[CQ:(\w+)`) var paramReg = regexp.MustCompile(`,([\w\-.]+?)=([^,\]]+)`) +var IgnoreInvalidCQCode = false + func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []MSG) { ur := false if len(raw) != 0 { @@ -199,8 +201,12 @@ func (bot *CQBot) ConvertStringMessage(m string, group bool) (r []message.IMessa } elem, err := bot.ToElement(t, d, group) if err != nil { - log.Warnf("转换CQ码到MiraiGo Element时出现错误: %v 将原样发送.", err) - r = append(r, message.NewText(code)) + if !IgnoreInvalidCQCode { + log.Warnf("转换CQ码 %v 到MiraiGo Element时出现错误: %v 将原样发送.", code, err) + r = append(r, message.NewText(code)) + } else { + log.Warnf("转换CQ码 %v 到MiraiGo Element时出现错误: %v 将忽略.", code, err) + } continue } r = append(r, elem) diff --git a/docs/config.md b/docs/config.md index 2ba5612e..245800f7 100644 --- a/docs/config.md +++ b/docs/config.md @@ -25,12 +25,14 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为: "relogin": false, "relogin_delay": 0, "post_message_format": "string", + "ignore_invalid_cqcode": false, + "force_fragmented": true, "http_config": { "enabled": true, "host": "0.0.0.0", "port": 5700, - "timeout": 5, - "post_urls": {"url:port": "secret"}, + "timeout": 5, + "post_urls": {"url:port": "secret"} }, "ws_config": { "enabled": true, @@ -51,18 +53,23 @@ 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 | 重登录延时(秒) | -| http_config | object | HTTP API配置 | -| ws_config | object | Websocket API 配置 | -| ws_reverse_servers | object[] | 反向 Websocket API 配置 | +| 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 | 重登录延时(秒) | +| post_message_format | string | 上报信息类型 | +| ignore_invalid_cqcode| bool | 是否忽略错误的CQ码 | +| force_fragmented | bool | 是否强制分片发送群长消息 | +| http_config | object | HTTP API配置 | +| ws_config | object | Websocket API 配置 | +| ws_reverse_servers | object[] | 反向 Websocket API 配置 | > 注: 开启密码加密后程序将在每次启动时要求输入解密密钥, 密钥错误会导致登录时提示密码错误. > 解密后密码将储存在内存中,用于自动重连等功能. 所以此加密并不能防止内存读取. > 解密密钥在使用完成后并不会留存在内存中, 所以可用相对简单的字符串作为密钥 + +> 注2: 分片发送为原酷Q发送长消息的老方案, 发送速度更优/兼容性更好。关闭后将优先使用新方案, 能发送更长的消息, 但发送速度更慢,在部分老客户端将无法解析. \ No newline at end of file diff --git a/global/config.go b/global/config.go index e41f7c4d..5f13ac40 100644 --- a/global/config.go +++ b/global/config.go @@ -6,19 +6,21 @@ import ( ) type JsonConfig struct { - Uin int64 `json:"uin"` - Password string `json:"password"` - EncryptPassword bool `json:"encrypt_password"` - PasswordEncrypted string `json:"password_encrypted"` - EnableDB bool `json:"enable_db"` - AccessToken string `json:"access_token"` - ReLogin bool `json:"relogin"` - ReLoginDelay int `json:"relogin_delay"` - HttpConfig *GoCQHttpConfig `json:"http_config"` - WSConfig *GoCQWebsocketConfig `json:"ws_config"` - ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"` - PostMessageFormat string `json:"post_message_format"` - Debug bool `json:"debug"` + Uin int64 `json:"uin"` + Password string `json:"password"` + EncryptPassword bool `json:"encrypt_password"` + PasswordEncrypted string `json:"password_encrypted"` + EnableDB bool `json:"enable_db"` + AccessToken string `json:"access_token"` + ReLogin bool `json:"relogin"` + ReLoginDelay int `json:"relogin_delay"` + IgnoreInvalidCQCode bool `json:"ignore_invalid_cqcode"` + ForceFragmented bool `json:"force_fragmented"` + HttpConfig *GoCQHttpConfig `json:"http_config"` + WSConfig *GoCQWebsocketConfig `json:"ws_config"` + ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"` + PostMessageFormat string `json:"post_message_format"` + Debug bool `json:"debug"` } type CQHttpApiConfig struct { @@ -68,6 +70,7 @@ func DefaultConfig() *JsonConfig { ReLogin: true, ReLoginDelay: 3, PostMessageFormat: "string", + ForceFragmented: true, HttpConfig: &GoCQHttpConfig{ Enabled: true, Host: "0.0.0.0", diff --git a/main.go b/main.go index 4410f007..b45d6e3e 100644 --- a/main.go +++ b/main.go @@ -220,6 +220,8 @@ func main() { } else { coolq.SetMessageFormat(conf.PostMessageFormat) } + coolq.IgnoreInvalidCQCode = conf.IgnoreInvalidCQCode + coolq.ForceFragmented = conf.ForceFragmented if conf.HttpConfig != nil && conf.HttpConfig.Enabled { server.HttpServer.Run(fmt.Sprintf("%s:%d", conf.HttpConfig.Host, conf.HttpConfig.Port), conf.AccessToken, b) for k, v := range conf.HttpConfig.PostUrls { From 174ebfae9db41dc32dac181355b8745ddc2473dc Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Tue, 25 Aug 2020 20:18:18 +0800 Subject: [PATCH 04/23] update MiraiGo. --- go.mod | 2 +- go.sum | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 6694dd69..426ba6ca 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp go 1.14 require ( - github.com/Mrs4s/MiraiGo v0.0.0-20200824170850-16fc454f752b + github.com/Mrs4s/MiraiGo v0.0.0-20200825052841-d3b0f5f9e839 github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/gin-gonic/gin v1.6.3 github.com/gorilla/websocket v1.4.2 diff --git a/go.sum b/go.sum index 148c90ae..ef1cb9a4 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Mrs4s/MiraiGo v0.0.0-20200824164833-834baa5b6b58 h1:bQDlJSgZmQh9fOMF7yWwL6w2HDm2YUmJlW871WQ404U= -github.com/Mrs4s/MiraiGo v0.0.0-20200824164833-834baa5b6b58/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM= -github.com/Mrs4s/MiraiGo v0.0.0-20200824170850-16fc454f752b h1:dYpx9kjDmSCVyu0Mr86GDou0Wz5iXYcMwYL52G5wz70= -github.com/Mrs4s/MiraiGo v0.0.0-20200824170850-16fc454f752b/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM= +github.com/Mrs4s/MiraiGo v0.0.0-20200825052841-d3b0f5f9e839 h1:TDhaPfWcubIMKDz1HU+N07SwIUjj7oVUQ7EXZBbDUxs= +github.com/Mrs4s/MiraiGo v0.0.0-20200825052841-d3b0f5f9e839/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM= github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0= github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= From fe7a1f502818399678ea21eb27de1c84e8706c7e Mon Sep 17 00:00:00 2001 From: F0ur Date: Wed, 26 Aug 2020 14:30:41 +0800 Subject: [PATCH 05/23] fix(ws): fix concurrent write to ws conn --- server/websocket.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/websocket.go b/server/websocket.go index 8dab69a1..7f0cae6a 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -319,6 +319,7 @@ func (s *websocketServer) onBotPushEvent(m coolq.MSG) { for i, l := 0, len(s.eventConn); i < l; i++ { conn := s.eventConn[i] log.Debugf("向WS客户端 %v 推送Event: %v", conn.RemoteAddr().String(), m.ToJson()) + conn.Lock() if err := conn.WriteMessage(websocket.TextMessage, []byte(m.ToJson())); err != nil { _ = conn.Close() next := i + 1 @@ -330,7 +331,9 @@ func (s *websocketServer) onBotPushEvent(m coolq.MSG) { i-- l-- conn = nil + continue } + conn.Unlock() } } From 01988cd3d76979fd3b936434a6eb00ea7399a3d7 Mon Sep 17 00:00:00 2001 From: xuthus5 Date: Thu, 27 Aug 2020 01:21:22 +0800 Subject: [PATCH 06/23] add:errlog file; fix:show version when start program --- .github/workflows/release.yml | 2 +- coolq/api.go | 4 ++-- docs/config.md | 1 + global/config.go | 1 + go.mod | 1 + go.sum | 18 +++++++++++++++ main.go | 41 +++++++++++++++++++++++++++++++++++ 7 files changed, 65 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 888004fe..48c5184f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,5 +26,5 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} goos: ${{ matrix.goos }} goarch: ${{ matrix.goarch }} - ldflags: -w -s -X "github.com/Mrs4s/go-cqhttp/coolq.version=${{ env.RELEASE_VERSION }}" + ldflags: -w -s -X "github.com/Mrs4s/go-cqhttp/coolq.Version=${{ env.RELEASE_VERSION }}" \ No newline at end of file diff --git a/coolq/api.go b/coolq/api.go index ea4aefae..6be70e9c 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -16,7 +16,7 @@ import ( "github.com/tidwall/gjson" ) -var version = "unknown" +var Version = "unknown" // https://cqhttp.cc/docs/4.15/#/API?id=get_login_info-%E8%8E%B7%E5%8F%96%E7%99%BB%E5%BD%95%E5%8F%B7%E4%BF%A1%E6%81%AF func (bot *CQBot) CQGetLoginInfo() MSG { @@ -590,7 +590,7 @@ func (bot *CQBot) CQGetVersionInfo() MSG { "plugin_build_configuration": "release", "runtime_version": runtime.Version(), "runtime_os": runtime.GOOS, - "version": version, + "version": Version, }) } diff --git a/docs/config.md b/docs/config.md index 245800f7..d3f0373c 100644 --- a/docs/config.md +++ b/docs/config.md @@ -67,6 +67,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为: | http_config | object | HTTP API配置 | | ws_config | object | Websocket API 配置 | | ws_reverse_servers | object[] | 反向 Websocket API 配置 | +| log_level | string | 指定日志收集级别,将收集的日志单独存放到固定文件中,便于查看日志线索 当前支持 warn,error| > 注: 开启密码加密后程序将在每次启动时要求输入解密密钥, 密钥错误会导致登录时提示密码错误. > 解密后密码将储存在内存中,用于自动重连等功能. 所以此加密并不能防止内存读取. diff --git a/global/config.go b/global/config.go index 5f13ac40..e3841370 100644 --- a/global/config.go +++ b/global/config.go @@ -21,6 +21,7 @@ type JsonConfig struct { ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"` PostMessageFormat string `json:"post_message_format"` Debug bool `json:"debug"` + LogLevel string `json:"log_level"` } type CQHttpApiConfig struct { diff --git a/go.mod b/go.mod index 426ba6ca..c227ae13 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible github.com/lestrrat-go/strftime v1.0.1 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 github.com/sirupsen/logrus v1.6.0 github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 github.com/tebeka/strftime v0.1.5 // indirect diff --git a/go.sum b/go.sum index ef1cb9a4..49aaf0a2 100644 --- a/go.sum +++ b/go.sum @@ -7,15 +7,18 @@ github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/ 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= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/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/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do= github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= +github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= @@ -42,16 +45,21 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/guonaihong/gout v0.1.1 h1:2i3eqQ1KUhTlj7AFeIHqVUFku5QwUhwE2wNgYTVpbxQ= github.com/guonaihong/gout v0.1.1/go.mod h1:vXvv5Kxr70eM5wrp4F0+t9lnLWmq+YPW2GByll2f/EA= +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.0 h1:J2SLSdy7HgElq8ekSl2Mxh6vrRNFxqbXGenYH2I02Vs= github.com/jonboulle/clockwork v0.2.0/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 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= @@ -59,6 +67,7 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxv github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8= github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is= github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible h1:4mNlp+/SvALIPFpbXV3kxNJJno9iKFWGxSDE13Kl66Q= github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA= @@ -67,15 +76,20 @@ github.com/lestrrat-go/strftime v1.0.1/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR7 github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnHyvtYjDeq0zlVHn9K/ZXoy17ylucdo= +github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5HgEKCvEIIrSpFI3ozzG5xOKA2DVlEX/gGnewM= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= @@ -83,9 +97,11 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 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.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc= github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= @@ -136,6 +152,7 @@ golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -155,6 +172,7 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= diff --git a/main.go b/main.go index b45d6e3e..22740c3f 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( "github.com/Mrs4s/go-cqhttp/global" "github.com/Mrs4s/go-cqhttp/server" rotatelogs "github.com/lestrrat-go/file-rotatelogs" + "github.com/rifflock/lfshook" log "github.com/sirupsen/logrus" easy "github.com/t-tomalak/logrus-easy-formatter" asciiart "github.com/yinghau76/go-ascii-art" @@ -133,6 +134,46 @@ func main() { time.Sleep(time.Second * 5) return } + + // log classified by level + // Collect all records up to the specified level (default level: warn) + logLevel := conf.LogLevel + if logLevel != "" { + date := time.Now().Format("2006-01-02") + var logPathMap lfshook.PathMap + switch conf.LogLevel { + case "warn": + logPathMap = lfshook.PathMap{ + log.WarnLevel: path.Join("logs", date+"-warn.log"), + log.ErrorLevel: path.Join("logs", date+"-warn.log"), + log.FatalLevel: path.Join("logs", date+"-warn.log"), + log.PanicLevel: path.Join("logs", date+"-warn.log"), + } + case "error": + logPathMap = lfshook.PathMap{ + log.ErrorLevel: path.Join("logs", date+"-error.log"), + log.FatalLevel: path.Join("logs", date+"-error.log"), + log.PanicLevel: path.Join("logs", date+"-error.log"), + } + default: + logPathMap = lfshook.PathMap{ + log.WarnLevel: path.Join("logs", date+"-warn.log"), + log.ErrorLevel: path.Join("logs", date+"-warn.log"), + log.FatalLevel: path.Join("logs", date+"-warn.log"), + log.PanicLevel: path.Join("logs", date+"-warn.log"), + } + } + + log.AddHook(lfshook.NewHook( + logPathMap, + &easy.Formatter{ + TimestampFormat: "2006-01-02 15:04:05", + LogFormat: "[%time%] [%lvl%]: %msg% \n", + }, + )) + } + + log.Info("当前版本:", coolq.Version) if conf.Debug { log.SetLevel(log.DebugLevel) log.Warnf("已开启Debug模式.") From 46747354c853f222112e038a8cfd7175d778d335 Mon Sep 17 00:00:00 2001 From: yyuueexxiinngg Date: Thu, 27 Aug 2020 01:59:02 +0800 Subject: [PATCH 07/23] Match netease music app id --- coolq/cqcode.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 726129d7..faa9f7ef 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -473,7 +473,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message. if info.Get("artists.0").Exists() { artistName = info.Get("artists.0.name").Str } - xml := fmt.Sprintf(``, + xml := fmt.Sprintf(``, name, d["id"], info.Get("album.picUrl").Str, d["id"], name, artistName) return &message.ServiceElement{ Id: 60, From 11592c44831df0e1932e0bef189127292ca314fc Mon Sep 17 00:00:00 2001 From: QianjuNakasumi Date: Thu, 27 Aug 2020 23:15:37 +0800 Subject: [PATCH 08/23] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=BF=83=E8=B7=B3=E6=9C=8D=E5=8A=A1=E9=97=B4=E9=9A=94?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=8F=8A=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coolq/bot.go | 38 +++++++++++++++++++++++--------------- docs/config.md | 6 +++++- global/config.go | 3 +++ 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/coolq/bot.go b/coolq/bot.go index 6f36aa2c..1aca7938 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -5,28 +5,31 @@ import ( "encoding/gob" "encoding/json" "fmt" - "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" - "github.com/tidwall/gjson" - "github.com/xujiajun/nutsdb" "hash/crc32" "path" "sync" "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" + "github.com/tidwall/gjson" + "github.com/xujiajun/nutsdb" ) type CQBot struct { Client *client.QQClient - events []func(MSG) - db *nutsdb.DB - friendReqCache sync.Map - invitedReqCache sync.Map - joinReqCache sync.Map - tempMsgCache sync.Map + events []func(MSG) + db *nutsdb.DB + heartbeatInterval uint16 + friendReqCache sync.Map + invitedReqCache sync.Map + joinReqCache sync.Map + tempMsgCache sync.Map } type MSG map[string]interface{} @@ -67,15 +70,20 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot { bot.Client.OnGroupInvited(bot.groupInvitedEvent) bot.Client.OnUserWantJoinGroup(bot.groupJoinReqEvent) go func() { + i := conf.HeartbeatInterval + if i < 1 { + log.Warn("警告: 心跳功能已关闭,若非预期,请检查配置文件。") + return + } for { - time.Sleep(time.Second * 5) + time.Sleep(time.Second * i) bot.dispatchEventMessage(MSG{ "time": time.Now().Unix(), "self_id": bot.Client.Uin, "post_type": "meta_event", "meta_event_type": "heartbeat", "status": nil, - "interval": 5000, + "interval": 1000 * i, }) } }() diff --git a/docs/config.md b/docs/config.md index d3f0373c..eb27e6d5 100644 --- a/docs/config.md +++ b/docs/config.md @@ -27,6 +27,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为: "post_message_format": "string", "ignore_invalid_cqcode": false, "force_fragmented": true, + "heartbeat_interval": 5, "http_config": { "enabled": true, "host": "0.0.0.0", @@ -64,6 +65,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为: | post_message_format | string | 上报信息类型 | | ignore_invalid_cqcode| bool | 是否忽略错误的CQ码 | | force_fragmented | bool | 是否强制分片发送群长消息 | +| heartbeat_interval | int64 | 心跳间隔时间,单位秒,若0则关闭心跳 | http_config | object | HTTP API配置 | | ws_config | object | Websocket API 配置 | | ws_reverse_servers | object[] | 反向 Websocket API 配置 | @@ -73,4 +75,6 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为: > 解密后密码将储存在内存中,用于自动重连等功能. 所以此加密并不能防止内存读取. > 解密密钥在使用完成后并不会留存在内存中, 所以可用相对简单的字符串作为密钥 -> 注2: 分片发送为原酷Q发送长消息的老方案, 发送速度更优/兼容性更好。关闭后将优先使用新方案, 能发送更长的消息, 但发送速度更慢,在部分老客户端将无法解析. \ No newline at end of file +> 注2: 分片发送为原酷Q发送长消息的老方案, 发送速度更优/兼容性更好。关闭后将优先使用新方案, 能发送更长的消息, 但发送速度更慢,在部分老客户端将无法解析. + +> 注3:关闭心跳服务可能引起断线,请谨慎关闭 \ No newline at end of file diff --git a/global/config.go b/global/config.go index e3841370..bd57850e 100644 --- a/global/config.go +++ b/global/config.go @@ -2,6 +2,8 @@ package global import ( "encoding/json" + "time" + log "github.com/sirupsen/logrus" ) @@ -16,6 +18,7 @@ type JsonConfig struct { ReLoginDelay int `json:"relogin_delay"` IgnoreInvalidCQCode bool `json:"ignore_invalid_cqcode"` ForceFragmented bool `json:"force_fragmented"` + HeartbeatInterval time.Duration `json:"heartbeat_interval"` HttpConfig *GoCQHttpConfig `json:"http_config"` WSConfig *GoCQWebsocketConfig `json:"ws_config"` ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"` From 41614b9d1617c2a6e64830d19fc9cb53aeda4c3d Mon Sep 17 00:00:00 2001 From: QianjuNakasumi Date: Thu, 27 Aug 2020 23:20:45 +0800 Subject: [PATCH 09/23] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=BF=83=E8=B7=B3?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E9=97=B4=E9=9A=94=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/config.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/config.md b/docs/config.md index eb27e6d5..7ee7c56b 100644 --- a/docs/config.md +++ b/docs/config.md @@ -56,18 +56,18 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为: | ------------------ | -------- | ------------------------------------------------------------------- | | uin | int64 | 登录用QQ号 | | password | string | 登录用密码 | -| encrypt_password | bool | 是否对密码进行加密. | +| encrypt_password | bool | 是否对密码进行加密. | | password_encrypted | string | 加密后的密码(请勿修改) | -| enable_db | bool | 是否开启内置数据库, 关闭后将无法使用 **回复/撤回** 等上下文相关接口 | -| access_token | string | 同CQHTTP的 `access_token` 用于身份验证 | -| relogin | bool | 是否自动重新登录 | -| relogin_delay | int | 重登录延时(秒) | -| post_message_format | string | 上报信息类型 | -| ignore_invalid_cqcode| bool | 是否忽略错误的CQ码 | +| enable_db | bool | 是否开启内置数据库, 关闭后将无法使用 **回复/撤回** 等上下文相关接口 | +| access_token | string | 同CQHTTP的 `access_token` 用于身份验证 | +| relogin | bool | 是否自动重新登录 | +| relogin_delay | int | 重登录延时(秒) | +| post_message_format | string | 上报信息类型 | +| ignore_invalid_cqcode| bool | 是否忽略错误的CQ码 | | force_fragmented | bool | 是否强制分片发送群长消息 | -| heartbeat_interval | int64 | 心跳间隔时间,单位秒,若0则关闭心跳 -| http_config | object | HTTP API配置 | -| ws_config | object | Websocket API 配置 | +| heartbeat_interval | int64 | 心跳间隔时间,单位秒,若0则关闭心跳 | +| http_config | object | HTTP API配置 | +| ws_config | object | Websocket API 配置 | | ws_reverse_servers | object[] | 反向 Websocket API 配置 | | log_level | string | 指定日志收集级别,将收集的日志单独存放到固定文件中,便于查看日志线索 当前支持 warn,error| From 50191fcedf4c9cf5b5ff801ca6b923ebb75407a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=83=E6=A9=98=E9=9B=AB=E9=9C=9E?= <53565118+qianjunakasumi@users.noreply.github.com> Date: Thu, 27 Aug 2020 23:29:10 +0800 Subject: [PATCH 10/23] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E7=9A=84=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coolq/bot.go | 1 - 1 file changed, 1 deletion(-) diff --git a/coolq/bot.go b/coolq/bot.go index 1aca7938..d27ff7bb 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -25,7 +25,6 @@ type CQBot struct { events []func(MSG) db *nutsdb.DB - heartbeatInterval uint16 friendReqCache sync.Map invitedReqCache sync.Map joinReqCache sync.Map From 0e7c30e85452854aff7822be168c095089b913e5 Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Thu, 27 Aug 2020 23:51:38 +0800 Subject: [PATCH 11/23] fix image error. --- coolq/cqcode.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index faa9f7ef..4e3a1a4e 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -367,12 +367,18 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message. if group { rsp, err := bot.Client.QueryGroupImage(1, hash, size) if err != nil { + if url != "" { + return bot.ToElement(t, map[string]string{"file": url}, group) + } return nil, err } return rsp, nil } rsp, err := bot.Client.QueryFriendImage(1, hash, size) if err != nil { + if url != "" { + return bot.ToElement(t, map[string]string{"file": url}, group) + } return nil, err } return rsp, nil From 04bcd2e2701625d3f2837c558786a7acd2f78ef0 Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Fri, 28 Aug 2020 00:27:40 +0800 Subject: [PATCH 12/23] supported one-way friend msg. close #98 --- coolq/bot.go | 28 ++++++++++++++++------------ coolq/event.go | 3 +++ go.mod | 2 +- go.sum | 2 ++ 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/coolq/bot.go b/coolq/bot.go index d27ff7bb..6d34bda4 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -23,12 +23,13 @@ import ( type CQBot struct { Client *client.QQClient - events []func(MSG) - db *nutsdb.DB - friendReqCache sync.Map - invitedReqCache sync.Map - joinReqCache sync.Map - tempMsgCache sync.Map + events []func(MSG) + db *nutsdb.DB + friendReqCache sync.Map + invitedReqCache sync.Map + joinReqCache sync.Map + tempMsgCache sync.Map + oneWayMsgCache sync.Map } type MSG map[string]interface{} @@ -166,12 +167,15 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in if msg != nil { id = msg.Id } - } else { - if code, ok := bot.tempMsgCache.Load(target); ok { - msg := bot.Client.SendTempMessage(code.(int64), target, m) - if msg != nil { - id = msg.Id - } + } else if code, ok := bot.tempMsgCache.Load(target); ok { + msg := bot.Client.SendTempMessage(code.(int64), target, m) + if msg != nil { + id = msg.Id + } + } else if _, ok := bot.oneWayMsgCache.Load(target); ok { + msg := bot.Client.SendPrivateMessage(target, m) + if msg != nil { + id = msg.Id } } if id == -1 { diff --git a/coolq/event.go b/coolq/event.go index 142e0960..e91a0ed8 100644 --- a/coolq/event.go +++ b/coolq/event.go @@ -32,6 +32,9 @@ func ToFormattedMessage(e []message.IMessageElement, code int64, raw ...bool) (r func (bot *CQBot) privateMessageEvent(c *client.QQClient, m *message.PrivateMessage) { bot.checkMedia(m.Elements) cqm := ToStringMessage(m.Elements, 0, true) + if !m.Sender.IsFriend { + bot.oneWayMsgCache.Store(m.Sender.Uin, "") + } log.Infof("收到好友 %v(%v) 的消息: %v", m.Sender.DisplayName(), m.Sender.Uin, cqm) fm := MSG{ "post_type": "message", diff --git a/go.mod b/go.mod index c227ae13..017cc9d5 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp go 1.14 require ( - github.com/Mrs4s/MiraiGo v0.0.0-20200825052841-d3b0f5f9e839 + github.com/Mrs4s/MiraiGo v0.0.0-20200827162217-d7e61afdfe07 github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/gin-gonic/gin v1.6.3 github.com/gorilla/websocket v1.4.2 diff --git a/go.sum b/go.sum index 49aaf0a2..7d781a61 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Mrs4s/MiraiGo v0.0.0-20200825052841-d3b0f5f9e839 h1:TDhaPfWcubIMKDz1HU+N07SwIUjj7oVUQ7EXZBbDUxs= github.com/Mrs4s/MiraiGo v0.0.0-20200825052841-d3b0f5f9e839/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM= +github.com/Mrs4s/MiraiGo v0.0.0-20200827162217-d7e61afdfe07 h1:AO8HeAS3GbUIfLQHlM7sPfYYN/KsKUpTTB+gVZNvo30= +github.com/Mrs4s/MiraiGo v0.0.0-20200827162217-d7e61afdfe07/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM= github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0= github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= From cefbfb64ce19253d27d0f3e3497aa7d330eca9b2 Mon Sep 17 00:00:00 2001 From: Mrs4s <1844812067@qq.com> Date: Fri, 28 Aug 2020 02:32:27 +0800 Subject: [PATCH 13/23] update MiraiGo. fix #172 --- coolq/cqcode.go | 2 +- go.mod | 2 +- go.sum | 22 ++-------------------- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 4e3a1a4e..40ce3c79 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -458,7 +458,7 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message. if len(aid) < 2 { return nil, errors.New("song error") } - xml := fmt.Sprintf(``, + xml := fmt.Sprintf(``, name, d["id"], aid[:len(aid)-2], aid, name, "", info.Get("track_info.singer.name").Str) return &message.ServiceElement{ Id: 60, diff --git a/go.mod b/go.mod index 017cc9d5..d32cd0fd 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp go 1.14 require ( - github.com/Mrs4s/MiraiGo v0.0.0-20200827162217-d7e61afdfe07 + github.com/Mrs4s/MiraiGo v0.0.0-20200827182935-51e155ef20da github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/gin-gonic/gin v1.6.3 github.com/gorilla/websocket v1.4.2 diff --git a/go.sum b/go.sum index 7d781a61..3eeba5ca 100644 --- a/go.sum +++ b/go.sum @@ -1,26 +1,21 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Mrs4s/MiraiGo v0.0.0-20200825052841-d3b0f5f9e839 h1:TDhaPfWcubIMKDz1HU+N07SwIUjj7oVUQ7EXZBbDUxs= -github.com/Mrs4s/MiraiGo v0.0.0-20200825052841-d3b0f5f9e839/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM= -github.com/Mrs4s/MiraiGo v0.0.0-20200827162217-d7e61afdfe07 h1:AO8HeAS3GbUIfLQHlM7sPfYYN/KsKUpTTB+gVZNvo30= -github.com/Mrs4s/MiraiGo v0.0.0-20200827162217-d7e61afdfe07/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM= +github.com/Mrs4s/MiraiGo v0.0.0-20200827182935-51e155ef20da h1:T2Qz4w6sMrBxw+oiwbUa/c996jWYulCAtM+x1L0l3R8= +github.com/Mrs4s/MiraiGo v0.0.0-20200827182935-51e155ef20da/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM= github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0= github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE= 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= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/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/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do= github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= -github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= @@ -47,21 +42,16 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/guonaihong/gout v0.1.1 h1:2i3eqQ1KUhTlj7AFeIHqVUFku5QwUhwE2wNgYTVpbxQ= github.com/guonaihong/gout v0.1.1/go.mod h1:vXvv5Kxr70eM5wrp4F0+t9lnLWmq+YPW2GByll2f/EA= -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.0 h1:J2SLSdy7HgElq8ekSl2Mxh6vrRNFxqbXGenYH2I02Vs= github.com/jonboulle/clockwork v0.2.0/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 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= @@ -69,7 +59,6 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxv github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8= github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is= github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible h1:4mNlp+/SvALIPFpbXV3kxNJJno9iKFWGxSDE13Kl66Q= github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA= @@ -78,16 +67,13 @@ github.com/lestrrat-go/strftime v1.0.1/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR7 github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 h1:mZHayPoR0lNmnHyvtYjDeq0zlVHn9K/ZXoy17ylucdo= @@ -99,11 +85,9 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 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.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc= github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= @@ -154,7 +138,6 @@ golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -174,7 +157,6 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= From 027aeca622cdc838312dc34de603cf5c8aaa6152 Mon Sep 17 00:00:00 2001 From: ceerRep <895986658@qq.com> Date: Fri, 28 Aug 2020 15:02:53 +0800 Subject: [PATCH 14/23] Fix indent --- docs/config.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/config.md b/docs/config.md index 7ee7c56b..bda965c4 100644 --- a/docs/config.md +++ b/docs/config.md @@ -27,7 +27,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为: "post_message_format": "string", "ignore_invalid_cqcode": false, "force_fragmented": true, - "heartbeat_interval": 5, + "heartbeat_interval": 5, "http_config": { "enabled": true, "host": "0.0.0.0", @@ -77,4 +77,4 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为: > 注2: 分片发送为原酷Q发送长消息的老方案, 发送速度更优/兼容性更好。关闭后将优先使用新方案, 能发送更长的消息, 但发送速度更慢,在部分老客户端将无法解析. -> 注3:关闭心跳服务可能引起断线,请谨慎关闭 \ No newline at end of file +> 注3:关闭心跳服务可能引起断线,请谨慎关闭 From 4d376c05186a1498692982642f121b024606b7e0 Mon Sep 17 00:00:00 2001 From: QianjuNakasumi Date: Fri, 28 Aug 2020 23:46:29 +0800 Subject: [PATCH 15/23] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A4=9A=E6=AC=A1?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=87=8D=E8=BF=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/config.md | 8 ++++-- global/config.go | 32 +++++++++++++-------- main.go | 73 +++++++++++++++++++++++++++++------------------- 3 files changed, 72 insertions(+), 41 deletions(-) diff --git a/docs/config.md b/docs/config.md index 7ee7c56b..f6af0f81 100644 --- a/docs/config.md +++ b/docs/config.md @@ -22,8 +22,11 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为: "password_encrypted": "", "enable_db": true, "access_token": "", - "relogin": false, - "relogin_delay": 0, + "relogin": { + "enabled": true, + "relogin_delay": 3, + "max_relogin_times": 0 + }, "post_message_format": "string", "ignore_invalid_cqcode": false, "force_fragmented": true, @@ -62,6 +65,7 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为: | access_token | string | 同CQHTTP的 `access_token` 用于身份验证 | | relogin | bool | 是否自动重新登录 | | relogin_delay | int | 重登录延时(秒) | +| max_relogin_times | uint | 最大重登录次数,若0则不设置上限 | | post_message_format | string | 上报信息类型 | | ignore_invalid_cqcode| bool | 是否忽略错误的CQ码 | | force_fragmented | bool | 是否强制分片发送群长消息 | diff --git a/global/config.go b/global/config.go index bd57850e..a69f9734 100644 --- a/global/config.go +++ b/global/config.go @@ -8,14 +8,17 @@ import ( ) type JsonConfig struct { - Uin int64 `json:"uin"` - Password string `json:"password"` - EncryptPassword bool `json:"encrypt_password"` - PasswordEncrypted string `json:"password_encrypted"` - EnableDB bool `json:"enable_db"` - AccessToken string `json:"access_token"` - ReLogin bool `json:"relogin"` - ReLoginDelay int `json:"relogin_delay"` + Uin int64 `json:"uin"` + Password string `json:"password"` + EncryptPassword bool `json:"encrypt_password"` + PasswordEncrypted string `json:"password_encrypted"` + EnableDB bool `json:"enable_db"` + AccessToken string `json:"access_token"` + ReLogin struct { + Enabled bool `json:"enabled"` + ReLoginDelay int `json:"relogin_delay"` + MaxReloginTimes uint `json:"max_relogin_times"` + } `json:"relogin"` IgnoreInvalidCQCode bool `json:"ignore_invalid_cqcode"` ForceFragmented bool `json:"force_fragmented"` HeartbeatInterval time.Duration `json:"heartbeat_interval"` @@ -70,9 +73,16 @@ type GoCQReverseWebsocketConfig struct { func DefaultConfig() *JsonConfig { return &JsonConfig{ - EnableDB: true, - ReLogin: true, - ReLoginDelay: 3, + EnableDB: true, + ReLogin: struct { + Enabled bool `json:"enabled"` + ReLoginDelay int `json:"relogin_delay"` + MaxReloginTimes uint `json:"max_relogin_times"` + }{ + Enabled: true, + ReLoginDelay: 3, + MaxReloginTimes: 0, + }, PostMessageFormat: "string", ForceFragmented: true, HttpConfig: &GoCQHttpConfig{ diff --git a/main.go b/main.go index 22740c3f..f5eae475 100644 --- a/main.go +++ b/main.go @@ -7,16 +7,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "github.com/Mrs4s/MiraiGo/binary" - "github.com/Mrs4s/MiraiGo/client" - "github.com/Mrs4s/go-cqhttp/coolq" - "github.com/Mrs4s/go-cqhttp/global" - "github.com/Mrs4s/go-cqhttp/server" - rotatelogs "github.com/lestrrat-go/file-rotatelogs" - "github.com/rifflock/lfshook" - log "github.com/sirupsen/logrus" - easy "github.com/t-tomalak/logrus-easy-formatter" - asciiart "github.com/yinghau76/go-ascii-art" "image" "io" "io/ioutil" @@ -26,6 +16,18 @@ import ( "strconv" "strings" "time" + + "github.com/Mrs4s/MiraiGo/binary" + "github.com/Mrs4s/MiraiGo/client" + "github.com/Mrs4s/go-cqhttp/coolq" + "github.com/Mrs4s/go-cqhttp/global" + "github.com/Mrs4s/go-cqhttp/server" + + rotatelogs "github.com/lestrrat-go/file-rotatelogs" + "github.com/rifflock/lfshook" + log "github.com/sirupsen/logrus" + easy "github.com/t-tomalak/logrus-easy-formatter" + asciiart "github.com/yinghau76/go-ascii-art" ) func init() { @@ -144,7 +146,7 @@ func main() { switch conf.LogLevel { case "warn": logPathMap = lfshook.PathMap{ - log.WarnLevel: path.Join("logs", date+"-warn.log"), + log.WarnLevel: path.Join("logs", date+"-warn.log"), log.ErrorLevel: path.Join("logs", date+"-warn.log"), log.FatalLevel: path.Join("logs", date+"-warn.log"), log.PanicLevel: path.Join("logs", date+"-warn.log"), @@ -157,7 +159,7 @@ func main() { } default: logPathMap = lfshook.PathMap{ - log.WarnLevel: path.Join("logs", date+"-warn.log"), + log.WarnLevel: path.Join("logs", date+"-warn.log"), log.ErrorLevel: path.Join("logs", date+"-warn.log"), log.FatalLevel: path.Join("logs", date+"-warn.log"), log.PanicLevel: path.Join("logs", date+"-warn.log"), @@ -278,24 +280,39 @@ func main() { log.Info("资源初始化完成, 开始处理信息.") log.Info("アトリは、高性能ですから!") cli.OnDisconnected(func(bot *client.QQClient, e *client.ClientDisconnectedEvent) { - if conf.ReLogin { - log.Warnf("Bot已离线 (%v),将在 %v 秒后尝试重连.", e.Message, conf.ReLoginDelay) - time.Sleep(time.Second * time.Duration(conf.ReLoginDelay)) - rsp, err := cli.Login() - if err != nil { - log.Fatalf("重连失败: %v", err) - } - if !rsp.Success { - switch rsp.Error { - case client.NeedCaptcha: - log.Fatalf("重连失败: 需要验证码. (验证码处理正在开发中)") - case client.UnsafeDeviceError: - log.Fatalf("重连失败: 设备锁") - default: - log.Fatalf("重连失败: %v", rsp.ErrorMessage) + if conf.ReLogin.Enabled { + var times uint = 1 + for { + + if conf.ReLogin.MaxReloginTimes == 0 { + } else if times > conf.ReLogin.MaxReloginTimes { + break } + log.Warnf("Bot已离线 (%v),将在 %v 秒后尝试重连. 重连次数:%v", + e.Message, conf.ReLogin.ReLoginDelay, times) + times++ + time.Sleep(time.Second * time.Duration(conf.ReLogin.ReLoginDelay)) + rsp, err := cli.Login() + if err != nil { + log.Errorf("重连失败: %v", err) + continue + } + if !rsp.Success { + switch rsp.Error { + case client.NeedCaptcha: + log.Fatalf("重连失败: 需要验证码. (验证码处理正在开发中)") + case client.UnsafeDeviceError: + log.Fatalf("重连失败: 设备锁") + default: + log.Errorf("重连失败: %v", rsp.ErrorMessage) + continue + } + } + log.Info("重连成功") + return + } - return + log.Fatal("重连失败: 重连次数达到设置的上限值") } b.Release() log.Fatalf("Bot已离线:%v", e.Message) From 33120b249625061f15c19b601f43436bd72662d7 Mon Sep 17 00:00:00 2001 From: Ink33 <51873347+Ink-33@users.noreply.github.com> Date: Sat, 29 Aug 2020 16:44:31 +0800 Subject: [PATCH 16/23] Update websocket.go --- server/websocket.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/websocket.go b/server/websocket.go index 7f0cae6a..bc917e9a 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -206,7 +206,7 @@ func (c *websocketClient) onBotPushEvent(m coolq.MSG) { func (s *websocketServer) event(w http.ResponseWriter, r *http.Request) { if s.token != "" { - if r.URL.Query().Get("access_token") != s.token && strings.SplitN(r.Header.Get("Authorization"), " ", 2)[1] != s.token { + if r.URL.Query().Get("access_token") != s.token || strings.SplitN(r.Header.Get("Authorization"), " ", 2)[1] != s.token { log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) w.WriteHeader(401) return @@ -235,7 +235,7 @@ func (s *websocketServer) event(w http.ResponseWriter, r *http.Request) { func (s *websocketServer) api(w http.ResponseWriter, r *http.Request) { if s.token != "" { - if r.URL.Query().Get("access_token") != s.token && strings.SplitN(r.Header.Get("Authorization"), " ", 2)[1] != s.token { + if r.URL.Query().Get("access_token") != s.token || strings.SplitN(r.Header.Get("Authorization"), " ", 2)[1] != s.token { log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) w.WriteHeader(401) return @@ -253,7 +253,7 @@ func (s *websocketServer) api(w http.ResponseWriter, r *http.Request) { func (s *websocketServer) any(w http.ResponseWriter, r *http.Request) { if s.token != "" { - if r.URL.Query().Get("access_token") != s.token && strings.SplitN(r.Header.Get("Authorization"), " ", 2)[1] != s.token { + if r.URL.Query().Get("access_token") != s.token || strings.SplitN(r.Header.Get("Authorization"), " ", 2)[1] != s.token { log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) w.WriteHeader(401) return From d0398f30c6c40cc934501db468ff1857ba75c937 Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Sat, 29 Aug 2020 17:06:25 +0800 Subject: [PATCH 17/23] Revert "Update websocket.go" This reverts commit 33120b249625061f15c19b601f43436bd72662d7. revert --- server/websocket.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/websocket.go b/server/websocket.go index bc917e9a..7f0cae6a 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -206,7 +206,7 @@ func (c *websocketClient) onBotPushEvent(m coolq.MSG) { func (s *websocketServer) event(w http.ResponseWriter, r *http.Request) { if s.token != "" { - if r.URL.Query().Get("access_token") != s.token || strings.SplitN(r.Header.Get("Authorization"), " ", 2)[1] != s.token { + if r.URL.Query().Get("access_token") != s.token && strings.SplitN(r.Header.Get("Authorization"), " ", 2)[1] != s.token { log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) w.WriteHeader(401) return @@ -235,7 +235,7 @@ func (s *websocketServer) event(w http.ResponseWriter, r *http.Request) { func (s *websocketServer) api(w http.ResponseWriter, r *http.Request) { if s.token != "" { - if r.URL.Query().Get("access_token") != s.token || strings.SplitN(r.Header.Get("Authorization"), " ", 2)[1] != s.token { + if r.URL.Query().Get("access_token") != s.token && strings.SplitN(r.Header.Get("Authorization"), " ", 2)[1] != s.token { log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) w.WriteHeader(401) return @@ -253,7 +253,7 @@ func (s *websocketServer) api(w http.ResponseWriter, r *http.Request) { func (s *websocketServer) any(w http.ResponseWriter, r *http.Request) { if s.token != "" { - if r.URL.Query().Get("access_token") != s.token || strings.SplitN(r.Header.Get("Authorization"), " ", 2)[1] != s.token { + if r.URL.Query().Get("access_token") != s.token && strings.SplitN(r.Header.Get("Authorization"), " ", 2)[1] != s.token { log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) w.WriteHeader(401) return From 9c65ff4dcd86e1d67dd3f8d3b7a36761c67d7bd1 Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Sat, 29 Aug 2020 17:24:09 +0800 Subject: [PATCH 18/23] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=AD=A3=E5=90=91WebSocket=E4=B8=8B=E7=9A=84=E9=89=B4=E6=9D=83?= =?UTF-8?q?panic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/websocket.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/server/websocket.go b/server/websocket.go index 7f0cae6a..5887d8a7 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -206,10 +206,16 @@ func (c *websocketClient) onBotPushEvent(m coolq.MSG) { func (s *websocketServer) event(w http.ResponseWriter, r *http.Request) { if s.token != "" { - if r.URL.Query().Get("access_token") != s.token && strings.SplitN(r.Header.Get("Authorization"), " ", 2)[1] != s.token { + if r.URL.Query().Get("access_token") != s.token { log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) w.WriteHeader(401) return + } else if auth := r.Header.Get("Authorization"); auth != "" { + if strings.SplitN(auth, " ", 2)[1] != s.token { + log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) + w.WriteHeader(401) + return + } } } c, err := upgrader.Upgrade(w, r, nil) @@ -235,10 +241,16 @@ func (s *websocketServer) event(w http.ResponseWriter, r *http.Request) { func (s *websocketServer) api(w http.ResponseWriter, r *http.Request) { if s.token != "" { - if r.URL.Query().Get("access_token") != s.token && strings.SplitN(r.Header.Get("Authorization"), " ", 2)[1] != s.token { + if r.URL.Query().Get("access_token") != s.token { log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) w.WriteHeader(401) return + } else if auth := r.Header.Get("Authorization"); auth != "" { + if strings.SplitN(auth, " ", 2)[1] != s.token { + log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) + w.WriteHeader(401) + return + } } } c, err := upgrader.Upgrade(w, r, nil) @@ -253,10 +265,16 @@ func (s *websocketServer) api(w http.ResponseWriter, r *http.Request) { func (s *websocketServer) any(w http.ResponseWriter, r *http.Request) { if s.token != "" { - if r.URL.Query().Get("access_token") != s.token && strings.SplitN(r.Header.Get("Authorization"), " ", 2)[1] != s.token { + if r.URL.Query().Get("access_token") != s.token { log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) w.WriteHeader(401) return + } else if auth := r.Header.Get("Authorization"); auth != "" { + if strings.SplitN(auth, " ", 2)[1] != s.token { + log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) + w.WriteHeader(401) + return + } } } c, err := upgrader.Upgrade(w, r, nil) From f5692253050c9ed0fd36557b5d73d515d6b30b3c Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Sat, 29 Aug 2020 17:49:40 +0800 Subject: [PATCH 19/23] =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E5=90=8E=E5=A4=87=E4=BB=BD=E6=BA=90=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=20=E9=85=8D=E7=BD=AE=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E5=8D=87=E7=BA=A7=E4=B8=8D=E5=A4=87=E4=BB=BD=EF=BC=8C?= =?UTF-8?q?=E6=88=91=E9=85=8D=E7=BD=AE=E6=B2=A1=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- global/config.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/global/config.go b/global/config.go index a69f9734..07ba2095 100644 --- a/global/config.go +++ b/global/config.go @@ -2,6 +2,8 @@ package global import ( "encoding/json" + "os" + "strconv" "time" log "github.com/sirupsen/logrus" @@ -117,6 +119,8 @@ func Load(p string) *JsonConfig { err := json.Unmarshal([]byte(ReadAllText(p)), &c) if err != nil { log.Warnf("尝试加载配置文件 %v 时出现错误: %v", p, err) + log.Infoln("原文件已备份") + os.Rename(p, p+".backup"+strconv.FormatInt(time.Now().Unix(), 10)) return nil } return &c From 804bd9a711ee5f4d562cadf5956a69092653450b Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Sat, 29 Aug 2020 17:54:39 +0800 Subject: [PATCH 20/23] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 10 ++++++---- go.sum | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index d32cd0fd..0c1dda96 100644 --- a/go.mod +++ b/go.mod @@ -7,18 +7,20 @@ require ( github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/gin-gonic/gin v1.6.3 github.com/gorilla/websocket v1.4.2 - github.com/guonaihong/gout v0.1.1 + github.com/guonaihong/gout v0.1.2 github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect github.com/jonboulle/clockwork v0.2.0 // indirect github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible - github.com/lestrrat-go/strftime v1.0.1 // indirect + github.com/lestrrat-go/strftime v1.0.3 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 github.com/sirupsen/logrus v1.6.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.0 + github.com/tidwall/gjson v1.6.1 github.com/xujiajun/nutsdb v0.5.0 github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189 - golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect + golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect + golang.org/x/sys v0.0.0-20200828194041-157a740278f4 // indirect + gopkg.in/yaml.v2 v2.3.0 // indirect ) diff --git a/go.sum b/go.sum index 3eeba5ca..95a0168e 100644 --- a/go.sum +++ b/go.sum @@ -49,6 +49,8 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/guonaihong/gout v0.1.1 h1:2i3eqQ1KUhTlj7AFeIHqVUFku5QwUhwE2wNgYTVpbxQ= github.com/guonaihong/gout v0.1.1/go.mod h1:vXvv5Kxr70eM5wrp4F0+t9lnLWmq+YPW2GByll2f/EA= +github.com/guonaihong/gout v0.1.2 h1:TR2XCRopGgJdj231IayEoeavgbznFXzzzcZVdT/hG10= +github.com/guonaihong/gout v0.1.2/go.mod h1:vXvv5Kxr70eM5wrp4F0+t9lnLWmq+YPW2GByll2f/EA= github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag= github.com/jonboulle/clockwork v0.2.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -64,6 +66,8 @@ github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible h1:4mNlp+/SvALIPFpbXV github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA= github.com/lestrrat-go/strftime v1.0.1 h1:o7qz5pmLzPDLyGW4lG6JvTKPUfTFXwe+vOamIYWtnVU= github.com/lestrrat-go/strftime v1.0.1/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g= +github.com/lestrrat-go/strftime v1.0.3 h1:qqOPU7y+TM8Y803I8fG9c/DyKG3xH/xkng6keC1015Q= +github.com/lestrrat-go/strftime v1.0.3/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g= github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= @@ -91,10 +95,14 @@ github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816/go github.com/tebeka/strftime v0.1.5/go.mod h1:29/OidkoWHdEKZqzyDLUyC+LmgDgdHo4WAFCDT7D/Ig= github.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc= github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= +github.com/tidwall/gjson v1.6.1 h1:LRbvNuNuvAiISWg6gxLEFuCe72UKy5hDqhxW/8183ws= +github.com/tidwall/gjson v1.6.1/go.mod h1:BaHyNc5bjzYkPqgLq7mdVzeiRtULKULXLgZFKsxEHI0= github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc= github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU= +github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= @@ -109,6 +117,7 @@ github.com/xujiajun/utils v0.0.0-20190123093513-8bf096c4f53b/go.mod h1:AZd87GYJl github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189 h1:4UJw9if55Fu3HOwbfcaQlJ27p3oeJU2JZqoeT3ITJQk= github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189/go.mod h1:rIrm5geMiBhPQkdfUm8gDFi/WiHneOp1i9KjmJqc+9I= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -117,8 +126,11 @@ golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -126,11 +138,15 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181221143128-b4a75ba826a6/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200828194041-157a740278f4 h1:kCCpuwSAoYJPkNc6x0xT9yTtV4oKtARo4RGBQWOfg9E= +golang.org/x/sys v0.0.0-20200828194041-157a740278f4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -163,5 +179,7 @@ gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWd gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From 047b5208f4f50a543a4a12a7646b5ae28551102a Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Sat, 29 Aug 2020 17:55:08 +0800 Subject: [PATCH 21/23] =?UTF-8?q?Builder=E6=9B=B4=E6=8D=A2=E4=B8=BA1.14.7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 62ddbbd5..478327d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.14.2-alpine AS builder +FROM golang:1.14.7-alpine AS builder RUN go env -w GO111MODULE=auto \ && go env -w CGO_ENABLED=0 \ From d35ad66adf1f27cbbe99108ba25c82a6b2b91879 Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Sat, 29 Aug 2020 20:24:11 +0800 Subject: [PATCH 22/23] =?UTF-8?q?=E6=8B=92=E7=BB=9D=E7=A9=BAToken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/websocket.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/server/websocket.go b/server/websocket.go index 5887d8a7..d3266651 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -206,7 +206,7 @@ func (c *websocketClient) onBotPushEvent(m coolq.MSG) { func (s *websocketServer) event(w http.ResponseWriter, r *http.Request) { if s.token != "" { - if r.URL.Query().Get("access_token") != s.token { + if auth := r.URL.Query().Get("access_token"); auth != s.token && auth != "" { log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) w.WriteHeader(401) return @@ -216,6 +216,10 @@ func (s *websocketServer) event(w http.ResponseWriter, r *http.Request) { w.WriteHeader(401) return } + } else { + log.Warnf("已拒绝 %v 的 Websocket 请求: 空Token", r.RemoteAddr) + w.WriteHeader(401) + return } } c, err := upgrader.Upgrade(w, r, nil) @@ -241,7 +245,7 @@ func (s *websocketServer) event(w http.ResponseWriter, r *http.Request) { func (s *websocketServer) api(w http.ResponseWriter, r *http.Request) { if s.token != "" { - if r.URL.Query().Get("access_token") != s.token { + if auth := r.URL.Query().Get("access_token"); auth != s.token && auth != "" { log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) w.WriteHeader(401) return @@ -251,6 +255,10 @@ func (s *websocketServer) api(w http.ResponseWriter, r *http.Request) { w.WriteHeader(401) return } + } else { + log.Warnf("已拒绝 %v 的 Websocket 请求: 空Token", r.RemoteAddr) + w.WriteHeader(401) + return } } c, err := upgrader.Upgrade(w, r, nil) @@ -265,7 +273,7 @@ func (s *websocketServer) api(w http.ResponseWriter, r *http.Request) { func (s *websocketServer) any(w http.ResponseWriter, r *http.Request) { if s.token != "" { - if r.URL.Query().Get("access_token") != s.token { + if auth := r.URL.Query().Get("access_token"); auth != s.token && auth != "" { log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) w.WriteHeader(401) return @@ -275,6 +283,10 @@ func (s *websocketServer) any(w http.ResponseWriter, r *http.Request) { w.WriteHeader(401) return } + } else { + log.Warnf("已拒绝 %v 的 Websocket 请求: 空Token", r.RemoteAddr) + w.WriteHeader(401) + return } } c, err := upgrader.Upgrade(w, r, nil) From 1f7c4cab5072959d24f68c1ebd77524fdfc0c31b Mon Sep 17 00:00:00 2001 From: Ink-33 Date: Sat, 29 Aug 2020 22:24:53 +0800 Subject: [PATCH 23/23] Update --- server/websocket.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/server/websocket.go b/server/websocket.go index d3266651..5c04d52b 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -210,14 +210,14 @@ func (s *websocketServer) event(w http.ResponseWriter, r *http.Request) { log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) w.WriteHeader(401) return - } else if auth := r.Header.Get("Authorization"); auth != "" { - if strings.SplitN(auth, " ", 2)[1] != s.token { + } else if auth := strings.SplitN(r.Header.Get("Authorization"), " ", 2); len(auth) == 2 { + if auth[1] != s.token { log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) w.WriteHeader(401) return } } else { - log.Warnf("已拒绝 %v 的 Websocket 请求: 空Token", r.RemoteAddr) + log.Warnf("已拒绝 %v 的 Websocket 请求: 空Token或传入格式错误", r.RemoteAddr) w.WriteHeader(401) return } @@ -249,14 +249,14 @@ func (s *websocketServer) api(w http.ResponseWriter, r *http.Request) { log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) w.WriteHeader(401) return - } else if auth := r.Header.Get("Authorization"); auth != "" { - if strings.SplitN(auth, " ", 2)[1] != s.token { + } else if auth := strings.SplitN(r.Header.Get("Authorization"), " ", 2); len(auth) == 2 { + if auth[1] != s.token { log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) w.WriteHeader(401) return } } else { - log.Warnf("已拒绝 %v 的 Websocket 请求: 空Token", r.RemoteAddr) + log.Warnf("已拒绝 %v 的 Websocket 请求: 空Token或传入格式错误", r.RemoteAddr) w.WriteHeader(401) return } @@ -277,14 +277,14 @@ func (s *websocketServer) any(w http.ResponseWriter, r *http.Request) { log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) w.WriteHeader(401) return - } else if auth := r.Header.Get("Authorization"); auth != "" { - if strings.SplitN(auth, " ", 2)[1] != s.token { + } else if auth := strings.SplitN(r.Header.Get("Authorization"), " ", 2); len(auth) == 2 { + if auth[1] != s.token { log.Warnf("已拒绝 %v 的 Websocket 请求: Token错误", r.RemoteAddr) w.WriteHeader(401) return } } else { - log.Warnf("已拒绝 %v 的 Websocket 请求: 空Token", r.RemoteAddr) + log.Warnf("已拒绝 %v 的 Websocket 请求: 空Token或传入格式错误", r.RemoteAddr) w.WriteHeader(401) return }