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

41 lines
857 B
JavaScript
Raw Normal View History

"use strict";
2017-07-14 19:40:09 +02:00
const Msg = require("../../models/msg");
module.exports = function(irc, network) {
2017-07-14 19:40:09 +02:00
const client = this;
irc.on("ctcp response", function(data) {
2017-07-14 19:40:09 +02:00
let chan = network.getChannel(data.nick);
if (typeof chan === "undefined") {
chan = network.channels[0];
}
2017-07-14 19:40:09 +02:00
const msg = new Msg({
type: Msg.Type.CTCP,
time: data.time,
from: data.nick,
ctcpType: data.type,
ctcpMessage: data.message,
});
chan.pushMessage(client, msg);
});
2014-09-03 23:43:27 +02:00
2017-07-14 19:40:09 +02:00
irc.on("ctcp request", (data) => {
switch (data.type) {
2017-07-14 19:40:09 +02:00
case "PING": {
const split = data.message.split(" ");
2015-10-01 00:39:57 +02:00
if (split.length === 2) {
irc.ctcpResponse(data.nick, "PING", split[1]);
2014-09-03 23:43:27 +02:00
}
break;
}
2017-07-14 19:40:09 +02:00
case "SOURCE": {
const packageJson = require("../../../package.json");
irc.ctcpResponse(data.nick, "SOURCE", packageJson.repository.url);
break;
}
}
2014-09-03 23:43:27 +02:00
});
};