With regular expression:
code:
if(/^\/(.+?\b)(?: (.*))?$/.test(Message)) {
var Command = RegExp.$1.toLowerCase();
var Parameters = RegExp.$2;
switch(Command) {
case "run":
myFunction(Parameters);
break;
}
}
I'm not sure if the regular expression is 100% correct, but it works as it's supposed to anyway. With this one, you can have spaces in your parameters and you don't need to count the length of the command. The parameter is also optional (if your command doesn't require parameters, it still works). If you need more than one parameter (separated by a space), you can use another regular expression.