Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set('display_errors', 1);
- error_reporting(E_ALL);
- function vkunread() {
- $access_token = 'xxx';
- $post_data = [
- 'count' => 200,
- 'preview_length' => 1,
- 'access_token' => $access_token
- ];
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'https://api.vkontakte.ru/method/messages.get');
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $request = curl_exec($ch);
- $response = json_decode($request);
- curl_close($ch);
- $unread = [];
- foreach($response->response as $message) {
- if(gettype($message) == 'object' && !$message->read_state) {
- array_push($unread, $message->uid);
- }
- }
- if(!$unread) {
- return false;
- }
- $text = '*Вконтакте: ' . count($unread) . "*\n";
- $authors = array_unique($unread);
- $post_data = [
- 'user_ids' => implode(',', $authors),
- 'access_token' => $access_token
- ];
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'https://api.vkontakte.ru/method/users.get');
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $request = curl_exec($ch);
- $response = json_decode($request);
- curl_close($ch);
- $names = [];
- foreach($response->response as $user) {
- $GLOBALS['search_id'] = $user->uid;
- $count = count(array_filter($unread, function($id) {
- return $id == $GLOBALS['search_id'];
- }));
- array_push($names, $user->first_name . ' ' . $user->last_name . ' (' . $count . ')');
- }
- return $text .= implode(', ', $names);
- }
- function mailunread() {
- $imap = imap_open('{imap.yandex.ru/imap:143}Work', 'seibel.stan', 'xxx');
- //return json_encode(imap_getmailboxes($imap, '{imap.yandex.ru}', '*'));
- $text = '';
- $unread = [];
- $count_all = imap_check($imap)->Nmsgs;
- if(!$count_all) {
- return false;
- }
- $messages = imap_fetch_overview($imap, '1:' . $count_all, 0);
- foreach($messages as $message) {
- if(!$message->seen) {
- $from = $message->from;
- $from = mb_decode_mimeheader($from);
- array_push($unread, $from);
- }
- }
- if(!$unread) {
- return false;
- }
- $text = '*Почта: ' . count($unread) . "*\n";
- $authors = array_unique($unread);
- $names = [];
- foreach($authors as $user) {
- $GLOBALS['search_id'] = $user;
- $count = count(array_filter($unread, function($id) {
- return $id == $GLOBALS['search_id'];
- }));
- array_push($names, $user . ' (' . $count . ')');
- }
- return $text .= implode(', ', $names);
- }
- $vkunread = vkunread();
- $mailunread = mailunread();
- $text = $vkunread;
- if(vkunread()) {
- $text .= "\n";
- }
- $text .= $mailunread;
- $dir = 'bots/';
- include('bots/connect.php');
- $lazy->sendMessage([
- 'chat_id' => 53540040,
- 'text' => $text,
- 'parse_mode' => 'Markdown'
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement