mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-06-30 20:03:24 +00:00
Compare commits
4 Commits
v0.9.25
...
v0.9.25-fi
Author | SHA1 | Date | |
---|---|---|---|
4662f1e170 | |||
ea65e545ad | |||
d67621487d | |||
c4e54446c5 |
21
coolq/api.go
21
coolq/api.go
@ -497,6 +497,27 @@ func (bot *CQBot) CQGetGroupHonorInfo(groupId int64, t string) MSG {
|
|||||||
return OK(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://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
|
// 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 {
|
func (bot *CQBot) CQHandleQuickOperation(context, operation gjson.Result) MSG {
|
||||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
|
|||||||
go 1.14
|
go 1.14
|
||||||
|
|
||||||
require (
|
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/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
|
||||||
github.com/gin-gonic/gin v1.6.3
|
github.com/gin-gonic/gin v1.6.3
|
||||||
github.com/go-playground/validator/v10 v10.3.0 // indirect
|
github.com/go-playground/validator/v10 v10.3.0 // indirect
|
||||||
|
8
go.sum
8
go.sum
@ -1,9 +1,9 @@
|
|||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
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/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-20200919083021-4013c077186d h1:LZ1pjJJ7sD/AOL8tvkTB9bPc0DiOErCNN+wWXUMyvX0=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200913112343-ad5531c3db09/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
|
github.com/Mrs4s/MiraiGo v0.0.0-20200919083021-4013c077186d/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200913133024-ad43b3f471e2 h1:otRnJmFOuRfK2ts5x6eOqc/vTIhUN4IYKcldjhN/IQY=
|
github.com/Mrs4s/MiraiGo v0.0.0-20200919153352-249af274638d h1:nGJSE9xQBeDiugBKKX0vUOq51MqlUEm/y2FMfZFH/w4=
|
||||||
github.com/Mrs4s/MiraiGo v0.0.0-20200913133024-ad43b3f471e2/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
|
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 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
|
||||||
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
|
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=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
|
8
main.go
8
main.go
@ -237,7 +237,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) {
|
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) {
|
_ = ioutil.WriteFile("servers.bin", binary.NewWriterF(func(w *binary.Writer) {
|
||||||
w.WriteUInt16(uint16(len(e.Servers)))
|
w.WriteUInt16(uint16(len(e.Servers)))
|
||||||
for _, s := range e.Servers {
|
for _, s := range e.Servers {
|
||||||
@ -251,10 +251,12 @@ func main() {
|
|||||||
if global.PathExists("servers.bin") {
|
if global.PathExists("servers.bin") {
|
||||||
if data, err := ioutil.ReadFile("servers.bin"); err == nil {
|
if data, err := ioutil.ReadFile("servers.bin"); err == nil {
|
||||||
r := binary.NewReader(data)
|
r := binary.NewReader(data)
|
||||||
r.ReadUInt16()
|
var addr []*net.TCPAddr
|
||||||
cli.CustomServer = &net.TCPAddr{
|
for i := 0; i < int(r.ReadUInt16()); i++ {
|
||||||
|
addr = append(addr, &net.TCPAddr{
|
||||||
IP: net.ParseIP(r.ReadString()),
|
IP: net.ParseIP(r.ReadString()),
|
||||||
Port: int(r.ReadUInt16()),
|
Port: int(r.ReadUInt16()),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -333,6 +333,11 @@ func (s *httpServer) GetVipInfo(c *gin.Context) {
|
|||||||
c.JSON(200, s.bot.CQGetVipInfo(uid))
|
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) {
|
func (s *httpServer) HandleQuickOperation(c *gin.Context) {
|
||||||
if c.Request.Method != "POST" {
|
if c.Request.Method != "POST" {
|
||||||
c.AbortWithStatus(404)
|
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) {
|
"_get_vip_info": func(s *httpServer, c *gin.Context) {
|
||||||
s.GetVipInfo(c)
|
s.GetVipInfo(c)
|
||||||
},
|
},
|
||||||
|
"get_stranger_info": func(s *httpServer, c *gin.Context) {
|
||||||
|
s.GetStrangerInfo(c)
|
||||||
|
},
|
||||||
"reload_event_filter": func(s *httpServer, c *gin.Context) {
|
"reload_event_filter": func(s *httpServer, c *gin.Context) {
|
||||||
s.ReloadEventFilter(c)
|
s.ReloadEventFilter(c)
|
||||||
},
|
},
|
||||||
|
@ -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 {
|
"can_send_record": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQCanSendRecord()
|
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 {
|
"get_status": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||||
return bot.CQGetStatus()
|
return bot.CQGetStatus()
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user