LizardBot r69 - Code Review

From LizardWiki, FastLizard4's wiki and website
Jump to: navigation, search
Repository:LizardBot
Revision:r67‎ | r69 (on ViewVC)‎ | r70 >
Date:10:13, 19 August 2010
Author:FastLizard4
Status:resolved (Comments)
Tags:
Comment:
*Fixes multiple regex bugs throughout the bot. For example, one bug prevented fishbot and the AI from working when the bot's nickname contained regex metacharacters (such as d[^_^]b)
*MySQL functions are now loaded even if MySQL is disabled in the config file. This is so MySQL can be enabled while the bot is running without crashing the bot.
*Adds full support for the bit.ly (URL shortener) API. See extended documentation on the wiki.
NOTE: Changes in this update require an update of the configuration file.
Modified paths:

Diff [purge]

Index: lizardbot.php
@@ -56,7 +56,7 @@
5757 |_____||_______| |________||_| |_| |_| \__\ |____/
5858
5959 PHP-LizardBot: IRC bot developed by FastLizard4 (who else?) and the LizardBot Development Team
60 -Version 7.0.0.3b (major.minor.build.revision) BETA
 60+Version 7.1.0.0b (major.minor.build.revision) BETA
6161 Licensed under the Creative Commons GNU General Public License 2.0 (GPL)
6262 For licensing details, contact me or read this page:
6363 http://creativecommons.org/licenses/GPL/2.0/
@@ -92,7 +92,7 @@
9393 <?php
9494 //Check for updates
9595 echo "{$c_yellow}Checking for updates...\r\n";
96 -$version = "7.0.0.3b";
 96+$version = "7.1.0.0b";
9797 $upfp = @fopen('http://lizardwiki.dyndns.org/w/index.php?title=LizardBot/Latest&action=raw', 'r');
9898 $data = @fgets($upfp);
9999 @fclose($upfp);
@@ -157,9 +157,9 @@
158158 curl_setopt ($this->_Pipe, CURLOPT_POSTFIELDS, "Name=$name&input=$input");
159159 curl_setopt ($this->_Pipe, CURLOPT_FOLLOWLOCATION, 1);
160160 $reply = curl_exec($this->_Pipe);
161 - if(isset($reply) && !preg_match("/^\s*$/", $reply)){
 161+ if(isset($reply) && !preg_match('/^\s*$/', $reply)){
162162 return $this->get_say($reply);
163 - } elseif(!isset($reply) || preg_match("/^\s*$/", $reply)) {
 163+ } elseif(!isset($reply) || preg_match('/^\s*$/', $reply)) {
164164 return $this->default_response;
165165 }
166166 curl_close($this->_Pipe);
@@ -186,7 +186,7 @@
187187
188188 private function get_say($input, $tag='font'){
189189 // Do a little regex to get the bot reply
190 - $pattern = "#<$tag color=\"\w+\">(.*?)</$tag>#";
 190+ $pattern = "#<$tag color=\"\\w+\">(.*?)</$tag>#";
191191 $var = preg_match($pattern, $input, $matches);
192192 $result = $this->sanitize($matches[1]); // Get outout and send for validation
193193 /* Simple Sanity Check - Null */
@@ -414,35 +414,49 @@
415415 if($setMySQLTablePre) {
416416 $setMySQLTablePre .= "_";
417417 }
418 - echo "Creating the MySQL-related functions....\r\n";
419 - function dbConnect() {
420 - global $setMySQLHost, $setMySQLPort, $setMySQLUserName, $setMySQLPassword, $setMySQLDB;
421 - $mysql = mysqli_connect($setMySQLHost, $setMySQLUserName, $setMySQLPassword, $setMySQLDB, $setMySQLPort) OR
422 - print("{$c_red}Failed to connect to the MySQL server! Details:\r\n" .
423 - mysqli_connect_error() . "{$c_n}\r\n");
424 - return $mysql;
425 - }
426 - function mkSane($mysql, $data) {
427 - return trim(mysqli_real_escape_string($mysql, $data));
428 - }
429 - function dbQuery($mysql, $query, &$result) {
430 - $result = mysqli_query($mysql, $query);
431 - if(!$result) {
432 - echo "\r\nERROR: An error occured in the database query:\r\n";
433 - echo "\t" . $query . "\r\n";
434 - echo "MySQL returned the following error:\r\n";
435 - echo "\t" . mysqli_error($mysql) . "\r\n";
436 - return "An error occured in the MySQL database query. Please check the console for details.";
437 - } else {
438 - return false;
439 - }
440 - }
 418+}
 419+echo "Creating the MySQL-related functions....\r\n";
 420+if(!$setEnableMySQL) {
 421+ echo "You might be wondering why this is happening even though MySQL\r\n";
 422+ echo "is disabled. The functions are being created so that you can\r\n";
 423+ echo "enable MySQL support while the bot is running without crashing\r\n";
 424+ echo "the bot. However, before you try to do this (enable MySQL\r\n";
 425+ echo "support while the bot is running), make sure that you have read\r\n";
 426+ echo "the MySQL documentation on the wiki *COMPLETELY*, or bad stuff\r\n";
 427+ echo "*WILL* happen.\r\n";
 428+}
 429+function dbConnect() {
 430+ global $setMySQLHost, $setMySQLPort, $setMySQLUserName, $setMySQLPassword, $setMySQLDB;
 431+ $mysql = mysqli_connect($setMySQLHost, $setMySQLUserName, $setMySQLPassword, $setMySQLDB, $setMySQLPort) OR
 432+ print("{$c_red}Failed to connect to the MySQL server! Details:\r\n" .
 433+ mysqli_connect_error() . "{$c_n}\r\n");
 434+ return $mysql;
 435+}
 436+function mkSane($mysql, $data) {
 437+ return trim(mysqli_real_escape_string($mysql, $data));
 438+}
 439+function dbQuery($mysql, $query, &$result) {
 440+ $result = mysqli_query($mysql, $query);
 441+ if(!$result) {
 442+ echo "\r\nERROR: An error occured in the database query:\r\n";
 443+ echo "\t" . $query . "\r\n";
 444+ echo "MySQL returned the following error:\r\n";
 445+ echo "\t" . mysqli_error($mysql) . "\r\n";
 446+ return "An error occured in the MySQL database query. Please check the console for details.";
 447+ } else {
 448+ return false;
 449+ }
 450+}
 451+if($setEnableMySQL) {
441452 echo "Verifying connection to MySQL database....";
442453 $mysql = dbConnect();
443454 if(!mysql) {die();}
444455 mysqli_close($mysql);
445456 echo "{$_green} done!{$c_n}\r\n";
446457 }
 458+if(!$setBitlyAPISleep || !is_int($setBitlyAPISleep)) {
 459+ $setBitlyAPISleep = 30;
 460+}
447461 if(!$timezone) {
448462 echo <<<EOD
449463 {$c_red}WARNING! You did not specify a time zone! This means you are using
@@ -518,7 +532,7 @@
519533 echo <<<EOD
520534 {$c_bold}Now checking validity of the nickname using standard regex tests...\r\n
521535 EOD;
522 -if(!preg_match("/^([A-Za-z_\[\]\|])([\w-\[\]\^\|`])*$/", $nick)) {
 536+if(!preg_match('/^([A-Za-z_\[\]\|])([\w-\[\]\^\|`])*$/', $nick)) {
523537 echo <<<EOD
524538 {$c_n}{$c_red}The regex does not match the nick, meaning that the IRC daemon of the server
525539 you are attempting to connect to would likely reject your registration signal.
@@ -1180,9 +1194,7 @@
11811195 $dataai = explode(" :", $data);
11821196 // echo "dataai: " . $dataai[2] . "\r\n";
11831197 // echo "dataai1: " . $dataai[1] . "\r\n";
1184 - $patterns = array("/\|/", "/\[/", "/\]/");
1185 - $replacements = array("\|", "\[", "\]");
1186 - $nicksan = preg_replace($patterns, $replacements, $nick);
 1198+ $nicksan = preg_quote($nick, '/');
11871199 $regex = "/^";
11881200 $regex .= $nicksan;
11891201 $regex .= "(: |, | - ).*$/i";
@@ -1196,7 +1208,7 @@
11971209 $ai->set_timeout(180); // 60 should be fine
11981210 $rofl = $ai->say($msg); // This is what you want to get back to the user.
11991211 $aicount++;
1200 - if(!$rofl || preg_match("/^\s*$/", $rofl)) { $rofl = $ai->default_response; }
 1212+ if(!$rofl || preg_match('/^\s*$/', $rofl)) { $rofl = $ai->default_response; }
12011213 $target = explode("!", $d[0]);
12021214 $e = $target[0] . ": ";
12031215 sleep(2);
@@ -1247,7 +1259,7 @@
12481260 $data = NULL;
12491261 $tinyurl = trim($rdata);
12501262 // $tinyurl = urlencode($tinyurl);
1251 - if(!preg_match("#^(http|https)://.*$#i", $tinyurl)) {
 1263+ if(!preg_match('#^(http|https)://.*$#i', $tinyurl)) {
12521264 $data = "Invalid URL.";
12531265 } else {
12541266 $tinyfp = fopen("http://tinyurl.com/api-create.php?url={$tinyurl}","r") OR $data = "Error in connection to TinyURL API.";
@@ -1305,7 +1317,7 @@
13061318 if($d[3] == "{$setTrigger}update" && hasPriv('*')) {
13071319 $cmdcount++;
13081320 echo "Checking for updates...\r\n";
1309 - $version = "7.0.0.3b";
 1321+ $version = "7.1.0.0b";
13101322 $upfp = @fopen('http://lizardwiki.dyndns.org/w/index.php?title=LizardBot/Latest&action=raw', 'r');
13111323 $data = @fgets($upfp);
13121324 @fclose($upfp);
@@ -1705,6 +1717,190 @@
17061718 echo "-!- PRIVMSG $c :" . $e . $data . "\r\n";
17071719 fclose($tinyurl);
17081720 }
 1721+ if($d[3] == "{$setTrigger}bit.ly" && hasPriv('bit.ly') && $setEnableBitly && $setBitlyLogin && $setBitlyAPIKey) {
 1722+ /* Right then. Here lies the code that allows bit.ly (another URL shortener
 1723+ ** interaction. I'm going to try to actually document the code, since it will
 1724+ ** be unusually complex. It will use cURL and bit.ly's API, version 3. So, if you're
 1725+ ** ready for your brain to be exploded, read on!
 1726+ */
 1727+ // First thing is that the bit.ly API is rate limited. So, we'll prevent the bot from
 1728+ // making an API request too often by noting the time of each request. This will be
 1729+ // user configurable.
 1730+ $bitlyThisRequestTime = time();
 1731+ if($bitlyThisRequestTime - $bitlyLastRequestTime < $setBitlyAPISleep) { //We've exceeded the bot-based ratelimit, so abort.
 1732+ $data = "Rate limit exceeded. Please wait a few seconds, or contact the bot's operator to get the limit raised.";
 1733+ } else { // Ratelimit OK, proceed
 1734+ $bitlyLastRequestTime = $bitlyThisRequestTime;
 1735+ // Many of the cURL options (i.e., curl_setopt()) are going to be common across all possible API queries, so we're
 1736+ // going to go ahead and start "building" the query
 1737+ $apiPipe = curl_init();
 1738+ $apiPipeSetoptSuccess = curl_setopt_array($apiPipe, array( // Begin setting cURL Options
 1739+ CURLOPT_AUTOREFERER => TRUE ,
 1740+ CURLOPT_VERBOSE => TRUE , // So, if necessary, bot operators can read debugging stuff from STDERR
 1741+ CURLOPT_CONNECTTIMEOUT => 20 , // 20 seconds for a timeout seems reasonable enough. Lower might be better, though
 1742+ CURLOPT_PORT => 80 ,
 1743+// CURLOPT_PROTOCOLS => CURLPROTO_HTTP,
 1744+ CURLOPT_TIMEOUT => 30 , // 30 seconds is the maximum amount of time we want to wait for this to work
 1745+ CURLOPT_RETURNTRANSFER => TRUE , // I would like my data back, kthx
 1746+ CURLOPT_USERAGENT => "PHP-LizardBot/7.1.0.0b (compatible; +http://lizardwiki.dyndns.org/wiki/LizardBot)" //Set our useragent
 1747+ ));
 1748+ if(!$apiPipeSetoptSuccess) { // Uhoh, it looks like that, for some reason, configuration of the pipe failed.
 1749+ $data = "For some reason, curl_setopt_array() configuration failed. Perhaps you're running an obsolete version of PHP-cURL? Or perhaps your version of PHP is outdated?";
 1750+ } else { // Configuration worked, so we're free to continue.
 1751+ // First, we set the URL base for all API queries.
 1752+ $apiPipeURLBase = 'http://api.bit.ly/v3/';
 1753+ // Now, we need to figure out what query we need to run.
 1754+ if($d[4] == "shorten") { // User wants to shorten a link
 1755+ if(!$d[5]) {
 1756+ $data = "A required parameter, the URL to shorten, was not provided. Syntax: @bit.ly shorten URLtoShorten";
 1757+ } else {
 1758+ $apiPipeRequestURL = $apiPipeURLBase . "shorten?format=json&domain=bit.ly&login={$setBitlyLogin}&apiKey={$setBitlyAPIKey}&";
 1759+ // Now we need to handle the long URL that needs to be shortened. It must be URL encoded.
 1760+ $apiPipeRequestLongUrlE = explode('shorten', $data);
 1761+ $apiPipeRequestLongUrl = rawurlencode(trim($apiPipeRequestLongUrlE[1]));
 1762+ $apiPipeRequestURL .= "longUrl={$apiPipeRequestLongUrl}";
 1763+ curl_setopt($apiPipe, CURLOPT_URL, $apiPipeRequestURL); //Set the URL to be exec'd
 1764+ $apiPipeReturn = curl_exec($apiPipe); // GO!
 1765+ $apiPipeOut = json_decode($apiPipeReturn, TRUE); // So we can like do stuff with the data we get back
 1766+ if($apiPipeOut['status_code'] != 200) { // Whoops, we can has problem
 1767+ $data = "Hmm, something went wrong when I tried to shorten your URL. Here's what I got back from the API: ERROR {$apiPipeOut['status_code']}: {$apiPipeOut['status_txt']}.";
 1768+ } else { // Looks like everything ran correctly, so proceed
 1769+ if($apiPipeOut['data']['new_hash']) {
 1770+ $newHash = "Yes.";
 1771+ } else {
 1772+ $newHash = "No.";
 1773+ }
 1774+ $data = "Shortened URL: {$apiPipeOut['data']['url']} - Is this the first time the long URL you entered was shortened? {$newHash}";
 1775+ }
 1776+ }
 1777+ } elseif($d[4] == "expand") { // User wants to expand
 1778+ if(!$d[5]) {
 1779+ $data = "A required parameter, the (full) URL to expand, was not found. Syntax: @bit.ly expand bit.lyURL";
 1780+ } else {
 1781+ //This is pretty much a reuse of the shorten code
 1782+ $apiPipeRequestURL = $apiPipeURLBase . "expand?format=json&login={$setBitlyLogin}&apiKey={$setBitlyAPIKey}&";
 1783+ $apiPipeRequestLongUrlE = explode('expand', $data);
 1784+ $apiPipeRequestLongUrl = rawurlencode(trim($apiPipeRequestLongUrlE[1]));
 1785+ $apiPipeRequestURL .= "shortUrl={$apiPipeRequestLongUrl}";
 1786+ curl_setopt($apiPipe, CURLOPT_URL, $apiPipeRequestURL); //Set the URL to be exec'd
 1787+ $apiPipeReturn = curl_exec($apiPipe); // GO!
 1788+ $apiPipeOut = json_decode($apiPipeReturn, TRUE); // So we can like do stuff with the data we get back
 1789+ if($apiPipeOut['status_code'] != 200) { // Whoops, we can has problem
 1790+ $data = "Hmm, something went wrong when I tried to expand your bit.ly URL. Here's what I got back from the API: ERROR {$apiPipeOut['status_code']}: {$apiPipeOut['status_txt']}.";
 1791+ } else { // Looks like everything ran correctly, so proceed
 1792+ if($apiPipeOut['data']['expand'][0]['error']) {
 1793+ $data = "The API returned an error for your short URL. Here it is: {$apiPipeOut['data']['expand'][0]['error']}.";
 1794+ } else {
 1795+ $data = "For the short URL {$apiPipeOut['data']['expand'][0]['short_url']}, the corresponding long URL is: {$apiPipeOut['data']['expand'][0]['long_url']}";
 1796+ }
 1797+ }
 1798+ }
 1799+ } elseif($d[4] == "clicks") { // User wants to get clicks for an already existing URL
 1800+ if(!$d[5]) {
 1801+ $data = "A required parameter, the bit.ly URL to get click data for, was not found. Syntax: @bit.ly clicks bit.lyURL";
 1802+ } else {
 1803+ //This is pretty much a reuse of the expand code
 1804+ $apiPipeRequestURL = $apiPipeURLBase . "clicks?format=json&login={$setBitlyLogin}&apiKey={$setBitlyAPIKey}&";
 1805+ $apiPipeRequestLongUrlE = explode('clicks', $data);
 1806+ $apiPipeRequestLongUrl = rawurlencode(trim($apiPipeRequestLongUrlE[1]));
 1807+ $apiPipeRequestURL .= "shortUrl={$apiPipeRequestLongUrl}";
 1808+ curl_setopt($apiPipe, CURLOPT_URL, $apiPipeRequestURL); //Set the URL to be exec'd
 1809+ $apiPipeReturn = curl_exec($apiPipe); // GO!
 1810+ $apiPipeOut = json_decode($apiPipeReturn, TRUE); // So we can like do stuff with the data we get back
 1811+ if($apiPipeOut['status_code'] != 200) { // Whoops, we can has problem
 1812+ $data = "Hmm, something went wrong when I tried to expand your bit.ly URL. Here's what I got back from the API: ERROR {$apiPipeOut['status_code']}: {$apiPipeOut['status_txt']}.";
 1813+ } else { // Looks like everything ran correctly, so proceed
 1814+ if($apiPipeOut['data']['clicks'][0]['error']) {
 1815+ $data = "The API returned an error for your short URL. Here it is: {$apiPipeOut['data']['clicks'][0]['error']}.";
 1816+ } else {
 1817+ $data = "For the short URL {$apiPipeOut['data']['clicks'][0]['short_url']}, the number of user clicks (for {$setBitlyLogin}'s URL) is {$apiPipeOut['data']['clicks'][0]['user_clicks']} and the number of global clicks is {$apiPipeOut['data']['clicks'][0]['global_clicks']}.";
 1818+ }
 1819+ }
 1820+ }
 1821+ } elseif($d[4] == "checkpro") { // User wants to see if a domain is a bit.ly pro domain
 1822+ if(!$d[5]) {
 1823+ $data = "A required parameter, the domain to check, was not found. Syntax: @bit.ly checkpro domainToCheck";
 1824+ } else {
 1825+ //This is pretty much a reuse of the expand code
 1826+ $apiPipeRequestURL = $apiPipeURLBase . "bitly_pro_domain?format=json&login={$setBitlyLogin}&apiKey={$setBitlyAPIKey}&";
 1827+ $apiPipeRequestLongUrlE = explode('checkpro', $data);
 1828+ $apiPipeRequestLongUrl = rawurlencode(trim($apiPipeRequestLongUrlE[1]));
 1829+ $apiPipeRequestURL .= "domain={$apiPipeRequestLongUrl}";
 1830+ curl_setopt($apiPipe, CURLOPT_URL, $apiPipeRequestURL); //Set the URL to be exec'd
 1831+ $apiPipeReturn = curl_exec($apiPipe); // GO!
 1832+ $apiPipeOut = json_decode($apiPipeReturn, TRUE); // So we can like do stuff with the data we get back
 1833+ if($apiPipeOut['status_code'] != 200) { // Whoops, we can has problem
 1834+ $data = "Hmm, something went wrong when I tried to expand your bit.ly URL. Here's what I got back from the API: ERROR {$apiPipeOut['status_code']}: {$apiPipeOut['status_txt']}.";
 1835+ } else { // Looks like everything ran correctly, so proceed
 1836+ if($apiPipeOut['data']['bitly_pro_domain']) {
 1837+ $data = "The domain you entered, {$apiPipeOut['data']['domain']}, IS a bitly pro domain.";
 1838+ } else {
 1839+ $data = "The domain you entered, {$apiPipeOut['data']['domain']}, IS NOT a bitly pro domain.";
 1840+ }
 1841+ }
 1842+ }
 1843+ } elseif($d[4] == "lookup") { // User wants to lookup an already existing bit.ly link for a long URL
 1844+ if(!$d[5]) {
 1845+ $data = "A required parameter, the long URL to check, was not found. Syntax: @bit.ly lookup longURL";
 1846+ } else {
 1847+ //This is pretty much a reuse of the expand code
 1848+ $apiPipeRequestURL = $apiPipeURLBase . "lookup?format=json&login={$setBitlyLogin}&apiKey={$setBitlyAPIKey}&";
 1849+ $apiPipeRequestLongUrlE = explode('lookup', $data);
 1850+ $apiPipeRequestLongUrl = rawurlencode(trim($apiPipeRequestLongUrlE[1]));
 1851+ $apiPipeRequestURL .= "url={$apiPipeRequestLongUrl}";
 1852+ curl_setopt($apiPipe, CURLOPT_URL, $apiPipeRequestURL); //Set the URL to be exec'd
 1853+ $apiPipeReturn = curl_exec($apiPipe); // GO!
 1854+ $apiPipeOut = json_decode($apiPipeReturn, TRUE); // So we can like do stuff with the data we get back
 1855+ if($apiPipeOut['status_code'] != 200) { // Whoops, we can has problem
 1856+ $data = "Hmm, something went wrong when I tried to expand your bit.ly URL. Here's what I got back from the API: ERROR {$apiPipeOut['status_code']}: {$apiPipeOut['status_txt']}.";
 1857+ } else { // Looks like everything ran correctly, so proceed
 1858+ if($apiPipeOut['data']['lookup'][0]['error']) {
 1859+ $data = "The API returned an error for your long URL. Here it is: {$apiPipeOut['data']['lookup'][0]['error']}. If this is NOT_FOUND, it means that no bit.ly URL yet exists for the long URL you entered.";
 1860+ } else {
 1861+ $data = "For the long URL {$apiPipeOut['data']['lookup'][0]['url']}, the following bit.ly short URL already exists: {$apiPipeOut['data']['lookup'][0]['short_url']}";
 1862+ }
 1863+ }
 1864+ }
 1865+ } elseif($d[4] == "info") { // User wants to get info
 1866+ if(!$d[5]) {
 1867+ $data = "A required parameter, the bit.ly URL to get info for, was not found. Syntax: @bit.ly info bit.lyURL";
 1868+ } else {
 1869+ //This is pretty much a reuse of the shorten code
 1870+ $apiPipeRequestURL = $apiPipeURLBase . "info?format=json&login={$setBitlyLogin}&apiKey={$setBitlyAPIKey}&";
 1871+ $apiPipeRequestLongUrlE = explode('info', $data);
 1872+ $apiPipeRequestLongUrl = rawurlencode(trim($apiPipeRequestLongUrlE[1]));
 1873+ $apiPipeRequestURL .= "shortUrl={$apiPipeRequestLongUrl}";
 1874+ curl_setopt($apiPipe, CURLOPT_URL, $apiPipeRequestURL); //Set the URL to be exec'd
 1875+ $apiPipeReturn = curl_exec($apiPipe); // GO!
 1876+ $apiPipeOut = json_decode($apiPipeReturn, TRUE); // So we can like do stuff with the data we get back
 1877+ if($apiPipeOut['status_code'] != 200) { // Whoops, we can has problem
 1878+ $data = "Hmm, something went wrong when I tried to expand your bit.ly URL. Here's what I got back from the API: ERROR {$apiPipeOut['status_code']}: {$apiPipeOut['status_txt']}.";
 1879+ } else { // Looks like everything ran correctly, so proceed
 1880+ if($apiPipeOut['data']['info'][0]['error']) {
 1881+ $data = "The API returned an error for your short URL. Here it is: {$apiPipeOut['data']['info'][0]['error']}.";
 1882+ } else {
 1883+ $data = "For the short URL {$apiPipeOut['data']['info'][0]['short_url']}, the page title is: \"{$apiPipeOut['data']['info'][0]['title']}\" and the bit.ly URL was created by the bit.ly user \"{$apiPipeOut['data']['info'][0]['created_by']}\".";
 1884+ }
 1885+ }
 1886+ }
 1887+ } else {
 1888+ $data = "A required parameter, the action, was not provided. Syntax: @bit.ly action [otherArguments]";
 1889+ }
 1890+ }
 1891+ }
 1892+ curl_close($apiPipe); //End the cURL session
 1893+ $target = explode("!", $d[0]);
 1894+ $e = $target[0] . ": ";
 1895+ if($d[2] == $nick) {
 1896+ $target = explode("!", $d[0]);
 1897+ $c = $target[0];
 1898+ $e = NULL;
 1899+ } else {
 1900+ $c = $d[2];
 1901+ }
 1902+ fwrite($ircc, "PRIVMSG $c :" . $e . $data . "\r\n");
 1903+ echo "-!- PRIVMSG $c :" . $e . $data . "\r\n";
 1904+ }
17091905 if($d[3] == "{$setTrigger}fish" && hasPriv('*')) {
17101906 $cmdcount++;
17111907 if($setEnableFishbot) {
@@ -1906,7 +2102,7 @@
19072103 }
19082104 } */
19092105 foreach($fishAresponses as $regex2 => $mtpl) {
1910 - $regex = str_replace('%f', $nick, $regex2);
 2106+ $regex = str_replace('%f', preg_quote($nick, '/'), $regex2);
19112107 if(preg_match($regex,$toProcess,$m) && !$stop) {
19122108 $data = str_replace(array('%n','%c','%1'),array($e,$c,$m[1]),$mtpl);
19132109 $stop = TRUE;
@@ -1923,7 +2119,7 @@
19242120 }
19252121 }*/
19262122 foreach($fishCresponses as $regex2 => $mtpl) {
1927 - $regex = str_replace('%f', $nick, $regex2);
 2123+ $regex = str_replace('%f', preg_quote($nick, '/'), $regex2);
19282124 if(preg_match($regex,$fishdata,$m) && !$stop) {
19292125 $data = str_replace(array('%n','%c','%1'),array($e,$c,$m[1]),$mtpl);
19302126 $stop = TRUE;
Index: lizardbot.conf.php
@@ -1,4 +1,4 @@
2 -<?php
 2+\<?php
33 /***************************************
44 LizardBot configuration file
55 ****************************************
@@ -107,6 +107,24 @@
108108
109109 $setEnableReminders: Whether or not to enable the @remind command. Boolean, TRUE by default. REQUIRES MYSQL
110110 TO BE ENABLED!
 111+
 112+ $setEnableBitly: Set this boolean variable to TRUE if you want to enable support for bit.ly URL shortening and
 113+ other functions. WARNING: YOU MUST HAVE THE CURL EXTENSION INSTALLED FOR THIS TO WORK!
 114+ *DO NOT SET THIS TO TRUE* if you do not have CURL installed, as it will just cause the bot to crash!
 115+ Set this to TRUE to enable, FALSE to disable bit.ly support. The default value for this is FALSE,
 116+ since, strangely, the default PHP package on many systems /does not/ include PHP-cURL.
 117+$setBitlyAPISleep: The time you want to wait (in seconds) before allowing more use of the @bit.ly command. I.e.,
 118+ this is a bot-based rate limit so we don't trip the rate limit over at bit.ly's API. Variable accepts
 119+ an integer, default 30.
 120+ $setBitlyLogin: Your API Login username for bit.ly. You need one of these to use the API! All you need is a bit.ly account
 121+ to get this (and the API key for the next step). If you don't provide a login, bit.ly functions will not work.
 122+ Required for @bit.ly command, expects a string. Must be set with $setBitlyAPIKey!
 123+ $setBitlyAPIKey: Your API key for bit.ly. You need a bit.ly account to use the API! It's free, and it comes with a key.
 124+ If you don't provide this, bit.ly functions will not work. Required for @bit.ly command, expects a string.
 125+ Must be set with $setBitlyLogin!
 126+ ** NOTE ABOUT THE ABOVE TWO CONFIGURATION VARIABLES: You can get your API Login and Key (assuming that
 127+ you have a bit.ly account) here: http://bit.ly/a/your_api_key. If you don't have an account, you'll need
 128+ to create one to use the bit.ly functions.
111129
112130 [AUTOCONNECT BLOCK]
113131 This optional block, when configured, allows the bot to immeidately automatically connect to a network
@@ -175,6 +193,7 @@
176194 $privgroups[ '*' ][ 'fantasy' ] = 1;
177195 $privgroups[ '*' ][ 'insult' ] = 1;
178196 $privgroups[ '*' ][ 'tinyurl' ] = 1;
 197+$privgroups[ '*' ][ 'bit.ly' ] = 1;
179198 $privgroups[ '*' ][ 'fish' ] = 1;
180199 $pvivgroups[ '*' ][ 'remind' ] = 1;
181200
@@ -268,6 +287,11 @@
269288
270289 $setEnableReminders = TRUE;
271290
 291+ $setEnableBitly = FALSE;
 292+$setBitlyAPISleep = 30;
 293+ $setBitlyLogin = '';
 294+ $setBitlyAPIKey = '';
 295+
272296 #################################################
273297 # AUTOCONNECT #
274298 # BLOCK #

Comments

#Comment by FastLizard4 (Talk | contribs)   10:18, 19 August 2010

Sufficiently tested in development to get an immediate 'ok' mark.

#Comment by FastLizard4 (Talk | contribs)   09:54, 20 August 2010

Pfft, found a bug in the bit.ly code, to be fixed in the next revision.

#Comment by FastLizard4 (Talk | contribs)   10:23, 20 August 2010

Bugs fixed in r70.

Status & tagging log