hardlounge/src/plugins/irc-events/topic.js

34 lines
707 B
JavaScript
Raw Normal View History

2014-09-13 17:29:45 -04:00
var _ = require("lodash");
var Msg = require("../../models/msg");
module.exports = function(irc, network) {
var client = this;
irc.on("topic", function(data) {
2016-02-14 12:09:51 -05:00
var chan = _.find(network.channels, {name: data.channel});
2014-09-13 17:29:45 -04:00
if (typeof chan === "undefined") {
return;
}
var from = data.nick || chan.name;
2014-10-10 16:05:25 -04:00
var topic = data.topic;
2014-09-13 17:29:45 -04:00
var msg = new Msg({
type: Msg.Type.TOPIC,
2014-10-04 08:31:45 -04:00
mode: chan.getMode(from),
2014-09-13 17:29:45 -04:00
from: from,
2014-10-10 16:05:25 -04:00
text: topic,
2016-02-23 11:22:41 -05:00
isSetByChan: from === chan.name,
self: from === irc.user.nick
2014-09-13 17:29:45 -04:00
});
chan.messages.push(msg);
client.emit("msg", {
chan: chan.id,
msg: msg
});
chan.topic = topic;
2014-10-10 16:05:25 -04:00
client.emit("topic", {
chan: chan.id,
topic: chan.topic
2014-10-10 16:05:25 -04:00
});
2014-09-13 17:29:45 -04:00
});
};