Add /ctcp command and handle ctcp responses

This commit is contained in:
Pavel Djundik 2016-03-27 18:57:59 +03:00 committed by Maxime Poulin
parent 2a7a93d207
commit 16370d8fcc
7 changed files with 44 additions and 3 deletions

View File

@ -827,6 +827,11 @@ button,
color: #2ecc40;
}
#chat .ctcp .from:before {
font-family: FontAwesome;
content: "\f0f6";
}
#chat .whois .from:before {
font-family: FontAwesome;
content: "\f007";

View File

@ -225,6 +225,7 @@ $(function() {
"topic_set_by",
"action",
"whois",
"ctcp",
].indexOf(type) !== -1) {
data.msg.template = "actions/" + type;
msg = $(render("msg_action", data.msg));

View File

@ -0,0 +1,2 @@
<a href="#" class="user" data-name="{{from}}">{{from}}</a>
<b>{{ctcpType}}</b> {{ctcpMessage}}

View File

@ -30,6 +30,7 @@ var events = [
"whois"
];
var inputs = [
"ctcp",
"msg",
"part",
"action",

View File

@ -14,6 +14,7 @@ Msg.Type = {
PART: "part",
QUIT: "quit",
TOGGLE: "toggle",
CTCP: "ctcp",
TOPIC: "topic",
TOPIC_SET_BY: "topic_set_by",
WHOIS: "whois"

View File

@ -0,0 +1,8 @@
exports.commands = ["ctcp"];
exports.input = function(network, chan, cmd, args) {
if (args.length > 1) {
var irc = network.irc;
irc.ctcpRequest(args[0], args.slice(1).join(" "));
}
};

View File

@ -1,15 +1,38 @@
var pkg = require(process.cwd() + "/package.json");
var Msg = require("../../models/msg");
module.exports = function(irc, network) {
var client = this;
irc.on("ctcp response", function(data) {
var chan = network.getChannel(data.nick);
if (typeof chan === "undefined") {
chan = network.channels[0];
}
var msg = new Msg({
type: Msg.Type.CTCP,
time: data.time,
from: data.nick,
ctcpType: data.type,
ctcpMessage: data.message
});
chan.messages.push(msg);
client.emit("msg", {
chan: chan.id,
msg: msg
});
});
module.exports = function(irc/* , network */) {
irc.on("ctcp request", function(data) {
switch (data.type) {
case "VERSION":
irc.ctcpResponse(data.nick, "VERSION " + pkg.name + " " + pkg.version);
irc.ctcpResponse(data.nick, "VERSION", pkg.name + " " + pkg.version);
break;
case "PING":
var split = data.message.split(" ");
if (split.length === 2) {
irc.ctcpResponse(data.nick, "PING " + split[1]);
irc.ctcpResponse(data.nick, "PING", split[1]);
}
break;
}