Index: lizardbot.php |
— | — | @@ -56,7 +56,7 @@ |
57 | 57 | |_____||_______| |________||_| |_| |_| \__\ |____/ |
58 | 58 | |
59 | 59 | 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 |
61 | 61 | Licensed under the Creative Commons GNU General Public License 2.0 (GPL) |
62 | 62 | For licensing details, contact me or read this page: |
63 | 63 | http://creativecommons.org/licenses/GPL/2.0/ |
— | — | @@ -92,7 +92,7 @@ |
93 | 93 | <?php |
94 | 94 | //Check for updates |
95 | 95 | echo "{$c_yellow}Checking for updates...\r\n"; |
96 | | -$version = "7.0.0.3b"; |
| 96 | +$version = "7.1.0.0b"; |
97 | 97 | $upfp = @fopen('http://lizardwiki.dyndns.org/w/index.php?title=LizardBot/Latest&action=raw', 'r'); |
98 | 98 | $data = @fgets($upfp); |
99 | 99 | @fclose($upfp); |
— | — | @@ -157,9 +157,9 @@ |
158 | 158 | curl_setopt ($this->_Pipe, CURLOPT_POSTFIELDS, "Name=$name&input=$input"); |
159 | 159 | curl_setopt ($this->_Pipe, CURLOPT_FOLLOWLOCATION, 1); |
160 | 160 | $reply = curl_exec($this->_Pipe); |
161 | | - if(isset($reply) && !preg_match("/^\s*$/", $reply)){ |
| 161 | + if(isset($reply) && !preg_match('/^\s*$/', $reply)){ |
162 | 162 | return $this->get_say($reply); |
163 | | - } elseif(!isset($reply) || preg_match("/^\s*$/", $reply)) { |
| 163 | + } elseif(!isset($reply) || preg_match('/^\s*$/', $reply)) { |
164 | 164 | return $this->default_response; |
165 | 165 | } |
166 | 166 | curl_close($this->_Pipe); |
— | — | @@ -186,7 +186,7 @@ |
187 | 187 | |
188 | 188 | private function get_say($input, $tag='font'){ |
189 | 189 | // Do a little regex to get the bot reply |
190 | | - $pattern = "#<$tag color=\"\w+\">(.*?)</$tag>#"; |
| 190 | + $pattern = "#<$tag color=\"\\w+\">(.*?)</$tag>#"; |
191 | 191 | $var = preg_match($pattern, $input, $matches); |
192 | 192 | $result = $this->sanitize($matches[1]); // Get outout and send for validation |
193 | 193 | /* Simple Sanity Check - Null */ |
— | — | @@ -414,35 +414,49 @@ |
415 | 415 | if($setMySQLTablePre) { |
416 | 416 | $setMySQLTablePre .= "_"; |
417 | 417 | } |
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) { |
441 | 452 | echo "Verifying connection to MySQL database...."; |
442 | 453 | $mysql = dbConnect(); |
443 | 454 | if(!mysql) {die();} |
444 | 455 | mysqli_close($mysql); |
445 | 456 | echo "{$_green} done!{$c_n}\r\n"; |
446 | 457 | } |
| 458 | +if(!$setBitlyAPISleep || !is_int($setBitlyAPISleep)) { |
| 459 | + $setBitlyAPISleep = 30; |
| 460 | +} |
447 | 461 | if(!$timezone) { |
448 | 462 | echo <<<EOD |
449 | 463 | {$c_red}WARNING! You did not specify a time zone! This means you are using |
— | — | @@ -518,7 +532,7 @@ |
519 | 533 | echo <<<EOD |
520 | 534 | {$c_bold}Now checking validity of the nickname using standard regex tests...\r\n |
521 | 535 | EOD; |
522 | | -if(!preg_match("/^([A-Za-z_\[\]\|])([\w-\[\]\^\|`])*$/", $nick)) { |
| 536 | +if(!preg_match('/^([A-Za-z_\[\]\|])([\w-\[\]\^\|`])*$/', $nick)) { |
523 | 537 | echo <<<EOD |
524 | 538 | {$c_n}{$c_red}The regex does not match the nick, meaning that the IRC daemon of the server |
525 | 539 | you are attempting to connect to would likely reject your registration signal. |
— | — | @@ -1180,9 +1194,7 @@ |
1181 | 1195 | $dataai = explode(" :", $data); |
1182 | 1196 | // echo "dataai: " . $dataai[2] . "\r\n"; |
1183 | 1197 | // echo "dataai1: " . $dataai[1] . "\r\n"; |
1184 | | - $patterns = array("/\|/", "/\[/", "/\]/"); |
1185 | | - $replacements = array("\|", "\[", "\]"); |
1186 | | - $nicksan = preg_replace($patterns, $replacements, $nick); |
| 1198 | + $nicksan = preg_quote($nick, '/'); |
1187 | 1199 | $regex = "/^"; |
1188 | 1200 | $regex .= $nicksan; |
1189 | 1201 | $regex .= "(: |, | - ).*$/i"; |
— | — | @@ -1196,7 +1208,7 @@ |
1197 | 1209 | $ai->set_timeout(180); // 60 should be fine |
1198 | 1210 | $rofl = $ai->say($msg); // This is what you want to get back to the user. |
1199 | 1211 | $aicount++; |
1200 | | - if(!$rofl || preg_match("/^\s*$/", $rofl)) { $rofl = $ai->default_response; } |
| 1212 | + if(!$rofl || preg_match('/^\s*$/', $rofl)) { $rofl = $ai->default_response; } |
1201 | 1213 | $target = explode("!", $d[0]); |
1202 | 1214 | $e = $target[0] . ": "; |
1203 | 1215 | sleep(2); |
— | — | @@ -1247,7 +1259,7 @@ |
1248 | 1260 | $data = NULL; |
1249 | 1261 | $tinyurl = trim($rdata); |
1250 | 1262 | // $tinyurl = urlencode($tinyurl); |
1251 | | - if(!preg_match("#^(http|https)://.*$#i", $tinyurl)) { |
| 1263 | + if(!preg_match('#^(http|https)://.*$#i', $tinyurl)) { |
1252 | 1264 | $data = "Invalid URL."; |
1253 | 1265 | } else { |
1254 | 1266 | $tinyfp = fopen("http://tinyurl.com/api-create.php?url={$tinyurl}","r") OR $data = "Error in connection to TinyURL API."; |
— | — | @@ -1305,7 +1317,7 @@ |
1306 | 1318 | if($d[3] == "{$setTrigger}update" && hasPriv('*')) { |
1307 | 1319 | $cmdcount++; |
1308 | 1320 | echo "Checking for updates...\r\n"; |
1309 | | - $version = "7.0.0.3b"; |
| 1321 | + $version = "7.1.0.0b"; |
1310 | 1322 | $upfp = @fopen('http://lizardwiki.dyndns.org/w/index.php?title=LizardBot/Latest&action=raw', 'r'); |
1311 | 1323 | $data = @fgets($upfp); |
1312 | 1324 | @fclose($upfp); |
— | — | @@ -1705,6 +1717,190 @@ |
1706 | 1718 | echo "-!- PRIVMSG $c :" . $e . $data . "\r\n"; |
1707 | 1719 | fclose($tinyurl); |
1708 | 1720 | } |
| 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 | + } |
1709 | 1905 | if($d[3] == "{$setTrigger}fish" && hasPriv('*')) { |
1710 | 1906 | $cmdcount++; |
1711 | 1907 | if($setEnableFishbot) { |
— | — | @@ -1906,7 +2102,7 @@ |
1907 | 2103 | } |
1908 | 2104 | } */ |
1909 | 2105 | foreach($fishAresponses as $regex2 => $mtpl) { |
1910 | | - $regex = str_replace('%f', $nick, $regex2); |
| 2106 | + $regex = str_replace('%f', preg_quote($nick, '/'), $regex2); |
1911 | 2107 | if(preg_match($regex,$toProcess,$m) && !$stop) { |
1912 | 2108 | $data = str_replace(array('%n','%c','%1'),array($e,$c,$m[1]),$mtpl); |
1913 | 2109 | $stop = TRUE; |
— | — | @@ -1923,7 +2119,7 @@ |
1924 | 2120 | } |
1925 | 2121 | }*/ |
1926 | 2122 | foreach($fishCresponses as $regex2 => $mtpl) { |
1927 | | - $regex = str_replace('%f', $nick, $regex2); |
| 2123 | + $regex = str_replace('%f', preg_quote($nick, '/'), $regex2); |
1928 | 2124 | if(preg_match($regex,$fishdata,$m) && !$stop) { |
1929 | 2125 | $data = str_replace(array('%n','%c','%1'),array($e,$c,$m[1]),$mtpl); |
1930 | 2126 | $stop = TRUE; |
Index: lizardbot.conf.php |
— | — | @@ -1,4 +1,4 @@ |
2 | | -<?php |
| 2 | +\<?php |
3 | 3 | /*************************************** |
4 | 4 | LizardBot configuration file |
5 | 5 | **************************************** |
— | — | @@ -107,6 +107,24 @@ |
108 | 108 | |
109 | 109 | $setEnableReminders: Whether or not to enable the @remind command. Boolean, TRUE by default. REQUIRES MYSQL |
110 | 110 | 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. |
111 | 129 | |
112 | 130 | [AUTOCONNECT BLOCK] |
113 | 131 | This optional block, when configured, allows the bot to immeidately automatically connect to a network |
— | — | @@ -175,6 +193,7 @@ |
176 | 194 | $privgroups[ '*' ][ 'fantasy' ] = 1; |
177 | 195 | $privgroups[ '*' ][ 'insult' ] = 1; |
178 | 196 | $privgroups[ '*' ][ 'tinyurl' ] = 1; |
| 197 | +$privgroups[ '*' ][ 'bit.ly' ] = 1; |
179 | 198 | $privgroups[ '*' ][ 'fish' ] = 1; |
180 | 199 | $pvivgroups[ '*' ][ 'remind' ] = 1; |
181 | 200 | |
— | — | @@ -268,6 +287,11 @@ |
269 | 288 | |
270 | 289 | $setEnableReminders = TRUE; |
271 | 290 | |
| 291 | + $setEnableBitly = FALSE; |
| 292 | +$setBitlyAPISleep = 30; |
| 293 | + $setBitlyLogin = ''; |
| 294 | + $setBitlyAPIKey = ''; |
| 295 | + |
272 | 296 | ################################################# |
273 | 297 | # AUTOCONNECT # |
274 | 298 | # BLOCK # |