1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-06-30 20:03:24 +00:00

Compare commits

..

6 Commits

Author SHA1 Message Date
c31169b99b fix #298. 2020-09-20 00:29:50 +08:00
b5b6117487 fix server. 2020-09-20 00:00:53 +08:00
4662f1e170 update MiraiGo. fix #288 2020-09-19 23:37:40 +08:00
ea65e545ad supported: get_stranger_info. 2020-09-19 17:02:21 +08:00
d67621487d update MiraiGo. fix #278 2020-09-19 16:46:19 +08:00
c4e54446c5 update MiraiGo. fix #283 2020-09-17 08:48:09 +08:00
6 changed files with 65 additions and 13 deletions

View File

@ -497,6 +497,27 @@ func (bot *CQBot) CQGetGroupHonorInfo(groupId int64, t string) MSG {
return OK(msg)
}
// https://github.com/howmanybots/onebot/blob/master/v11/specs/api/public.md#get_stranger_info-%E8%8E%B7%E5%8F%96%E9%99%8C%E7%94%9F%E4%BA%BA%E4%BF%A1%E6%81%AF
func (bot *CQBot) CQGetStrangerInfo(userId int64) MSG {
info, err := bot.Client.GetSummaryInfo(userId)
if err != nil {
return Failed(100)
}
return OK(MSG{
"user_id": info.Uin,
"nickname": info.Nickname,
"sex": func() string {
if info.Sex == 1 {
return "female"
}
return "male"
}(),
"age": info.Age,
"level": info.Level,
"login_days": info.LoginDays,
})
}
// https://cqhttp.cc/docs/4.15/#/API?id=-handle_quick_operation-%E5%AF%B9%E4%BA%8B%E4%BB%B6%E6%89%A7%E8%A1%8C%E5%BF%AB%E9%80%9F%E6%93%8D%E4%BD%9C
// https://github.com/richardchien/coolq-http-api/blob/master/src/cqhttp/plugins/web/http.cpp#L376
func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {

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-20200913133024-ad43b3f471e2
github.com/Mrs4s/MiraiGo v0.0.0-20200919153352-249af274638d
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

8
go.sum
View File

@ -1,9 +1,9 @@
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-20200913112343-ad5531c3db09 h1:zTe9IBmO+z6icSwjT2PgI9aMIIwlfWc00cFEz2+j9rc=
github.com/Mrs4s/MiraiGo v0.0.0-20200913112343-ad5531c3db09/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20200913133024-ad43b3f471e2 h1:otRnJmFOuRfK2ts5x6eOqc/vTIhUN4IYKcldjhN/IQY=
github.com/Mrs4s/MiraiGo v0.0.0-20200913133024-ad43b3f471e2/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20200919083021-4013c077186d h1:LZ1pjJJ7sD/AOL8tvkTB9bPc0DiOErCNN+wWXUMyvX0=
github.com/Mrs4s/MiraiGo v0.0.0-20200919083021-4013c077186d/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20200919153352-249af274638d h1:nGJSE9xQBeDiugBKKX0vUOq51MqlUEm/y2FMfZFH/w4=
github.com/Mrs4s/MiraiGo v0.0.0-20200919153352-249af274638d/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=

28
main.go
View File

@ -237,9 +237,16 @@ func main() {
}
})
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) {
log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. 服务器地址: %v:%v 服务器位置: %v", e.Servers[0].Server, e.Servers[0].Port, e.Servers[0].Location)
log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. 地址信息已储存到 servers.bin 文件")
_ = ioutil.WriteFile("servers.bin", binary.NewWriterF(func(w *binary.Writer) {
w.WriteUInt16(uint16(len(e.Servers)))
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)
@ -250,12 +257,25 @@ func main() {
})
if global.PathExists("servers.bin") {
if data, err := ioutil.ReadFile("servers.bin"); err == nil {
func() {
defer func() {
if pan := recover(); pan != nil {
log.Error("读取服务器地址时出现错误: %v", pan)
}
}()
r := binary.NewReader(data)
r.ReadUInt16()
cli.CustomServer = &net.TCPAddr{
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()

View File

@ -333,6 +333,11 @@ func (s *httpServer) GetVipInfo(c *gin.Context) {
c.JSON(200, s.bot.CQGetVipInfo(uid))
}
func (s *httpServer) GetStrangerInfo(c *gin.Context) {
uid, _ := strconv.ParseInt(getParam(c, "user_id"), 10, 64)
c.JSON(200, s.bot.CQGetStrangerInfo(uid))
}
func (s *httpServer) HandleQuickOperation(c *gin.Context) {
if c.Request.Method != "POST" {
c.AbortWithStatus(404)
@ -486,6 +491,9 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
"_get_vip_info": func(s *httpServer, c *gin.Context) {
s.GetVipInfo(c)
},
"get_stranger_info": func(s *httpServer, c *gin.Context) {
s.GetStrangerInfo(c)
},
"reload_event_filter": func(s *httpServer, c *gin.Context) {
s.ReloadEventFilter(c)
},

View File

@ -486,6 +486,9 @@ var wsApi = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
"can_send_record": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQCanSendRecord()
},
"get_stranger_info": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetStrangerInfo(p.Get("user_id").Int())
},
"get_status": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
return bot.CQGetStatus()
},