wechaty.js 1.1 KB
Newer Older
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1 2
const EventEmitter = require('events')
//const Util = require('util');
3 4


Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
5 6 7 8 9 10
const Puppet      = require('./puppet')
const PuppetWeb   = require('./puppet-web')

const Message     = require('./message')
const Contact     = require('./contact')
const Group       = require('./group')
11 12 13

class Wechaty extends EventEmitter {
  // cookie,Uin, Sid,SKey
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
14
  constructor() {
15
    super()
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
16 17
    this.puppet   = new Puppet.Web()
    /*
18 19 20
    this.contact  = new Contact(this.puppet)
    this.group    = new Group(this.puppet)
    this.message  = new Message(this.puppet)
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
21
    */
22 23 24 25 26 27 28 29 30 31 32 33

    this.puppet.on('message', (e) => {
      this.emit('message', e)
    })
    this.puppet.on('login', (e) => {
      this.emit('login', e)
    })
    this.puppet.on('logout', (e) => {
      this.emit('logout', e)
    })
  }

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
34 35 36
  init()          { return this.puppet.init() }
  currentUser()   { return this.puppet.currentUser() }
  send(message)   { return this.puppet.send(message) }
37

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
38
  ding()          { return 'dong' }
39 40
}

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
41
Puppet.Web = PuppetWeb
42

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
43 44 45 46 47 48
Object.assign(Wechaty, {
  Puppet:     Puppet
  , Message:  Message
  , Contact:  Contact
  , Group:    Group
})
49 50

module.exports = Wechaty