Rewrite ctcp handling

This commit is contained in:
Pavel Djundik 2017-12-31 11:20:20 +02:00 committed by Jérémie Astori
parent 95abf830cd
commit 7330dc9553
No known key found for this signature in database
GPG Key ID: B9A4F245CD67BDE8
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({ network.irc = new ircFramework.Client({
version: pkg.name + " " + Helper.getVersion() + " -- " + pkg.homepage, version: false, // We handle it ourselves
host: network.host, host: network.host,
port: network.port, port: network.port,
nick: nick, nick: nick,

View File

@ -1,6 +1,18 @@
"use strict"; "use strict";
const Helper = require("../../helper");
const Msg = require("../../models/msg"); 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) { module.exports = function(irc, network) {
const client = this; const client = this;
@ -23,19 +35,10 @@ module.exports = function(irc, network) {
}); });
irc.on("ctcp request", (data) => { irc.on("ctcp request", (data) => {
switch (data.type) { const response = ctcpResponses[data.type];
case "PING": {
const split = data.message.split(" "); if (response) {
if (split.length === 2) { irc.ctcpResponse(data.nick, data.type, response(data));
irc.ctcpResponse(data.nick, "PING", split[1]);
}
break;
}
case "SOURCE": {
const packageJson = require("../../../package.json");
irc.ctcpResponse(data.nick, "SOURCE", packageJson.repository.url);
break;
}
} }
}); });
}; };