mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-06 12:03:50 +08:00
Merge branch 'master' into dev
This commit is contained in:
commit
1f5c9acefb
@ -214,6 +214,7 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int
|
||||
return -1
|
||||
}
|
||||
m.Elements = newElem
|
||||
bot.checkMedia(newElem)
|
||||
ret := bot.Client.SendGroupMessage(groupId, m, ForceFragmented)
|
||||
if ret == nil || ret.Id == -1 {
|
||||
log.Warnf("群消息发送失败: 账号可能被风控.")
|
||||
@ -299,6 +300,7 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in
|
||||
return -1
|
||||
}
|
||||
m.Elements = newElem
|
||||
bot.checkMedia(newElem)
|
||||
var id int32 = -1
|
||||
if bot.Client.FindFriend(target) != nil { // 双向好友
|
||||
msg := bot.Client.SendPrivateMessage(target, m)
|
||||
|
@ -243,6 +243,10 @@ func ToStringMessage(e []message.IMessageElement, code int64, raw ...bool) (r st
|
||||
} else {
|
||||
r += fmt.Sprintf(`[CQ:image,file=%s,url=%s]`, o.Filename, CQCodeEscapeValue(o.Url))
|
||||
}
|
||||
case *message.GroupImageElement:
|
||||
r += fmt.Sprintf("[CQ:image,file=%s]", hex.EncodeToString(o.Md5)+".image")
|
||||
case *message.FriendImageElement:
|
||||
r += fmt.Sprintf("[CQ:image,file=%s]", hex.EncodeToString(o.Md5)+".image")
|
||||
case *message.ServiceElement:
|
||||
if isOk := strings.Contains(o.Content, "<?xml"); isOk {
|
||||
r += fmt.Sprintf(`[CQ:xml,data=%s,resid=%d]`, CQCodeEscapeValue(o.Content), o.Id)
|
||||
|
@ -478,6 +478,26 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement) {
|
||||
}), 0644)
|
||||
}
|
||||
i.Filename = filename
|
||||
case *message.GroupImageElement:
|
||||
filename := hex.EncodeToString(i.Md5) + ".image"
|
||||
if !global.PathExists(path.Join(global.IMAGE_PATH, filename)) {
|
||||
_ = ioutil.WriteFile(path.Join(global.IMAGE_PATH, filename), binary.NewWriterF(func(w *binary.Writer) {
|
||||
w.Write(i.Md5)
|
||||
w.WriteUInt32(uint32(i.Size))
|
||||
w.WriteString(filename)
|
||||
w.WriteString(i.Url)
|
||||
}), 0644)
|
||||
}
|
||||
case *message.FriendImageElement:
|
||||
filename := hex.EncodeToString(i.Md5) + ".image"
|
||||
if !global.PathExists(path.Join(global.IMAGE_PATH, filename)) {
|
||||
_ = ioutil.WriteFile(path.Join(global.IMAGE_PATH, filename), binary.NewWriterF(func(w *binary.Writer) {
|
||||
w.Write(i.Md5)
|
||||
w.WriteUInt32(uint32(0)) // 发送时会调用url, 大概没事
|
||||
w.WriteString(filename)
|
||||
w.WriteString(i.Url)
|
||||
}), 0644)
|
||||
}
|
||||
case *message.VoiceElement:
|
||||
i.Name = strings.ReplaceAll(i.Name, "{", "")
|
||||
i.Name = strings.ReplaceAll(i.Name, "}", "")
|
||||
|
@ -229,8 +229,7 @@ func (s *webServer) Dologin() {
|
||||
log.Warn("Bot已登录")
|
||||
return
|
||||
}
|
||||
if conf.ReLogin.MaxReloginTimes == 0 {
|
||||
} else if times > conf.ReLogin.MaxReloginTimes {
|
||||
if times > conf.ReLogin.MaxReloginTimes && conf.ReLogin.MaxReloginTimes != 0 {
|
||||
break
|
||||
}
|
||||
log.Warnf("Bot已离线 (%v),将在 %v 秒后尝试重连. 重连次数:%v",
|
||||
|
Loading…
x
Reference in New Issue
Block a user