MadelineProto/magna.php

308 lines
15 KiB
PHP
Raw Normal View History

2017-07-31 19:17:10 +02:00
#!/usr/bin/env php
<?php
/*
Copyright 2016-2018 Daniil Gentili
2017-07-31 19:17:10 +02:00
(https://daniil.it)
This file is part of MadelineProto.
MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU General Public License along with MadelineProto.
If not, see <http://www.gnu.org/licenses/>.
2019-03-29 20:25:42 +01:00
*/
set_include_path(get_include_path() . ':' . realpath(dirname(__FILE__) . '/MadelineProto/'));
2017-08-18 13:27:44 +02:00
2019-03-29 20:25:42 +01:00
if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
echo 'You did not run composer update, using madeline.php' . PHP_EOL;
2018-03-29 23:06:40 +02:00
if (!file_exists('madeline.php')) {
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
}
include 'madeline.php';
} else {
require_once 'vendor/autoload.php';
}
Merge alpha into master (async, huge bugfixes and more) (#546) * Implement async and lots of bugfixes * Implement more async * Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr * Apply fixes from StyleCI * Bugfixes * Apply fixes from StyleCI * Bugfixes, implement combined promises * Apply fixes from StyleCI * Support passing method arguments as callable * Starting to write async upload logic * Apply fixes from StyleCI * Start implementing async file upload * Apply fixes from StyleCI * bugfix * Apply fixes from StyleCI * Start rewriting connection module * Add PHP file docblocks for all classes * Start working on new async stream API * Finish writing stream API * More stream API fixes * Apply fixes from StyleCI * Rewrite DataCenter and Connection modules * Clean up stream API documentation * Fixes * Apply fixes from StyleCI * Add referenced parameter to get length of buffer to read in getReadBuffer API * Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar * Start fixing reads * Fix all protocol stream wrappers * Apply fixes from StyleCI * Implement disconnection, and remove end function * Working async RPC * Implement async file upload * Bugfix * Method recall bugfixes * Bugfixes * Trait bugfixes * Fix FIFO buffer * Bugfixes and speedtests * Async logging * Implement websocket streams * Implement loop API, signal API, clean closing and start changing layer * Small magna, websocket and HTTP fixes * Clean up loop API * Improved stack traces, 2FA and async * Login fixes * Added instructions for manual verification * Small fixes * More app info improvements * More app info improvements * TL and 2FA fixes * Update to layer 89 * More bugfixes * Implement broken media reporting * Remove debug comments * PHP 7.2 backwards compatibility * Bugfixes * Async key generation * Some simplifications * Transport fixes * Cleanup * async API * Performance fixes * Fixes to async API * Bugfixes * Implement one-time async loop * Authorization and logging fixes * Update to layer 91 * 7to5 fix * Null coalesce conversion * Implement socks5 proxy * Implement HTTP proxy * Fixes to HTTP proxy * MTProxy and socks5 fixes * Disable PHP 5 conversion * Proxies have higher priority * Avoid error handling in vendor * Override composer dependencies * Fix travis build * Final composer fixes * Proxy logic fixes * Fix get_updates update handling * Do not use parallel file driver if not supported * Refactor loader and implement HTTP fixes * Suppress errors in loader * HTTP and authorization fixes * HTTP fixes * Improved peer management * Use HTTP protocol on altervista * Small bugfixes * Minor fixes * Docufix * Docufix * Legacy fixes * Fix message queue * Avoid updating if using MTProxy * Improve logs and examples * Trim final newlines while converting parse mode * Reimplement noResponse flag * Async combined event handler and APIFactory fixes * Actually return config * Case-insensitive methods * Bugfix * Apply fixes from StyleCI (#545) * MTProxy fixes * PHP 5 warning * Improved PHP 5 warning * Use <br> along with newlines in web logs * Update docs
2018-12-26 20:51:14 +01:00
if (!file_exists('songs.php')) {
copy('https://github.com/danog/MadelineProto/raw/master/songs.php', 'songs.php');
2017-07-31 19:17:10 +02:00
}
2019-03-29 20:25:42 +01:00
echo 'Deserializing MadelineProto from session.madeline...' . PHP_EOL;
2017-08-13 18:52:32 +02:00
/*if (!isset($MadelineProto->inputEncryptedFilePhoto) && false) {
2019-03-29 20:25:42 +01:00
$MadelineProto->inputEncryptedFilePhoto = $MadelineProto->upload_encrypted('tests/faust.jpg', 'fausticorn.jpg'); // This gets an inputFile object with file name magic
$MadelineProto->inputEncryptedFileGif = $MadelineProto->upload_encrypted('tests/pony.mp4');
$MadelineProto->inputEncryptedFileSticker = $MadelineProto->upload_encrypted('tests/lel.webp');
$MadelineProto->inputEncryptedFileDocument = $MadelineProto->upload_encrypted('tests/60', 'magic'); // This gets an inputFile object with file name magic
$MadelineProto->inputEncryptedFileVideo = $MadelineProto->upload_encrypted('tests/swing.mp4');
$MadelineProto->inputEncryptedFileAudio = $MadelineProto->upload_encrypted('tests/mosconi.mp3');
}*/
2017-12-16 19:08:11 +01:00
class EventHandler extends \danog\MadelineProto\EventHandler
2018-03-24 19:06:19 +01:00
{
public function configureCall($call)
{
include 'songs.php';
$call->configuration['enable_NS'] = false;
$call->configuration['enable_AGC'] = false;
$call->configuration['enable_AEC'] = false;
2019-03-29 20:25:42 +01:00
$call->configuration['log_file_path'] = '/tmp/logs' . $call->getCallID()['id'] . '.log'; // Default is /dev/null
2018-05-04 12:21:33 +02:00
//$call->configuration["stats_dump_file_path"] = "/tmp/stats".$call->getCallID()['id'].".txt"; // Default is /dev/null
$call->parseConfig();
$call->playOnHold($songs);
2018-10-13 17:12:57 +02:00
//$this->messages->sendMessage(['message' => var_export($call->configuration, true), 'peer' => $call->getOtherID()]);
2018-03-24 16:22:13 +01:00
}
2018-03-29 23:05:15 +02:00
public function handleMessage($chat_id, $from_id, $message)
{
try {
if (!isset($this->my_users[$from_id]) || $message === '/start') {
$this->my_users[$from_id] = true;
$message = '/call';
$this->messages->sendMessage(['no_webpage' => true, 'peer' => $chat_id, 'message' => "Hi, I'm @magnaluna the webradio.
Call _me_ to listen to some **awesome** music, or send /call to make _me_ call _you_ (don't forget to disable call privacy settings!).
You can also program a phone call with /program:
/program 29 August 2018 - call me the 29th of august 2018
/program +1 hour 30 minutes - call me in one hour and thirty minutes
/program next Thursday - call me next Thursday at midnight
Send /start to see this message again.
I also provide advanced stats during calls!
I'm a userbot powered by @MadelineProto, created by @danogentili.
2018-03-30 12:53:51 +02:00
Source code: https://github.com/danog/MadelineProto
Propic art by @magnaluna on [deviantart](https://magnaluna.deviantart.com).", 'parse_mode' => 'Markdown']);
}
if (!isset($this->calls[$from_id]) && $message === '/call') {
$call = $this->request_call($from_id);
$this->configureCall($call);
Merge alpha into master (async, huge bugfixes and more) (#546) * Implement async and lots of bugfixes * Implement more async * Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr * Apply fixes from StyleCI * Bugfixes * Apply fixes from StyleCI * Bugfixes, implement combined promises * Apply fixes from StyleCI * Support passing method arguments as callable * Starting to write async upload logic * Apply fixes from StyleCI * Start implementing async file upload * Apply fixes from StyleCI * bugfix * Apply fixes from StyleCI * Start rewriting connection module * Add PHP file docblocks for all classes * Start working on new async stream API * Finish writing stream API * More stream API fixes * Apply fixes from StyleCI * Rewrite DataCenter and Connection modules * Clean up stream API documentation * Fixes * Apply fixes from StyleCI * Add referenced parameter to get length of buffer to read in getReadBuffer API * Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar * Start fixing reads * Fix all protocol stream wrappers * Apply fixes from StyleCI * Implement disconnection, and remove end function * Working async RPC * Implement async file upload * Bugfix * Method recall bugfixes * Bugfixes * Trait bugfixes * Fix FIFO buffer * Bugfixes and speedtests * Async logging * Implement websocket streams * Implement loop API, signal API, clean closing and start changing layer * Small magna, websocket and HTTP fixes * Clean up loop API * Improved stack traces, 2FA and async * Login fixes * Added instructions for manual verification * Small fixes * More app info improvements * More app info improvements * TL and 2FA fixes * Update to layer 89 * More bugfixes * Implement broken media reporting * Remove debug comments * PHP 7.2 backwards compatibility * Bugfixes * Async key generation * Some simplifications * Transport fixes * Cleanup * async API * Performance fixes * Fixes to async API * Bugfixes * Implement one-time async loop * Authorization and logging fixes * Update to layer 91 * 7to5 fix * Null coalesce conversion * Implement socks5 proxy * Implement HTTP proxy * Fixes to HTTP proxy * MTProxy and socks5 fixes * Disable PHP 5 conversion * Proxies have higher priority * Avoid error handling in vendor * Override composer dependencies * Fix travis build * Final composer fixes * Proxy logic fixes * Fix get_updates update handling * Do not use parallel file driver if not supported * Refactor loader and implement HTTP fixes * Suppress errors in loader * HTTP and authorization fixes * HTTP fixes * Improved peer management * Use HTTP protocol on altervista * Small bugfixes * Minor fixes * Docufix * Docufix * Legacy fixes * Fix message queue * Avoid updating if using MTProxy * Improve logs and examples * Trim final newlines while converting parse mode * Reimplement noResponse flag * Async combined event handler and APIFactory fixes * Actually return config * Case-insensitive methods * Bugfix * Apply fixes from StyleCI (#545) * MTProxy fixes * PHP 5 warning * Improved PHP 5 warning * Use <br> along with newlines in web logs * Update docs
2018-12-26 20:51:14 +01:00
if ($call->getCallState() !== \danog\MadelineProto\VoIP::CALL_STATE_ENDED) {
$this->calls[$call->getOtherID()] = $call;
2019-03-29 20:25:42 +01:00
$this->times[$call->getOtherID()] = [time(), $this->messages->sendMessage(['peer' => $call->getOtherID(), 'message' => 'Total running calls: ' . count($this->calls) . PHP_EOL . PHP_EOL . $call->getDebugString()])['id']];
Merge alpha into master (async, huge bugfixes and more) (#546) * Implement async and lots of bugfixes * Implement more async * Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr * Apply fixes from StyleCI * Bugfixes * Apply fixes from StyleCI * Bugfixes, implement combined promises * Apply fixes from StyleCI * Support passing method arguments as callable * Starting to write async upload logic * Apply fixes from StyleCI * Start implementing async file upload * Apply fixes from StyleCI * bugfix * Apply fixes from StyleCI * Start rewriting connection module * Add PHP file docblocks for all classes * Start working on new async stream API * Finish writing stream API * More stream API fixes * Apply fixes from StyleCI * Rewrite DataCenter and Connection modules * Clean up stream API documentation * Fixes * Apply fixes from StyleCI * Add referenced parameter to get length of buffer to read in getReadBuffer API * Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar * Start fixing reads * Fix all protocol stream wrappers * Apply fixes from StyleCI * Implement disconnection, and remove end function * Working async RPC * Implement async file upload * Bugfix * Method recall bugfixes * Bugfixes * Trait bugfixes * Fix FIFO buffer * Bugfixes and speedtests * Async logging * Implement websocket streams * Implement loop API, signal API, clean closing and start changing layer * Small magna, websocket and HTTP fixes * Clean up loop API * Improved stack traces, 2FA and async * Login fixes * Added instructions for manual verification * Small fixes * More app info improvements * More app info improvements * TL and 2FA fixes * Update to layer 89 * More bugfixes * Implement broken media reporting * Remove debug comments * PHP 7.2 backwards compatibility * Bugfixes * Async key generation * Some simplifications * Transport fixes * Cleanup * async API * Performance fixes * Fixes to async API * Bugfixes * Implement one-time async loop * Authorization and logging fixes * Update to layer 91 * 7to5 fix * Null coalesce conversion * Implement socks5 proxy * Implement HTTP proxy * Fixes to HTTP proxy * MTProxy and socks5 fixes * Disable PHP 5 conversion * Proxies have higher priority * Avoid error handling in vendor * Override composer dependencies * Fix travis build * Final composer fixes * Proxy logic fixes * Fix get_updates update handling * Do not use parallel file driver if not supported * Refactor loader and implement HTTP fixes * Suppress errors in loader * HTTP and authorization fixes * HTTP fixes * Improved peer management * Use HTTP protocol on altervista * Small bugfixes * Minor fixes * Docufix * Docufix * Legacy fixes * Fix message queue * Avoid updating if using MTProxy * Improve logs and examples * Trim final newlines while converting parse mode * Reimplement noResponse flag * Async combined event handler and APIFactory fixes * Actually return config * Case-insensitive methods * Bugfix * Apply fixes from StyleCI (#545) * MTProxy fixes * PHP 5 warning * Improved PHP 5 warning * Use <br> along with newlines in web logs * Update docs
2018-12-26 20:51:14 +01:00
}
}
if (strpos($message, '/program') === 0) {
$time = strtotime(str_replace('/program ', '', $message));
if ($time === false) {
$this->messages->sendMessage(['peer' => $chat_id, 'message' => 'Invalid time provided']);
} else {
$this->programmed_call[] = [$from_id, $time];
$this->messages->sendMessage(['peer' => $chat_id, 'message' => 'OK']);
}
}
if ($message === '/broadcast' && $from_id === 101374607) {
2018-03-29 23:05:15 +02:00
$time = time() + 100;
2018-03-30 18:03:16 +02:00
$message = explode(' ', $message, 2);
2018-03-30 18:02:34 +02:00
unset($message[0]);
2018-03-30 18:03:16 +02:00
$message = implode(' ', $message);
foreach ($this->get_dialogs() as $peer) {
2018-03-30 13:16:49 +02:00
$this->times_messages[] = [$peer, $time, $message];
if (isset($peer['user_id'])) {
$this->programmed_call[] = [$peer['user_id'], $time];
2018-03-24 16:22:13 +01:00
}
2018-03-30 18:02:34 +02:00
$time += 30;
}
}
} catch (\danog\MadelineProto\RPCErrorException $e) {
try {
if ($e->rpc === 'USER_PRIVACY_RESTRICTED') {
$e = 'Please disable call privacy settings to make me call you';
} elseif (strpos($e->rpc, 'FLOOD_WAIT_') === 0) {
$t = str_replace('FLOOD_WAIT_', '', $e->rpc);
$this->programmed_call[] = [$from_id, time() + 1 + $t];
$e = "Too many people used the /call function. I'll call you back in $t seconds.\nYou can also call me right now.";
}
$this->messages->sendMessage(['peer' => $chat_id, 'message' => (string) $e]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
}
echo $e;
} catch (\danog\MadelineProto\Exception $e) {
echo $e;
}
}
public function onUpdateNewMessage($update)
{
if ($update['message']['out'] || $update['message']['to_id']['_'] !== 'peerUser' || !isset($update['message']['from_id'])) {
return;
}
2018-04-17 23:51:54 +02:00
\danog\MadelineProto\Logger::log($update);
$chat_id = $from_id = $this->get_info($update)['bot_api_id'];
$message = isset($update['message']['message']) ? $update['message']['message'] : '';
$this->handleMessage($chat_id, $from_id, $message);
}
2018-03-29 23:05:15 +02:00
public function onUpdateNewEncryptedMessage($update)
{
return;
$chat_id = $this->get_info($update)['InputEncryptedChat'];
$from_id = $this->get_secret_chat($chat_id)['user_id'];
$message = isset($update['message']['decrypted_message']['message']) ? $update['message']['decrypted_message']['message'] : '';
$this->handleMessage($chat_id, $from_id, $message);
}
2018-03-29 23:05:15 +02:00
public function onUpdateEncryption($update)
{
return;
2018-03-29 23:05:15 +02:00
try {
if ($update['chat']['_'] !== 'encryptedChat') {
return;
}
$chat_id = $this->get_info($update)['InputEncryptedChat'];
$from_id = $this->get_secret_chat($chat_id)['user_id'];
$message = '';
} catch (\danog\MadelineProto\Exception $e) {
return;
}
$this->handleMessage($chat_id, $from_id, $message);
}
2018-03-29 23:05:15 +02:00
public function onUpdatePhoneCall($update)
{
2018-03-29 23:05:15 +02:00
if (is_object($update['phone_call']) && isset($update['phone_call']->madeline) && $update['phone_call']->getCallState() === \danog\MadelineProto\VoIP::CALL_STATE_INCOMING) {
$this->configureCall($update['phone_call']);
if ($update['phone_call']->accept() === false) {
echo 'DID NOT ACCEPT A CALL';
}
$this->calls[$update['phone_call']->getOtherID()] = $update['phone_call'];
2018-03-29 23:05:15 +02:00
try {
2019-03-29 20:25:42 +01:00
$this->times[$update['phone_call']->getOtherID()] = [time(), $this->messages->sendMessage(['peer' => $update['phone_call']->getOtherID(), 'message' => 'Total running calls: ' . count($this->calls) . PHP_EOL . PHP_EOL])['id']];
2018-03-29 23:05:15 +02:00
} catch (\danog\MadelineProto\RPCErrorException $e) {
}
}
}
2018-04-17 23:52:28 +02:00
2018-04-17 23:51:54 +02:00
public function onAny($update)
{
\danog\MadelineProto\Logger::log($update);
}
2018-04-17 23:52:28 +02:00
public function onLoop()
{
2018-03-29 23:05:15 +02:00
foreach ($this->programmed_call as $key => $pair) {
list($user, $time) = $pair;
if ($time < time()) {
if (!isset($this->calls[$user])) {
2018-03-24 16:22:13 +01:00
try {
2018-03-29 23:05:15 +02:00
$call = $this->request_call($user);
$this->configureCall($call);
Merge alpha into master (async, huge bugfixes and more) (#546) * Implement async and lots of bugfixes * Implement more async * Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr * Apply fixes from StyleCI * Bugfixes * Apply fixes from StyleCI * Bugfixes, implement combined promises * Apply fixes from StyleCI * Support passing method arguments as callable * Starting to write async upload logic * Apply fixes from StyleCI * Start implementing async file upload * Apply fixes from StyleCI * bugfix * Apply fixes from StyleCI * Start rewriting connection module * Add PHP file docblocks for all classes * Start working on new async stream API * Finish writing stream API * More stream API fixes * Apply fixes from StyleCI * Rewrite DataCenter and Connection modules * Clean up stream API documentation * Fixes * Apply fixes from StyleCI * Add referenced parameter to get length of buffer to read in getReadBuffer API * Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar * Start fixing reads * Fix all protocol stream wrappers * Apply fixes from StyleCI * Implement disconnection, and remove end function * Working async RPC * Implement async file upload * Bugfix * Method recall bugfixes * Bugfixes * Trait bugfixes * Fix FIFO buffer * Bugfixes and speedtests * Async logging * Implement websocket streams * Implement loop API, signal API, clean closing and start changing layer * Small magna, websocket and HTTP fixes * Clean up loop API * Improved stack traces, 2FA and async * Login fixes * Added instructions for manual verification * Small fixes * More app info improvements * More app info improvements * TL and 2FA fixes * Update to layer 89 * More bugfixes * Implement broken media reporting * Remove debug comments * PHP 7.2 backwards compatibility * Bugfixes * Async key generation * Some simplifications * Transport fixes * Cleanup * async API * Performance fixes * Fixes to async API * Bugfixes * Implement one-time async loop * Authorization and logging fixes * Update to layer 91 * 7to5 fix * Null coalesce conversion * Implement socks5 proxy * Implement HTTP proxy * Fixes to HTTP proxy * MTProxy and socks5 fixes * Disable PHP 5 conversion * Proxies have higher priority * Avoid error handling in vendor * Override composer dependencies * Fix travis build * Final composer fixes * Proxy logic fixes * Fix get_updates update handling * Do not use parallel file driver if not supported * Refactor loader and implement HTTP fixes * Suppress errors in loader * HTTP and authorization fixes * HTTP fixes * Improved peer management * Use HTTP protocol on altervista * Small bugfixes * Minor fixes * Docufix * Docufix * Legacy fixes * Fix message queue * Avoid updating if using MTProxy * Improve logs and examples * Trim final newlines while converting parse mode * Reimplement noResponse flag * Async combined event handler and APIFactory fixes * Actually return config * Case-insensitive methods * Bugfix * Apply fixes from StyleCI (#545) * MTProxy fixes * PHP 5 warning * Improved PHP 5 warning * Use <br> along with newlines in web logs * Update docs
2018-12-26 20:51:14 +01:00
if ($call->getCallState() !== \danog\MadelineProto\VoIP::CALL_STATE_ENDED) {
$this->calls[$call->getOtherID()] = $call;
2019-03-29 20:25:42 +01:00
$this->times[$call->getOtherID()] = [time(), $this->messages->sendMessage(['peer' => $call->getOtherID(), 'message' => 'Total running calls: ' . count($this->calls) . PHP_EOL . PHP_EOL . $call->getDebugString()])['id']];
Merge alpha into master (async, huge bugfixes and more) (#546) * Implement async and lots of bugfixes * Implement more async * Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr * Apply fixes from StyleCI * Bugfixes * Apply fixes from StyleCI * Bugfixes, implement combined promises * Apply fixes from StyleCI * Support passing method arguments as callable * Starting to write async upload logic * Apply fixes from StyleCI * Start implementing async file upload * Apply fixes from StyleCI * bugfix * Apply fixes from StyleCI * Start rewriting connection module * Add PHP file docblocks for all classes * Start working on new async stream API * Finish writing stream API * More stream API fixes * Apply fixes from StyleCI * Rewrite DataCenter and Connection modules * Clean up stream API documentation * Fixes * Apply fixes from StyleCI * Add referenced parameter to get length of buffer to read in getReadBuffer API * Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar * Start fixing reads * Fix all protocol stream wrappers * Apply fixes from StyleCI * Implement disconnection, and remove end function * Working async RPC * Implement async file upload * Bugfix * Method recall bugfixes * Bugfixes * Trait bugfixes * Fix FIFO buffer * Bugfixes and speedtests * Async logging * Implement websocket streams * Implement loop API, signal API, clean closing and start changing layer * Small magna, websocket and HTTP fixes * Clean up loop API * Improved stack traces, 2FA and async * Login fixes * Added instructions for manual verification * Small fixes * More app info improvements * More app info improvements * TL and 2FA fixes * Update to layer 89 * More bugfixes * Implement broken media reporting * Remove debug comments * PHP 7.2 backwards compatibility * Bugfixes * Async key generation * Some simplifications * Transport fixes * Cleanup * async API * Performance fixes * Fixes to async API * Bugfixes * Implement one-time async loop * Authorization and logging fixes * Update to layer 91 * 7to5 fix * Null coalesce conversion * Implement socks5 proxy * Implement HTTP proxy * Fixes to HTTP proxy * MTProxy and socks5 fixes * Disable PHP 5 conversion * Proxies have higher priority * Avoid error handling in vendor * Override composer dependencies * Fix travis build * Final composer fixes * Proxy logic fixes * Fix get_updates update handling * Do not use parallel file driver if not supported * Refactor loader and implement HTTP fixes * Suppress errors in loader * HTTP and authorization fixes * HTTP fixes * Improved peer management * Use HTTP protocol on altervista * Small bugfixes * Minor fixes * Docufix * Docufix * Legacy fixes * Fix message queue * Avoid updating if using MTProxy * Improve logs and examples * Trim final newlines while converting parse mode * Reimplement noResponse flag * Async combined event handler and APIFactory fixes * Actually return config * Case-insensitive methods * Bugfix * Apply fixes from StyleCI (#545) * MTProxy fixes * PHP 5 warning * Improved PHP 5 warning * Use <br> along with newlines in web logs * Update docs
2018-12-26 20:51:14 +01:00
}
2017-08-05 17:43:07 +02:00
} catch (\danog\MadelineProto\RPCErrorException $e) {
2018-03-29 23:05:15 +02:00
try {
if ($e->rpc === 'USER_PRIVACY_RESTRICTED') {
$e = 'Please disable call privacy settings to make me call you';
} elseif (strpos($e->rpc, 'FLOOD_WAIT_') === 0) {
$t = str_replace('FLOOD_WAIT_', '', $e->rpc);
$this->programmed_call[] = [$user, time() + 1 + $t];
$e = "I'll call you back in $t seconds.\nYou can also call me right now.";
}
$this->messages->sendMessage(['peer' => $user, 'message' => (string) $e]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
}
2017-08-05 17:43:07 +02:00
}
2018-03-24 16:22:13 +01:00
}
2018-03-29 23:05:15 +02:00
unset($this->programmed_call[$key]);
}
2018-03-30 13:16:49 +02:00
break;
}
2018-03-30 12:53:51 +02:00
foreach ($this->times_messages as $key => $pair) {
list($peer, $time, $message) = $pair;
if ($time < time()) {
2018-03-30 12:54:16 +02:00
try {
$this->messages->sendMessage(['peer' => $peer, 'message' => $message]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
if (strpos($e->rpc, 'FLOOD_WAIT_') === 0) {
$t = str_replace('FLOOD_WAIT_', '', $e->rpc);
$this->times_messages[] = [$peer, time() + 1 + $t, $message];
2018-03-30 12:53:51 +02:00
}
2018-03-30 12:54:16 +02:00
echo $e;
}
2018-03-30 12:53:51 +02:00
unset($this->times_messages[$key]);
}
2018-03-30 13:16:49 +02:00
break;
2018-03-30 12:53:51 +02:00
}
2019-03-29 20:25:42 +01:00
\danog\MadelineProto\Logger::log(count($this->calls) . ' calls running!');
2018-03-29 23:05:15 +02:00
foreach ($this->calls as $key => $call) {
if ($call->getCallState() === \danog\MadelineProto\VoIP::CALL_STATE_ENDED) {
2018-05-04 12:21:33 +02:00
try {
2018-05-04 12:21:57 +02:00
if (isset($this->times[$call->getOtherID()][1])) {
/*$this->messages->sendMedia([
'reply_to_msg_id' => $this->times[$call->getOtherID()][1],
'peer' => $call->getOtherID(), 'message' => 'Call statistics by @magnaluna',
'media' => [
2019-03-29 20:25:42 +01:00
'_' => 'inputMediaUploadedDocument',
'file' => "/tmp/stats".$call->getCallID()['id'].".txt",
'attributes' => [
['_' => 'documentAttributeFilename', 'file_name' => "stats".$call->getCallID()['id'].".txt"]
]
2018-05-04 12:21:57 +02:00
],
]);*/
$this->messages->sendMedia([
2019-03-29 20:25:42 +01:00
'reply_to_msg_id' => $this->times[$call->getOtherID()][1],
'peer' => $call->getOtherID(), 'message' => 'Debug info by @magnaluna',
'media' => [
'_' => 'inputMediaUploadedDocument',
'file' => '/tmp/logs' . $call->getCallID()['id'] . '.log',
'attributes' => [
['_' => 'documentAttributeFilename', 'file_name' => 'logs' . $call->getCallID()['id'] . '.log'],
],
],
]);
2018-05-04 12:21:57 +02:00
}
Merge alpha into master (async, huge bugfixes and more) (#546) * Implement async and lots of bugfixes * Implement more async * Implement async, implement bugfixes for the connection module, for the datacenter module, huge bugfixes, huge perfomance improvements, media DCs for https, advanced selecting, custom var_dump, totally rewritten IOLoop and response mechanism, promises, improvements to the TL parser, custom mb_substr * Apply fixes from StyleCI * Bugfixes * Apply fixes from StyleCI * Bugfixes, implement combined promises * Apply fixes from StyleCI * Support passing method arguments as callable * Starting to write async upload logic * Apply fixes from StyleCI * Start implementing async file upload * Apply fixes from StyleCI * bugfix * Apply fixes from StyleCI * Start rewriting connection module * Add PHP file docblocks for all classes * Start working on new async stream API * Finish writing stream API * More stream API fixes * Apply fixes from StyleCI * Rewrite DataCenter and Connection modules * Clean up stream API documentation * Fixes * Apply fixes from StyleCI * Add referenced parameter to get length of buffer to read in getReadBuffer API * Moved all MessageHandler code in the Connection module, added a PHP version warning in the phar * Start fixing reads * Fix all protocol stream wrappers * Apply fixes from StyleCI * Implement disconnection, and remove end function * Working async RPC * Implement async file upload * Bugfix * Method recall bugfixes * Bugfixes * Trait bugfixes * Fix FIFO buffer * Bugfixes and speedtests * Async logging * Implement websocket streams * Implement loop API, signal API, clean closing and start changing layer * Small magna, websocket and HTTP fixes * Clean up loop API * Improved stack traces, 2FA and async * Login fixes * Added instructions for manual verification * Small fixes * More app info improvements * More app info improvements * TL and 2FA fixes * Update to layer 89 * More bugfixes * Implement broken media reporting * Remove debug comments * PHP 7.2 backwards compatibility * Bugfixes * Async key generation * Some simplifications * Transport fixes * Cleanup * async API * Performance fixes * Fixes to async API * Bugfixes * Implement one-time async loop * Authorization and logging fixes * Update to layer 91 * 7to5 fix * Null coalesce conversion * Implement socks5 proxy * Implement HTTP proxy * Fixes to HTTP proxy * MTProxy and socks5 fixes * Disable PHP 5 conversion * Proxies have higher priority * Avoid error handling in vendor * Override composer dependencies * Fix travis build * Final composer fixes * Proxy logic fixes * Fix get_updates update handling * Do not use parallel file driver if not supported * Refactor loader and implement HTTP fixes * Suppress errors in loader * HTTP and authorization fixes * HTTP fixes * Improved peer management * Use HTTP protocol on altervista * Small bugfixes * Minor fixes * Docufix * Docufix * Legacy fixes * Fix message queue * Avoid updating if using MTProxy * Improve logs and examples * Trim final newlines while converting parse mode * Reimplement noResponse flag * Async combined event handler and APIFactory fixes * Actually return config * Case-insensitive methods * Bugfix * Apply fixes from StyleCI (#545) * MTProxy fixes * PHP 5 warning * Improved PHP 5 warning * Use <br> along with newlines in web logs * Update docs
2018-12-26 20:51:14 +01:00
} catch (\danog\MadelineProto\Exception $e) {
echo $e;
2018-05-04 12:21:33 +02:00
} catch (\danog\MadelineProto\RPCErrorException $e) {
echo $e;
2018-10-13 17:12:57 +02:00
} catch (\danog\MadelineProto\Exception $e) {
echo $e;
2018-05-04 12:21:33 +02:00
}
2019-03-29 20:25:42 +01:00
@unlink('/tmp/logs' . $call->getCallID()['id'] . '.log');
@unlink('/tmp/stats' . $call->getCallID()['id'] . '.txt');
2018-03-29 23:05:15 +02:00
unset($this->calls[$key]);
} elseif (isset($this->times[$call->getOtherID()]) && $this->times[$call->getOtherID()][0] < time()) {
$this->times[$call->getOtherID()][0] += 30 + count($this->calls);
2018-03-29 23:05:15 +02:00
try {
2019-03-29 20:25:42 +01:00
$this->messages->editMessage(['id' => $this->times[$call->getOtherID()][1], 'peer' => $call->getOtherID(), 'message' => 'Total running calls: ' . count($this->calls) . PHP_EOL . PHP_EOL . $call->getDebugString()]);
2018-03-29 23:05:15 +02:00
} catch (\danog\MadelineProto\RPCErrorException $e) {
echo $e;
}
}
}
}
2018-03-24 19:06:19 +01:00
}
2019-03-29 20:25:42 +01:00
\danog\MadelineProto\VoIPServerConfig::update(
[
'audio_init_bitrate' => 100 * 1000,
'audio_max_bitrate' => 100 * 1000,
'audio_min_bitrate' => 10 * 1000,
'audio_congestion_window' => 4 * 1024,
]
);
$MadelineProto = new \danog\MadelineProto\API('session.madeline', ['secret_chats' => ['accept_chats' => false], 'logger' => ['logger' => 3, 'logger_param' => getcwd() . '/MadelineProto.log']]);
2018-06-29 18:20:07 +02:00
$MadelineProto->start();
if (!isset($MadelineProto->programmed_call)) {
$MadelineProto->programmed_call = [];
}
foreach (['my_users', 'times', 'times_messages', 'calls'] as $key) {
if (!isset($MadelineProto->{$key})) {
$MadelineProto->{$key} = [];
}
}
$MadelineProto->setEventHandler('\EventHandler');
$MadelineProto->loop();