Created
May 7, 2014 15:30
-
-
Save xeoncross/45a5a2d0e4e58773e627 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* This is daniel664's karma bot, fixed and stabilised by goeo_. | |
* It was a w_b_e fork anyway | |
*/ | |
set_time_limit(0); | |
error_reporting(0); | |
date_default_timezone_set('Europe/Istanbul'); | |
$server = "irc.freenode.org"; | |
$nick = "jbqakarmabot"; | |
$channels = array("#jailbreakqa", "#atxhack"); | |
$port = 6697; | |
$connection = fsockopen("ssl://{$server}", $port); | |
fputs ($connection, "USER $nick $nick $nick $nick :$nick\n"); | |
fputs ($connection, "NICK $nick\n"); | |
foreach ($channels as $channel){ | |
fputs ($connection, "JOIN $channel\n"); | |
} | |
$we = fopen ("php://stdin","r"); | |
stream_set_blocking($we,0); | |
stream_set_blocking($connection,0); | |
while(1){ | |
$mydata = fgets($we); | |
if($mydata){ | |
fputs($connection, "{$mydata}\n"); | |
} | |
while($data = fgets($connection)){ | |
echo nl2br($data); | |
flush(); | |
$a1 = explode(' ', $data); | |
$a2 = explode(':', $a1[3]); | |
$a3 = explode('@', $a1[0]); | |
$a4 = explode('!', $a3[0]); | |
$a5 = explode(':', $a4[0]); | |
$a6 = explode(':', $data); | |
$nicker = $a5[1]; | |
$inchannel = $a1[2]; | |
$command = $a2[1]; | |
if($a1[0] == "PING"){ | |
fputs($connection, "PONG ".$a1[1]."\n"); | |
} | |
$all1 = NULL; for ($i = 4; $i < count($a1); $i++) { | |
$add = str_replace("\n", "", $a1[$i]); | |
$add = str_replace("\r", "", $add); | |
$all1 .= $add . ' '; | |
} | |
$all = substr($all1, 0, -1); | |
if($command == "!karma"){ | |
echo ($all); | |
echo (urlencode($user)); | |
$user = $all; | |
$uurl = url($user,ge("http://www.jailbreakqa.com/users/?q=".urlencode($user))); | |
if(!$uurl){ | |
fputs($connection, "PRIVMSG {$inchannel} :{$nicker}: User not found.\n"); | |
} | |
else{ | |
fputs($connection, "PRIVMSG {$inchannel} :{$nicker}: {$user} has " . karma($uurl) . " karma.\n"); | |
} | |
} | |
} | |
} | |
function ge($url) | |
{ | |
$ch = curl_init( $url ); | |
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ); | |
curl_setopt( $ch, CURLOPT_HEADER, true ); | |
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); | |
curl_setopt( $ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); | |
$response = preg_split( '/([\r\n][\r\n])\\1/', curl_exec( $ch )); | |
$response = preg_split( '/([\r\n][\r\n]){2}/', curl_exec( $ch ),2); | |
curl_close( $ch ); | |
return $response[1]; | |
} | |
function url($user,$html) | |
{ | |
$dom = new DOMDocument(); | |
@$dom->loadHTML($html); | |
$opshit = "{$user} ♦"; | |
$oopshit = "{$user} ♦♦"; | |
$a = $dom->getElementsByTagName('a'); | |
for ($i =0; $i < $a->length; $i++) { | |
$elem = $a->item($i); | |
$cont = $elem->textContent; | |
$href = $elem->getAttribute("href"); | |
if(stripos($cont, $user) !== FALSE) | |
{ | |
return $href; | |
} | |
elseif(stripos($cont, $opshit) !== FALSE) | |
{ | |
return $href; | |
} | |
elseif(stripos($cont, $oopshit) !== FALSE) | |
{ | |
return $href; | |
} | |
} | |
return false; | |
} | |
function karma($userurl) | |
{ | |
$dom = new DOMDocument(); | |
@$dom->loadHTML(ge("http://www.jailbreakqa.com{$userurl}")); | |
$div = $dom->getElementById('user-reputation'); | |
return $div->textContent; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment