hardlounge/src/plugins/irc-events/away.js
Pavel Djundik b8d60ddaa6 Correctly handle away and back events
Also support for self messages

Co-Authored-By: jay2k1 <jay2k1@users.noreply.github.com>
2018-06-20 19:32:19 +03:00

46 lines
814 B
JavaScript

"use strict";
const Msg = require("../../models/msg");
module.exports = function(irc, network) {
const client = this;
irc.on("away", (data) => handleAway(Msg.Type.AWAY, data));
irc.on("back", (data) => handleAway(Msg.Type.BACK, data));
function handleAway(type, data) {
const away = data.message;
if (data.self) {
const msg = new Msg({
self: true,
type: type,
text: away,
time: data.time,
});
network.channels[0].pushMessage(client, msg, true);
return;
}
network.channels.forEach((chan) => {
const user = chan.findUser(data.nick);
if (!user || user.away === away) {
return;
}
const msg = new Msg({
type: type,
text: away || "",
time: data.time,
from: user,
});
chan.pushMessage(client, msg);
user.away = away;
});
}
};