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) {
|
2016-02-14 17:09:51 +00:00
|
|
|
var chan = _.find(network.channels, {name: data.channel});
|
2014-09-13 21:29:45 +00:00
|
|
|
if (typeof chan === "undefined") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var from = data.nick || chan.name;
|
2014-10-10 20:05:25 +00:00
|
|
|
var topic = data.topic;
|
2015-04-26 22:20:54 +00:00
|
|
|
|
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,
|
2015-04-26 22:20:54 +00:00
|
|
|
self: (from.toLowerCase() === irc.me.toLowerCase())
|
2014-09-13 21:29:45 +00:00
|
|
|
});
|
|
|
|
chan.messages.push(msg);
|
|
|
|
client.emit("msg", {
|
|
|
|
chan: chan.id,
|
|
|
|
msg: msg
|
|
|
|
});
|
2015-04-26 22:20:54 +00:00
|
|
|
chan.topic = topic;
|
2014-10-10 20:05:25 +00:00
|
|
|
client.emit("topic", {
|
|
|
|
chan: chan.id,
|
2015-04-26 22:20:54 +00:00
|
|
|
topic: chan.topic
|
2014-10-10 20:05:25 +00:00
|
|
|
});
|
2014-09-13 21:29:45 +00:00
|
|
|
});
|
|
|
|
};
|