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

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

Author Topic: Quotes module  (Read 5614 times)

0 Members and 1 Guest are viewing this topic.

Offline Dabaron

  • BeBot Apprentice
  • ***
  • Posts: 163
  • Karma: +0/-0
Quotes module
« on: January 19, 2009, 06:53:17 am »
Has anyone made a .6.1 version of this?  I finally got around to upgrading from .4 and this one doesn't work and I don't see any threads for it.

Offline Serbaa

  • BeBot User
  • **
  • Posts: 22
  • Karma: +0/-0
Re: Quotes module
« Reply #1 on: January 20, 2009, 07:59:33 am »
last i checked it was working what kind of errors do you get?

Offline Dabaron

  • BeBot Apprentice
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Quotes module
« Reply #2 on: January 22, 2009, 06:41:15 am »
Ok, I did find a quotes module that was ported for .5+ that mostly works.  Found that at http://bebot.link/aoc-support/quotes-bug/

Using that one however (not the one linked at the top, it was for .4, I had to use the one that has the code pasted in the last post) I'm getting incorrect results.  If I just do a "/tell bot quote" (or quotes) I get "No quotes exist. Add some!".  I get the same thing if I do "/tell bot quotes 777" (any number here that doesn't exist).  However if I do a "/tell bot quotes cyber" I do get all results back that it matches, also works with "/tell bot quotes 1" (any number here that does exist).  Here is the code for that module so you don't to link over.
Code: [Select]
<?
/*
* Quotes.php - Quotes Module.
* Original quotes module Developed by Sabkor (RK1)
* Most of his original code is still in here. Any changes have been documented.
* Modified/updated by Andrew Zbikowski <[email protected]> AKA Glarawyn, RK1
*
* Channge Log:
*    v2.0.1
*        - Fixed a typo.
*    v2.0.0
*        - Updated for BeBot 0.4
*        - Force use of MyISAM for Quotes table.
*        - Quotes table can be shared between bots.
*        - Using Settings module instead of internal settings.
*        - Change addslashes() to mysql_real_escape_string()
*    v1.5.0
*        - Added search_quotes() to search the quote database. ()
*    v1.0.1
*          - Added Auto Quote "spam"
*          - Changed BLOB to TEXT fo facility searching of quotes (v1.0.1)
*          - Added handler() to remove redundant code.  (v1.0.1)
*          - Added load_settings, change_setting, show_settings,
*             handler, cron(), and connect(). (v1.0.1)
*          - Modified add_quote() function to use addslashes() instead
*             of str_replace() when inserting into database. (v1.0.1)
*
* BeBot - An Anarchy Online Chat Automaton
* Copyright (C) 2004 Jonas Jax
* Copyright (C) 2005-2007 Thomas Juberg Stenså ShadowRealm Creations and the BeBot development team.
*
* Developed by:
* - Alreadythere (RK2)
* - Blondengy (RK1)
* - Blueeagl3 (RK1)
* - Glarawyn (RK1)
* - Khalem (RK1)
* - Naturalistic (RK1)
*
* See Credits file for all aknowledgements.
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; version 2 of the License only.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
*  USA
*
* File last changed at $LastChangedDate: 2007-07-25 14:09:30 -0500 (Wed, 25 Jul 2007) $
* Revision: $Id: _ExampleModule.php 818 2007-07-25 19:09:30Z shadowmaster $
*/

/*
Add a "_" at the beginning of the file (_Quotes.php) if you do not want it to be loaded.
*/

$db -> query("CREATE TABLE IF NOT EXISTS ".$db -> define_tablename("quotes", "false")."
    (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
     quote TEXT,
     contributor VARCHAR(15) NOT NULL,
     botname VARCHAR(15) NOT NULL DEFAULT 'Import',
     FULLTEXT (quote,contributor)) ENGINE=MyISAM");

$quotes = new Quotes($bot);

/*
The Class itself...
*/
class Quotes Extends BaseActiveModule
{
    var $bot;
    // When the next auto quote will display.
    var $nextquote;

    /*
    Constructor:
    Hands over a referance to the "Bot" class.
    */
    function __construct (&$bot)
    {
        parent::__construct(&$bot, get_class($this));

        /*
        Bind the command to the bot.
        */
        $this -> register_command('all', 'quote', 'GUEST');
        $this -> register_command('all', 'quotes', 'GUEST');

        $this -> register_event('connect');
        $this -> register_event('cron', '5min');

        $this -> bot -> core("settings") -> create ("Quotes", "Auto", "On", "Automatically send quotes to configured channels.", "On;Off", FALSE, 5);
        $this -> bot -> core("settings") -> create ("Quotes", "Interval", 60, "Minutes between automatic quote output.", "5;10;15;20;25;30;45;60", FALSE, 10);
        $this -> bot -> core("settings") -> create ("Quotes", "Channel", "Both", "Automatic quote output channel.", "Guild;Group;Both", FALSE, 15);

        $this -> help['description'] = 'Stores and retrives quotes.';
        $this -> help['command']['quotes']="Displays a random quote from the database.";
        $this -> help['command']['quotes add <quote>'] = "Adds <quote> to the database.";
        $this -> help['command']['quotes remove|del|rem|delete <number>'] = "Removes quote <number> from the database.";
        $this -> help['command']['quotes by <name>'] = "Shows quotes contributed by <name>.";
        $this -> help['command']['quotes <search string>'] = "Searches for quotes matching <search string>.";

        $this -> help['command']['quote']="Displays a random quote from the database.";
        $this -> help['command']['quote add <quote>'] = "Adds <quote> to the database.";
        $this -> help['command']['quote remove|del|rem|delete <number>'] = "Removes quote <number> from the database.";
        $this -> help['command']['quote by <name>'] = "Shows quotes contributed by <name>.";
        $this -> help['command']['quote <search string>'] = "Searches for quotes matching <search string>.";

        $this -> help['notes'] = "See /tell <botname> <pre>settings quotes";

        $this -> bot -> db -> query("ALTER TABLE #___quotes ADD COLUMN botname VARCHAR(255) NOT NULL DEFAULT '';");
    }

    /*
    This gets called when bot connects
    */
    function connect()
    {
        $this -> nextquote = time() + 270; // Don't display quotes right away.
    }

    /*
    This is cron()!
    */
    function cron()
    { // Start function cron()
        if ($this -> nextquote < time() && $this -> bot -> core("settings") -> get("Quotes", "Auto") == True)
        { // Start if()
            // Set time of next quote output.
            $this -> nextquote = $this -> nextquote + ($this -> bot -> core("settings") -> get("Quotes", "INTERVAL")*60);
            switch (strtoupper($this -> bot -> core("settings") -> get("Quotes", "Channel")))
            { // Start switch
                case "GC":
                    $this -> bot -> send_gc($this -> send_quote());
                break;
                case "PGROUP":
                    $this -> bot -> send_pgroup($this -> send_quote());
                break;
                case "BOTH":
                    $this -> bot -> send_gc($this -> send_quote());
                    $this -> bot -> send_pgroup($this -> send_quote());
                break;
            } // End Switch
        } // End if()
    } // End function cron()


    /*
    This function handles all the inputs and returns FALSE if the
    calling function should not send output, otherwise returns a string
    sutible for output via send_tell, send_pgroup, and send_gc.
    */
    function command_handler($name, $msg, $origin)
    {
        $this->error->reset(); //Reset the error message so we don't trigger the handler by old error messages.

        $com = $this->parse_com($msg, array('com', 'sub', 'arg'));

        switch($com['sub'])
        {
            case 'add':
                return $this -> add_quote($com['arg'], $name);
                break;
            case 'del':
            case 'delete':
            case 'rem':
            case 'remove':
                return $this -> del_quote($com['arg'], $name);
                break;
            case 'by':
                return $this -> search_quotes($com['arg'], $origin, TRUE);
                break;
            case '':
                return $this -> send_quote();
                break;
            default:
                if(is_numeric($com['sub']) && (int) $com['sub'] == (real) $com['sub'] && empty($com['arg']))
                    return $this -> send_quote($com['sub']);
                else
                    return $this -> search_quotes(trim($com['sub'].' '.$com['args']), $origin);
        }

        return $this -> show_vent();
    }

    function add_quote($strquote, $name)
    { // Start function add_quote()
        $strquote = mysql_real_escape_string($strquote);
        $name = mysql_real_escape_string($name);
        $sql = "INSERT INTO #___quotes (quote, contributor, botname) ";
        $sql .= "VALUES ('".$strquote."','".$name."','".$this -> bot -> botname."')";
        $this -> bot -> db -> query($sql);
        $sql = "SELECT id FROM #___quotes ORDER BY id DESC";
        $num = $this -> bot -> db -> select($sql);
        $strmsg = "Thank you, your quote has been added as id #" . $num[0][0];
        return $strmsg;
    } // End function add_quote()

    function del_quote($qnum, $name)
    { // Start function del_quote()
        $qnum = mysql_real_escape_string($qnum);
        $sql = "SELECT * FROM #___quotes WHERE id=".$qnum;
        $result = $this -> bot -> db -> select($sql, MYSQL_ASSOC);
        if (!empty($result))
        {
            $candel = false;
            if($this -> bot -> core('security') -> check_access($name, "ADMIN"))
                $candel = true;
            if($result[0]['contributor']==$name)
                $candel = true;

            if ($candel==true)
            {
                $sql = "DELETE FROM #___quotes WHERE id=". $qnum;
                $this -> bot -> db -> query($sql);
                $reply = "Quote removed.";
            }
            else
            {
                $reply = "Unable to delete quote with ID of " . $qnum . ". You must be an admin or the contributor of the quote to delete it.";
            }
        }
        else
        {
            $sql = "SELECT id FROM #___quotes ORDER BY id DESC LIMIT 1";
            $num = $this -> bot -> db -> select($sql);
            if(!empty($num))
                $reply = "Quote with id of " . $qnum . " not found. (Highest quote ID is " . $num[0][0] . ".)";
            else
                $reply = "No quotes exist. Add some!";
        }
        return $reply;
    } // End function del_quote()

    function send_quote($qnum = -1)
    { // Start function send_quote()
        $strquote = "";
        if($qnum == -1)
        {
            // Get the ID of the highest quote.
            $sql = "SELECT id FROM #___quotes ORDER BY id DESC LIMIT 1";
            $result = $this -> bot -> db -> select($sql);

            if(!is_array($result))
            {
                $num = intval($result[0][0]);

                if($num > 0)
                {
                    $found = false;
                    while ($found == false)
                    {
                        $qnum = rand(0,$num);
                        $sql = "SELECT * FROM #___quotes WHERE id = ".$qnum;
                        $result = $this -> bot -> db -> select($sql, MYSQL_ASSOC);
                        if (!empty($result))
                        {
                            $strquote = "#" . $result[0]['id'] . " - " . $result[0]['quote'] . " [Contributed by: " . $result[0]['contributor'] . "]";
                            $found = true;
                        }
                    }
                }
                else
                {
                    $strquote = "No quotes exist. Add some!";
                }
              }
            else
            {
                $strquote = "No quotes exist. Add some!";
            }
        }
        else
        {
            $sql = "SELECT * FROM #___quotes WHERE id=".$qnum;
            $result = $this -> bot -> db -> select($sql, MYSQL_ASSOC);
            if (!empty($result))
            {
                $strquote = "#" . $result[0]['id'] . " - " . $result[0]['quote'] . " [Contributed by: " . $result[0]['contributor'] . "]";
            }
            else
            {
                $sql = "SELECT id FROM #___quotes ORDER BY id DESC LIMIT 1";
                $result = $this -> bot -> db -> select($sql);
                if(!empty($results))
                {
                    $num = $result[0];
                    $strquote = "Quote with id of " . $qnum . " not found. (Highest quote ID is " .$num[0][0]. ".)";
                }
                else
                {
                    $strquote = "No quotes exist. Add some!";
                }
            }
        }
        return $strquote;
    } // End function send_quote()

    /*
    Searches the quote database.
    */
    function search_quotes($searchterm, $origin="tell", $contributor=FALSE)
    { // Start function search_quotes()
        $searchterm = mysql_real_escape_string($searchterm);
        // If $searchterm is 3 characters or less, do a LIKE search.
        // Otherwise, do a fulltext search of the index.
        if ($contributor) // Only show quotes added by $contributor
        {
            $sql = "SELECT id,quote,contributor FROM #___quotes WHERE contributor LIKE '%".$searchterm."%'";
        }
        else if (strlen($searchterm) > 0 AND strlen($searchterm) < 4)
        {
            $sql = "SELECT id,quote,contributor FROM #___quotes WHERE quote LIKE '%".$searchterm."%' OR contributor LIKE '%".$searchterm."%'";
        }
        else
        {
            $sql = "SELECT id,quote,contributor FROM #___quotes WHERE MATCH (quote,contributor) AGAINST('".$searchterm."' IN BOOLEAN MODE)";
        }
        $result = $this -> bot -> db -> select($sql);

        if (!is_array($result))
        {
            return "Sorry, no quotes found matching ".$searchterm;
        }
        else
        {
            $numresult = count($result);
        }

        if ($numresult == 1)
        {
            return $this -> send_quote($result[0][0]);
        }

        else if ($numresult > 1)
        {
            switch ($origin)
            {
                case "tell":
                    $chat = "/tell <botname>";
                break;
                case "pgmsg":
                    $chat = "/g <botname>";
                break;
                case "gc":
// Age of Conan specific
                    //$chat = "/gu";
// Anarchy Online specific
                   $chat = "/o";
                break;
            }
            $inside = "Quotes Matching ".$searchterm.": \n\n";
            foreach ($result as $answer)
            {
                $inside .= $answer[0].": <a href='chatcmd://".$chat." <pre>quotes ".$answer[0]."'>".substr(str_replace("<br>", "\n", $answer[1]), 0, 72)."</a>\n";
            }
            return $this -> bot -> core("tools") -> make_blob("Mutiple Search Results", $inside);
        }
        else
        {
            return FALSE;
        }
    } // End function search_quotes

} // End of class
?>

Any suggestions would be most appreciated.
« Last Edit: January 22, 2009, 06:45:11 am by Dabaron »

Offline Serbaa

  • BeBot User
  • **
  • Posts: 22
  • Karma: +0/-0
Re: Quotes module
« Reply #3 on: January 25, 2009, 04:30:31 am »
What game are you running? AO or AoC? because there is a quotes module in the bebot\modules\aoc folder that works for AoC.

Offline Temar

  • Contributor
  • *******
  • Posts: 1140
  • Karma: +0/-0
    • AoFiles
Re: Quotes module
« Reply #4 on: January 25, 2009, 07:29:43 am »
that quotes module will work with any game, the only reason its in aoc folder cuz it was in bebot hyborian and not the version for AO, so when i merged it ended up in there

but this version doesnt have auto spamming of quotes or a search

Offline Dabaron

  • BeBot Apprentice
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Quotes module
« Reply #5 on: January 26, 2009, 08:58:41 am »
I'm looking for AO.

Any ideas why it won't find on random?

Offline Sabkor

  • Contributor
  • *******
  • Posts: 30
  • Karma: +0/-0
Re: Quotes module
« Reply #6 on: April 01, 2009, 05:03:49 am »
Sorry for the necro, but I just got around to updating to 0.6 on my own bots. Here's the updates Quotes module that I did up tonight. Seems to work for me.

Code: [Select]
<?
/*
* Quotes.php - Quotes Module.
* Original quotes module Developed by Sabkor (RK1)
* Most of his original code is still in here. Any changes have been documented.
* Modified/updated by Andrew Zbikowski <[email protected]> AKA Glarawyn, RK1
*
* Change Log:
*    v3.0.0
*         - Updated for BeBot 0.6
* v2.0.1
* - Fixed a typo.
* v2.0.0
* - Updated for BeBot 0.4
* - Force use of MyISAM for Quotes table.
* - Quotes table can be shared between bots.
* - Using Settings module instead of internal settings.
* - Change addslashes() to mysql_real_escape_string()
* v1.5.0
* - Added search_quotes() to search the quote database. ()
* v1.0.1
- Added Auto Quote "spam"
- Changed BLOB to TEXT fo facility searching of quotes (v1.0.1)
- Added handler() to remove redundant code.  (v1.0.1)
- Added load_settings, change_setting, show_settings,
*      handler, cron(), and connect(). (v1.0.1)
- Modified add_quote() function to use addslashes() instead
*      of str_replace() when inserting into database. (v1.0.1)

* BeBot - An Anarchy Online Chat Automaton
* Copyright (C) 2004 Jonas Jax
* Copyright (C) 2005-2007 Thomas Juberg Stenså ShadowRealm Creations and the BeBot development team.
*
* Developed by:
* - Alreadythere (RK2)
* - Blondengy (RK1)
* - Blueeagl3 (RK1)
* - Glarawyn (RK1)
* - Khalem (RK1)
* - Naturalistic (RK1)
*
* See Credits file for all aknowledgements.
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; version 2 of the License only.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
*  USA
*
* File last changed at $LastChangedDate: 2007-07-25 14:09:30 -0500 (Wed, 25 Jul 2007) $
* Revision: $Id: _ExampleModule.php 818 2007-07-25 19:09:30Z shadowmaster $
*/

/*
Add a "_" at the beginning of the file (_Quotes.php) if you do not want it to be loaded.
*/

$db -> query("CREATE TABLE IF NOT EXISTS ".$db -> define_tablename("quotes", "false")."
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
quote TEXT,
contributor VARCHAR(15) NOT NULL,
botname VARCHAR(15) NOT NULL DEFAULT 'Import',
FULLTEXT (quote,contributor)) ENGINE=MyISAM");

$quotes = new Quotes($bot);

/*
The Class itself...
*/
class Quotes extends BaseActiveModule

  {
var $nextquote;

    /*

      Constructor:

        Hands over a referance to the "Bot" class.

    */

function __construct(&$bot)
{
// Initialize the base module
parent::__construct(&$bot, get_class($this));

$this->register_command('all', 'quotes', 'GUEST');
$this->register_command('all', 'quote', 'GUEST');

$this -> register_event("connect");
$this -> register_event("cron", "5min");

$this -> bot = &$bot;
$module = "Quotes";
$desc = "Automatically send quotes to configured channels.";
$this -> bot -> core("settings") -> create ($module, "Auto", FALSE, $desc, "On;Off");

$desc = "Minutes between automatic quote output.";
$this -> bot -> core("settings") -> create ($module, "Interval", 60, $desc, "5;10;15;20;25;30;45;60");

$desc = "Automatic quote output channel.";
$this -> bot -> core("settings") -> create ($module, "Channel", "Both", $desc, "Guild;Group;Both");

unset($module);
unset($desc);

$this -> help['description'] = 'Stores and retrives quotes.';
$this -> help['command']['quotes']="Displays a random quote from the database.";
$this -> help['command']['quotes add <quote>'] = "Adds <quote> to the database.";
$this -> help['command']['quotes remove|del|rem|delete <number>'] = "Removes quote <number> from the database.";
$this -> help['command']['quotes by <name>'] = "Shows quotes contributed by <name>.";
$this -> help['command']['quotes <search string>'] = "Searches for quotes matching <search string>.";

$this -> help['command']['quote']="Displays a random quote from the database.";
$this -> help['command']['quote add <quote>'] = "Adds <quote> to the database.";
$this -> help['command']['quote remove|del|rem|delete <number>'] = "Removes quote <number> from the database.";
$this -> help['command']['quote by <name>'] = "Shows quotes contributed by <name>.";
$this -> help['command']['quote <search string>'] = "Searches for quotes matching <search string>.";

$this -> help['notes'] = "See /tell <botname> <pre>settings quotes";
}

function command_handler($name, $msg, $origin)
{
$this->error->reset();

return $this->handler($name, $msg, $origin);
}

/*
This gets called when bot connects
*/
function connect()
{
$this -> nextquote = time() + 270; // Don't display quotes right away.
}

/*
This is cron()!
*/
function cron($interval)
{ // Start function cron()
if ($this -> nextquote < time() && $this -> bot -> core("settings") -> get("Quotes", "Auto") == True)
{ // Start if()
// Set time of next quote output.
$this -> nextquote = $this -> nextquote + ($this -> bot -> core("settings") -> get("Quotes", "INTERVAL")*60);
switch (strtoupper($this -> bot -> core("settings") -> get("Quotes", "Channel")))
{ // Start switch
case "GC":
$this -> bot -> send_gc($this -> send_quote(-1));
break;
case "PGROUP":
$this -> bot -> send_pgroup($this -> send_quote(-1));
break;
case "BOTH":
$this -> bot -> send_gc($this -> send_quote(-1));
$this -> bot -> send_pgroup($this -> send_quote(-1));
break;
} // End Switch
} // End if()
} // End function cron()

/*
This function handles all the inputs and returns output
sutible for send_tell, send_pgroup, and send_gc.
*/
function handler($name, $msg, $origin)
{ // Start function handler()
if (preg_match("/^(quotes|quote) ([0-9]+)$/i", $msg, $info))
{
return $this -> send_quote($info[2]);
}
else if (preg_match("/^(quotes|quote) add (.+)$/i", $msg, $info))
{
return $this -> add_quote($info[2], $name);
}
else if (preg_match("/^(quotes|quote) (remove|del|rem|delete) ([0-9]+)$/i", $msg, $info))
{
return $this -> del_quote($info[3], $name);
}
else if (preg_match("/^(quotes|quote) by (.+)$/i", $msg, $info))
{
return $this -> search_quotes($info[2], $origin, TRUE);
}
else if (preg_match("/^(quotes|quote) (.+)$/i", $msg, $info))
{
return $this -> search_quotes($info[2], $origin);
}
else
{
return $this -> send_quote(-1);
}
} // End function handler()

function add_quote($strquote, $name)
{ // Start function add_quote()
$strquote = mysql_real_escape_string($strquote);
$name = mysql_real_escape_string($name);
$sql = "INSERT INTO #___quotes (quote, contributor, botname) ";
$sql .= "VALUES ('".$strquote."','".$name."','".$this -> bot -> botname."')";
$this -> bot -> db -> query($sql);
$sql = "SELECT id FROM #___quotes ORDER BY id DESC";
$num = $this -> bot -> db -> select($sql);
$strmsg = "Thank you, your quote has been added as id #" . $num[0][0];
return $strmsg;         
} // End function add_quote()

function del_quote($qnum, $name)
{ // Start function del_quote()
$qnum = mysql_real_escape_string($qnum);
$sql = "SELECT * FROM #___quotes WHERE id=".$qnum;
$result = $this -> bot -> db -> select($sql, MYSQL_ASSOC);
if (!empty($result))
{
$candel = false;
if($this -> bot -> core("security") -> check_access($name, "ADMIN")) $candel = true;
if($result[0]['contributor']==$name) $candel = true;

if ($candel==true)
{
$sql = "DELETE FROM #___quotes WHERE id=". $qnum;
$this -> bot -> db -> query($sql);
$reply = "Quote removed.";
}
else
{
$reply = "Unable to delete quote with ID of " . $qnum . ". You must be an admin or the contributor of the quote to delete it.";
}
}
else
{
$sql = "SELECT id FROM #___quotes ORDER BY id DESC LIMIT 1";
$num = $this -> bot -> db -> select($sql);
$reply = "Quote with id of " . $qnum . " not found. (Highest quote ID is " . $num[0][0] . ".)";
}
return $reply;
} // End function del_quote()

function send_quote($qnum)
{ // Start function send_quote()
$strquote = "";

// Get the ID of the highest quote.
$sql = "SELECT id FROM #___quotes ORDER BY id DESC LIMIT 1";
$result = $this -> bot -> db -> select($sql);
$num = intval($result[0][0]);

if($qnum == -1)
{
if($num > 0)
{
$found = false;
while ($found == false)
{
$qnum = rand(0,$num);
$sql = "SELECT * FROM #___quotes WHERE id = ".$qnum;
$result = $this -> bot -> db -> select($sql, MYSQL_ASSOC);
if (!empty($result))
{
$strquote = "#" . $result[0]['id'] . " - " . $result[0]['quote'] . " [Contributed by: " . $result[0]['contributor'] . "]";
$found = true;
}
}
}
else
{
$strquote = "No quotes exist. Add some!";
}
}
else
{
$sql = "SELECT * FROM #___quotes WHERE id=".$qnum;
$result = $this -> bot -> db -> select($sql, MYSQL_ASSOC);
if (!empty($result))
{
$strquote = "#" . $result[0]['id'] . " - " . $result[0]['quote'] . " [Contributed by: " . $result[0]['contributor'] . "]";
}
else
{
//$sql = "SELECT id FROM #___quotes ORDER BY id DESC LIMIT 1";
//$result = $this -> bot -> db -> select($sql, MYSQL_ASSOC);
//$num = $result[0];
$strquote = "Quote with id of " . $qnum . " not found. (Highest quote ID is " .$num. ".)";
}         
}
return $strquote;
} // End function send_quote()

/*
Searches the quote database.
*/
function search_quotes($searchterm, $origin="tell", $contributor=FALSE)
{ // Start function search_quotes()
$searchterm = mysql_real_escape_string($searchterm);
// If $searchterm is 3 characters or less, do a LIKE search.
// Otherwise, do a fulltext search of the index.
if ($contributor) // Only show quotes added by $contributor
{
$sql = "SELECT id,quote,contributor FROM #___quotes WHERE contributor LIKE '%".$searchterm."%'";
}
else if (strlen($searchterm) > 0 AND strlen($searchterm) < 4)
{
$sql = "SELECT id,quote,contributor FROM #___quotes WHERE quote LIKE '%".$searchterm."%' OR contributor LIKE '%".$searchterm."%'";
}
else
{
$sql = "SELECT id,quote,contributor FROM #___quotes WHERE MATCH (quote,contributor) AGAINST('".$searchterm."' IN BOOLEAN MODE)";
}
$result = $this -> bot -> db -> select($sql);

if (!is_array($result))
{
return "Sorry, no quotes found matching ".$searchterm;
}
else
{
$numresult = count($result);
}

if ($numresult == 1)
{
return $this -> send_quote($result[0][0]);
}

else if ($numresult > 1)
{
switch ($origin)
{
case "tell":
$chat = "/tell <botname>";
break;
case "pgmsg":
$chat = "/g <botname>";
break;
case "gc":
$chat = "/o";
break;
}
$inside = "Quotes Matching ".$searchterm.": \n\n";
foreach ($result as $answer)
{
$inside .= $answer[0].": <a href='chatcmd://".$chat." <pre>quotes ".$answer[0]."'>".substr(str_replace("<br>", "\n", $answer[1]), 0, 72)."</a>\n";
}
return $this -> bot -> core("tools") -> make_blob("Mutiple Search Results", $inside);
}
else
{
return FALSE;
}
} // End function search_quotes

} // End of class
?>

Offline clashbot

  • BeBot Expert
  • ****
  • Posts: 295
  • Karma: +0/-0
    • Ascension's Home
Re: Quotes module
« Reply #7 on: July 04, 2009, 04:44:54 pm »
getting an error on it:

fatal error: cannot use string offset as an array in quotes.php on line 213

also getting unknown column 'botname' in 'field list'

this was on adding a quote. If I just do "quotes" I get an error (same error) on line 255


 

* Recent Posts
Com bot module by bitnykk
[November 25, 2024, 05:36:11 pm ]


0.8.x updates for AO by bitnykk
[June 23, 2024, 03:19:47 pm ]


0.8.x updates for AoC by bitnykk
[June 23, 2024, 03:19:44 pm ]


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


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

* Who's Online
  • Dot Guests: 200
  • 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