mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-06 12:03:50 +08:00
feature get_online_clients.
This commit is contained in:
parent
2ac94a7e95
commit
164feca7c7
20
coolq/api.go
20
coolq/api.go
@ -868,6 +868,26 @@ func (bot *CQBot) CQGetGroupMessageHistory(groupId int64, seq int64) MSG {
|
||||
})
|
||||
}
|
||||
|
||||
func (bot *CQBot) CQGetOnlineClients(noCache bool) MSG {
|
||||
if noCache {
|
||||
if err := bot.Client.RefreshStatus(); err != nil {
|
||||
log.Warnf("刷新客户端状态时出现问题 %v", err)
|
||||
return Failed(100, "REFRESH_STATUS_ERROR", err.Error())
|
||||
}
|
||||
}
|
||||
var d []MSG
|
||||
for _, oc := range bot.Client.OnlineClients {
|
||||
d = append(d, MSG{
|
||||
"app_id": oc.AppId,
|
||||
"device_name": oc.DeviceName,
|
||||
"device_kind": oc.DeviceKind,
|
||||
})
|
||||
}
|
||||
return OK(MSG{
|
||||
"clients": d,
|
||||
})
|
||||
}
|
||||
|
||||
func (bot *CQBot) CQCanSendImage() MSG {
|
||||
return OK(MSG{"yes": true})
|
||||
}
|
||||
|
@ -427,6 +427,10 @@ func GetGroupMessageHistory(s *httpServer, c *gin.Context) {
|
||||
c.JSON(200, s.bot.CQGetGroupMessageHistory(gid, seq))
|
||||
}
|
||||
|
||||
func GetOnlineClients(s *httpServer, c *gin.Context) {
|
||||
c.JSON(200, s.bot.CQGetOnlineClients(getParamOrDefault(c, "no_cache", "false") == "true"))
|
||||
}
|
||||
|
||||
func HandleQuickOperation(s *httpServer, c *gin.Context) {
|
||||
if c.Request.Method != "POST" {
|
||||
c.AbortWithStatus(404)
|
||||
@ -578,6 +582,7 @@ var httpApi = map[string]func(s *httpServer, c *gin.Context){
|
||||
".ocr_image": OcrImage,
|
||||
"ocr_image": OcrImage,
|
||||
"get_group_at_all_remain": GetGroupAtAllRemain,
|
||||
"get_online_clients": GetOnlineClients,
|
||||
".get_word_slices": GetWordSlices,
|
||||
}
|
||||
|
||||
|
@ -580,6 +580,9 @@ var wsAPI = map[string]func(*coolq.CQBot, gjson.Result) coolq.MSG{
|
||||
"get_group_at_all_remain": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
return bot.CQGetAtAllRemain(p.Get("group_id").Int())
|
||||
},
|
||||
"get_online_clients": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
return bot.CQGetOnlineClients(p.Get("no_cache").Bool())
|
||||
},
|
||||
".get_word_slices": func(bot *coolq.CQBot, p gjson.Result) coolq.MSG {
|
||||
return bot.CQGetWordSlices(p.Get("content").Str)
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user