MCPcopy
hub / github.com/wechaty/wechaty / initPuppet

Method initPuppet

src/wechaty.ts:380–418  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

378 }
379
380 private async initPuppet (): Promise<void> {
381 log.verbose('Wechaty', 'initPuppet() %s', this.options.puppet || '')
382
383 const initialized = !!this.puppet
384
385 if (initialized) {
386 log.verbose('Wechaty', 'initPuppet(%s) had already been initialized, no need to init twice', this.options.puppet)
387 return
388 }
389
390 if (!this.memory) {
391 throw new Error('no memory')
392 }
393
394 const puppet = this.options.puppet || config.systemPuppetName()
395 const puppetMemory = this.memory.multiplex(PUPPET_MEMORY_NAME)
396
397 const puppetInstance = await PuppetManager.resolve({
398 puppet,
399 puppetOptions : this.options.puppetOptions,
400 // wechaty : this,
401 })
402
403 /**
404 * Plug the Memory Card to Puppet
405 */
406 puppetInstance.setMemory(puppetMemory)
407
408 this.initPuppetEventBridge(puppetInstance)
409 this.wechatifyUserModules(puppetInstance)
410
411 /**
412 * Private Event
413 * emit puppet when set
414 *
415 * Huan(202005)
416 */
417 ;(this.emit as any)('puppet', puppetInstance)
418 }
419
420 protected initPuppetEventBridge (puppet: Puppet) {
421 log.verbose('Wechaty', 'initPuppetEventBridge(%s)', puppet)

Callers 1

startMethod · 0.95

Calls 4

initPuppetEventBridgeMethod · 0.95
wechatifyUserModulesMethod · 0.95
systemPuppetNameMethod · 0.80
resolveMethod · 0.80

Tested by

no test coverage detected