1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-22 13:53:04 +01:00

Further improvements

This commit is contained in:
Daniil Gentili 2023-07-16 14:29:03 +02:00
parent bfd7db0e94
commit 52d7b743cd
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
8 changed files with 67 additions and 41 deletions

View File

@ -686,8 +686,7 @@ Want to add your own open-source project to this list? [Click here!](https://doc
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#openfileappendonly-string-path-amp-file-file" name="openFileAppendOnly">Opens a file in append-only mode: openFileAppendOnly</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/phone.receivedCall.html" name="phone.receivedCall">Optional: notify the server that the user is currently busy in a call: this will automatically refuse all incoming phone calls until the current phone call is ended: phone.receivedCall</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#updatesettings-settingsabstract-settings-void" name="updateSettings">Parse, update and store settings: updateSettings</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#validateeventhandlerclass-class-string-eventhandler-class-void" name="validateEventHandlerClass">Perform static analysis on a certain event handler class, to make sure it satisfies some performance requirements: validateEventHandlerClass</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#validateeventhandlercode-string-code-bool-plugin-void" name="validateEventHandlerCode">Perform static analysis on a certain event handler class, to make sure it satisfies some performance requirements: validateEventHandlerCode</a>
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#validateeventhandlerclass-class-string-eventhandler-class-list-eventhandlerissue" name="validateEventHandlerClass">Perform static analysis on a certain event handler class, to make sure it satisfies some performance requirements: validateEventHandlerClass</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.updatePinnedMessage.html" name="messages.updatePinnedMessage">Pin a message: messages.updatePinnedMessage</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/channels.updatePinnedForumTopic.html" name="channels.updatePinnedForumTopic">Pin or unpin forum topics: channels.updatePinnedForumTopic</a>
* <a href="https://docs.madelineproto.xyz/API_docs/methods/messages.toggleDialogPin.html" name="messages.toggleDialogPin">Pin/unpin a dialog: messages.toggleDialogPin</a>

View File

@ -37,6 +37,8 @@ use danog\MadelineProto\Settings\Database\Postgres;
use danog\MadelineProto\Settings\Database\Redis;
use danog\MadelineProto\SimpleEventHandler;
use function Amp\File\read;
// MadelineProto is already loaded
if (class_exists(API::class)) {
// Otherwise, if a stable version of MadelineProto was installed via composer, load composer autoloader

View File

@ -59,6 +59,14 @@ class PingPlugin extends PluginEventHandler
$this->sendMessageToAdmins("The bot was started!");
}
/**
* Plugins may be enabled or disabled at startup by returning true or false from this function.
*/
public function isPluginEnabled(): bool
{
return true;
}
/**
* This cron function will be executed forever, every 60 seconds.
*/

View File

@ -139,7 +139,7 @@
"do_not_use_deprecated_function": "the %s function is deprecated, please use %s, instead",
"do_not_use_non_root_require_in_event_handler": "for performance reasons, you must not use require or include inside of an event handler class, only root-level requires are allowed.",
"recommend_not_use_filesystem_function": "usage of %s the function is not recommended, because accesses the filesystem and will slow down your bot if used during update handling, please see https://docs.madelineproto.xyz/docs/UPDATES.html#avoiding-the-use-of-filesystem-functions for a list of alternative ways to store data that will not slow down your bot!",
"recommend_not_use_filesystem_function": "usage of %s the function is not recommended, because accessing the filesystem during update handling will slow down your bot, please see https://docs.madelineproto.xyz/docs/UPDATES.html#avoiding-the-use-of-filesystem-functions for a list of alternative ways to store data that will not slow down your bot!",
"plugins_do_not_use_require": "for performance reasons, plugins can only automatically include or require other files present in the plugins folder by triggering the PSR-4 autoloader (not by manually require()'ing them).",
"plugins_must_have_exactly_one_class": "a plugin must define exactly one class! To define multiple classes, interfaces or traits, create separate files, they will be autoloaded by MadelineProto automatically."

View File

@ -119,5 +119,12 @@
"sec_peer_not_in_db": "این peer مخفی در پایگاه داده (دیتابیس) داخلی peer وجود ندارد",
"stream_handle_invalid": "یک کنترل‌کننده جریان (استریم هندل) نامعتبر لحاظ گردیده.",
"noReportPeers": "هشدار: هیچ peerـی به عنوان peer گزارشات تنظیم نشده، لطفا متود زیر را به ایونت هندلر اضافه کنید",
"mmapErrorPart2": "برای حل کردن مشکل، کامند مقابل را با دسترسی root اجرا کنید: %s"
"mmapErrorPart2": "برای حل کردن مشکل، کامند مقابل را با دسترسی root اجرا کنید: %s",
"mmapErrorPart4": "روی ویندوز و WSL، افزایش سایز pagefile ممکن است کمک کند؛ اگر مشکل پافشاری کرد لطفا سیستم‌عامل خود را به لینوکس تغییر دهید.",
"extensionRecommended": "هشدار: افزونه %s نصب نشده است. لطفا برای افزایش سرعت مدلین‌پروتو آن را نصب کنید!",
"botAlreadyRunning": "ربات هم اکنون در حال اجرا است!",
"extensionRequiredInstallWithApt": "اجرای کامند sudo apt-get install %s را امتحان کنید.",
"extensionRequiredInstallWithCustomInstructions": "برای نصب آن، دستورالعمل ها را در %s دنبال کنید.",
"extensionRequired": "مدلین برای اجرا نیاز به افزونه %s دارد. %s",
"manualAdminActionRequired": "!!!!!!!!! فعالیت دستی ادمین سیستم نیاز است !!!!!!!!!"
}

View File

@ -154,7 +154,8 @@ final class Lang
'signup_ok' => 'بە سەرکەوتوویی ناوت تۆمار کرد!',
'signup_uncalled' => 'چاوەڕێی ناو تۆمارکردن ناکەم! تکایە سەرەتا پەیوەندی بە phoneLogin و شێوازەکانی completePhoneLogin بکەن!',
'src_file_invalid' => 'پەڕگەی سەرچاوەی نادروست دابین کرا: ',
'static_analysis' => 'An error occurred during static analysis of %s: ',
'static_analysis_minor' => 'A minor issue was encountered during static analysis of %s: %s',
'static_analysis_severe' => 'A severe issue was encountered during static analysis of %s: %s',
'stream_handle_invalid' => 'دەستەیەکی نادروستی سترێم دابین کرابوو.',
'type_extract_error' => 'نەتوانرا جۆری "%s" دەربهێنرێت، پێویستە MadelineProto نوێ بکەیتەوە!',
'type_extract_error_id' => 'نەتوانرا جۆری: %s بە id %s دەربهێنرێت، پێویستە MadelineProto نوێ بکەیتەوە!',
@ -298,7 +299,8 @@ final class Lang
'signup_ok' => 'Signed up in successfully!',
'signup_uncalled' => 'I\'m not waiting to signup! Please call the phoneLogin and the completePhoneLogin methods first!',
'src_file_invalid' => 'Invalid source file was provided: ',
'static_analysis' => 'An error occurred during static analysis of %s: ',
'static_analysis_minor' => 'A minor issue was encountered during static analysis of %s: %s',
'static_analysis_severe' => 'A severe issue was encountered during static analysis of %s: %s',
'stream_handle_invalid' => 'An invalid stream handle was provided.',
'type_extract_error' => 'Could not extract type "%s", you should update MadelineProto!',
'type_extract_error_id' => 'Could not extract type: %s with id %s, you should update MadelineProto!',
@ -343,7 +345,7 @@ final class Lang
'api_not_set' => 'شما باید یک api key و یک api id وارد کنید، @ خوتان را از my.telegram.org بگیرید',
'array_invalid' => 'شما یک آرایه معتبر وارد نکردید',
'bool_error' => 'نمی‌توان‌ boolean را استخراج کرد',
'botAlreadyRunning' => 'The bot is already running!',
'botAlreadyRunning' => 'ربات هم اکنون در حال اجرا است!',
'botapi_conversion_error' => 'نمیتوان %s را به شی ربات API تبدیل کرد',
'call_already_accepted' => 'تماس %s از قبل پذیرفته شده',
'call_already_declined' => 'تماس %s از قبل رد شده',
@ -363,10 +365,10 @@ final class Lang
'do_not_use_non_root_require_in_event_handler' => 'for performance reasons, you must not use require or include inside of an event handler class, only root-level requires are allowed.',
'done' => 'انجام شد!',
'encode_double_error' => 'نمی‌توان به درستی double را رمزنگاری (انکد) کرد',
'extensionRecommended' => 'Warning: the %s extension is not installed, please install it to speed up MadelineProto!',
'extensionRequired' => 'MadelineProto requires the %s extension to run. %s',
'extensionRequiredInstallWithApt' => 'Try running sudo apt-get install %s.',
'extensionRequiredInstallWithCustomInstructions' => 'Follow the instructions at %s to install it.',
'extensionRecommended' => 'هشدار: افزونه %s نصب نشده است. لطفا برای افزایش سرعت مدلین‌پروتو آن را نصب کنید!',
'extensionRequired' => 'مدلین برای اجرا نیاز به افزونه %s دارد. %s',
'extensionRequiredInstallWithApt' => 'اجرای کامند sudo apt-get install %s را امتحان کنید.',
'extensionRequiredInstallWithCustomInstructions' => 'برای نصب آن، دستورالعمل ها را در %s دنبال کنید.',
'file_not_exist' => 'فایل وجود ندارد',
'file_parsing' => 'درحال تجزیه %s...',
'file_type_invalid' => 'نوع فایل نامعتبر شناسایی شد (%s)',
@ -410,12 +412,12 @@ final class Lang
'long_not_32' => 'مقدار ورودی به طول 32 بایت نیست',
'long_not_64' => 'مقدار ورودی به طول 64 بایت نیست',
'madelineproto_ready' => 'MadelineProto آماده است!',
'manualAdminActionRequired' => '!!!!!!!!! MANUAL SYSTEM ADMIN ACTION REQUIRED !!!!!!!!!',
'manualAdminActionRequired' => '!!!!!!!!! فعالیت دستی ادمین سیستم نیاز است !!!!!!!!!',
'method_not_found' => 'تابع پیدا نشد: ',
'mmapErrorPart1' => 'The maximum number of memory mapped (mmap) regions was reached (%s): please increase the vm.max_map_count kernel config to 262144 to fix.',
'mmapErrorPart2' => 'برای حل کردن مشکل، کامند مقابل را با دسترسی root اجرا کنید: %s',
'mmapErrorPart3' => 'To persist the change across reboots: %s',
'mmapErrorPart4' => 'On Windows and WSL, increasing the size of the pagefile might help; please switch to native Linux if the issue persists.',
'mmapErrorPart4' => 'روی ویندوز و WSL، افزایش سایز pagefile ممکن است کمک کند؛ اگر مشکل پافشاری کرد لطفا سیستم‌عامل خود را به لینوکس تغییر دهید.',
'must_have_declare_types' => 'for performance reasons, the first statement of an event handler file must be declare(strict_types=1);',
'nearest_dc' => 'ما در %s هستیم، نزدیک ترین دیتاسنتر %d است.',
'noReportPeers' => 'هشدار: هیچ peerـی به عنوان peer گزارشات تنظیم نشده، لطفا متود زیر را به ایونت هندلر اضافه کنید',
@ -442,7 +444,8 @@ final class Lang
'signup_ok' => 'با موفقیت ثبت‌نام شد!',
'signup_uncalled' => 'من منتظر ساخت حساب نیستم! لطفا اول توابع phoneLogin و completePhoneLogin را صدا بزنید!',
'src_file_invalid' => 'منبع فایل نامعتبری لحاظ گردیده: ',
'static_analysis' => 'An error occurred during static analysis of %s: ',
'static_analysis_minor' => 'A minor issue was encountered during static analysis of %s: %s',
'static_analysis_severe' => 'A severe issue was encountered during static analysis of %s: %s',
'stream_handle_invalid' => 'یک کنترل‌کننده جریان (استریم هندل) نامعتبر لحاظ گردیده.',
'type_extract_error' => 'نمی‌توان نوع (تایپ) "%s" را استخراج کرد، شما باید MadelineProto را به روز رسانی کنید!',
'type_extract_error_id' => 'نمی‌توان نوع: %s را با ایدی %s استخراج کرد، شما باید MadelineProto را به روز رسانی کنید!',
@ -586,7 +589,8 @@ final class Lang
'signup_ok' => 'Inscription réussie!',
'signup_uncalled' => 'I\'m not waiting to signup! Please call the phoneLogin and the completePhoneLogin methods first!',
'src_file_invalid' => 'Invalid source file was provided: ',
'static_analysis' => 'An error occurred during static analysis of %s: ',
'static_analysis_minor' => 'A minor issue was encountered during static analysis of %s: %s',
'static_analysis_severe' => 'A severe issue was encountered during static analysis of %s: %s',
'stream_handle_invalid' => 'An invalid stream handle was provided.',
'type_extract_error' => 'Could not extract type "%s", you should update MadelineProto!',
'type_extract_error_id' => 'Could not extract type: %s with id %s, you should update MadelineProto!',
@ -730,7 +734,8 @@ final class Lang
'signup_ok' => 'נרשמת בהצלחה!',
'signup_uncalled' => 'אני לא מחכה להירשם! עליך להשתמש בפונקציות phoneLogin ו- completePhoneLogin קודם!',
'src_file_invalid' => 'סופק קובץ מקור לא חוקי: ',
'static_analysis' => 'An error occurred during static analysis of %s: ',
'static_analysis_minor' => 'A minor issue was encountered during static analysis of %s: %s',
'static_analysis_severe' => 'A severe issue was encountered during static analysis of %s: %s',
'stream_handle_invalid' => 'סופק stream handle לא חוקי',
'type_extract_error' => 'לא ניתן היה לחלץ את הסוג "%s", נדרש לעדכן את MadelineProto!',
'type_extract_error_id' => 'לא ניתן היה לחלץ את הסוג: %s עם מזהה id %s, נדרש לעדכן את MadelineProto!',
@ -874,7 +879,8 @@ final class Lang
'signup_ok' => 'Mi sono registrato su Telegram!',
'signup_uncalled' => 'Chiama prima le funzioni phoneLogin e completePhoneLogin!',
'src_file_invalid' => 'È stato fornito un file sorgente non valido: ',
'static_analysis' => 'An error occurred during static analysis of %s: ',
'static_analysis_minor' => 'A minor issue was encountered during static analysis of %s: %s',
'static_analysis_severe' => 'A severe issue was encountered during static analysis of %s: %s',
'stream_handle_invalid' => 'Il valore fornito non è uno stream.',
'type_extract_error' => 'Impossibile estrarre il tipo "%s", dovresti aggiornare MadelineProto!',
'type_extract_error_id' => 'Non sono riuscito ad estrarre il tipo %s con ID %s, dovresti aggiornare MadelineProto!',
@ -1018,7 +1024,8 @@ final class Lang
'signup_ok' => 'Signed up in successfully!',
'signup_uncalled' => 'I\'m not waiting to signup! Please call the phoneLogin and the completePhoneLogin methods first!',
'src_file_invalid' => 'Invalid source file was provided: ',
'static_analysis' => 'An error occurred during static analysis of %s: ',
'static_analysis_minor' => 'A minor issue was encountered during static analysis of %s: %s',
'static_analysis_severe' => 'A severe issue was encountered during static analysis of %s: %s',
'stream_handle_invalid' => 'An invalid stream handle was provided.',
'type_extract_error' => 'Could not extract type "%s", you should update MadelineProto!',
'type_extract_error_id' => 'Could not extract type: %s with id %s, you should update MadelineProto!',
@ -1162,7 +1169,8 @@ final class Lang
'signup_ok' => 'Muvaffaqiyatli ro\'yxatdan o\'tildi!',
'signup_uncalled' => 'Men ro\'yxatdan o\'tishni kutmayman! Iltimos, birinchi navbatda phoneLogin va completePhoneLogin metodlarini ishga tushuring!',
'src_file_invalid' => 'Yaroqsiz manba fayl taqdim etildi: ',
'static_analysis' => 'An error occurred during static analysis of %s: ',
'static_analysis_minor' => 'A minor issue was encountered during static analysis of %s: %s',
'static_analysis_severe' => 'A severe issue was encountered during static analysis of %s: %s',
'stream_handle_invalid' => 'Yaroqsiz oqim tutqichi taqdim etildi.',
'type_extract_error' => '“%s” turini chiqarib bolmadi, siz MadelineProtoni yangilashingiz kerak!',
'type_extract_error_id' => 'Turni ajratib bolmadi: %s identifikatori %s, siz MadelineProtoni yangilashingiz kerak!',
@ -1308,7 +1316,8 @@ final class Lang
'signup_ok' => 'Signed up in successfully!',
'signup_uncalled' => 'I\'m not waiting to signup! Please call the phoneLogin and the completePhoneLogin methods first!',
'src_file_invalid' => 'Invalid source file was provided: ',
'static_analysis' => 'An error occurred during static analysis of %s: ',
'static_analysis_minor' => 'A minor issue was encountered during static analysis of %s: %s',
'static_analysis_severe' => 'A severe issue was encountered during static analysis of %s: %s',
'stream_handle_invalid' => 'An invalid stream handle was provided.',
'type_extract_error' => 'Could not extract type "%s", you should update MadelineProto!',
'type_extract_error_id' => 'Could not extract type: %s with id %s, you should update MadelineProto!',

View File

@ -25,7 +25,6 @@ use Amp\Dns\DnsResolver;
use Amp\Future;
use Amp\Http\Client\HttpClient;
use Amp\Sync\LocalMutex;
use AssertionError;
use danog\MadelineProto\Broadcast\Broadcast;
use danog\MadelineProto\Db\DbArray;
use danog\MadelineProto\Db\DbPropertiesFactory;
@ -1609,18 +1608,14 @@ final class MTProto implements TLCallback, LoggerGetter
$issues = Tools::validateEventHandlerClass($this->event_handler_instance::class);
foreach ($issues as $issue) {
$issue->log();
$issueStr = \htmlentities((string) $issue);
$color = $issue->severe ? 'red' : 'yellow';
$warning .= "<h2 style='color:$color;'>{$issueStr}</h2>";
$warning .= $issue->getHTML();
}
foreach ($this->pluginInstances as $class => $_) {
$issues = Tools::validateEventHandlerClass($class);
foreach ($issues as $issue) {
$issue->log();
$issueStr = \htmlentities((string) $issue);
$color = $issue->severe ? 'red' : 'yellow';
$warning .= "<h2 style='color:$color;'>{$issueStr}</h2>";
}
}
foreach ($this->pluginInstances as $class => $_) {
$issues = Tools::validateEventHandlerClass($class);
foreach ($issues as $issue) {
$issue->log();
$warning .= $issue->getHTML();
}
}
}

View File

@ -31,6 +31,7 @@ use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Include_;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\String_;
@ -719,7 +720,7 @@ abstract class Tools extends AsyncTools
if (\in_array($name, self::BANNED_FILE_FUNCTIONS, true)) {
$issues []= new EventHandlerIssue(
message: Lang::$current_lang['recommend_not_use_filesystem_function'],
message: sprintf(Lang::$current_lang['recommend_not_use_filesystem_function'], $name),
file: $file,
line: $call->getStartLine(),
severe: false
@ -745,8 +746,7 @@ abstract class Tools extends AsyncTools
}
/** @var Include_ $include */
$include = $finder->findFirstInstanceOf($code, Include_::class);
if ($include) {
foreach ($finder->findInstanceOf($code, Include_::class) as $include) {
if ($plugin) {
$issues []= new EventHandlerIssue(
message: Lang::$current_lang['plugins_do_not_use_require'],
@ -755,12 +755,18 @@ abstract class Tools extends AsyncTools
severe: true
);
} elseif ($include->getAttribute('parent')) {
$issues []= new EventHandlerIssue(
message: Lang::$current_lang['do_not_use_non_root_require_in_event_handler'],
file: $file,
line: $include->getStartLine(),
severe: true
);
$parent = $include;
while ($parent = $parent->getAttribute('parent')) {
if ($parent instanceof FunctionLike) {
$issues []= new EventHandlerIssue(
message: Lang::$current_lang['do_not_use_non_root_require_in_event_handler'],
file: $file,
line: $include->getStartLine(),
severe: true
);
break;
}
}
}
}