puppet.ts 1.9 KB
Newer Older
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
1
/**
2
 * Wechaty - Wechat for Bot. Connecting ChatBots
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
3
 *
4
 * Interface for Puppet
5
 *
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
6
 * Class Puppet
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
7 8
 *
 * Licenst: ISC
9
 * https://github.com/wechaty/wechaty
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
10 11
 *
 */
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
12

13
import { EventEmitter } from 'events'
14

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
15
import {
L
lijiarui 已提交
16
  Sayable,
17
}                       from './config'
18 19 20 21
import { Contact }      from './contact'
import { Message }      from './message'
import { StateMonitor } from './state-monitor'
import { Room }         from './room'
22

23 24 25
// type ContactGetterFunc = {
//   (id: string): Promise<any>
// }
26

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
27
export abstract class Puppet extends EventEmitter implements Sayable {
28 29
  public userId:  string  | null
  public user:    Contact | null
30 31
  public abstract getContact(id: string): Promise<any>

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
32 33
  public state = new StateMonitor<'live', 'dead'>('Puppet', 'dead')

34 35
  constructor() {
    super()
36 37
  }

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
38
  public abstract async init(): Promise<void>
39

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
40
  public abstract self(): Contact
41

42 43
  public abstract send(message: Message): Promise<void>
  public abstract say(content: string): Promise<void>
44

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
45
  public abstract reset(reason?: string): void
46 47
  public abstract logout(): Promise<void>
  public abstract quit(): Promise<void>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
48

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
49
  public abstract ding(): Promise<string>
50

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
51 52 53
  /**
   * FriendRequest
   */
54 55 56
  public abstract friendRequestSend(contact: Contact, hello?: string): Promise<any>
  public abstract friendRequestAccept(contact: Contact, ticket: string): Promise<any>

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
57 58 59
  /**
   * Room
   */
60 61 62 63
  public abstract roomAdd(room: Room, contact: Contact): Promise<number>
  public abstract roomDel(room: Room, contact: Contact): Promise<number>
  public abstract roomTopic(room: Room, topic: string): Promise<string>
  public abstract roomCreate(contactList: Contact[], topic?: string): Promise<Room>
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
64
  public abstract roomFind(filterFunc: string): Promise<Room[]>
65

Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
66 67 68
  /**
   * Contact
   */
Huan (李卓桓)'s avatar
Huan (李卓桓) 已提交
69
  public abstract contactFind(filterFunc: string): Promise<Contact[]>
70
  public abstract contactAlias(contact: Contact, alias: string|null): Promise<boolean>
71
}