Merge pull request #1928 from thelounge/xpaw/ctcp-resp

Rewrite ctcp handling
This commit is contained in:
Jérémie Astori 2018-02-20 00:12:30 -05:00 committed by GitHub
commit 7975f4debc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 14 deletions

View file

@ -240,7 +240,7 @@ Client.prototype.connect = function(args) {
}
network.irc = new ircFramework.Client({
version: pkg.name + " " + Helper.getVersion() + " -- " + pkg.homepage,
version: false, // We handle it ourselves
host: network.host,
port: network.port,
nick: nick,

View file

@ -1,6 +1,18 @@
"use strict";
const Helper = require("../../helper");
const Msg = require("../../models/msg");
const pkg = require("../../../package.json");
const ctcpResponses = {
CLIENTINFO: () => Object // TODO: This is currently handled by irc-framework
.getOwnPropertyNames(ctcpResponses)
.filter((key) => key !== "CLIENTINFO" && typeof ctcpResponses[key] === "function")
.join(" "),
PING: ({message}) => message.substring(5),
SOURCE: () => pkg.repository.url,
VERSION: () => pkg.name + " " + Helper.getVersion() + " -- " + pkg.homepage,
};
module.exports = function(irc, network) {
const client = this;
@ -23,19 +35,10 @@ module.exports = function(irc, network) {
});
irc.on("ctcp request", (data) => {
switch (data.type) {
case "PING": {
const split = data.message.split(" ");
if (split.length === 2) {
irc.ctcpResponse(data.nick, "PING", split[1]);
}
break;
}
case "SOURCE": {
const packageJson = require("../../../package.json");
irc.ctcpResponse(data.nick, "SOURCE", packageJson.repository.url);
break;
}
const response = ctcpResponses[data.type];
if (response) {
irc.ctcpResponse(data.nick, data.type, response(data));
}
});
};