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,
|
2017-11-15 06:35:15 +00:00
|
|
|
self: false,
|
2017-07-24 06:01:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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",
|
2017-07-10 16:01:20 +00:00
|
|
|
AWAY: "away",
|
2014-09-13 21:29:45 +00:00
|
|
|
ACTION: "action",
|
2017-07-10 16:01:20 +00:00
|
|
|
BACK: "back",
|
2014-09-13 21:29:45 +00:00
|
|
|
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",
|
2017-11-15 06:35:15 +00:00
|
|
|
BANLIST: "ban_list",
|
2014-09-13 21:29:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Msg;
|