collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18363
  • stats Total Topics: 2500
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: 02_BaseActiveModule.php - parse_com  (Read 3782 times)

0 Members and 1 Guest are viewing this topic.

Offline BarkinMad

  • BeBot Rookie
  • *
  • Posts: 6
  • Karma: +0/-0
02_BaseActiveModule.php - parse_com
« on: July 03, 2011, 06:51:47 pm »
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.

Code: [Select]
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
« Last Edit: July 03, 2011, 06:55:29 pm by BarkinMad »

Offline Khalem

  • BeBot Founder
  • Administrator
  • ********
  • Posts: 1169
  • Karma: +0/-0
    • http://www.ancarim.com
Re: 02_BaseActiveModule.php - parse_com
« Reply #1 on: August 11, 2011, 08:16:42 pm »
BeBot Founder and Fixer Kingpin

 

* Recent Posts
[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm]


0.8.x updates for AoC by bitnykk
[January 30, 2024, 11:16:08 pm]


0.8.x updates for AO by bitnykk
[January 30, 2024, 11:15:37 pm]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am]


Bebot and Rasberry by bitnykk
[November 29, 2023, 11:04:14 pm]

* Who's Online
  • Dot Guests: 504
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal