diff --git a/client/css/style.css b/client/css/style.css index a17be73f..25f0a381 100644 --- a/client/css/style.css +++ b/client/css/style.css @@ -236,6 +236,7 @@ kbd { #chat .topic .from::before, #chat .mode .from::before, #chat .ctcp .from::before, +#chat .ctcp_request .from::before, #chat .whois .from::before, #chat .nick .from::before, #chat .action .from::before, @@ -351,7 +352,8 @@ kbd { color: #2ecc40; } -#chat .ctcp .from::before { +#chat .ctcp .from::before, +#chat .ctcp_request .from::before { content: "\f0f6"; /* http://fontawesome.io/icon/file-text-o/ */ } diff --git a/client/views/actions/ctcp.tpl b/client/views/actions/ctcp.tpl index 44b74e78..41c2f222 100644 --- a/client/views/actions/ctcp.tpl +++ b/client/views/actions/ctcp.tpl @@ -1,2 +1,2 @@ {{> ../user_name from}} -{{ctcpType}} {{{parse ctcpMessage}}} +{{{parse ctcpMessage}}} diff --git a/client/views/actions/ctcp_request.tpl b/client/views/actions/ctcp_request.tpl new file mode 100644 index 00000000..2cbb1c90 --- /dev/null +++ b/client/views/actions/ctcp_request.tpl @@ -0,0 +1,3 @@ +{{> ../user_name from}} +sent a CTCP request: +{{{parse ctcpMessage}}} diff --git a/src/models/msg.js b/src/models/msg.js index 0bafbd4f..e1b7dc72 100644 --- a/src/models/msg.js +++ b/src/models/msg.js @@ -62,6 +62,7 @@ Msg.Type = { PART: "part", QUIT: "quit", CTCP: "ctcp", + CTCP_REQUEST: "ctcp_request", CHGHOST: "chghost", TOPIC: "topic", TOPIC_SET_BY: "topic_set_by", diff --git a/src/plugins/irc-events/ctcp.js b/src/plugins/irc-events/ctcp.js index 752528e6..46700271 100644 --- a/src/plugins/irc-events/ctcp.js +++ b/src/plugins/irc-events/ctcp.js @@ -1,7 +1,9 @@ "use strict"; +const _ = require("lodash"); const Helper = require("../../helper"); const Msg = require("../../models/msg"); +const User = require("../../models/user"); const pkg = require("../../../package.json"); const ctcpResponses = { @@ -16,29 +18,40 @@ const ctcpResponses = { module.exports = function(irc, network) { const client = this; + const lobby = network.channels[0]; irc.on("ctcp response", function(data) { let chan = network.getChannel(data.nick); if (typeof chan === "undefined") { - chan = network.channels[0]; + chan = lobby; } const msg = new Msg({ type: Msg.Type.CTCP, time: data.time, from: chan.getUser(data.nick), - ctcpType: data.type, ctcpMessage: data.message, }); chan.pushMessage(client, msg); }); - irc.on("ctcp request", (data) => { + // Limit requests to a rate of one per second max + irc.on("ctcp request", _.throttle((data) => { const response = ctcpResponses[data.type]; if (response) { irc.ctcpResponse(data.nick, data.type, response(data)); } - }); + + // Let user know someone is making a CTCP request against their nick + const msg = new Msg({ + type: Msg.Type.CTCP_REQUEST, + time: data.time, + from: new User({nick: data.nick}), + hostmask: data.ident + "@" + data.hostname, + ctcpMessage: data.message, + }); + lobby.pushMessage(client, msg); + }, 1000, {trailing: false})); };