Ok, I got a little sidetracked on adding a new system to my site, but I'll try to get the cron jobs done when I have a spare moment (or get too pissed off with the debugging the thing I'm currently working on
: assuming you have basic php knowledge you can find the iai_update_stats() function in the includes/functions_post.php file and edit out the part that updates the Bot's post count. I think it's pretty obvious (from memory).
Actually stuff it, I'll do the cron jobs now. It shouldn't take too long.
Opps, I never posted this message. Oh well I've finished the cron job thingy. Here's the code:
Code: Select all
##############################################################
## MOD Title: Forum AI Post Delay
## Project Homepage/Demo: http://palgn.com/iai/
## MOD Author: zemaj < zemaj@palgn.com > (James Gay) http://www.palgn.com/
## Description: This mod edits your Forum AI and adds a delay in the posting time
## so it posts more like a normal user.
## MOD Version: 0.1.0
##
## Installation Level: Easy
## Installation Time: ~3 Minutes
## Files To Edit: posting.php
## includes/functions_post.php
## mods/iai/includes/constants.php
## Included Files: 1
##############################################################
## This MOD is released under the GPL License.
## Intellectual Property is retained by the MOD Author(s) listed above
##############################################################
## For Security Purposes, Please Check: http://www.phpbb.com/mods/downloads/ for the
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code
## to enter into your phpBB Forum. As such, phpBB will not offer support for MOD's not offered
## in our MOD-Database, located at: http://www.phpbb.com/mods/downloads/
##############################################################
## Authors Notes:
##
## This adds a delay to your bot's posting. If someone else has posted since the bot is replying,
## then the bot quotes the post it is responding to, so we know who it is.
##
## You need IAI v0.2.0 installed and the abilty to add cron jobs on your server to run this.
##
## Once you have done the editing below you will need to add iai_cron.php as a cron job to be run
## every minute. e.g. * * * * * lynx -dump http://yoursite.com/iai_cron.php
##
## In order to change the time between which the bot responds you can edit the second replace below.
## I have made it obvious what to edit.
##
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################
#
# Table structure for table 'iai_cron_posts'
#
CREATE TABLE iai_cron_posts (
post_id int(11) NOT NULL,
topic_id int(11) NOT NULL,
forum_id int(11) NOT NULL,
post_subject text,
post_text text,
bbcode_uid varchar(255),
past_post_id int(11) NOT NULL,
update_time int(11) NOT NULL,
);
#
#-----[ OPEN ]------------------------------------------
#
includes/functions_post.php
#
#-----[ FIND ]------------------------------------------
#
//
// Post IAI's response to database
//
function iai_submit_post($mode, &$iai_id, &$forum_id, &$topic_id, &$iai_post_id, &$topic_type, $bbcode_on, $html_on, $smilies_on, $attach_sig, &$bbcode_uid, &$iai_username, &$iai_subject, &$iai_message)
{
global $board_config, $lang, $db, $phpbb_root_path, $phpEx;
//Stores user's IP since IAI has none. Can be changed as wished.
global $user_ip;
$current_time = time();
$sql = "INSERT INTO " . POSTS_TABLE . " (topic_id, forum_id, poster_id, post_username, post_time, poster_ip, enable_bbcode, enable_html, enable_smilies, enable_sig) VALUES ($topic_id, $forum_id, $iai_id, '$iai_username', $current_time, '$user_ip', $bbcode_on, $html_on, $smilies_on, $attach_sig)";
if ( !($result = $db->sql_query($sql, BEGIN_TRANSACTION)) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
$iai_post_id = $db->sql_nextid();
$sql = "INSERT INTO " . POSTS_TEXT_TABLE . " (post_id, post_subject, bbcode_uid, post_text) VALUES ($iai_post_id, '$iai_subject', '$bbcode_uid', '$iai_message')";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
add_search_words($iai_post_id, stripslashes($iai_message), stripslashes($iai_subject));
return false;
}
#
#-----[ REPLACE WITH ]------------------------------------------
#
//
// Prepare IAI's post to submitted with in the cron job.
//
function iai_submit_post($mode, &$iai_id, &$forum_id, &$topic_id, &$iai_post_id, &$topic_type, $bbcode_on, $html_on, $smilies_on, $attach_sig, &$bbcode_uid, &$iai_username, &$iai_subject, &$iai_message, &$update_time)
{
global $board_config, $lang, $db, $phpbb_root_path, $phpEx;
//Stores user's IP since IAI has none. Can be changed as wished.
global $user_ip;
$current_time = time();
$sql = "SELECT topic_last_post_id
FROM " . TOPICS_TABLE . "
WHERE topic_id = $topic_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
$past_post = $db->sql_fetchrow($result);
$past_post_id = $past_post['topic_last_post_id'];
$sql = "INSERT INTO " . POSTS_TABLE . " (topic_id, forum_id, poster_id, post_username, post_time, poster_ip, enable_bbcode, enable_html, enable_smilies, enable_sig) VALUES (0, 0, $iai_id, '$iai_username', $current_time, '$user_ip', $bbcode_on, $html_on, $smilies_on, $attach_sig)";
if ( !($result = $db->sql_query($sql, BEGIN_TRANSACTION)) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
$iai_post_id = $db->sql_nextid();
$sql = "INSERT INTO " . IAI_CRON_TABLE . " (post_id, topic_id, forum_id, post_subject, post_text, bbcode_uid, past_post_id, update_time) VALUES ($iai_post_id, $topic_id, $forum_id, '$iai_subject', '$iai_message', '$bbcode_uid', $past_post_id, $update_time)";
if ( !($result = $db->sql_query($sql, END_TRANSACTION)) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
return false;
}
#
#-----[ OPEN ]------------------------------------------
#
posting.php
#
#-----[ FIND ]------------------------------------------
#
if ( $error_msg == '' && !empty($iai_message) )
{
// Submit IAI's response to DB & update stats
iai_submit_post($iai_mode, $iai_id, $forum_id, $topic_id, $iai_post_id, $iai_topic_type, 1, 1, 1, 1, $bbcode_uid, str_replace("\'", "''", $iai_username), str_replace("\'", "''", $iai_subject), str_replace("\'", "''", $iai_message));
iai_update_post_stats($forum_id, $topic_id, $iai_post_id, $iai_id);
}
#
#-----[ REPLACE WITH ]------------------------------------------
#
if ( $error_msg == '' && !empty($iai_message) )
{
// You can edit the two values below to set the minimum and maximum time
// in minutes to wait before posting the message. A random time will be
// choosen between the two.
$minimum_time = 0; //in mins
$maximum_time = 10; //in mins
$add_mins = mt_rand($minimum_time, $maximum_time);
$update_time = time() + ($add_mins * 60);
iai_submit_post($iai_mode, $iai_id, $forum_id, $topic_id, $iai_post_id, $iai_topic_type, 1, 1, 1, 1, $bbcode_uid, str_replace("\'", "''", $iai_username), str_replace("\'", "''", $iai_subject), str_replace("\'", "''", $iai_message), $update_time);
}
#
#-----[ OPEN ]------------------------------------------
#
mods/iai/includes/constants.php
#
#-----[ FIND ]------------------------------------------
#
define('IAI_THATIDEX_T', $iai_prefix.'thatindex');
define('IAI_THATSTACK_T', $iai_prefix.'thatstack');
define('IAI_GMCACHE_T', $iai_prefix.'gmcache');
#
#-----[ ADD AFTER ]------------------------------------------
#
define('IAI_CRON_TABLE', $iai_prefix.'cron_posts');
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
##############################################################
#
# EoM
Code: Select all
<?php
/***************************************************************************
* iai_cron.php
* -------------------
* copyright : (C) 2003 James Gay
* email : zemaj@palgn.com
*
***************************************************************************/
/***************************************************************************
*
* This *should* check & update IAI posts where needed when called.
* To use set this page as a cron jobs to run every minute.
*
***************************************************************************/
define('IN_PHPBB', true);
$phpbb_root_path='./';
include($phpbb_root_path.'extension.inc');
include($phpbb_root_path.'common.'.$phpEx);
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);
include($phpbb_root_path . 'includes/functions_post.'.$phpEx);
// Grab all our data
$sql = "SELECT c.*, pt.post_text AS past_message, pt.bbcode_uid AS past_bbcode_uid, p.post_username, t.topic_last_post_id
FROM " . IAI_CRON_TABLE . " c, " . POSTS_TEXT_TABLE . " pt, " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
WHERE c.update_time < " . time() . "
AND pt.post_id = c.past_post_id
AND p.post_id = c.past_post_id
AND t.topic_id = p.topic_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
$posts = $db->sql_fetchrowset($result);
if($total_posts = count($posts))
{
for( $i = 0; $i < $total_posts; $i++ )
{
// Int vars
$iai_post_id = $posts[$i]['post_id'];
$topic_id = $posts[$i]['topic_id'];
$forum_id = $posts[$i]['forum_id'];
$iai_subject = $posts[$i]['post_subject'];
$bbcode_uid = $posts[$i]['post_text'];
$iai_message = $posts[$i]['bbcode_uid'];
$current_time = time();
if($posts[$i]['topic_last_post_id'] != $posts[$i]['past_post_id'])
{
// New posts in thread since this reply was set...
// Now we have to add old text in a quote. Fun.
$past_message = preg_replace('/\:(([a-z0-9]:)?)' . $posts[$i]['past_bbcode_uid'] . '/s', '', $posts[$i]['past_message']);
$iai_message = preg_replace('/\:(([a-z0-9]:)?)' . $bbcode_uid . '/s', '', $iai_message);
$iai_message = '[quote="' . $posts[$i]['post_username'] . '"]' . $past_message . '[/quote]' . $iai_message;
// Parse with new bbcode
$bbcode_uid = make_bbcode_uid();
$iai_message = bbencode_first_pass($iai_message, $bbcode_uid);
}
$sql = "UPDATE " . POSTS_TABLE . "
SET topic_id = $topic_id, forum_id = $forum_id, post_time = $current_time
WHERE post_id = $iai_post_id";
if ( !($result = $db->sql_query($sql, BEGIN_TRANSACTION)) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
$sql = "INSERT INTO " . POSTS_TEXT_TABLE . " (post_id, post_subject, bbcode_uid, post_text) VALUES ($iai_post_id, '$iai_subject', '$bbcode_uid', '$iai_message')";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
add_search_words($iai_post_id, stripslashes($iai_message), stripslashes($iai_subject));
iai_update_post_stats($forum_id, $topic_id, $iai_post_id, $board_config['iai_userid']);
// Updating complete! Remove this cron job!
$sql = "DELETE FROM " . IAI_CRON_TABLE . "
WHERE post_id = $iai_post_id";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql);
}
}
}
?>
Whipped it up in half an hour or so. It was a little more complicated than I thought it might be, but everything should still run smoothly.
I haven't tested this AT ALL, so if anyone does, please do not do try it on a live forum.
Please use debug mode and post the full errors if you get any.