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

33 lines
694 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) {
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;
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,
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
});
chan.topic = topic;
2014-10-10 20:05:25 +00:00
client.emit("topic", {
chan: chan.id,
topic: chan.topic
2014-10-10 20:05:25 +00:00
});
2014-09-13 21:29:45 +00:00
});
};