I have been doing a lot of modification of my vBulletin forums, and I've taken particular interest in different forms of AI and botting on the forums. I recently created a plugin that will make the bot post in a thread if it is called. It works some of the time, and doesn't other times. I can't figure out why it's so unreliable.
It fires at the hook location "newpost_complete" and has the following code:
if (stristr($postinfo['pagetext'],'.robot:')){
preg_match('@^(?:.robot:)?([^:]+)@i',$postinfo['pagetext'], $matches);
$host = $matches[1];
require_once(DIR . '/includes/functions_robot.php');
run($host,$threadinfo['threadid']);
}
I'm not good with regex so I am not sure that preg_match is optimal. I've found that it rarely runs the code if you post .robot:hi: but if you quote a post with .robot:hi: in it, it will run without fail even if the actual quoted content is changed to something else.
Here's the relevant code in the functions_robot.php file:
function run($command,$threadid) {
global $vbulletin;
global $db;
if ($command == 'hi') {
$output = 'Hello.';
//Queries
}
}
Any ideas on what's causing it to be so unreliable? There's a lot of potential if I can get it running smoothly.
I was able to figure it out with the use of http://regex.larsolavtorvik.com/
I switched to postdata_presave hook instead of newpost_complete.
$pagetext =& $this->fetch_field('pagetext', 'post');
$threadid =& $this->fetch_field('threadid', 'post');
if (stristr($pagetext,'.robot:')){
preg_match('/(\.robot:)(.*)(:)/iU',$pagetext, $matches);
$host = $matches[2];
require_once(DIR . '/includes/functions_robot.php');
run($host,$threadid);
}
The new hook location meant it was usually firing off quicker than the insert on my actual post, making the robot post before me. I fixed this by adding usleep(500000);
to the start of my run() function.