mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-12 06:45:46 +08:00
update MiraiGo.
This commit is contained in:
commit
9b41cd8ea2
@ -125,6 +125,7 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bo
|
||||
if mid == -1 {
|
||||
return Failed(100)
|
||||
}
|
||||
log.Infof("发送群 %v(%v) 的消息: %v (%v)", groupId, groupId, m.String(), mid)
|
||||
return OK(MSG{"message_id": mid})
|
||||
}
|
||||
str = func() string {
|
||||
@ -151,6 +152,7 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}, autoEscape bo
|
||||
if mid == -1 {
|
||||
return Failed(100)
|
||||
}
|
||||
log.Infof("发送群 %v(%v) 的消息: %v (%v)", groupId, groupId, str, mid)
|
||||
return OK(MSG{"message_id": mid})
|
||||
}
|
||||
|
||||
@ -247,6 +249,7 @@ func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}, autoEscape b
|
||||
if mid == -1 {
|
||||
return Failed(100)
|
||||
}
|
||||
log.Infof("发送好友 %v(%v) 的消息: %v (%v)", userId, userId, m.String(), mid)
|
||||
return OK(MSG{"message_id": mid})
|
||||
}
|
||||
str = func() string {
|
||||
@ -271,6 +274,7 @@ func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}, autoEscape b
|
||||
if mid == -1 {
|
||||
return Failed(100)
|
||||
}
|
||||
log.Infof("发送好友 %v(%v) 的消息: %v (%v)", userId, userId, str, mid)
|
||||
return OK(MSG{"message_id": mid})
|
||||
}
|
||||
|
||||
|
@ -58,8 +58,6 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
|
||||
"type": "text",
|
||||
"data": map[string]string{"text": o.Content},
|
||||
}
|
||||
case *message.ReplyElement:
|
||||
continue
|
||||
case *message.LightAppElement:
|
||||
//m = MSG{
|
||||
// "type": "text",
|
||||
@ -144,6 +142,8 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
|
||||
"data": map[string]string{"data": o.Content, "resid": fmt.Sprintf("%d", o.Id)},
|
||||
}
|
||||
}
|
||||
default:
|
||||
continue
|
||||
}
|
||||
r = append(r, m)
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ go-cqhttp 默认生成的文件树如下所示:
|
||||
├── go-cqhttp
|
||||
├── config.json
|
||||
├── device.json
|
||||
├── servers.bin
|
||||
├── logs
|
||||
│ └── xx-xx-xx.log
|
||||
└── data
|
||||
@ -21,7 +20,6 @@ go-cqhttp 默认生成的文件树如下所示:
|
||||
| go-cqhttp | go-cqhttp可执行文件 |
|
||||
| config.json | 运行配置文件 |
|
||||
| device.json | 虚拟设备配置文件 |
|
||||
| servers.bin | 储存QQ服务器地址 |
|
||||
| logs | 日志存放目录 |
|
||||
| data | 数据目录 |
|
||||
| data/images | 图片缓存目录 |
|
||||
|
42
main.go
42
main.go
@ -10,7 +10,6 @@ import (
|
||||
"image"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path"
|
||||
@ -237,47 +236,8 @@ func main() {
|
||||
}
|
||||
})
|
||||
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) {
|
||||
log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. 地址信息已储存到 servers.bin 文件")
|
||||
_ = ioutil.WriteFile("servers.bin", binary.NewWriterF(func(w *binary.Writer) {
|
||||
w.WriteUInt16(func() (c uint16) {
|
||||
for _, s := range e.Servers {
|
||||
if !strings.Contains(s.Server, "com") {
|
||||
c++
|
||||
}
|
||||
}
|
||||
return
|
||||
}())
|
||||
for _, s := range e.Servers {
|
||||
if !strings.Contains(s.Server, "com") {
|
||||
w.WriteString(s.Server)
|
||||
w.WriteUInt16(uint16(s.Port))
|
||||
}
|
||||
}
|
||||
}), 0644)
|
||||
log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. ")
|
||||
})
|
||||
if global.PathExists("servers.bin") {
|
||||
if data, err := ioutil.ReadFile("servers.bin"); err == nil {
|
||||
func() {
|
||||
defer func() {
|
||||
if pan := recover(); pan != nil {
|
||||
log.Error("读取服务器地址时出现错误: ", pan)
|
||||
}
|
||||
}()
|
||||
r := binary.NewReader(data)
|
||||
var addr []*net.TCPAddr
|
||||
l := r.ReadUInt16()
|
||||
for i := 0; i < int(l); i++ {
|
||||
addr = append(addr, &net.TCPAddr{
|
||||
IP: net.ParseIP(r.ReadString()),
|
||||
Port: int(r.ReadUInt16()),
|
||||
})
|
||||
}
|
||||
if len(addr) > 0 {
|
||||
cli.SetCustomServer(addr)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
rsp, err := cli.Login()
|
||||
for {
|
||||
global.Check(err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user