juzibot / donut-tester

40 stars 4 forks source link

获取群列表数据混乱 #73

Open ljinkai opened 3 years ago

ljinkai commented 3 years ago

node.js版本: v10.20.1 "wechaty": "^0.51.5"

问题描述: 1、初始化bot后,A扫描二维码登录,调用bot.Room.findAll()获取群列表信息正常,然后调用bot.logout()退出登录 2、B开始扫描二维码登录,调用bot.Room.findAll()获取群列表,获取到的含有A的群列表信息

使用代码如下:

bot = new Wechaty({
        puppet: 'wechaty-puppet-hostie',
        puppetOptions: {
            token,
        }
    });
bot
    .on('scan', (qrcode, status) => {
        qrCodeData.status = status
        console.log("=1=", qrcode, status)
        if (status === ScanStatus.Waiting || status === ScanStatus.Timeout) {
            // require('qrcode-terminal').generate(qrcode) // show qrcode on console

            const qrcodeImageUrl = [
                'https://api.qrserver.com/v1/create-qr-code/?data=',
                encodeURIComponent(qrcode),
            ].join('')

            qrCodeData.qrcode = qrcode
            qrCodeData.qrcodeImageUrl = qrcodeImageUrl

            log.info('StarterBot', 'onScan: %s(%s) - %s', ScanStatus[status], status, qrcodeImageUrl)
        } else {
            log.info('StarterBot', 'onScan: %s(%s)', ScanStatus[status], status)
        }
    })
    .on('login', async function(user) {
        log.info('StarterBot', '%s login', JSON.stringify(user))

        setTimeout(async () => { // auto logout after 10 minutes
            await bot.logout()
            log.info('auto logout', '%s logout', user.name())
        }, 600000)
    })
   .on('ready', async function() {
            console.log('Bot ready now.')
            const roomList = await bot.Room.findAll();// 这个地方获取的群是混乱的
            console.log("rommList:" + roomList.length); 
        })
    .start()
    .catch(e => {
        console.error(e)
        // process.exit(1)
    })
su-chang commented 3 years ago

建议尝试在on('ready') 事件中获取群列表

ljinkai commented 3 years ago

建议尝试在on('ready') 事件中获取群列表

已经改成ready事件中获取,B登录后,调用await bot.Room.findAll() 还是获取到了A中的群?