2016-10-09 19:14:02 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-09-13 21:29:45 +00:00
|
|
|
var _ = require("lodash");
|
|
|
|
|
2017-07-24 06:01:25 +00:00
|
|
|
var id = 0;
|
|
|
|
|
|
|
|
class Msg {
|
|
|
|
constructor(attr) {
|
|
|
|
_.defaults(this, attr, {
|
|
|
|
from: "",
|
|
|
|
id: id++,
|
|
|
|
previews: [],
|
|
|
|
text: "",
|
|
|
|
type: Msg.Type.MESSAGE,
|
|
|
|
self: false
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this.time > 0) {
|
|
|
|
this.time = new Date(this.time);
|
|
|
|
} else {
|
|
|
|
this.time = new Date();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
findPreview(link) {
|
|
|
|
return this.previews.find((preview) => preview.link === link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-13 21:29:45 +00:00
|
|
|
Msg.Type = {
|
2016-04-24 15:12:54 +00:00
|
|
|
UNHANDLED: "unhandled",
|
2014-09-13 21:29:45 +00:00
|
|
|
ACTION: "action",
|
|
|
|
ERROR: "error",
|
2016-02-12 11:24:13 +00:00
|
|
|
INVITE: "invite",
|
2014-09-13 21:29:45 +00:00
|
|
|
JOIN: "join",
|
|
|
|
KICK: "kick",
|
|
|
|
MESSAGE: "message",
|
|
|
|
MODE: "mode",
|
|
|
|
MOTD: "motd",
|
|
|
|
NICK: "nick",
|
|
|
|
NOTICE: "notice",
|
|
|
|
PART: "part",
|
|
|
|
QUIT: "quit",
|
2016-03-27 15:57:59 +00:00
|
|
|
CTCP: "ctcp",
|
2014-09-13 21:29:45 +00:00
|
|
|
TOPIC: "topic",
|
2016-03-08 09:26:43 +00:00
|
|
|
TOPIC_SET_BY: "topic_set_by",
|
2017-04-22 12:51:21 +00:00
|
|
|
WHOIS: "whois",
|
|
|
|
BANLIST: "ban_list"
|
2014-09-13 21:29:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Msg;
|