1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-06 20:13:50 +08:00
sync
This commit is contained in:
wdvxdr1123 2020-09-28 18:37:47 +08:00 committed by GitHub
commit 2e59cb8a17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 52 deletions

View File

@ -6,6 +6,7 @@ import (
"path"
"runtime"
"strconv"
"strings"
"time"
"github.com/Mrs4s/MiraiGo/binary"
@ -125,6 +126,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, limitedString(m.String()), mid)
return OK(MSG{"message_id": mid})
}
str = func() string {
@ -151,6 +153,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, limitedString(str), mid)
return OK(MSG{"message_id": mid})
}
@ -247,6 +250,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, limitedString(m.String()), mid)
return OK(MSG{"message_id": mid})
}
str = func() string {
@ -271,6 +275,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, limitedString(str), mid)
return OK(MSG{"message_id": mid})
}
@ -754,3 +759,12 @@ func convertGroupMemberInfo(groupId int64, m *client.GroupMemberInfo) MSG {
"card_changeable": false,
}
}
func limitedString(str string) string {
if strings.Count(str, "") <= 10 {
return str
}
limited := []rune(str)
limited = limited[:10]
return string(limited) + " ..."
}

View File

@ -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)
}

View File

@ -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 | 图片缓存目录 |

View File

@ -1,3 +1,3 @@
# 开始
欢迎来到 go-cqhttp 文档
欢迎来到 go-cqhttp 文档 目前还在咕

2
go.mod
View File

@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
go 1.14
require (
github.com/Mrs4s/MiraiGo v0.0.0-20200921142226-9a449519db5c
github.com/Mrs4s/MiraiGo v0.0.0-20200928082341-65c1709f5eec
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/gin-gonic/gin v1.6.3
github.com/go-playground/validator/v10 v10.3.0 // indirect

9
go.sum
View File

@ -1,7 +1,7 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Mrs4s/MiraiGo v0.0.0-20200921142226-9a449519db5c h1:TpGiSjI8Pe0YLEQPAVkOV37OFLeJnQ6jxvcDSb/LESY=
github.com/Mrs4s/MiraiGo v0.0.0-20200921142226-9a449519db5c/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20200928082341-65c1709f5eec h1:lzFAr6b1yO6JIzfse0VIsPq71E0KfdsoS3VnyOLurS4=
github.com/Mrs4s/MiraiGo v0.0.0-20200928082341-65c1709f5eec/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
@ -56,7 +56,6 @@ github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
@ -138,8 +137,8 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009 h1:W0lCpv29Hv0UaM1LXb9QlBHLNP8UFfcKjblhVCWftOM=
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200916084744-dbad9cb7cb7a h1:chkwkn8HYWVtTE5DCQNKYlkyptadXYY0+PuyaVdyMo4=
golang.org/x/sys v0.0.0-20200916084744-dbad9cb7cb7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s=

42
main.go
View File

@ -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)