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
Handle commands in a better way #154
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,21 +33,21 @@ var events = [ | |
"whois" | ||
]; | ||
var inputs = [ | ||
// These inputs are sorted in order that is most likely to be used | ||
"msg", | ||
"whois", | ||
"part", | ||
"action", | ||
"connect", | ||
"invite", | ||
"join", | ||
"kick", | ||
"mode", | ||
"msg", | ||
"nick", | ||
"notice", | ||
"part", | ||
"quit", | ||
"raw", | ||
"services", | ||
"topic", | ||
"whois" | ||
]; | ||
|
||
function Client(manager, name, config) { | ||
|
@@ -270,16 +270,22 @@ Client.prototype.input = function(data) { | |
var client = this; | ||
var text = data.text.trim(); | ||
var target = client.find(data.target); | ||
if (text.charAt(0) !== "/") { | ||
text = "/say " + text; | ||
|
||
// This is either a normal message or a command escaped with a leading '/' | ||
if (text.charAt(0) !== "/" || text.charAt(1) === "/") { | ||
text = "say " + text.replace(/^\//, ""); | ||
} else { | ||
text = text.substr(1); | ||
} | ||
|
||
var args = text.split(" "); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While testing this, I found an issue: any text starting with one or more whitespace does not send anything nor produce an error. It's because var args = text.trim().split(" ");
var args = text.split(" ").filter(function (a) { return a.length !== 0; }); I might be missing an alternative, but I wanted to address the bug in the first place and look for potential solutions :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've reverted the trim change, it will have to go into the next overhaul. |
||
var cmd = args.shift().replace("/", "").toLowerCase(); | ||
_.each(inputs, function(plugin) { | ||
var cmd = args.shift().toLowerCase(); | ||
|
||
var result = inputs.some(function(plugin) { | ||
try { | ||
var path = "./plugins/inputs/" + plugin; | ||
var fn = require(path); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we load the EDIT: Please disregard this comment for current PR. |
||
fn.apply(client, [ | ||
return fn.apply(client, [ | ||
target.network, | ||
target.chan, | ||
cmd, | ||
|
@@ -289,6 +295,10 @@ Client.prototype.input = function(data) { | |
console.log(path + ": " + e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you consider my comment above, this The current code is a bit worrying I think, because it fairly difficult to detect a silenced bug as is, unless you keep an eye on the log (which, by the way, is not even the error log...). EDIT: Please disregard this comment for current PR. |
||
} | ||
}); | ||
|
||
if (result !== true) { | ||
target.network.irc.write(text); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes! This is the magic sauce that will let things like |
||
} | ||
}; | ||
|
||
Client.prototype.more = function(data) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,6 @@ module.exports = function(network, chan, cmd, args) { | |
}); | ||
break; | ||
} | ||
|
||
return true; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,11 @@ module.exports = function(network, chan, cmd, args) { | |
if (cmd !== "join") { | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing Edit: It might be that you rely on the fact that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't matter since both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does if for any reason we add code checking |
||
} | ||
|
||
if (args.length !== 0) { | ||
var irc = network.irc; | ||
irc.join(args[0], args[1]); | ||
} | ||
|
||
return true; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,11 @@ module.exports = function(network, chan, cmd, args) { | |
if (cmd !== "kick") { | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing |
||
} | ||
|
||
if (args.length !== 0) { | ||
var irc = network.irc; | ||
irc.kick(chan.name, args[0]); | ||
} | ||
|
||
return true; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,14 @@ module.exports = function(network, chan, cmd, args) { | |
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing Edit: silencing for the remaining ones. If I'm wrong, I don't need to advertise it n times :D |
||
} | ||
if (args.length === 0 || args[0] === "") { | ||
return; | ||
return true; | ||
} | ||
var irc = network.irc; | ||
var target = ""; | ||
if (cmd === "msg") { | ||
target = args.shift(); | ||
if (args.length === 0) { | ||
return; | ||
return true; | ||
} | ||
} else { | ||
target = chan.name; | ||
|
@@ -27,4 +27,6 @@ module.exports = function(network, chan, cmd, args) { | |
message: msg | ||
}); | ||
} | ||
|
||
return true; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,6 @@ module.exports = function(network, chan, cmd, args) { | |
chan: targetChan.id, | ||
msg: msg | ||
}); | ||
|
||
return true; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,6 @@ module.exports = function(network, chan, cmd, args) { | |
}); | ||
|
||
irc.quit(quitMessage); | ||
|
||
return true; | ||
}; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,6 @@ module.exports = function(network, chan, cmd, args) { | |
|
||
var irc = network.irc; | ||
irc.write(msg); | ||
|
||
return true; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a stupid question, so don't be too tough on me :-)
Rather than making assumptions on most frequently used commands and calling them one by one until we have a match, why don't we directly math the input to the command name?
From what I see,
/join
matches tojoin
,/nick
matches tonick
, ...If this is not 100% the case, we can either forward commands, rename them, or treat the non-matching one differently.
EDIT: Disregard this comment for the current PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put whois at the top because it's triggered by clicking on a username. Ideally though, yes, we would have a direct hashmap of the commands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After getting that the point of this PR was to avoid a full rewrite, you can disregard this earlier comment.
I'll implement this in a further PR as well as include a bunch of tests for these at the same time, I should get to it within the next days.
By the way, I agree with this order, was just saying it could get opinionated at some point, but that won't matter when I add direct mapping.