Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standard replies #386

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
31 changes: 27 additions & 4 deletions src/commands/handlers/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ const _ = {
map: require('lodash/map'),
};
const Helpers = require('../../helpers');

const handlers = {
RPL_LISTSTART: function(command, handler) {
const cache = getChanListCache(handler);
cache.channels = [];
handler.emit('channel list start');
},

RPL_LISTEND: function(command, handler) {
const cache = getChanListCache(handler);
if (cache.channels.length) {
Expand Down Expand Up @@ -300,6 +298,12 @@ const handlers = {
cache.destroy();
},

FAIL: standardReply,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually okay with adding this, but I get the sentiment for now at least it should follow the other style guide.

for example :

FAIL: function(command, handler) {
 const [command, code, ...context] = command.params;
   ...
}

The naming convention is close but just for consistency we can use command

description is also obligatory for the server side, so it probably should also be added.

Also while context is in the spec, it should be documented for the IRC3 implementation here too.

For brevity the spec is listed here : https://ircv3.net/specs/extensions/standard-replies

It would be nice to also add the documentation of it somewhere.


WARN: standardReply,

NOTE: standardReply,

BATCH: function(command, handler) {
const batch_start = command.params[0].substr(0, 1) === '+';
const batch_id = command.params[0].substr(1);
Expand Down Expand Up @@ -351,7 +355,26 @@ const handlers = {
handler.emit('batch end ' + emit_obj.type, emit_obj);
}
};

/**
*
* @param {import('../command')} irccommand
* @param {import('../handler')} handler
*/
function standardReply(irccommand, handler) {
const [command, code, ...context] = irccommand.params;
const description = context[context.length-1]
.indexOf(' ') !== -1 ?
context.pop() :
null;
handler.emit('standard reply', {
reply_type: irccommand.command,
command,
code,
context,
description,
tags: irccommand.tags
});
}
module.exports = function AddCommandHandlers(command_controller) {
_.each(handlers, function(handler, handler_command) {
command_controller.addHandler(handler_command, handler);
Expand All @@ -367,4 +390,4 @@ function getChanListCache(handler) {
}

return cache;
}
}