-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.ts
74 lines (63 loc) · 1.43 KB
/
message.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"use strict";
import Adapter from "./adapter";
import Robot from "./robot";
import Room from "./room";
import User from "./user";
export class Message {
robot: Robot;
adapter: Adapter;
user: User;
done: any;
rawData: any;
room: Room;
msgType = "message";
constructor(user, adapter, done, room?: Room) {
this.robot = adapter.robot;
this.adapter = adapter;
this.user = user;
if (!done) {
this.done = false;
} else {
this.done = done;
}
if (this.room) {
this.room = room;
}
}
finish() {
this.done = true;
}
}
export class TextMessage extends Message {
text: string;
room: Room;
id: string;
constructor(user: User, text: string, room: any, id: string, adapter: Adapter, rawData: any) {
if (!user || !text) {
throw new Error(
`Cannot create text message without user or text. user: ${user} text: ${text}`
);
}
super(user, adapter, false);
this.msgType = "text";
this.text = text;
this.room = room;
this.id = id;
this.rawData = rawData;
}
match(regex) {
return this.text.match(regex);
}
toString() {
return this.text;
}
}
export class EnterMessage extends Message {}
export class LeaveMessage extends Message {}
export class TopicMessage extends TextMessage {}
export class CatchAllMessage extends Message {
constructor(message) {
super(message.user, null, false);
this.rawData = message;
}
}