wechaty / getting-started

A Starter Project Template for Wechaty works out-of-the-box
https://gitpod.io/#https://github.com/wechaty/wechaty-getting-started
Apache License 2.0
803 stars 352 forks source link

ding-dong-bot.js can't be started with wechaty-puppet-mock #143

Open suntong opened 4 years ago

suntong commented 4 years ago

Important:Please file the issue follow the template, or we won't help you to solve the problem.

0. Report Issue Guide

  1. Please run the following command and check whether the problem has been fixed:
    rm -rf package-lock.json
    rm -rf node_modules
    npm install

Not fixed.

  1. Please search in FAQ List first, and make sure your problem has not been solved before.

Done.

  1. Please search in the issue first, and make sure your problem had not been reported before

Done.

1. Versions

npm ls wechaty wechaty-puppet wechaty-puppet-mock wechaty-puppet-padplus
wechaty-getting-started@0.1.20 /path/to/wechaty-examples
├─┬ wechaty@0.48.10 
│ └── UNMET PEER DEPENDENCY wechaty-puppet@0.32.3  deduped
├── UNMET PEER DEPENDENCY wechaty-puppet@0.32.3 
├── wechaty-puppet-mock@0.28.1 
└─┬ wechaty-puppet-padplus@0.7.40 
  └─┬ wechaty-puppet-cache@0.1.10
    └── wechaty-puppet@0.24.0 
$ lsb_release -a 
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:    20.04
Codename:   focal

2. Describe the bug

ding-dong-bot.js can't be started with wechaty-puppet-mock

3. To Reproduce

Steps to reproduce the behavior:

  1. remove require('./.util/helper') line from ding-dong-bot.js
  2. under wechaty-getting-started, run

    WECHATY_PUPPET=wechaty-puppet-mock WECHATY_LOG=silly node examples/ding-dong-bot.js

4. Expected behavior

Received mock messages continuously.

5. Actual behavior

Mock messages not received.

6. Full Output Logs

Show Logs ```shell $ WECHATY_PUPPET=wechaty-puppet-mock WECHATY_LOG=silly node examples/ding-dong-bot.js 19:43:45 SILL Puppet Config: WECHATY_LOG set level to silly 19:43:45 INFO Config registering process.on("unhandledRejection") for development/debug 19:43:45 VERB Config constructor() 19:43:46 VERB Wechaty constructor() 19:43:46 VERB StateSwitch constructor(Wechaty, "{"log":{"enableTimestamp":true,"logLevel":5,"prefixFilter":{}}}") 19:43:46 VERB StateSwitch constructor(WechatyReady, "{"log":{"enableTimestamp":true,"logLevel":5,"prefixFilter":{}}}") 19:43:46 VERB Wechaty on(scan, listener) registered 19:43:46 VERB Wechaty on(login, listener) registered 19:43:46 VERB Wechaty on(logout, listener) registered 19:43:46 VERB Wechaty on(message, listener) registered 19:43:46 VERB Wechaty (ding-dong-bot) start() v0.41.17 is starting... 19:43:46 VERB Wechaty id: ckeovwwjo0000vefu2rmm1lwz 19:43:46 SILL StateSwitch on() is false 19:43:46 SILL StateSwitch off() is true 19:43:46 VERB StateSwitch off(true) <- (true) 19:43:46 SILL StateSwitch on() is false 19:43:46 VERB StateSwitch on(pending) <- (false) 19:43:46 VERB MemoryCard constructor("ding-dong-bot") 19:43:46 VERB MemoryCard getStorage() for storage type: N/A 19:43:46 VERB getStorage name: ding-dong-bot, options: {"type":"file"} 19:43:46 VERB StorageFile constructor(ding-dong-bot, ...) 19:43:46 VERB StorageBackend constructor(ding-dong-bot, { type: file }) 19:43:46 VERB MemoryCard load() from storage: StorageFile 19:43:46 VERB StorageFile load() from /path/to/wechaty-getting-started/ding-dong-bot.memory-card.json 19:43:46 VERB Wechaty initPuppet() 19:43:46 VERB MemoryCard multiplex(puppet) 19:43:46 VERB MemoryCard static multiplex(MemoryCard, puppet) 19:43:46 VERB MemoryCard constructor({"name":"ding-dong-bot","multiplex":{"name":"puppet","parent":{"options":{"name":"ding-dong-bot"},"name":"ding-dong-bot","payload":{"\rpuppet\nPUPPET_PUPPETEER":[{"name":"mm_lang","value":"en","domain":".wx.qq.com","path":"/","expires":1586873706,"size":9,"httpOnly":false,"secure":true,"session":false},{"name":"MM_WX_NOTIFY_STATE","value":"1","domain":"wx.qq.com","path":"/","expires":-1,"size":19,"httpOnly":false,"secure":false,"session":true},{"name":"MM_WX_SOUND_STATE","value":"1","domain":"wx.qq.com","path":"/","expires":-1,"size":18,"httpOnly":false,"secure":false,"session":true}]},"multiplexNameList":[],"storage":{"name":"ding-dong-bot","options":{"type":"file"},"absFileName":"/path/to/wechaty-getting-started/ding-dong-bot.memory-card.json"}}}}) 19:43:46 VERB PuppetManager resolve({puppet: wechaty-puppet-mock, puppetOptions: undefined}) 19:43:46 VERB PuppetManager resolveName(wechaty-puppet-mock) 19:43:46 VERB PuppetManager checkModule(wechaty-puppet-mock) 19:43:46 SILL PuppetManager checkModule() wechaty-puppet-mock installed version 0.22.31 satisfied range ^0.22.3 19:43:46 VERB Puppet constructor({}) #0 19:43:46 VERB StateSwitch constructor(PuppetMock, "{"log":{"enableTimestamp":true,"logLevel":5,"prefixFilter":{}}}") 19:43:46 VERB MemoryCard constructor(undefined) 19:43:46 VERB MemoryCard getStorage() for storage type: N/A 19:43:46 VERB MemoryCard load() from storage: N/A 19:43:46 VERB MemoryCard load() no storage 19:43:46 VERB Puppet constructor() watchdog timeout set to 60 seconds 19:43:46 VERB HotImport callerResolve(., /path/to/wechaty-getting-started/node_modules/wechaty-puppet/dist/src/puppet.js) 19:43:46 SILL HotImport callerResolve() callsites() file=/path/to/wechaty-getting-started/node_modules/hot-import/dist/src/hot-import.js, type=Object 19:43:46 SILL HotImport callerResolve() callsites() file=/path/to/wechaty-getting-started/node_modules/wechaty-puppet/dist/src/puppet.js, type=null 19:43:46 SILL HotImport callerResolve() callsites() file=/path/to/wechaty-getting-started/node_modules/wechaty/node_modules/wechaty-puppet-mock/dist/src/puppet-mock.js, type=null 19:43:46 SILL HotImport callerResolve() callerFile=/path/to/wechaty-getting-started/node_modules/wechaty/node_modules/wechaty-puppet-mock/dist/src/puppet-mock.js 19:43:46 VERB Puppet constructor() childClassPath=/path/to/wechaty-getting-started/node_modules/wechaty/node_modules/wechaty-puppet-mock/dist/src 19:43:46 VERB PuppetMock constructor() 19:43:46 VERB PuppetMock constructor() creating the default mocker 19:43:46 VERB Mocker constructor() 19:43:46 SILL MockAccessory static set mocker = "Mocker" 19:43:46 SILL MockAccessory static set mocker = "Mocker" 19:43:46 SILL MockAccessory static set mocker = "Mocker" 19:43:46 VERB Puppet constructor() memory.load() done 19:43:46 VERB Puppet setMemory() 19:43:46 VERB Wechaty initPuppetEventBridge(Puppet#0(ding-dong-bot)) 19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(friendship) (listenerCount:0) registering... 19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(login) (listenerCount:0) registering... 19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(logout) (listenerCount:0) registering... 19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(message) (listenerCount:0) registering... 19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(room-invite) (listenerCount:0) registering... 19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(room-join) (listenerCount:0) registering... 19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(room-leave) (listenerCount:0) registering... 19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(room-topic) (listenerCount:0) registering... 19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(scan) (listenerCount:0) registering... 19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(dong) (listenerCount:0) registering... 19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(error) (listenerCount:0) registering... 19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(heartbeat) (listenerCount:1) registering... 19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(ready) (listenerCount:0) registering... 19:43:46 VERB Wechaty initPuppetEventBridge() puppet.on(reset) (listenerCount:1) registering... 19:43:46 VERB Wechaty initAccessory(Puppet#0(ding-dong-bot)) 19:43:46 SILL Accessory static set wechaty = "Wechaty#ckeovwwjo0000vefu2rmm1lwz<>(ding-dong-bot)" 19:43:46 SILL Accessory static set wechaty = "Wechaty#ckeovwwjo0000vefu2rmm1lwz<>(ding-dong-bot)" 19:43:46 SILL Accessory static set wechaty = "Wechaty#ckeovwwjo0000vefu2rmm1lwz<>(ding-dong-bot)" 19:43:46 SILL Accessory static set wechaty = "Wechaty#ckeovwwjo0000vefu2rmm1lwz<>(ding-dong-bot)" 19:43:46 SILL Accessory static set wechaty = "Wechaty#ckeovwwjo0000vefu2rmm1lwz<>(ding-dong-bot)" 19:43:46 SILL Accessory static set wechaty = "Wechaty#ckeovwwjo0000vefu2rmm1lwz<>(ding-dong-bot)" 19:43:46 SILL Accessory static set wechaty = "Wechaty#ckeovwwjo0000vefu2rmm1lwz<>(ding-dong-bot)" 19:43:46 SILL Accessory static set wechaty = "Wechaty#ckeovwwjo0000vefu2rmm1lwz<>(ding-dong-bot)" 19:43:46 SILL Accessory static set puppet = "Puppet#0(ding-dong-bot)" 19:43:46 SILL Accessory static set puppet = "Puppet#0(ding-dong-bot)" 19:43:46 SILL Accessory static set puppet = "Puppet#0(ding-dong-bot)" 19:43:46 SILL Accessory static set puppet = "Puppet#0(ding-dong-bot)" 19:43:46 SILL Accessory static set puppet = "Puppet#0(ding-dong-bot)" 19:43:46 SILL Accessory static set puppet = "Puppet#0(ding-dong-bot)" 19:43:46 SILL Accessory static set puppet = "Puppet#0(ding-dong-bot)" 19:43:46 SILL Accessory static set puppet = "Puppet#0(ding-dong-bot)" 19:43:46 VERB PuppetMock start() 19:43:46 SILL StateSwitch on() is false 19:43:46 SILL StateSwitch on() is false 19:43:46 VERB StateSwitch on(pending) <- (false) 19:43:46 SILL StateSwitch on() is pending 19:43:46 VERB StateSwitch on(true) <- (pending) 19:43:46 VERB Wechaty on(heartbeat, listener) registered 19:43:46 SILL StateSwitch on() is pending 19:43:46 VERB StateSwitch on(true) <- (pending) 19:43:46 INFO StarterBot Starter Bot Started. 19:43:46 VERB Mocker start() 19:43:46 SILL MockAccessory static set mocker = "Mocker" 19:43:46 SILL MockAccessory static set mocker = "Mocker" 19:43:46 SILL MockAccessory static set mocker = "Mocker" ^C ```

7. Additional context

N.A.

[bug]

huan commented 4 years ago

The wechaty-puppet-mock now will not emit any message any more by default.

You need to specify an Environment for our mocking if you want the mocking environment to interact with your bot.

See: https://github.com/wechaty/wechaty-puppet-mock#mocker--environment

suntong commented 4 years ago

OK. Thanks.

So, how to make use of the wechaty-puppet-mock now?

Looking from the source, it seems to me that I need to launch a "Mocker & Environment" instant first, then start the "Puppet Mock" instant, as my normal client, is it? Apart from SimpleEnvironment(), what else Environment() can we choose?

Also, can we still change the puppet on the fly from out side as it used to be?

I.e., previously it was only a matter of switching to WECHATY_PUPPET=wechaty-puppet-mock from ipad or puppeteer, to start

node examples/ding-dong-bot.js

without changing/touch the script at all. Can we still do that now? Thx!

suntong commented 4 years ago

Bump, Can we still do that now? Thx!

huan commented 4 years ago

Also, can we still change the puppet on the fly from outside as it used to be?

Currently, we can only change puppet to wechaty-puppet-mock on the fly from outside, but if you want to emit auto-generated messages, it can not be set on the fly yet. (PR will be welcome!)

We can start to receive the auto-generated message from puppet mock by the following code:

import {
  PuppetMock,
  Mocker,
  SimpleEnvironment,
}                     from 'wechaty-puppet-mock'

const mocker = new Mocker()
mocker.use(SimpleEnvironment())

const puppet = new PuppetMock({ mocker })
const wechaty = new Wechaty({ puppet })

wechaty.start()

// The Mocker will start perform the SimpleEnvironment...