generated from mirzaev/pot
distributions registration; resolved #11, resolved #16, resolved #18, resolved #19, resolved #21, resolved #27
This commit is contained in:
parent
845a9d04e0
commit
6af2a441a6
|
@ -27,7 +27,8 @@
|
|||
"mirzaev/minimal": "^3.4.0",
|
||||
"badfarm/zanzara": "^0.9.1",
|
||||
"react/filesystem": "^0.1.2",
|
||||
"mirzaev/baza": "^3.1.0"
|
||||
"mirzaev/baza": "^3.1.0",
|
||||
"svoboda/time": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~9.5"
|
||||
|
|
|
@ -4,23 +4,86 @@
|
|||
return [
|
||||
// System
|
||||
'svoboda' => 'Svoboda',
|
||||
'empty' => 'Empty',
|
||||
|
||||
// Settings
|
||||
'settings_language_title' => 'Language',
|
||||
'settings_language_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',
|
||||
|
||||
// Distribution selection
|
||||
'select_distributions_title' => 'Select distribution',
|
||||
'select_distributions_description' => 'The selected distribution will be used in the current process',
|
||||
'select_distribution_button_registrate' => 'Registrate a distribution',
|
||||
|
||||
// Language setting
|
||||
'settings_select_language_title' => 'Select language',
|
||||
'settings_select_language_description' => 'The selected language will be writed in your account settings',
|
||||
'settings_language_update_success' => 'Language replaced:',
|
||||
'settings_language_update_fail' => 'Failed to replace language',
|
||||
|
||||
// Authorizing
|
||||
// Distributions
|
||||
'distributions_title' => 'Registry of distributions',
|
||||
'distributions_description' => '*Distribution* is an autonomous cell of Svoboda, representing any type of formation \(for example: commune\), but necessarily inherits the *Vhod* protocol and tied to a location',
|
||||
'distributions_registered' => 'Registered',
|
||||
'distributions_button_search' => 'Search',
|
||||
'distributions_button_register' => 'Registrate',
|
||||
|
||||
// Distribution registration
|
||||
'distribution_registration_started' => 'Process of the distribution registration started',
|
||||
'distribution_registration_not_started' => 'Process of the distribution registration has not started',
|
||||
'distribution_registration_continiued' => 'Process of the distribution registration found and continiued',
|
||||
'distribution_registration_generation' => 'The distribution record generation',
|
||||
'distribution_registration_created_distribution' => 'Created the distribution record in the database',
|
||||
'distribution_registration_created_localization' => 'Created the distribution localization record in the database',
|
||||
'distribution_registration_canceled' => 'Process of the distribution registration canceled',
|
||||
'distribution_registration_completed' => 'Process of the distribution registration completed',
|
||||
'distribution_registration_not_created_distribution' => 'Failed to create the distribution record in the database',
|
||||
'distribution_registration_not_created_localization' => 'Failed to create the distribution localization record in the database',
|
||||
'distribution_registration_button_language' => 'Language',
|
||||
'distribution_registration_select_language_title' => 'Choose language',
|
||||
'distribution_registration_select_language_description' => "The selected language will create a localization for users with the same language\n\nYou can create 1 localization for each language",
|
||||
'distribution_registration_language_update_success' => 'Language replaced:',
|
||||
'distribution_registration_language_update_fail' => 'Failed to replace language',
|
||||
'distribution_registration_button_name' => 'Name',
|
||||
'distribution_registration_name_request' => 'Enter name',
|
||||
'distribution_registration_name_request_not_acceptable' => 'Failed to process the name',
|
||||
'distribution_registration_name_request_too_short' => 'Name length must be \>\= 3 and \<\= 32',
|
||||
'distribution_registration_name_request_too_long' => 'Name length must be \>\= 3 and \<\= 32',
|
||||
'distribution_registration_name_request_spaces' => "No more than 2 spaces are allowed",
|
||||
'distribution_registration_name_request_restricted_characters_title' => "Restricted any characters except letters",
|
||||
'distribution_registration_name_request_restricted_characters_description' => "Remove these characters:",
|
||||
'distribution_registration_name_update_success' => 'Name replaced:',
|
||||
'distribution_registration_name_update_fail' => 'Failed to replace name',
|
||||
'distribution_registration_button_location' => 'Location',
|
||||
'distribution_registration_button_location_send' => 'Send location',
|
||||
'distribution_registration_location_send_title' => 'Send location',
|
||||
'distribution_registration_location_send_description' => "You now have a button on your main keyboard\nWhen you click on it, you can select a location on the map\n\n*Send latitude and longitude in the format:* 50\.969043, 9\.797588",
|
||||
'distribution_registration_location_send_not_acceptable' => 'Failed to process the location',
|
||||
'distribution_registration_location_send_latitude_too_small' => 'Latitude must be \>\= 0 and \<\=90',
|
||||
'distribution_registration_location_send_latitude_too_big' => 'Latitude must be \>\= 0 and \<\=90',
|
||||
'distribution_registration_location_send_longitude_too_small' => 'Longitude must be \>\= 0 and \<\=180',
|
||||
'distribution_registration_location_send_longitude_too_big' => 'Longitude must be \>\= 0 and \<\=180',
|
||||
'distribution_registration_location_update_success' => 'Location replaced:',
|
||||
'distribution_registration_location_update_fail' => 'Failed to replace location',
|
||||
'distribution_registration_button_confirm' => 'Confirm',
|
||||
'distribution_registration_button_cancel' => 'Cancel',
|
||||
|
||||
// Distribution localization
|
||||
'distribution_localization_started' => 'Registration of the distribution process started',
|
||||
'distribution_localization_continiued' => 'Registration of the distribution process found and continiued',
|
||||
'distribution_localization_created' => 'Created the distribution localization record in the database',
|
||||
'distribution_localization_not_created' => 'Failed to create the distribution localization record in the database',
|
||||
'distribution_localization_select_language_title' => 'Choose language',
|
||||
'distribution_localization_select_language_description' => "The selected language will create a localization for users with the same language\n\nYou can create 1 localization for each language",
|
||||
|
||||
// Authorization
|
||||
'not_authorized_system' => 'You do not have access to the system',
|
||||
'not_authorized_contact' => 'You do not have access to contact with the organisation',
|
||||
'not_authorized_request' => 'You do not have access to requesting to the organisation',
|
||||
'not_authorized_settings' => 'You do not have access to the settings',
|
||||
'not_authorized_system_settings' => 'You do not have access to the system settings',
|
||||
|
||||
// Errors
|
||||
'not_initialized_account' => '',
|
||||
|
||||
// Other
|
||||
'why_so_shroomious' => 'why so shroomious',
|
||||
];
|
||||
|
|
|
@ -4,13 +4,79 @@
|
|||
return [
|
||||
// Система
|
||||
'svoboda' => 'Свобода',
|
||||
'empty' => 'Пусто',
|
||||
|
||||
// Выбор языка
|
||||
'select_language_title' => 'Выбери язык',
|
||||
'select_language_description' => 'Выбранный язык будет использован в текущем процессе',
|
||||
'select_language_button_add' => 'Добавить язык',
|
||||
|
||||
// Выбор дистрибутива
|
||||
'select_distributions_title' => 'Выбери дистрибутив',
|
||||
'select_distributions_description' => 'Выбранный дистрибутив будет использован в текущем процесса',
|
||||
'select_distribution_button_registrate' => 'Зарегистрировать дистрибутив',
|
||||
|
||||
// Настройки
|
||||
'settings_language_title' => 'Язык',
|
||||
'settings_language_add' => 'Добавить язык',
|
||||
'settings_select_language_title' => 'Выбери язык',
|
||||
'settings_select_language_description' => 'Выбранный язык будет записан в настройки аккаунта',
|
||||
'settings_language_update_success' => 'Язык заменён:',
|
||||
'settings_language_update_fail' => 'Не удалось заменить язык',
|
||||
|
||||
// Дистрибутивы
|
||||
'distributions_title' => 'Реестр дистрибутивов',
|
||||
'distributions_description' => '*Дистрибутив* \- это автономная ячейка Свободы, являющаяся любым видом формирования \(например: коммуна\), но обязательно наследующая *Vhod* протокол, участвующая в глобальных процессах организации и привязанная к местоположению',
|
||||
'distributions_registered' => 'Зарегистрировано',
|
||||
'distributions_button_search' => 'Поиск',
|
||||
'distributions_button_register' => 'Зарегистрировать',
|
||||
|
||||
// Регистрация дистрибутива
|
||||
'distribution_registration_started' => 'Процесс регистрации дистрибутива запущен',
|
||||
'distribution_registration_not_started' => 'Процесс регистрации дистрибутива не запущен',
|
||||
'distribution_registration_continiued' => 'Процесс регистрации дистрибутива найден и продолжен',
|
||||
'distribution_registration_generation' => 'Генерация записи дистрибутива',
|
||||
'distribution_registration_created_distribution' => 'Создана запись дистрибутива в базе данных',
|
||||
'distribution_registration_created_localization' => 'Создана запись локализации дистрибутива в базе данных',
|
||||
'distribution_registration_canceled' => 'Процесс регистрации дистрибутива отменён',
|
||||
'distribution_registration_completed' => 'Процесс регистрации дистрибутива завершен',
|
||||
'distribution_registration_not_created_distribution' => 'Не удалось создать запись дистрибутива в базе данных',
|
||||
'distribution_registration_not_created_localization' => 'Не удалось создать запись локализации дистрибутива в базе данных',
|
||||
'distribution_registration_button_language' => 'Язык',
|
||||
'distribution_registration_select_language_title' => 'Выбери язык',
|
||||
'distribution_registration_select_language_description' => "Выбранный язык позволит создать локализацию для пользователей с таким же языком\n\nТы можешь создать 1 локализацию для каждого языка",
|
||||
'distribution_registration_language_update_success' => 'Язык заменён:',
|
||||
'distribution_registration_language_update_fail' => 'Не удалось заменить язык',
|
||||
'distribution_registration_button_name' => 'Название',
|
||||
'distribution_registration_name_request' => 'Введите название',
|
||||
'distribution_registration_name_request_not_acceptable' => 'Не удалось обработать название',
|
||||
'distribution_registration_name_request_too_short' => 'Длина имени должна быть \>\= 3 и \<\= 32',
|
||||
'distribution_registration_name_request_too_long' => 'Длина имени должна быть \>\= 3 и \<\= 32',
|
||||
'distribution_registration_name_request_spaces' => "Разрешено использовать не более чем 2 пробела",
|
||||
'distribution_registration_name_request_restricted_characters_title' => "Запрещены любые символы кроме букв",
|
||||
'distribution_registration_name_request_restricted_characters_description' => "Удалите эти символы:",
|
||||
'distribution_registration_name_update_success' => 'Название заменено:',
|
||||
'distribution_registration_name_update_fail' => 'Не удалось заменить название',
|
||||
'distribution_registration_button_location' => 'Местоположение',
|
||||
'distribution_registration_button_location_send' => 'Отправить местоположение',
|
||||
'distribution_registration_location_send_title' => 'Отправь местоположение',
|
||||
'distribution_registration_location_send_description' => "У тебя появилась кнопка на основной клавиатуре\nПри нажатии на неё можно будет выбрать локацию на карте\n\n*Пришли широту и долготу в формате:* 50\.969043, 9\.797588",
|
||||
'distribution_registration_location_send_not_acceptable' => 'Не удалось обработать местоположение',
|
||||
'distribution_registration_location_send_latitude_too_small' => 'Широта должна быть \>\= 0 и \<\=90',
|
||||
'distribution_registration_location_send_latitude_too_big' => 'Широта должна быть \>\= 0 и \<\=90',
|
||||
'distribution_registration_location_send_longitude_too_small' => 'Долгота должна быть \>\= 0 и \<\=180',
|
||||
'distribution_registration_location_send_longitude_too_big' => 'Долгота должна быть \>\= 0 и \<\=180',
|
||||
'distribution_registration_location_update_success' => 'Местоположение заменено:',
|
||||
'distribution_registration_location_update_fail' => 'Не удалось заменить местоположение',
|
||||
'distribution_registration_button_confirm' => 'Подтвердить',
|
||||
'distribution_registration_button_cancel' => 'Отменить',
|
||||
|
||||
// Локализация дистрибутива
|
||||
'distribution_localization_started' => 'Запущен процесс локализации дистрибутива',
|
||||
'distribution_localization_continiued' => 'Найден и продолжен процесс локализации дистрибутива',
|
||||
'distribution_localization_created' => 'Создана запись локализации дистрибутива в базе данных',
|
||||
'distribution_localization_not_created' => 'Не удалось создать запись локализации дистрибутива в базе данных',
|
||||
'distribution_localization_select_language_title' => 'Выбери язык',
|
||||
'distribution_localization_select_language_description' => "Выбранный язык позволит создать локализацию для пользователей с таким же языком\n\nТы можешь создать 1 локализацию для каждого языка",
|
||||
|
||||
// Авторизация
|
||||
'not_authorized_system' => 'У тебя нет доступа к системе',
|
||||
'not_authorized_contact' => 'У тебя нет доступа к коммуникации с организацией',
|
||||
|
@ -18,9 +84,6 @@ return [
|
|||
'not_authorized_settings' => 'У тебя нет доступа к настройкам',
|
||||
'not_authorized_system_settings' => 'У тебя нет доступа к системным настройкам',
|
||||
|
||||
// Ошибки
|
||||
'not_initialized_account' => '',
|
||||
|
||||
// Прочее
|
||||
'why_so_shroomious' => 'почему такой грибъёзный',
|
||||
];
|
||||
|
|
|
@ -7,6 +7,9 @@ namespace svoboda\negotiator\models;
|
|||
// Files of the project
|
||||
use svoboda\negotiator\models\core;
|
||||
|
||||
// Svoboda time
|
||||
use svoboda\time\statement as svoboda;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\database,
|
||||
mirzaev\baza\column,
|
||||
|
@ -34,7 +37,7 @@ final class account extends core
|
|||
/**
|
||||
* File
|
||||
*
|
||||
* @var string $database Path to the accounts database file
|
||||
* @var string $database Path to the database file
|
||||
*/
|
||||
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'accounts.baza';
|
||||
|
||||
|
@ -43,7 +46,7 @@ final class account extends core
|
|||
*
|
||||
* @var database $database The database
|
||||
*/
|
||||
public static database $database;
|
||||
public protected(set) database $database;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -53,20 +56,23 @@ final class account extends core
|
|||
public function __construct()
|
||||
{
|
||||
// Initializing the database
|
||||
static::$database = new database()
|
||||
$this->database = new database()
|
||||
->encoding(encoding::utf8)
|
||||
->columns(
|
||||
new column('identifier', type::integer_unsigned),
|
||||
new column('identifier_telegram', type::integer),
|
||||
new column('domain', type::string, ['length' => 32]),
|
||||
new column('name_first', type::string, ['length' => 64]),
|
||||
new column('name_second', type::string, ['length' => 64]),
|
||||
new column('domain', type::string, ['length' => 32]),
|
||||
new column('language', type::string, ['length' => 2]),
|
||||
new column('robot', type::char),
|
||||
new column('authorized_system', type::char),
|
||||
new column('authorized_contact', type::char),
|
||||
new column('authorized_request', type::char),
|
||||
new column('authorized_settings', type::char),
|
||||
new column('authorized_system_settings', type::char)
|
||||
new column('authorized_system_settings', type::char),
|
||||
new column('created', type::integer_unsigned),
|
||||
new column('updated', type::integer_unsigned)
|
||||
)
|
||||
->connect($this->file);
|
||||
}
|
||||
|
@ -87,7 +93,7 @@ final class account extends core
|
|||
public function initialize(telegram $telegram): record
|
||||
{
|
||||
// Searching for the account in the database
|
||||
$account = static::$database->read(filter: fn(record $record) => $record->identifier === $telegram->getId(), amount: 1)[0] ?? null;
|
||||
$account = $this->database->read(filter: fn(record $record) => $record->identifier_telegram === $telegram->getId(), amount: 1)[0] ?? null;
|
||||
|
||||
if ($account instanceof record) {
|
||||
// Found the account record
|
||||
|
@ -100,13 +106,14 @@ final class account extends core
|
|||
// The telegram account was updated
|
||||
|
||||
// Updating the account in the database
|
||||
$updated = static::$database->read(
|
||||
filter: fn(record $record) => $record->identifier === $telegram->getId(),
|
||||
$updated = $this->database->read(
|
||||
filter: fn(record $record) => $record->identifier_telegram === $telegram->getId(),
|
||||
update: function (record &$record) use ($telegram){
|
||||
// Writing new values into the record
|
||||
$record->name_first = $telegram->getFirstName();
|
||||
$record->name_second = $telegram->getLastName();
|
||||
$record->domain = $telegram->getUsername();
|
||||
$record->updated = svoboda::timestamp();
|
||||
},
|
||||
amount: 1
|
||||
)[0] ?? null;
|
||||
|
@ -133,7 +140,7 @@ final class account extends core
|
|||
// Registered the account
|
||||
|
||||
// Searching for the registered account in the database
|
||||
$account = static::$database->read(filter: fn(record $record) => $record->identifier === $telegram->getId(), amount: 1)[0] ?? null;
|
||||
$account = $this->database->read(filter: fn(record $record) => $record->identifier_telegram === $telegram->getId(), amount: 1)[0] ?? null;
|
||||
|
||||
if ($account instanceof record) {
|
||||
// Found the registered account
|
||||
|
@ -162,12 +169,16 @@ final class account extends core
|
|||
*
|
||||
* @param telegram $telegram The telegram account
|
||||
*
|
||||
* @return bool Is the accound record created?
|
||||
* @return int|false The record identifier, if created
|
||||
*/
|
||||
public function registrate(telegram $telegram): bool
|
||||
public function registrate(telegram $telegram): int|false
|
||||
{
|
||||
// Initializing the identifier
|
||||
$identifier = $this->database->count() + 1;
|
||||
|
||||
// Initializing the record
|
||||
$record = static::$database->record(
|
||||
$record = $this->database->record(
|
||||
$identifier,
|
||||
(int) $telegram->getId(),
|
||||
$telegram->getFirstName(),
|
||||
$telegram->getLastName(),
|
||||
|
@ -178,13 +189,15 @@ final class account extends core
|
|||
1,
|
||||
1,
|
||||
1,
|
||||
0
|
||||
0,
|
||||
svoboda::timestamp(),
|
||||
svoboda::timestamp()
|
||||
);
|
||||
|
||||
// Creating the accound record in the database
|
||||
$created = static::$database->write($record);
|
||||
$created = $this->database->write($record);
|
||||
|
||||
// Exit (success)
|
||||
return $created;
|
||||
return $created ? $identifier : false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace svoboda\negotiator\models;
|
||||
|
||||
// Files of the project
|
||||
use svoboda\negotiator\models\core;
|
||||
|
||||
// Svoboda time
|
||||
use svoboda\time\statement as svoboda;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\database,
|
||||
mirzaev\baza\column,
|
||||
mirzaev\baza\record,
|
||||
mirzaev\baza\enumerations\encoding,
|
||||
mirzaev\baza\enumerations\type;
|
||||
|
||||
// Framework for Telegram
|
||||
use Zanzara\Telegram\Type\User as telegram;
|
||||
|
||||
// Built-in libraries
|
||||
use Exception as exception,
|
||||
RuntimeException as exception_runtime;
|
||||
|
||||
/**
|
||||
* Distribution
|
||||
*
|
||||
* @package svoboda\negotiator\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 distribution extends core
|
||||
{
|
||||
/**
|
||||
* File
|
||||
*
|
||||
* @var string $database Path to the database file
|
||||
*/
|
||||
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'distributions.baza';
|
||||
|
||||
/**
|
||||
* Database
|
||||
*
|
||||
* @var database $database The database
|
||||
*/
|
||||
public protected(set) database $database;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Initializing the database
|
||||
$this->database = new database()
|
||||
->encoding(encoding::ascii)
|
||||
->columns(
|
||||
new column('identifier', type::integer_unsigned),
|
||||
new column('creator', type::integer_unsigned),
|
||||
new column('latitude', type::float),
|
||||
new column('longitude', type::float),
|
||||
new column('created', type::integer_unsigned),
|
||||
new column('updated', type::integer_unsigned)
|
||||
)
|
||||
->connect($this->file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create
|
||||
*
|
||||
* Creates the distribution record in the database
|
||||
*
|
||||
* @param int $creator Identifier of the creator account
|
||||
* @param float $latitude Latitude
|
||||
* @param float $longitude Longitude
|
||||
*
|
||||
* @return int|false The record identifier, if created
|
||||
*/
|
||||
public function create(int $creator, float $latitude = 0, float $longitude = 0): int|false
|
||||
{
|
||||
// Initializing the identifier
|
||||
$identifier = $this->database->count() + 1;
|
||||
|
||||
// Initializing the record
|
||||
$record = $this->database->record(
|
||||
$identifier,
|
||||
$creator,
|
||||
$latitude,
|
||||
$longitude,
|
||||
svoboda::timestamp(),
|
||||
svoboda::timestamp()
|
||||
);
|
||||
|
||||
// Creating the accound record in the database
|
||||
$created = $this->database->write($record);
|
||||
|
||||
// Exit (success)
|
||||
return $created ? $identifier : false;
|
||||
}
|
||||
}
|
|
@ -5,17 +5,17 @@ declare(strict_types=1);
|
|||
namespace svoboda\negotiator\models\enumerations;
|
||||
|
||||
/**
|
||||
* Session
|
||||
* Entity
|
||||
*
|
||||
* Types of session verification
|
||||
* Types of entities
|
||||
*
|
||||
* @package svoboda\negotiator\models\enumerations
|
||||
*
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author svoboda <mail@domain.zone>
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
enum session
|
||||
enum entity
|
||||
{
|
||||
case hash_only;
|
||||
case hash_else_address;
|
||||
case account;
|
||||
case distribution;
|
||||
}
|
|
@ -13,7 +13,6 @@ namespace svoboda\negotiator\models\enumerations;
|
|||
*
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
* @author svoboda <mail@domain.zone>
|
||||
*/
|
||||
enum language
|
||||
{
|
||||
|
@ -47,7 +46,7 @@ enum language
|
|||
/**
|
||||
* Flag
|
||||
*
|
||||
* Initialize tge flag emoji of the language
|
||||
* Initialize the flag emoji of the language
|
||||
*
|
||||
* @return string The flag emoji of the language
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace svoboda\negotiator\models\localizations;
|
||||
|
||||
// Files of the project
|
||||
use svoboda\negotiator\models\core,
|
||||
svoboda\negotiator\models\enumerations\language;
|
||||
|
||||
// Svoboda time
|
||||
use svoboda\time\statement as svoboda;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\database,
|
||||
mirzaev\baza\column,
|
||||
mirzaev\baza\record,
|
||||
mirzaev\baza\enumerations\encoding,
|
||||
mirzaev\baza\enumerations\type;
|
||||
|
||||
// Framework for Telegram
|
||||
use Zanzara\Telegram\Type\User as telegram;
|
||||
|
||||
// Built-in libraries
|
||||
use Exception as exception,
|
||||
RuntimeException as exception_runtime;
|
||||
|
||||
/**
|
||||
* Distribution
|
||||
*
|
||||
* @package svoboda\negotiator\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 distribution extends core
|
||||
{
|
||||
/**
|
||||
* File
|
||||
*
|
||||
* @var string $database Path to the database file
|
||||
*/
|
||||
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'localizations' . DIRECTORY_SEPARATOR . 'distributions.baza';
|
||||
|
||||
/**
|
||||
* Database
|
||||
*
|
||||
* @var database $database The database
|
||||
*/
|
||||
public protected(set) database $database;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Initializing the database
|
||||
$this->database = new database()
|
||||
->encoding(encoding::utf8)
|
||||
->columns(
|
||||
new column('identifier', type::integer_unsigned),
|
||||
new column('distribution', type::integer_unsigned),
|
||||
new column('language', type::string, ['length' => 2]),
|
||||
new column('name', type::string, ['length' => 32]),
|
||||
new column('created', type::integer_unsigned),
|
||||
new column('updated', type::integer_unsigned)
|
||||
)
|
||||
->connect($this->file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create
|
||||
*
|
||||
* Creates the distribution localization record in the database
|
||||
*
|
||||
* @param int $distribution Identifier of the distribution
|
||||
* @param language $language Language
|
||||
* @param string $name Name
|
||||
*
|
||||
* @return int|false The record identifier, if created
|
||||
*/
|
||||
public function create(int $distribution, language $language, string $name): int|false
|
||||
{
|
||||
// Initializing the identifier
|
||||
$identifier = $this->database->count() + 1;
|
||||
|
||||
// Initializing the record
|
||||
$record = $this->database->record(
|
||||
$identifier,
|
||||
$distribution,
|
||||
$language->name,
|
||||
$name,
|
||||
svoboda::timestamp(),
|
||||
svoboda::timestamp()
|
||||
);
|
||||
|
||||
// Creating the accound record in the database
|
||||
$created = $this->database->write($record);
|
||||
|
||||
// Exit (success)
|
||||
return $created ? $identifier : false;
|
||||
}
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace svoboda\negotiator\models\telegram;
|
||||
|
||||
// Files of the project
|
||||
use svoboda\negotiator\models\core,
|
||||
svoboda\negotiator\models\account,
|
||||
svoboda\negotiator\models\enumerations\language;
|
||||
|
||||
// Framework for Telegram
|
||||
use Zanzara\Zanzara,
|
||||
Zanzara\Context as context,
|
||||
Zanzara\Telegram\Type\Input\InputFile as file_input,
|
||||
Zanzara\Telegram\Type\File\Document as document,
|
||||
Zanzara\Middleware\MiddlewareNode as node,
|
||||
Zanzara\Telegram\Type\User as user;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\record;
|
||||
|
||||
// Built-in libraries
|
||||
use Exception as exception,
|
||||
Error as error;
|
||||
|
||||
/**
|
||||
* Telegram settings
|
||||
*
|
||||
* @package svoboda\negotiator\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
|
||||
{
|
||||
/**
|
||||
* Settings: language
|
||||
*
|
||||
* Responce for the command: "/language"
|
||||
*
|
||||
* Sends a language selection menu
|
||||
*
|
||||
* @param context $context Request data from Telegram
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function settings_language(context $context): void
|
||||
{
|
||||
// Initializing the account
|
||||
$account = $context->get('account');
|
||||
|
||||
if ($account instanceof record) {
|
||||
// Initialized the account
|
||||
|
||||
// Initializing localization
|
||||
$localization = $context->get('localization');
|
||||
|
||||
if ($localization) {
|
||||
// Initialized localization
|
||||
|
||||
// Initializing the title
|
||||
$title = '🌏 *' . $localization['language_settings'] . '*';
|
||||
|
||||
// Declaring the buffer of generated keyboard with languages
|
||||
$keyboard = [];
|
||||
|
||||
// Initializing the iterator of rows
|
||||
$row = 0;
|
||||
|
||||
foreach (language::cases() as $language) {
|
||||
// Iterating over languages
|
||||
|
||||
// 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' => 'settings_language_' . $language->name
|
||||
];
|
||||
|
||||
// When reaching 4 buttons in a row, move to the next row
|
||||
if (count($keyboard[$row]) === 4) ++$row;
|
||||
}
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage(
|
||||
<<<TXT
|
||||
$title
|
||||
TXT,
|
||||
[
|
||||
'reply_markup' => [
|
||||
'inline_keyboard' => $keyboard
|
||||
],
|
||||
'disable_notification' => true
|
||||
]
|
||||
)
|
||||
->then(function ($message) use ($context) {
|
||||
//
|
||||
});
|
||||
} else {
|
||||
// Not initialized localization
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||
->then(function ($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) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,277 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace svoboda\negotiator\models\telegram\buttons\distribution;
|
||||
|
||||
// Files of the project
|
||||
use svoboda\negotiator\models\core,
|
||||
svoboda\negotiator\models\account,
|
||||
svoboda\negotiator\models\distribution,
|
||||
svoboda\negotiator\models\telegram\selections,
|
||||
svoboda\negotiator\models\telegram\processes\distribution\registration as process_distribution_registration,
|
||||
svoboda\negotiator\models\localization\distribution as distribution_localization,
|
||||
svoboda\negotiator\models\enumerations\language;
|
||||
|
||||
// Framework for Telegram
|
||||
use Zanzara\Context as context,
|
||||
Zanzara\Telegram\Type\Message as message;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\record;
|
||||
|
||||
/**
|
||||
* Telegram distribution registration buttons
|
||||
*
|
||||
* @package svoboda\negotiator\models\telegram\buttons\distribution
|
||||
*
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
final class registration extends core
|
||||
{
|
||||
/**
|
||||
* Language
|
||||
*
|
||||
* Send the language selection menu
|
||||
*
|
||||
* @param context $context Request data from Telegram
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function language(context $context)
|
||||
{
|
||||
// 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
|
||||
|
||||
// Reading from the telegram user buffer
|
||||
$context->getUserDataItem('distribution_registration')
|
||||
->then(function ($distribution) use ($context, $account, $localization) {
|
||||
// Readed from the telegram user buffer
|
||||
|
||||
if ($distribution) {
|
||||
// Found started registration process
|
||||
|
||||
// Sending the language selection
|
||||
selections::language(
|
||||
context: $context,
|
||||
prefix: 'distribution_registration_select_language_',
|
||||
title: '🌏 *' . $localization['distribution_registration_select_language_title'] . '*',
|
||||
description: '🌏 *' . $localization['distribution_registration_select_language_description'] . '*'
|
||||
);
|
||||
} else {
|
||||
// Not found started registretion process
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *' . $localization['distribution_registration_not_started'] . '*');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Not initialized localization
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||
->then(function ($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) 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) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Name
|
||||
*
|
||||
* Request to enter name
|
||||
*
|
||||
* @param context $context Request data from Telegram
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function name(context $context)
|
||||
{
|
||||
// Initializing the account
|
||||
$account = $context->get('account');
|
||||
|
||||
if ($account instanceof record) {
|
||||
// Initialized the account
|
||||
|
||||
// Initializing localization
|
||||
$localization = $context->get('localization');
|
||||
|
||||
if ($localization) {
|
||||
// Initialized localization
|
||||
|
||||
// Reading from the telegram user buffer
|
||||
$context->getUserDataItem('distribution_registration')
|
||||
->then(function ($distribution) use ($context, $account, $localization) {
|
||||
// Readed from the telegram user buffer
|
||||
|
||||
if ($distribution) {
|
||||
// Found started registration process
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage('📄 *' . $localization['distribution_registration_name_request'] . '*')
|
||||
->then(function (message $message) use ($context) {
|
||||
// Sended the message
|
||||
|
||||
// Writing into the distribution registration buffer
|
||||
$context->nextStep([process_distribution_registration::class, 'name']);
|
||||
});
|
||||
} else {
|
||||
// Not found started registretion process
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *' . $localization['distribution_registration_not_started'] . '*');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Not initialized localization
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||
->then(function ($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) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Location
|
||||
*
|
||||
* Request to send location
|
||||
*
|
||||
* @param context $context Request data from Telegram
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function location(context $context)
|
||||
{
|
||||
// Initializing the account
|
||||
$account = $context->get('account');
|
||||
|
||||
if ($account instanceof record) {
|
||||
// Initialized the account
|
||||
|
||||
// Initializing localization
|
||||
$localization = $context->get('localization');
|
||||
|
||||
if ($localization) {
|
||||
// Initialized localization
|
||||
|
||||
// Reading from the telegram user buffer
|
||||
$context->getUserDataItem('distribution_registration')
|
||||
->then(function ($distribution) use ($context, $account, $localization) {
|
||||
// Readed from the telegram user buffer
|
||||
|
||||
if ($distribution) {
|
||||
// Found started registration process
|
||||
|
||||
// Initializing the message title
|
||||
$title = '🗺 *' . $localization['distribution_registration_location_send_title'] . '*';
|
||||
|
||||
// Initializing the message description
|
||||
$description = $localization['distribution_registration_location_send_description'];
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage(
|
||||
<<<TXT
|
||||
$title
|
||||
|
||||
$description
|
||||
TXT,
|
||||
[
|
||||
'reply_markup' => [
|
||||
'keyboard' => [
|
||||
[
|
||||
[
|
||||
'text' => '🗺 ' . $localization['distribution_registration_button_location_send'],
|
||||
'request_location' => true
|
||||
]
|
||||
],
|
||||
],
|
||||
'disable_notification' => true
|
||||
]
|
||||
]
|
||||
|
||||
)
|
||||
->then(function (message $message) use ($context) {
|
||||
// Sended the message
|
||||
|
||||
// Writing into the distribution registration buffer
|
||||
$context->nextStep([process_distribution_registration::class, 'location']);
|
||||
});
|
||||
} else {
|
||||
// Not found started registretion process
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *' . $localization['distribution_registration_not_started'] . '*');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Not initialized localization
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||
->then(function ($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) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,24 +6,18 @@ namespace svoboda\negotiator\models\telegram;
|
|||
|
||||
// Files of the project
|
||||
use svoboda\negotiator\models\core,
|
||||
svoboda\negotiator\models\account,
|
||||
svoboda\negotiator\models\distribution,
|
||||
svoboda\negotiator\models\telegram\selections,
|
||||
svoboda\negotiator\models\enumerations\language;
|
||||
|
||||
// Framework for Telegram
|
||||
use Zanzara\Zanzara,
|
||||
Zanzara\Context as context,
|
||||
Zanzara\Telegram\Type\Input\InputFile as file_input,
|
||||
Zanzara\Telegram\Type\File\Document as document,
|
||||
Zanzara\Middleware\MiddlewareNode as node,
|
||||
Zanzara\Telegram\Type\User as user;
|
||||
use Zanzara\Context as context,
|
||||
Zanzara\Telegram\Type\Message as message,
|
||||
Zanzara\Telegram\Type\Input\InputFile as file_input;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\record;
|
||||
|
||||
// Built-in libraries
|
||||
use Exception as exception,
|
||||
Error as error;
|
||||
|
||||
/**
|
||||
* Telegram commands
|
||||
*
|
||||
|
@ -64,7 +58,7 @@ final class commands extends core
|
|||
$context->sendMessage(<<<TXT
|
||||
$title
|
||||
TXT)
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
//
|
||||
});
|
||||
} else {
|
||||
|
@ -72,7 +66,7 @@ final class commands extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -82,7 +76,7 @@ final class commands extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -115,7 +109,7 @@ final class commands extends core
|
|||
$context->sendMessage(<<<TXT
|
||||
*⚠️ Failed to initialize your Telegram account*
|
||||
TXT)
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
//
|
||||
});
|
||||
} else {
|
||||
|
@ -123,7 +117,110 @@ final class commands extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Distributions
|
||||
*
|
||||
* Responce for the command: "/distributions"
|
||||
*
|
||||
* Sends the distributions menu
|
||||
*
|
||||
* @param context $context Request data from Telegram
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function distributions(context $context): void
|
||||
{
|
||||
// Initializing the account
|
||||
$account = $context->get('account');
|
||||
|
||||
if ($account instanceof record) {
|
||||
// Initialized the account
|
||||
|
||||
// Initializing language
|
||||
$language = $context->get('language');
|
||||
|
||||
if ($language instanceof language) {
|
||||
// Initialized language
|
||||
|
||||
// Initializing localization
|
||||
$localization = $context->get('localization');
|
||||
|
||||
if ($localization) {
|
||||
// Initialized localization
|
||||
|
||||
// Initializing the message title
|
||||
$title = '🏘 *' . $localization['distributions_title'] . '*';
|
||||
|
||||
// Initializing the message description
|
||||
$description = $localization['distributions_description'];
|
||||
|
||||
// Initializing the distribution model
|
||||
$model = new distribution;
|
||||
|
||||
// Initializing the message "registered" row
|
||||
$registered = '*' . $localization['distributions_registered'] . ':* ' . $model->database->count();
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage(
|
||||
<<<TXT
|
||||
$title
|
||||
|
||||
$registered
|
||||
|
||||
$description
|
||||
TXT,
|
||||
[
|
||||
'reply_markup' => [
|
||||
'inline_keyboard' => [
|
||||
[
|
||||
[
|
||||
'text' => '📋 ' . $localization['distributions_button_register'],
|
||||
'callback_data' => 'distribution_registration_start'
|
||||
],
|
||||
[
|
||||
'text' => '🔎 ' . $localization['distributions_button_search'],
|
||||
'callback_data' => 'distribution_search_start'
|
||||
]
|
||||
]
|
||||
],
|
||||
'disable_notification' => true,
|
||||
'remove_keyboard' => 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 language
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize language*')
|
||||
->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();
|
||||
});
|
||||
|
@ -135,7 +232,7 @@ final class commands extends core
|
|||
*
|
||||
* Responce for the command: "/language"
|
||||
*
|
||||
* Sends a language selection menu
|
||||
* Send the language selection menu
|
||||
*
|
||||
* @param context $context Request data from Telegram
|
||||
*
|
||||
|
@ -149,58 +246,41 @@ final class commands extends core
|
|||
if ($account instanceof record) {
|
||||
// Initialized the account
|
||||
|
||||
// Initializing language
|
||||
$language = $context->get('language');
|
||||
|
||||
if ($language instanceof language) {
|
||||
// Initialized language
|
||||
|
||||
// Initializing localization
|
||||
$localization = $context->get('localization');
|
||||
|
||||
if ($localization) {
|
||||
// Initialized localization
|
||||
|
||||
// Declaring the buffer of generated keyboard with languages
|
||||
$keyboard = [];
|
||||
|
||||
// Initializing the iterator of rows
|
||||
$row = 0;
|
||||
|
||||
foreach (language::cases() as $language) {
|
||||
// Iterating over languages
|
||||
|
||||
// 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' => 'settings_language_' . $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] = [
|
||||
[
|
||||
'text' => '🗂 ' . $localization['settings_language_add'],
|
||||
'url' => 'https://git.svoboda.works/svoboda/negotiator/src/branch/stable/svoboda/negotiator/system/localizations'
|
||||
]
|
||||
];
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage(
|
||||
'🌏 *' . $localization['settings_language_title'] . '*',
|
||||
[
|
||||
'reply_markup' => [
|
||||
'inline_keyboard' => $keyboard
|
||||
],
|
||||
'disable_notification' => true
|
||||
]
|
||||
// Sending the language selection
|
||||
selections::language(
|
||||
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) use ($context) {
|
||||
->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) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -210,7 +290,7 @@ final class commands extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -255,7 +335,7 @@ final class commands extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -265,7 +345,7 @@ final class commands extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace svoboda\negotiator\models\telegram;
|
||||
|
||||
// Files of the project
|
||||
use svoboda\negotiator\models\core,
|
||||
svoboda\negotiator\models\account,
|
||||
svoboda\negotiator\models\distribution as model,
|
||||
svoboda\negotiator\models\localization\distribution as distribution_localization,
|
||||
svoboda\negotiator\models\enumerations\language;
|
||||
|
||||
// Framework for Telegram
|
||||
use Zanzara\Context as context,
|
||||
Zanzara\Telegram\Type\Message as message;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\record;
|
||||
|
||||
/**
|
||||
* Telegram distribution
|
||||
*
|
||||
* @package svoboda\negotiator\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 distribution extends core {}
|
|
@ -10,19 +10,15 @@ use svoboda\negotiator\models\core,
|
|||
svoboda\negotiator\models\enumerations\language;
|
||||
|
||||
// Framework for Telegram
|
||||
use Zanzara\Zanzara,
|
||||
Zanzara\Context as context,
|
||||
Zanzara\Telegram\Type\Input\InputFile as file_input,
|
||||
Zanzara\Telegram\Type\File\Document as document,
|
||||
Zanzara\Middleware\MiddlewareNode as node,
|
||||
Zanzara\Telegram\Type\User as user;
|
||||
use Zanzara\Context as context,
|
||||
Zanzara\Telegram\Type\Message as message,
|
||||
Zanzara\Middleware\MiddlewareNode as node;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\record;
|
||||
|
||||
// Built-in libraries
|
||||
use Exception as exception,
|
||||
Error as error;
|
||||
use Error as error;
|
||||
|
||||
/**
|
||||
* Telegram middlewares
|
||||
|
@ -69,7 +65,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -123,7 +119,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -178,7 +174,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -188,7 +184,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize the localization file*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -198,7 +194,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize language*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -208,7 +204,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -252,7 +248,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⛔ *' . $localization['not_authorized_system'] . '*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -264,7 +260,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -275,7 +271,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -319,7 +315,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⛔ *' . $localization['not_authorized_contact'] . '*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -331,7 +327,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -342,7 +338,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -386,7 +382,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⛔ *' . $localization['not_authorized_request'] . '*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -398,7 +394,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -409,7 +405,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -453,7 +449,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⛔ *' . $localization['not_authorized_settings'] . '*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -465,7 +461,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -476,7 +472,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -520,7 +516,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⛔ *' . $localization['not_authorized_system_settings'] . '*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -532,7 +528,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -543,7 +539,7 @@ final class middlewares extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
|
|
@ -0,0 +1,238 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace svoboda\negotiator\models\telegram\processes\distribution;
|
||||
|
||||
// Files of the project
|
||||
use svoboda\negotiator\models\core,
|
||||
svoboda\negotiator\models\enumerations\language;
|
||||
|
||||
// Framework for Telegram
|
||||
use Zanzara\Context as context,
|
||||
Zanzara\Telegram\Type\Message as message;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\record;
|
||||
|
||||
/**
|
||||
* Distribution localization process
|
||||
*
|
||||
* @package svoboda\negotiator\models\telegram\processes\distribution
|
||||
*
|
||||
* @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
|
||||
{
|
||||
/**
|
||||
* Start
|
||||
*
|
||||
* Starting the distribution localization process
|
||||
*
|
||||
* @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 record) {
|
||||
// Initialized the account
|
||||
|
||||
// Initializing language
|
||||
$language = $context->get('language');
|
||||
|
||||
if ($language instanceof language) {
|
||||
// Initialized language
|
||||
|
||||
// Initializing localization
|
||||
$localization = $context->get('localization');
|
||||
|
||||
if ($localization) {
|
||||
// Initialized localization
|
||||
|
||||
// Reading from the telegram user buffer
|
||||
$context->getUserDataItem('distribution_localization')
|
||||
->then(function ($distribution_localization) use ($context, $account, $localization) {
|
||||
// Readed from the telegram user buffer
|
||||
|
||||
if ($distribution_localization) {
|
||||
// Found started localization process
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage('🌏 *' . $localization['distribution_localization_continiued'] . '*')
|
||||
->then(function (message $message) use ($context, $localization) {
|
||||
// Sended the message
|
||||
|
||||
// Sending the localization generation menu
|
||||
static::generation($context);
|
||||
});
|
||||
} else {
|
||||
// Not found started localization process
|
||||
|
||||
// Reading from the telegram user buffer
|
||||
$context->getUserDataItem('distribution_registration')
|
||||
->then(function ($distribution) use ($context, $account, $localization) {
|
||||
// Readed from the telegram user buffer
|
||||
|
||||
if ($distribution instanceof record) {
|
||||
// Found started registration process
|
||||
|
||||
// Writing to the telegram user buffer
|
||||
$context->setUserDataItem('distribution_localization', ['distribution' => $distribution])
|
||||
->then(function () use ($context, $localization) {
|
||||
// Writed to the telegram user buffer
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage('🌏 *' . $localization['distribution_localization_started'] . '*')
|
||||
->then(function (message $message) use ($context, $localization) {
|
||||
// Sended the message
|
||||
|
||||
// Sending the localization generation menu
|
||||
static::generation($context);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Not found started registration process
|
||||
|
||||
// Здесь надо просить выбрать дистрибутив
|
||||
|
||||
// Проверять на то, что он creator дистрибутива, иначе посылать
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} 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) {
|
||||
// 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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generation
|
||||
*
|
||||
* Send the generation menu
|
||||
*
|
||||
* @param context $context Request data from Telegram
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function generation(context $context): array
|
||||
{
|
||||
// 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
|
||||
|
||||
// Reading from the telegram user buffer
|
||||
$context->getUserDataItem('distribution_localization')
|
||||
->then(function ($distribution_localization) use ($context, $account, $language, $localization) {
|
||||
// Readed from the telegram user buffer
|
||||
|
||||
if ($distribution_localization) {
|
||||
// Found started localization process
|
||||
|
||||
// Initializing the buffer of generated keyboard with languages
|
||||
$keyboard = [
|
||||
[
|
||||
[
|
||||
'text' => (empty($distribution_localization['language']) ? language::{$distribution_localization['language']}->flag() : '🟢') . ' ' . $localization['distribution_localization_button_language'],
|
||||
'callback_data' => 'distribution_localization_language'
|
||||
]
|
||||
],
|
||||
[
|
||||
[
|
||||
'text' => (empty($distribution_localization['name']) ? '🔴 ' : '🟢 ') . $localization['distribution_localization_button_name'],
|
||||
'callback_data' => 'distribution_localization_name'
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage(
|
||||
'🌏 *' . $localization['distribution_localization_generation_menu'] . '*',
|
||||
[
|
||||
'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) {
|
||||
// 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) {
|
||||
// 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();
|
||||
});
|
||||
}
|
||||
// Exit (success)
|
||||
return [];
|
||||
}
|
||||
}
|
1082
svoboda/negotiator/system/models/telegram/processes/distribution/registration.php
Executable file
1082
svoboda/negotiator/system/models/telegram/processes/distribution/registration.php
Executable file
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace svoboda\negotiator\models\telegram\processes\distribution;
|
||||
|
||||
// Files of the project
|
||||
use svoboda\negotiator\models\core,
|
||||
svoboda\negotiator\models\account,
|
||||
svoboda\negotiator\models\distribution,
|
||||
svoboda\negotiator\models\localization\distribution as distribution_localization,
|
||||
svoboda\negotiator\models\enumerations\language;
|
||||
|
||||
// Framework for Telegram
|
||||
use Zanzara\Zanzara,
|
||||
Zanzara\Context as context,
|
||||
Zanzara\Telegram\Type\Input\InputFile as file_input,
|
||||
Zanzara\Telegram\Type\File\Document as document,
|
||||
Zanzara\Middleware\MiddlewareNode as node,
|
||||
Zanzara\Telegram\Type\User as user;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\record;
|
||||
|
||||
// Built-in libraries
|
||||
use Exception as exception,
|
||||
Error as error;
|
||||
|
||||
/**
|
||||
* Distribution search process
|
||||
*
|
||||
* @package svoboda\negotiator\models\telegram\processes\distribution
|
||||
*
|
||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
final class search extends core
|
||||
{
|
||||
/**
|
||||
* Registry
|
||||
*
|
||||
* Registrate the distribution
|
||||
*
|
||||
* @param context $context Request data from Telegram
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function registry(context $context): void
|
||||
{
|
||||
// Initializing the account
|
||||
$account = $context->get('account');
|
||||
|
||||
if ($account instanceof record) {
|
||||
// Initialized the account
|
||||
|
||||
// Initializing language
|
||||
$language = $context->get('language');
|
||||
|
||||
if ($language instanceof language) {
|
||||
// Initialized language
|
||||
|
||||
// Initializing localization
|
||||
$localization = $context->get('localization');
|
||||
|
||||
if ($localization) {
|
||||
// Initialized localization
|
||||
|
||||
// Declaring the buffer of generated keyboard with languages
|
||||
$keyboard = [];
|
||||
|
||||
// Initializing the iterator of rows
|
||||
$row = 0;
|
||||
|
||||
// Initializing the distribution model
|
||||
$model = new distribution;
|
||||
|
||||
// Initializing the distribution localization model
|
||||
$model_localization = new distribution_localization;
|
||||
|
||||
foreach ($model->database->read(amount: PHP_INT_MAX) as $distribution) {
|
||||
// Iterating over distributions
|
||||
|
||||
// Initializing the distribution localized values
|
||||
$localized = $model_localization->database->read(filter: fn($record) => $record->identifier === $distribution->identifier && $record->language === $language->name, amount: 1)[0] ?? null;
|
||||
|
||||
// Initializing the row
|
||||
$keyboard[$row] ??= [];
|
||||
|
||||
// Writing the language choose button into the buffer of generated keyboard with languages
|
||||
$keyboard[$row][] = [
|
||||
'text' => $localized->name,
|
||||
'callback_data' => 'distributions_open_' . $distribution->identifier
|
||||
];
|
||||
|
||||
// When reaching 4 buttons in a row, move to the next row
|
||||
if (count($keyboard[$row]) === 3) ++$row;
|
||||
}
|
||||
|
||||
// Writing the button for helping lozalizing
|
||||
$keyboard[++$row] = [
|
||||
[
|
||||
'text' => '🗂 ' . $localization['settings_language_add'],
|
||||
'url' => 'https://git.svoboda.works/svoboda/negotiator/src/branch/stable/svoboda/negotiator/system/localizations'
|
||||
]
|
||||
];
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage(
|
||||
'🌏 *' . $localization['settings_language_title'] . '*',
|
||||
[
|
||||
'reply_markup' => [
|
||||
'inline_keyboard' => $keyboard
|
||||
],
|
||||
'disable_notification' => true
|
||||
]
|
||||
);
|
||||
} else {
|
||||
// Not initialized localization
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||
->then(function ($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) 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) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace svoboda\negotiator\models\telegram;
|
||||
|
||||
// Files of the project
|
||||
use svoboda\negotiator\models\core,
|
||||
svoboda\negotiator\models\enumerations\language;
|
||||
|
||||
// Framework for Telegram
|
||||
use Zanzara\Context as context,
|
||||
Zanzara\Telegram\Type\Message as message;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\record;
|
||||
|
||||
/**
|
||||
* Telegram selections
|
||||
*
|
||||
* @package svoboda\negotiator\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 selections extends core
|
||||
{
|
||||
/**
|
||||
* Language
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function language(context $context, string $prefix, string $title, string $description): 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
|
||||
|
||||
// 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] = [
|
||||
[
|
||||
'text' => '🗂 ' . $localization['select_language_button_add'],
|
||||
'url' => 'https://git.svoboda.works/svoboda/negotiator/src/branch/stable/svoboda/negotiator/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) {
|
||||
// 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) {
|
||||
// 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();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,17 +13,14 @@ use svoboda\negotiator\models\core,
|
|||
// Framework for Telegram
|
||||
use Zanzara\Zanzara,
|
||||
Zanzara\Context as context,
|
||||
Zanzara\Telegram\Type\Input\InputFile as file_input,
|
||||
Zanzara\Telegram\Type\File\Document as document,
|
||||
Zanzara\Middleware\MiddlewareNode as node,
|
||||
Zanzara\Telegram\Type\User as user;
|
||||
Zanzara\Telegram\Type\Message as message,
|
||||
Zanzara\Middleware\MiddlewareNode as node;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\record;
|
||||
|
||||
// Built-in libraries
|
||||
use Exception as exception,
|
||||
Error as error;
|
||||
use Error as error;
|
||||
|
||||
/**
|
||||
* Telegram settings
|
||||
|
@ -59,8 +56,11 @@ final class settings extends core
|
|||
if ($localization) {
|
||||
// Initialized localization
|
||||
|
||||
// Initializing the account model
|
||||
$model = new account();
|
||||
|
||||
// Updating the account in the database
|
||||
$updated = account::$database->read(
|
||||
$updated = $model->database->read(
|
||||
filter: fn(record $record) => $record->identifier === $account->identifier,
|
||||
update: function (record &$record) use ($language) {
|
||||
// Writing new language value into the record
|
||||
|
@ -86,6 +86,7 @@ final class settings extends core
|
|||
|
||||
if ($localization) {
|
||||
// Initialized localization
|
||||
|
||||
try {
|
||||
// Initializing the old language
|
||||
$old = language::{$account->language};
|
||||
|
@ -94,8 +95,8 @@ final class settings extends core
|
|||
$new = language::{$updated->language};
|
||||
|
||||
// Sending the message
|
||||
$context->sendMessage('✅ *' . $localization['settings_language_update_success'] . '* ' . ($old->flag() ? $old->flag() . ' ' : '') . $old->label($new) . ' » ' . ($new->flag() ? $new->flag() . ' ' : '') . $new->label($new))
|
||||
->then(function ($message) use ($context) {
|
||||
$context->sendMessage('✅ *' . $localization['settings_language_update_success'] . '* ' . ($old->flag() ? $old->flag() . ' ' : '') . $old->label($new) . ' → *' . ($new->flag() ? $new->flag() . ' ' : '') . $new->label($new) . '*')
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -104,7 +105,7 @@ final class settings extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('❎ *' . $localization['settings_language_update_fail'])
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -114,7 +115,7 @@ final class settings extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -126,7 +127,7 @@ final class settings extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('❎ *' . $localization['settings_language_update_fail'])
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -136,7 +137,7 @@ final class settings extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
@ -146,7 +147,7 @@ final class settings extends core
|
|||
|
||||
// Sending the message
|
||||
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
|
||||
->then(function ($message) use ($context) {
|
||||
->then(function (message $message) use ($context) {
|
||||
// Ending the conversation process
|
||||
$context->endConversation();
|
||||
});
|
||||
|
|
|
@ -5,17 +5,26 @@ declare(strict_types=1);
|
|||
namespace svoboda\negotiator;
|
||||
|
||||
// Files of the project
|
||||
use svoboda\negotiator\models\telegram\middlewares,
|
||||
use svoboda\negotiator\models\distribution,
|
||||
svoboda\negotiator\models\localization\distribution as distribution_localization,
|
||||
svoboda\negotiator\models\telegram\middlewares,
|
||||
svoboda\negotiator\models\telegram\commands,
|
||||
svoboda\negotiator\models\telegram\buttons,
|
||||
svoboda\negotiator\models\telegram\selections,
|
||||
svoboda\negotiator\models\telegram\settings,
|
||||
svoboda\negotiator\models\enumerations\language;
|
||||
svoboda\negotiator\models\enumerations\language,
|
||||
svoboda\negotiator\models\telegram\processes\distribution\registration as process_distribution_registration,
|
||||
svoboda\negotiator\models\telegram\buttons\distribution\registration as button_distribution_registration,
|
||||
svoboda\negotiator\models\telegram\processes\distribution\localization as process_distribution_localization;
|
||||
|
||||
// Framework for Telegram
|
||||
use Zanzara\Zanzara as zanzara,
|
||||
Zanzara\Context as context,
|
||||
Zanzara\Config as config;
|
||||
|
||||
// Baza database
|
||||
use mirzaev\baza\record;
|
||||
|
||||
// Enabling debugging
|
||||
/* ini_set('error_reporting', E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
@ -66,13 +75,64 @@ $robot->middleware([middlewares::class, 'system']);
|
|||
$robot->onCommand('start', [commands::class, 'menu']);
|
||||
$robot->onCommand('menu', [commands::class, 'menu']);
|
||||
/* $robot->onCommand('request', [telegram::class, 'request_start'])->middleware([telegram::class, 'request']); */
|
||||
/* $robot->onCommand('svoboda', [commands::class, 'svoboda']);
|
||||
$robot->onCommand('members', [commands::class, 'members']); */
|
||||
$robot->onCommand('distributions', [commands::class, 'distributions']);
|
||||
$robot->onCommand('language', [commands::class, 'language'])->middleware([middlewares::class, 'settings']);
|
||||
$robot->onCommand('society', [commands::class, 'society']);
|
||||
|
||||
// Initializing the robot protected commands handlers
|
||||
/* $robot->onCommand('system_settings', [commands::class, 'system_settings'])->middleware([middlewares::class, 'system_settings']); */
|
||||
// Initializing the robot distributions registration buttons handlers
|
||||
$robot->onCbQueryData(['distribution_registration_start'], [process_distribution_registration::class, 'start']);
|
||||
$robot->onCbQueryData(['distribution_registration_cancel'], [process_distribution_registration::class, 'cancel']);
|
||||
$robot->onCbQueryData(['distribution_registration_end'], [process_distribution_registration::class, 'end']);
|
||||
|
||||
// Initializing the robot buttons handlers
|
||||
// Initializing the robot distribution localization language select button handler
|
||||
$robot->onCbQueryData(['distribution_registration_language'], [button_distribution_registration::class, 'language']);
|
||||
|
||||
// Initializing the robot distribution registration language buttons handlers
|
||||
foreach (language::cases() as $language) {
|
||||
// Iterating over languages
|
||||
|
||||
// Initializing language buttons
|
||||
$robot->onCbQueryData(['distribution_registration_select_language_' . $language->name], fn(context $context) => process_distribution_registration::language($context, $language));
|
||||
};
|
||||
|
||||
// Initializing the robot distribution localization name enter button handler
|
||||
$robot->onCbQueryData(['distribution_registration_name'], [button_distribution_registration::class, 'name']);
|
||||
|
||||
// Initializing the robot distribution location send button handler
|
||||
$robot->onCbQueryData(['distribution_registration_location'], [button_distribution_registration::class, 'location']);
|
||||
|
||||
|
||||
// Initializing the robot distributions localization buttons handlers
|
||||
/* $robot->onCbQueryData(['distribution_localization_start'], [process_distribution_localization::class, 'start']); */
|
||||
/* $robot->onCbQueryData(['distribution_localization_language'], [distribution_localization::class, 'language']);
|
||||
$robot->onCbQueryData(['distribution_localization_name'], [distribution_localization::class, 'name']); */
|
||||
|
||||
/* // Initializing the robot distribution localization language select button handler
|
||||
$robot->onCbQueryData(
|
||||
['distribution_localization_language'],
|
||||
fn(context $context) => selections::language(
|
||||
context: $context,
|
||||
prefix: 'distribution_localization_language_',
|
||||
title: '🌏 *' . $localization['distribution_localization_select_language_title'] . '*',
|
||||
description: '🌏 *' . $localization['distribution_localization_select_language_description'] . '*'
|
||||
)
|
||||
);
|
||||
|
||||
// Initializing the robot distribution localization language buttons handlers
|
||||
foreach (language::cases() as $language) {
|
||||
// Iterating over languages
|
||||
|
||||
// Initializing language buttons
|
||||
$robot->onCbQueryData(['distribution_localization_language_' . $language->name], fn(context $context) => settings::language($context, $language));
|
||||
}; */
|
||||
|
||||
|
||||
// Initializing the robot distributions menu buttons handlers
|
||||
/* $robot->onCbQueryData(['distributions_search_start'], [process_distribution_search::class, 'start']); */
|
||||
|
||||
// Initializing the robot settings language buttons handlers
|
||||
foreach (language::cases() as $language) {
|
||||
// Iterating over languages
|
||||
|
||||
|
@ -80,6 +140,8 @@ foreach (language::cases() as $language) {
|
|||
$robot->onCbQueryData(['settings_language_' . $language->name], fn(context $context) => settings::language($context, $language));
|
||||
};
|
||||
|
||||
// Initializing the robot protected commands handlers
|
||||
/* $robot->onCommand('system_settings', [commands::class, 'system_settings'])->middleware([middlewares::class, 'system_settings']); */
|
||||
|
||||
// Starting chat-robot
|
||||
$robot->run();
|
||||
|
|
Loading…
Reference in New Issue