Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors', 1);
  3. error_reporting(E_ALL);
  4.  
  5. function vkunread() {
  6. $access_token = 'xxx';
  7.  
  8. $post_data = [
  9. 'count' => 200,
  10. 'preview_length' => 1,
  11. 'access_token' => $access_token
  12. ];
  13. $ch = curl_init();
  14. curl_setopt($ch, CURLOPT_URL, 'https://api.vkontakte.ru/method/messages.get');
  15. curl_setopt($ch, CURLOPT_POST, 1);
  16. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  17. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  18. $request = curl_exec($ch);
  19. $response = json_decode($request);
  20. curl_close($ch);
  21.  
  22. $unread = [];
  23. foreach($response->response as $message) {
  24. if(gettype($message) == 'object' && !$message->read_state) {
  25. array_push($unread, $message->uid);
  26. }
  27. }
  28.  
  29. if(!$unread) {
  30. return false;
  31. }
  32.  
  33. $text = '*Вконтакте: ' . count($unread) . "*\n";
  34.  
  35. $authors = array_unique($unread);
  36.  
  37. $post_data = [
  38. 'user_ids' => implode(',', $authors),
  39. 'access_token' => $access_token
  40. ];
  41. $ch = curl_init();
  42. curl_setopt($ch, CURLOPT_URL, 'https://api.vkontakte.ru/method/users.get');
  43. curl_setopt($ch, CURLOPT_POST, 1);
  44. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  45. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  46. $request = curl_exec($ch);
  47. $response = json_decode($request);
  48. curl_close($ch);
  49.  
  50. $names = [];
  51. foreach($response->response as $user) {
  52. $GLOBALS['search_id'] = $user->uid;
  53. $count = count(array_filter($unread, function($id) {
  54. return $id == $GLOBALS['search_id'];
  55. }));
  56. array_push($names, $user->first_name . ' ' . $user->last_name . ' (' . $count . ')');
  57. }
  58.  
  59. return $text .= implode(', ', $names);
  60. }
  61.  
  62. function mailunread() {
  63. $imap = imap_open('{imap.yandex.ru/imap:143}Work', 'seibel.stan', 'xxx');
  64. //return json_encode(imap_getmailboxes($imap, '{imap.yandex.ru}', '*'));
  65.  
  66. $text = '';
  67. $unread = [];
  68. $count_all = imap_check($imap)->Nmsgs;
  69.  
  70. if(!$count_all) {
  71. return false;
  72. }
  73.  
  74. $messages = imap_fetch_overview($imap, '1:' . $count_all, 0);
  75.  
  76. foreach($messages as $message) {
  77. if(!$message->seen) {
  78. $from = $message->from;
  79. $from = mb_decode_mimeheader($from);
  80. array_push($unread, $from);
  81. }
  82. }
  83.  
  84. if(!$unread) {
  85. return false;
  86. }
  87.  
  88. $text = '*Почта: ' . count($unread) . "*\n";
  89.  
  90. $authors = array_unique($unread);
  91.  
  92. $names = [];
  93. foreach($authors as $user) {
  94. $GLOBALS['search_id'] = $user;
  95. $count = count(array_filter($unread, function($id) {
  96. return $id == $GLOBALS['search_id'];
  97. }));
  98. array_push($names, $user . ' (' . $count . ')');
  99. }
  100.  
  101. return $text .= implode(', ', $names);
  102. }
  103.  
  104. $vkunread = vkunread();
  105. $mailunread = mailunread();
  106.  
  107. $text = $vkunread;
  108. if(vkunread()) {
  109. $text .= "\n";
  110. }
  111. $text .= $mailunread;
  112.  
  113. $dir = 'bots/';
  114. include('bots/connect.php');
  115. $lazy->sendMessage([
  116. 'chat_id' => 53540040,
  117. 'text' => $text,
  118. 'parse_mode' => 'Markdown'
  119. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement