Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module.exports = class IrcClient extends EventEmitter {
client.network = new NetworkInfo();
client.user = new User();

client.command_handler = new IrcCommandHandler(client.connection, client.network);
client.command_handler = new IrcCommandHandler(client.connection, client.network, client.user);

client.addCommandHandlerListeners();

Expand Down
5 changes: 3 additions & 2 deletions src/commands/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ const irc_numerics = require('./numerics');
const IrcCommand = require('./command');

module.exports = class IrcCommandHandler extends EventEmitter {
constructor(connection, network_info) {
constructor(connection, network, user) {
super();

// Adds an 'all' event to .emit()
this.addAllEventName();

this.connection = connection;
this.network = network_info;
this.network = network;
this.user = user;
this.handlers = [];

this.request_extra_caps = [];
Expand Down
14 changes: 13 additions & 1 deletion src/commands/handlers/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ const handlers = {
NOTICE: function(command, handler) {
const time = command.getServerTime();
const message = command.params[command.params.length - 1];
const is_echo = handler.network.cap.isEnabled('echo-message') && command.nick === handler.user.nick;

let target = command.params[0];
let target_group;

if ((message.charAt(0) === '\x01') && (message.charAt(message.length - 1) === '\x01')) {
// It's a CTCP response
handler.emit('ctcp response', {
is_echo: is_echo,
nick: command.nick,
ident: command.ident,
hostname: command.hostname,
Expand All @@ -34,6 +37,7 @@ const handlers = {

handler.emit('notice', {
from_server: !command.nick,
is_echo: is_echo,
nick: command.nick,
ident: command.ident,
hostname: command.hostname,
Expand All @@ -51,6 +55,8 @@ const handlers = {
PRIVMSG: function(command, handler) {
const time = command.getServerTime();
const message = command.params[command.params.length - 1];
const is_echo = handler.network.cap.isEnabled('echo-message') && command.nick === handler.user.nick;

let target = command.params[0];
let target_group;

Expand All @@ -66,6 +72,7 @@ const handlers = {
if (ctcp_command === 'ACTION') {
handler.emit('action', {
from_server: !command.nick,
is_echo: is_echo,
nick: command.nick,
ident: command.ident,
hostname: command.hostname,
Expand All @@ -77,7 +84,7 @@ const handlers = {
account: command.getTag('account'),
batch: command.batch
});
} else if (ctcp_command === 'VERSION' && handler.connection.options.version) {
} else if (ctcp_command === 'VERSION' && !is_echo && handler.connection.options.version) {
handler.connection.write(util.format(
'NOTICE %s :\x01VERSION %s\x01',
command.nick,
Expand All @@ -86,6 +93,7 @@ const handlers = {
} else {
handler.emit('ctcp request', {
from_server: !command.nick,
is_echo: is_echo,
nick: command.nick,
ident: command.ident,
hostname: command.hostname,
Expand All @@ -101,6 +109,7 @@ const handlers = {
} else {
handler.emit('privmsg', {
from_server: !command.nick,
is_echo: is_echo,
nick: command.nick,
ident: command.ident,
hostname: command.hostname,
Expand All @@ -117,8 +126,11 @@ const handlers = {
TAGMSG: function(command, handler) {
const time = command.getServerTime();
const target = command.params[0];
const is_echo = handler.network.cap.isEnabled('echo-message') && command.nick === handler.user.nick;

handler.emit('tagmsg', {
from_server: !command.nick,
is_echo: is_echo,
nick: command.nick,
ident: command.ident,
hostname: command.hostname,
Expand Down