2016-10-09 19:14:02 +00:00
|
|
|
"use strict";
|
|
|
|
|
2018-01-11 11:33:36 +00:00
|
|
|
const _ = require("lodash");
|
2014-09-13 21:29:45 +00:00
|
|
|
|
2017-07-24 06:01:25 +00:00
|
|
|
class Msg {
|
|
|
|
constructor(attr) {
|
2017-11-29 06:22:03 +00:00
|
|
|
// Some properties need to be copied in the Msg object instead of referenced
|
|
|
|
if (attr) {
|
|
|
|
["from", "target"].forEach((prop) => {
|
|
|
|
if (attr[prop]) {
|
|
|
|
this[prop] = {
|
|
|
|
mode: attr[prop].mode,
|
|
|
|
nick: attr[prop].nick,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-07-24 06:01:25 +00:00
|
|
|
_.defaults(this, attr, {
|
2017-11-29 07:15:27 +00:00
|
|
|
from: {},
|
2018-04-27 10:16:23 +00:00
|
|
|
id: 0,
|
2017-07-24 06:01:25 +00:00
|
|
|
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);
|
|
|
|
}
|
2018-01-31 08:56:06 +00:00
|
|
|
|
|
|
|
isLoggable() {
|
2018-06-03 19:12:17 +00:00
|
|
|
if (this.type === Msg.Type.TOPIC) {
|
|
|
|
// Do not log topic that is sent on channel join
|
|
|
|
return !!this.from.nick;
|
|
|
|
}
|
|
|
|
|
2019-07-17 09:33:59 +00:00
|
|
|
return (
|
2020-06-29 07:51:17 +00:00
|
|
|
this.type !== Msg.Type.MONOSPACE_BLOCK &&
|
2017-11-28 17:56:53 +00:00
|
|
|
this.type !== Msg.Type.ERROR &&
|
2018-06-03 19:12:17 +00:00
|
|
|
this.type !== Msg.Type.TOPIC_SET_BY &&
|
2019-03-07 10:57:31 +00:00
|
|
|
this.type !== Msg.Type.MODE_CHANNEL &&
|
2019-07-17 07:34:23 +00:00
|
|
|
this.type !== Msg.Type.RAW &&
|
2019-10-22 16:44:05 +00:00
|
|
|
this.type !== Msg.Type.WHOIS &&
|
|
|
|
this.type !== Msg.Type.PLUGIN
|
2019-07-17 09:33:59 +00:00
|
|
|
);
|
2018-01-31 08:56:06 +00:00
|
|
|
}
|
2017-07-24 06:01:25 +00:00
|
|
|
}
|
|
|
|
|
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",
|
2019-03-07 10:57:31 +00:00
|
|
|
MODE_CHANNEL: "mode_channel",
|
2020-06-29 07:51:17 +00:00
|
|
|
MONOSPACE_BLOCK: "monospace_block",
|
2014-09-13 21:29:45 +00:00
|
|
|
NICK: "nick",
|
|
|
|
NOTICE: "notice",
|
|
|
|
PART: "part",
|
|
|
|
QUIT: "quit",
|
2016-03-27 15:57:59 +00:00
|
|
|
CTCP: "ctcp",
|
2018-01-02 05:29:29 +00:00
|
|
|
CTCP_REQUEST: "ctcp_request",
|
2017-09-19 15:22:50 +00:00
|
|
|
CHGHOST: "chghost",
|
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",
|
2019-07-17 07:34:23 +00:00
|
|
|
RAW: "raw",
|
2019-10-22 16:44:05 +00:00
|
|
|
PLUGIN: "plugin",
|
2014-09-13 21:29:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Msg;
|