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

36 lines
753 B
JavaScript
Raw Normal View History

2014-09-13 21:29:45 +00:00
var _ = require("lodash");
var Msg = require("../../models/msg");
module.exports = function(irc, network) {
var client = this;
irc.on("topic", function(data) {
var chan = _.findWhere(network.channels, {name: data.channel});
if (typeof chan === "undefined") {
return;
}
var from = data.nick || chan.name;
2014-09-14 18:49:42 +00:00
var self = false;
if (from.toLowerCase() == irc.me.toLowerCase()) {
self = true;
}
2014-10-10 20:05:25 +00:00
var topic = data.topic;
2014-09-13 21:29:45 +00:00
var msg = new Msg({
type: Msg.Type.TOPIC,
2014-10-04 12:31:45 +00:00
mode: chan.getMode(from),
2014-09-13 21:29:45 +00:00
from: from,
2014-10-10 20:05:25 +00:00
text: topic,
2014-09-14 18:49:42 +00:00
self: self
2014-09-13 21:29:45 +00:00
});
chan.messages.push(msg);
client.emit("msg", {
chan: chan.id,
msg: msg
});
2014-10-10 20:05:25 +00:00
chan.topic = topic
client.emit("topic", {
chan: chan.id,
topic: _.escape(topic)
2014-10-10 20:05:25 +00:00
});
2014-09-13 21:29:45 +00:00
});
};