Add: Check if user exist.

This commit is contained in:
dennydai 2016-06-14 16:16:09 +08:00
parent 8eb00284f0
commit 4261e33836

View File

@ -4,48 +4,51 @@ PluginSet("find someone on Github");
$opts = array ('http' => array ('header' => "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0",)); $opts = array ('http' => array ('header' => "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0",));
if (strpos($plugin_text,"@") === 0) {$plugin_text = substr($plugin_text,1);} if (strpos($plugin_text,"@") === 0) {$plugin_text = substr($plugin_text,1);}
if (!strpos($plugin_text,'/')) { if (!strpos($plugin_text,'/')) {
$user = file_get_contents("https://api.github.com/users/".urlencode($plugin_text).'?access_token='.PLUGIN_GITHUB_TOKEN, false, stream_context_create($opts)); $user = file_get_contents("https://api.github.com/users/".urlencode($plugin_text).'?access_token='.PLUGIN_GITHUB_TOKEN, false, stream_context_create($opts));
$starred = file_get_contents("https://api.github.com/users/".urlencode($plugin_text)."/starred".'?access_token='.PLUGIN_GITHUB_TOKEN, false, stream_context_create($opts)); $starred = file_get_contents("https://api.github.com/users/".urlencode($plugin_text)."/starred".'?access_token='.PLUGIN_GITHUB_TOKEN, false, stream_context_create($opts));
$user = json_decode($user,true); $user = json_decode($user,true);
$msg = "ID: @".$user['login']; $msg = "ID: @".$user['login'];
plugin_github_check("Type", $user['type']); plugin_github_check("Type", $user['type']);
plugin_github_check("Name", $user['name']); plugin_github_check("Name", $user['name']);
plugin_github_check("Email", $user['email']); plugin_github_check("Email", $user['email']);
plugin_github_check("Company", $user['company']); plugin_github_check("Company", $user['company']);
if (count(json_decode($starred,true)) == 30) { if (count(json_decode($starred,true)) == 30) {
$starred = '>30'; $starred = '>30';
}else{ }else{
$starred = count(json_decode($starred,true)); $starred = count(json_decode($starred,true));
} }
plugin_github_check("Starred", $starred); plugin_github_check("Starred", $starred);
plugin_github_check("Repos", $user['public_repos']); plugin_github_check("Repos", $user['public_repos']);
plugin_github_check("Followers", $user['followers']); plugin_github_check("Followers", $user['followers']);
plugin_github_check("Following", $user['following']); plugin_github_check("Following", $user['following']);
@$msg .= "\nUrl: https://github.com/".$user['login']; @$msg .= "\nUrl: https://github.com/".$user['login'];
}else{ }else{
$repo = file_get_contents("https://api.github.com/repos/".$plugin_text.'?access_token='.PLUGIN_GITHUB_TOKEN, false, stream_context_create($opts)); $repo = file_get_contents("https://api.github.com/repos/".$plugin_text.'?access_token='.PLUGIN_GITHUB_TOKEN, false, stream_context_create($opts));
$repo = json_decode($repo,true); $repo = json_decode($repo,true);
$msg = "Name: ".$repo['name']; $msg = "Name: ".$repo['name'];
plugin_github_check("Description", $repo['description']); plugin_github_check("Description", $repo['description']);
plugin_github_check("Is Fork", $repo['fork']); plugin_github_check("Is Fork", $repo['fork']);
plugin_github_check("Stars", $repo['stargazers_count']); plugin_github_check("Stars", $repo['stargazers_count']);
plugin_github_check("Forks", $repo['forks_count']); plugin_github_check("Forks", $repo['forks_count']);
plugin_github_check("Language", $repo['language']); plugin_github_check("Language", $repo['language']);
@$msg .= "\nUrl: https://github.com/".$plugin_text; @$msg .= "\nUrl: https://github.com/".$plugin_text;
} }
function plugin_github_check($title, $check) function plugin_github_check($title, $check)
{ {
global $msg; global $msg;
if (!empty($check)) { if (!empty($check)) {
return @$msg .= "\n".$title.": ".$check; return @$msg .= "\n".$title.": ".$check;
}elseif ($check === true){ }elseif ($check === true){
return @$msg .= "\n".$title.": True"; return @$msg .= "\n".$title.": True";
}elseif ($check === false){ }elseif ($check === false){
return @$msg .= "\n".$title.": False"; return @$msg .= "\n".$title.": False";
} }
} }
if (!empty($user['login'])) {
$BOT->msg($plugin_sendto, $msg); $BOT->msg($plugin_sendto, $msg);
}else{
$BOT->msg($plugin_sendto, 'User Not Found.');
}