This repository was archived by the owner on Nov 2, 2023. It is now read-only.
Repository navigation
92.事件文档
takayama edited this page Sep 5, 2021
·
16 revisions
一级事件共有五类
- Event: system 系统类(上下线、验证码、设备锁等)
- Event: message 聊天消息类(群聊、私聊、讨论组)
- Event: request 请求类(好友申请、群申请、群邀请)
- Event: notice 通知类(入群退群、禁言、撤回等)
- Event: sync 同步类(用于同步同账号其他设备的操作)
Event: internal 内部隐藏事件
实例化client后,使用 client.on() 来监听一个事件,常用的比如:
/** 监听上线事件 */
client.on("system.online", ()=>console.log("logged in!"))
/** 监听全部的消息事件 */
client.on("message", (event)=>console.log(event))
/** 监听群消息事件 */
client.on("message.group", (event)=>console.log(event))
/** 监听私聊消息事件 */
client.on("message.private", (event)=>console.log(event))
/** 监听好友申请事件 */
client.on("request.friend.add", (event)=>console.log(event))
/** 监听入群申请事件 */
client.on("request.group.add", (event)=>console.log(event))
/** 监听群邀请事件 */
client.on("request.group.invite", (event)=>console.log(event))
/** 监听全部的通知事件 */
client.on("notice", (event)=>console.log(event))
/** 监听群通知事件 */
client.on("notice.group", (event)=>console.log(event))
/** 监听成员入群事件 */
client.on("notice.group.increase", (event)=>console.log(event))一个事件可以绑定多个监听函数,并且为连续传递,例如:
为 notice 事件绑定的监听器,对所有 notice.*.* 事件都有效
为 notice.group 事件绑定的监听器,对所有 notice.group.* 事件都有效
使用 VScode 编辑器可以获得完整的智能提示
一个 event 的数据可能是如下形式的对象:
{
self_id: 147258369, //登录账号
time: 1621582964, //时间戳
post_type: 'notice', //一级分类
notice_type: 'group', //二级分类
sub_type: 'ban', //三级分类
group_id: 258147369, //群号
operator_id: 369258147, //操作者
user_id: 147258369, //被操作者
duration: 600 //时长(秒)
}
// 这是一个群禁言事件
// 可以通过监听 `notice.group.ban` 或 `notice.group` 或 `notice` 捕获-
system.login.qrcode使用扫码登录时收到二维码事件-
imageBuffer 图片字节集
-
-
system.login.slider收到滑动验证码事件-
urlstring 滑动地址
-
-
system.login.device需要解设备锁事件-
urlstring 设备锁验证地址(用于扫二维码解锁) -
phonestring 密保手机号(用于发短信解锁)
-
-
system.login.error登陆失败事件-
messagestring "密码错误"等详细原因 -
codenumber 错误码
-
-
system.online上线事件,可以开始处理消息 system.offline-
system.offline.network网络不通畅或服务器繁忙,默认自动重登 (见相关配置reconn_interval) -
system.offline.kickoff被其他客户端踢下线,默认不自动重登 (见相关配置kickoff) -
system.offline.frozen被冻结或因特殊原因下线,不自动重登 -
system.offline.unknown未知事件,自动重登(目前尚未遇到过,如果你遇到了请告诉我)-
messagestring 下线原因
-
掉线后,论是否重登,都会触发
system.offline事件
重登成功后会触发system.online事件
-
message.private私聊消息事件 (拥有五四个三级分类friendsinglegroupotherself对应:好友,单向好友,群临时会话,其他临时会话,其他在线设备) -
message.group群聊消息事件 (拥有两个三级分类normalanonymous对应:普通消息,匿名消息,群临时会话) -
message.discuss讨论组消息事件
-
request.friend.add好友请求事件 -
request.friend.single被添加为单向好友事件 -
request.group.add加群申请事件 -
request.group.invite群邀请事件
- notice.friend
-
notice.friend.increase好友增加事件 -
notice.friend.decrease好友减少事件 (被拉黑或自己删除都会触发) -
notice.friend.recall私聊消息撤回事件 -
notice.friend.profile好友资料变更事件 -
notice.friend.poke好友戳一戳事件 - notice.group
-
notice.group.increase群员增加事件 (自己入群、他人入群) -
notice.group.decrease群员减少事件 (自己被踢、他人退群/被踢、解散) -
notice.group.recall群消息撤回事件 -
notice.group.admin群管理员变更事件 -
notice.group.ban群禁言事件 -
notice.group.transfer群转让事件 -
notice.group.poke群戳一戳事件 -
notice.group.setting群设置变更事件
-
sync.message私聊同步事件 -
sync.status在线状态同步事件 -
sync.profile个人资料同步事件 -
sync.readed已读同步事件 有两个三级事件private和group sync.black黑名单同步事件
-
internal.input对方正在输入 -
internal.sso监听所有事件的原始数据包