wechaty / puppet-mock

Puppet Mocker for Wechaty (& A Puppet Template Starter)
https://paka.dev/npm/wechaty-puppet-mock
Apache License 2.0
45 stars 14 forks source link

bot receives messages that are not sent to him #50

Open panlina opened 7 months ago

panlina commented 7 months ago

In the following code, I create 3 contacts:

Then I let contactA send a message to contactB. I suppose bot will not receive this message event because it's not sent to user or any room that he is in, but actually it receives this message event. Why?

var { Wechaty, Message } = require('wechaty')
var { PuppetMock, mock: { Mocker } } = require('wechaty-puppet-mock');

async function main() {
    var mocker = new Mocker();

    var puppet = new PuppetMock({ mocker });
    var bot = new Wechaty({ puppet });

    bot.on('message', message => {
        console.log(`bot received ${message.text()} from ${message.talker().payload.id}`);
    });

    await bot.start();

    mocker.scan('https://github.com/wechaty', 1);
    var user = mocker.createContact({ id: 'user' });
    mocker.login(user);

    var contactA = mocker.createContact({ id: 'contactA' });
    var contactB = mocker.createContact({ id: 'contactB' });

    contactA.say("a").to(contactB);
};

main();

The consequence is that, if I use() a Wechaty plugin, it will not work, because Wechaty plugin never suppose it will receive any messages that is not sent to the logged-in user, isn't it?

huan commented 4 months ago

Hi Panlina,

It's great to read your issue!

Very few people will do bot testing in our community, and you are one of them. ;-)

Can you join our Discord community and DM me? I'd love to work with you to improve the puppet-mock for Wechaty!

https://discord.gg/7q8NBZbQzt