mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-26 19:45:01 +01:00
.env and performance improvements (#45)
* * Changes for use .env file and not a php with sensible data * * Changes for use .env file and not a php with sensible data * * Changes for use .env file and not a php with sensible data * * Changes for use .env file and not a php with sensible data * Changes for use .env files * Moving $settings to .env file * Update testing.php syntax * Update testing.php * * More variables moved to environments file and updated .env.example file * improvement in defining device_model and system_version * Performance improvements in defining settings * removed desnecessary call to unserialize class in testing file
This commit is contained in:
parent
2b84d543f7
commit
3bb266e20b
@ -1,2 +1,5 @@
|
||||
MTPROTO_NUMBER=+123456789
|
||||
MTPROTO_SETTINGS=[]
|
||||
MTPROTO_SETTINGS={"app_info":{"api_id":65536,"api_hash":"4251a2777e179232705e2462706f4143"}}
|
||||
TEST_USERNAME=@danogentili
|
||||
TEST_DESTINATION_GROUPS=["@pwrtelegramgroup","@pwrtelegramgroupita"]
|
||||
BOT_TOKEN=
|
@ -82,17 +82,17 @@ class MTProto extends PrimeModule
|
||||
$this->ipv6 = strlen($google) > 0;
|
||||
|
||||
// Detect device model
|
||||
$device_model = 'Web server';
|
||||
try {
|
||||
$device_model = php_uname('s');
|
||||
} catch (Exception $e) {
|
||||
$device_model = 'Web server';
|
||||
}
|
||||
|
||||
// Detect system version
|
||||
$system_version = phpversion();
|
||||
try {
|
||||
$system_version = php_uname('r');
|
||||
} catch (Exception $e) {
|
||||
$system_version = phpversion();
|
||||
}
|
||||
|
||||
// Set default settings
|
||||
@ -203,16 +203,7 @@ Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB
|
||||
],
|
||||
'pwr' => ['pwr' => false, 'db_token' => false, 'strict' => false],
|
||||
];
|
||||
foreach ($default_settings as $key => $param) {
|
||||
if (!isset($settings[$key])) {
|
||||
$settings[$key] = $param;
|
||||
}
|
||||
foreach ($param as $subkey => $subparam) {
|
||||
if (!isset($settings[$key][$subkey])) {
|
||||
$settings[$key][$subkey] = $subparam;
|
||||
}
|
||||
}
|
||||
}
|
||||
$settings = array_replace_recursive($default_settings, $settings);
|
||||
if (isset($settings['connection_settings']['all'])) {
|
||||
foreach ($this->range(1, 6) as $n) {
|
||||
if (!isset($settings['connection_settings'][$n])) {
|
||||
|
16
testing.php
16
testing.php
@ -16,6 +16,7 @@ if (file_exists('web_data.php')) {
|
||||
require_once 'web_data.php';
|
||||
}
|
||||
|
||||
echo 'Deserializing MadelineProto from session.madeline...'.PHP_EOL;
|
||||
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('session.madeline');
|
||||
|
||||
if (file_exists('.env')) {
|
||||
@ -42,12 +43,10 @@ if ($MadelineProto === false) {
|
||||
echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL;
|
||||
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL;
|
||||
}
|
||||
echo 'Deserializing MadelineProto from session.madeline...'.PHP_EOL;
|
||||
$MadelineProto = \danog\MadelineProto\Serialization::deserialize('session.madeline');
|
||||
$message = (getenv('TRAVIS_COMMIT') == '') ? 'I iz works always (io laborare sembre) (yo lavorar siempre)' : ('Travis ci tests in progress: commit '.getenv('TRAVIS_COMMIT').', job '.getenv('TRAVIS_JOB_NUMBER').', PHP version: '.getenv('TRAVIS_PHP_VERSION'));
|
||||
|
||||
$flutter = 'https://storage.pwrtelegram.xyz/pwrtelegrambot/document/file_6570.mp4';
|
||||
$mention = $MadelineProto->get_info('@danogentili'); // Returns an array with all of the constructors that can be extracted from a username or an id
|
||||
$mention = $MadelineProto->get_info(getenv('TEST_USERNAME')); // Returns an array with all of the constructors that can be extracted from a username or an id
|
||||
$mention = $mention['user_id']; // Selects only the numeric user id
|
||||
|
||||
$media = [];
|
||||
@ -84,7 +83,7 @@ $inputFile = $MadelineProto->upload('60', 'magic'); // This gets an inputFile ob
|
||||
var_dump(time() - $time);
|
||||
$media['document'] = ['_' => 'inputMediaUploadedDocument', 'file' => $inputFile, 'mime_type' => 'magic/magic', 'caption' => 'This file was uploaded using MadelineProto', 'attributes' => [['_' => 'documentAttributeFilename', 'file_name' => 'magic.magic']]];
|
||||
|
||||
foreach (['@pwrtelegramgroup', '@pwrtelegramgroupita'] as $peer) {
|
||||
foreach (json_decode(getenv('TEST_DESTINATION_GROUPS'), true) as $peer) {
|
||||
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message, 'entities' => [['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => strlen($message), 'user_id' => $mention]]]);
|
||||
\danog\MadelineProto\Logger::log($sentMessage);
|
||||
foreach ($media as $type => $inputMedia) {
|
||||
@ -99,17 +98,16 @@ echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL;
|
||||
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL;
|
||||
echo 'Size of MadelineProto instance is '.strlen(serialize($MadelineProto)).' bytes'.PHP_EOL;
|
||||
|
||||
if (file_exists('token.php')) {
|
||||
include_once 'token.php';
|
||||
if ($bot_token = getenv('BOT_TOKEN')) {
|
||||
$MadelineProto = new \danog\MadelineProto\API($settings);
|
||||
$authorization = $MadelineProto->bot_login($token);
|
||||
$authorization = $MadelineProto->bot_login($bot_token);
|
||||
\danog\MadelineProto\Logger::log($authorization);
|
||||
}
|
||||
$message = 'yay';
|
||||
$mention = $MadelineProto->get_info('@danogentili'); // Returns an array with all of the constructors that can be extracted from a username or an id
|
||||
$mention = $MadelineProto->get_info(getenv('TEST_USERNAME')); // Returns an array with all of the constructors that can be extracted from a username or an id
|
||||
$mention = $mention['user_id']; // Selects only the numeric user id
|
||||
|
||||
foreach (['@pwrtelegramgroup', '@pwrtelegramgroupita'] as $peer) {
|
||||
foreach (json_decode(getenv('TEST_DESTINATION_GROUPS'), true) as $peer) {
|
||||
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message, 'entities' => [['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => strlen($message), 'user_id' => $mention]]]);
|
||||
\danog\MadelineProto\Logger::log($sentMessage);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user