2016-10-09 21:14:02 +02:00
|
|
|
"use strict";
|
|
|
|
|
2018-01-03 01:53:42 +01:00
|
|
|
const _ = require("lodash");
|
2017-12-31 10:20:20 +01:00
|
|
|
const Helper = require("../../helper");
|
2017-07-14 19:40:09 +02:00
|
|
|
const Msg = require("../../models/msg");
|
2018-01-02 06:29:29 +01:00
|
|
|
const User = require("../../models/user");
|
2017-12-31 10:20:20 +01:00
|
|
|
const pkg = require("../../../package.json");
|
|
|
|
|
|
|
|
const ctcpResponses = {
|
2019-07-17 11:33:59 +02:00
|
|
|
CLIENTINFO: () =>
|
|
|
|
Object.getOwnPropertyNames(ctcpResponses) // TODO: This is currently handled by irc-framework
|
|
|
|
.filter((key) => key !== "CLIENTINFO" && typeof ctcpResponses[key] === "function")
|
|
|
|
.join(" "),
|
2017-12-31 10:20:20 +01:00
|
|
|
PING: ({message}) => message.substring(5),
|
|
|
|
SOURCE: () => pkg.repository.url,
|
|
|
|
VERSION: () => pkg.name + " " + Helper.getVersion() + " -- " + pkg.homepage,
|
|
|
|
};
|
2016-03-27 17:57:59 +02:00
|
|
|
|
2020-03-21 21:55:36 +01:00
|
|
|
module.exports = function (irc, network) {
|
2017-07-14 19:40:09 +02:00
|
|
|
const client = this;
|
2018-01-02 06:29:29 +01:00
|
|
|
const lobby = network.channels[0];
|
2016-03-27 17:57:59 +02:00
|
|
|
|
2020-03-21 21:55:36 +01:00
|
|
|
irc.on("ctcp response", function (data) {
|
|
|
|
const shouldIgnore = network.ignoreList.some(function (entry) {
|
2018-07-01 20:48:37 +02:00
|
|
|
return Helper.compareHostmask(entry, data);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (shouldIgnore) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-14 19:40:09 +02:00
|
|
|
let chan = network.getChannel(data.nick);
|
2017-11-10 21:44:14 +01:00
|
|
|
|
2016-03-27 17:57:59 +02:00
|
|
|
if (typeof chan === "undefined") {
|
2018-01-02 06:29:29 +01:00
|
|
|
chan = lobby;
|
2016-03-27 17:57:59 +02:00
|
|
|
}
|
|
|
|
|
2017-07-14 19:40:09 +02:00
|
|
|
const msg = new Msg({
|
2016-03-27 17:57:59 +02:00
|
|
|
type: Msg.Type.CTCP,
|
|
|
|
time: data.time,
|
2017-11-10 21:44:14 +01:00
|
|
|
from: chan.getUser(data.nick),
|
2017-11-15 07:35:15 +01:00
|
|
|
ctcpMessage: data.message,
|
2016-03-27 17:57:59 +02:00
|
|
|
});
|
2018-06-04 00:47:30 +02:00
|
|
|
chan.pushMessage(client, msg, true);
|
2016-03-27 17:57:59 +02:00
|
|
|
});
|
2014-09-03 23:43:27 +02:00
|
|
|
|
2018-01-03 01:53:42 +01:00
|
|
|
// Limit requests to a rate of one per second max
|
2019-07-17 11:33:59 +02:00
|
|
|
irc.on(
|
|
|
|
"ctcp request",
|
|
|
|
_.throttle(
|
|
|
|
(data) => {
|
2020-01-01 17:06:42 +01:00
|
|
|
// Ignore echoed ctcp requests that aren't targeted at us
|
|
|
|
// See https://github.com/kiwiirc/irc-framework/issues/225
|
|
|
|
if (
|
|
|
|
data.nick === irc.user.nick &&
|
|
|
|
data.nick !== data.target &&
|
|
|
|
network.irc.network.cap.isEnabled("echo-message")
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-21 21:55:36 +01:00
|
|
|
const shouldIgnore = network.ignoreList.some(function (entry) {
|
2019-07-17 11:33:59 +02:00
|
|
|
return Helper.compareHostmask(entry, data);
|
|
|
|
});
|
2018-07-01 20:48:37 +02:00
|
|
|
|
2019-07-17 11:33:59 +02:00
|
|
|
if (shouldIgnore) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-01 20:48:37 +02:00
|
|
|
|
2020-05-11 20:55:30 +02:00
|
|
|
const target = data.from_server ? data.hostname : data.nick;
|
2019-07-17 11:33:59 +02:00
|
|
|
const response = ctcpResponses[data.type];
|
2017-12-31 10:20:20 +01:00
|
|
|
|
2019-07-17 11:33:59 +02:00
|
|
|
if (response) {
|
2020-05-11 20:55:30 +02:00
|
|
|
irc.ctcpResponse(target, data.type, response(data));
|
2019-07-17 11:33:59 +02:00
|
|
|
}
|
2018-01-02 06:29:29 +01:00
|
|
|
|
2019-07-17 11:33:59 +02:00
|
|
|
// Let user know someone is making a CTCP request against their nick
|
|
|
|
const msg = new Msg({
|
|
|
|
type: Msg.Type.CTCP_REQUEST,
|
|
|
|
time: data.time,
|
2020-05-11 20:55:30 +02:00
|
|
|
from: new User({nick: target}),
|
2019-07-17 11:33:59 +02:00
|
|
|
hostmask: data.ident + "@" + data.hostname,
|
|
|
|
ctcpMessage: data.message,
|
|
|
|
});
|
|
|
|
lobby.pushMessage(client, msg, true);
|
|
|
|
},
|
|
|
|
1000,
|
|
|
|
{trailing: false}
|
|
|
|
)
|
|
|
|
);
|
2014-09-03 23:43:27 +02:00
|
|
|
};
|