1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-04 19:17:37 +08:00

feature client status updated event.

This commit is contained in:
Mrs4s 2021-01-23 00:19:48 +08:00
parent 8a81b67511
commit 61625f2e32
2 changed files with 22 additions and 0 deletions

View File

@ -77,6 +77,7 @@ func NewQQBot(cli *client.QQClient, conf *global.JSONConfig) *CQBot {
bot.Client.OnNewFriendAdded(bot.friendAddedEvent)
bot.Client.OnGroupInvited(bot.groupInvitedEvent)
bot.Client.OnUserWantJoinGroup(bot.groupJoinReqEvent)
bot.Client.OnOtherClientStatusChanged(bot.otherClientStatusChangedEvent)
go func() {
i := conf.HeartbeatInterval
if i < 0 {

View File

@ -413,6 +413,27 @@ func (bot *CQBot) groupJoinReqEvent(c *client.QQClient, e *client.UserJoinGroupR
})
}
func (bot *CQBot) otherClientStatusChangedEvent(c *client.QQClient, e *client.OtherClientStatusChangedEvent) {
if e.Online {
log.Infof("Bot 账号在客户端 %v (%v) 登录.", e.Client.DeviceName, e.Client.DeviceKind)
} else {
log.Infof("Bot 账号在客户端 %v (%v) 登出.", e.Client.DeviceName, e.Client.DeviceKind)
}
bot.dispatchEventMessage(MSG{
"post_type": "notice",
"notice_type": "client_status",
"client": MSG{
"online": e.Online,
"app_id": e.Client.AppId,
"device_name": e.Client.DeviceName,
"device_kind": e.Client.DeviceKind,
},
"self_id": c.Uin,
"time": time.Now().Unix(),
})
}
func (bot *CQBot) groupIncrease(groupCode, operatorUin, userUin int64) MSG {
return MSG{
"post_type": "notice",