From 49f76013764536614e17f94ed0a03a7d81110987 Mon Sep 17 00:00:00 2001 From: Little Fluffy Clouds Date: Fri, 11 Jul 2025 12:12:20 +0300 Subject: [PATCH] Fix ID integer length error & change those pesky tabulations --- mirzaev/deeproots/system/models/account.php | 338 ++-- mirzaev/deeproots/system/models/answer.php | 2 +- .../deeproots/system/models/connection.php | 144 +- .../system/models/enumerations/language.php | 98 +- mirzaev/deeproots/system/models/question.php | 2 +- .../system/models/question/localization.php | 2 +- mirzaev/deeproots/system/models/telegram.php | 8 +- .../system/models/telegram/middlewares.php | 1354 ++++++++--------- mirzaev/deeproots/system/public/telegram.php | 6 +- .../system/test/utils/database_read.php | 6 +- 10 files changed, 981 insertions(+), 979 deletions(-) diff --git a/mirzaev/deeproots/system/models/account.php b/mirzaev/deeproots/system/models/account.php index 8932e5b..ea6bcc1 100755 --- a/mirzaev/deeproots/system/models/account.php +++ b/mirzaev/deeproots/system/models/account.php @@ -6,24 +6,24 @@ namespace mirzaev\deeproots\models; // Files of the project use mirzaev\deeproots\models\core, - mirzaev\deeproots\models\connection, - mirzaev\deeproots\models\telegram, - mirzaev\deeproots\models\enumerations\language, - mirzaev\deeproots\models\account\localization; + mirzaev\deeproots\models\connection, + mirzaev\deeproots\models\telegram, + mirzaev\deeproots\models\enumerations\language, + mirzaev\deeproots\models\account\localization; // Svoboda time use svoboda\time\statement as svoboda; // Baza database use mirzaev\baza\database, - mirzaev\baza\column, - mirzaev\baza\record, - mirzaev\baza\enumerations\encoding, - mirzaev\baza\enumerations\type; + mirzaev\baza\column, + mirzaev\baza\record, + mirzaev\baza\enumerations\encoding, + mirzaev\baza\enumerations\type; // Built-in libraries use Exception as exception, - RuntimeException as exception_runtime; + RuntimeException as exception_runtime; /** * Account @@ -35,190 +35,190 @@ use Exception as exception, */ final class account extends core { - /** - * File - * - * @var string $database Path to the database file - */ - protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'accounts.baza'; + /** + * File + * + * @var string $database Path to the database file + */ + protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'accounts.baza'; - /** - * Database - * - * @var database $database The database - */ - public protected(set) database $database; + /** + * Database + * + * @var database $database The database + */ + public protected(set) database $database; - /** - * Constructor - * - * @return void - */ - public function __construct() - { - // Initializing the database - $this->database = new database() - ->encoding(encoding::utf8) - ->columns( - new column('identifier', type::integer_unsigned), - new column('name', type::string, ['length' => 64]), - new column('language', type::string, ['length' => 2]), - new column('authorized_system', type::char), - new column('authorized_game_play', type::char), - new column('authorized_rating_display', type::char), - new column('authorized_balance_deposit', type::char), - new column('authorized_balance_withdraw', type::char), - new column('authorized_settings', type::char), - new column('authorized_system_accounts', type::char), - new column('authorized_system_questions', type::char), - new column('authorized_system_settings', type::char), - new column('updated', type::integer_unsigned), - new column('created', type::integer_unsigned) - ) - ->connect($this->file); - } + /** + * Constructor + * + * @return void + */ + public function __construct() + { + // Initializing the database + $this->database = new database() + ->encoding(encoding::utf8) + ->columns( + new column('identifier', type::long_long_unsigned), + new column('name', type::string, ['length' => 64]), + new column('language', type::string, ['length' => 2]), + new column('authorized_system', type::char), + new column('authorized_game_play', type::char), + new column('authorized_rating_display', type::char), + new column('authorized_balance_deposit', type::char), + new column('authorized_balance_withdraw', type::char), + new column('authorized_settings', type::char), + new column('authorized_system_accounts', type::char), + new column('authorized_system_questions', type::char), + new column('authorized_system_settings', type::char), + new column('updated', type::integer_unsigned), + new column('created', type::integer_unsigned) + ) + ->connect($this->file); + } - /** - * Initialize - * - * Searches for the account record by the telegram account in the database, - * and if it does not find it, then create the account record and the connection record - * - * @param record $telegram The telegram account - * - * @throws exception_runtime if failed to deactivate the connection between missing account and the telegram account - * @throws exception_runtime if failed to connect the account with the telegram account - * @throws exception_runtime if failed to find the created account - * @throws exception_runtime if failed to create the account - * - * @return record The account record from the database - */ - public function initialize(record $telegram): record - { - // Initializing the connection model - $connection = new connection; + /** + * Initialize + * + * Searches for the account record by the telegram account in the database, + * and if it does not find it, then create the account record and the connection record + * + * @param record $telegram The telegram account + * + * @throws exception_runtime if failed to deactivate the connection between missing account and the telegram account + * @throws exception_runtime if failed to connect the account with the telegram account + * @throws exception_runtime if failed to find the created account + * @throws exception_runtime if failed to create the account + * + * @return record The account record from the database + */ + public function initialize(record $telegram): record + { + // Initializing the connection model + $connection = new connection; - // Searching for the connection record between theaccount and the telegram account in the database - $connected = $connection->database->read(filter: fn(record $record) => $record->telegram === $telegram->identifier, amount: 1)[0] ?? null; + // Searching for the connection record between theaccount and the telegram account in the database + $connected = $connection->database->read(filter: fn(record $record) => $record->telegram === $telegram->identifier, amount: 1)[0] ?? null; - if ($connected instanceof record) { - // Found the connection record between the account and the telegram account + if ($connected instanceof record) { + // Found the connection record between the account and the telegram account - // Searching for the account in the database - $account = $this->database->read(filter: fn(record $record) => $record->identifier === $connected->account, amount: 1)[0] ?? null; + // Searching for the account in the database + $account = $this->database->read(filter: fn(record $record) => $record->identifier === $connected->account, amount: 1)[0] ?? null; - if ($account instanceof record) { - // Found the account + if ($account instanceof record) { + // Found the account - // Exit (success) - return $account; - } else { - // Not found the account + // Exit (success) + return $account; + } else { + // Not found the account - // Deactivating the connection between missing account and the telegram account - $deactivated = $connected->read( - filter: fn(record $record) => $record->identifier === $connected->identifier, - update: function (record &$record) { - $record->active = 0; - $record->updated = svoboda::timestamp(); - }, - amount: 1)[0] ?? null; + // Deactivating the connection between missing account and the telegram account + $deactivated = $connected->read( + filter: fn(record $record) => $record->identifier === $connected->identifier, + update: function (record &$record) { + $record->active = 0; + $record->updated = svoboda::timestamp(); + }, + amount: 1)[0] ?? null; - if ($deactivated instanceof record && $deactivated->active === 0) { - // Deactivated the connection between missing account and the telegram account - - // Creating the account - goto create; - } else { - // Failed to deactivate the connection between missing account and the telegram account + if ($deactivated instanceof record && $deactivated->active === 0) { + // Deactivated the connection between missing account and the telegram account - // Exit (fail) - throw new exception_runtime('Failed to deactivate the connection between missing account and the telegram account'); - } - } - } else { - // Not found the connection record between the account and the telegram account + // Creating the account + goto create; + } else { + // Failed to deactivate the connection between missing account and the telegram account - // Creating the account process start - create: + // Exit (fail) + throw new exception_runtime('Failed to deactivate the connection between missing account and the telegram account'); + } + } + } else { + // Not found the connection record between the account and the telegram account - // Creating the account - $identifier = $this->create("$telegram->name_first $telegram->name_second", language::{$telegram->language ?? language::en->name} ?? language::en); + // Creating the account process start + create: - if ($identifier) { - // Created the account + // Creating the account + $identifier = $this->create("$telegram->name_first $telegram->name_second", language::{$telegram->language ?? language::en->name} ?? language::en); - // Searching for the created account in the database - $account = $this->database->read(filter: fn(record $record) => $record->identifier === $identifier, amount: 1)[0] ?? null; + if ($identifier) { + // Created the account - if ($account instanceof record) { - // Found the created account + // Searching for the created account in the database + $account = $this->database->read(filter: fn(record $record) => $record->identifier === $identifier, amount: 1)[0] ?? null; - // Connecting the created account with the telegram account - $connected = $connection->create(account: $account->identifier, telegram: $telegram->identifier); + if ($account instanceof record) { + // Found the created account - if ($connected) { - // Connected the created account with the telegram account + // Connecting the created account with the telegram account + $connected = $connection->create(account: $account->identifier, telegram: $telegram->identifier); - // Exit (success) - return $account; - } else { - // Not connected the created account with the telegram account + if ($connected) { + // Connected the created account with the telegram account - // Exit (fail) - throw new exception_runtime('Failed to connect the account with the telegram account'); - } - } else { - // Not found the created account + // Exit (success) + return $account; + } else { + // Not connected the created account with the telegram account - // Exit (fail) - throw new exception_runtime('Failed to find the created account'); - } - } else { - // Not created the account + // Exit (fail) + throw new exception_runtime('Failed to connect the account with the telegram account'); + } + } else { + // Not found the created account - // Exit (fail) - throw new exception_runtime('Failed to create the account'); - } - } - } + // Exit (fail) + throw new exception_runtime('Failed to find the created account'); + } + } else { + // Not created the account - /** - * Create - * - * Creates the account record in the database - * - * @param telegram $telegram The telegram account - * - * @return int|false The record identifier, if created - */ - public function create(string $name, language $language): int|false - { - // Initializing the identifier - $identifier = $this->database->count() + 1; + // Exit (fail) + throw new exception_runtime('Failed to create the account'); + } + } + } - // Initializing the record - $record = $this->database->record( - $identifier, - $name, - $language->name, - ACCOUNT_ACCESS_SYSTEM, - ACCOUNT_ACCESS_GAME_PLAY, - ACCOUNT_ACCESS_RATING_DISPLAY, - ACCOUNT_ACCESS_BALANCE_DEPOSIT, - ACCOUNT_ACCESS_BALANCE_WITHDRAW, - ACCOUNT_ACCESS_SETTINGS, - ACCOUNT_ACCESS_SYSTEM_ACCOUNTS, - ACCOUNT_ACCESS_SYSTEM_QUESTIONS, - ACCOUNT_ACCESS_SYSTEM_SETTINGS, - svoboda::timestamp(), - svoboda::timestamp() - ); + /** + * Create + * + * Creates the account record in the database + * + * @param telegram $telegram The telegram account + * + * @return int|false The record identifier, if created + */ + public function create(string $name, language $language): int|false + { + // Initializing the identifier + $identifier = $this->database->count() + 1; - // Creating the record in the database - $created = $this->database->write($record); + // Initializing the record + $record = $this->database->record( + $identifier, + $name, + $language->name, + ACCOUNT_ACCESS_SYSTEM, + ACCOUNT_ACCESS_GAME_PLAY, + ACCOUNT_ACCESS_RATING_DISPLAY, + ACCOUNT_ACCESS_BALANCE_DEPOSIT, + ACCOUNT_ACCESS_BALANCE_WITHDRAW, + ACCOUNT_ACCESS_SETTINGS, + ACCOUNT_ACCESS_SYSTEM_ACCOUNTS, + ACCOUNT_ACCESS_SYSTEM_QUESTIONS, + ACCOUNT_ACCESS_SYSTEM_SETTINGS, + svoboda::timestamp(), + svoboda::timestamp() + ); - // Exit (success) - return $created ? $identifier : false; - } + // Creating the record in the database + $created = $this->database->write($record); + + // Exit (success) + return $created ? $identifier : false; + } } diff --git a/mirzaev/deeproots/system/models/answer.php b/mirzaev/deeproots/system/models/answer.php index 7413ee9..500b2e6 100755 --- a/mirzaev/deeproots/system/models/answer.php +++ b/mirzaev/deeproots/system/models/answer.php @@ -61,7 +61,7 @@ final class answer extends core $this->database = new database() ->encoding(encoding::ascii) ->columns( - new column('identifier', type::integer_unsigned), + new column('identifier', type::long_long_unsigned), new column('A', type::char), new column('B', type::char), new column('C', type::char), diff --git a/mirzaev/deeproots/system/models/connection.php b/mirzaev/deeproots/system/models/connection.php index 3d60ba2..0ee2b05 100755 --- a/mirzaev/deeproots/system/models/connection.php +++ b/mirzaev/deeproots/system/models/connection.php @@ -12,17 +12,17 @@ use svoboda\time\statement as svoboda; // Baza database use mirzaev\baza\database, - mirzaev\baza\column, - mirzaev\baza\record, - mirzaev\baza\enumerations\encoding, - mirzaev\baza\enumerations\type; + mirzaev\baza\column, + mirzaev\baza\record, + mirzaev\baza\enumerations\encoding, + mirzaev\baza\enumerations\type; // Framework for Telegram use Zanzara\Telegram\Type\User as telegram; // Built-in libraries use Exception as exception, - RuntimeException as exception_runtime; + RuntimeException as exception_runtime; /** * Connection between account::class and telegram::class @@ -34,77 +34,77 @@ use Exception as exception, */ final class connection extends core { - /** - * File - * - * @var string $database Path to the database file - */ - protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'connection.baza'; + /** + * File + * + * @var string $database Path to the database file + */ + protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'connection.baza'; - /** - * Database - * - * Identifier: The record identifier - * Account: The account identifier - * Telegram: The telegram account identifier - * Updated: Timestamp of the last the record update - * Created: Timestamp of the record creating - * - * @var database $database The database - */ - public protected(set) database $database; + /** + * Database + * + * Identifier: The record identifier + * Account: The account identifier + * Telegram: The telegram account identifier + * Updated: Timestamp of the last the record update + * Created: Timestamp of the record creating + * + * @var database $database The database + */ + public protected(set) database $database; - /** - * Constructor - * - * @return void - */ - public function __construct() - { - // Initializing the database - $this->database = new database() - ->encoding(encoding::ascii) - ->columns( - new column('identifier', type::integer_unsigned), - new column('account', type::integer_unsigned), - new column('telegram', type::integer_unsigned), - new column('active', type::char), - new column('updated', type::integer_unsigned), - new column('created', type::integer_unsigned) - ) - ->connect($this->file); - } + /** + * Constructor + * + * @return void + */ + public function __construct() + { + // Initializing the database + $this->database = new database() + ->encoding(encoding::ascii) + ->columns( + new column('identifier', type::integer_unsigned), + new column('account', type::integer_unsigned), + new column('telegram', type::long_long_unsigned), + new column('active', type::char), + new column('updated', type::integer_unsigned), + new column('created', type::integer_unsigned) + ) + ->connect($this->file); + } - /** - * Create - * - * Creates the record in the database - * - * @param int $account Identifier of the account - * @param int $telegram Identifier of the telegram account - * @param bool $active Is the connection active? - * - * @return int|false The record identifier, if created - */ - public function create(int $account, int $telegram, bool $active = true): int|false - { - // Initializing the identifier - $identifier = $this->database->count() + 1; + /** + * Create + * + * Creates the record in the database + * + * @param int $account Identifier of the account + * @param int $telegram Identifier of the telegram account + * @param bool $active Is the connection active? + * + * @return int|false The record identifier, if created + */ + public function create(int $account, int $telegram, bool $active = true): int|false + { + // Initializing the identifier + $identifier = $this->database->count() + 1; - // Initializing the record - $record = $this->database->record( - $identifier, - $account, - $telegram, - (int) $active, - svoboda::timestamp(), - svoboda::timestamp() - ); + // Initializing the record + $record = $this->database->record( + $identifier, + $account, + $telegram, + (int) $active, + svoboda::timestamp(), + svoboda::timestamp() + ); - // Creating the record in the database - $created = $this->database->write($record); + // Creating the record in the database + $created = $this->database->write($record); - // Exit (success) - return $created ? $identifier : false; - } + // Exit (success) + return $created ? $identifier : false; + } } diff --git a/mirzaev/deeproots/system/models/enumerations/language.php b/mirzaev/deeproots/system/models/enumerations/language.php index 4e00cb7..c52ec84 100755 --- a/mirzaev/deeproots/system/models/enumerations/language.php +++ b/mirzaev/deeproots/system/models/enumerations/language.php @@ -16,55 +16,55 @@ namespace mirzaev\deeproots\models\enumerations; */ enum language { - case en; - case ru; - case in; + case en; + case ru; + case in; - /** - * Label - * - * Initialize label of the language - * - * @param language|null language Language into which to translate - * - * @return string Translated label of the language - */ - public function label(?language $language = language::en): string - { - // Exit (success) - return match ($this) { - language::en => match ($language) { - language::en => 'English', - language::ru => 'Английский', - language::in => 'अंग्रेज़ी', - }, - language::ru => match ($language) { - language::en => 'Russian', - language::ru => 'Русский', - language::in => 'रूसी', - }, - language::in => match ($language) { - language::en => 'Hindi', - language::ru => 'Хинди', - language::in => 'हिन्दी', - } - }; - } + /** + * Label + * + * Initialize label of the language + * + * @param language|null language Language into which to translate + * + * @return string Translated label of the language + */ + public function label(?language $language = language::en): string + { + // Exit (success) + return match ($this) { + language::en => match ($language) { + language::en => 'English', + language::ru => 'Английский', + language::in => 'अंग्रेज़ी', + }, + language::ru => match ($language) { + language::en => 'Russian', + language::ru => 'Русский', + language::in => 'रूसी', + }, + language::in => match ($language) { + language::en => 'Hindi', + language::ru => 'Хинди', + language::in => 'हिन्दी', + } + }; + } - /** - * Flag - * - * Initialize the flag emoji of the language - * - * @return string The flag emoji of the language - */ - public function flag(): string - { - // Exit (success) - return match ($this) { - language::en => '🇺🇸', - language::ru => '🇷🇺', - language::in => '🇮🇳', - }; - } + /** + * Flag + * + * Initialize the flag emoji of the language + * + * @return string The flag emoji of the language + */ + public function flag(): string + { + // Exit (success) + return match ($this) { + language::en => '🇺🇸', + language::ru => '🇷🇺', + language::in => '🇮🇳', + }; + } } diff --git a/mirzaev/deeproots/system/models/question.php b/mirzaev/deeproots/system/models/question.php index b8476c4..5fd0639 100755 --- a/mirzaev/deeproots/system/models/question.php +++ b/mirzaev/deeproots/system/models/question.php @@ -59,7 +59,7 @@ final class question extends core $this->database = new database() ->encoding(encoding::ascii) ->columns( - new column('identifier', type::integer_unsigned), + new column('identifier', type::long_long_unsigned), new column('active', type::char), new column('updated', type::integer_unsigned), new column('created', type::integer_unsigned) diff --git a/mirzaev/deeproots/system/models/question/localization.php b/mirzaev/deeproots/system/models/question/localization.php index cf6df79..1fd587c 100755 --- a/mirzaev/deeproots/system/models/question/localization.php +++ b/mirzaev/deeproots/system/models/question/localization.php @@ -61,7 +61,7 @@ final class localization extends core $this->database = new database() ->encoding(encoding::ascii) ->columns( - new column('identifier', type::integer_unsigned), + new column('identifier', type::long_long_unsigned), new column('text', type::string, ['length' => 256]), new column('A', type::string, ['length' => 128]), new column('B', type::string, ['length' => 128]), diff --git a/mirzaev/deeproots/system/models/telegram.php b/mirzaev/deeproots/system/models/telegram.php index ce08035..6199c9e 100755 --- a/mirzaev/deeproots/system/models/telegram.php +++ b/mirzaev/deeproots/system/models/telegram.php @@ -60,7 +60,7 @@ final class telegram extends core $this->database = new database() ->encoding(encoding::utf8) ->columns( - new column('identifier', type::integer_unsigned), + new column('identifier', type::long_long_unsigned), new column('domain', type::string, ['length' => 32]), new column('name_first', type::string, ['length' => 64]), new column('name_second', type::string, ['length' => 64]), @@ -106,7 +106,7 @@ final class telegram extends core update: function (record &$record) use ($telegram){ // Writing new values into the record $record->name_first = $telegram->getFirstName(); - $record->name_second = $telegram->getLastName(); + $record->name_second = (string) $telegram->getLastName(); $record->domain = $telegram->getUsername(); $record->updated = svoboda::timestamp(); }, @@ -171,12 +171,14 @@ final class telegram extends core // Initializing the identifier $identifier = (int) $telegram->getId(); + echo(svoboda::timestamp()); + // Initializing the record $record = $this->database->record( $identifier, $telegram->getUsername(), $telegram->getFirstName(), - $telegram->getLastName(), + (string) $telegram->getLastName(), $telegram->getLanguageCode(), (int) $telegram->isBot(), svoboda::timestamp(), diff --git a/mirzaev/deeproots/system/models/telegram/middlewares.php b/mirzaev/deeproots/system/models/telegram/middlewares.php index 4269615..515ac90 100755 --- a/mirzaev/deeproots/system/models/telegram/middlewares.php +++ b/mirzaev/deeproots/system/models/telegram/middlewares.php @@ -6,14 +6,14 @@ namespace mirzaev\deeproots\models\telegram; // Files of the project use mirzaev\deeproots\models\core, - mirzaev\deeproots\models\account, - mirzaev\deeproots\models\telegram, - mirzaev\deeproots\models\enumerations\language; + mirzaev\deeproots\models\account, + mirzaev\deeproots\models\telegram, + mirzaev\deeproots\models\enumerations\language; // Framework for Telegram use Zanzara\Context as context, - Zanzara\Telegram\Type\Message as message, - Zanzara\Middleware\MiddlewareNode as node; + Zanzara\Telegram\Type\Message as message, + Zanzara\Middleware\MiddlewareNode as node; // Baza database use mirzaev\baza\record; @@ -31,676 +31,676 @@ use Error as error; */ final class middlewares extends core { - /** - * account (middleware) - * - * Initialize or registrate the account and write it to the `telegram` variable inside the `$context` - * - * @param context $context - * @param node $next - * - * @return void - */ - public static function telegram(context $context, node $next): void - { - // Is the process stopped? - if ($context->get('stop')) return; - - // Initializing the account - $telegram = $context->getEffectiveUser(); - - // Initializing the telegram accont - $telegram = (new telegram())->initialize($telegram); - - if ($telegram instanceof record) { - // Initialized the account - - // Writing the account into the context variable - $context->set('telegram', $telegram); - - // Continuation of the process - $next($context); - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * Account (middleware) - * - * Initialize or registrate the account and write it to the `account` variable inside the `$context` - * - * @param context $context - * @param node $next - * - * @return void - */ - public static function account(context $context, node $next): void - { - // Is the process stopped? - if ($context->get('stop')) return; - - // Initializing the account - $telegram = $context->get('telegram'); - - if ($telegram instanceof record) { - // Initialized the account - - // Initializing the account - /* $account = new account()->initialize($telegram); */ - $account = (new account())->initialize($telegram); - - if ($account instanceof record) { - // Initialized the account - - // Writing the account into the context variable - $context->set('account', $account); - - // Continuation of the process - $next($context); - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * Language (middleware) - * - * Implement the account language - * - * @param context $context - * @param node $next - * - * @return void - */ - public static function language(context $context, node $next): void - { - // Is the process stopped? - if ($context->get('stop')) return; - - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Writing the account language into the context variable - $context->set('language', language::{$account->language ?? LANGUAGE_DEFAULT} ?? language::{LANGUAGE_DEFAULT}); - - // Continuation of the process - $next($context); - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * Localization (middleware) - * - * Implement the account language and initialize the localization file - * - * @param context $context - * @param node $next - * - * @return void - */ - public static function localization(context $context, node $next): void - { - // Is the process stopped? - if ($context->get('stop')) return; - - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing the language - $language = $context->get('language'); - - if ($language instanceof language) { - // Initialized the language - - // Initializing path to the localization file - $file = LOCALIZATIONS . DIRECTORY_SEPARATOR . strtolower($language->label()) . '.php'; - - if (file_exists($file) && is_readable($file)) { - // Found the localization file - - // Initializing localization - $localization = require($file); - - if (is_array($localization)) { - // Initializae localization - - // Writing localization into the context variable - $context->set('localization', $localization); - - // Continuation of the process - $next($context); - } else { - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not found the localization file - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the localization file*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized language - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize language*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * System (middleware) - * - * Check the account for access to the system - * - * @param context $context - * @param node $next - * - * @return void - */ - public static function system(context $context, node $next): void - { - // Is the process stopped? - if ($context->get('stop')) return; - - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - if ($account->authorized_system) { - // Authorized the account to the system - - // Continuation of the process - $next($context); - } else { - // Not authorized the account to the system - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Sending the message - $context->sendMessage('⛔ *' . $localization['not_authorized_system'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - - // Stopping the process - $context->set('stop', true); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * Contact (middleware) - * - * Check the account for access to contact with the organization - * - * @param context $context - * @param node $next - * - * @return void - */ - public static function contact(context $context, node $next): void - { - // Is the process stopped? - if ($context->get('stop')) return; - - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - if ($account->authorized_contact) { - // Authorized the account to contact with the organization - - // Continuation of the process - $next($context); - } else { - // Not authorized the account to contact with the organization - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Sending the message - $context->sendMessage('⛔ *' . $localization['not_authorized_contact'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - - // Stopping the process - $context->set('stop', true); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * Join (middleware) - * - * Check the account for access to join to distributions - * - * @param context $context - * @param node $next - * - * @return void - */ - public static function join(context $context, node $next): void - { - // Is the process stopped? - if ($context->get('stop')) return; - - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - if ($account->authorized_joins) { - // Authorized the account to joint to distributions - - // Continuation of the process - $next($context); - } else { - // Not authorized the account to joint to distributions - - // Sending the message - $context->sendMessage('⛔ *' . $localization['not_authorized_joins'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - - // Stopping the process - $context->set('stop', true); - } - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * Settings (middleware) - * - * Check the account for access to settings - * - * @param context $context - * @param node $next - * - * @return void - */ - public static function settings(context $context, node $next): void - { - // Is the process stopped? - if ($context->get('stop')) return; - - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - if ($account->authorized_settings) { - // Authorized the account to the settings - - // Continuation of the process - $next($context); - } else { - // Not authorized the account to the settings - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Sending the message - $context->sendMessage('⛔ *' . $localization['not_authorized_settings'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - - // Stopping the process - $context->set('stop', true); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * Questions (system) (middleware) - * - * Check the account for system access to questions - * - * @param context $context - * @param node $next - * - * @return void - */ - public static function system_questions(context $context, node $next): void - { - // Is the process stopped? - if ($context->get('stop')) return; - - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - if ($account->authorized_system_questions) { - // Authorized the account to the system settings - - // Continuation of the process - $next($context); - } else { - // Not authorized the account to the system settings - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Sending the message - $context->sendMessage('⛔ *' . $localization['not_authorized_system_questions'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - - // Stopping the process - $context->set('stop', true); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - - /** - * System settings (system) (middleware) - * - * Check the account for system access to settings - * - * @param context $context - * @param node $next - * - * @return void - */ - public static function system_settings(context $context, node $next): void - { - // Is the process stopped? - if ($context->get('stop')) return; - - // Initializing the account - $account = $context->get('account'); - - if ($account instanceof record) { - // Initialized the account - - if ($account->authorized_system_settings) { - // Authorized the account to the system settings - - // Continuation of the process - $next($context); - } else { - // Not authorized the account to the system settings - - // Initializing localization - $localization = $context->get('localization'); - - if ($localization) { - // Initialized localization - - // Sending the message - $context->sendMessage('⛔ *' . $localization['not_authorized_system_settings'] . '*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - - // Stopping the process - $context->set('stop', true); - } else { - // Not initialized localization - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize localization*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } - } else { - // Not initialized the account - - // Sending the message - $context->sendMessage('⚠️ *Failed to initialize the account*') - ->then(function (message $message) use ($context) { - // Sended the message - - // Ending the conversation process - $context->endConversation(); - }); - } - } + /** + * account (middleware) + * + * Initialize or registrate the account and write it to the `telegram` variable inside the `$context` + * + * @param context $context + * @param node $next + * + * @return void + */ + public static function telegram(context $context, node $next): void + { + // Is the process stopped? + if ($context->get('stop')) return; + + // Initializing the account + $telegram = $context->getEffectiveUser(); + + // Initializing the telegram accont + $telegram = (new telegram())->initialize($telegram); + + if ($telegram instanceof record) { + // Initialized the account + + // Writing the account into the context variable + $context->set('telegram', $telegram); + + // Continuation of the process + $next($context); + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * Account (middleware) + * + * Initialize or registrate the account and write it to the `account` variable inside the `$context` + * + * @param context $context + * @param node $next + * + * @return void + */ + public static function account(context $context, node $next): void + { + // Is the process stopped? + if ($context->get('stop')) return; + + // Initializing the account + $telegram = $context->get('telegram'); + + if ($telegram instanceof record) { + // Initialized the account + + // Initializing the account + /* $account = new account()->initialize($telegram); */ + $account = (new account())->initialize($telegram); + + if ($account instanceof record) { + // Initialized the account + + // Writing the account into the context variable + $context->set('account', $account); + + // Continuation of the process + $next($context); + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * Language (middleware) + * + * Implement the account language + * + * @param context $context + * @param node $next + * + * @return void + */ + public static function language(context $context, node $next): void + { + // Is the process stopped? + if ($context->get('stop')) return; + + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Writing the account language into the context variable + $context->set('language', language::{$account->language ?? LANGUAGE_DEFAULT} ?? language::{LANGUAGE_DEFAULT}); + + // Continuation of the process + $next($context); + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * Localization (middleware) + * + * Implement the account language and initialize the localization file + * + * @param context $context + * @param node $next + * + * @return void + */ + public static function localization(context $context, node $next): void + { + // Is the process stopped? + if ($context->get('stop')) return; + + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing the language + $language = $context->get('language'); + + if ($language instanceof language) { + // Initialized the language + + // Initializing path to the localization file + $file = LOCALIZATIONS . DIRECTORY_SEPARATOR . strtolower($language->label()) . '.php'; + + if (file_exists($file) && is_readable($file)) { + // Found the localization file + + // Initializing localization + $localization = require($file); + + if (is_array($localization)) { + // Initializae localization + + // Writing localization into the context variable + $context->set('localization', $localization); + + // Continuation of the process + $next($context); + } else { + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not found the localization file + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the localization file*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized language + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize language*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * System (middleware) + * + * Check the account for access to the system + * + * @param context $context + * @param node $next + * + * @return void + */ + public static function system(context $context, node $next): void + { + // Is the process stopped? + if ($context->get('stop')) return; + + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + if ($account->authorized_system) { + // Authorized the account to the system + + // Continuation of the process + $next($context); + } else { + // Not authorized the account to the system + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Sending the message + $context->sendMessage('⛔ *' . $localization['not_authorized_system'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + + // Stopping the process + $context->set('stop', true); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * Contact (middleware) + * + * Check the account for access to contact with the organization + * + * @param context $context + * @param node $next + * + * @return void + */ + public static function contact(context $context, node $next): void + { + // Is the process stopped? + if ($context->get('stop')) return; + + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + if ($account->authorized_contact) { + // Authorized the account to contact with the organization + + // Continuation of the process + $next($context); + } else { + // Not authorized the account to contact with the organization + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Sending the message + $context->sendMessage('⛔ *' . $localization['not_authorized_contact'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + + // Stopping the process + $context->set('stop', true); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * Join (middleware) + * + * Check the account for access to join to distributions + * + * @param context $context + * @param node $next + * + * @return void + */ + public static function join(context $context, node $next): void + { + // Is the process stopped? + if ($context->get('stop')) return; + + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + if ($account->authorized_joins) { + // Authorized the account to joint to distributions + + // Continuation of the process + $next($context); + } else { + // Not authorized the account to joint to distributions + + // Sending the message + $context->sendMessage('⛔ *' . $localization['not_authorized_joins'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + + // Stopping the process + $context->set('stop', true); + } + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * Settings (middleware) + * + * Check the account for access to settings + * + * @param context $context + * @param node $next + * + * @return void + */ + public static function settings(context $context, node $next): void + { + // Is the process stopped? + if ($context->get('stop')) return; + + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + if ($account->authorized_settings) { + // Authorized the account to the settings + + // Continuation of the process + $next($context); + } else { + // Not authorized the account to the settings + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Sending the message + $context->sendMessage('⛔ *' . $localization['not_authorized_settings'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + + // Stopping the process + $context->set('stop', true); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * Questions (system) (middleware) + * + * Check the account for system access to questions + * + * @param context $context + * @param node $next + * + * @return void + */ + public static function system_questions(context $context, node $next): void + { + // Is the process stopped? + if ($context->get('stop')) return; + + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + if ($account->authorized_system_questions) { + // Authorized the account to the system settings + + // Continuation of the process + $next($context); + } else { + // Not authorized the account to the system settings + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Sending the message + $context->sendMessage('⛔ *' . $localization['not_authorized_system_questions'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + + // Stopping the process + $context->set('stop', true); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + + /** + * System settings (system) (middleware) + * + * Check the account for system access to settings + * + * @param context $context + * @param node $next + * + * @return void + */ + public static function system_settings(context $context, node $next): void + { + // Is the process stopped? + if ($context->get('stop')) return; + + // Initializing the account + $account = $context->get('account'); + + if ($account instanceof record) { + // Initialized the account + + if ($account->authorized_system_settings) { + // Authorized the account to the system settings + + // Continuation of the process + $next($context); + } else { + // Not authorized the account to the system settings + + // Initializing localization + $localization = $context->get('localization'); + + if ($localization) { + // Initialized localization + + // Sending the message + $context->sendMessage('⛔ *' . $localization['not_authorized_system_settings'] . '*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + + // Stopping the process + $context->set('stop', true); + } else { + // Not initialized localization + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize localization*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } + } else { + // Not initialized the account + + // Sending the message + $context->sendMessage('⚠️ *Failed to initialize the account*') + ->then(function (message $message) use ($context) { + // Sended the message + + // Ending the conversation process + $context->endConversation(); + }); + } + } } diff --git a/mirzaev/deeproots/system/public/telegram.php b/mirzaev/deeproots/system/public/telegram.php index 7f42061..dea0ab0 100755 --- a/mirzaev/deeproots/system/public/telegram.php +++ b/mirzaev/deeproots/system/public/telegram.php @@ -19,9 +19,9 @@ use Zanzara\Zanzara as zanzara, Zanzara\Config as config; // Enabling debugging -/* ini_set('error_reporting', E_ALL); - ini_set('display_errors', 1); - ini_set('display_startup_errors', 1); */ +// ini_set('error_reporting', E_ALL); +// ini_set('display_errors', 1); +// ini_set('display_startup_errors', 1); // Initializing path to the public directory define('INDEX', __DIR__); diff --git a/mirzaev/deeproots/system/test/utils/database_read.php b/mirzaev/deeproots/system/test/utils/database_read.php index 97b67f7..873ea4b 100644 --- a/mirzaev/deeproots/system/test/utils/database_read.php +++ b/mirzaev/deeproots/system/test/utils/database_read.php @@ -23,14 +23,14 @@ $file = DATABASES . DIRECTORY_SEPARATOR . 'telegram.baza'; $database = new database() ->encoding(encoding::utf8) ->columns( - new column('identifier', type::integer_unsigned), + new column('identifier', type::long_long_unsigned), new column('domain', type::string, ['length' => 32]), new column('name_first', type::string, ['length' => 64]), new column('name_second', type::string, ['length' => 64]), new column('language', type::string, ['length' => 2]), new column('robot', type::char), - new column('updated', type::integer_unsigned), - new column('created', type::integer_unsigned) + new column('updated', type::integer), + new column('created', type::integer) ) ->connect($file);