Advertisement
tristamoff

Untitled

Feb 19th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.13 KB | None | 0 0
  1.  
  2. function commIsUser($text) {
  3.   $text = trim($text);//обрезаем пробелы в начале и в конце
  4.   $space = strpos($text, ' ');
  5.   if (($space === FALSE) && (mb_substr($text, 0, 1) == '@')) {
  6.     //возможно это ник пользователя
  7.     //подключаемся к блокчейну
  8.     require('vendor/autoload.php');
  9.     $client = new WebSocket\Client("wss://ws.golos.io/");
  10.     $req = json_encode(
  11.       [
  12.         'id' => 1, 'method' => 'get_accounts', 'params' => [[mb_substr($text, 1)]]
  13.       ]
  14.     );
  15.     $client->send($req);
  16.     $golos_resp = $client->receive();
  17.     $resp_object = json_decode($golos_resp);
  18.     if (!empty($resp_object->result)) {
  19.       $obj = $resp_object->result[0];
  20.       $user = array();
  21.       $user[] = 'ID: ' . $obj->id;
  22.       $user[] = 'Логин: ' . $obj->name;
  23.       $user[] = 'Аккаунт создан: ' . $obj->created;
  24.       $user[] = 'Последний раз голосовал: ' . $obj->last_vote_time;
  25.       $user[] = 'Голосов: ' . $obj->balance;
  26.       $user[] = 'Золота: ' . $obj->sbd_balance;
  27.       $user[] = 'Создано постов: ' . $obj->post_count;
  28.  
  29.       //расчёт репутации
  30.       $reputation = $obj->reputation;
  31.       $user[] = 'Репутация: ' . round((max(log10(abs($reputation)) - 9,0) * (($reputation >= 0) ? 1 : -1) * 9 + 25), 3);
  32.  
  33.       $json_metadata = json_decode($obj->json_metadata);
  34.       if (!empty($json_metadata->user_image)) {
  35.         //фото
  36.         // передавать не буду, так как у некоторых логинов "заколдованные" аватары и сообщение в телеграм не приходит
  37.        // $user[] = 'Аватар: ' . $json_metadata->user_image;
  38.       }
  39.       $text = implode("\n", $user);
  40.  
  41.       $data = array(
  42.         'text' => $text,
  43.         'parse_mode' => 'Markdown',
  44.       );
  45.     }
  46.     else {
  47.       $data = array(
  48.         'text' => 'Пользователь не найден.',
  49.       );
  50.     }
  51.     $client->close();
  52.  
  53.     if (!empty($data)) {
  54.       return $data;
  55.     }
  56.   }
  57.   return NULL;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement