generated from mirzaev/pot-php-telegram
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4757a81d95 | |||
| 4fdcae74be | |||
| 4839f950e5 | |||
| 3fa8e067a1 | |||
| 74d2eaa62b | |||
| 0692db9c80 | |||
| ebba2a970e | |||
| 8d83ab152f | |||
| e7ccc3616b | |||
| 8e8962d22d | |||
| a1b5b463c2 |
@@ -24,7 +24,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": "^8.5",
|
"php": "^8.5",
|
||||||
"mirzaev/minimal": "^3.7",
|
"mirzaev/minimal": "^3.7",
|
||||||
"mirzaev/baza": "^3.3",
|
"mirzaev/baza": "^3.4",
|
||||||
"mirzaev/record": "^1.0",
|
"mirzaev/record": "^1.0",
|
||||||
"mirzaev/languages": "^1.0",
|
"mirzaev/languages": "^1.0",
|
||||||
"mirzaev/currencies": "^2.0",
|
"mirzaev/currencies": "^2.0",
|
||||||
@@ -35,7 +35,11 @@
|
|||||||
"twig/extra-bundle": "^3.7",
|
"twig/extra-bundle": "^3.7",
|
||||||
"twig/intl-extra": "^3.10",
|
"twig/intl-extra": "^3.10",
|
||||||
"react/filesystem": "^0.1.2",
|
"react/filesystem": "^0.1.2",
|
||||||
"nyholm/psr7": "^1.8"
|
"nyholm/psr7": "^1.8",
|
||||||
|
"irazasyed/telegram-bot-sdk": "^3.15",
|
||||||
|
"nutgram/nutgram": "^4.42",
|
||||||
|
"psr/simple-cache": "^3.0",
|
||||||
|
"symfony/cache": "^8.0"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"mirzaev/files": "Easy working with files",
|
"mirzaev/files": "Easy working with files",
|
||||||
|
|||||||
2003
composer.lock
generated
2003
composer.lock
generated
File diff suppressed because it is too large
Load Diff
75
kodorvan/constructor/system/databases/scripts/workers.php
Normal file
75
kodorvan/constructor/system/databases/scripts/workers.php
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\account,
|
||||||
|
kodorvan\constructor\models\authorizations,
|
||||||
|
kodorvan\constructor\models\worker,
|
||||||
|
kodorvan\constructor\models\tariff;
|
||||||
|
|
||||||
|
// The library for currencies support
|
||||||
|
use mirzaev\currencies\currency;
|
||||||
|
|
||||||
|
// Svoboda time
|
||||||
|
use svoboda\time\statement as svoboda;
|
||||||
|
|
||||||
|
// Baza database
|
||||||
|
use mirzaev\baza\record;
|
||||||
|
|
||||||
|
// Enabling debugging
|
||||||
|
/* 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__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'public');
|
||||||
|
|
||||||
|
// Initializing path to the root directory
|
||||||
|
define('ROOT', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
|
||||||
|
|
||||||
|
// Initializing path to the settings directory
|
||||||
|
define('SETTINGS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'settings');
|
||||||
|
|
||||||
|
// Initializing path to the storage directory
|
||||||
|
define('STORAGE', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'storage');
|
||||||
|
|
||||||
|
// Initializing path to the databases directory
|
||||||
|
define('DATABASES', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'databases');
|
||||||
|
|
||||||
|
// Initializing path to the localizations directory
|
||||||
|
define('LOCALIZATIONS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'localizations');
|
||||||
|
|
||||||
|
// Initiailizing telegram data
|
||||||
|
require(SETTINGS . DIRECTORY_SEPARATOR . 'telegram.php');
|
||||||
|
|
||||||
|
// Initializing dependencies
|
||||||
|
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||||
|
|
||||||
|
// Initializing the account model
|
||||||
|
$account_model = new account();
|
||||||
|
|
||||||
|
// Searching for the account
|
||||||
|
$account = $account_model->read(
|
||||||
|
filter: fn(record $record) => $record->domain === 'buddy_volkodav',
|
||||||
|
);
|
||||||
|
|
||||||
|
var_dump($account);
|
||||||
|
|
||||||
|
// Searching for the account authorizations
|
||||||
|
$authorizations = $account->authorizations();
|
||||||
|
|
||||||
|
var_dump($authorizations);
|
||||||
|
|
||||||
|
// Creating the worker
|
||||||
|
$worker = new worker()->write(
|
||||||
|
account: $account->identifier,
|
||||||
|
hour: 2000,
|
||||||
|
currency: currency::rub,
|
||||||
|
active: true
|
||||||
|
);
|
||||||
|
|
||||||
|
var_dump($worker);
|
||||||
|
|
||||||
@@ -9,6 +9,7 @@ return [
|
|||||||
|
|
||||||
// Main menu
|
// Main menu
|
||||||
'menu_title' => 'Main menu',
|
'menu_title' => 'Main menu',
|
||||||
|
'menu_update' => 'Last update',
|
||||||
|
|
||||||
// Account
|
// Account
|
||||||
'account_title' => 'Account',
|
'account_title' => 'Account',
|
||||||
@@ -16,18 +17,16 @@ return [
|
|||||||
'account_authorized_settings' => 'Access to settings',
|
'account_authorized_settings' => 'Access to settings',
|
||||||
'account_authorized_system_settings' => 'System access to the system settings',
|
'account_authorized_system_settings' => 'System access to the system settings',
|
||||||
|
|
||||||
// Language setting
|
// Settings: language
|
||||||
'settings_select_language_title' => 'Select language',
|
'settings_language_title' => 'Select language',
|
||||||
'settings_select_language_description' => 'The selected language will be writed in your account settings',
|
'settings_language_description' => 'The selected language will be used in the system interface generation',
|
||||||
'settings_language_update_success' => 'Language replaced:',
|
'settings_language_update_success' => 'Language replaced',
|
||||||
'settings_language_update_fail' => 'Failed to replace language',
|
'settings_language_update_fail' => 'Failed to replace language',
|
||||||
|
'settings_language_button_add' => 'Add a 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',
|
|
||||||
|
|
||||||
// Authorization
|
// Authorization
|
||||||
|
'authorization_system' => 'System',
|
||||||
|
'authorization_settings' => 'Settings',
|
||||||
'not_authorized_system' => 'You do not have access to the system',
|
'not_authorized_system' => 'You do not have access to the system',
|
||||||
'not_authorized_settings' => 'You do not have access to the settings',
|
'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_settings' => 'You do not have access to the system settings',
|
||||||
|
|||||||
@@ -9,9 +9,8 @@ return [
|
|||||||
|
|
||||||
// Главное меню
|
// Главное меню
|
||||||
'menu_title' => 'Главное меню',
|
'menu_title' => 'Главное меню',
|
||||||
'menu_description_guest' => "*Создайте ваш первый проект* и получите *ориентировочную стоимость* всего за 2 минуты\n\nПосле расчёта *сформируйте заявку* к проджект\-менеджеру для более глубокого анализа и составлении ТЗ\n\nПри желании этот этап можно пропустить сразу *связавшись с оператором* _\(график работы указан в его профиле\)_",
|
'menu_description_guest' => "🔥 *Создайте ваш первый проект* и получите *ориентировочную стоимость* всего за 2 минуты",
|
||||||
'menu_description_partner' => "Надеемся, что наше сотрудничество оставляет сугубо *положительные эмоции* и способствует *развитию обоих сторон*\n\n*Благодарим за выбор нашей команды*",
|
'menu_description_partner' => "*Благодарю за выбор нашей команды*\. Теперь Вы один из наших %d партнёров!",
|
||||||
'menu_experiment' => "Чат\-робот находится в *экспериментальном* режиме\n_Просьба сообщать при обнаружении любых проблем, спасибо_",
|
|
||||||
'menu_update' => 'Последнее обновление',
|
'menu_update' => 'Последнее обновление',
|
||||||
'menu_button_project_new' => 'Создать',
|
'menu_button_project_new' => 'Создать',
|
||||||
'menu_button_projects' => 'Проекты',
|
'menu_button_projects' => 'Проекты',
|
||||||
@@ -23,18 +22,110 @@ return [
|
|||||||
'account_authorized_settings' => 'Доступ к изменению настроек',
|
'account_authorized_settings' => 'Доступ к изменению настроек',
|
||||||
'account_authorized_system_settings' => 'Системный доступ к системным настройкам',
|
'account_authorized_system_settings' => 'Системный доступ к системным настройкам',
|
||||||
|
|
||||||
// Настройки языка
|
// Проект: создание
|
||||||
'settings_select_language_title' => 'Выбери язык',
|
'project_create_title' => 'Создание проекта',
|
||||||
'settings_select_language_description' => 'Выбранный язык будет записан в настройки аккаунта',
|
/* 'project_create_description' => "Расчитайте ориентировочное время разработки, затем выберите разработчиков и получите стоимость\n\nПосле расчётов можно будет отправить проект в заказ разработчикам и приложить ТЗ, либо краткое описание задачи\n\nМы погружаемся в проекты полностью, поэтому стараемся не распыляться - от степени нагрузки меняется коэффициент стоимости!", */
|
||||||
'settings_language_update_success' => 'Язык заменён:',
|
'project_create_description' => "Установите параметры и получите ориентировочное время разработки\n\n_После расчётов можно отправить проект в заказ приложив ТЗ, либо описание задачи_",
|
||||||
'settings_language_update_fail' => 'Не удалось заменить язык',
|
'project_create_warning_cost' => "Стоимость и сроки выполнения предоставлены для планирования и *не являются публичной офертой*",
|
||||||
|
'project_create_team_warning' => "",
|
||||||
|
'project_create_time' => 'Время',
|
||||||
|
'project_create_time_hours' => 'ч',
|
||||||
|
'project_create_time_hours_from' => 'от',
|
||||||
|
'project_create_time_days' => 'дн',
|
||||||
|
'project_create_cost' => 'Стоимость',
|
||||||
|
'project_create_cost_prepayment' => 'Предоплата',
|
||||||
|
'project_create_team_title' => 'Сбор команды',
|
||||||
|
'project_create_team_description' => '_Вы можете *убрать* или *добавить* специалистов, создавая максимально удобное сотрудничество под вашу систему_',
|
||||||
|
'project_create_team_warning_cost' => '_*Не влияет на время разработки*_',
|
||||||
|
'project_create_team_button_programmers' => 'Программисты: %d%s',
|
||||||
|
'project_create_team_button_designers' => 'Дизайнеры: %d%s',
|
||||||
|
'project_create_team_button_boosters' => 'Бустеры: %d%s',
|
||||||
|
'project_create_cost_title' => 'Стоимость разработки',
|
||||||
|
'project_create_cost_description' => 'Введите предложение по *оплате за 1 час* разработки',
|
||||||
|
'project_create_cost_default' => '*`%d%s`* \- средняя стоимость с учётом *компетенции*, совокупного опыта, *уникальных* разработок\. Цена уже включает\: *наши сервера*, документирование кода, *передачу кода*, ведение репозитория, *техподдержку* и репутационные гарантии',
|
||||||
|
'project_create_cost_warning' => '_Если цена окажется *недостаточной*, мы выставим *справедливое* и *конкурентное* встречное предложение_',
|
||||||
|
'project_create_cost_error_distance' => 'Длина сообщения должна быть от %d и до %d символов',
|
||||||
|
'project_create_cost_error_not_a_number' => 'Значение должно быть числом',
|
||||||
|
'project_create_button_back' => 'Назад',
|
||||||
|
'project_create_button_cost_per_hour' => 'Час',
|
||||||
|
'project_create_button_request' => 'Заказать',
|
||||||
|
|
||||||
// Выбор языка
|
'project_create_architectures_title' => 'Выбор архитектуры проекта',
|
||||||
'select_language_title' => 'Выбери язык',
|
'project_create_architectures_description' => 'Каждая архитектура имеет уникальные параметры и коэффициенты \- это основа дальнейших расчётов\!',
|
||||||
'select_language_description' => 'Выбранный язык будет использован в текущем процессе',
|
'project_create_button_architecture' => 'Архитектура',
|
||||||
'select_language_button_add' => 'Добавить язык',
|
'project_create_button_architecture_selected' => 'Архитектура',
|
||||||
|
|
||||||
|
'project_create_purposes_title' => 'Выбор назначения',
|
||||||
|
'project_create_purposes_description' => 'Вектор разработки, основание проекта',
|
||||||
|
'project_create_button_purpose' => 'Назначение',
|
||||||
|
'project_create_button_purpose_selected' => 'Назнач.',
|
||||||
|
|
||||||
|
'project_create_integrations_title' => 'Выбор интеграций',
|
||||||
|
'project_create_integrations_description' => "Синхронизация заказов, товаров, публикаций и прочего в реальном времени, скачивание, загрузка, админ\-панель, рассылка сообщений, подключение аккаунтов\.\.\.\n\n_Отправка запросов в *API*, генерация и перехват *HTTP\-сообщений*, *эмуляция действий пользователя*_",
|
||||||
|
'project_create_button_integrations' => 'Интеграции',
|
||||||
|
'project_create_button_integrations_selected' => 'Интеграции',
|
||||||
|
'project_create_button_team' => 'Команда: %d%s',
|
||||||
|
'project_create_peoples' => '',
|
||||||
|
'project_create_requested' => 'Проект создан и отправлен оператору',
|
||||||
|
'project_create_cancelled' => 'Создание проекта отменено',
|
||||||
|
|
||||||
|
'project_request_title' => 'Заказ #%d',
|
||||||
|
'project_request_architecture' => 'Архитектура',
|
||||||
|
'project_request_purpose' => 'Назначение',
|
||||||
|
'project_request_hours' => 'Часы',
|
||||||
|
'project_request_cost' => 'Стоимость',
|
||||||
|
'project_request_team' => 'Команда',
|
||||||
|
'project_request_empty' => 'Пусто',
|
||||||
|
'project_request_button_accept' => 'Принять',
|
||||||
|
'project_request_button_refuse' => 'Отказать',
|
||||||
|
'project_request_button_edit' => 'Редактировать',
|
||||||
|
'project_request_button_chat' => 'Чат с заказчиком',
|
||||||
|
|
||||||
|
// Проект: типы
|
||||||
|
'project_architecture_chat_robot' => 'Чат-робот',
|
||||||
|
'project_architecture_parser' => 'Парсер',
|
||||||
|
'project_architecture_calculator' => 'Калькулятор',
|
||||||
|
'project_architecture_crm' => 'CRM',
|
||||||
|
'project_architecture_site' => 'Сайт',
|
||||||
|
'project_architecture_program' => 'Программа',
|
||||||
|
'project_architecture_complex' => 'Нестандартная',
|
||||||
|
|
||||||
|
// Проект: назначение
|
||||||
|
'project_purpose_funnel' => 'Воронка',
|
||||||
|
'project_purpose_contact' => 'Контакты',
|
||||||
|
'project_purpose_neural_network' => 'Нейросеть',
|
||||||
|
'project_purpose_gallery' => 'Галерея',
|
||||||
|
'project_purpose_crm' => 'CRM',
|
||||||
|
'project_purpose_landing' => 'Лендинг',
|
||||||
|
'project_purpose_marketplace' => 'Маркетплейс',
|
||||||
|
'project_purpose_charity' => 'Благотворительность',
|
||||||
|
'project_purpose_search' => 'Поиск',
|
||||||
|
'project_purpose_calcul+ate' => 'Расчёт',
|
||||||
|
'project_purpose_tools' => 'Инструменты',
|
||||||
|
'project_purpose_workers' => 'Рабочие',
|
||||||
|
'project_purpose_objects' => 'Предметы',
|
||||||
|
'project_purpose_events' => 'События',
|
||||||
|
'project_purpose_special' => 'Особенное',
|
||||||
|
|
||||||
|
// Проект: интеграции
|
||||||
|
'project_integration_one_c' => '1C',
|
||||||
|
'project_integration_bitrix24' => 'Битрикс 24',
|
||||||
|
'project_integration_moy_sklad' => 'Мой Склад',
|
||||||
|
'project_integration_telegram' => 'Телеграм',
|
||||||
|
'project_integration_mail' => 'Почта',
|
||||||
|
'project_integration_excel' => 'Excel',
|
||||||
|
/* 'project_integration_' => '', */
|
||||||
|
|
||||||
|
// Настройки: язык
|
||||||
|
'settings_language_title' => 'Выбери язык',
|
||||||
|
'settings_language_description' => 'Выбранный язык будет использоваться для генерации системного отображения',
|
||||||
|
'settings_language_update_success' => 'Язык заменён',
|
||||||
|
'settings_language_update_fail' => 'Не удалось заменить язык',
|
||||||
|
'settings_language_button_add' => 'Добавить язык',
|
||||||
|
|
||||||
// Авторизация
|
// Авторизация
|
||||||
|
'authorization_system' => 'Система',
|
||||||
|
'authorization_settings' => 'Настройки',
|
||||||
'not_authorized_system' => 'У тебя нет доступа к системе',
|
'not_authorized_system' => 'У тебя нет доступа к системе',
|
||||||
'not_authorized_settings' => 'У тебя нет доступа к настройкам',
|
'not_authorized_settings' => 'У тебя нет доступа к настройкам',
|
||||||
'not_authorized_system_settings' => 'У тебя нет доступа к системным настройкам',
|
'not_authorized_system_settings' => 'У тебя нет доступа к системным настройкам',
|
||||||
|
|||||||
@@ -8,11 +8,17 @@ namespace kodorvan\constructor\models;
|
|||||||
use kodorvan\constructor\models\core,
|
use kodorvan\constructor\models\core,
|
||||||
kodorvan\constructor\models\authorizations,
|
kodorvan\constructor\models\authorizations,
|
||||||
kodorvan\constructor\models\settings,
|
kodorvan\constructor\models\settings,
|
||||||
kodorvan\constructor\models\projects;
|
kodorvan\constructor\models\worker,
|
||||||
|
kodorvan\constructor\models\project,
|
||||||
|
kodorvan\constructor\models\project\enumerations\type as project_type,
|
||||||
|
kodorvan\constructor\models\project\enumerations\status as project_status;
|
||||||
|
|
||||||
// The library for languages support
|
// The library for languages support
|
||||||
use mirzaev\languages\language;
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// The library for currencies support
|
||||||
|
use mirzaev\currencies\currency;
|
||||||
|
|
||||||
// Baza database
|
// Baza database
|
||||||
use mirzaev\baza\database,
|
use mirzaev\baza\database,
|
||||||
mirzaev\baza\column,
|
mirzaev\baza\column,
|
||||||
@@ -28,7 +34,7 @@ use mirzaev\record\interfaces\record as record_interface,
|
|||||||
use svoboda\time\statement as svoboda;
|
use svoboda\time\statement as svoboda;
|
||||||
|
|
||||||
// Framework for Telegram
|
// Framework for Telegram
|
||||||
use Zanzara\Telegram\Type\User as telegram_user;
|
use SergiX44\Nutgram\Telegram\Types\User\User as telegram_user;
|
||||||
|
|
||||||
// Built-in libraries
|
// Built-in libraries
|
||||||
use Exception as exception,
|
use Exception as exception,
|
||||||
@@ -49,7 +55,7 @@ final class account extends core implements record_interface
|
|||||||
/**
|
/**
|
||||||
* File
|
* File
|
||||||
*
|
*
|
||||||
* @var string $database Path to the database file
|
* @var string $file Path to the database file
|
||||||
*/
|
*/
|
||||||
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'accounts.baza';
|
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'accounts.baza';
|
||||||
|
|
||||||
@@ -60,6 +66,13 @@ final class account extends core implements record_interface
|
|||||||
*/
|
*/
|
||||||
public protected(set) database $database;
|
public protected(set) database $database;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialized
|
||||||
|
*
|
||||||
|
* @var bool $serialized Is the implementator object serialized?
|
||||||
|
*/
|
||||||
|
private bool $serialized = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@@ -79,6 +92,7 @@ final class account extends core implements record_interface
|
|||||||
new column('name_first', type::string, ['length' => 64]),
|
new column('name_first', type::string, ['length' => 64]),
|
||||||
new column('name_second', type::string, ['length' => 64]),
|
new column('name_second', type::string, ['length' => 64]),
|
||||||
new column('language', type::string, ['length' => 2]),
|
new column('language', type::string, ['length' => 2]),
|
||||||
|
new column('currency', type::string, ['length' => 3]),
|
||||||
new column('robot', type::char),
|
new column('robot', type::char),
|
||||||
/* new column('', type::), */
|
/* new column('', type::), */
|
||||||
new column('active', type::char),
|
new column('active', type::char),
|
||||||
@@ -105,26 +119,26 @@ final class account extends core implements record_interface
|
|||||||
public function initialize(telegram_user $telegram): ?static
|
public function initialize(telegram_user $telegram): ?static
|
||||||
{
|
{
|
||||||
// Searching for the account in the database
|
// Searching for the account in the database
|
||||||
$account = $this->database->read(filter: fn(record $record) => $record->identifier_telegram === $telegram->getId(), amount: 1)[0] ?? null;
|
$account = $this->database->read(filter: fn(record $record) => $record->identifier_telegram === $telegram->id, amount: 1)[0] ?? null;
|
||||||
|
|
||||||
if ($account instanceof record) {
|
if ($account instanceof record) {
|
||||||
// Found the account record
|
// Found the account record
|
||||||
|
|
||||||
if (
|
if (
|
||||||
$account->domain !== (string) $telegram->getUsername() ||
|
$account->domain !== (string) $telegram->username ||
|
||||||
$account->name_first !== (string) $telegram->getFirstName() ||
|
$account->name_first !== (string) $telegram->first_name ||
|
||||||
$account->name_second !== (string) $telegram->getLastName()
|
$account->name_second !== (string) $telegram->last_name
|
||||||
) {
|
) {
|
||||||
// The telegram account was updated
|
// The telegram account was updated
|
||||||
|
|
||||||
// Updating the account in the database
|
// Updating the account in the database
|
||||||
$updated = $this->database->read(
|
$updated = $this->database->read(
|
||||||
filter: fn(record $record) => $record->identifier_telegram === $telegram->getId(),
|
filter: fn(record $record) => $record->identifier_telegram === $telegram->id,
|
||||||
update: function (record &$record) use ($telegram) {
|
update: function (record &$record) use ($telegram) {
|
||||||
// Writing new values into the record
|
// Writing new values into the record
|
||||||
$record->domain = (string) $telegram->getUsername();
|
$record->domain = (string) $telegram->username;
|
||||||
$record->name_first = (string) $telegram->getFirstName();
|
$record->name_first = (string) $telegram->first_name;
|
||||||
$record->name_second = (string) $telegram->getLastName();
|
$record->name_second = (string) $telegram->last_name;
|
||||||
$record->updated = svoboda::timestamp();
|
$record->updated = svoboda::timestamp();
|
||||||
},
|
},
|
||||||
amount: 1
|
amount: 1
|
||||||
@@ -164,7 +178,7 @@ final class account extends core implements record_interface
|
|||||||
// Registered the account
|
// Registered the account
|
||||||
|
|
||||||
// Searching for the registered account in the database
|
// Searching for the registered account in the database
|
||||||
$registered = $this->database->read(filter: fn(record $record) => $record->identifier_telegram === $telegram->getId(), amount: 1)[0] ?? null;
|
$registered = $this->database->read(filter: fn(record $record) => $record->identifier_telegram === $telegram->id, amount: 1)[0] ?? null;
|
||||||
|
|
||||||
if ($registered instanceof record) {
|
if ($registered instanceof record) {
|
||||||
// Found the registered account
|
// Found the registered account
|
||||||
@@ -205,12 +219,13 @@ final class account extends core implements record_interface
|
|||||||
{
|
{
|
||||||
// Creating the record
|
// Creating the record
|
||||||
$record = $this->write(
|
$record = $this->write(
|
||||||
telegram_identifier: (int) $telegram->getId(),
|
telegram_identifier: (int) $telegram->id,
|
||||||
name_first: (string) $telegram->getFirstName(),
|
name_first: (string) $telegram->first_name,
|
||||||
name_second: (string) $telegram->getLastName(),
|
name_second: (string) $telegram->last_name,
|
||||||
domain: (string) $telegram->getUsername(),
|
domain: (string) $telegram->username,
|
||||||
language: (string) $telegram->getLanguageCode(),
|
language: (string) $telegram->language_code,
|
||||||
robot: (bool) $telegram->isBot()
|
currency: CURRENCY_DEFAULT,
|
||||||
|
robot: (bool) $telegram->is_bot
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($record instanceof record) {
|
if ($record instanceof record) {
|
||||||
@@ -229,11 +244,11 @@ final class account extends core implements record_interface
|
|||||||
$settings->write(account: $record->identifier);
|
$settings->write(account: $record->identifier);
|
||||||
|
|
||||||
// Writing the record into the database
|
// Writing the record into the database
|
||||||
$record = $this->database->read(
|
/* $record = $this->database->read(
|
||||||
filter: fn(record $_record) => $_record->identifier === $record->identifier,
|
filter: fn(record $_record) => $_record->identifier === $record->identifier,
|
||||||
update: fn(record &$_record) => $_record = $record,
|
update: fn(record &$_record) => $_record = $record,
|
||||||
amount: 1
|
amount: 1
|
||||||
)[0] ?? null;
|
)[0] ?? null; */
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $record;
|
return $record;
|
||||||
@@ -251,6 +266,7 @@ final class account extends core implements record_interface
|
|||||||
* @param string $name_second
|
* @param string $name_second
|
||||||
* @param string $domain
|
* @param string $domain
|
||||||
* @param language|string $language
|
* @param language|string $language
|
||||||
|
* @param currency|string $currency
|
||||||
* @param bool $robot Is a robot?
|
* @param bool $robot Is a robot?
|
||||||
* @param bool $active Is the record active?
|
* @param bool $active Is the record active?
|
||||||
*
|
*
|
||||||
@@ -262,6 +278,7 @@ final class account extends core implements record_interface
|
|||||||
string $name_first = '',
|
string $name_first = '',
|
||||||
string $name_second = '',
|
string $name_second = '',
|
||||||
language|string $language = LANGUAGE_DEFAULT ?? language::en,
|
language|string $language = LANGUAGE_DEFAULT ?? language::en,
|
||||||
|
currency|string $currency = CURRENCY_DEFAULT ?? currency::usd,
|
||||||
bool $robot = false,
|
bool $robot = false,
|
||||||
bool $active = true,
|
bool $active = true,
|
||||||
): record|false {
|
): record|false {
|
||||||
@@ -273,6 +290,7 @@ final class account extends core implements record_interface
|
|||||||
$name_first,
|
$name_first,
|
||||||
$name_second,
|
$name_second,
|
||||||
$language instanceof language ? $language->name : (string) $language,
|
$language instanceof language ? $language->name : (string) $language,
|
||||||
|
$currency instanceof currency ? $currency->name : (string) $currency,
|
||||||
(int) $robot,
|
(int) $robot,
|
||||||
/* */
|
/* */
|
||||||
(int) $active,
|
(int) $active,
|
||||||
@@ -294,11 +312,22 @@ final class account extends core implements record_interface
|
|||||||
*/
|
*/
|
||||||
public function serialize(): self
|
public function serialize(): self
|
||||||
{
|
{
|
||||||
|
if ($this->serialized) {
|
||||||
|
// The record implementor is serialized
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception_runtime('The record implementor is already serialized');
|
||||||
|
}
|
||||||
|
|
||||||
// Serializing the record parameters
|
// Serializing the record parameters
|
||||||
$this->record->language = $this->record->language->name;
|
$this->record->language = $this->record->language->name;
|
||||||
|
$this->record->currency = $this->record->currency->name;
|
||||||
$this->record->robot = (int) $this->record->robot;
|
$this->record->robot = (int) $this->record->robot;
|
||||||
$this->record->active = (int) $this->record->active;
|
$this->record->active = (int) $this->record->active;
|
||||||
|
|
||||||
|
// Writing the status of serializing
|
||||||
|
$this->serialized = true;
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -310,11 +339,22 @@ final class account extends core implements record_interface
|
|||||||
*/
|
*/
|
||||||
public function deserialize(): self
|
public function deserialize(): self
|
||||||
{
|
{
|
||||||
|
if (!$this->serialized) {
|
||||||
|
// The record implementor is deserialized
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception_runtime('The record implementor is already deserialized');
|
||||||
|
}
|
||||||
|
|
||||||
// Deserializing the record parameters
|
// Deserializing the record parameters
|
||||||
$this->record->language = language::{$this->record->language} ?? LANGUAGE_DEFAULT ?? language::en;
|
$this->record->language = language::{$this->record->language} ?? LANGUAGE_DEFAULT ?? language::en;
|
||||||
|
$this->record->currency = currency::{$this->record->currency} ?? CURRENCY_DEFAULT ?? currency::usd;
|
||||||
$this->record->robot = (bool) $this->record->robot;
|
$this->record->robot = (bool) $this->record->robot;
|
||||||
$this->record->active = (bool) $this->record->active;
|
$this->record->active = (bool) $this->record->active;
|
||||||
|
|
||||||
|
// Writing the status of serializing
|
||||||
|
$this->serialized = false;
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -342,6 +382,29 @@ final class account extends core implements record_interface
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Worker
|
||||||
|
*
|
||||||
|
* Search for the account worker
|
||||||
|
*
|
||||||
|
* @return worker|null The account worker
|
||||||
|
*/
|
||||||
|
public function worker(): ?worker
|
||||||
|
{
|
||||||
|
// Search for the account worker
|
||||||
|
$worker = new worker()->read(filter: fn(record $record) => $record->active === 1 && $record->account === $this->identifier);
|
||||||
|
|
||||||
|
if ($worker instanceof worker) {
|
||||||
|
// Found the account worker
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return $worker;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Settings
|
* Settings
|
||||||
*
|
*
|
||||||
@@ -370,16 +433,79 @@ final class account extends core implements record_interface
|
|||||||
*
|
*
|
||||||
* Search for the account projects
|
* Search for the account projects
|
||||||
*
|
*
|
||||||
|
* @param project_type|null $type Type of the project
|
||||||
|
* @param project_status|null $status Status of the project
|
||||||
* @param int $amount Maximum amount
|
* @param int $amount Maximum amount
|
||||||
*
|
*
|
||||||
* @return array The account projects
|
* @return array The account projects
|
||||||
*/
|
*/
|
||||||
public function projects(int $amount = 20): array
|
public function projects(
|
||||||
{
|
?project_type $type = null,
|
||||||
|
?project_status $status = null,
|
||||||
|
int $amount = 20
|
||||||
|
): array {
|
||||||
// Search for the account projects
|
// Search for the account projects
|
||||||
$projects = new project()->database->read(filter: fn(record $record) => $record->active === 1 && $record->account === $this->identifier, amount: $amount);
|
$projects = new project()->database->read(
|
||||||
|
filter: fn(record $record) =>
|
||||||
|
$record->active === 1
|
||||||
|
&& $record->account === $this->identifier
|
||||||
|
&& ($type === null || $record->type === $type->name)
|
||||||
|
&& ($status === null || $record->status === $status->name),
|
||||||
|
amount: $amount
|
||||||
|
);
|
||||||
|
|
||||||
// Exit (success/fail)
|
// Exit (success/fail)
|
||||||
return $projects;
|
return $projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Partners
|
||||||
|
*
|
||||||
|
* Search for accounts that have at least one project in development
|
||||||
|
*
|
||||||
|
* @param int $amount Maximum amount
|
||||||
|
*
|
||||||
|
* @return array Partners accounts without duplicates
|
||||||
|
*/
|
||||||
|
public static function partners(int $amount = PHP_INT_MAX): array
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// Search for projects
|
||||||
|
$projects = new project()->database->read(
|
||||||
|
filter: fn(record $record) =>
|
||||||
|
$record->active === 1
|
||||||
|
&& match (project_status::{$record->status}) {
|
||||||
|
project_status::developing, project_status::developed, project_status::launched => true,
|
||||||
|
default => false
|
||||||
|
},
|
||||||
|
amount: $amount
|
||||||
|
);
|
||||||
|
|
||||||
|
// Declaring the registry of partners accounts
|
||||||
|
$partners = [];
|
||||||
|
|
||||||
|
foreach ($projects as $project) {
|
||||||
|
// Iterating over projects
|
||||||
|
|
||||||
|
if (isset($partners[$project->account])) {
|
||||||
|
// The partner account is already was in the partners accounts registry
|
||||||
|
|
||||||
|
// Skipping the iteration
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Searching the partner account and writing into the partners accounts registry
|
||||||
|
$partners[$project->account] = new account()->read(filter: fn(record $record) => $record->identifier === $project->account);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return $partners;
|
||||||
|
} catch (exception $exception) {
|
||||||
|
// Writing the exception into the errors output buffer
|
||||||
|
error_log((string) $exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,9 +21,6 @@ use mirzaev\record\interfaces\record as record_interface,
|
|||||||
// Svoboda time
|
// Svoboda time
|
||||||
use svoboda\time\statement as svoboda;
|
use svoboda\time\statement as svoboda;
|
||||||
|
|
||||||
// Framework for Telegram
|
|
||||||
use Zanzara\Telegram\Type\User as telegram;
|
|
||||||
|
|
||||||
// Built-in libraries
|
// Built-in libraries
|
||||||
use Exception as exception,
|
use Exception as exception,
|
||||||
RuntimeException as exception_runtime;
|
RuntimeException as exception_runtime;
|
||||||
@@ -43,7 +40,7 @@ final class authorizations extends core implements record_interface
|
|||||||
/**
|
/**
|
||||||
* File
|
* File
|
||||||
*
|
*
|
||||||
* @var string $database Path to the database file
|
* @var string $file Path to the database file
|
||||||
*/
|
*/
|
||||||
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'authorizations.baza';
|
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'authorizations.baza';
|
||||||
|
|
||||||
@@ -54,6 +51,13 @@ final class authorizations extends core implements record_interface
|
|||||||
*/
|
*/
|
||||||
public protected(set) database $database;
|
public protected(set) database $database;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialized
|
||||||
|
*
|
||||||
|
* @var bool $serialized Is the implementator object serialized?
|
||||||
|
*/
|
||||||
|
private bool $serialized = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@@ -92,7 +96,7 @@ final class authorizations extends core implements record_interface
|
|||||||
* @param bool $system_settings
|
* @param bool $system_settings
|
||||||
* @param bool $active Is the record active?
|
* @param bool $active Is the record active?
|
||||||
*
|
*
|
||||||
* @return int|false The record identifier, if created
|
* @return int|false The record, if created
|
||||||
*/
|
*/
|
||||||
public function write(
|
public function write(
|
||||||
int $account,
|
int $account,
|
||||||
@@ -100,7 +104,7 @@ final class authorizations extends core implements record_interface
|
|||||||
bool $settings = true,
|
bool $settings = true,
|
||||||
bool $system_settings = false,
|
bool $system_settings = false,
|
||||||
bool $active = true,
|
bool $active = true,
|
||||||
): int|false
|
): record|false
|
||||||
{
|
{
|
||||||
$record = $this->database->record(
|
$record = $this->database->record(
|
||||||
$this->database->count() + 1,
|
$this->database->count() + 1,
|
||||||
@@ -117,7 +121,7 @@ final class authorizations extends core implements record_interface
|
|||||||
$created = $this->database->write($record);
|
$created = $this->database->write($record);
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $created ? $record->identifier : false;
|
return $created ? $record : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,12 +131,22 @@ final class authorizations extends core implements record_interface
|
|||||||
*/
|
*/
|
||||||
public function serialize(): self
|
public function serialize(): self
|
||||||
{
|
{
|
||||||
|
if ($this->serialized) {
|
||||||
|
// The record implementor is serialized
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception_runtime('The record implementor is already serialized');
|
||||||
|
}
|
||||||
|
|
||||||
// Serializing the record parameters
|
// Serializing the record parameters
|
||||||
$this->record->system = (int) $this->record->system;
|
$this->record->system = (int) $this->record->system;
|
||||||
$this->record->settings = (int) $this->record->settings;
|
$this->record->settings = (int) $this->record->settings;
|
||||||
$this->record->system_settings = (int) $this->record->system_settings;
|
$this->record->system_settings = (int) $this->record->system_settings;
|
||||||
$this->record->active = (int) $this->record->active;
|
$this->record->active = (int) $this->record->active;
|
||||||
|
|
||||||
|
// Writing the status of serializing
|
||||||
|
$this->serialized = true;
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -144,12 +158,22 @@ final class authorizations extends core implements record_interface
|
|||||||
*/
|
*/
|
||||||
public function deserialize(): self
|
public function deserialize(): self
|
||||||
{
|
{
|
||||||
|
if (!$this->serialized) {
|
||||||
|
// The record implementor is deserialized
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception_runtime('The record implementor is already deserialized');
|
||||||
|
}
|
||||||
|
|
||||||
// Deserializing the record parameters
|
// Deserializing the record parameters
|
||||||
$this->record->system = (bool) $this->record->system;
|
$this->record->system = (bool) $this->record->system;
|
||||||
$this->record->settings = (bool) $this->record->settings;
|
$this->record->settings = (bool) $this->record->settings;
|
||||||
$this->record->system_settings = (bool) $this->record->system_settings;
|
$this->record->system_settings = (bool) $this->record->system_settings;
|
||||||
$this->record->active = (bool) $this->record->active;
|
$this->record->active = (bool) $this->record->active;
|
||||||
|
|
||||||
|
// Writing the status of serializing
|
||||||
|
$this->serialized = false;
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,4 +41,3 @@ class core extends model
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
201
kodorvan/constructor/system/models/localization.php
Normal file
201
kodorvan/constructor/system/models/localization.php
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\core;
|
||||||
|
|
||||||
|
// Baza database
|
||||||
|
use mirzaev\baza\database,
|
||||||
|
mirzaev\baza\column,
|
||||||
|
mirzaev\baza\record,
|
||||||
|
mirzaev\baza\enumerations\encoding,
|
||||||
|
mirzaev\baza\enumerations\type;
|
||||||
|
|
||||||
|
// The library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use ArrayAccess as array_access,
|
||||||
|
Exception as exception,
|
||||||
|
RuntimeException as exception_runtime,
|
||||||
|
LogicException as exception_logic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Localization
|
||||||
|
*
|
||||||
|
* @package kodorvan\constructor\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 localization extends core implements array_access
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* File
|
||||||
|
*
|
||||||
|
* @var string $file Path to the localization file
|
||||||
|
*/
|
||||||
|
protected string $file;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Language
|
||||||
|
*
|
||||||
|
* @var language $language The localization language
|
||||||
|
*/
|
||||||
|
public readonly language $language;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registry
|
||||||
|
*
|
||||||
|
* @var array $registry The localization records
|
||||||
|
*/
|
||||||
|
protected array $registry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @method language $language The language
|
||||||
|
*
|
||||||
|
* @throws exception_runtime If failed to initialize the localization file
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(language $language)
|
||||||
|
{
|
||||||
|
// Initializing the localization language
|
||||||
|
$this->language = $language;
|
||||||
|
|
||||||
|
// Initializing the path to the localization file
|
||||||
|
$this->file = LOCALIZATIONS . DIRECTORY_SEPARATOR . strtolower($this->language->label()) . '.php';
|
||||||
|
|
||||||
|
if (file_exists($this->file) && is_readable($this->file)) {
|
||||||
|
// Found the localization file
|
||||||
|
|
||||||
|
// Initializing the localization registry
|
||||||
|
$this->registry = require($this->file);
|
||||||
|
} else {
|
||||||
|
// Not found the localization file
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception_runtime('Failed to initialize the localization file');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write as array
|
||||||
|
*
|
||||||
|
* @param mixed $offset The record name
|
||||||
|
* @param mixed $value The record value
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function offsetSet(mixed $offset, mixed $value): void
|
||||||
|
{
|
||||||
|
if (is_null($offset)) {
|
||||||
|
// Not received name of the localization record
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception_logic('Failed to initialized the localization record name');
|
||||||
|
} else {
|
||||||
|
// Received name of the localization record
|
||||||
|
|
||||||
|
// Writing the record into into the registry
|
||||||
|
$this->registry[$offset] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read as from array
|
||||||
|
*
|
||||||
|
* @param mixed $offset The record name
|
||||||
|
*
|
||||||
|
* @return mixed The record value
|
||||||
|
*/
|
||||||
|
public function offsetGet(mixed $offset): mixed
|
||||||
|
{
|
||||||
|
// Reading the record from the registry and exit (success)
|
||||||
|
return $this->registry[$offset] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for initializing as array
|
||||||
|
*
|
||||||
|
* @param mixed $offset The record name
|
||||||
|
*
|
||||||
|
* @return bool Is the record initialized?
|
||||||
|
*/
|
||||||
|
public function offsetExists(mixed $offset): bool
|
||||||
|
{
|
||||||
|
// Checking the record existance in the registry and exit (success)
|
||||||
|
return isset($this->registry[$offset]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete as from array
|
||||||
|
*
|
||||||
|
* @param mixed $offset The record name
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function offsetUnset(mixed $offset): void
|
||||||
|
{
|
||||||
|
// Deleting the record from the registry and exit (succes)
|
||||||
|
unset($this->registry[$offset]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write
|
||||||
|
*
|
||||||
|
* @param string $name The record name
|
||||||
|
* @param mixed $value The record value
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __set(string $name, mixed $value = null): void
|
||||||
|
{
|
||||||
|
// Writing the record into the registry
|
||||||
|
$this->registry[$name] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read
|
||||||
|
*
|
||||||
|
* @param string $name The record name
|
||||||
|
*
|
||||||
|
* @return mixed The record value
|
||||||
|
*/
|
||||||
|
public function __get(string $name): mixed
|
||||||
|
{
|
||||||
|
// Reading the record from the registry and exit (success)
|
||||||
|
return $this->registry[$name];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for initializing
|
||||||
|
*
|
||||||
|
* @param string $name The record name
|
||||||
|
*
|
||||||
|
* @return bool Is the record initialized?
|
||||||
|
*/
|
||||||
|
public function __isset(string $name): bool
|
||||||
|
{
|
||||||
|
// Check for initializing of the property and exit (success)
|
||||||
|
return isset($this->registry[$name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete
|
||||||
|
*
|
||||||
|
* @param string $name The record name
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __unset(string $name): void
|
||||||
|
{
|
||||||
|
// Deleting the record from the registry and exit (success)
|
||||||
|
unset($this->registry[$name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,9 @@ declare(strict_types=1);
|
|||||||
namespace kodorvan\constructor\models;
|
namespace kodorvan\constructor\models;
|
||||||
|
|
||||||
// Files of the project
|
// Files of the project
|
||||||
use kodorvan\constructor\models\core;
|
use kodorvan\constructor\models\core,
|
||||||
|
kodorvan\constructor\models\project\enumerations\status as project_status,
|
||||||
|
kodorvan\constructor\models\project\enumerations\status as project_type;
|
||||||
|
|
||||||
// Baza database
|
// Baza database
|
||||||
use mirzaev\baza\database,
|
use mirzaev\baza\database,
|
||||||
@@ -40,7 +42,7 @@ final class project extends core implements record_interface
|
|||||||
/**
|
/**
|
||||||
* File
|
* File
|
||||||
*
|
*
|
||||||
* @var string $database Path to the database file
|
* @var string $file Path to the database file
|
||||||
*/
|
*/
|
||||||
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'project.baza';
|
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'project.baza';
|
||||||
|
|
||||||
@@ -51,6 +53,13 @@ final class project extends core implements record_interface
|
|||||||
*/
|
*/
|
||||||
public protected(set) database $database;
|
public protected(set) database $database;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialized
|
||||||
|
*
|
||||||
|
* @var bool $serialized Is the implementator object serialized?
|
||||||
|
*/
|
||||||
|
private bool $serialized = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@@ -66,6 +75,8 @@ final class project extends core implements record_interface
|
|||||||
->columns(
|
->columns(
|
||||||
new column('identifier', type::long_long_unsigned),
|
new column('identifier', type::long_long_unsigned),
|
||||||
new column('account', type::long_long_unsigned),
|
new column('account', type::long_long_unsigned),
|
||||||
|
new column('status', type::string, ['length' => 16]),
|
||||||
|
new column('type', type::string, ['length' => 32]),
|
||||||
new column('name', type::string, ['length' => 64]),
|
new column('name', type::string, ['length' => 64]),
|
||||||
/* new column('', type::), */
|
/* new column('', type::), */
|
||||||
new column('active', type::char),
|
new column('active', type::char),
|
||||||
@@ -82,19 +93,32 @@ final class project extends core implements record_interface
|
|||||||
* Write
|
* Write
|
||||||
*
|
*
|
||||||
* @param int $account The account identifier
|
* @param int $account The account identifier
|
||||||
* @param string $name Name of the project
|
* @param project_status $status Status of the project
|
||||||
|
* @param project_type $status Type of the project
|
||||||
|
* @param string|null $name Name of the project
|
||||||
* @param int $active Is the record active?
|
* @param int $active Is the record active?
|
||||||
*
|
*
|
||||||
* @return int|false The record identifier, if created
|
* @return record|false The record, if created
|
||||||
*/
|
*/
|
||||||
public function write(
|
public function write(
|
||||||
int $account,
|
int $account,
|
||||||
string $name = '',
|
project_status $status = project_status::creating,
|
||||||
|
project_type $type = project_type::special,
|
||||||
|
?string $name = null,
|
||||||
bool $active = true,
|
bool $active = true,
|
||||||
): int|false {
|
): record|false {
|
||||||
|
if (empty($name)) {
|
||||||
|
// Not received the project name
|
||||||
|
|
||||||
|
// Generating the project name
|
||||||
|
$name = 'Project №' . count(new account()->read(filter: fn(record $record) => $record->active === 1 && $record->account === $account)?->projects() ?? []);
|
||||||
|
}
|
||||||
|
|
||||||
$record = $this->database->record(
|
$record = $this->database->record(
|
||||||
$this->database->count() + 1,
|
$this->database->count() + 1,
|
||||||
$account,
|
$account,
|
||||||
|
$status->name,
|
||||||
|
$type->name,
|
||||||
$name,
|
$name,
|
||||||
(int) $active,
|
(int) $active,
|
||||||
svoboda::timestamp(),
|
svoboda::timestamp(),
|
||||||
@@ -105,7 +129,7 @@ final class project extends core implements record_interface
|
|||||||
$created = $this->database->write($record);
|
$created = $this->database->write($record);
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $created ? $record->identifier : false;
|
return $created ? $record : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -115,8 +139,20 @@ final class project extends core implements record_interface
|
|||||||
*/
|
*/
|
||||||
public function serialize(): self
|
public function serialize(): self
|
||||||
{
|
{
|
||||||
|
if ($this->serialized) {
|
||||||
|
// The record implementor is serialized
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception_runtime('The record implementor is already serialized');
|
||||||
|
}
|
||||||
|
|
||||||
// Serializing the record parameters
|
// Serializing the record parameters
|
||||||
$this->record->active = (int) $this->record->active;
|
$this->record->active = (int) $this->record->active;
|
||||||
|
$this->record->status = $this->record->status->name;
|
||||||
|
$this->record->type = $this->record->type->name;
|
||||||
|
|
||||||
|
// Writing the status of serializing
|
||||||
|
$this->serialized = true;
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $this;
|
return $this;
|
||||||
@@ -129,11 +165,52 @@ final class project extends core implements record_interface
|
|||||||
*/
|
*/
|
||||||
public function deserialize(): self
|
public function deserialize(): self
|
||||||
{
|
{
|
||||||
|
if (!$this->serialized) {
|
||||||
|
// The record implementor is deserialized
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception_runtime('The record implementor is already deserialized');
|
||||||
|
}
|
||||||
|
|
||||||
// Deserializing the record parameters
|
// Deserializing the record parameters
|
||||||
$this->record->active = (bool) $this->record->active;
|
$this->record->active = (bool) $this->record->active;
|
||||||
|
$this->record->status = project_status::{$this->record->status};
|
||||||
|
$this->record->type = project_status::{$this->record->type};
|
||||||
|
|
||||||
|
// Writing the status of serializing
|
||||||
|
$this->serialized = false;
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parameters
|
||||||
|
*
|
||||||
|
* Search for all the project properties
|
||||||
|
*
|
||||||
|
* @return self The instance from which the method was called (fluent interface)
|
||||||
|
*/
|
||||||
|
public function parameters(): self
|
||||||
|
{
|
||||||
|
// Deserializing the record parameters
|
||||||
|
$this->record->active = (bool) $this->record->active;
|
||||||
|
$this->record->status = project_status::{$this->record->status};
|
||||||
|
|
||||||
|
if (!$this->serialized) {
|
||||||
|
// Not serialized
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Serialized
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception('The project implementator is serialized');
|
||||||
|
}
|
||||||
|
/* if ($this->record->type === '') */
|
||||||
|
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,243 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\project\enumerations;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\project\enumerations\purpose,
|
||||||
|
kodorvan\constructor\models\project\enumerations\integration,
|
||||||
|
kodorvan\constructor\models\worker\enumerations\type as worker_type;
|
||||||
|
|
||||||
|
// The library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// The library for currencies support
|
||||||
|
use mirzaev\currencies\currency;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use InvalidArgumentException as exception_argument,
|
||||||
|
DomainException as exception_domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Architecture
|
||||||
|
*
|
||||||
|
* @package kodorvan\neurobot\models\project\enumerations
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
enum architecture
|
||||||
|
{
|
||||||
|
case chat_robot;
|
||||||
|
case parser;
|
||||||
|
case script;
|
||||||
|
case site;
|
||||||
|
case program;
|
||||||
|
|
||||||
|
case complex;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Label
|
||||||
|
*
|
||||||
|
* @param language $language The language
|
||||||
|
*
|
||||||
|
* @return string The project architecture label
|
||||||
|
*/
|
||||||
|
public function label(language $language = LANGUAGE_DEFAULT): string
|
||||||
|
{
|
||||||
|
// Exit (success)
|
||||||
|
return match ($this) {
|
||||||
|
static::chat_robot => match ($language) {
|
||||||
|
language::en => 'Chat-robot',
|
||||||
|
language::ru => 'Чат-робот'
|
||||||
|
},
|
||||||
|
static::parser => match ($language) {
|
||||||
|
language::en => 'Parser',
|
||||||
|
language::ru => 'Парсер'
|
||||||
|
},
|
||||||
|
static::script => match ($language) {
|
||||||
|
language::en => 'Script',
|
||||||
|
language::ru => 'Скрипт'
|
||||||
|
},
|
||||||
|
static::site => match ($language) {
|
||||||
|
language::en => 'Site',
|
||||||
|
language::ru => 'Сайт'
|
||||||
|
},
|
||||||
|
static::program => match ($language) {
|
||||||
|
language::en => 'Program',
|
||||||
|
language::ru => 'Программа'
|
||||||
|
},
|
||||||
|
static::complex => match ($language) {
|
||||||
|
language::en => 'Non-standart',
|
||||||
|
language::ru => 'Нестандартный'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Length
|
||||||
|
*
|
||||||
|
* @return int Amount of buttons cells length
|
||||||
|
*/
|
||||||
|
public function length(): int
|
||||||
|
{
|
||||||
|
// Exit (success)
|
||||||
|
return match ($this) {
|
||||||
|
static::chat_robot => 2,
|
||||||
|
static::parser => 1,
|
||||||
|
static::script => 1,
|
||||||
|
static::site => 2,
|
||||||
|
static::program => 2,
|
||||||
|
static::complex => 4,
|
||||||
|
default => 1
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purposes
|
||||||
|
*
|
||||||
|
* @return array Purposes
|
||||||
|
*/
|
||||||
|
public function purposes(): array
|
||||||
|
{
|
||||||
|
// Initializing purposes
|
||||||
|
$purposes = purpose::cases();
|
||||||
|
|
||||||
|
// Deleting the special purpose
|
||||||
|
$indexes = array_keys($purposes, purpose::special);
|
||||||
|
foreach ($indexes as $index) unset($purposes[$index]);
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return match ($this) {
|
||||||
|
static::chat_robot => [
|
||||||
|
purpose::funnel,
|
||||||
|
purpose::contact,
|
||||||
|
purpose::neural_network,
|
||||||
|
purpose::game,
|
||||||
|
purpose::gallery,
|
||||||
|
purpose::crm,
|
||||||
|
purpose::calculate,
|
||||||
|
purpose::landing,
|
||||||
|
purpose::marketplace,
|
||||||
|
],
|
||||||
|
static::parser => [
|
||||||
|
purpose::search
|
||||||
|
],
|
||||||
|
static::script => [
|
||||||
|
purpose::logic
|
||||||
|
],
|
||||||
|
static::site => [
|
||||||
|
purpose::funnel,
|
||||||
|
purpose::contact,
|
||||||
|
purpose::neural_network,
|
||||||
|
purpose::gallery,
|
||||||
|
purpose::crm,
|
||||||
|
purpose::calculate,
|
||||||
|
purpose::landing,
|
||||||
|
purpose::marketplace,
|
||||||
|
],
|
||||||
|
static::program => [
|
||||||
|
purpose::neural_network,
|
||||||
|
purpose::crm,
|
||||||
|
purpose::calculate,
|
||||||
|
purpose::marketplace,
|
||||||
|
],
|
||||||
|
default => []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cost
|
||||||
|
*
|
||||||
|
* @return int|float The minimal cost of the project development
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
public function cost(currency $currency = CURRENCY_DEFAULT): int|float
|
||||||
|
{
|
||||||
|
// Exit (success)
|
||||||
|
return match ($this) {
|
||||||
|
static::chat_robot => match ($currency) {
|
||||||
|
currency::usd => 20,
|
||||||
|
currency::rub => 2000
|
||||||
|
},
|
||||||
|
static::parser => match ($currency) {
|
||||||
|
currency::usd => 35,
|
||||||
|
currency::rub => 3500
|
||||||
|
},
|
||||||
|
static::script => match ($currency) {
|
||||||
|
currency::usd => 10,
|
||||||
|
currency::rub => 1000
|
||||||
|
},
|
||||||
|
static::site => match ($currency) {
|
||||||
|
currency::usd => 50,
|
||||||
|
currency::rub => 5000
|
||||||
|
},
|
||||||
|
static::program => match ($currency) {
|
||||||
|
currency::usd => 70,
|
||||||
|
currency::rub => 6000
|
||||||
|
},
|
||||||
|
static::complex => match ($currency) {
|
||||||
|
currency::usd => 100,
|
||||||
|
currency::rub => 10000
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Coefficient
|
||||||
|
*
|
||||||
|
* @return int The project development hours
|
||||||
|
*/
|
||||||
|
public function coefficient(): int|float
|
||||||
|
{
|
||||||
|
// Exit (success)
|
||||||
|
return (int) match ($this) {
|
||||||
|
static::chat_robot => 3,
|
||||||
|
static::parser => 2,
|
||||||
|
static::script => 1,
|
||||||
|
static::site => 3,
|
||||||
|
static::program => 4,
|
||||||
|
static::complex => 5,
|
||||||
|
default => 5
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Workers
|
||||||
|
*
|
||||||
|
* @return array Workers
|
||||||
|
*/
|
||||||
|
public function workers(): array
|
||||||
|
{
|
||||||
|
// Exit (success)
|
||||||
|
return match ($this) {
|
||||||
|
static::chat_robot => [
|
||||||
|
worker_type::programmer->name => 1,
|
||||||
|
worker_type::booster->name => 1
|
||||||
|
],
|
||||||
|
static::parser => [
|
||||||
|
worker_type::programmer->name => 1
|
||||||
|
],
|
||||||
|
static::script => [
|
||||||
|
worker_type::programmer->name => 1
|
||||||
|
],
|
||||||
|
static::site => [
|
||||||
|
worker_type::programmer->name => 1,
|
||||||
|
worker_type::designer->name => 1,
|
||||||
|
worker_type::booster->name => 1
|
||||||
|
],
|
||||||
|
static::program => [
|
||||||
|
worker_type::programmer->name => 1,
|
||||||
|
worker_type::designer->name => 1
|
||||||
|
],
|
||||||
|
static::complex => [
|
||||||
|
worker_type::programmer->name => 1
|
||||||
|
],
|
||||||
|
default => [
|
||||||
|
worker_type::programmer->name => 1
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\project\enumerations;
|
||||||
|
|
||||||
|
// The library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use InvalidArgumentException as exception_argument,
|
||||||
|
DomainException as exception_domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integration
|
||||||
|
*
|
||||||
|
* @package kodorvan\neurobot\models\project\enumerations
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
enum integration
|
||||||
|
{
|
||||||
|
case one_c;
|
||||||
|
case bitrix24;
|
||||||
|
case moy_sklad;
|
||||||
|
case telegram;
|
||||||
|
case mail;
|
||||||
|
case excel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Label
|
||||||
|
*
|
||||||
|
* @param language $language The language
|
||||||
|
*
|
||||||
|
* @return string The project form label
|
||||||
|
*/
|
||||||
|
public function label(language $language = LANGUAGE_DEFAULT): string
|
||||||
|
{
|
||||||
|
// Exit (success)
|
||||||
|
return match ($this) {
|
||||||
|
static::one_c => '1C',
|
||||||
|
static::bitrix24 => match ($language) {
|
||||||
|
language::en => 'Bitrix 24',
|
||||||
|
language::ru => 'Битрикс 24'
|
||||||
|
},
|
||||||
|
static::moy_sklad => match ($language) {
|
||||||
|
language::en => 'Moy Sklad',
|
||||||
|
language::ru => 'Мой Склад'
|
||||||
|
},
|
||||||
|
static::telegram => match ($language) {
|
||||||
|
language::en => 'Telegram',
|
||||||
|
language::ru => 'Телеграм'
|
||||||
|
},
|
||||||
|
static::mail => match ($language) {
|
||||||
|
language::en => 'Mail',
|
||||||
|
language::ru => 'Почта'
|
||||||
|
},
|
||||||
|
static::excel => 'Excel'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Length
|
||||||
|
*
|
||||||
|
* @return int Amount of buttons cells length
|
||||||
|
*/
|
||||||
|
public function length(): int
|
||||||
|
{
|
||||||
|
// Exit (success)
|
||||||
|
return match ($this) {
|
||||||
|
static::one_c => 1,
|
||||||
|
static::bitrix24 => 2,
|
||||||
|
static::moy_sklad => 2,
|
||||||
|
static::telegram => 2,
|
||||||
|
static::mail => 1,
|
||||||
|
static::excel => 1,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Coefficient
|
||||||
|
*
|
||||||
|
* @return int|float Coefficient to the project development hours
|
||||||
|
*/
|
||||||
|
public function coefficient(): int|float
|
||||||
|
{
|
||||||
|
// Exit (success)
|
||||||
|
return match ($this) {
|
||||||
|
static::one_c => 3,
|
||||||
|
static::bitrix24 => 3.5,
|
||||||
|
static::moy_sklad => 3,
|
||||||
|
static::telegram => 2,
|
||||||
|
static::mail => 1.2,
|
||||||
|
static::excel => 1.5,
|
||||||
|
default => 2
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,267 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\project\enumerations;
|
||||||
|
|
||||||
|
// The library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use InvalidArgumentException as exception_argument,
|
||||||
|
DomainException as exception_domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purpose
|
||||||
|
*
|
||||||
|
* @package kodorvan\neurobot\models\project\enumerations
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
enum purpose
|
||||||
|
{
|
||||||
|
case funnel;
|
||||||
|
case contact;
|
||||||
|
case neural_network;
|
||||||
|
case gallery;
|
||||||
|
case crm;
|
||||||
|
case landing;
|
||||||
|
case marketplace;
|
||||||
|
/* case charity; */
|
||||||
|
case search;
|
||||||
|
case calculate;
|
||||||
|
case logic;
|
||||||
|
case game;
|
||||||
|
|
||||||
|
/* case workers;
|
||||||
|
case tools;
|
||||||
|
case objects;
|
||||||
|
case events; */
|
||||||
|
|
||||||
|
case special;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Label
|
||||||
|
*
|
||||||
|
* @param language $language The language
|
||||||
|
*
|
||||||
|
* @return string The project form label
|
||||||
|
*/
|
||||||
|
public function label(language $language = LANGUAGE_DEFAULT): string
|
||||||
|
{
|
||||||
|
// Exit (success)
|
||||||
|
return match ($this) {
|
||||||
|
static::funnel => match ($language) {
|
||||||
|
language::en => 'Funnel',
|
||||||
|
language::ru => 'Воронка'
|
||||||
|
},
|
||||||
|
static::contact => match ($language) {
|
||||||
|
language::en => 'Contact',
|
||||||
|
language::ru => 'Контакты'
|
||||||
|
},
|
||||||
|
static::neural_network => match ($language) {
|
||||||
|
language::en => 'Neural network',
|
||||||
|
language::ru => 'Нейросеть'
|
||||||
|
},
|
||||||
|
static::game => match ($language) {
|
||||||
|
language::en => 'Game',
|
||||||
|
language::ru => 'Игра'
|
||||||
|
},
|
||||||
|
static::gallery => match ($language) {
|
||||||
|
language::en => 'Gallery',
|
||||||
|
language::ru => 'Галерея'
|
||||||
|
},
|
||||||
|
static::crm => match ($language) {
|
||||||
|
default => 'CRM'
|
||||||
|
},
|
||||||
|
static::landing => match ($language) {
|
||||||
|
language::en => 'Landing',
|
||||||
|
language::ru => 'Лендинг'
|
||||||
|
},
|
||||||
|
static::marketplace => match ($language) {
|
||||||
|
language::en => 'Marketplace',
|
||||||
|
language::ru => 'Маркетплейс'
|
||||||
|
},
|
||||||
|
/* static::charity => match ($language) {
|
||||||
|
language::en => 'Charity',
|
||||||
|
language::ru => 'Благотворительность'
|
||||||
|
}, */
|
||||||
|
static::search => match ($language) {
|
||||||
|
language::en => 'Search',
|
||||||
|
language::ru => 'Поиск'
|
||||||
|
},
|
||||||
|
static::calculate => match ($language) {
|
||||||
|
language::en => 'Calculate',
|
||||||
|
language::ru => 'Расчёты'
|
||||||
|
},
|
||||||
|
/* static::logic => match ($language) {
|
||||||
|
language::en => 'Logic',
|
||||||
|
language::ru => 'Логика'
|
||||||
|
}, */
|
||||||
|
static::game => match ($language) {
|
||||||
|
language::en => 'Game',
|
||||||
|
language::ru => 'Игра'
|
||||||
|
},
|
||||||
|
/* static::workers => match ($language) {
|
||||||
|
language::en => 'Workes',
|
||||||
|
language::ru => 'Рабочие'
|
||||||
|
},
|
||||||
|
static::tools => match ($language) {
|
||||||
|
language::en => 'Tools',
|
||||||
|
language::ru => 'Инструменты'
|
||||||
|
},
|
||||||
|
static::objects => match ($language) {
|
||||||
|
language::en => 'Objects',
|
||||||
|
language::ru => 'Предметы'
|
||||||
|
},
|
||||||
|
static::events => match ($language) {
|
||||||
|
language::en => 'Events',
|
||||||
|
language::ru => 'События'
|
||||||
|
}, */
|
||||||
|
static::special => match ($language) {
|
||||||
|
language::en => 'Special',
|
||||||
|
language::ru => 'Особенное'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integrations
|
||||||
|
*
|
||||||
|
* @return array Integrations
|
||||||
|
*/
|
||||||
|
public function integrations(): array
|
||||||
|
{
|
||||||
|
// Exit (success)
|
||||||
|
return match ($this) {
|
||||||
|
static::funnel => [
|
||||||
|
integration::telegram,
|
||||||
|
integration::mail,
|
||||||
|
integration::bitrix24
|
||||||
|
],
|
||||||
|
static::contact => [
|
||||||
|
integration::mail,
|
||||||
|
integration::bitrix24
|
||||||
|
],
|
||||||
|
static::neural_network => [
|
||||||
|
integration::telegram
|
||||||
|
],
|
||||||
|
static::game => [
|
||||||
|
integration::telegram
|
||||||
|
],
|
||||||
|
static::gallery => [],
|
||||||
|
static::crm => [
|
||||||
|
integration::one_c,
|
||||||
|
integration::moy_sklad,
|
||||||
|
integration::excel
|
||||||
|
],
|
||||||
|
static::landing => [
|
||||||
|
integration::telegram
|
||||||
|
],
|
||||||
|
static::marketplace => [
|
||||||
|
integration::one_c,
|
||||||
|
integration::moy_sklad,
|
||||||
|
integration::excel
|
||||||
|
],
|
||||||
|
/* static::charity => [
|
||||||
|
integration::one_c,
|
||||||
|
integration::moy_sklad,
|
||||||
|
integration::excel
|
||||||
|
], */
|
||||||
|
static::search => [],
|
||||||
|
static::calculate => [
|
||||||
|
integration::one_c,
|
||||||
|
integration::moy_sklad,
|
||||||
|
integration::excel
|
||||||
|
],
|
||||||
|
/* static::logic => [],
|
||||||
|
static::tools => [
|
||||||
|
integration::one_c,
|
||||||
|
integration::moy_sklad,
|
||||||
|
integration::excel
|
||||||
|
],
|
||||||
|
static::workers => [
|
||||||
|
integration::one_c,
|
||||||
|
integration::moy_sklad,
|
||||||
|
integration::excel
|
||||||
|
],
|
||||||
|
static::objects => [
|
||||||
|
integration::one_c,
|
||||||
|
integration::moy_sklad,
|
||||||
|
integration::excel
|
||||||
|
],
|
||||||
|
static::events => [
|
||||||
|
integration::one_c,
|
||||||
|
integration::moy_sklad,
|
||||||
|
integration::excel
|
||||||
|
],
|
||||||
|
static::special => [
|
||||||
|
integration::one_c,
|
||||||
|
integration::moy_sklad,
|
||||||
|
integration::excel
|
||||||
|
], */
|
||||||
|
default => []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Length
|
||||||
|
*
|
||||||
|
* @return int Amount of buttons cells length
|
||||||
|
*/
|
||||||
|
public function length(): int
|
||||||
|
{
|
||||||
|
// Exit (success)
|
||||||
|
return match ($this) {
|
||||||
|
static::funnel => 2,
|
||||||
|
static::contact => 2,
|
||||||
|
static::neural_network => 3,
|
||||||
|
static::game => 1,
|
||||||
|
static::gallery => 1,
|
||||||
|
static::crm => 1,
|
||||||
|
static::landing => 1,
|
||||||
|
static::marketplace => 2,
|
||||||
|
/* static::charity => 2, */
|
||||||
|
static::search => 2,
|
||||||
|
static::calculate => 2,
|
||||||
|
/* static::logic => 1,
|
||||||
|
static::tools => 1,
|
||||||
|
static::workers => 1,
|
||||||
|
static::objects => 1,
|
||||||
|
static::events => 1, */
|
||||||
|
static::special => 4,
|
||||||
|
default => 1
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Coefficient
|
||||||
|
*
|
||||||
|
* @return int|float Coefficient to the project development hours
|
||||||
|
*/
|
||||||
|
public function coefficient(): int|float
|
||||||
|
{
|
||||||
|
// Exit (success)
|
||||||
|
return match ($this) {
|
||||||
|
static::funnel => 2,
|
||||||
|
static::contact => 1.1,
|
||||||
|
static::neural_network => 4,
|
||||||
|
static::game => 3,
|
||||||
|
static::gallery => 1,
|
||||||
|
static::crm => 6,
|
||||||
|
static::landing => 1.5,
|
||||||
|
static::marketplace => 8,
|
||||||
|
/* static::charity => 0.8, */
|
||||||
|
static::search => 1,
|
||||||
|
static::calculate => 2,
|
||||||
|
/* static::logic => 1,
|
||||||
|
static::tools => 1,
|
||||||
|
static::workers => 1.2,
|
||||||
|
static::objects => 1,
|
||||||
|
static::events => 1.5, */
|
||||||
|
static::special => 2,
|
||||||
|
default => 1
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,22 +9,22 @@ use InvalidArgumentException as exception_argument,
|
|||||||
DomainException as exception_domain;
|
DomainException as exception_domain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type
|
* Status
|
||||||
*
|
*
|
||||||
* @package kodorvan\neurobot\models\project\enumerations
|
* @package kodorvan\neurobot\models\project\enumerations
|
||||||
*
|
*
|
||||||
* @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>
|
||||||
*/
|
*/
|
||||||
enum type
|
enum status
|
||||||
{
|
{
|
||||||
case telegram_voronka;
|
case creating;
|
||||||
case parser;
|
case calculated;
|
||||||
case calculator;
|
case requested;
|
||||||
case crm;
|
|
||||||
case marketplace;
|
|
||||||
case site;
|
|
||||||
case program;
|
|
||||||
|
|
||||||
case special;
|
case invoiced;
|
||||||
|
|
||||||
|
case developing;
|
||||||
|
case developed;
|
||||||
|
case launched;
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ final class settings extends core implements record_interface
|
|||||||
/**
|
/**
|
||||||
* File
|
* File
|
||||||
*
|
*
|
||||||
* @var string $database Path to the database file
|
* @var string $file Path to the database file
|
||||||
*/
|
*/
|
||||||
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'settings.baza';
|
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'settings.baza';
|
||||||
|
|
||||||
@@ -51,6 +51,13 @@ final class settings extends core implements record_interface
|
|||||||
*/
|
*/
|
||||||
public protected(set) database $database;
|
public protected(set) database $database;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialized
|
||||||
|
*
|
||||||
|
* @var bool $serialized Is the implementator object serialized?
|
||||||
|
*/
|
||||||
|
private bool $serialized = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@@ -83,12 +90,12 @@ final class settings extends core implements record_interface
|
|||||||
* @param int $account The account identifier
|
* @param int $account The account identifier
|
||||||
* @param int $active Is the record active?
|
* @param int $active Is the record active?
|
||||||
*
|
*
|
||||||
* @return int|false The record identifier, if created
|
* @return int|false The record, if created
|
||||||
*/
|
*/
|
||||||
public function write(
|
public function write(
|
||||||
int $account,
|
int $account,
|
||||||
bool $active = true,
|
bool $active = true,
|
||||||
): int|false {
|
): record|false {
|
||||||
$record = $this->database->record(
|
$record = $this->database->record(
|
||||||
$this->database->count() + 1,
|
$this->database->count() + 1,
|
||||||
$account,
|
$account,
|
||||||
@@ -101,7 +108,7 @@ final class settings extends core implements record_interface
|
|||||||
$created = $this->database->write($record);
|
$created = $this->database->write($record);
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $created ? $record->identifier : false;
|
return $created ? $record : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -111,9 +118,19 @@ final class settings extends core implements record_interface
|
|||||||
*/
|
*/
|
||||||
public function serialize(): self
|
public function serialize(): self
|
||||||
{
|
{
|
||||||
|
if ($this->serialized) {
|
||||||
|
// The record implementor is serialized
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception_runtime('The record implementor is already serialized');
|
||||||
|
}
|
||||||
|
|
||||||
// Serializing the record parameters
|
// Serializing the record parameters
|
||||||
$this->record->active = (int) $this->record->active;
|
$this->record->active = (int) $this->record->active;
|
||||||
|
|
||||||
|
// Writing the status of serializing
|
||||||
|
$this->serialized = true;
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -125,11 +142,20 @@ final class settings extends core implements record_interface
|
|||||||
*/
|
*/
|
||||||
public function deserialize(): self
|
public function deserialize(): self
|
||||||
{
|
{
|
||||||
|
if (!$this->serialized) {
|
||||||
|
// The record implementor is deserialized
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception_runtime('The record implementor is already deserialized');
|
||||||
|
}
|
||||||
|
|
||||||
// Deserializing the record parameters
|
// Deserializing the record parameters
|
||||||
$this->record->active = (bool) $this->record->active;
|
$this->record->active = (bool) $this->record->active;
|
||||||
|
|
||||||
|
// Writing the status of serializing
|
||||||
|
$this->serialized = false;
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,373 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace kodorvan\constructor\models\telegram;
|
|
||||||
|
|
||||||
// Files of the project
|
|
||||||
use kodorvan\constructor\models\core,
|
|
||||||
kodorvan\constructor\models\account,
|
|
||||||
kodorvan\constructor\models\settings,
|
|
||||||
kodorvan\constructor\models\telegram\processes\language\select as process_language_select;
|
|
||||||
|
|
||||||
// Library for languages support
|
|
||||||
use mirzaev\languages\language;
|
|
||||||
|
|
||||||
// The library for escaping all markdown symbols
|
|
||||||
use function mirzaev\unmarkdown;
|
|
||||||
|
|
||||||
// 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\constructor\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
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Start
|
|
||||||
*
|
|
||||||
* Responce for command: "/start"
|
|
||||||
*
|
|
||||||
* @param context $context Request data from Telegram
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function start(context $context): void
|
|
||||||
{
|
|
||||||
// Initializing the account
|
|
||||||
$account = $context->get('account');
|
|
||||||
|
|
||||||
if ($account instanceof account) {
|
|
||||||
// Initialized the account
|
|
||||||
|
|
||||||
// Initializing the language
|
|
||||||
$language = $context->get('language');
|
|
||||||
|
|
||||||
if ($language instanceof language) {
|
|
||||||
// Initialized the language
|
|
||||||
|
|
||||||
// Initializing localization
|
|
||||||
$localization = $context->get('localization');
|
|
||||||
|
|
||||||
if ($localization) {
|
|
||||||
// Initialized localization
|
|
||||||
|
|
||||||
// Initializing the message title text
|
|
||||||
$title = '📋 *' . $localization['menu_title'] . '*';
|
|
||||||
|
|
||||||
// Initializing the keyboard array
|
|
||||||
/* $keyboard = [];
|
|
||||||
|
|
||||||
foreach (project) */
|
|
||||||
|
|
||||||
// Calculating amount of projects
|
|
||||||
$projects = count($account->projects());
|
|
||||||
|
|
||||||
// Initializing the message description text
|
|
||||||
$description = $projects > 0 ? $localization['menu_description_partner'] : ('🔥 ' . $localization['menu_description_guest']);
|
|
||||||
|
|
||||||
// Initializing the message experiment text
|
|
||||||
$experiment = '⚠️ ' . $localization['menu_experiment'];
|
|
||||||
|
|
||||||
// Initializing the message last update text
|
|
||||||
exec(command: 'git log --oneline $(git describe --tags --abbrev=0 @^)..@ -1 --format="%at" | xargs -I{} date -d @{} "+%Y.%m.%d %H:%M"', output: $git);
|
|
||||||
$update = empty($git) ? '' : "\n*" . $localization['menu_update'] . ':* ' . $git;
|
|
||||||
|
|
||||||
// Sending the message
|
|
||||||
$context->sendMessage(
|
|
||||||
<<<TXT
|
|
||||||
$title
|
|
||||||
|
|
||||||
$description
|
|
||||||
|
|
||||||
$experiment$update
|
|
||||||
TXT,
|
|
||||||
[
|
|
||||||
'reply_markup' => [
|
|
||||||
'inline_keyboard' => [
|
|
||||||
[
|
|
||||||
[
|
|
||||||
'text' => '📂 ' . $localization['menu_button_project_new'],
|
|
||||||
'callback_data' => 'calculator'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'text' => '🗂 ' . $localization['menu_button_projects'] . ': ' . $projects,
|
|
||||||
'callback_data' => 'projects'
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
[
|
|
||||||
'text' => '📡 ' . $localization['menu_button_operator'],
|
|
||||||
'callback_data' => 'operator'
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'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 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) {
|
|
||||||
// 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 account) {
|
|
||||||
// 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");
|
|
||||||
|
|
||||||
// Sending the message
|
|
||||||
$context->sendMessage(
|
|
||||||
<<<TXT
|
|
||||||
$title
|
|
||||||
|
|
||||||
$authorizations
|
|
||||||
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 account) {
|
|
||||||
// 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();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 account) {
|
|
||||||
// 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();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
118
kodorvan/constructor/system/models/telegram/commands/account.php
Normal file
118
kodorvan/constructor/system/models/telegram/commands/account.php
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\telegram\commands;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\core,
|
||||||
|
kodorvan\constructor\models\account as model,
|
||||||
|
kodorvan\constructor\models\settings,
|
||||||
|
kodorvan\constructor\models\localization,
|
||||||
|
kodorvan\constructor\models\telegram\processes\language\select as process_language_select;
|
||||||
|
|
||||||
|
// Library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// The library for escaping all markdown symbols
|
||||||
|
use function mirzaev\unmarkdown;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use SergiX44\Nutgram\Nutgram as telegram,
|
||||||
|
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Message\Message as message,
|
||||||
|
SergiX44\Nutgram\Handlers\Type\Command as command,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Internal\InputFile as input,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardMarkup as keyboard,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardButton as button;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command: account
|
||||||
|
*
|
||||||
|
* @package kodorvan\constructor\models\telegram\commands
|
||||||
|
*
|
||||||
|
* @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 command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Command
|
||||||
|
*
|
||||||
|
* @var string $name Name of the command
|
||||||
|
*/
|
||||||
|
protected string $command = 'account';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description
|
||||||
|
*
|
||||||
|
* @var string $description
|
||||||
|
*/
|
||||||
|
protected ?string $description = 'Account profile';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Localizations
|
||||||
|
*
|
||||||
|
* Descriptions of the command
|
||||||
|
*
|
||||||
|
* @var array $localizedDescriptions
|
||||||
|
*/
|
||||||
|
protected array $localizedDescriptions = [
|
||||||
|
'ru' => 'Профиль аккаунта',
|
||||||
|
'*' => 'Account profile'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle
|
||||||
|
*
|
||||||
|
* Processing the command
|
||||||
|
*
|
||||||
|
* @param telegram $robot The chat-robot instance
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(telegram $robot): void
|
||||||
|
{
|
||||||
|
// Initializing the language
|
||||||
|
$language = $robot->get('language') ?? LANGUAGE_DEFAULT;
|
||||||
|
|
||||||
|
// Initializing the menu message localization
|
||||||
|
$localization = $robot->get('localization') ?? new localization($language);
|
||||||
|
|
||||||
|
// Initializing the account
|
||||||
|
$account = $robot->get('account');
|
||||||
|
|
||||||
|
// Declaring buufer of rows about authorizations
|
||||||
|
$authorizations = '';
|
||||||
|
|
||||||
|
// Initializing rows about authorization
|
||||||
|
foreach ($account->authorizations()?->record->values() as $key => $value) {
|
||||||
|
// Iterating over account parameters
|
||||||
|
|
||||||
|
if (match ($key) {
|
||||||
|
'identifier', 'account', 'active', 'updated', 'created' => false,
|
||||||
|
default => true
|
||||||
|
} && !str_starts_with($key, 'system_')) {
|
||||||
|
// The value is not metadata and system authorozations
|
||||||
|
|
||||||
|
// Writing into buffer of rows about authorizations
|
||||||
|
$authorizations .= ($value ? '✅' : '❎') . ' *' . ($localization["authorization_$key"] ?? $key) . ':* ' . ($value ? $localization->yes : $localization->no) . "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trimming the last line break character
|
||||||
|
$authorizations = trim($authorizations, "\n");
|
||||||
|
|
||||||
|
$robot->sendMessage(
|
||||||
|
text: implode(
|
||||||
|
"\n\n",
|
||||||
|
[
|
||||||
|
"🫵 *$localization->account_title*",
|
||||||
|
$authorizations
|
||||||
|
]
|
||||||
|
),
|
||||||
|
parse_mode: mode::MARKDOWN,
|
||||||
|
disable_notification: true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,175 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\telegram\commands;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\core,
|
||||||
|
kodorvan\constructor\models\account,
|
||||||
|
kodorvan\constructor\models\settings,
|
||||||
|
kodorvan\constructor\models\localization,
|
||||||
|
kodorvan\constructor\models\telegram\processes\language\select as process_language_select;
|
||||||
|
|
||||||
|
// Library for languages support
|
||||||
|
use mirzaev\languages\language as type;
|
||||||
|
|
||||||
|
// The library for escaping all markdown symbols
|
||||||
|
use function mirzaev\unmarkdown;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use SergiX44\Nutgram\Nutgram as telegram,
|
||||||
|
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Message\Message as message,
|
||||||
|
SergiX44\Nutgram\Handlers\Type\Command as command,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Internal\InputFile as input,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardMarkup as keyboard,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardButton as button;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command: language
|
||||||
|
*
|
||||||
|
* @package kodorvan\constructor\models\telegram\commands
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
final class language extends command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Command
|
||||||
|
*
|
||||||
|
* @var string $name Name of the command
|
||||||
|
*/
|
||||||
|
protected string $command = 'language';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description
|
||||||
|
*
|
||||||
|
* @var string $description
|
||||||
|
*/
|
||||||
|
protected ?string $description = 'System language';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Localizations
|
||||||
|
*
|
||||||
|
* Descriptions of the command
|
||||||
|
*
|
||||||
|
* @var array $localizedDescriptions
|
||||||
|
*/
|
||||||
|
protected array $localizedDescriptions = [
|
||||||
|
'ru' => 'Язык системы',
|
||||||
|
'*' => 'System language'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle
|
||||||
|
*
|
||||||
|
* Processing the command
|
||||||
|
*
|
||||||
|
* @param telegram $robot The chat-robot instance
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(telegram $robot): void
|
||||||
|
{
|
||||||
|
// Initializing the language
|
||||||
|
$language = $robot->get('language') ?? LANGUAGE_DEFAULT;
|
||||||
|
|
||||||
|
// Initializing the localization
|
||||||
|
$localization = $robot->get('localization') ?? new localization($language);
|
||||||
|
|
||||||
|
$this::menu(
|
||||||
|
robot: $robot,
|
||||||
|
prefix: 'settings_language_',
|
||||||
|
title: "🌏 *$localization->settings_language_title*",
|
||||||
|
description: $localization->settings_language_description,
|
||||||
|
language: $language
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Menu
|
||||||
|
*
|
||||||
|
* Generate and send the language selection menu
|
||||||
|
*
|
||||||
|
* @param telegram $robot The chat-robot instance
|
||||||
|
* @param string|null $prefix The process prefix
|
||||||
|
* @param string|null $title The menu message title
|
||||||
|
* @param string|null $description The menu message description (main content)
|
||||||
|
* @param array $exclude Languages that will be excluded ['ru', 'en'...]
|
||||||
|
* @param type $language The menu message language
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function menu(telegram $robot, ?string $prefix = null, ?string $title = null, ?string $description = null, array $exclude = [], type $language = LANGUAGE_DEFAULT): void
|
||||||
|
{
|
||||||
|
// Initializing the menu message localization
|
||||||
|
$localization = $robot->get('localization') ?? new localization($language);
|
||||||
|
|
||||||
|
// Initializing the keyboard
|
||||||
|
$keyboard = keyboard::make();
|
||||||
|
|
||||||
|
// Initializing the row
|
||||||
|
$row = [];
|
||||||
|
|
||||||
|
// Initializing the maximum amount of buttons in a row
|
||||||
|
$length = 4;
|
||||||
|
|
||||||
|
// Initializing buffer of languages
|
||||||
|
$languages = type::cases();
|
||||||
|
|
||||||
|
// Initializing the selected language index
|
||||||
|
$selected = array_search($language, $languages, strict: true);
|
||||||
|
|
||||||
|
// Exclude the selected language from buffer of languages
|
||||||
|
if ($selected !== false) unset($languages[$selected]);
|
||||||
|
|
||||||
|
// Sorting buffer of languages by the selected language
|
||||||
|
$languages = [$language, ...$languages];
|
||||||
|
|
||||||
|
foreach ($languages as $language) {
|
||||||
|
// Iterating over languages
|
||||||
|
|
||||||
|
// Skipping excluded languages
|
||||||
|
if (array_search($language->name, $exclude, strict: true) !== false) continue;
|
||||||
|
|
||||||
|
// Writing the language choose button into the buffer of generated keyboard with languages
|
||||||
|
$row[] = button::make(
|
||||||
|
text: ($language->flag() ? $language->flag() . ' ' : '') . $language->label($language),
|
||||||
|
callback_data: $prefix . $language->name
|
||||||
|
);
|
||||||
|
|
||||||
|
if (count($row) >= $length) {
|
||||||
|
// Reached the limit of buttons in a row
|
||||||
|
|
||||||
|
// Writing the row into the keyboard
|
||||||
|
$keyboard->addRow(...$row);
|
||||||
|
|
||||||
|
// Reinitializing the row
|
||||||
|
$row = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($row) / $length < 1) {
|
||||||
|
// The row was not writed
|
||||||
|
|
||||||
|
// Writing the row into the keyboard
|
||||||
|
$keyboard->addRow(...$row);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Writing the row into the keyboard
|
||||||
|
$keyboard->addRow(button::make(
|
||||||
|
text: '🗂 ' . $localization->settings_language_button_add,
|
||||||
|
url: PROJECT_REPOSITORY_LANGUAGE_ADD
|
||||||
|
));
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$robot->sendMessage(
|
||||||
|
text: ($title ?? "🌏 *$localization->settings_language_title*") . "\n\n" . ($description ?? $localization->settings_language_description),
|
||||||
|
parse_mode: mode::MARKDOWN,
|
||||||
|
disable_notification: true,
|
||||||
|
reply_markup: $keyboard,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\telegram\commands;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\core,
|
||||||
|
kodorvan\constructor\models\account,
|
||||||
|
kodorvan\constructor\models\settings,
|
||||||
|
kodorvan\constructor\models\telegram\processes\language\select as process_language_select;
|
||||||
|
|
||||||
|
// Library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// The library for escaping all markdown symbols
|
||||||
|
use function mirzaev\unmarkdown;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use SergiX44\Nutgram\Nutgram as telegram,
|
||||||
|
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Message\Message as message,
|
||||||
|
SergiX44\Nutgram\Handlers\Type\Command as command,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Internal\InputFile as input;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command: society
|
||||||
|
*
|
||||||
|
* @package kodorvan\constructor\models\telegram\commands
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
final class society extends command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Command
|
||||||
|
*
|
||||||
|
* @var string $name Name of the command
|
||||||
|
*/
|
||||||
|
protected string $command = 'society';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description
|
||||||
|
*
|
||||||
|
* @var string $description
|
||||||
|
*/
|
||||||
|
protected ?string $description = 'thing about it';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Localizations
|
||||||
|
*
|
||||||
|
* Descriptions of the command
|
||||||
|
*
|
||||||
|
* @var array $localizedDescriptions
|
||||||
|
*/
|
||||||
|
protected array $localizedDescriptions = [
|
||||||
|
'*' => 'thing about it'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle
|
||||||
|
*
|
||||||
|
* Processing the command
|
||||||
|
*
|
||||||
|
* @param telegram $robot The chat-robot instance
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(telegram $robot): void
|
||||||
|
{
|
||||||
|
$robot->sendPhoto(
|
||||||
|
photo: input::make(STORAGE . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'mushroom.jpg'),
|
||||||
|
caption: $robot->get('localization')['why_so_shroomious'] ?? 'why so shroomious',
|
||||||
|
disable_notification: true,
|
||||||
|
parse_mode: mode::MARKDOWN
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
132
kodorvan/constructor/system/models/telegram/commands/start.php
Normal file
132
kodorvan/constructor/system/models/telegram/commands/start.php
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\telegram\commands;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\core,
|
||||||
|
kodorvan\constructor\models\account,
|
||||||
|
kodorvan\constructor\models\settings,
|
||||||
|
kodorvan\constructor\models\localization,
|
||||||
|
kodorvan\constructor\models\telegram\processes\language\select as process_language_select;
|
||||||
|
|
||||||
|
// Library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// The library for escaping all markdown symbols
|
||||||
|
use function mirzaev\unmarkdown;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use SergiX44\Nutgram\Nutgram as telegram,
|
||||||
|
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Message\Message as message,
|
||||||
|
SergiX44\Nutgram\Handlers\Type\Command as command,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Internal\InputFile as input,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardMarkup as keyboard,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardButton as button;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command: start
|
||||||
|
*
|
||||||
|
* @package kodorvan\constructor\models\telegram\commands
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
final class start extends command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Command
|
||||||
|
*
|
||||||
|
* @var string $name Name of the command
|
||||||
|
*/
|
||||||
|
protected string $command = 'start';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description
|
||||||
|
*
|
||||||
|
* @var string $description
|
||||||
|
*/
|
||||||
|
protected ?string $description = 'Main menu';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Localizations
|
||||||
|
*
|
||||||
|
* Descriptions of the command
|
||||||
|
*
|
||||||
|
* @var array $localizedDescriptions
|
||||||
|
*/
|
||||||
|
protected array $localizedDescriptions = [
|
||||||
|
'ru' => 'Главное меню',
|
||||||
|
'*' => 'Main menu'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle
|
||||||
|
*
|
||||||
|
* Processing the command
|
||||||
|
*
|
||||||
|
* @param telegram $robot The chat-robot instance
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(telegram $robot): void
|
||||||
|
{
|
||||||
|
// Initializing the language
|
||||||
|
$language = $robot->get('language') ?? LANGUAGE_DEFAULT;
|
||||||
|
|
||||||
|
// Initializing the menu message localization
|
||||||
|
$localization = $robot->get('localization') ?? new localization($language);
|
||||||
|
|
||||||
|
// Initializing the account
|
||||||
|
$account = $robot->get('account');
|
||||||
|
|
||||||
|
// Initializing the message last update text
|
||||||
|
exec(command: 'git log --oneline $(git describe --tags --abbrev=0 @^ --always)..@ -1 --format="%at" | xargs -I{} date -d @{} "+%Y.%m.%d %H:%M"', output: $git);
|
||||||
|
$update = empty($git[0]) ? '' : "🔏 *$localization->menu_update:* " . unmarkdown($git[0]);
|
||||||
|
|
||||||
|
// Calculating amount of projects
|
||||||
|
$projects = count($account->projects());
|
||||||
|
|
||||||
|
// Calculating amount of partners
|
||||||
|
$partners = count(account::partners());
|
||||||
|
|
||||||
|
// Initializing the keyboard
|
||||||
|
$keyboard = keyboard::make();
|
||||||
|
|
||||||
|
// Writing the row into the keyboard
|
||||||
|
$keyboard->addRow(
|
||||||
|
button::make(
|
||||||
|
text: "📂 $localization->menu_button_project_new",
|
||||||
|
callback_data: 'project_create'
|
||||||
|
),
|
||||||
|
button::make(
|
||||||
|
text: "🗂 $localization->menu_button_projects: $projects",
|
||||||
|
callback_data: 'projects'
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Writing the row into the keyboard
|
||||||
|
$keyboard->addRow(
|
||||||
|
button::make(
|
||||||
|
text: "📡 $localization->menu_button_operator",
|
||||||
|
url: PROJECT_OPERATOR_URL ?? PROJECT_MEDIA_URL ?? 'https://t.me/kodorvan'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$robot->sendMessage(
|
||||||
|
text: implode(
|
||||||
|
"\n\n",
|
||||||
|
[
|
||||||
|
"📋 *$localization->menu_title*",
|
||||||
|
$projects > 0 ? printf($localization->menu_description_partner, $partners) : $localization->menu_description_guest,
|
||||||
|
$update
|
||||||
|
]
|
||||||
|
),
|
||||||
|
parse_mode: mode::MARKDOWN,
|
||||||
|
disable_notification: true,
|
||||||
|
reply_markup: $keyboard
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,469 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace kodorvan\constructor\models\telegram;
|
|
||||||
|
|
||||||
// Files of the project
|
|
||||||
use kodorvan\constructor\models\core,
|
|
||||||
kodorvan\constructor\models\account,
|
|
||||||
kodorvan\constructor\models\authorizations;
|
|
||||||
|
|
||||||
// The library for languages support
|
|
||||||
use mirzaev\languages\language;
|
|
||||||
|
|
||||||
// The library for escaping all markdown symbols
|
|
||||||
use function mirzaev\unmarkdown;
|
|
||||||
|
|
||||||
// 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\constructor\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 into 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);
|
|
||||||
|
|
||||||
if ($account instanceof account) {
|
|
||||||
// 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();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Authorizations (middleware)
|
|
||||||
*
|
|
||||||
* Initialize the account authorizations and write them into the `authorizations` variable inside the `$context`
|
|
||||||
*
|
|
||||||
* @param context $context
|
|
||||||
* @param node $next
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public static function authorizations(context $context, node $next): void
|
|
||||||
{
|
|
||||||
// Is the process stopped?
|
|
||||||
if ($context->get('stop')) return;
|
|
||||||
|
|
||||||
// Initializing the account
|
|
||||||
$account = $context->get('account');
|
|
||||||
|
|
||||||
if ($account instanceof account) {
|
|
||||||
// Initialized the account
|
|
||||||
|
|
||||||
// Initializing the account authorizations
|
|
||||||
$authorizations = $account->authorizations();
|
|
||||||
|
|
||||||
if ($authorizations instanceof authorizations) {
|
|
||||||
// Initialized the account authorizations
|
|
||||||
|
|
||||||
// Writing the account authorizations into the context variable
|
|
||||||
$context->set('authorizations', $authorizations);
|
|
||||||
|
|
||||||
// Continuation of the process
|
|
||||||
$next($context);
|
|
||||||
} else {
|
|
||||||
// Not initialized the account
|
|
||||||
|
|
||||||
// Sending the message
|
|
||||||
$context->sendMessage('⚠️ *Failed to initialize your Telegram account authorizations*')
|
|
||||||
->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();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 account) {
|
|
||||||
// Initialized the account
|
|
||||||
|
|
||||||
if ($account->language instanceof language) {
|
|
||||||
// Initialized the language parameter
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Writing the account language into the context variable
|
|
||||||
$context->set('language', $account->language);
|
|
||||||
} catch (error $error) {
|
|
||||||
// Not initialized the language
|
|
||||||
|
|
||||||
// Writing the default language into the context variable
|
|
||||||
$context->set('language', LANGUAGE_DEFAULT ?? language::en);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Not initialized the language parameter
|
|
||||||
|
|
||||||
// Writing the default language into the context variable
|
|
||||||
$context->set('language', LANGUAGE_DEFAULT ?? 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 account) {
|
|
||||||
// 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 the localization
|
|
||||||
|
|
||||||
// Writing localization into the context variable
|
|
||||||
$context->set('localization', $localization);
|
|
||||||
|
|
||||||
// Continuation of the process
|
|
||||||
$next($context);
|
|
||||||
} else {
|
|
||||||
// Not initialized the 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 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 account) {
|
|
||||||
// Initialized the account
|
|
||||||
|
|
||||||
// Initializing the account authorizations
|
|
||||||
$authorizations = $context->get('authorizations');
|
|
||||||
|
|
||||||
if ($authorizations instanceof authorizations) {
|
|
||||||
// Initialized the account authorizations
|
|
||||||
|
|
||||||
if ($authorizations->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 authorizations
|
|
||||||
|
|
||||||
// Sending the message
|
|
||||||
$context->sendMessage('⚠️ *Failed to initialize your Telegram account authorizations*')
|
|
||||||
->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 account) {
|
|
||||||
// Initialized the account
|
|
||||||
|
|
||||||
// Initializing the account authorizations
|
|
||||||
$authorizations = $context->get('authorizations');
|
|
||||||
|
|
||||||
if ($authorizations instanceof authorizations) {
|
|
||||||
// Initialized the account authorizations
|
|
||||||
|
|
||||||
if ($authorizations->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 authorizations*')
|
|
||||||
->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,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\telegram\middlewares;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\account as model,
|
||||||
|
kodorvan\constructor\models\authorizations;
|
||||||
|
|
||||||
|
// The library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// The library for escaping all markdown symbols
|
||||||
|
use function mirzaev\unmarkdown;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use SergiX44\Nutgram\Nutgram as telegram,
|
||||||
|
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use Error as error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Telegram middleware: account
|
||||||
|
*
|
||||||
|
* @package kodorvan\constructor\models\telegram\middlewares
|
||||||
|
*
|
||||||
|
* @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
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Account
|
||||||
|
*
|
||||||
|
* Initialize or registrate the account and write it into the `account` variable inside the `$robot`
|
||||||
|
*
|
||||||
|
* @param telegram $robot
|
||||||
|
* @param $next
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __invoke(telegram $robot, $next): void
|
||||||
|
{
|
||||||
|
// Is the process stopped?
|
||||||
|
if ($robot->get('stop')) return;
|
||||||
|
|
||||||
|
// Initializing the telegram account
|
||||||
|
$telegram = $robot->user();
|
||||||
|
|
||||||
|
// Initializing the account
|
||||||
|
$account = new model()->initialize(telegram: $telegram);
|
||||||
|
|
||||||
|
if ($account instanceof model) {
|
||||||
|
// Initialized the account
|
||||||
|
|
||||||
|
// Writing the account into the robot variable
|
||||||
|
$robot->set('account', $account);
|
||||||
|
|
||||||
|
// Continuation of the process
|
||||||
|
$next($robot);
|
||||||
|
} else {
|
||||||
|
// Not initialized the account
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$robot->sendMessage(
|
||||||
|
text: '⚠️ *Failed to initialize your Telegram account*',
|
||||||
|
parse_mode: mode::MARKDOWN
|
||||||
|
);
|
||||||
|
|
||||||
|
// Ending the conversation process
|
||||||
|
$robot->endConversation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\telegram\middlewares;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\account,
|
||||||
|
kodorvan\constructor\models\authorizations as model;
|
||||||
|
|
||||||
|
// The library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// The library for escaping all markdown symbols
|
||||||
|
use function mirzaev\unmarkdown;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use SergiX44\Nutgram\Nutgram as telegram,
|
||||||
|
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use Error as error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Telegram middleware: authorizations
|
||||||
|
*
|
||||||
|
* @package kodorvan\constructor\models\telegram\middlewares
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
final class authorizations
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Authorizations
|
||||||
|
*
|
||||||
|
* Initialize the account authorizations and write them into the `authorizations` variable inside the `$robot`
|
||||||
|
*
|
||||||
|
* @param telegram $robot
|
||||||
|
* @param $next
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __invoke(telegram $robot, $next): void
|
||||||
|
{
|
||||||
|
// Is the process stopped?
|
||||||
|
if ($robot->get('stop')) return;
|
||||||
|
|
||||||
|
// Initializing the account
|
||||||
|
$account = $robot->get('account');
|
||||||
|
|
||||||
|
if ($account instanceof account) {
|
||||||
|
// Initialized the account
|
||||||
|
|
||||||
|
// Initializing the account authorizations
|
||||||
|
$authorizations = $account->authorizations();
|
||||||
|
|
||||||
|
if ($authorizations instanceof model) {
|
||||||
|
// Initialized the account authorizations
|
||||||
|
|
||||||
|
// Writing the account authorizations into the robot variable
|
||||||
|
$robot->set('authorizations', $authorizations);
|
||||||
|
|
||||||
|
// Continuation of the process
|
||||||
|
$next($robot);
|
||||||
|
} else {
|
||||||
|
// Not initialized the account authorizations
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$robot->sendMessage(
|
||||||
|
text: '⚠️ *Failed to initialize your Telegram account authorizations*',
|
||||||
|
parse_mode: mode::MARKDOWN
|
||||||
|
);
|
||||||
|
|
||||||
|
// Ending the conversation process
|
||||||
|
$robot->endConversation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\telegram\middlewares;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\account,
|
||||||
|
kodorvan\constructor\models\authorizations;
|
||||||
|
|
||||||
|
// The library for languages support
|
||||||
|
use mirzaev\languages\language as type;
|
||||||
|
|
||||||
|
// The library for escaping all markdown symbols
|
||||||
|
use function mirzaev\unmarkdown;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use SergiX44\Nutgram\Nutgram as telegram,
|
||||||
|
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use Error as error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Telegram middleware: language
|
||||||
|
*
|
||||||
|
* @package kodorvan\constructor\models\telegram\middlewares
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
final class language
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Language
|
||||||
|
*
|
||||||
|
* Implement the account language
|
||||||
|
*
|
||||||
|
* @param telegram $robot
|
||||||
|
* @param $next
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __invoke(telegram $robot, $next): void
|
||||||
|
{
|
||||||
|
// Is the process stopped?
|
||||||
|
if ($robot->get('stop')) return;
|
||||||
|
|
||||||
|
// Initializing the account
|
||||||
|
$account = $robot->get('account');
|
||||||
|
|
||||||
|
if ($account instanceof account) {
|
||||||
|
// Initialized the account
|
||||||
|
|
||||||
|
if ($account->language instanceof type) {
|
||||||
|
// Initialized the language parameter
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Writing the account language into the robot variable
|
||||||
|
$robot->set('language', $account->language);
|
||||||
|
} catch (error $error) {
|
||||||
|
// Not initialized the language
|
||||||
|
|
||||||
|
// Writing the default language into the robot variable
|
||||||
|
$robot->set('language', LANGUAGE_DEFAULT ?? type::en);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Not initialized the language parameter
|
||||||
|
|
||||||
|
// Writing the default language into the robot variable
|
||||||
|
$robot->set('language', LANGUAGE_DEFAULT ?? type::en);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Continuation of the process
|
||||||
|
$next($robot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\telegram\middlewares;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\account,
|
||||||
|
kodorvan\constructor\models\localization as model,
|
||||||
|
kodorvan\constructor\models\authorizations;
|
||||||
|
|
||||||
|
// The library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// The library for escaping all markdown symbols
|
||||||
|
use function mirzaev\unmarkdown;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use SergiX44\Nutgram\Nutgram as telegram,
|
||||||
|
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use Exception as exception,
|
||||||
|
Error as error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Telegram middleware: localization
|
||||||
|
*
|
||||||
|
* @package kodorvan\constructor\models\telegram\middlewares
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
final class localization
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Localization
|
||||||
|
*
|
||||||
|
* Implement the account language and initialize the localization file
|
||||||
|
*
|
||||||
|
* @param telegram $robot
|
||||||
|
* @param $next
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __invoke(telegram $robot, $next): void
|
||||||
|
{
|
||||||
|
// Is the process stopped?
|
||||||
|
if ($robot->get('stop')) return;
|
||||||
|
|
||||||
|
// Initializing the account
|
||||||
|
$account = $robot->get('account');
|
||||||
|
|
||||||
|
if ($account instanceof account) {
|
||||||
|
// Initialized the account
|
||||||
|
|
||||||
|
// Initializing the language
|
||||||
|
$language = $robot->get('language');
|
||||||
|
|
||||||
|
if ($language instanceof language) {
|
||||||
|
// Initialized the language
|
||||||
|
|
||||||
|
// Initializing the localization
|
||||||
|
$localization = new model($language);
|
||||||
|
|
||||||
|
// Writing localization into the robot variable
|
||||||
|
$robot->set('localization', $localization);
|
||||||
|
|
||||||
|
// Continuation of the process
|
||||||
|
$next($robot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\telegram\middlewares;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\account,
|
||||||
|
kodorvan\constructor\models\authorizations;
|
||||||
|
|
||||||
|
// The library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// The library for escaping all markdown symbols
|
||||||
|
use function mirzaev\unmarkdown;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use SergiX44\Nutgram\Nutgram as telegram,
|
||||||
|
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use Error as error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Telegram middleware: language
|
||||||
|
*
|
||||||
|
* @package kodorvan\constructor\models\telegram\middlewares
|
||||||
|
*
|
||||||
|
* @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
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Settings
|
||||||
|
*
|
||||||
|
* Implement the account language
|
||||||
|
*
|
||||||
|
* @param telegram $robot
|
||||||
|
* @param $next
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __invoke(telegram $robot, $next): void
|
||||||
|
{
|
||||||
|
// Is the process stopped?
|
||||||
|
if ($robot->get('stop')) return;
|
||||||
|
|
||||||
|
// Initializing the account
|
||||||
|
$account = $robot->get('account');
|
||||||
|
|
||||||
|
if ($account instanceof account) {
|
||||||
|
// Initialized the account
|
||||||
|
|
||||||
|
// Initializing the account authorizations
|
||||||
|
$authorizations = $robot->get('authorizations');
|
||||||
|
|
||||||
|
if ($authorizations instanceof authorizations) {
|
||||||
|
// Initialized the account authorizations
|
||||||
|
|
||||||
|
if ($authorizations->settings) {
|
||||||
|
// Authorized the account to the settings
|
||||||
|
|
||||||
|
// Continuation of the process
|
||||||
|
$next($robot);
|
||||||
|
} else {
|
||||||
|
// Not authorized the account to the settings
|
||||||
|
|
||||||
|
// Initializing localization
|
||||||
|
$localization = $robot->get('localization');
|
||||||
|
|
||||||
|
if ($localization) {
|
||||||
|
// Initialized localization
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$robot->sendMessage(
|
||||||
|
text: "⛔ *$localization->not_authorized_settings*",
|
||||||
|
parse_mode: mode::MARKDOWN
|
||||||
|
);
|
||||||
|
|
||||||
|
// Ending the conversation process
|
||||||
|
$robot->endConversation();
|
||||||
|
|
||||||
|
// Stopping the process
|
||||||
|
$robot->set('stop', true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\telegram\middlewares\system;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\account,
|
||||||
|
kodorvan\constructor\models\authorizations;
|
||||||
|
|
||||||
|
// The library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// The library for escaping all markdown symbols
|
||||||
|
use function mirzaev\unmarkdown;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use SergiX44\Nutgram\Nutgram as telegram,
|
||||||
|
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use Error as error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Telegram middleware: system settings
|
||||||
|
*
|
||||||
|
* @package kodorvan\constructor\models\telegram\middlewares\system
|
||||||
|
*
|
||||||
|
* @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
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* System settings (middleware)
|
||||||
|
*
|
||||||
|
* Check the account for access to the system settings
|
||||||
|
*
|
||||||
|
* @param telegram $robot
|
||||||
|
* @param $next
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __invoke(telegram $robot, $next): void
|
||||||
|
{
|
||||||
|
// Is the process stopped?
|
||||||
|
if ($robot->get('stop')) return;
|
||||||
|
|
||||||
|
// Initializing the account
|
||||||
|
$account = $robot->get('account');
|
||||||
|
|
||||||
|
if ($account instanceof account) {
|
||||||
|
// Initialized the account
|
||||||
|
|
||||||
|
// Initializing the account authorizations
|
||||||
|
$authorizations = $robot->get('authorizations');
|
||||||
|
|
||||||
|
if ($authorizations instanceof authorizations) {
|
||||||
|
// Initialized the account authorizations
|
||||||
|
|
||||||
|
if ($authorizations->system_settings) {
|
||||||
|
// Authorized the account to the system settings
|
||||||
|
|
||||||
|
// Continuation of the process
|
||||||
|
$next($robot);
|
||||||
|
} else {
|
||||||
|
// Not authorized the account to the system settings
|
||||||
|
|
||||||
|
// Initializing localization
|
||||||
|
$localization = $robot->get('localization');
|
||||||
|
|
||||||
|
if ($localization) {
|
||||||
|
// Initialized localization
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$robot->sendMessage(
|
||||||
|
text: '⛔ *' . $localization['not_authorized_system_settings'] . '*',
|
||||||
|
parse_mode: mode::MARKDOWN
|
||||||
|
);
|
||||||
|
|
||||||
|
// Ending the conversation process
|
||||||
|
$robot->endConversation();
|
||||||
|
|
||||||
|
// Stopping the process
|
||||||
|
$robot->set('stop', true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,152 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace kodorvan\constructor\models\telegram\processes\language;
|
|
||||||
|
|
||||||
// Files of the project
|
|
||||||
use kodorvan\constructor\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\constructor\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\constructor/src/branch/stable/kodorvan/neurobot/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();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
81
kodorvan/constructor/system/models/telegram/project.php
Normal file
81
kodorvan/constructor/system/models/telegram/project.php
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\telegram;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\core,
|
||||||
|
kodorvan\constructor\models\account,
|
||||||
|
kodorvan\constructor\models\localization,
|
||||||
|
kodorvan\constructor\models\settings as model,
|
||||||
|
kodorvan\constructor\models\telegram\processes\language\select as process_language_select;
|
||||||
|
|
||||||
|
// Library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// The library for escaping all markdown symbols
|
||||||
|
use function mirzaev\unmarkdown;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use SergiX44\Nutgram\Nutgram as telegram,
|
||||||
|
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Message\Message as message,
|
||||||
|
SergiX44\Nutgram\Handlers\Type\Command as command,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Internal\InputFile as input,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardMarkup as keyboard,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardButton as button;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use Error as error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Telegram project
|
||||||
|
*
|
||||||
|
* @package kodorvan\constructor\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 project extends core
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Language
|
||||||
|
*
|
||||||
|
* Write the language into the account and the robot instance
|
||||||
|
*
|
||||||
|
* @param telegram $robot The chat-robot instance
|
||||||
|
* @param language $language The language
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function create(telegram $robot, language $language = LANGUAGE_DEFAULT): void
|
||||||
|
{
|
||||||
|
/* // Initializing the account
|
||||||
|
$account = $robot->get('account');
|
||||||
|
|
||||||
|
if ($account instanceof account) {
|
||||||
|
// Initialized the account
|
||||||
|
|
||||||
|
// Initializing the menu message localization
|
||||||
|
$localization = new localization($language);
|
||||||
|
|
||||||
|
if ($localization instanceof localization) {
|
||||||
|
// Initialized the localization
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$robot->sendMessage(
|
||||||
|
text: "✅ *$localization->settings_language_update_success:* " . trim($from->flag() . ' ' . $from->label($to)) . ' → *' . trim($to->flag() . ' ' . $to->label($to)) . '*',
|
||||||
|
parse_mode: mode::MARKDOWN,
|
||||||
|
disable_notification: true
|
||||||
|
);
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$robot->answerCallbackQuery(
|
||||||
|
text: $to->label($to),
|
||||||
|
show_alert: false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} */
|
||||||
|
}
|
||||||
|
}
|
||||||
123
kodorvan/constructor/system/models/telegram/settings.php
Normal file
123
kodorvan/constructor/system/models/telegram/settings.php
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\telegram;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\core,
|
||||||
|
kodorvan\constructor\models\account,
|
||||||
|
kodorvan\constructor\models\localization,
|
||||||
|
kodorvan\constructor\models\settings as model,
|
||||||
|
kodorvan\constructor\models\telegram\processes\language\select as process_language_select;
|
||||||
|
|
||||||
|
// Library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// The library for escaping all markdown symbols
|
||||||
|
use function mirzaev\unmarkdown;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use SergiX44\Nutgram\Nutgram as telegram,
|
||||||
|
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Message\Message as message,
|
||||||
|
SergiX44\Nutgram\Handlers\Type\Command as command,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Internal\InputFile as input,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardMarkup as keyboard,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardButton as button;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use Error as error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Telegram settings
|
||||||
|
*
|
||||||
|
* @package kodorvan\constructor\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 the language into the account and the robot instance
|
||||||
|
*
|
||||||
|
* @param telegram $robot The chat-robot instance
|
||||||
|
* @param language $language The language
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function language(telegram $robot, language $language = LANGUAGE_DEFAULT): void
|
||||||
|
{
|
||||||
|
// Initializing the account
|
||||||
|
$account = $robot->get('account');
|
||||||
|
|
||||||
|
if ($account instanceof account) {
|
||||||
|
// Initialized the account
|
||||||
|
|
||||||
|
// Initializing the menu message localization
|
||||||
|
$localization = new localization($language);
|
||||||
|
|
||||||
|
if ($localization instanceof localization) {
|
||||||
|
// Initialized the localization
|
||||||
|
|
||||||
|
// Initializing the account old language
|
||||||
|
$from = $account->language;
|
||||||
|
|
||||||
|
// Writing the language into the account
|
||||||
|
$account->language = $language;
|
||||||
|
|
||||||
|
// Serializing the account
|
||||||
|
$account->serialize();
|
||||||
|
|
||||||
|
// Writing the account into the database;
|
||||||
|
$updated = $account->update();
|
||||||
|
|
||||||
|
// Deserializing the account
|
||||||
|
$account->deserialize();
|
||||||
|
|
||||||
|
if ($updated instanceof account) {
|
||||||
|
// Writed the account into the database
|
||||||
|
|
||||||
|
// Writing the account into the robot instance
|
||||||
|
$robot->set('account', $account);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Initializing the account new language
|
||||||
|
$to = $account->language;
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$robot->sendMessage(
|
||||||
|
text: "✅ *$localization->settings_language_update_success:* " . trim($from->flag() . ' ' . $from->label($to)) . ' → *' . trim($to->flag() . ' ' . $to->label($to)) . '*',
|
||||||
|
parse_mode: mode::MARKDOWN,
|
||||||
|
disable_notification: true
|
||||||
|
);
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$robot->answerCallbackQuery(
|
||||||
|
text: $to->label($to),
|
||||||
|
show_alert: false
|
||||||
|
);
|
||||||
|
} catch (error $error) {
|
||||||
|
// Failed to send the message about language update
|
||||||
|
|
||||||
|
// Writing into the errors output buffer
|
||||||
|
error_log((string) $error);
|
||||||
|
|
||||||
|
// Sending the message
|
||||||
|
$robot->sendMessage(
|
||||||
|
text: "❎ *$localization->settings_language_update_fail*",
|
||||||
|
parse_mode: mode::MARKDOWN,
|
||||||
|
disable_notification: true
|
||||||
|
);
|
||||||
|
|
||||||
|
// Ending the conversation process
|
||||||
|
$robot->endConversation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
227
kodorvan/constructor/system/models/worker.php
Normal file
227
kodorvan/constructor/system/models/worker.php
Normal file
@@ -0,0 +1,227 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\core,
|
||||||
|
kodorvan\constructor\models\authorizations,
|
||||||
|
kodorvan\constructor\models\settings,
|
||||||
|
kodorvan\constructor\models\project,
|
||||||
|
kodorvan\constructor\models\account,
|
||||||
|
kodorvan\constructor\models\project\enumerations\type as project_type,
|
||||||
|
kodorvan\constructor\models\project\enumerations\status as project_status;
|
||||||
|
|
||||||
|
// The library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// The library for currencies support
|
||||||
|
use mirzaev\currencies\currency;
|
||||||
|
|
||||||
|
// Baza database
|
||||||
|
use mirzaev\baza\database,
|
||||||
|
mirzaev\baza\column,
|
||||||
|
mirzaev\baza\record,
|
||||||
|
mirzaev\baza\enumerations\encoding,
|
||||||
|
mirzaev\baza\enumerations\type;
|
||||||
|
|
||||||
|
// Active Record pattern
|
||||||
|
use mirzaev\record\interfaces\record as record_interface,
|
||||||
|
mirzaev\record\traits\record as record_trait;
|
||||||
|
|
||||||
|
// Svoboda time
|
||||||
|
use svoboda\time\statement as svoboda;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use SergiX44\Nutgram\Telegram\Types\User\User as telegram_user;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use Exception as exception,
|
||||||
|
RuntimeException as exception_runtime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Worker
|
||||||
|
*
|
||||||
|
* @package kodorvan\constructor\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 worker extends core implements record_interface
|
||||||
|
{
|
||||||
|
use record_trait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File
|
||||||
|
*
|
||||||
|
* @var string $file Path to the database file
|
||||||
|
*/
|
||||||
|
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'workers.baza';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database
|
||||||
|
*
|
||||||
|
* @var database $database The database
|
||||||
|
*/
|
||||||
|
public protected(set) database $database;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialized
|
||||||
|
*
|
||||||
|
* @var bool $serialized Is the implementator object serialized?
|
||||||
|
*/
|
||||||
|
private bool $serialized = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @method record|null $record The record
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(?record $record = null)
|
||||||
|
{
|
||||||
|
// Initializing the database
|
||||||
|
$this->database = new database()
|
||||||
|
->encoding(encoding::utf8)
|
||||||
|
->columns(
|
||||||
|
new column('identifier', type::long_long_unsigned),
|
||||||
|
new column('account', type::long_long_unsigned),
|
||||||
|
new column('hour', type::integer_unsigned),
|
||||||
|
new column('currency', type::string, ['length' => 3]),
|
||||||
|
new column('active', type::char),
|
||||||
|
new column('updated', type::integer_unsigned),
|
||||||
|
new column('created', type::integer_unsigned)
|
||||||
|
)
|
||||||
|
->connect($this->file);
|
||||||
|
|
||||||
|
// Initializing the record
|
||||||
|
$record instanceof record and $this->record = $record;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write
|
||||||
|
*
|
||||||
|
* @param int $account The account identifier
|
||||||
|
* @param int|float $hour Cost per hour
|
||||||
|
* @param currency|string $currency Currency of cost per hour
|
||||||
|
* @param bool $active Is the record active?
|
||||||
|
*
|
||||||
|
* @return record|false The record, if created
|
||||||
|
*/
|
||||||
|
public function write(
|
||||||
|
int $account,
|
||||||
|
int|float $hour,
|
||||||
|
currency|string $currency = CURRENCY_DEFAULT ?? currency::usd,
|
||||||
|
bool $active = true,
|
||||||
|
): record|false {
|
||||||
|
// Initializing the record
|
||||||
|
$record = $this->database->record(
|
||||||
|
$this->database->count() + 1,
|
||||||
|
(int) $account,
|
||||||
|
$hour,
|
||||||
|
$currency instanceof currency ? $currency->name : (string) $currency,
|
||||||
|
(int) $active,
|
||||||
|
svoboda::timestamp(),
|
||||||
|
svoboda::timestamp()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Writing the record into the database
|
||||||
|
$created = $this->database->write($record);
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return $created ? $record : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Account
|
||||||
|
*
|
||||||
|
* Search for the worker account
|
||||||
|
*
|
||||||
|
* @return account|null The account worker
|
||||||
|
*/
|
||||||
|
public function account(): ?account
|
||||||
|
{
|
||||||
|
// Search for the worker account
|
||||||
|
$account = new account()->read(filter: fn(record $record) => $record->active === 1 && $record->identifier === $this->account);
|
||||||
|
|
||||||
|
if ($account instanceof account) {
|
||||||
|
// Found the worker account
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return $account;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Workers
|
||||||
|
*
|
||||||
|
* Search for workers
|
||||||
|
*
|
||||||
|
* @param int $amount Amount
|
||||||
|
*
|
||||||
|
* @return array Workers
|
||||||
|
*/
|
||||||
|
public static function workers(int $amount = 100): array
|
||||||
|
{
|
||||||
|
// Search for workers and exit (success/fail)
|
||||||
|
return new static()->database->read(
|
||||||
|
filter: fn(record $record) => $record->active === 1,
|
||||||
|
amount: $amount
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize
|
||||||
|
*
|
||||||
|
* @return self The instance from which the method was called (fluent interface)
|
||||||
|
*/
|
||||||
|
public function serialize(): self
|
||||||
|
{
|
||||||
|
if ($this->serialized) {
|
||||||
|
// The record implementor is serialized
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception_runtime('The record implementor is already serialized');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Serializing the record parameters
|
||||||
|
$this->record->currency = $this->record->currency->name;
|
||||||
|
$this->record->active = (int) $this->record->active;
|
||||||
|
|
||||||
|
// Writing the status of serializing
|
||||||
|
$this->serialized = true;
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deserialize
|
||||||
|
*
|
||||||
|
* @return self The instance from which the method was called (fluent interface)
|
||||||
|
*/
|
||||||
|
public function deserialize(): self
|
||||||
|
{
|
||||||
|
if (!$this->serialized) {
|
||||||
|
// The record implementor is deserialized
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception_runtime('The record implementor is already deserialized');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deserializing the record parameters
|
||||||
|
$this->record->currency = currency::{$this->record->currency} ?? CURRENCY_DEFAULT ?? currency::usd;
|
||||||
|
$this->record->active = (bool) $this->record->active;
|
||||||
|
|
||||||
|
// Writing the status of serializing
|
||||||
|
$this->serialized = false;
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\worker\enumerations;
|
||||||
|
|
||||||
|
// The library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use InvalidArgumentException as exception_argument,
|
||||||
|
DomainException as exception_domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type
|
||||||
|
*
|
||||||
|
* @package kodorvan\neurobot\models\worker\enumerations
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
enum type
|
||||||
|
{
|
||||||
|
case programmer;
|
||||||
|
case designer;
|
||||||
|
case booster;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Label
|
||||||
|
*
|
||||||
|
* @param language $language The language
|
||||||
|
*
|
||||||
|
* @return string The project architecture label
|
||||||
|
*/
|
||||||
|
public function label(language $language = LANGUAGE_DEFAULT): string
|
||||||
|
{
|
||||||
|
// Exit (success)
|
||||||
|
return match ($this) {
|
||||||
|
static::programmer => match ($language) {
|
||||||
|
language::en => 'Programmer',
|
||||||
|
language::ru => 'Программист'
|
||||||
|
},
|
||||||
|
static::designer => match ($language) {
|
||||||
|
language::en => 'Designer',
|
||||||
|
language::ru => 'Дизайнер'
|
||||||
|
},
|
||||||
|
static::booster => match ($language) {
|
||||||
|
language::en => 'Booster',
|
||||||
|
language::ru => 'Бустер'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ namespace kodorvan\constructor;
|
|||||||
// Files of the project
|
// Files of the project
|
||||||
use kodorvan\constructor\models\account,
|
use kodorvan\constructor\models\account,
|
||||||
kodorvan\constructor\models\telegram\middlewares,
|
kodorvan\constructor\models\telegram\middlewares,
|
||||||
kodorvan\constructor\models\telegram\commands,
|
kodorvan\constructor\models\telegram\commands\start,
|
||||||
kodorvan\constructor\models\telegram\settings;
|
kodorvan\constructor\models\telegram\settings;
|
||||||
|
|
||||||
// Library for languages support
|
// Library for languages support
|
||||||
@@ -18,9 +18,10 @@ use mirzaev\minimal\core,
|
|||||||
mirzaev\minimal\route;
|
mirzaev\minimal\route;
|
||||||
|
|
||||||
// Framework for Telegram
|
// Framework for Telegram
|
||||||
use Zanzara\Zanzara as zanzara,
|
use SergiX44\Nutgram\Nutgram as telegram,
|
||||||
Zanzara\Context as context,
|
SergiX44\Nutgram\Configuration as telegram_settings,
|
||||||
Zanzara\Config as config;
|
SergiX44\Nutgram\RunningMode\Webhook as webhook,
|
||||||
|
SergiX44\Nutgram\Telegram\Types\Internal\InputFile as input;
|
||||||
|
|
||||||
// Enabling debugging
|
// Enabling debugging
|
||||||
/* ini_set('error_reporting', E_ALL);
|
/* ini_set('error_reporting', E_ALL);
|
||||||
@@ -28,7 +29,7 @@ ini_set('display_errors', 1);
|
|||||||
ini_set('display_startup_errors', 1); */
|
ini_set('display_startup_errors', 1); */
|
||||||
|
|
||||||
// Initializing path to the public directory
|
// Initializing path to the public directory
|
||||||
define('INDEX', __DIR__);
|
define('INDEX', __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..');
|
||||||
|
|
||||||
// Initializing path to the project root directory
|
// Initializing path to the project root directory
|
||||||
define('ROOT', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
|
define('ROOT', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
|
||||||
@@ -52,45 +53,24 @@ define('DATABASES', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '
|
|||||||
define('LOCALIZATIONS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'localizations');
|
define('LOCALIZATIONS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'localizations');
|
||||||
|
|
||||||
// Initiailizing Telegram chat-robot settings
|
// Initiailizing Telegram chat-robot settings
|
||||||
require(SETTINGS . DIRECTORY_SEPARATOR . 'telegram.php');
|
define('TELEGRAM', require(SETTINGS . DIRECTORY_SEPARATOR . 'telegram.php'));
|
||||||
|
|
||||||
// Initializing dependencies
|
// Initializing dependencies
|
||||||
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||||
|
|
||||||
// Initializing the configuration
|
|
||||||
$config = new config();
|
|
||||||
$config->setParseMode(config::PARSE_MODE_MARKDOWN);
|
|
||||||
$config->useReactFileSystem(true);
|
|
||||||
|
|
||||||
// Initializing the robot
|
// Initializing the robot
|
||||||
$robot = new Zanzara(ROBOT['key'], $config);
|
$robot = new telegram(
|
||||||
|
token: TELEGRAM['key'],
|
||||||
|
config: new telegram_settings(
|
||||||
|
botName: TELEGRAM['name']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// Initializing the updates listener
|
$robot->setWebhook(
|
||||||
$robot->onUpdate(function (context $context): void {});
|
url: 'https://' . PROJECT_DOMAIN . '/telegram/constructor/webhook.php',
|
||||||
|
certificate: new input(resource: PROJECT_CERTIFICATE),
|
||||||
// Initializing the robot middlewares
|
ip_address: SERVER_IP_ADDRESS,
|
||||||
$robot->middleware([middlewares::class, 'account']);
|
max_connections: 10,
|
||||||
$robot->middleware([middlewares::class, 'language']);
|
drop_pending_updates: false,
|
||||||
$robot->middleware([middlewares::class, 'localization']);
|
secret_token: TELEGRAM['password']
|
||||||
$robot->middleware([middlewares::class, 'authorizations']);
|
);
|
||||||
|
|
||||||
// Initializing the robot commands handlers
|
|
||||||
$robot->onCommand('start', [commands::class, 'start']);
|
|
||||||
|
|
||||||
$robot->onCommand('start telegram voronka', [commands::class, 'start']);
|
|
||||||
$robot->onCommand('start parser', [commands::class, 'start']);
|
|
||||||
$robot->onCommand('start calculator', [commands::class, 'start']);
|
|
||||||
|
|
||||||
$robot->onCommand('language', [commands::class, 'language'])->middleware([middlewares::class, 'settings']);
|
|
||||||
$robot->onCommand('society', [commands::class, 'society']);
|
|
||||||
|
|
||||||
// Initializing the robot settings language buttons handlers
|
|
||||||
foreach (language::cases() as $language) {
|
|
||||||
// Iterating over languages
|
|
||||||
|
|
||||||
// Initializing language buttons
|
|
||||||
$robot->onCbQueryData(["settings_language_$language->name"], fn(context $context) => settings::language($context, $language));
|
|
||||||
};
|
|
||||||
|
|
||||||
// Starting chat-robot
|
|
||||||
$robot->run();
|
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\account,
|
||||||
|
kodorvan\constructor\models\telegram\settings,
|
||||||
|
kodorvan\constructor\models\telegram\commands\start as command_start,
|
||||||
|
kodorvan\constructor\models\telegram\commands\account as command_account,
|
||||||
|
kodorvan\constructor\models\telegram\commands\society as command_society,
|
||||||
|
kodorvan\constructor\models\telegram\commands\language as command_language,
|
||||||
|
kodorvan\constructor\models\telegram\conversations\project\create as conversation_project_create,
|
||||||
|
kodorvan\constructor\models\telegram\middlewares\account as middleware_account,
|
||||||
|
kodorvan\constructor\models\telegram\middlewares\language as middleware_language,
|
||||||
|
kodorvan\constructor\models\telegram\middlewares\localization as middleware_localization,
|
||||||
|
kodorvan\constructor\models\telegram\middlewares\settings as middleware_settings,
|
||||||
|
kodorvan\constructor\models\telegram\middlewares\authorizations as middleware_authorizations;
|
||||||
|
|
||||||
|
// Library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// Framework for PHP
|
||||||
|
use mirzaev\minimal\core,
|
||||||
|
mirzaev\minimal\route;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use SergiX44\Nutgram\Nutgram as telegram,
|
||||||
|
SergiX44\Nutgram\Configuration as telegram_settings,
|
||||||
|
SergiX44\Nutgram\RunningMode\Webhook as webhook;
|
||||||
|
|
||||||
|
// The symphony cache library
|
||||||
|
use Symfony\Component\Cache\Adapter\FilesystemAdapter as cache_adapter,
|
||||||
|
Symfony\Component\Cache\Psr16Cache as cache;
|
||||||
|
|
||||||
|
// Enabling debugging
|
||||||
|
/* 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__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..');
|
||||||
|
|
||||||
|
// Initializing path to the project root directory
|
||||||
|
define('ROOT', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
|
||||||
|
|
||||||
|
// Initializing path to the directory of views
|
||||||
|
define('VIEWS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'views');
|
||||||
|
|
||||||
|
// Initializing path to the directory of settings
|
||||||
|
define('SETTINGS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'settings');
|
||||||
|
|
||||||
|
// Initializing system settings
|
||||||
|
require SETTINGS . DIRECTORY_SEPARATOR . 'system.php';
|
||||||
|
|
||||||
|
// Initializing path to the directory of the storage
|
||||||
|
define('STORAGE', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'storage');
|
||||||
|
|
||||||
|
// Initializing path to the databases directory
|
||||||
|
define('DATABASES', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'databases');
|
||||||
|
|
||||||
|
// Initializing path to the localizations directory
|
||||||
|
define('LOCALIZATIONS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'localizations');
|
||||||
|
|
||||||
|
// Initiailizing Telegram chat-robot settings
|
||||||
|
define('TELEGRAM', require(SETTINGS . DIRECTORY_SEPARATOR . 'telegram.php'));
|
||||||
|
|
||||||
|
// Initializing dependencies
|
||||||
|
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||||
|
|
||||||
|
// Initializing the robot
|
||||||
|
$robot = new telegram(
|
||||||
|
token: TELEGRAM['key'],
|
||||||
|
config: new telegram_settings(
|
||||||
|
botName: TELEGRAM['name'],
|
||||||
|
cache: new cache(new cache_adapter())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$webhook = new webhook(secretToken: TELEGRAM['password']);
|
||||||
|
$webhook->setSafeMode(true);
|
||||||
|
|
||||||
|
$robot->setRunningMode($webhook);
|
||||||
|
|
||||||
|
$robot->middleware(middleware_account::class);
|
||||||
|
$robot->middleware(middleware_language::class);
|
||||||
|
$robot->middleware(middleware_localization::class);
|
||||||
|
$robot->middleware(middleware_authorizations::class);
|
||||||
|
|
||||||
|
// Start
|
||||||
|
$robot->registerCommand(command_start::class);
|
||||||
|
$robot->onCommand('start telegram voronka', command_start::class);
|
||||||
|
$robot->onCommand('start parser', command_start::class);
|
||||||
|
$robot->onCommand('start calculator', command_start::class);
|
||||||
|
|
||||||
|
// Account
|
||||||
|
$robot->registerCommand(command_account::class);
|
||||||
|
|
||||||
|
// Language
|
||||||
|
$robot->registerCommand(command_language::class)->middleware(middleware_settings::class);
|
||||||
|
foreach (language::cases() as $language) {
|
||||||
|
// Iterating over languages
|
||||||
|
|
||||||
|
// Select the language
|
||||||
|
$robot->onCallbackQueryData('settings_language_$language->name', fn(telegram $robot) => settings::language(robot: $robot, language: $language));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Society
|
||||||
|
$robot->registerCommand(command_society::class);
|
||||||
|
|
||||||
|
// Project: create
|
||||||
|
$robot->onCallbackQueryData('project_create', conversation_project_create::class);
|
||||||
|
|
||||||
|
$robot->run();
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
*
|
*
|
||||||
!.gitignore
|
!.gitignore
|
||||||
!*.sample
|
!*.sample
|
||||||
|
!*/
|
||||||
|
!*.md
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
openssl req -newkey rsa:2048 -sha256 -nodes -keyout private.key -x509 -days 365 -out public.pem -subj "/C=US/ST=New York/L=Brooklyn/O=Example Brooklyn Company/CN=Sex"
|
||||||
@@ -3,13 +3,40 @@
|
|||||||
// The library for languages support
|
// The library for languages support
|
||||||
use mirzaev\languages\language;
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// The library for currencies support
|
||||||
|
use mirzaev\currencies\currency;
|
||||||
|
|
||||||
// Initializing dependencies
|
// Initializing dependencies
|
||||||
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||||
|
|
||||||
define('PROJECT_NAME', '');
|
define('SERVER_IP_ADDRESS', '5.140.110.25');
|
||||||
define('PROJECT_DOMAIN', '');
|
|
||||||
|
|
||||||
|
define('REPOSITORY', 'https://git.svoboda.works');
|
||||||
|
|
||||||
|
define('PROJECT_CREATOR', 'kodorvan');
|
||||||
|
define('PROJECT_NAME', 'constructor');
|
||||||
|
define('PROJECT_DOMAIN', 'constructor.kodorvan.tech');
|
||||||
|
define('PROJECT_CERTIFICATE', SETTINGS . DIRECTORY_SEPARATOR . 'certificate' . DIRECTORY_SEPARATOR . 'public.pem');
|
||||||
|
define('PROJECT_MEDIA_URL', 'https://t.me/kodorvan');
|
||||||
|
define('PROJECT_OPERATOR_URL', 'https://t.me/kodorvan?direct');
|
||||||
|
define('PROJECT_REPOSITORY', REPOSITORY . '/' . PROJECT_CREATOR . '/' . PROJECT_NAME);
|
||||||
|
define('PROJECT_REPOSITORY_LANGUAGE_ADD', PROJECT_REPOSITORY . '/src/branch/stable/' . PROJECT_CREATOR . '/' . PROJECT_NAME . '/system/localizations');
|
||||||
|
|
||||||
|
define('CURRENCY_DEFAULT', currency::usd);
|
||||||
define('LANGUAGE_DEFAULT', language::en);
|
define('LANGUAGE_DEFAULT', language::en);
|
||||||
|
|
||||||
|
define('PROJECT_CREATE_START_HOURS', 1);
|
||||||
|
define('PROJECT_CREATE_START_COEFFICIENT', 0);
|
||||||
|
define('PROJECT_CREATE_HOURS_ADDITIONAL', 0);
|
||||||
|
define('PROJECT_CREATE_HOURS_MINIMAL', 4);
|
||||||
|
define('PROJECT_CREATE_DAY_HOURS', 4);
|
||||||
|
define('PROJECT_CREATE_DAY_ADDITIONAL', 1);
|
||||||
|
define('PROJECT_CREATE_COST_HOUR_DEFAULT', 20);
|
||||||
|
define('PROJECT_CREATE_COST_CURRENCY', CURRENCY_DEFAULT);
|
||||||
|
|
||||||
|
define('PROJECT_CREATE_REQUEST_RECEIVERS', [
|
||||||
|
'-0000000000000'
|
||||||
|
]);
|
||||||
|
|
||||||
// Initializing default theme for the views templater
|
// Initializing default theme for the views templater
|
||||||
define('THEME', 'default');
|
define('THEME', 'default');
|
||||||
|
|||||||
@@ -1,7 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Robot
|
// Telegram API chat-robot
|
||||||
define('ROBOT', [
|
return [
|
||||||
'identifier' => null,
|
'identifier' => 0,
|
||||||
'key' => ''
|
'domain' => 'kodorvan_bot',
|
||||||
]);
|
'name' => 'kodorvan',
|
||||||
|
'password' => '',
|
||||||
|
'key' => '',
|
||||||
|
'database' => [
|
||||||
|
'host' => '/run/mysqld/mysqld.sock',
|
||||||
|
'port' => 3306,
|
||||||
|
'user' => '',
|
||||||
|
'password' => '',
|
||||||
|
'database' => '',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
2
logs/.gitignore
vendored
Normal file
2
logs/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
Reference in New Issue
Block a user