Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.49 KB | None | 0 0
  1. <?php
  2.     $token = "d229ca7525**************************************1ee4bff93c8c640a";
  3.     $id = "-188435782";
  4.    
  5.     function send($token, $id , $message)
  6.     {
  7.         $url = 'https://api.vk.com/method/messages.send';
  8.         $rand = rand(1000000000, 9999999999);
  9.         $params = array(
  10.             'user_id' => $id,
  11.             'message' => $message,
  12.             'random_id' => $rand,
  13.             'access_token' => $token,
  14.             'v' => '5.95',
  15.         );
  16.  
  17.         // В $result вернется id отправленного сообщения
  18.         $result = file_get_contents($url, false, stream_context_create(array(
  19.             'http' => array(
  20.                 'method'  => 'POST',
  21.                 'header'  => 'Content-type: application/x-www-form-urlencoded',
  22.                 'content' => http_build_query($params)
  23.             )
  24.         )));
  25.     }
  26.    
  27.     function ArrayLetters($length, $proto, $dead) {
  28.          
  29.         $dict = file("wordlist/" . $length . "_letters.txt", FILE_IGNORE_NEW_LINES);
  30.          
  31.         $exp = '/^' . str_replace('*', '\w{1}', $proto) . '$/u';
  32.         $words = array_filter($dict, function ($v) use ($exp, $dead) {
  33.             $dw = true;
  34.             foreach (array_diff(preg_split('//u', $dead), ['']) as $d) {
  35.                 if (preg_match('/' . $d . '/u', $v)) {
  36.                     $dw = false;
  37.                     break;
  38.                 };
  39.             }
  40.             return (preg_match($exp, $v) && $dw);
  41.         });
  42.          
  43.         $letters = [];
  44.         foreach ($words as $v) {
  45.             $imp = implode('|', preg_split('//u', str_replace('*', '', $proto)));
  46.             foreach (array_diff(preg_split('//u', preg_replace('/(' . $imp . ')/u', '', $v)), ['']) as $w) {
  47.                 $letters[] = $w;
  48.             }
  49.         }
  50.          
  51.         $percentageLetters = [];
  52.         $count = count($words);
  53.         foreach (array_unique($letters) as $v) {
  54.             $c = 0;
  55.             foreach ($words as $w) {
  56.                 if (preg_match('/' . $v . '/u', $w)) $c++;
  57.             }
  58.             $percentageLetters[] = ['letter' => $v, 'percent' => round(($c / $count * 100), 1) . '%'];
  59.         }
  60.         uasort($percentageLetters, function ($a, $b) {
  61.             return ((float)$a['percent'] > (float)$b['percent']) ? -1 : 1;
  62.         });
  63.        
  64.         /* массив букв со 100% вероятностью */
  65.         $arrPercent100 = array_values(array_filter($percentageLetters, function($data) {
  66.             return ((float)$data['percent'] == 100);
  67.         }));
  68.        
  69.         /* буква с самым большим процентом */
  70.         $mostLetter = array_shift($percentageLetters);
  71.          
  72.         if ($arrPercent100) {
  73.             print_r($arrPercent100);
  74.         }
  75.         elseif ($mostLetter) {
  76.             print_r($mostLetter);
  77.         }
  78.     }
  79.    
  80.     function getlastmess($token, $id, $type)
  81.     {
  82.         $url = 'https://api.vk.com/method/messages.getHistory';
  83.         $params = array(
  84.             'count' => 1,
  85.             'user_id' => $id,
  86.             'access_token' => $token,
  87.             'v' => '5.95',
  88.         );
  89.  
  90.         // В $result вернется id отправленного сообщения
  91.         $result = file_get_contents($url, false, stream_context_create(array(
  92.             'http' => array(
  93.                 'method'  => 'POST',
  94.                 'header'  => 'Content-type: application/x-www-form-urlencoded',
  95.                 'content' => http_build_query($params)
  96.             )
  97.         )));
  98.        
  99.         $arresult = json_decode($result, true);
  100.         $lastmes = $arresult['response']['items'][0]['text'];
  101.         $exparresult = explode("\n",$lastmes);
  102.        
  103.         switch ($type) {
  104.             case "proto":
  105.                 $letters = str_replace('📗 Отгаданные буквы:', '', $exparresult[0]);
  106.                 break;
  107.             case "dead":
  108.                 $letters = str_replace(array('👿 Неверные попытки:', ', '), '', $exparresult[1]);
  109.                 break;
  110.         }
  111.        
  112.         return $letters;
  113.        
  114.     }
  115.    
  116.     $length = strlen(getlastmess($token, $id, "proto"))-1;
  117.     $proto = getlastmess($token, $id, "proto");
  118.     $dead = getlastmess($token, $id, "dead");
  119.     ArrayLetters($length, $proto, $dead);
  120. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement