From 7330dc9553a437b8386845a3df83165a4d00e607 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 31 Dec 2017 11:20:20 +0200 Subject: [PATCH] Rewrite ctcp handling --- src/client.js | 2 +- src/plugins/irc-events/ctcp.js | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/client.js b/src/client.js index 668ec677..eff05433 100644 --- a/src/client.js +++ b/src/client.js @@ -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, diff --git a/src/plugins/irc-events/ctcp.js b/src/plugins/irc-events/ctcp.js index d1a9e215..752528e6 100644 --- a/src/plugins/irc-events/ctcp.js +++ b/src/plugins/irc-events/ctcp.js @@ -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)); } }); };