Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
  • Loading branch information
Fripine committed Oct 10, 2024
1 parent 02acaca commit c9ba1fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
33 changes: 16 additions & 17 deletions cmd/gocq/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,22 +235,11 @@ func LoginInteract() {
} else if len(base.Account.Password) > 0 {
base.PasswordHash = md5.Sum([]byte(base.Account.Password))
}
if !base.FastStart {
log.Info("Bot将在5秒后登录并开始信息处理, 按 Ctrl+C 取消.")
time.Sleep(time.Second * 5)
}
log.Info("开始尝试登录并同步消息...")
log.Infof("使用协议: %s", device.Protocol.Version())
// if !base.FastStart {
// log.Info("Bot将在5秒后登录并开始信息处理, 按 Ctrl+C 取消.")
// time.Sleep(time.Second * 5)
// }
cli = newClient()
cli.UseDevice(device)
isQRCodeLogin := (base.Account.Uin == 0 || len(base.Account.Password) == 0) && !base.Account.Encrypt
isTokenLogin := false

if isQRCodeLogin && cli.Device().Protocol != 2 {
log.Warn("当前协议不支持二维码登录, 请配置账号密码登录.")
os.Exit(0)
}

// 加载本地版本信息, 一般是在上次登录时保存的
versionFile := path.Join(global.VersionsPath, fmt.Sprint(int(cli.Device().Protocol))+".json")
if global.PathExists(versionFile) {
Expand All @@ -266,6 +255,16 @@ func LoginInteract() {
}
log.Infof("从文件 %s 读取协议版本 %v.", versionFile, cli.Device().Protocol.Version())
}
cli.UseDevice(device)
log.Info("开始尝试登录并同步消息...")
log.Infof("使用协议: %s", device.Protocol.Version())
isQRCodeLogin := (base.Account.Uin == 0 || len(base.Account.Password) == 0) && !base.Account.Encrypt
isTokenLogin := false

if isQRCodeLogin && cli.Device().Protocol != 2 {
log.Warn("当前协议不支持二维码登录, 请配置账号密码登录.")
os.Exit(0)
}

saveToken := func() {
base.AccountToken = cli.GenToken()
Expand Down Expand Up @@ -482,8 +481,8 @@ func newClient() *client.QQClient {
}

var remoteVersions = map[int]string{
1: "https://raw.githubusercontent.com/RomiChan/protocol-versions/master/android_phone.json",
6: "https://raw.githubusercontent.com/RomiChan/protocol-versions/master/android_pad.json",
1: "https://raw.githubusercontent.com/sealdice/protocol-versions/master/android_phone.json",
6: "https://raw.githubusercontent.com/sealdice/protocol-versions/master/android_pad.json",
}

func getRemoteLatestProtocolVersion(protocolType int) ([]byte, error) {
Expand Down
8 changes: 4 additions & 4 deletions coolq/cqcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func toElements(e []message.IMessageElement, source message.Source) (r []msg.Ele
}
case *message.GroupImageElement:
data := pairs{
{K: "file", V: hex.EncodeToString(o.Md5) + ".image"},
{K: "file", V: o.ImageId},
{K: "subType", V: strconv.FormatInt(int64(o.ImageBizType), 10)},
{K: "url", V: o.Url},
}
Expand All @@ -193,7 +193,7 @@ func toElements(e []message.IMessageElement, source message.Source) (r []msg.Ele
}
case *message.FriendImageElement:
data := pairs{
{K: "file", V: hex.EncodeToString(o.Md5) + ".image"},
{K: "file", V: o.ImageId},
{K: "url", V: o.Url},
}
if o.Flash {
Expand Down Expand Up @@ -339,7 +339,7 @@ func ToMessageContent(e []message.IMessageElement, source message.Source) (r []g
"data": global.MSG{"file": o.Name, "url": o.Url},
}
case *message.GroupImageElement:
data := global.MSG{"file": hex.EncodeToString(o.Md5) + ".image", "url": o.Url, "subType": uint32(o.ImageBizType)}
data := global.MSG{"file": o.ImageId, "url": o.Url, "subType": uint32(o.ImageBizType)}
switch {
case o.Flash:
data["type"] = "flash"
Expand All @@ -357,7 +357,7 @@ func ToMessageContent(e []message.IMessageElement, source message.Source) (r []g
"data": global.MSG{"file": hex.EncodeToString(o.Md5) + ".image", "url": o.Url},
}
case *message.FriendImageElement:
data := global.MSG{"file": hex.EncodeToString(o.Md5) + ".image", "url": o.Url}
data := global.MSG{"file": o.ImageId, "url": o.Url}
if o.Flash {
data["type"] = "flash"
}
Expand Down

0 comments on commit c9ba1fa

Please sign in to comment.