From accfe5a4965dc37a8794324f08315e8047495311 Mon Sep 17 00:00:00 2001 From: mirzaev Date: Thu, 6 Mar 2025 06:17:11 +0700 Subject: [PATCH] fixes --- .../system/models/interneturok.php | 21 +++++---- .../system/models/telegram/parser.php | 45 ++++++++++++------- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/mirzaev/parser_from_interneturok/system/models/interneturok.php b/mirzaev/parser_from_interneturok/system/models/interneturok.php index 6844fc5..78454c3 100644 --- a/mirzaev/parser_from_interneturok/system/models/interneturok.php +++ b/mirzaev/parser_from_interneturok/system/models/interneturok.php @@ -900,16 +900,21 @@ final class interneturok extends core */ public static function amount(): int { - // Opening the interneturok accounts file - $file = new spl(INTERNETUROK_ACCOUNTS_FILE, 'r'); + try { + // Opening the interneturok accounts file + $file = new spl(INTERNETUROK_ACCOUNTS_FILE, 'r'); - // Move the cursor to the last row - $file->seek(PHP_INT_MAX); + // Move the cursor to the last row + $file->seek(PHP_INT_MAX); - // Initializing number of the last row - $rows = $file->key(); + // Initializing number of the last row + $rows = $file->key(); - // Exit (success) - return $rows; + // Exit (success) + return $rows; + } catch (exception $exception) { + // Exit (fail) + return 0; + } } } diff --git a/mirzaev/parser_from_interneturok/system/models/telegram/parser.php b/mirzaev/parser_from_interneturok/system/models/telegram/parser.php index 073b365..84ad439 100644 --- a/mirzaev/parser_from_interneturok/system/models/telegram/parser.php +++ b/mirzaev/parser_from_interneturok/system/models/telegram/parser.php @@ -17,6 +17,9 @@ use Zanzara\Context as context, // Framework for asynchronous PHP use function React\Async\await; +// Built-in libraries +use Exception as exception; + /** * Telegram shcool subjects parser * @@ -205,26 +208,38 @@ final class parser extends core // Initializing the parser $parser = new interneturok(); - // Parsing homework files - $files = $parser->parse(subject: $subject, grade: $grade, waiting: 3); + try { - if (!empty($files)) { - // Initialized homework files + // Parsing homework files + $files = $parser->parse(subject: $subject, grade: $grade, waiting: 3); - foreach ($files as $file) { - // Iterating over files in the storage + if (!empty($files)) { + // Initialized homework files - // Sending the file - await($context->sendDocument(new file_input($file))); + foreach ($files as $file) { + // Iterating over files in the storage + + // Sending the file + await($context->sendDocument(new file_input($file))); + } + + // Deleting in the telegram user buffer + $context->deleteUserDataItem(static::PROCESS); + } else { + // Not initialized homework files + + // Sending the message + $context->sendMessage('❌ *Не найдены домашние задания') + ->then(function (message $message) use ($context) { + // Sended the message + + // Sending the menu with subjects + commands::menu($context); + }); } - - // Deleting in the telegram user buffer - $context->deleteUserDataItem(static::PROCESS); - } else { - // Not initialized homework files - + } catch (exception $exception) { // Sending the message - $context->sendMessage('❌ *Не найдены домашние задания') + $context->sendMessage('⚠️ *Произошла ошибка при обработке домашних заданий') ->then(function (message $message) use ($context) { // Sended the message