Rewrite ctcp handling
This commit is contained in:
parent
95abf830cd
commit
7330dc9553
@ -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,
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user