diff --git a/docs b/docs index 2cfccd0d5..ecb8774a1 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 2cfccd0d5d83a44cf30750a27ad6f9f511ecbb0b +Subproject commit ecb8774a1acc96a62a57a60baf3569283216432b diff --git a/langs/it.json b/langs/it.json index 2d4802da8..0ec492b8f 100644 --- a/langs/it.json +++ b/langs/it.json @@ -143,5 +143,8 @@ "plugins_do_not_use_require": "per motivi di performance, i plugin possono solo includere altri file presenti nella cartella plugins usando il meccanismo di autocaricamento PSR-4 (non usando require o include).", "cli_need_dl.php_link": "È necessario specificare l'URL dello script di scaricamente per usare getDownloadLink via CLI!", "need_dl.php": "Impossibile generare lo script di scaricamento di default (%s), è necessario creare un file dl.php con il seguente contenuto: %s e passare il suo URL al secondo parametro di getDownloadLink", - "dl.php_powered_by_madelineproto": "Server di scaricamento file Telegram (fino a 4GB), creato usando MadelineProto!
Clicca qui per configurare il tuo personale server di scaricamento file Telegram!" + "dl.php_powered_by_madelineproto": "Server di scaricamento file Telegram (fino a 4GB), creato usando MadelineProto!
Clicca qui per configurare il tuo personale server di scaricamento file Telegram!", + "invalid_dl.php_session": "%s non è uno script di scaricamento valido perché l'ID della sessione non è corretto (mi aspettavo %s, ho ricevuto %s)", + "account_banned": "!!!!!!! ATTENZIONE !!!!!!!\nIl sistema antispam di telegram ha sospeso questo account.\nPer continuare, è richiesta una verifica manuale.\nMandare un'email in inglese a recover@telegram.org, chiedendo di sbannare il numero di telefono %s, spiegando brevemente cosa si ha intenzione di fare con l'account.\nPoi rieseguite nuovamente il login.\nIgnorare questo messaggio se la sessione è stata resettata intenzionalmente.", + "plugin_path_does_not_exist": "La cartella dei plugin %s non esiste!" } diff --git a/src/EventHandler.php b/src/EventHandler.php index b703a952f..f4395d313 100644 --- a/src/EventHandler.php +++ b/src/EventHandler.php @@ -379,7 +379,7 @@ abstract class EventHandler extends AbstractAPI $pathNew = \realpath(\dirname((new ReflectionClass($class))->getFileName()).DIRECTORY_SEPARATOR.$path); if ($pathNew === false) { unset($paths[$k]); - Logger::log(sprintf(Lang::$current_lang['plugin_path_does_not_exist'], $path), Logger::FATAL_ERROR); + Logger::log(\sprintf(Lang::$current_lang['plugin_path_does_not_exist'], $path), Logger::FATAL_ERROR); continue; } } @@ -403,7 +403,7 @@ abstract class EventHandler extends AbstractAPI require $file; continue; } - if (str_contains($fileName, '.')) { + if (\str_contains($fileName, '.')) { continue; } $class = $namespace.'\\'.$fileName; diff --git a/src/EventHandler/Filter/FilterCommand.php b/src/EventHandler/Filter/FilterCommand.php index 84ca42cd5..02b19544b 100644 --- a/src/EventHandler/Filter/FilterCommand.php +++ b/src/EventHandler/Filter/FilterCommand.php @@ -2,7 +2,9 @@ namespace danog\MadelineProto\EventHandler\Filter; +use AssertionError; use Attribute; +use danog\MadelineProto\EventHandler\CommandType; use danog\MadelineProto\EventHandler\Message; use danog\MadelineProto\EventHandler\Update; use Webmozart\Assert\Assert; @@ -13,12 +15,29 @@ use Webmozart\Assert\Assert; #[Attribute(Attribute::TARGET_METHOD)] final class FilterCommand extends Filter { - public function __construct(private readonly string $command) + /** + * @var array + */ + public readonly array $commandTypes; + /** + * @param string $command Command + * @param list $types Command types, if empty all command types are allowed. + */ + public function __construct(private readonly string $command, array $types = [CommandType::BANG, CommandType::DOT, CommandType::SLASH]) { Assert::true(\preg_match("/^\w+$/", $command) === 1, "An invalid command was specified!"); + Assert::notEmpty($types, 'No command types were specified!'); + $c = []; + foreach ($types as $type) { + if (isset($c[$type->value])) { + throw new AssertionError($type->value." was already specified!"); + } + $c[$type->value] = true; + } + $this->commandTypes = $types; } public function apply(Update $update): bool { - return $update instanceof Message && $update->command === $this->command; + return $update instanceof Message && $update->command === $this->command && \in_array($update->command, $this->commandTypes, true); } } diff --git a/src/Exception.php b/src/Exception.php index acd2d2631..14ff7e8d1 100644 --- a/src/Exception.php +++ b/src/Exception.php @@ -105,12 +105,12 @@ class Exception extends \Exception */ public static function exceptionHandler(\Throwable $exception): void { - $print = function (string $s) { + $print = function (string $s): void { Logger::log($s, Logger::FATAL_ERROR); if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') { echo($s.PHP_EOL); } else { - echo(str_replace("\n", "
", htmlentities($s)).PHP_EOL); + echo(\str_replace("\n", "
", \htmlentities($s)).PHP_EOL); } }; if (\str_contains($exception->getMessage(), 'Fiber stack protect failed') diff --git a/src/Lang.php b/src/Lang.php index fa4267e7f..673bf0f27 100644 --- a/src/Lang.php +++ b/src/Lang.php @@ -146,6 +146,7 @@ If you intentionally deleted this account, ignore this message.', 'not_numeric' => 'بەهای پێدراو ژمارەیی نییە', 'params_missing' => 'پارامێتری پێویست نەماوە', 'peer_not_in_db' => 'ئەم هاوتایە لە بنکەدراوەی ناوخۆیی هاوتادا ئامادە نییە', + 'plugin_path_does_not_exist' => 'Plugin path %s does not exist!', '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.', 'predicate_not_set' => 'پێشبینی (بەهای ژێر _) دانەنرابوو!', @@ -301,6 +302,7 @@ If you intentionally deleted this account, ignore this message.', 'not_numeric' => 'Given value isn\'t numeric', 'params_missing' => 'Missing required parameter', 'peer_not_in_db' => 'This peer is not present in the internal peer database', + 'plugin_path_does_not_exist' => 'Plugin path %s does not exist!', '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.', 'predicate_not_set' => 'Predicate (value under _) was not set!', @@ -456,6 +458,7 @@ If you intentionally deleted this account, ignore this message.', 'not_numeric' => 'مقدار ورودی عددی نیست', 'params_missing' => 'ورودی موردنیاز یافت نشد', 'peer_not_in_db' => 'این peer در پایگاه داده (دیتابیس) peer وجود ندارد', + 'plugin_path_does_not_exist' => 'Plugin path %s does not exist!', 'plugins_do_not_use_require' => 'به دلایل عملکردی و اجرایی، پلاگین‌ها فقط میتوانند فایل های دیگر را که در پوشه پلاگین هاست با استفاده از راه‌اندازی بارگذار خودکار PSR-4، به صورت خودکار include یا require کنند (بدون require کردن دستی آنها).', 'plugins_must_have_exactly_one_class' => 'یک پلاگین باید دقیقا یک کلس را تعریف کند! برای تعریف چند کلس، اینترفیس یا تریت، فایل‌های جداگانه بسازید، آنها توسط مدلین‌پروتو به صورت خودکار بارگذاری خواهند شد.', 'predicate_not_set' => 'مستند (مقدار تحت _) تنظیم نشده!', @@ -611,6 +614,7 @@ If you intentionally deleted this account, ignore this message.', 'not_numeric' => 'La valeur donnée n\'est pas numérique', 'params_missing' => 'Paramètre requis manquant', 'peer_not_in_db' => 'This peer is not present in the internal peer database', + 'plugin_path_does_not_exist' => 'Plugin path %s does not exist!', '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.', 'predicate_not_set' => 'Predicate (value under _) was not set!', @@ -766,6 +770,7 @@ If you intentionally deleted this account, ignore this message.', 'not_numeric' => 'הערך הנתון אינו מספרי', 'params_missing' => 'חסר פרמטר נדרש', 'peer_not_in_db' => 'עמית זה לא קיים במסד הנתונים הפנימי של עמיתים', + 'plugin_path_does_not_exist' => 'Plugin path %s does not exist!', '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.', 'predicate_not_set' => 'פרדיקט (ערך תחת _) לא הוגדר!', @@ -800,12 +805,12 @@ If you intentionally deleted this account, ignore this message.', [ '2fa_uncalled' => 'Non sto aspettando la password, chiama prima le funzioni phoneLogin e completePhoneLogin!', 'accepting_call' => 'Sto accettando una chiamata da %s...', - 'account_banned' => '!!!!!!! WARNING !!!!!!! -Telegram\'s flood prevention system suspended this account. -To continue, manual verification is required. -Send an email to recover@telegram.org, asking to unban the phone number %s, and shortly describe what will you do with this phone number. -Then login again. -If you intentionally deleted this account, ignore this message.', + 'account_banned' => '!!!!!!! ATTENZIONE !!!!!!! +Il sistema antispam di telegram ha sospeso questo account. +Per continuare, è richiesta una verifica manuale. +Mandare un\'email in inglese a recover@telegram.org, chiedendo di sbannare il numero di telefono %s, spiegando brevemente cosa si ha intenzione di fare con l\'account. +Poi rieseguite nuovamente il login. +Ignorare questo messaggio se la sessione è stata resettata intenzionalmente.', 'already_loggedIn' => 'Questa istanza di MadelineProto è già loggata!', 'apiAppInstructionsAuto0' => 'Inserisci il nome dell\'app, può essere qualsiasi cosa: ', 'apiAppInstructionsAuto1' => 'Inserisci il nome ridotto dell\'app, caratteri alfanumerici: ', @@ -867,7 +872,7 @@ If you intentionally deleted this account, ignore this message.', 'file_type_invalid' => 'È stato fornito un tipo file errato', 'fingerprint_invalid' => 'fingerprint della chiave non valido!', 'go' => 'Vai', - 'invalid_dl.php_session' => '%s is not a valid download script because its session ID is different (expected %s, got %s)', + 'invalid_dl.php_session' => '%s non è uno script di scaricamento valido perché l\'ID della sessione non è corretto (mi aspettavo %s, ho ricevuto %s)', 'length_too_big' => 'Il valore fornito è troppo lungo', 'loginBot' => 'Inserisci il tuo bot token: ', 'loginBotTokenWeb' => 'Token del bot', @@ -921,6 +926,7 @@ If you intentionally deleted this account, ignore this message.', 'not_numeric' => 'Il valore fornito non è numerico', 'params_missing' => 'Non hai fornito un parametro obbligatorio, rileggi la documentazione API', 'peer_not_in_db' => 'Questo utente/gruppo/canale non è presente nel database interno MadelineProto', + 'plugin_path_does_not_exist' => 'La cartella dei plugin %s non esiste!', 'plugins_do_not_use_require' => 'per motivi di performance, i plugin possono solo includere altri file presenti nella cartella plugins usando il meccanismo di autocaricamento PSR-4 (non usando require o include).', 'plugins_must_have_exactly_one_class' => 'un plugin deve definire esattamente una classe! Per definire più classi, interfacce o trait, si prega di creare file separati, che verranno caricati da MadelineProto automaticamente.', 'predicate_not_set' => 'Il predicato (valore sotto chiave _, esempio [\'_\' => \'inputPeer\']) non è impostato!', @@ -1076,6 +1082,7 @@ If you intentionally deleted this account, ignore this message.', 'not_numeric' => 'Given value isn\'t numeric', 'params_missing' => 'Missing required parameter', 'peer_not_in_db' => 'This peer is not present in the internal peer database', + 'plugin_path_does_not_exist' => 'Plugin path %s does not exist!', '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.', 'predicate_not_set' => 'Predicate (value under _) was not set!', @@ -1231,6 +1238,7 @@ If you intentionally deleted this account, ignore this message.', 'not_numeric' => 'Kiritilgan qiymat raqamlar emas', 'params_missing' => 'Talab etiladigan parametr kiritilmagan', 'peer_not_in_db' => 'Bu obyekt ichki ma\'lumotlar bazasida mavjud emas', + 'plugin_path_does_not_exist' => 'Plugin path %s does not exist!', '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.', 'predicate_not_set' => 'Predikat (_ ostidagi qiymat) belgilanmagan!', @@ -1388,6 +1396,7 @@ If you intentionally deleted this account, ignore this message.', 'not_numeric' => 'Given value isn\'t numeric', 'params_missing' => 'Missing required parameter', 'peer_not_in_db' => 'This peer is not present in the internal peer database', + 'plugin_path_does_not_exist' => 'Plugin path %s does not exist!', '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.', 'predicate_not_set' => 'Predicate (value under _) was not set!', diff --git a/src/MTProtoTools/UpdateHandler.php b/src/MTProtoTools/UpdateHandler.php index cccf772f4..5283effe1 100644 --- a/src/MTProtoTools/UpdateHandler.php +++ b/src/MTProtoTools/UpdateHandler.php @@ -489,7 +489,7 @@ trait UpdateHandler } } if ($result === null) { - $updates = json_encode($updates); + $updates = \json_encode($updates); throw new Exception("Could not find any message in $updates!"); } return $result;