[ABD] Forum AI v0.2.0

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
Locked
zemaj
Registered User
Posts: 267
Joined: Thu Mar 07, 2002 3:58 am
Location: Australia
Contact:

Post by zemaj »

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 ;) ).

FMC Sponge: 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:

NOT TESTED.

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.

Cheers,

-zemaj
FMC Sponge
Registered User
Posts: 7
Joined: Tue Feb 11, 2003 5:26 pm
Contact:

Post by FMC Sponge »

zemaj wrote: FMC Sponge: 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).


yes, zemaj, I figured it out. Thanks, and thanks for the great work here. My forum users have nominated our bot for president. :D
Xiph3r
Registered User
Posts: 342
Joined: Sun Oct 27, 2002 8:21 pm
Location: the wired
Contact:

Post by Xiph3r »

does the iai bot work with subforums yet?
kip2001
Registered User
Posts: 313
Joined: Sun Sep 15, 2002 9:44 am

Post by kip2001 »

FMC Sponge wrote: Thanks, and thanks for the great work here. My forum users have nominated our bot for president. :D


WOW, there a smart buch of people :roll:
zemaj
Registered User
Posts: 267
Joined: Thu Mar 07, 2002 3:58 am
Location: Australia
Contact:

Post by zemaj »

Xiph3r wrote: does the iai bot work with subforums yet?


It should work with sub forums anyway.

Try installing it an see what happens. I installed sub-forums on my site - i didn't have the bot running at the time, but I don't see why it wouldn't work.


Anyone tried the cron jobs script?

-zem
User avatar
LaZeR
Registered User
Posts: 671
Joined: Sat Jun 29, 2002 8:38 pm
Contact:

Post by LaZeR »

zemaj wrote: Anyone tried the cron jobs script?

-zem


I tried it earlier today and it didn't seem to work. I did all the edits, created the crons table, and the cron file which I placed in my phpbb root dir. Then I made a cron job to fire every minute as noted.

The post data seemed to be placed in the new table in the DB, however the bot would never respond. I tested twice in a forum set to 100% response and I also made sure to call the bot by name. Waited over 10 minutes and never got a response. Checked my email and the cron gave no reports back to encountering any problems so I have no idea what was wrong. :?
Eltargrim Irithyl
Registered User
Posts: 17
Joined: Fri Aug 23, 2002 3:56 am
Contact:

Post by Eltargrim Irithyl »

I love this mod. It is working perfectly right now, just have to tweak it.
zemaj
Registered User
Posts: 267
Joined: Thu Mar 07, 2002 3:58 am
Location: Australia
Contact:

Post by zemaj »

LaZeR wrote:
zemaj wrote:
Anyone tried the cron jobs script?

-zem


I tried it earlier today and it didn't seem to work. I did all the edits, created the crons table, and the cron file which I placed in my phpbb root dir. Then I made a cron job to fire every minute as noted.

The post data seemed to be placed in the new table in the DB, however the bot would never respond. I tested twice in a forum set to 100% response and I also made sure to call the bot by name. Waited over 10 minutes and never got a response. Checked my email and the cron gave no reports back to encountering any problems so I have no idea what was wrong. :?


Can you run the page from your browser and see what if it prints out anything?

-zem
[[MAL]]
Registered User
Posts: 8
Joined: Thu Feb 27, 2003 5:47 pm

Post by [[MAL]] »

Mine just says "error in posting" when I run the chron php file direct.
Eltargrim Irithyl
Registered User
Posts: 17
Joined: Fri Aug 23, 2002 3:56 am
Contact:

Post by Eltargrim Irithyl »

Ok I have a question. I have 2 boards using the same MySQL database just different prefixes. What I want to know is can I have the mod working on both boards but have 2 different personalities. One for the one board and a different one for the other board.
DorG
Registered User
Posts: 412
Joined: Thu Mar 21, 2002 6:40 am

Post by DorG »

I had a problem, bigger text file, but add css to rabnk was causing that problem, so removed that mod, no help needed anymore ;)
---
- <
---
mr.luc
Registered User
Posts: 213
Joined: Mon Feb 24, 2003 4:09 pm
Contact:

Post by mr.luc »

couple of questions:
1. i read through the 40+ pages 8O

a. i installed the mod to keep the bot from posting when deleting!!!
it didn't really work. she kept on posting even if i deleted her last post!

so i came up with this one that seems to work at least for me:

in posting.php find:

Code: Select all

			// START IAI response and entry to db (if active)
			if ($run_iai)

BEFORE ADD:

Code: Select all

			if($mode == 'delete') {
				$run_iai = FALSE;
			}
As i say it seems to work for me... but i only tried it on a thread or 2


--------------------------------------------

I read that posting delay was discussed before (i cant use crontabs on my forum) the only discussion i found was someone saying it was not implemented. did i overread something???????
RawketCato
Registered User
Posts: 2
Joined: Sat Mar 01, 2003 3:44 am

Post by RawketCato »

well i have iai running ok with only a few issues. i was wondering if anyone has made a "aiml" of hobby rocket terms and facts. thanks
-Rawket
HELP HELP
Registered User
Posts: 8
Joined: Sat Mar 01, 2003 3:03 pm
Contact:

Post by HELP HELP »

HELP HELP!!

If I install the Mod, I can not post any more!

Please help me!


And where can I finde the newest (working) Version of the Mod?
HELP HELP
Registered User
Posts: 8
Joined: Sat Mar 01, 2003 3:03 pm
Contact:

Post by HELP HELP »

Pleas HELPPPPP!!!!!!
Locked

Return to “[2.0.x] MODs in Development”