Skip to content

Commit 8493f25

Browse files
authored
Merge branch 'Mrs4s:dev' into dev
2 parents ccff299 + 6bb98fc commit 8493f25

File tree

6 files changed

+33
-19
lines changed

6 files changed

+33
-19
lines changed

cmd/gocq/login.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/mattn/go-colorable"
1616
"github.com/pkg/errors"
1717
log "github.com/sirupsen/logrus"
18+
"gopkg.ilharper.com/x/isatty"
1819

1920
"github.com/Mrs4s/go-cqhttp/global"
2021
"github.com/Mrs4s/go-cqhttp/internal/download"
@@ -44,6 +45,14 @@ func readLineTimeout(t time.Duration, de string) (str string) {
4445
return
4546
}
4647

48+
func readIfTTY(de string) (str string) {
49+
if isatty.Isatty(os.Stdin.Fd()) {
50+
return readLine()
51+
}
52+
log.Warnf("未检测到输入终端,自动选择%s.", de)
53+
return de
54+
}
55+
4756
var cli *client.QQClient
4857

4958
// ErrSMSRequestError SMS请求出错
@@ -149,7 +158,7 @@ func loginResponseProcessor(res *client.LoginResponse) error {
149158
log.Warnf("1. 使用浏览器抓取滑条并登录")
150159
log.Warnf("2. 使用手机QQ扫码验证 (需要手Q和gocq在同一网络下).")
151160
log.Warn("请输入(1 - 2):")
152-
text = readLine()
161+
text = readIfTTY("1")
153162
if strings.Contains(text, "1") {
154163
ticket := getTicket(res.VerifyUrl)
155164
if ticket == "" {
@@ -185,8 +194,8 @@ func loginResponseProcessor(res *client.LoginResponse) error {
185194
log.Warnf("账号已开启设备锁,请选择验证方式:")
186195
log.Warnf("1. 向手机 %v 发送短信验证码", res.SMSPhone)
187196
log.Warnf("2. 使用手机QQ扫码验证.")
188-
log.Warn("请输入(1 - 2) (将在10秒后自动选择2):")
189-
text = readLineTimeout(time.Second*10, "2")
197+
log.Warn("请输入(1 - 2):")
198+
text = readIfTTY("2")
190199
if strings.Contains(text, "1") {
191200
if !cli.RequestSMS() {
192201
log.Warnf("发送验证码失败,可能是请求过于频繁.")

cmd/gocq/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ func Main() {
224224
log.Warnf("警告: 配置文件内的QQ号 (%v) 与缓存内的QQ号 (%v) 不相同", base.Account.Uin, cu)
225225
log.Warnf("1. 使用会话缓存继续.")
226226
log.Warnf("2. 删除会话缓存并重启.")
227-
log.Warnf("请选择: (5秒后自动选1)")
228-
text := readLineTimeout(time.Second*5, "1")
227+
log.Warnf("请选择:")
228+
text := readIfTTY("1")
229229
if text == "2" {
230230
_ = os.Remove("session.token")
231231
log.Infof("缓存已删除.")

coolq/event.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -543,21 +543,23 @@ func (bot *CQBot) groupInvitedEvent(c *client.QQClient, e *client.GroupInvitedRe
543543
log.Infof("收到来自群 %v(%v) 内用户 %v(%v) 的加群邀请.", e.GroupName, e.GroupCode, e.InvitorNick, e.InvitorUin)
544544
flag := strconv.FormatInt(e.RequestId, 10)
545545
bot.dispatchEvent("request/group/invite", global.MSG{
546-
"group_id": e.GroupCode,
547-
"user_id": e.InvitorUin,
548-
"comment": "",
549-
"flag": flag,
546+
"group_id": e.GroupCode,
547+
"user_id": e.InvitorUin,
548+
"invitor_id": 0,
549+
"comment": "",
550+
"flag": flag,
550551
})
551552
}
552553

553554
func (bot *CQBot) groupJoinReqEvent(c *client.QQClient, e *client.UserJoinGroupRequest) {
554555
log.Infof("群 %v(%v) 收到来自用户 %v(%v) 的加群请求.", e.GroupName, e.GroupCode, e.RequesterNick, e.RequesterUin)
555556
flag := strconv.FormatInt(e.RequestId, 10)
556557
bot.dispatchEvent("request/group/add", global.MSG{
557-
"group_id": e.GroupCode,
558-
"user_id": e.RequesterUin,
559-
"comment": e.Message,
560-
"flag": flag,
558+
"group_id": e.GroupCode,
559+
"user_id": e.RequesterUin,
560+
"invitor_id": e.ActionUin,
561+
"comment": e.Message,
562+
"flag": flag,
561563
})
562564
}
563565

global/quote.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ func Quote(s string) string {
1818
return quoteWith(s, '"', false, false)
1919
}
2020

21-
func quoteWith(s string, quote byte, ASCIIonly, graphicOnly bool) string {
22-
return string(appendQuotedWith(make([]byte, 0, 3*len(s)/2), s, quote, ASCIIonly, graphicOnly))
21+
func quoteWith(s string, quote byte, asciiOnly, graphicOnly bool) string {
22+
return string(appendQuotedWith(make([]byte, 0, 3*len(s)/2), s, quote, asciiOnly, graphicOnly))
2323
}
2424

25-
func appendQuotedWith(buf []byte, s string, quote byte, ASCIIonly, graphicOnly bool) []byte {
25+
func appendQuotedWith(buf []byte, s string, quote byte, asciiOnly, graphicOnly bool) []byte {
2626
// Often called with big strings, so preallocate. If there's quoting,
2727
// this is conservative but still helps a lot.
2828
if cap(buf)-len(buf) < len(s) {
@@ -43,19 +43,19 @@ func appendQuotedWith(buf []byte, s string, quote byte, ASCIIonly, graphicOnly b
4343
buf = append(buf, lowerhex[s[0]&0xF])
4444
continue
4545
}
46-
buf = appendEscapedRune(buf, r, quote, ASCIIonly, graphicOnly)
46+
buf = appendEscapedRune(buf, r, quote, asciiOnly, graphicOnly)
4747
}
4848
buf = append(buf, quote)
4949
return buf
5050
}
51-
func appendEscapedRune(buf []byte, r rune, quote byte, ASCIIonly, graphicOnly bool) []byte {
51+
func appendEscapedRune(buf []byte, r rune, quote byte, asciiOnly, graphicOnly bool) []byte {
5252
var runeTmp [utf8.UTFMax]byte
5353
if r == rune(quote) || r == '\\' { // always backslashed
5454
buf = append(buf, '\\')
5555
buf = append(buf, byte(r))
5656
return buf
5757
}
58-
if ASCIIonly {
58+
if asciiOnly {
5959
if r < utf8.RuneSelf && strconv.IsPrint(r) {
6060
buf = append(buf, byte(r))
6161
return buf

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ require (
2424
golang.org/x/sys v0.2.0
2525
golang.org/x/term v0.2.0
2626
golang.org/x/time v0.2.0
27+
gopkg.ilharper.com/x/isatty v1.1.0
2728
gopkg.in/yaml.v3 v3.0.1
2829
)
2930

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ
182182
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
183183
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
184184
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
185+
gopkg.ilharper.com/x/isatty v1.1.0 h1:slOK6hP9/y9mJWyCInMwnT432NExfWyYV2SsebdYOCY=
186+
gopkg.ilharper.com/x/isatty v1.1.0/go.mod h1:ofpv77Td5qQO6R1dmDd3oNt8TZdRo+l5gYAMxopRyS0=
185187
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
186188
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
187189
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=

0 commit comments

Comments
 (0)