I'm sorry to say that the function parse_com of BaseActiveModule class does not perform quite right. Extra spaces cause the value of $com['sub'] or $com['args'] to be null, depending on what the pattern is, and where the extra space is. That's another thing, it also doesn't work for multiple args. That said, here's a function, written by yours truly, to address those issues. It DOES have some limitations itself, it requires the first value of the pattern to be a variation on 'com' and try as i might, i couldn't get it to work with tabs or newlines, but it still handles better than the explode() based current function. If anyone can think up a way of removing the aforementioned limitations, go ahead, just be sure to give credit where it's due.
function comm_parse($msg, $breakdown = array('com', 'sub', 'args')){
$delims = " \t\n";
$delims .= $this->bot->commpre;
$containerTemp = strtok($msg, $delims);
$count = 0;
while($containerTemp != FALSE){
$tokens[$count] = $containerTemp;
$count += 1;
$containerTemp = strtok($delims);
}
$labelcount = count($breakdown);
$subPresent = FALSE;
for($i = 0; $i < $labelcount; $i++){
if(strtolower($breakdown[$i]) == 'com'){
$com[$breakdown[$i]] = $tokens[0];
} else if(strtolower($breakdown[$i]) == 'sub'){
$com[$breakdown[$i]] = $tokens[1];
$subPresent = TRUE;
} else {
$toks = $this->trimm($tokens, $subPresent);
$com[$breakdown[$i]] = $toks;
}
}
return $com;
}
function trimm($msg, $subflag = TRUE){
if($subflag){
for($i = 2; $i < count($msg); $i++){
$ret[$i-2] = $msg[$i];
}
}else{
for($i = 1; $i < count($msg); $i++){
$ret[$i-1] = $msg[$i];
}
}
return $ret;
}
edit: please forgive if it's in the wrong forum