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

29 lines
607 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-09-13 21:29:45 +00:00
var msg = new Msg({
type: Msg.Type.TOPIC,
from: from,
text: data.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
});
});
};