generated from mirzaev/pot
created by Arsen
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "damper.mjs"]
|
||||||
|
path = damper.mjs
|
||||||
|
url = https://git.svoboda.works/mirzaev/damper.mjs
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// Exit (success)
|
|
||||||
return [
|
|
||||||
'' => ''
|
|
||||||
]
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// Exit (success)
|
|
||||||
return [
|
|
||||||
'' => ''
|
|
||||||
]
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace kodorvan\brainrot\models\enumerations;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Language
|
|
||||||
*
|
|
||||||
* Types of languages by ISO 639-1 standart
|
|
||||||
*
|
|
||||||
* @package kodorvan\brainrot\models\enumerations
|
|
||||||
*
|
|
||||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
|
||||||
* @author kodorvan <mail@domain.zone>
|
|
||||||
*/
|
|
||||||
enum language
|
|
||||||
{
|
|
||||||
case en;
|
|
||||||
case ru;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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::ru => match ($language) {
|
|
||||||
language::en => 'Russian',
|
|
||||||
language::ru => 'Русский'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 => '🇷🇺'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "kodorvan/brainrot",
|
"name": "kodorvan/brainrot",
|
||||||
"description": "",
|
"description": "",
|
||||||
"homepage": "https://git.svoboda.works/kodorvan/brainrot",
|
"homepage": "https://git.svoboda.works/kodorvan/brainrot",
|
||||||
"type": "site",
|
"type": "game",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"minimal",
|
"minimal",
|
||||||
"baza"
|
"baza"
|
||||||
@@ -11,9 +11,9 @@
|
|||||||
"license": "WTFPL",
|
"license": "WTFPL",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "kodorvan",
|
"name": "Arsen Mirzaev Tatyano-Muradovich",
|
||||||
"email": "kodorvan@gmail.com",
|
"email": "arsen@mirzaev.sexy",
|
||||||
"homepage": "https://kodorvan.page",
|
"homepage": "https://mirzaev.sexy",
|
||||||
"role": "Programmer"
|
"role": "Programmer"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -27,7 +27,13 @@
|
|||||||
"mirzaev/baza": "^3.3",
|
"mirzaev/baza": "^3.3",
|
||||||
"twig/twig": "^3.2",
|
"twig/twig": "^3.2",
|
||||||
"twig/extra-bundle": "^3.7",
|
"twig/extra-bundle": "^3.7",
|
||||||
"twig/intl-extra": "^3.10"
|
"twig/intl-extra": "^3.10",
|
||||||
|
"mirzaev/languages": "^1.0",
|
||||||
|
"mirzaev/currencies": "^1.0",
|
||||||
|
"svoboda/time": "^1.0",
|
||||||
|
"badfarm/zanzara": "^0.9.1",
|
||||||
|
"nyholm/psr7": "^1.8",
|
||||||
|
"react/filesystem": "^0.1.2"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
@@ -41,5 +47,11 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"pre-update-cmd": "./install.sh"
|
"pre-update-cmd": "./install.sh"
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"allow-plugins": {
|
||||||
|
"php-http/discovery": true,
|
||||||
|
"wyrihaximus/composer-update-bin-autoload-path": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
damper.mjs
Submodule
1
damper.mjs
Submodule
Submodule damper.mjs added at 81d208b964
13
install.sh
13
install.sh
@@ -1,10 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/fish
|
||||||
|
|
||||||
if [ -d author/project ]; then
|
|
||||||
mv author/project author/brainrot
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -d author ]; then
|
|
||||||
mv author kodorvan
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
if not test -L kodorvan/brainrot/system/public/js/modules/damper.mjs
|
||||||
|
ln -s ../../../../../../damper.mjs/damper.mjs kodorvan/brainrot/system/public/js/modules/damper.mjs
|
||||||
|
end
|
||||||
|
|||||||
@@ -6,8 +6,10 @@ namespace kodorvan\brainrot\controllers;
|
|||||||
|
|
||||||
// Files of the project
|
// Files of the project
|
||||||
use kodorvan\brainrot\views\templater,
|
use kodorvan\brainrot\views\templater,
|
||||||
kodorvan\brainrot\models\core as models,
|
kodorvan\brainrot\models\core as models;
|
||||||
kodorvan\brainrot\models\enumerations\language;
|
|
||||||
|
// Library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
// Framework for PHP
|
// Framework for PHP
|
||||||
use mirzaev\minimal\core as minimal,
|
use mirzaev\minimal\core as minimal,
|
||||||
@@ -28,7 +30,6 @@ use mirzaev\minimal\core as minimal,
|
|||||||
*
|
*
|
||||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
* @author kodorvan <mail@domain.zone>
|
|
||||||
*/
|
*/
|
||||||
class core extends controller
|
class core extends controller
|
||||||
{
|
{
|
||||||
@@ -22,7 +22,6 @@ use mirzaev\minimal\http\enumerations\content,
|
|||||||
*
|
*
|
||||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
* @author kodorvan <mail@domain.zone>
|
|
||||||
*/
|
*/
|
||||||
final class index extends core
|
final class index extends core
|
||||||
{
|
{
|
||||||
76
kodorvan/brainrot/system/localizations/english.php
Normal file
76
kodorvan/brainrot/system/localizations/english.php
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return [
|
||||||
|
// System
|
||||||
|
'svoboda' => 'Svoboda',
|
||||||
|
'kodorvan' => 'Kodorvan',
|
||||||
|
'brainrot' => 'Steal Brainrot',
|
||||||
|
'empty' => 'Empty',
|
||||||
|
'yes' => 'Yes',
|
||||||
|
'no' => 'No',
|
||||||
|
|
||||||
|
// Main menu
|
||||||
|
'menu_title' => 'Main menu',
|
||||||
|
'menu_accounts' => 'Accounts',
|
||||||
|
|
||||||
|
// Account
|
||||||
|
'account_title' => 'Account',
|
||||||
|
'account_authorized_system' => 'Access to the system',
|
||||||
|
'account_authorized_settings' => 'Access to settings',
|
||||||
|
'account_authorized_system_accounts' => 'System access to accounts management',
|
||||||
|
'account_authorized_system_settings' => 'System access to the system settings',
|
||||||
|
'account_button_localizations' => 'Localizations',
|
||||||
|
'account_localization_create_failted_to_initialize_language' => 'Failed to initialize language',
|
||||||
|
|
||||||
|
// Language setting
|
||||||
|
'settings_select_language_title' => 'Select language',
|
||||||
|
'settings_select_language_description' => 'The selected language will be writed in your account settings',
|
||||||
|
'settings_language_update_success' => 'Language replaced:',
|
||||||
|
'settings_language_update_fail' => 'Failed to replace language',
|
||||||
|
|
||||||
|
// Language selection
|
||||||
|
'select_language_title' => 'Select language',
|
||||||
|
'select_language_description' => 'The selected language will be used in the current process',
|
||||||
|
'select_language_button_add' => 'Add a language',
|
||||||
|
|
||||||
|
// Repository
|
||||||
|
'repository_title' => 'Repository',
|
||||||
|
'repository_text' => <<<TXT
|
||||||
|
Pechatalka is written in [PHP](https://www.php.net/) using [Zanzara](https://github.com/badfarm/zanzara) for Telegram,
|
||||||
|
my [MINIMAL](https://git.svoboda.works/mirzaev/minimal) framework for PHP and my [Baza](https://git.svoboda.works/mirzaev/baza) database
|
||||||
|
|
||||||
|
The code is under the [WTFPL](https://en.wikipedia.org/wiki/WTFPL) license
|
||||||
|
You can help me with the development, or use my code for free\!
|
||||||
|
TXT,
|
||||||
|
'repository_button_code' => 'The code',
|
||||||
|
'repository_button_issues' => 'Issues',
|
||||||
|
'repository_button_suggestions' => 'Suggestions',
|
||||||
|
|
||||||
|
// Author
|
||||||
|
'author_title' => 'Author',
|
||||||
|
'author_text' => <<<TXT
|
||||||
|
*Arsen Mirzaev Tatyano\-Muradovich*
|
||||||
|
Programmer, anarchist, vegetarian
|
||||||
|
TXT,
|
||||||
|
'author_button_neurojournal' => 'Neurojournal',
|
||||||
|
'author_button_projects' => 'Projects',
|
||||||
|
'author_button_telegram' => 'Telegram',
|
||||||
|
'author_button_twitter' => 'Twitter',
|
||||||
|
'author_button_bluesky' => 'Bluesky',
|
||||||
|
'author_button_bastyon' => 'Bastyon',
|
||||||
|
'author_button_youtube_english' => 'YouTube',
|
||||||
|
'author_button_youtube_russian' => 'YouTube',
|
||||||
|
'author_button_message' => 'Send a message',
|
||||||
|
|
||||||
|
// Authorization
|
||||||
|
'not_authorized_system' => 'You do not have access to the system',
|
||||||
|
'not_authorized_messages' => 'You do not have access to send messages',
|
||||||
|
'not_authorized_joins' => 'You do not have access to joins',
|
||||||
|
'not_authorized_settings' => 'You do not have access to the settings',
|
||||||
|
'not_authorized_system_settings' => 'You do not have access to the system settings',
|
||||||
|
'not_authorized_system_distributions' => 'You do not have access to distributions administration',
|
||||||
|
|
||||||
|
// Other
|
||||||
|
'why_so_shroomious' => 'why so shroomious'
|
||||||
|
];
|
||||||
80
kodorvan/brainrot/system/localizations/russian.php
Normal file
80
kodorvan/brainrot/system/localizations/russian.php
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return [
|
||||||
|
// System
|
||||||
|
'svoboda' => 'Свобода',
|
||||||
|
'kodorvan' => 'Кодорвань',
|
||||||
|
'brainrot' => 'Укради Брейнрот',
|
||||||
|
'empty' => 'Пусто',
|
||||||
|
'yes' => 'Да',
|
||||||
|
'no' => 'Нет',
|
||||||
|
|
||||||
|
// Main menu
|
||||||
|
'menu_title' => 'Главное меню',
|
||||||
|
'menu_accounts' => 'Аккаунты',
|
||||||
|
|
||||||
|
// Аккаунт
|
||||||
|
'account_title' => 'Аккаунт',
|
||||||
|
'account_authorized_system' => 'Доступ к системе',
|
||||||
|
'account_authorized_messages' => 'Доступ к сообщениям',
|
||||||
|
'account_authorized_joins' => 'Доступ к вступлениям',
|
||||||
|
'account_authorized_settings' => 'Доступ к изменению настроек',
|
||||||
|
'account_authorized_system_accounts' => 'Системный доступ к управлению аккаунтами',
|
||||||
|
'account_authorized_system_distributions' => 'Системный доступ к управлению дистрибутивами',
|
||||||
|
'account_authorized_system_members' => 'Системный доступ к управлению участниками дистрибутивов',
|
||||||
|
'account_authorized_system_settings' => 'Системный доступ к системным настройкам',
|
||||||
|
'account_button_localizations' => 'Локализации',
|
||||||
|
'account_localization_create_failted_to_initialize_language' => 'Не удалось инициализировать язык',
|
||||||
|
|
||||||
|
// Настройки языка
|
||||||
|
'settings_select_language_title' => 'Выбери язык',
|
||||||
|
'settings_select_language_description' => 'Выбранный язык будет записан в настройки аккаунта',
|
||||||
|
'settings_language_update_success' => 'Язык заменён:',
|
||||||
|
'settings_language_update_fail' => 'Не удалось заменить язык',
|
||||||
|
|
||||||
|
// Выбор языка
|
||||||
|
'select_language_title' => 'Выбери язык',
|
||||||
|
'select_language_description' => 'Выбранный язык будет использован в текущем процессе',
|
||||||
|
'select_language_button_add' => 'Добавить язык',
|
||||||
|
|
||||||
|
// Репозиторий
|
||||||
|
'repository_title' => 'Репозиторий',
|
||||||
|
'repository_text' => <<<TXT
|
||||||
|
Печаталка написана на [PHP](https://www.php.net/) используя [Zanzara](https://github.com/badfarm/zanzara) для Telegram,
|
||||||
|
мой [MINIMAL](https://git.svoboda.works/mirzaev/minimal) фреймворк для PHP и моя база данных [Baza](https://git.svoboda.works/mirzaev/baza)
|
||||||
|
|
||||||
|
Код находится под лицензией [WTFPL](https://en.wikipedia.org/wiki/WTFPL)
|
||||||
|
Помогай с разработкой или используй мой код бесплатно\!
|
||||||
|
TXT,
|
||||||
|
'repository_button_code' => 'Код',
|
||||||
|
'repository_button_issues' => 'Проблемы',
|
||||||
|
'repository_button_suggestions' => 'Предложения',
|
||||||
|
|
||||||
|
// Автор
|
||||||
|
'author_title' => 'Автор',
|
||||||
|
'author_text' => <<<TXT
|
||||||
|
*Арсен Мирзаев Татьяно\-Мурадович*
|
||||||
|
Программист, анархист, вегетарианец
|
||||||
|
TXT,
|
||||||
|
'author_button_neurojournal' => 'Нейрожурнал',
|
||||||
|
'author_button_projects' => 'Проекты',
|
||||||
|
'author_button_telegram' => 'Телеграм',
|
||||||
|
'author_button_twitter' => 'Twitter',
|
||||||
|
'author_button_bluesky' => 'Bluesky',
|
||||||
|
'author_button_bastyon' => 'Bastyon',
|
||||||
|
'author_button_youtube_english' => 'YouTube',
|
||||||
|
'author_button_youtube_russian' => 'YouTube',
|
||||||
|
'author_button_message' => 'Отправить сообщение',
|
||||||
|
|
||||||
|
// Авторизация
|
||||||
|
'not_authorized_system' => 'У тебя нет доступа к системе',
|
||||||
|
'not_authorized_messages' => 'У тебя нет доступа к сообщениям',
|
||||||
|
'not_authorized_joins' => 'У тебя нет доступа к вступлениям',
|
||||||
|
'not_authorized_settings' => 'У тебя нет доступа к настройкам',
|
||||||
|
'not_authorized_system_settings' => 'У тебя нет доступа к системным настройкам',
|
||||||
|
'not_authorized_system_distributions' => 'У тебя нет доступа к администрированию дистрибутивов',
|
||||||
|
|
||||||
|
// Прочее
|
||||||
|
'why_so_shroomious' => 'почему такой грибъёзный'
|
||||||
|
];
|
||||||
201
kodorvan/brainrot/system/models/account.php
Normal file
201
kodorvan/brainrot/system/models/account.php
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\brainrot\models;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\brainrot\models\core;
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use Zanzara\Telegram\Type\User as telegram;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use Exception as exception,
|
||||||
|
RuntimeException as exception_runtime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Account
|
||||||
|
*
|
||||||
|
* @package kodorvan\brainrot\models
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
final class account extends core
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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('identifier_telegram', 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('authorized_system', type::char),
|
||||||
|
new column('authorized_settings', type::char),
|
||||||
|
new column('authorized_system_accounts', 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 in the database, and if it does not find it, it creates it
|
||||||
|
*
|
||||||
|
* @param telegram $telegram The telegram account
|
||||||
|
*
|
||||||
|
* @throws exception_runtime if update the account record in the database by the telegram account values
|
||||||
|
* @throws exception_runtime if failed to find the registered account
|
||||||
|
* @throws exception_runtime if failed to registrate the account
|
||||||
|
*
|
||||||
|
* @return record The account record from the database
|
||||||
|
*/
|
||||||
|
public function initialize(telegram $telegram): record
|
||||||
|
{
|
||||||
|
// Searching for the account in the database
|
||||||
|
$account = $this->database->read(filter: fn(record $record) => $record->identifier_telegram === $telegram->getId(), amount: 1)[0] ?? null;
|
||||||
|
|
||||||
|
if ($account instanceof record) {
|
||||||
|
// Found the account record
|
||||||
|
|
||||||
|
if (
|
||||||
|
$account->name_first !== $telegram->getFirstName() ||
|
||||||
|
$account->name_second !== $telegram->getLastName() ||
|
||||||
|
$account->domain !== $telegram->getUsername()
|
||||||
|
) {
|
||||||
|
// The telegram account was updated
|
||||||
|
|
||||||
|
// Updating the account in the database
|
||||||
|
$updated = $this->database->read(
|
||||||
|
filter: fn(record $record) => $record->identifier_telegram === $telegram->getId(),
|
||||||
|
update: function (record &$record) use ($telegram){
|
||||||
|
// Writing new values into the record
|
||||||
|
$record->name_first = $telegram->getFirstName();
|
||||||
|
$record->name_second = $telegram->getLastName();
|
||||||
|
$record->domain = $telegram->getUsername();
|
||||||
|
$record->updated = svoboda::timestamp();
|
||||||
|
},
|
||||||
|
amount: 1
|
||||||
|
)[0] ?? null;
|
||||||
|
|
||||||
|
if ($updated instanceof record && $updated->values() !== $account->values()) {
|
||||||
|
// Updated the account in the database
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return $updated;
|
||||||
|
} else {
|
||||||
|
// Not updated the account in the database
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception_runtime('Failed to update the account record in the database by the telegram account values');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return $account;
|
||||||
|
} else {
|
||||||
|
// Not found the account record
|
||||||
|
|
||||||
|
if ($this->registrate($telegram)) {
|
||||||
|
// Registered the account
|
||||||
|
|
||||||
|
// Searching for the registered account in the database
|
||||||
|
$account = $this->database->read(filter: fn(record $record) => $record->identifier_telegram === $telegram->getId(), amount: 1)[0] ?? null;
|
||||||
|
|
||||||
|
if ($account instanceof record) {
|
||||||
|
// Found the registered account
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return $account;
|
||||||
|
} else {
|
||||||
|
// Not found the registered account
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception_runtime('Failed to find the registered account');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Not registered the account
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception_runtime('Failed to registrate the account');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registrate
|
||||||
|
*
|
||||||
|
* Creates the account record in the database
|
||||||
|
*
|
||||||
|
* @param telegram $telegram The telegram account
|
||||||
|
*
|
||||||
|
* @return int|false The record identifier, if created
|
||||||
|
*/
|
||||||
|
public function registrate(telegram $telegram): int|false
|
||||||
|
{
|
||||||
|
// Initializing the identifier
|
||||||
|
$identifier = $this->database->count() + 1;
|
||||||
|
|
||||||
|
// Initializing the record
|
||||||
|
$record = $this->database->record(
|
||||||
|
$identifier,
|
||||||
|
(int) $telegram->getId(),
|
||||||
|
(string) $telegram->getFirstName(),
|
||||||
|
(string) $telegram->getLastName(),
|
||||||
|
(string) $telegram->getUsername(),
|
||||||
|
(string) $telegram->getLanguageCode(),
|
||||||
|
(int) $telegram->isBot(),
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
svoboda::timestamp(),
|
||||||
|
svoboda::timestamp()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Creating the record in the database
|
||||||
|
$created = $this->database->write($record);
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return $created ? $identifier : false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,7 +20,6 @@ use exception;
|
|||||||
*
|
*
|
||||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
* @author kodorvan <mail@domain.zone>
|
|
||||||
*/
|
*/
|
||||||
class core extends model
|
class core extends model
|
||||||
{
|
{
|
||||||
34
kodorvan/brainrot/system/models/telegram/account.php
Normal file
34
kodorvan/brainrot/system/models/telegram/account.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\brainrot\models\telegram;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\brainrot\models\core,
|
||||||
|
kodorvan\brainrot\models\account as model;
|
||||||
|
|
||||||
|
// Library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// Baza database
|
||||||
|
use mirzaev\baza\record;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use Zanzara\Context as context,
|
||||||
|
Zanzara\Telegram\Type\Message as message;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use Error as error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Telegram account
|
||||||
|
*
|
||||||
|
* @package kodorvan\brainrot\models\telegram
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
final class account extends core
|
||||||
|
{
|
||||||
|
}
|
||||||
531
kodorvan/brainrot/system/models/telegram/commands.php
Normal file
531
kodorvan/brainrot/system/models/telegram/commands.php
Normal file
@@ -0,0 +1,531 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\brainrot\models\telegram;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\brainrot\models\core,
|
||||||
|
kodorvan\brainrot\models\account,
|
||||||
|
kodorvan\brainrot\models\distribution,
|
||||||
|
kodorvan\brainrot\models\member,
|
||||||
|
kodorvan\brainrot\models\telegram\processes\language\select as process_language_select;
|
||||||
|
|
||||||
|
// Library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// Baza database
|
||||||
|
use mirzaev\baza\record;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use Zanzara\Context as context,
|
||||||
|
Zanzara\Telegram\Type\Message as message,
|
||||||
|
Zanzara\Telegram\Type\Input\InputFile as file_input;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Telegram commands
|
||||||
|
*
|
||||||
|
* @package kodorvan\brainrot\models\telegram
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
final class commands extends core
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Menu
|
||||||
|
*
|
||||||
|
* Responce for the commands: "/start", '/menu'
|
||||||
|
*
|
||||||
|
* @param context $context Request data from Telegram
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function menu(context $context): void
|
||||||
|
{
|
||||||
|
// Initializing the account
|
||||||
|
$account = $context->get('account');
|
||||||
|
|
||||||
|
if ($account instanceof record) {
|
||||||
|
// Initialized the account
|
||||||
|
|
||||||
|
// Initializing localization
|
||||||
|
$localization = $context->get('localization');
|
||||||
|
|
||||||
|
if ($localization) {
|
||||||
|
// Initialized localization
|
||||||
|
|
||||||
|
// Initializing the title
|
||||||
|
$title = '📋 *' . $localization['menu_title'] . '*';
|
||||||
|
|
||||||
|
// Initializing accounts
|
||||||
|
$accounts = '*' . $localization['menu_accounts'] . ':* ' . ((new account)->database->count() ?? 0);
|
||||||
|
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage(
|
||||||
|
<<<TXT
|
||||||
|
$title
|
||||||
|
|
||||||
|
$accounts
|
||||||
|
TXT,
|
||||||
|
[
|
||||||
|
'reply_markup' => [
|
||||||
|
'inline_keyboard' => [
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'text' => '🐣 ' . $localization['kodorvan'],
|
||||||
|
'web_app' => [
|
||||||
|
'url' => 'https://brainrot.svoboda.works'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'disable_notification' => true,
|
||||||
|
'remove_keyboard' => true
|
||||||
|
],
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Sended the message
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Not initialized localization
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Not initialized the account
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Account
|
||||||
|
*
|
||||||
|
* Responce for the command: "/account"
|
||||||
|
*
|
||||||
|
* Sends information about account with menu
|
||||||
|
*
|
||||||
|
* @param context $context Request data from Telegram
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function account(context $context): void
|
||||||
|
{
|
||||||
|
// Initializing the account
|
||||||
|
$account = $context->get('account');
|
||||||
|
|
||||||
|
if ($account instanceof record) {
|
||||||
|
// Initialized the account
|
||||||
|
|
||||||
|
// Initializing localization
|
||||||
|
$localization = $context->get('localization');
|
||||||
|
|
||||||
|
if ($localization) {
|
||||||
|
// Initialized localization
|
||||||
|
|
||||||
|
// Initializing title for the message
|
||||||
|
$title = '🫵 ' . $localization['account_title'];
|
||||||
|
|
||||||
|
// Declaring buufer of rows about authorizations
|
||||||
|
$authorizations = '';
|
||||||
|
|
||||||
|
// Initializing rows about authorization
|
||||||
|
foreach ($account->values() as $key => $value) {
|
||||||
|
// Iterating over account parameters
|
||||||
|
|
||||||
|
if (str_starts_with($key, 'authorized_')) {
|
||||||
|
// Iterating over account authorizations
|
||||||
|
|
||||||
|
// Skipping system authorizations
|
||||||
|
if (str_starts_with($key, 'authorized_system_')) continue;
|
||||||
|
|
||||||
|
// Writing into buffer of rows about authorizations
|
||||||
|
$authorizations .= ($value ? '✅' : '❎') . ' *' . ($localization["account_$key"] ?? $key) . ':* ' . ($value ? $localization['yes'] : $localization['no']) . "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trimming the last line break character
|
||||||
|
$authorizations = trim($authorizations, "\n");
|
||||||
|
|
||||||
|
// Initializing the data export for the message
|
||||||
|
$export = '📤 ' . $localization['account_export'];
|
||||||
|
|
||||||
|
// Initializing the data security for the message
|
||||||
|
$data = $localization['account_data'];
|
||||||
|
|
||||||
|
// Initializing the data security repository for the message
|
||||||
|
$security = '📁 [' . $localization['account_security_repository'] . '](https://git.svoboda.works/mirzaev/security) \([' . $localization['account_security_repository_mirror_github'] . '](https://github.com/mature-woman/security)\)';
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage(
|
||||||
|
<<<TXT
|
||||||
|
$title
|
||||||
|
|
||||||
|
$authorizations
|
||||||
|
|
||||||
|
$export
|
||||||
|
|
||||||
|
$data
|
||||||
|
|
||||||
|
$security
|
||||||
|
TXT,
|
||||||
|
[
|
||||||
|
'reply_markup' => [
|
||||||
|
'remove_keyboard' => true,
|
||||||
|
'disable_notification' => true
|
||||||
|
],
|
||||||
|
'link_preview_options' => [
|
||||||
|
'is_disabled' => true
|
||||||
|
]
|
||||||
|
]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Not initialized localization
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Not initialized the account
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Language
|
||||||
|
*
|
||||||
|
* Responce for the command: "/language"
|
||||||
|
*
|
||||||
|
* Send the language selection menu
|
||||||
|
*
|
||||||
|
* @param context $context Request data from Telegram
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function language(context $context): void
|
||||||
|
{
|
||||||
|
// Initializing the account
|
||||||
|
$account = $context->get('account');
|
||||||
|
|
||||||
|
if ($account instanceof record) {
|
||||||
|
// Initialized the account
|
||||||
|
|
||||||
|
// Initializing language
|
||||||
|
$language = $context->get('language');
|
||||||
|
|
||||||
|
if ($language instanceof language) {
|
||||||
|
// Initialized language
|
||||||
|
|
||||||
|
// Initializing localization
|
||||||
|
$localization = $context->get('localization');
|
||||||
|
|
||||||
|
if ($localization) {
|
||||||
|
// Initialized localization
|
||||||
|
|
||||||
|
// Sending the language selection
|
||||||
|
process_language_select::menu(
|
||||||
|
context: $context,
|
||||||
|
prefix: 'settings_language_',
|
||||||
|
title: '🌏 *' . $localization['settings_select_language_title'] . '*',
|
||||||
|
description: '🌏 *' . $localization['settings_select_language_description'] . '*'
|
||||||
|
);
|
||||||
|
} 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 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 your Telegram account*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Sended the message
|
||||||
|
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository
|
||||||
|
*
|
||||||
|
* Responce for the command: "/repository"
|
||||||
|
*
|
||||||
|
* Sends information about project and menu
|
||||||
|
*
|
||||||
|
* @param context $context Request data from Telegram
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function repository(context $context): void
|
||||||
|
{
|
||||||
|
// Initializing the account
|
||||||
|
$account = $context->get('account');
|
||||||
|
|
||||||
|
if ($account instanceof record) {
|
||||||
|
// Initialized the account
|
||||||
|
|
||||||
|
// Initializing localization
|
||||||
|
$localization = $context->get('localization');
|
||||||
|
|
||||||
|
if ($localization) {
|
||||||
|
// Initialized localization
|
||||||
|
|
||||||
|
// Initializing title of the message
|
||||||
|
$title = '🏛️ ' . $localization['repository_title'];
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage($title . "\n\n" . $localization['repository_text'], [
|
||||||
|
'reply_markup' => [
|
||||||
|
'inline_keyboard' => [
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'text' => '🏛️ ' . $localization['repository_button_code'],
|
||||||
|
'url' => 'https://git.mirzaev.sexy/kodorvan/brainrot'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'text' => '⚠️ ' . $localization['repository_button_issues'],
|
||||||
|
'url' => 'https://git.mirzaev.sexy/kodorvan/brainrot/issues'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'text' => '🌱 ' . $localization['repository_button_suggestions'],
|
||||||
|
'url' => 'https://git.mirzaev.sexy/kodorvan/brainrot/issues'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'remove_keyboard' => true,
|
||||||
|
'disable_notification' => true
|
||||||
|
],
|
||||||
|
'link_preview_options' => [
|
||||||
|
'is_disabled' => true
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
// Not initialized localization
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Not initialized the account
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author
|
||||||
|
*
|
||||||
|
* Responce for the command: "/author"
|
||||||
|
*
|
||||||
|
* Sends
|
||||||
|
*
|
||||||
|
* @param context $context Request data from Telegram
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function author(context $context): void
|
||||||
|
{
|
||||||
|
// Initializing the account
|
||||||
|
$account = $context->get('account');
|
||||||
|
|
||||||
|
if ($account instanceof record) {
|
||||||
|
// Initialized the account
|
||||||
|
|
||||||
|
// Initializing localization
|
||||||
|
$localization = $context->get('localization');
|
||||||
|
|
||||||
|
if ($localization) {
|
||||||
|
// Initialized localization
|
||||||
|
|
||||||
|
// Initializing title of the message
|
||||||
|
$title = '👽 ' . $localization['author_title'];
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage($title . "\n\n" . $localization['author_text'], [
|
||||||
|
'reply_markup' => [
|
||||||
|
'inline_keyboard' => [
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'text' => '📚 ' . $localization['author_button_neurojournal'],
|
||||||
|
'url' => 'https://mirzaev.sexy'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'text' => '🤟 ' . $localization['author_button_projects'],
|
||||||
|
'url' => 'https://git.svoboda.works/mirzaev?tab=activity'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'text' => '📣 ' . $localization['author_button_telegram'],
|
||||||
|
'url' => 'https://t.me/blog_mirzaev_sexy'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'text' => '✖️ ' . $localization['author_button_twitter'],
|
||||||
|
'url' => 'https://x.com/mirzaev_sexy'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'text' => '🦋 ' . $localization['author_button_bluesky'],
|
||||||
|
'url' => 'https://bsky.app/profile/mirzaev.bsky.social'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'text' => '⛓️ ' . $localization['author_button_bastyon'],
|
||||||
|
'url' => 'https://bsky.app/profile/mirzaev.bsky.social'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'text' => '🇺🇸 ' . $localization['author_button_youtube_english'],
|
||||||
|
'url' => 'https://www.youtube.com/@MIRZAEV'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'text' => '🇷🇺 ' . $localization['author_button_youtube_russian'],
|
||||||
|
'url' => 'https://www.youtube.com/@MIRZAEV'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'text' => '✉️ ' . $localization['author_button_message'],
|
||||||
|
'url' => 'https://t.me/mirzaev_sexy'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'remove_keyboard' => true,
|
||||||
|
'disable_notification' => true
|
||||||
|
],
|
||||||
|
'link_preview_options' => [
|
||||||
|
'is_disabled' => true
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
// Not initialized localization
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Not initialized the account
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Society
|
||||||
|
*
|
||||||
|
* Responce for the command: "/society"
|
||||||
|
*
|
||||||
|
* Sends the "mushroom" image and the localized text "why so shroomious"
|
||||||
|
*
|
||||||
|
* @param context $context Request data from Telegram
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function society(context $context): void
|
||||||
|
{
|
||||||
|
// Initializing the account
|
||||||
|
$account = $context->get('account');
|
||||||
|
|
||||||
|
if ($account instanceof record) {
|
||||||
|
// Initialized the account
|
||||||
|
|
||||||
|
// Initializing localization
|
||||||
|
$localization = $context->get('localization');
|
||||||
|
|
||||||
|
if ($localization) {
|
||||||
|
// Initialized localization
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendPhoto(
|
||||||
|
new file_input(STORAGE . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'mushroom.jpg'),
|
||||||
|
[
|
||||||
|
'caption' => $localization['why_so_shroomious'],
|
||||||
|
'disable_notification' => true
|
||||||
|
]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Not initialized localization
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Not initialized the account
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
373
kodorvan/brainrot/system/models/telegram/middlewares.php
Normal file
373
kodorvan/brainrot/system/models/telegram/middlewares.php
Normal file
@@ -0,0 +1,373 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\brainrot\models\telegram;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\brainrot\models\core,
|
||||||
|
kodorvan\brainrot\models\account;
|
||||||
|
|
||||||
|
// Library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// Baza database
|
||||||
|
use mirzaev\baza\record;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use Zanzara\Context as context,
|
||||||
|
Zanzara\Telegram\Type\Message as message,
|
||||||
|
Zanzara\Middleware\MiddlewareNode as node;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use Error as error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Telegram middlewares
|
||||||
|
*
|
||||||
|
* @package kodorvan\brainrot\models\telegram
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
final class middlewares extends core
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 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 telegram account
|
||||||
|
$telegram = $context->getEffectiveUser();
|
||||||
|
|
||||||
|
// 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 your Telegram 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
|
||||||
|
|
||||||
|
if ($account->language) {
|
||||||
|
// Initialized the language parameter
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Writing the account language into the context variable
|
||||||
|
$context->set('language', language::{$account->language});
|
||||||
|
} catch (error $error) {
|
||||||
|
// Not initialized the language
|
||||||
|
|
||||||
|
// Writing the default language into the context variable
|
||||||
|
$context->set('language', language::en);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Not initialized the language parameter
|
||||||
|
|
||||||
|
// Writing the default language into the context variable
|
||||||
|
$context->set('language', language::en);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Continuation of the process
|
||||||
|
$next($context);
|
||||||
|
} else {
|
||||||
|
// Not initialized the account
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage('⚠️ *Failed to initialize your Telegram 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)) {
|
||||||
|
// Initialized 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 your Telegram account*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Sended the message
|
||||||
|
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Settings (middleware)
|
||||||
|
*
|
||||||
|
* Check the account for access to the 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 your Telegram account*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Sended the message
|
||||||
|
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* System settings (middleware)
|
||||||
|
*
|
||||||
|
* Check the account for access to the system 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 your Telegram account*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Sended the message
|
||||||
|
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\brainrot\models\telegram\processes\language;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\brainrot\models\core;
|
||||||
|
|
||||||
|
// Library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// Baza database
|
||||||
|
use mirzaev\baza\record;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use Zanzara\Context as context,
|
||||||
|
Zanzara\Telegram\Type\Message as message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Telegram language select
|
||||||
|
*
|
||||||
|
* @package kodorvan\brainrot\models\telegram\processes\language
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
final class select extends core
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Language
|
||||||
|
*
|
||||||
|
* Send the language choose menu
|
||||||
|
*
|
||||||
|
* @param context $context Request data from Telegram
|
||||||
|
* @param string $prefix Prefix for 'callback_data' (`$prefix . $language->name`)
|
||||||
|
* @param string $title Title of the message
|
||||||
|
* @param string $description Description of the message
|
||||||
|
* @param array $exclude Languages that will be excluded ['ru', 'en'...]
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function menu(context $context, string $prefix, string $title, string $description, array $exclude = []): void
|
||||||
|
{
|
||||||
|
// Initializing the account
|
||||||
|
$account = $context->get('account');
|
||||||
|
|
||||||
|
if ($account instanceof record) {
|
||||||
|
// Initialized the account
|
||||||
|
|
||||||
|
// Initializing language
|
||||||
|
$language = $context->get('language');
|
||||||
|
|
||||||
|
if ($language) {
|
||||||
|
// Initialized language
|
||||||
|
|
||||||
|
// Initializing localization
|
||||||
|
$localization = $context->get('localization');
|
||||||
|
|
||||||
|
if ($localization) {
|
||||||
|
// Initialized localization
|
||||||
|
|
||||||
|
// Declaring the buffer of generated keyboard with languages
|
||||||
|
$keyboard = [];
|
||||||
|
|
||||||
|
// Initializing the iterator of rows
|
||||||
|
$row = 0;
|
||||||
|
|
||||||
|
// Initializing buffer of languages
|
||||||
|
$languages = language::cases();
|
||||||
|
|
||||||
|
// Deleting the actual language from buffer of languages
|
||||||
|
unset($languages[array_search($language, $languages, strict: true)]);
|
||||||
|
|
||||||
|
// Sorting buffer of languages by the actual language
|
||||||
|
$languages = [$language, ...$languages];
|
||||||
|
|
||||||
|
foreach ($languages as $language) {
|
||||||
|
// Iterating over languages
|
||||||
|
|
||||||
|
// Skipping excluded languages
|
||||||
|
if (array_search($language->name, $exclude, strict: true) !== false) continue;
|
||||||
|
|
||||||
|
// Initializing the row
|
||||||
|
$keyboard[$row] ??= [];
|
||||||
|
|
||||||
|
// Writing the language choose button into the buffer of generated keyboard with languages
|
||||||
|
$keyboard[$row][] = [
|
||||||
|
'text' => ($language->flag() ? $language->flag() . ' ' : '') . $language->label($language),
|
||||||
|
'callback_data' => $prefix . $language->name
|
||||||
|
];
|
||||||
|
|
||||||
|
// When reaching 4 buttons in a row, move to the next row
|
||||||
|
if (count($keyboard[$row]) === 4) ++$row;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Writing the button for helping lozalizing
|
||||||
|
$keyboard[$row === 0 && empty($keyboard[0]) ? 0 : ++$row] = [
|
||||||
|
[
|
||||||
|
'text' => '🗂 ' . $localization['select_language_button_add'],
|
||||||
|
'url' => 'https://git.svoboda.works/kodorvan/brainrot/src/branch/stable/kodorvan/brainrot/system/localizations'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage(
|
||||||
|
$title ?? '🌏 *' . $localization['select_language_title'] . "*\n" . ($description ?? $localization['select_language_description']),
|
||||||
|
[
|
||||||
|
'reply_markup' => [
|
||||||
|
'inline_keyboard' => $keyboard,
|
||||||
|
'disable_notification' => 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 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 your Telegram account*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Sended the message
|
||||||
|
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
158
kodorvan/brainrot/system/models/telegram/settings.php
Normal file
158
kodorvan/brainrot/system/models/telegram/settings.php
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\brainrot\models\telegram;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\brainrot\models\core,
|
||||||
|
kodorvan\brainrot\models\account,
|
||||||
|
kodorvan\brainrot\models\telegram\middlewares;
|
||||||
|
|
||||||
|
// Library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// Baza database
|
||||||
|
use mirzaev\baza\record;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use Zanzara\Zanzara,
|
||||||
|
Zanzara\Context as context,
|
||||||
|
Zanzara\Telegram\Type\Message as message,
|
||||||
|
Zanzara\Middleware\MiddlewareNode as node;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use Error as error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Telegram settings
|
||||||
|
*
|
||||||
|
* @package kodorvan\brainrot\models\telegram
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
final class settings extends core
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Language
|
||||||
|
*
|
||||||
|
* Write language into the account record
|
||||||
|
*
|
||||||
|
* @param context $context Request data from Telegram
|
||||||
|
* @param language $language The language
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function language(context $context, language $language): void
|
||||||
|
{
|
||||||
|
// Initializing the account
|
||||||
|
$account = $context->get('account');
|
||||||
|
|
||||||
|
if ($account instanceof record) {
|
||||||
|
// Initialized the account
|
||||||
|
|
||||||
|
// Initializing localization
|
||||||
|
$localization = $context->get('localization');
|
||||||
|
|
||||||
|
if ($localization) {
|
||||||
|
// Initialized localization
|
||||||
|
|
||||||
|
// Initializing the account model
|
||||||
|
$model = new account();
|
||||||
|
|
||||||
|
// Updating the account in the database
|
||||||
|
$updated = $model->database->read(
|
||||||
|
filter: fn(record $record) => $record->identifier === $account->identifier,
|
||||||
|
update: function (record &$record) use ($language) {
|
||||||
|
// Writing new language value into the record
|
||||||
|
$record->language = $language->name;
|
||||||
|
},
|
||||||
|
amount: 1
|
||||||
|
)[0] ?? null;
|
||||||
|
|
||||||
|
if ($updated instanceof record) {
|
||||||
|
// Updated the account in the database
|
||||||
|
|
||||||
|
// Writing the updated account into the context variable
|
||||||
|
$context->set('account', $updated);
|
||||||
|
|
||||||
|
middlewares::language($context, new node(function (context $context) use ($account, $updated) {
|
||||||
|
// Updated language
|
||||||
|
|
||||||
|
middlewares::localization($context, new node(function (context $context) use ($account, $updated) {
|
||||||
|
// Updated localization
|
||||||
|
|
||||||
|
// Initializing localization
|
||||||
|
$localization = $context->get('localization');
|
||||||
|
|
||||||
|
if ($localization) {
|
||||||
|
// Initialized localization
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Initializing the old language
|
||||||
|
$old = language::{$account->language};
|
||||||
|
|
||||||
|
// Initializing the new language
|
||||||
|
$new = language::{$updated->language};
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage('✅ *' . $localization['settings_language_update_success'] . '* ' . ($old->flag() ? $old->flag() . ' ' : '') . $old->label($new) . ' → *' . ($new->flag() ? $new->flag() . ' ' : '') . $new->label($new) . '*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
} catch (error $error) {
|
||||||
|
// Failed to send the message about language update
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage('❎ *' . $localization['settings_language_update_fail'])
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Not initialized localization
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
// Not updated the account in the database
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage('❎ *' . $localization['settings_language_update_fail'])
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Not initialized localization
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Not initialized the account
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||||
|
->then(function (message $message) use ($context) {
|
||||||
|
// Ending the conversation process
|
||||||
|
$context->endConversation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,6 @@ use exception;
|
|||||||
*
|
*
|
||||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
* @author kodorvan <mail@domain.zone>
|
|
||||||
*/
|
*/
|
||||||
trait files
|
trait files
|
||||||
{
|
{
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user