Skip to content

Commit 481cf7c

Browse files
committed
Merge branch 'dev' of https://github.com/Mrs4s/go-cqhttp into dev
2 parents 9ba2fda + 551a475 commit 481cf7c

File tree

10 files changed

+195
-81
lines changed

10 files changed

+195
-81
lines changed

README.md

Lines changed: 54 additions & 54 deletions
Large diffs are not rendered by default.

cmd/gocq/login.go

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ package gocq
33
import (
44
"bufio"
55
"bytes"
6+
"fmt"
67
"image"
78
"image/png"
89
"os"
910
"strings"
1011
"time"
1112

1213
"github.com/Mrs4s/MiraiGo/client"
14+
"github.com/Mrs4s/MiraiGo/utils"
1315
"github.com/mattn/go-colorable"
1416
"github.com/pkg/errors"
1517
log "github.com/sirupsen/logrus"
18+
"github.com/tidwall/gjson"
1619

1720
"github.com/Mrs4s/go-cqhttp/global"
1821
)
@@ -142,7 +145,19 @@ func loginResponseProcessor(res *client.LoginResponse) error {
142145
var text string
143146
switch res.Error {
144147
case client.SliderNeededError:
145-
log.Warnf("登录需要滑条验证码, 请使用手机QQ扫描二维码以继续登录.")
148+
log.Warnf("登录需要滑条验证码, 请选择验证方式: ")
149+
log.Warnf("1. 使用浏览器抓取滑条并登录")
150+
log.Warnf("2. 使用手机QQ扫码验证 (需要手Q和gocq在同一网络下).")
151+
log.Warn("请输入(1 - 2) (将在10秒后自动选择1):")
152+
text = readLineTimeout(time.Second*10, "1")
153+
if strings.Contains(text, "1") {
154+
ticket := sliderCaptchaProcessor(res.VerifyUrl)
155+
if ticket == "" {
156+
os.Exit(0)
157+
}
158+
res, err = cli.SubmitTicket(ticket)
159+
continue
160+
}
146161
cli.Disconnect()
147162
cli.Release()
148163
cli = client.NewClientEmpty()
@@ -192,8 +207,7 @@ func loginResponseProcessor(res *client.LoginResponse) error {
192207
msg := res.ErrorMessage
193208
if strings.Contains(msg, "版本") {
194209
msg = "密码错误或账号被冻结"
195-
}
196-
if strings.Contains(msg, "冻结") {
210+
} else if strings.Contains(msg, "冻结") {
197211
log.Fatalf("账号被冻结")
198212
}
199213
log.Warnf("登录失败: %v", msg)
@@ -203,3 +217,23 @@ func loginResponseProcessor(res *client.LoginResponse) error {
203217
}
204218
}
205219
}
220+
221+
func sliderCaptchaProcessor(u string) string {
222+
id := utils.RandomString(8)
223+
log.Warnf("请前往该地址验证 -> %v", strings.ReplaceAll(u, "https://ssl.captcha.qq.com/template/wireless_mqq_captcha.html?", fmt.Sprintf("https://captcha.go-cqhttp.org/captcha?id=%v&", id)))
224+
start := time.Now()
225+
for time.Since(start).Minutes() < 2 {
226+
time.Sleep(time.Second)
227+
data, err := global.GetBytes("https://captcha.go-cqhttp.org/captcha/ticket?id=" + id)
228+
if err != nil {
229+
log.Warnf("获取 Ticket 时出现错误: %v", err)
230+
return ""
231+
}
232+
g := gjson.ParseBytes(data)
233+
if g.Get("ticket").Exists() {
234+
return g.Get("ticket").String()
235+
}
236+
}
237+
log.Warnf("验证超时")
238+
return ""
239+
}

coolq/api.go

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,30 @@ func (bot *CQBot) CQUploadGroupFile(groupID int64, file, name, folder string) gl
601601
return OK(nil)
602602
}
603603

604+
// CQUploadPrivateFile 扩展API-上传私聊文件
605+
//
606+
// @route(upload_private_file)
607+
func (bot *CQBot) CQUploadPrivateFile(userID int64, file, name string) global.MSG {
608+
target := message.Source{
609+
SourceType: message.SourcePrivate,
610+
PrimaryID: userID,
611+
}
612+
fileBody, err := os.Open(file)
613+
if err != nil {
614+
log.Warnf("上传私聊文件 %v 失败: %+v", file, err)
615+
return Failed(100, "OPEN_FILE_ERROR", "打开文件失败")
616+
}
617+
localFile := &client.LocalFile{
618+
FileName: name,
619+
Body: fileBody,
620+
}
621+
if err := bot.Client.UploadFile(target, localFile); err != nil {
622+
log.Warnf("上传私聊 %v 文件 %v 失败: %+v", userID, file, err)
623+
return Failed(100, "FILE_SYSTEM_UPLOAD_API_ERROR", err.Error())
624+
}
625+
return OK(nil)
626+
}
627+
604628
// CQGroupFileCreateFolder 拓展API-创建群文件文件夹
605629
//
606630
// @route(create_group_file_folder)
@@ -808,7 +832,12 @@ func (bot *CQBot) uploadForwardElement(m gjson.Result, target int64, sourceType
808832
groupID := target
809833
source := message.Source{SourceType: sourceType, PrimaryID: target}
810834
if sourceType == message.SourcePrivate {
811-
groupID = 0
835+
// ios 设备的合并转发来源群号不能为 0
836+
if len(bot.Client.GroupList) == 0 {
837+
groupID = 1
838+
} else {
839+
groupID = bot.Client.GroupList[1].Uin
840+
}
812841
}
813842
builder := bot.Client.NewForwardMessageBuilder(groupID)
814843

@@ -849,17 +878,21 @@ func (bot *CQBot) uploadForwardElement(m gjson.Result, target int64, sourceType
849878
}
850879
if e.Get("data.id").Exists() {
851880
i := e.Get("data.id").Int()
852-
m, _ := db.GetGroupMessageByGlobalID(int32(i))
881+
m, _ := db.GetMessageByGlobalID(int32(i))
853882
if m != nil {
854-
msgTime := m.Attribute.Timestamp
883+
mSource := message.SourcePrivate
884+
if m.GetType() == "group" {
885+
mSource = message.SourceGroup
886+
}
887+
msgTime := m.GetAttribute().Timestamp
855888
if msgTime == 0 {
856889
msgTime = ts.Unix()
857890
}
858891
return &message.ForwardNode{
859-
SenderId: m.Attribute.SenderUin,
860-
SenderName: m.Attribute.SenderName,
892+
SenderId: m.GetAttribute().SenderUin,
893+
SenderName: m.GetAttribute().SenderName,
861894
Time: int32(msgTime),
862-
Message: resolveElement(bot.ConvertContentMessage(m.Content, message.SourceGroup)),
895+
Message: resolveElement(bot.ConvertContentMessage(m.GetContent(), mSource)),
863896
}
864897
}
865898
log.Warnf("警告: 引用消息 %v 错误或数据库未开启.", e.Get("data.id").Str)
@@ -892,7 +925,7 @@ func (bot *CQBot) uploadForwardElement(m gjson.Result, target int64, sourceType
892925
}
893926
}
894927
}
895-
content := bot.ConvertObjectMessage(c, message.SourceGroup)
928+
content := bot.ConvertObjectMessage(c, sourceType)
896929
if uin != 0 && name != "" && len(content) > 0 {
897930
return &message.ForwardNode{
898931
SenderId: uin,
@@ -1364,6 +1397,7 @@ func (bot *CQBot) CQGetStrangerInfo(userID int64) global.MSG {
13641397
"age": info.Age,
13651398
"level": info.Level,
13661399
"login_days": info.LoginDays,
1400+
"vip_level": info.VipLevel,
13671401
})
13681402
}
13691403

docs/EventFilter.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@
163163

164164
## 过滤时的事件数据对象
165165

166-
过滤器在go-cqhttp构建好事件数据后运行,各事件的数据字段见[OneBot标准]( https://github.com/howmanybots/onebot/blob/master/v11/specs/event/README.md )
166+
过滤器在go-cqhttp构建好事件数据后运行,各事件的数据字段见[OneBot标准]( https://github.com/botuniverse/onebot-11/blob/master/event/README.md )
167167

168168
这里有几点需要注意:
169169

170-
- `message` 字段在运行过滤器时和上报信息类型相同(见 [消息格式]( https://github.com/howmanybots/onebot/blob/master/v11/specs/message/array.md )
170+
- `message` 字段在运行过滤器时和上报信息类型相同(见 [消息格式]( https://github.com/botuniverse/onebot-11/blob/master/message/array.md )
171171
- `raw_message` 字段为未经**CQ码**处理的原始消息字符串,这意味着其中可能会出现形如 `[CQ:face,id=123]` 的 CQ 码

docs/config.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ servers:
8484
# HTTP 通信设置
8585
- http:
8686
# 服务端监听地址
87-
host: 127.0.0.1
88-
# 服务端监听端口
89-
port: 5700
87+
# 如需指定监听ipv4, 可使用 `address: tcp4://0.0.0.0:5700` (ipv6同理)
88+
address: 0.0.0.0:5700
9089
# 反向HTTP超时时间, 单位秒
9190
# 最小值为5,小于5将会忽略本项设置
9291
timeout: 5
@@ -102,9 +101,8 @@ servers:
102101
# 正向WS设置
103102
- ws:
104103
# 正向WS服务器监听地址
105-
host: 127.0.0.1
106-
# 正向WS服务器监听端口
107-
port: 6700
104+
# 如需指定监听ipv4, 可使用 `address: tcp4://0.0.0.0:6700` (ipv6同理)
105+
address: 0.0.0.0:6700
108106
middlewares:
109107
<<: *default # 引用默认中间件
110108

docs/cqhttp.md

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,18 @@ Type: `tts`
491491

492492
示例: `[CQ:tts,text=这是一条测试消息]`
493493

494+
### 猜拳消息
495+
496+
Type: `rps`
497+
498+
参数:
499+
500+
| 参数名 | 类型 | 说明 |
501+
|---------|-----|------------------|
502+
| `value` | int | 0:石头, 1:剪刀, 2:布 |
503+
504+
示例: `[CQ:rps,value=0]`
505+
494506
## API
495507

496508
### 设置群名
@@ -613,15 +625,16 @@ Type: `tts`
613625
}
614626
````
615627

616-
### 发送合并转发(群)
628+
### 发送合并转发(群/私聊)
617629

618-
终结点: `/send_group_forward_msg`
630+
终结点: `/send_group_forward_msg`, `send_private_forward_msg`, `send_forward_msg`
619631

620632
**参数**
621633

622-
| 字段 | 类型 | 说明 |
623-
| ---------- | -------------- | ---------------------------- |
624-
| `group_id` | int64 | 群号 |
634+
| 字段 | 类型 | 说明 |
635+
|------------|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
636+
| `group_id` | int64 | 群号 |
637+
| `user_id` | int64 | 私聊QQ号 |
625638
| `messages` | forward node[] | 自定义转发消息, 具体看 [CQCode](https://github.com/Mrs4s/go-cqhttp/blob/master/docs/cqhttp.md#%E5%90%88%E5%B9%B6%E8%BD%AC%E5%8F%91%E6%B6%88%E6%81%AF%E8%8A%82%E7%82%B9) |
626639

627640
响应数据
@@ -883,6 +896,36 @@ Type: `tts`
883896
> 在不提供 `folder` 参数的情况下默认上传到根目录
884897
> 只能上传本地文件, 需要上传 `http` 文件的话请先调用 `download_file` API下载
885898
899+
### 上传私聊文件
900+
901+
终结点: `/upload_private_file`
902+
903+
**参数**
904+
905+
| 字段 | 类型 | 说明 |
906+
|-----------|--------|--------|
907+
| `user_id` | int64 | 接收者id |
908+
| `file` | string | 本地文件路径 |
909+
| `name` | string | 储存名称 |
910+
911+
> 只能上传本地文件, 需要上传 `http` 文件的话请先调用 `download_file` API下载
912+
913+
### 设置 QQ 个人资料
914+
915+
终结点: `/set_qq_profile`
916+
917+
**参数**
918+
919+
| 字段 | 类型 | 说明 |
920+
|-----------------|--------|------|
921+
| `nickname` | int64 | 昵称 |
922+
| `company` | string | 公司 |
923+
| `email` | string | 邮箱 |
924+
| `college` | string | 大学 |
925+
| `personal_note` | string | 个人签名 |
926+
927+
> 所有参数字段都为可选。
928+
886929
### 获取状态
887930

888931
终结点: `/get_status`

global/net.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func DownloadFileMultiThreading(url, path string, limit int64, threadCount int,
184184
req.Header.Set(k, v)
185185
}
186186

187-
if _, ok := headers["User-Agent"]; ok {
187+
if _, ok := headers["User-Agent"]; !ok {
188188
req.Header["User-Agent"] = []string{UserAgent}
189189
}
190190
req.Header.Set("range", "bytes="+strconv.FormatInt(block.BeginOffset, 10)+"-"+strconv.FormatInt(block.EndOffset, 10))

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.18
44

55
require (
66
github.com/Microsoft/go-winio v0.5.1
7-
github.com/Mrs4s/MiraiGo v0.0.0-20220614093722-87ff2f95910c
7+
github.com/Mrs4s/MiraiGo v0.0.0-20220622015746-24ee0103e7de
88
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c
99
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc
1010
github.com/fumiama/go-base16384 v1.5.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY=
22
github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
3-
github.com/Mrs4s/MiraiGo v0.0.0-20220614093722-87ff2f95910c h1:LGJoAua1bYxx28255h02owv66v9eWkSwcZx/jEO79Z0=
4-
github.com/Mrs4s/MiraiGo v0.0.0-20220614093722-87ff2f95910c/go.mod h1:mZp8Lt7uqLCUwSLouB2yuiP467Cwl4mnG9IMAaXUKA0=
3+
github.com/Mrs4s/MiraiGo v0.0.0-20220622015746-24ee0103e7de h1:senbiV71dgsYt60BWLEHWwvKFCYUcIzGQ/fmXRaOeQ4=
4+
github.com/Mrs4s/MiraiGo v0.0.0-20220622015746-24ee0103e7de/go.mod h1:mZp8Lt7uqLCUwSLouB2yuiP467Cwl4mnG9IMAaXUKA0=
55
github.com/RomiChan/protobuf v0.1.1-0.20220602121309-9e3b8cbefd7a h1:WIfEWYj82oEuPtm5pqlyQmCJCoiw00C6ugZFqHA0cC8=
66
github.com/RomiChan/protobuf v0.1.1-0.20220602121309-9e3b8cbefd7a/go.mod h1:2Ie+hdBFQpQFDHfeklgxoFmQRCE7O+KwFpISeXq7OwA=
77
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c h1:cNPOdTNiVwxLpROLjXCgbIPvdkE+BwvxDvgmdYmWx6Q=

modules/api/api.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)