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

46 lines
965 B
JavaScript
Raw Normal View History

"use strict";
2014-09-13 23:29:45 +02:00
var Msg = require("../../models/msg");
module.exports = function(irc, network) {
var client = this;
irc.on("topic", function(data) {
2016-03-20 15:28:47 +01:00
var chan = network.getChannel(data.channel);
2014-09-13 23:29:45 +02:00
if (typeof chan === "undefined") {
return;
}
2014-09-13 23:29:45 +02:00
var msg = new Msg({
2016-03-12 10:36:55 +01:00
time: data.time,
2014-09-13 23:29:45 +02:00
type: Msg.Type.TOPIC,
mode: (data.nick && chan.getMode(data.nick)) || "",
from: data.nick,
text: data.topic,
self: data.nick === irc.user.nick,
2014-09-13 23:29:45 +02:00
});
chan.pushMessage(client, msg);
chan.topic = data.topic;
2014-10-10 22:05:25 +02:00
client.emit("topic", {
chan: chan.id,
topic: chan.topic,
2014-10-10 22:05:25 +02:00
});
2014-09-13 23:29:45 +02:00
});
irc.on("topicsetby", function(data) {
2016-03-20 15:28:47 +01:00
var chan = network.getChannel(data.channel);
if (typeof chan === "undefined") {
return;
}
var msg = new Msg({
type: Msg.Type.TOPIC_SET_BY,
mode: chan.getMode(data.nick),
nick: data.nick,
2016-03-20 18:18:43 +01:00
when: new Date(data.when * 1000),
self: data.nick === irc.user.nick,
});
chan.pushMessage(client, msg);
});
2014-09-13 23:29:45 +02:00
};