puppet.ts 2.0 KB
Newer Older
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1
/**
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
2 3 4
 * Wechat for Bot. and for human who can talk with bot/robot
 *
 * Interface for puppet
5
 *
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
6
 * Class Puppet
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
7 8 9 10 11
 *
 * Licenst: ISC
 * https://github.com/zixia/wechaty
 *
 */
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
12

13
const EventEmitter = require('events')
14 15

import log from './brolog-env'
16 17 18 19

class Puppet extends EventEmitter {
  constructor() {
    super()
20 21

    /*
22
     * @deprecated
23 24 25
     * connected / disconnected
     * connecting / disconnecting
     */
26 27 28 29 30 31 32 33 34 35 36 37 38
    // this._readyState = 'disconnected'

    this.targetState('dead')
    this.currentState('dead')
  }

  // targetState : 'live' | 'dead'
  targetState(newState) {
    if (newState) {
      log.verbose('Puppet', 'targetState(%s)', newState)
      this._targetState = newState
    }
    return this._targetState
39 40
  }

41 42
  // currentState : 'birthing' | 'killing'
  currentState(newState) {
43
    if (newState) {
44 45
      log.verbose('Puppet', 'currentState(%s)', newState)
      this._currentState = newState
46
    }
47
    return this._currentState
48 49
  }

50 51 52 53 54 55 56 57 58
  // @deprecated
  // readyState(newState) {
  //   if (newState) {
  //     log.verbose('Puppet', 'readyState() set to "%s"', newState)
  //     this._readyState = newState
  //   }
  //   return this._readyState
  // }

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
59
  /**
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
60 61 62
   * let puppet send message
   *
   * @param <Message> message - the message to be sent
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
63
   * @return <Promise>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
64
   */
65
  send(message)         { throw new Error('To Be Implemented') }
66
  reply(message, reply) { throw new Error('To Be Implemented') }
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
67

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
68
  logout()      { throw new Error('To Be Implementsd') }
69
  quit()        { throw new Error('To Be Implementsd') }
70
  ding()        { throw new Error('To Be Implementsd') }
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
71

72
  getContact(id)  { // for unit testing
73
    log.verbose('Puppet', `Interface method getContact(${id})`)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
74 75
    throw new Error('Absolute Interface Method should never to be called')
    // return Promise.resolve({UserName: 'WeChaty', NickName: 'Puppet'})
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
76
  }
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
77

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
78
  // () { throw new Error('To Be Implemented')  }
79 80
}

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
81 82 83
Object.assign(Puppet, {
  Message:    require('./message')
  , Contact:  require('./contact')
84
  , Room:     require('./room')
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
85
})
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
86

87 88
// module.exports = Puppet
export default Puppet