0 Members and 1 Guest are viewing this topic.
Jayina [2008-07-08 16:42:30] [TELL] [INC] Stormriser: !quotes testFatal error: Cannot use string offset as an array in C:\php5\bebot-hyborian\modules\Quotes.php on line 125
<?/** 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?>