wechaty / wechaty-puppet-padpro

Apache License 2.0
238 stars 64 forks source link

退出登录的时候未正常获取到用户名信息 #46

Open zhoumh1988 opened 5 years ago

zhoumh1988 commented 5 years ago

1. 版本信息

2. 期待程序运行的结果

退出登录时需要获取到用户名称,并发邮件出来。 举例:Contact <小明> logout at 2019-01-18 15:29:35

3. 程序实际运行的结果

Contact logout at 2019-01-18 15:29:35

4. 解决的步骤

bot.on('logout', (user) => {
    let msg = `${user} logout at ${moment().format('YYYY-MM-DD HH:mm:ss')}`;
    console.warn(msg);
    info.warn(msg);
    // MQPusher是我写的一个消息队列类
    MQPusher.push(`${user} logout at ${moment().format('YYYY-MM-DD HH:mm:ss')}`, 3);
});

改为

bot.on('logout', (user) => {
    let msg = `${user} logout at ${moment().format('YYYY-MM-DD HH:mm:ss')}`;
    console.warn(msg);
    info.warn(msg);
    MQPusher.push(msg, 3);
});

5. 分析原因

原来到代码是调用了2次user对象去获取,猜测在第二次调用的时候user对象应该是被释放了,因此再次调用user的时候user找不到了,是一个空对象。

windmemory commented 5 years ago

Thanks for posting the issue and your solutions here, we will put this into our F&Q.