Advertisement
Guest User

Untitled

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