5 Commits
1.1.0 ... 1.5.0

56 changed files with 16432 additions and 228 deletions

View File

@@ -1,12 +1,14 @@
{
"name": "svoboda/negotiator",
"description": "Chat-robot negotiator of the Svoboda organization",
"homepage": "https://git.svoboda.works/svoboda/negotiator",
"name": "svoboda/antivertical",
"description": "Svoboda Telegram chat-robot",
"homepage": "https://git.svoboda.works/svoboda/antivertical",
"type": "chat-robot",
"keywords": [
"svoboda",
"telegram",
"minimal"
"minimal",
"baza",
"anarchism"
],
"readme": "README.md",
"license": "WTFPL",
@@ -19,26 +21,26 @@
}
],
"support": {
"wiki": "https://git.svoboda.works/svoboda/negotiator/wiki",
"issues": "https://git.svoboda.works/svoboda/negotiator/issues"
"wiki": "https://git.svoboda.works/svoboda/antivertical/wiki",
"issues": "https://git.svoboda.works/svoboda/antivertical/issues"
},
"require": {
"php": "^8.4",
"mirzaev/minimal": "^3.4.0",
"mirzaev/minimal": "^3.6.2",
"mirzaev/baza": "^3.4",
"svoboda/time": "^1.0",
"badfarm/zanzara": "^0.9.1",
"react/filesystem": "^0.1.2"
},
"require-dev": {
"phpunit/phpunit": "~9.5"
"react/filesystem": "^0.1.2",
"react/async": "^4.3"
},
"autoload": {
"psr-4": {
"svoboda\\negotiator\\": "svoboda/negotiator/system"
"svoboda\\antivertical\\": "svoboda/antivertical/system"
}
},
"autoload-dev": {
"psr-4": {
"svoboda\\negotiator\\tests\\": "svoboda/negotiator/tests"
"svoboda\\antivertical\\tests\\": "svoboda/antivertical/tests"
}
},
"scripts": {

0
examples/demonstration_1_0_0.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 288 KiB

After

Width:  |  Height:  |  Size: 288 KiB

View File

@@ -1,53 +0,0 @@
server {
listen 80;
listen [::]:80;
server_name negotiator.svoboda.works;
# 301 302
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
listen 443 quic;
listen [::]:443 ssl;
listen [::]:443 quic;
server_name negotiator.svoboda.works;
http2 on;
http3 on;
quic_gso on;
quic_retry on;
add_header Alt-Svc 'h3=":$server_port"; ma=86400';
add_header x-quic 'h3';
root /var/www/negotiator/svoboda/negotiator/system/public;
index index.php;
keepalive_timeout 60;
include snippets/ssl-params.conf;
include snippets/ssl-svoboda.conf;
include snippets/php8_4.conf;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|mp3|ogg|ogv|webm|htc|woff2|woff)$ {
expires 1M;
access_log off;
add_header Cache-Control "max-age=2629746, public";
}
location ~* \.(?:css|js|mjs|min)$ {
expires 1y;
access_log off;
add_header Cache-Control "max-age=31556952, public";
}
}

View File

@@ -5,8 +5,8 @@ Wants=network.target
After=syslog.target network-online.target
[Service]
ExecStart=sudo -u www-data /usr/bin/php /var/www/project/svoboda/negotiator/system/public/telegram.php
PIDFile=/var/run/php/negotiator-telegram.pid
ExecStart=sudo -u www-data /usr/bin/php /var/www/project/svoboda/svoboder/system/public/telegram.php
PIDFile=/var/run/php/svoboder-telegram.pid
RemainAfterExit=no
RuntimeMaxSec=3600s
Restart=always

View File

@@ -1,7 +1,7 @@
#!/bin/bash
if [ -d author/project ]; then
mv author/project author/negotiator
mv author/project author/svoboder
fi
if [ -d author ]; then

View File

@@ -2,10 +2,10 @@
declare(strict_types=1);
namespace svoboda\negotiator\controllers;
namespace svoboda\antivertical\controllers;
// Files of the project
use svoboda\negotiator\models\core as models;
use svoboda\antivertical\models\core as models;
// Framework for PHP
use mirzaev\minimal\core as minimal,
@@ -16,7 +16,7 @@ use mirzaev\minimal\core as minimal,
/**
* Controllers core
*
* @package svoboda\negotiator\controllers
* @package svoboda\antivertical\controllers
*
* @param language $language Language
* @param response $response Response
@@ -25,7 +25,7 @@ use mirzaev\minimal\core as minimal,
* @method void __construct(minimal $minimal, bool $initialize) Constructor
*
* @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>
*/
class core extends controller
{

View File

@@ -0,0 +1,3 @@
!.gitignore
*.baza
# *.php

View File

@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical;
// Files of the project
use svoboda\antivertical\models\account;
// 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__);
// 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 key
define('TELEGRAM_KEY', require(SETTINGS . DIRECTORY_SEPARATOR . 'telegram.php'));
// Initializing dependencies
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
// Initializing the account model
$model = new account();
var_dump(
$model->database->read(
update: function (record &$record) {
$record->authorized_system_accounts = 1;
$record->authorized_system_distributions = 1;
$record->authorized_system_settings = 1;
$record->updated = svoboda::timestamp();
},
amount: 1,
offset: 0
)
);

View File

@@ -0,0 +1,420 @@
<?php
// Exit (success)
return [
// System
'svoboda' => 'Svoboda',
'antivertical' => 'Antivertical',
'empty' => 'Empty',
'yes' => 'Yes',
'no' => 'No',
// Main menu
'menu_title' => 'Antivertical',
'menu_accounts' => 'Accounts',
'menu_distributions' => 'Distributions',
'menu_structors' => 'Structors',
'menu_autonoms' => 'Autonoms',
'menu_volunteers' => 'Volunteers',
'menu_investors' => 'Investors',
'menu_recruiters' => 'Recruiters',
/* 'menu_' => '', */
'menu_not_syncronized' => 'The database are not synchronized with the blockchain network',
'menu_warning_database' => 'The database are publish into the repository everyday',
'menu_button_channel' => 'Channel',
'menu_button_site' => 'Site',
'menu_button_map' => 'Map',
'menu_button_blog' => 'Blog',
'menu_button_chats' => 'Chats',
'menu_button_channels' => 'Channels',
'menu_button_memberships' => 'Memberships',
'menu_button_distributions' => 'Distributions',
'menu_button_projects' => 'Projects',
'menu_button_events' => 'Events',
'menu_button_organisation' => 'Organisation',
// Thinking stuff
'thing_about_it_1' => 'Great names are created in the East',
'thing_about_it_1_author' => 'Lermontov M. Y.',
'thing_about_it_2' => '',
'thing_about_it_3' => '',
'thing_about_it_4' => '',
'thing_about_it_5' => '',
/* 'thing_about_it_' => '',
'thing_about_it__author' => '', */
// Structor
'memberships_title' => 'Registry of structors',
'memberships_structor' => 'Structor \- an anarchist representing the distribution',
'memberships_autonom' => 'Autonom - an anarchist representing only himself personally',
'memberships_button_search' => 'Search',
// Memberships search
'membership_search_started' => 'Process of the membership search started',
'membership_search_not_started' => 'Process of the membership search has not started',
'membership_search_ended' => 'Process of the membership search ended',
'membership_search_not_localized' => 'Failed to initialize the membership account localization',
'membership_search_not_named' => 'No name',
'membership_search_status' => 'Status',
'membership_search_status_2' => 'Membership',
'membership_search_status_1' => 'Planned',
'membership_search_status_0' => 'Unknown',
'membership_search_continiued' => 'Process of the membership search found and continiued',
'membership_search_empty' => 'No memberships found',
'membership_search_title' => 'Membership search',
'membership_search_distribution' => 'Distribution',
'membership_search_page_next_exists' => 'There are more memberships in the registry',
'membership_search_page_next_not_exists' => 'There are no more memberships in the registry',
'membership_search_button_name' => 'Name',
'membership_search_name_request_title' => 'Enter name',
'membership_search_name_request_description' => 'Search will be conducted by memberships names using the Levenshtein function',
'membership_search_name_request_not_acceptable' => 'Failed to process the name',
'membership_search_name_request_too_short' => 'Name length must be \>\= 2 and \<\= 128',
'membership_search_name_request_too_long' => 'Name length must be \>\= 2 and \<\= 128',
'membership_search_name_request_restricted_characters_title' => "Restricted any characters except letters, dashes and spaces",
'membership_search_name_request_restricted_characters_description' => "Remove these characters:",
'membership_search_name_update_success' => 'Name replaced:',
'membership_search_name_update_fail' => 'Failed to replace name',
'membership_search_distribution_selection_description' => 'The selected distribution will be used to search for memberships',
'membership_search_distribution_update_success' => 'Distribution replaced:',
'membership_search_distribution_update_fail' => 'Failed to replace distribution',
'membership_search_status_select_title' => 'Select the membership status',
'membership_search_status_update_success' => 'Status replaced:',
'membership_search_status_update_fail' => 'Failed to replace status',
'membership_search_button_start' => 'Start the search',
'membership_search_button_end' => 'End the search',
'membership_search_button_page_next' => 'Next page',
'membership_search_button_message' => 'Message',
'membership_search_button_distribution' => 'Distribution',
'membership_search_button_status' => 'Status',
'membership_search_button_status_2' => 'Membership',
'membership_search_button_status_1' => 'Planned',
'membership_search_button_status_0' => 'Unknown',
// Distributions
'distributions_title' => 'Registry of distributions',
'distributions_description' => '*Distribution* is an autonomous cell of Svoboda, representing any type of formation, but necessarily inherits the codex',
'distributions_declared' => 'Declared',
'distributions_recognized' => 'Recognized',
'distributions_button_search' => 'Search',
'distributions_button_declare' => 'Declare',
// 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', */
// Distribution declaration
'distribution_declaration_started' => 'Process of the distribution declaration started',
'distribution_declaration_not_started' => 'Process of the distribution declaration has not started',
'distribution_declaration_ended' => 'Process of the distribution declaration ended',
'distribution_declaration_continiued' => 'Process of the distribution declaration found and continiued',
'distribution_declaration_generation' => 'The distribution record generation',
'distribution_declaration_created_distribution' => 'Created the distribution record in the database',
'distribution_declaration_created_localization' => 'Created the distribution localization record in the database',
'distribution_declaration_canceled' => 'Process of the distribution declaration canceled',
'distribution_declaration_completed' => 'Process of the distribution declaration completed',
'distribution_declaration_not_created_distribution' => 'Failed to create the distribution record in the database',
'distribution_declaration_not_created_localization' => 'Failed to create the distribution localization record in the database',
'distribution_declaration_button_language' => 'Language',
'distribution_declaration_select_language_title' => 'Choose a language',
'distribution_declaration_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_declaration_language_update_success' => 'Language replaced:',
'distribution_declaration_language_update_fail' => 'Failed to replace language',
'distribution_declaration_button_name' => 'Name',
'distribution_declaration_name_request' => 'Enter name',
'distribution_declaration_name_request_not_acceptable' => 'Failed to process the name',
'distribution_declaration_name_request_too_short' => 'Name length must be \>\= 3 and \<\= 64',
'distribution_declaration_name_request_too_long' => 'Name length must be \>\= 3 and \<\= 64',
'distribution_declaration_name_request_spaces' => "No more than 2 spaces are allowed",
'distribution_declaration_name_request_restricted_characters_title' => "Restricted any characters except letters",
'distribution_declaration_name_request_restricted_characters_description' => "Remove these characters:",
'distribution_declaration_name_update_success' => 'Name replaced:',
'distribution_declaration_name_update_fail' => 'Failed to replace name',
'distribution_declaration_button_location' => 'Location',
'distribution_declaration_button_location_send' => 'Send location',
'distribution_declaration_location_send_title' => 'Send location',
'distribution_declaration_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_declaration_location_send_not_acceptable' => 'Failed to process the location',
'distribution_declaration_location_send_latitude_too_small' => 'Latitude must be \>\= 0 and \<\=90',
'distribution_declaration_location_send_latitude_too_big' => 'Latitude must be \>\= 0 and \<\=90',
'distribution_declaration_location_send_longitude_too_small' => 'Longitude must be \>\= 0 and \<\=180',
'distribution_declaration_location_send_longitude_too_big' => 'Longitude must be \>\= 0 and \<\=180',
'distribution_declaration_location_update_success' => 'Location replaced:',
'distribution_declaration_location_update_fail' => 'Failed to replace location',
'distribution_declaration_button_confirm' => 'Confirm',
'distribution_declaration_button_cancel' => 'Cancel',
// Distribution localization
'distribution_localization_started' => 'declaration of the distribution process started',
'distribution_localization_continiued' => 'declaration 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 a 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",
// Distribution search
'distribution_search_started' => 'Process of the distribution search started',
'distribution_search_not_started' => 'Process of the distribution search has not started',
'distribution_search_ended' => 'Process of the distribution search ended',
'distribution_search_not_localized' => 'Failed to initialize the distribution localization',
'distribution_search_not_named' => 'No name',
'distribution_search_continiued' => 'Process of the distribution search found and continiued',
'distribution_search_empty' => 'No distributions found',
'distribution_search_title' => 'Distribution search',
'distribution_search_memberships' => 'Memberships',
'distribution_search_recognized' => 'Recognized',
'distribution_search_planners' => 'Planners',
'distribution_search_volunteers' => 'Volunteers',
'distribution_search_messages' => 'Messages',
'distribution_search_location' => 'Location',
'distribution_search_page_next_exists' => 'There are more distributions in the registry',
'distribution_search_page_next_not_exists' => 'There are no more distributions in the registry',
'distribution_search_button_name' => 'Name',
'distribution_search_name_request_title' => 'Enter name',
'distribution_search_name_request_description' => 'Search will be conducted by distributions names using the Levenshtein function',
'distribution_search_name_request_not_acceptable' => 'Failed to process the name',
'distribution_search_name_request_too_short' => 'Name length must be \>\= 3 and \<\= 64',
'distribution_search_name_request_too_long' => 'Name length must be \>\= 3 and \<\= 64',
'distribution_search_name_request_restricted_characters_title' => "Restricted any characters except letters",
'distribution_search_name_request_restricted_characters_description' => "Remove these characters:",
'distribution_search_name_update_success' => 'Name replaced:',
'distribution_search_name_update_fail' => 'Failed to replace name',
'distribution_search_button_location' => 'Location',
'distribution_search_button_location_send' => 'Send location',
'distribution_search_location_send_title' => 'Send location',
'distribution_search_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_search_location_send_not_acceptable' => 'Failed to process the location',
'distribution_search_location_send_latitude_too_small' => 'Latitude must be \>\= 0 and \<\=90',
'distribution_search_location_send_latitude_too_big' => 'Latitude must be \>\= 0 and \<\=90',
'distribution_search_location_send_longitude_too_small' => 'Longitude must be \>\= 0 and \<\=180',
'distribution_search_location_send_longitude_too_big' => 'Longitude must be \>\= 0 and \<\=180',
'distribution_search_location_update_success' => 'Location replaced:',
'distribution_search_location_update_fail' => 'Failed to replace location',
'distribution_search_button_distance' => 'Distance',
'distribution_search_distance_request_title' => 'Enter distance',
'distribution_search_distance_request_description' => 'Search will be performed within a radius of this value using the Vincenty formula',
'distribution_search_distance_request_not_acceptable' => 'Failed to process the distance',
'distribution_search_distance_request_too_short_km' => 'Distance value must be \>\= 0 and \<\= 600',
'distribution_search_distance_request_too_long_km' => 'Distance value must be \>\= 0 and \<\= 600',
'distribution_search_distance_request_restricted_characters_title' => "Restricted any characters except digitals",
'distribution_search_distance_request_restricted_characters_description' => "Delete these characters:",
'distribution_search_distance_update_success' => 'Distance replaced:',
'distribution_search_distance_update_fail' => 'Failed to replace distance',
'distribution_search_button_start' => 'Start the search',
'distribution_search_button_end' => 'End the search',
'distribution_search_button_page_next' => 'Next page',
'distribution_search_button_map' => 'Map',
'distribution_search_button_memberships' => 'Memberships',
'distribution_search_button_volunteers' => 'Volunteers',
'distribution_search_button_plan' => 'Plan',
'distribution_search_button_unplan' => 'Cancel the planning',
'distribution_search_planned' => 'You planned to join to the distribution',
'distribution_search_already_planned' => 'You are already planned to join to the distribution',
'distribution_search_unplanned' => 'You canceled planning to join to the distribution',
'distribution_search_already_unplanned' => 'You are already canceled planning to join to the distribution',
'distribution_search_button_join' => 'Join',
'distribution_search_button_leave' => 'Leave',
'distribution_search_joined_title' => 'You joined the distribution',
'distribution_search_joined_description' => 'You stated yourself as the distribution structor',
'distribution_search_already_joined' => 'You are already stated as the distribution structor',
'distribution_search_leaved' => 'You leaved the distribution',
'distribution_search_already_leaved' => 'You are already leaved the distribution',
'distribution_search_button_message' => 'Message',
'distribution_search_km' => 'km',
'distribution_search_mi' => 'ml',
'distribution_search_membership_not_updated' => 'Failed to update the membership record in the database',
'distribution_search_membership_not_created' => 'Failed to create the membership record in the database',
'distribution_search_distribution_not_initialized' => 'Failed to initalize the distribution',
'distribution_search_message_not_initialized' => 'Failed to initialized the message',
'distribution_search_another_joined' => 'You are already a membership of another distribution',
'distribution_search_another_planned' => 'You are already planning to join another distribution',
// Distribution select
'distribution_select_started' => 'Process of the distribution selection started',
'distribution_select_not_started' => 'Process of the distribution selection has not started',
'distribution_select_ended' => 'Process of the distribution selection ended',
'distribution_select_not_localized' => 'Failed to initialize the distribution localization',
'distribution_select_not_named' => 'No name',
'distribution_select_continiued' => 'Process of the distribution select found and continiued',
'distribution_select_empty' => 'No distributions found',
'distribution_select_title' => 'Distribution selection',
'distribution_select_button_name' => 'Name',
'distribution_select_name_request_title' => 'Enter name',
'distribution_select_name_request_description' => 'Selection will be conducted by distributions names using the Levenshtein function',
'distribution_select_name_request_not_acceptable' => 'Failed to process the name',
'distribution_select_name_request_too_short' => 'Name length must be \>\= 3 and \<\= 64',
'distribution_select_name_request_too_long' => 'Name length must be \>\= 3 and \<\= 64',
'distribution_select_name_request_restricted_characters_title' => "Restricted any characters except letters",
'distribution_select_name_request_restricted_characters_description' => "Remove these characters:",
'distribution_select_name_update_success' => 'Name replaced:',
'distribution_select_name_update_fail' => 'Failed to replace name',
'distribution_select_button_location' => 'Location',
'distribution_select_button_location_send' => 'Send location',
'distribution_select_location_send_title' => 'Send location',
'distribution_select_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_select_location_send_not_acceptable' => 'Failed to process the location',
'distribution_select_location_send_latitude_too_small' => 'Latitude must be \>\= 0 and \<\=90',
'distribution_select_location_send_latitude_too_big' => 'Latitude must be \>\= 0 and \<\=90',
'distribution_select_location_send_longitude_too_small' => 'Longitude must be \>\= 0 and \<\=180',
'distribution_select_location_send_longitude_too_big' => 'Longitude must be \>\= 0 and \<\=180',
'distribution_select_location_update_success' => 'Location replaced:',
'distribution_select_location_update_fail' => 'Failed to replace location',
'distribution_select_page_next_exists' => 'There are more distributions in the registry',
'distribution_select_page_next_not_exists' => 'There are no more distributions in the registry',
'distribution_select_button_distance' => 'Distance',
'distribution_select_distance_request_title' => 'Enter distance',
'distribution_select_distance_request_description' => 'Selection will be performed within a radius of this value using the Vincenty formula',
'distribution_select_distance_request_not_acceptable' => 'Failed to process the distance',
'distribution_select_distance_request_too_short_km' => 'Distance value must be \>\= 0 and \<\= 600',
'distribution_select_distance_request_too_long_km' => 'Distance value must be \>\= 0 and \<\= 600',
'distribution_select_distance_request_restricted_characters_title' => "Restricted any characters except digitals",
'distribution_select_distance_request_restricted_characters_description' => "Delete these characters:",
'distribution_select_distance_update_success' => 'Distance replaced:',
'distribution_select_distance_update_fail' => 'Failed to replace distance',
'distribution_select_button_delete' => 'Delete',
'distribution_select_button_cancel' => 'Cancel',
'distribution_select_button_page_next' => 'Next page',
'distribution_select_button_select' => 'Select',
'distribution_select_km' => 'km',
'distribution_select_mi' => 'ml',
// Organisation
'organisation_title' => 'Organisation',
'organisation_description' => 'International association of all who want to live honestly and freely',
'organisation_structor' => 'Structor \- an anarchist representing the distribution',
'organisation_autonom' => 'Autonom - an anarchist representing only himself personally',
'organisation_warning_legal' => 'Do not do anything that breaks the law of the country you are in, do not trust anyone and think with your own head',
'organisation_warning_administration' => 'At this stage of the Antivertical project development, the administration reserves the right to make a sole decision on the removal of materials that are potentially dangerous for the organization and its participants',
'organisation_button_help' => 'Help',
'organisation_button_investor' => 'Investor',
'organisation_button_volunteer' => 'Volunteer',
'organisation_button_structor' => 'Structor',
'organisation_button_structor_distribution' => 'Distribution',
'organisation_button_autonom' => 'Autonom',
// Account
'account_title' => 'Account',
'account_identifier' => 'Identifier',
'account_export' => 'Export to the main blockchain network is available',
/* 'account_data' => "⚠️ Your data may be given to the special services of Russia\nBe careful and think with your head",
'account_security_repository' => 'Information security',
'account_security_repository_mirror_github' => 'mirror', */
'account_authorized_system' => 'Access to the system',
'account_authorized_messages' => 'Access to messages',
'account_authorized_autonom' => 'Be an autonom',
'account_authorized_structor' => 'Be a structor',
'account_authorized_volunteer' => 'Be a volunteer',
'account_authorized_investor' => 'Be an investor',
'account_authorized_recruiter' => 'Be a recruiter',
'account_authorized_settings' => 'Access to settings',
'account_authorized_system_accounts' => 'Access to the accounts system',
'account_authorized_system_distributions' => 'Access to the distributions system',
'account_authorized_system_settings' => 'Access to the system settings',
'account_button_localizations' => 'Localizations',
'account_localization_create_failted_to_initialize_language' => 'Failed to initialize language',
'account_localization_title' => 'Localizations',
'account_localization_amount' => 'Amount',
'account_localization_create' => 'Create a localization',
'account_localization_create_started' => 'Process of the account localization creating started',
'account_localization_create_not_started' => 'Process of the account localization creating not started',
'account_localization_create_ended' => 'Process of the account localization creating ended',
'account_localization_create_continiued' => 'Process of the account localization creating found and continiued',
'account_localization_create_generation' => 'The account localization record generation',
'account_localization_create_created' => 'Created the account localization record in the database',
'account_localization_create_canceled' => 'Process of the account localization creating canceled',
'account_localization_create_completed' => 'Process of the account localization creating completed',
'account_localization_create_not_created' => 'Failed to create the account localization record in the database',
'account_localization_create_every_language_created' => 'Localizations have already been created for all languages existing in the registry',
'account_localization_create_button_language' => 'Language',
'account_localization_create_select_language_title' => 'Choose a language',
'account_localization_create_select_language_description' => "The selected language will be used when creating the account localization\n\nYou can create 1 localization for each language",
'account_localization_create_language_update_success' => 'Language replaced:',
'account_localization_create_language_update_fail' => 'Failed to replace language',
'account_localization_create_button_name' => 'Name',
'account_localization_create_name_request' => 'Enter name',
'account_localization_create_name_request_not_acceptable' => 'Failed to process the name',
'account_localization_create_name_request_too_short' => 'Name length must be \>\= 2 and \<\= 128',
'account_localization_create_name_request_too_long' => 'Name length must be \>\= 2 and \<\= 128',
'account_localization_create_name_request_restricted_characters_title' => "Restricted any characters except letters, dashes and spaces",
'account_localization_create_name_request_restricted_characters_description' => "Remove these characters:",
'account_localization_create_name_update_success' => 'Name replaced:',
'account_localization_create_name_update_fail' => 'Failed to replace name',
'account_localization_create_button_confirm' => 'Confirm',
'account_localization_create_button_cancel' => 'Cancel',
'account_localization_update_started' => 'Process of the account localization updating started',
'account_localization_update_not_started' => 'Process of the account localization updating not started',
'account_localization_update_ended' => 'Process of the account localization updating ended',
'account_localization_update_continiued' => 'Process of the account localization updating found and continiued',
'account_localization_update_generation' => 'The account localization record generation',
'account_localization_update_generation_target' => 'Editing',
'account_localization_update_updated' => 'Updated the account localization record in the database',
'account_localization_update_canceled' => 'Process of the account localization updating canceled',
'account_localization_update_completed' => 'Process of the account localization updating completed',
'account_localization_update_not_updated' => 'Failed to update the account localization record in the database',
'account_localization_update_not_initialized_localization' => 'Failed to initialize the account localization from the database',
'account_localization_update_button_name' => 'Name',
'account_localization_update_name_request' => 'Enter name',
'account_localization_update_name_request_not_acceptable' => 'Failed to process the name',
'account_localization_update_name_request_too_short' => 'Name length must be \>\= 2 and \<\= 128',
'account_localization_update_name_request_too_long' => 'Name length must be \>\= 2 and \<\= 128',
'account_localization_update_name_request_restricted_characters_title' => "Restricted any characters except letters, dashes and spaces",
'account_localization_update_name_request_restricted_characters_description' => "Remove these characters:",
'account_localization_update_name_update_success' => 'Name replaced:',
'account_localization_update_name_update_fail' => 'Failed to replace name',
'account_localization_update_button_confirm' => 'Confirm',
'account_localization_update_button_cancel' => 'Cancel',
'account_localization_search' => 'search',
// Language setting
'settings_select_language_title' => 'Select language',
'settings_select_language_description' => 'The selected language will be writed in your account settings',
'settings_language_update_success' => 'Language replaced:',
'settings_language_update_fail' => 'Failed to replace language',
// Language selection
'select_language_title' => 'Select language',
'select_language_description' => 'The selected language will be used in the current process',
'select_language_button_add' => 'Add a language',
// Repository
'repository_title' => 'Repository',
'repository_text' => <<<TXT
Svoboder is written in [PHP](https://www.php.net/) using [Zanzara](https://github.com/badfarm/zanzara) for Telegram,
my [MINIMAL](https://git.svoboda.works/mirzaev/minimal) framework for PHP and my [Baza](https://git.svoboda.works/mirzaev/baza) database
The code is under the [WTFPL](https://en.wikipedia.org/wiki/WTFPL) license
You can help me with the development, or use my code for free\!
TXT,
'repository_button_code' => 'The code',
'repository_button_issues' => 'Issues',
'repository_button_suggestions' => 'Suggestions',
// Author
'author_title' => 'Author',
'author_text' => <<<TXT
*Arsen Mirzaev Tatyano\-Muradovich*
Programmer, anarchist, vegetarian
TXT,
'author_button_neurojournal' => 'Neurojournal',
'author_button_projects' => 'Projects',
'author_button_twitter' => 'Twitter',
'author_button_bluesky' => 'Bluesky',
'author_button_bastyon' => 'Bastyon',
'author_button_youtube_english' => 'YouTube',
'author_button_youtube_russian' => 'YouTube',
'author_button_message' => 'Send a message',
// Authorization
'not_authorized_system' => 'You do not have access to the system',
'not_authorized_messages' => 'You do not have access to send messages',
'not_authorized_joins' => 'You do not have access to joins',
'not_authorized_settings' => 'You do not have access to the settings',
'not_authorized_system_settings' => 'You do not have access to the system settings',
'not_authorized_system_distributions' => 'You do not have access to distributions administration',
// Other
'why_so_shroomious' => 'why so shroomious',
];

View File

@@ -0,0 +1,417 @@
<?php
// Exit (success)
return [
// Система
'svoboda' => 'Свобода',
'antivertical' => 'Антивертикаль',
'empty' => 'Пусто',
'yes' => 'Да',
'no' => 'Нет',
// Главное меню
'menu_title' => 'Антивертикаль',
'menu_accounts' => 'Аккаунты',
'menu_distributions' => 'Дистрибутивы',
'menu_structors' => 'Структоры',
'menu_autonoms' => 'Автономы',
'menu_volunteers' => 'Волонтёры',
'menu_investors' => 'Инвесторы',
'menu_recruiters' => 'Вербовщики',
/* 'menu_' => '', */
'menu_not_syncronized' => 'База данных не синхронизирована с блокчейн сетью',
'menu_warning_database' => 'База данных публикуется в репозиторий ежедневно',
'menu_button_channel' => 'Канал',
'menu_button_site' => 'Сайт',
'menu_button_map' => 'Карта',
'menu_button_blog' => 'Блог',
'menu_button_chats' => 'Чаты',
'menu_button_channels' => 'Каналы',
'menu_button_memberships' => 'Участники',
'menu_button_distributions' => 'Дистрибутивы',
'menu_button_projects' => 'Проекты',
'menu_button_events' => 'События',
'menu_button_organisation' => 'Организация',
// Думающие штуки
'thing_about_it_1' => 'Великие имена создаются на востоке',
'thing_about_it_1_author' => 'Лермонтов М. Ю.',
'thing_about_it_2' => '',
'thing_about_it_3' => '',
'thing_about_it_4' => '',
'thing_about_it_5' => '',
/* 'thing_about_it_' => '',
'thing_about_it__author' => '', */
// Участники
'memberships_title' => 'Реестр участников',
'memberships_structor' => '*Структор* \- анархист, представляющий дистрибутив',
'memberships_autonom' => '*Автоном* \- анархист, представляющий только себя лично',
'memberships_button_search' => 'Поиск',
// Поиск участника
'membership_search_started' => 'Процесс поиска участника дистрибутива запущен',
'membership_search_not_started' => 'Процесс поиска участника дистрибутива не запущен',
'membership_search_ended' => 'Процесс поиска участника дистрибутива завершён',
'membership_search_not_localized' => 'Не удалось инициализировать локализацию аккаунта участника',
'membership_search_not_named' => 'Нет имени',
'membership_search_status' => 'Статус',
'membership_search_status_2' => 'Участие',
'membership_search_status_2_emoji' => '🧳',
'membership_search_status_1' => 'Планирование',
'membership_search_status_1_emoji' => '📅',
'membership_search_status_0' => 'Неизвестно',
'membership_search_status_0_emoji' => '👽',
'membership_search_continiued' => 'Процесс поиска участника дистрибутива найден и продолжен',
'membership_search_empty' => 'Не найдены участники дистрибутивов',
'membership_search_title' => 'Поиск участника дистрибутива',
'membership_search_distribution' => 'Дистрибутив',
'membership_search_page_next_exists' => 'В реестре есть ещё участники дистрибутивов',
'membership_search_page_next_not_exists' => 'В реестре больше нет участников дистрибутивов',
'membership_search_button_name' => 'Имя',
'membership_search_name_request_title' => 'Введи имя',
'membership_search_name_request_description' => 'Поиск будет проводиться по именам участников дистрибутивов с использованием функции Левенштейна',
'membership_search_name_request_not_acceptable' => 'Не удалось обработать имя',
'membership_search_name_request_too_short' => 'Длина имени должна быть \>\= 2 и \<\= 128',
'membership_search_name_request_too_long' => 'Длина имени должна быть \>\= 2 и \<\= 128',
'membership_search_name_request_restricted_characters_title' => "Запрещены любые символы кроме букв",
'membership_search_name_request_restricted_characters_description' => "Удали эти символы:",
'membership_search_name_update_success' => 'Имя заменено:',
'membership_search_name_update_fail' => 'Не удалось заменить имя',
'membership_search_button_start' => 'Начать поиск',
'membership_search_button_end' => 'Завершить поиск',
'membership_search_button_page_next' => 'Следующая страница',
'membership_search_button_message' => 'Сообщение',
'membership_search_button_distribution' => 'Дистрибутив',
'membership_search_button_status' => 'Статус',
'membership_search_button_status_2' => 'участие',
'membership_search_button_status_2_emoji' => '🧳',
'membership_search_button_status_1' => 'планирование',
'membership_search_button_status_1_emoji' => '📅',
'membership_search_button_status_0' => 'неизвестно',
'membership_search_button_status_0_emoji' => '👽',
// Дистрибутивы
'distributions_title' => 'Реестр дистрибутивов',
'distributions_description' => '*Дистрибутив* \- автономная ячейка Свободы, являющаяся любым видом формирования, подразумевающее безоговорочный солидарный союз со всеми признанными дистрибутивами внутри организации',
'distributions_declared' => 'Объявленные',
'distributions_recognized' => 'Признанные',
'distributions_button_search' => 'Поиск',
'distributions_button_declare' => 'Объявить',
// Выбор дистрибутива
/* 'select_distributions_title' => 'Выбери дистрибутив',
'select_distributions_description' => 'Выбранный дистрибутив будет использован в текущем процесса',
'select_distribution_button_registrate' => 'Зарегистрировать дистрибутив', */
// Объявление дистрибутива
'distribution_declaration_started' => 'Процесс объявления дистрибутива запущен',
'distribution_declaration_not_started' => 'Процесс объявления дистрибутива не запущен',
'distribution_declaration_ended' => 'Процесс объявления дистрибутива завершён',
'distribution_declaration_continiued' => 'Процесс объявления дистрибутива найден и продолжен',
'distribution_declaration_generation' => 'Генерация записи дистрибутива',
'distribution_declaration_created_distribution' => 'Создана запись дистрибутива в базе данных',
'distribution_declaration_created_localization' => 'Создана запись локализации дистрибутива в базе данных',
'distribution_declaration_canceled' => 'Процесс объявления дистрибутива отменён',
'distribution_declaration_completed' => 'Процесс объявления дистрибутива завершен',
'distribution_declaration_not_created_distribution' => 'Не удалось создать запись дистрибутива в базе данных',
'distribution_declaration_not_created_localization' => 'Не удалось создать запись локализации дистрибутива в базе данных',
'distribution_declaration_button_language' => 'Язык',
'distribution_declaration_select_language_title' => 'Выбери язык',
'distribution_declaration_select_language_description' => "Выбранный язык позволит создать локализацию для пользователей с таким же языком\n\nТы можешь создать 1 локализацию для каждого языка",
'distribution_declaration_language_update_success' => 'Язык заменён:',
'distribution_declaration_language_update_fail' => 'Не удалось заменить язык',
'distribution_declaration_button_name' => 'Название',
'distribution_declaration_name_request' => 'Введи название',
'distribution_declaration_name_request_not_acceptable' => 'Не удалось обработать название',
'distribution_declaration_name_request_too_short' => 'Длина имени должна быть \>\= 3 и \<\= 64',
'distribution_declaration_name_request_too_long' => 'Длина имени должна быть \>\= 3 и \<\= 64',
'distribution_declaration_name_request_spaces' => "Разрешено использовать не более чем 2 пробела",
'distribution_declaration_name_request_restricted_characters_title' => "Запрещены любые символы кроме букв",
'distribution_declaration_name_request_restricted_characters_description' => "Удали эти символы:",
'distribution_declaration_name_update_success' => 'Название заменено:',
'distribution_declaration_name_update_fail' => 'Не удалось заменить название',
'distribution_declaration_button_location' => 'Местоположение',
'distribution_declaration_button_location_send' => 'Отправить местоположение',
'distribution_declaration_location_send_title' => 'Отправь местоположение',
'distribution_declaration_location_send_description' => "У тебя появилась кнопка на основной клавиатуре\nПри нажатии на неё можно будет выбрать локацию на карте\n\n*Пришли широту и долготу в формате:* 50\.969043, 9\.797588",
'distribution_declaration_location_send_not_acceptable' => 'Не удалось обработать местоположение',
'distribution_declaration_location_send_latitude_too_small' => 'Широта должна быть \>\= 0 и \<\=90',
'distribution_declaration_location_send_latitude_too_big' => 'Широта должна быть \>\= 0 и \<\=90',
'distribution_declaration_location_send_longitude_too_small' => 'Долгота должна быть \>\= 0 и \<\=180',
'distribution_declaration_location_send_longitude_too_big' => 'Долгота должна быть \>\= 0 и \<\=180',
'distribution_declaration_location_update_success' => 'Местоположение заменено:',
'distribution_declaration_location_update_fail' => 'Не удалось заменить местоположение',
'distribution_declaration_button_confirm' => 'Подтвердить',
'distribution_declaration_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 локализацию для каждого языка",
// Поиск дистрибутива
'distribution_search_started' => 'Процесс поиска дистрибутива запущен',
'distribution_search_not_started' => 'Процесс поиска дистрибутива не запущен',
'distribution_search_ended' => 'Процесс поиска дистрибутива завершён',
'distribution_search_not_localized' => 'Не удалось инициализировать локализацию дистрибутива',
'distribution_search_not_named' => 'Нет названия',
'distribution_search_continiued' => 'Процесс поиска дистрибутива найден и продолжен',
'distribution_search_empty' => 'Не найдены дистрибутивы',
'distribution_search_title' => 'Поиск дистрибутива',
'distribution_search_memberships' => 'Участники',
'distribution_search_recognized' => 'Признанные',
'distribution_search_planners' => 'Планирующие',
'distribution_search_volunteers' => 'Волонтёры',
'distribution_search_messages' => 'Сообщения',
'distribution_search_location' => 'Местоположение',
'distribution_search_page_next_exists' => 'В реестре есть ещё дистрибутивы',
'distribution_search_page_next_not_exists' => 'В реестре больше нет дистрибутивов',
'distribution_search_button_name' => 'Название',
'distribution_search_name_request_title' => 'Введи название',
'distribution_search_name_request_description' => 'Поиск будет проводиться по названиям с использованием функции Левенштейна',
'distribution_search_name_request_not_acceptable' => 'Не удалось обработать название',
'distribution_search_name_request_too_short' => 'Длина названия должна быть \>\= 3 и \<\= 64',
'distribution_search_name_request_too_long' => 'Длина названия должна быть \>\= 3 и \<\= 64',
'distribution_search_name_request_restricted_characters_title' => "Запрещены любые символы кроме букв",
'distribution_search_name_request_restricted_characters_description' => "Удали эти символы:",
'distribution_search_name_update_success' => 'Название заменено:',
'distribution_search_name_update_fail' => 'Не удалось заменить название',
'distribution_search_button_location' => 'Местоположение',
'distribution_search_button_location_send' => 'Отправить местоположение',
'distribution_search_location_send_title' => 'Отправь местоположение',
'distribution_search_location_send_description' => "У тебя появилась кнопка на основной клавиатуре\nПри нажатии на неё можно будет выбрать локацию на карте\n\n*Пришли широту и долготу в формате:* 50\.969043, 9\.797588",
'distribution_search_location_send_not_acceptable' => 'Не удалось обработать местоположение',
'distribution_search_location_send_latitude_too_small' => 'Широта должна быть \>\= 0 и \<\=90',
'distribution_search_location_send_latitude_too_big' => 'Широта должна быть \>\= 0 и \<\=90',
'distribution_search_location_send_longitude_too_small' => 'Долгота должна быть \>\= 0 и \<\=180',
'distribution_search_location_send_longitude_too_big' => 'Долгота должна быть \>\= 0 и \<\=180',
'distribution_search_location_update_success' => 'Местоположение заменено:',
'distribution_search_location_update_fail' => 'Не удалось заменить местоположение',
'distribution_search_button_distance' => 'Расстояние',
'distribution_search_distance_request_title' => 'Введи расстояние',
'distribution_search_distance_request_description' => 'Поиск будет производиться в радиусе от этого значения по формуле Винсенти',
'distribution_search_distance_request_not_acceptable' => 'Не удалось обработать расстояние',
'distribution_search_distance_request_too_short_km' => 'Длина расстояния должна быть \>\= 0 и \<\= 600',
'distribution_search_distance_request_too_long_km' => 'Длина расстояния должна быть \>\= 0 и \<\= 600',
'distribution_search_distance_request_restricted_characters_title' => "Запрещены любые символы кроме цифр",
'distribution_search_distance_request_restricted_characters_description' => "Удали эти символы:",
'distribution_search_distance_update_success' => 'Расстояние заменено:',
'distribution_search_distance_update_fail' => 'Не удалось заменить расстояние',
'distribution_search_button_start' => 'Начать поиск',
'distribution_search_button_end' => 'Завершить поиск',
'distribution_search_button_page_next' => 'Следующая страница',
'distribution_search_button_map' => 'Карта',
'distribution_search_button_memberships' => 'Участники',
'distribution_search_button_volunteers' => 'Волонтёры',
'distribution_search_button_plan' => 'Запланировать',
'distribution_search_button_unplan' => 'Отменить планирование',
'distribution_search_planned' => 'Ты запланировал вступление в дистрибутив',
'distribution_search_already_planned' => 'Ты уже запланировал вступление в дистрибутив',
'distribution_search_unplanned' => 'Ты отменил запланированное вступление в дистрибутив',
'distribution_search_already_unplanned' => 'Ты уже отменил запланировал вступление в дистрибутив',
'distribution_search_button_join' => 'Присоединиться',
'distribution_search_button_leave' => 'Покинуть',
'distribution_search_joined_title' => 'Ты вступил в дистрибутив',
'distribution_search_joined_description' => 'Ты заявил о том, что являешься структором дистрибутива',
'distribution_search_already_joined' => 'Ты уже заявил себя структором дистрибутива',
'distribution_search_leaved' => 'Ты покинул дистрибутив',
'distribution_search_already_leaved' => 'Ты уже покинул дистрибутив',
'distribution_search_button_message' => 'Сообщение',
'distribution_search_km' => 'км',
'distribution_search_mi' => 'мл',
'distribution_search_membership_not_updated' => 'Не удалось обновить запись участника дистрибутива в базе данных',
'distribution_search_membership_not_created' => 'Не удалось создать запись участника дистрибутива в базе данных',
'distribution_search_distribution_not_initialized' => 'Не удалось инициализировать дистрибутив',
'distribution_search_message_not_initialized' => 'Не удалось инициализировать сообщение',
'distribution_search_another_joined' => 'Ты уже являешься участником другого дистрибутива',
'distribution_search_another_planned' => 'Ты уже планируешь вступить в другой дистрибутив',
// Выбор дистрибутива
'distribution_select_started' => 'Процесс выбора дистрибутива запущен',
'distribution_select_not_started' => 'Процесс выбора дистрибутива не запущен',
'distribution_select_ended' => 'Процесс выбора дистрибутива завершён',
'distribution_select_not_localized' => 'Не удалось инициализировать локализацию дистрибутива',
'distribution_select_not_named' => 'Нет названия',
'distribution_select_continiued' => 'Процесс выбора дистрибутива найден и продолжен',
'distribution_select_empty' => 'Не найдены дистрибутивы',
'distribution_select_title' => 'Выбор дистрибутива',
'distribution_select_page_next_exists' => 'В реестре есть ещё дистрибутивы',
'distribution_select_page_next_not_exists' => 'В реестре больше нет дистрибутивов',
'distribution_select_button_name' => 'Название',
'distribution_select_name_request_title' => 'Введи название',
'distribution_select_name_request_description' => 'выбор будет проводиться по названиям с использованием функции Левенштейна',
'distribution_select_name_request_not_acceptable' => 'Не удалось обработать название',
'distribution_select_name_request_too_short' => 'Длина названия должна быть \>\= 3 и \<\= 64',
'distribution_select_name_request_too_long' => 'Длина названия должна быть \>\= 3 и \<\= 64',
'distribution_select_name_request_restricted_characters_title' => "Запрещены любые символы кроме букв",
'distribution_select_name_request_restricted_characters_description' => "Удали эти символы:",
'distribution_select_name_update_success' => 'Название заменено:',
'distribution_select_name_update_fail' => 'Не удалось заменить название',
'distribution_select_button_location' => 'Местоположение',
'distribution_select_button_location_send' => 'Отправить местоположение',
'distribution_select_location_send_title' => 'Отправь местоположение',
'distribution_select_location_send_description' => "У тебя появилась кнопка на основной клавиатуре\nПри нажатии на неё можно будет выбрать локацию на карте\n\n*Пришли широту и долготу в формате:* 50\.969043, 9\.797588",
'distribution_select_location_send_not_acceptable' => 'Не удалось обработать местоположение',
'distribution_select_location_send_latitude_too_small' => 'Широта должна быть \>\= 0 и \<\=90',
'distribution_select_location_send_latitude_too_big' => 'Широта должна быть \>\= 0 и \<\=90',
'distribution_select_location_send_longitude_too_small' => 'Долгота должна быть \>\= 0 и \<\=180',
'distribution_select_location_send_longitude_too_big' => 'Долгота должна быть \>\= 0 и \<\=180',
'distribution_select_location_update_success' => 'Местоположение заменено:',
'distribution_select_location_update_fail' => 'Не удалось заменить местоположение',
'distribution_select_button_distance' => 'Расстояние',
'distribution_select_distance_request_title' => 'Введи расстояние',
'distribution_select_distance_request_description' => 'Поиск будет производиться в радиусе от этого значения по формуле Винсенти',
'distribution_select_distance_request_not_acceptable' => 'Не удалось обработать расстояние',
'distribution_select_distance_request_too_short_km' => 'Длина расстояния должна быть \>\= 0 и \<\= 600',
'distribution_select_distance_request_too_long_km' => 'Длина расстояния должна быть \>\= 0 и \<\= 600',
'distribution_select_distance_request_restricted_characters_title' => "Запрещены любые символы кроме цифр",
'distribution_select_distance_request_restricted_characters_description' => "Удали эти символы:",
'distribution_select_distance_update_success' => 'Расстояние заменено:',
'distribution_select_distance_update_fail' => 'Не удалось заменить расстояние',
'distribution_select_button_select' => 'Выбрать',
'distribution_select_button_cancel' => 'Отменить выбор',
'distribution_select_button_page_next' => 'Следующая страница',
// Организация
'organisation_title' => 'Организация',
'organisation_description' => 'Интернациональное объединение всех кто хочет жить честно и свободно, где никто ни от кого ничего не требует и ни к чему не принуждает',
'organisation_structor' => '*Структор* \- анархист, представляющий дистрибутив',
'organisation_autonom' => '*Автоном* \- анархист, представляющий только себя лично',
'organisation_warning_legal' => 'Не делайте ничего, что нарушает закон страны в которой вы находитесь, не доверяйте никому и думайте своей головой',
'organisation_warning_administration' => 'На данном этапе развития проекта Антивертикаль администрация сохраняет за собой право единолично принимать решение по удалению потенциально опасных для организации и её участников материалов',
'organisation_button_help' => 'Помощь',
'organisation_button_investor' => 'Инвестор',
'organisation_button_volunteer' => 'Волонтёр',
'organisation_button_structor' => 'Структор',
'organisation_button_structor_distribution' => 'Дистрибутив',
'organisation_button_autonom' => 'Автоном',
// Аккаунт
'account_title' => 'Аккаунт',
'account_identifier' => 'Идентификатор',
'account_export' => 'Доступен экспорт в основную блокчейн сеть',
/* 'account_data' => "⚠️ Твои данные могут быть выданы спецслужбам России\nБудь осторожен и думай своей головой",
'account_security_repository' => 'Информационная безопасность',
'account_security_repository_mirror_github' => 'зеркало', */
'account_authorized_system' => 'Доступ к системе',
'account_authorized_messages' => 'Доступ к сообщениям',
'account_authorized_authonom' => 'Становиться автономом',
'account_authorized_structor' => 'Становиться структором',
'account_authorized_volunteer' => 'Становиться волонтёром',
'account_authorized_investor' => 'Становиться инвестором',
'account_authorized_recruiter' => 'Становиться вербовщиком',
'account_authorized_relations' => 'Доступ к отношениям',
'account_authorized_settings' => 'Доступ к настройкам',
'account_authorized_system_accounts' => 'Доступ к системе аккаунтов',
'account_authorized_system_distributions' => 'Доступ к системе дистрибутивов',
'account_authorized_system_settings' => 'Доступ к системным настройкам',
'account_button_localizations' => 'Локализации',
'account_localization_create_failted_to_initialize_language' => 'Не удалось инициализировать язык',
'account_localization_title' => 'Локализации',
'account_localization_amount' => 'Количество',
'account_localization_create' => 'Создать локализацию',
'account_localization_create_started' => 'Процесс создания локализации аккаунта запущен',
'account_localization_create_not_started' => 'Процесс создания локализации аккаунта не запущен',
'account_localization_create_ended' => 'Процесс создания локализации аккаунта завершён',
'account_localization_create_continiued' => 'Процесс создания локализации аккаунта найден и продолжен',
'account_localization_create_generation' => 'Генерация записи локализации аккаунта',
'account_localization_create_created' => 'Создана запись локализации аккаунта в базе данных',
'account_localization_create_canceled' => 'Процесс создания локализации аккаунта отменён',
'account_localization_create_completed' => 'Процесс создания локализации аккаунта завершен',
'account_localization_create_not_created' => 'Не удалось создать запись локализации аккаунта в базе данных',
'account_localization_create_every_language_created' => 'Для всех существующих в реестре языков уже были созданы локализации',
'account_localization_create_button_language' => 'Язык',
'account_localization_create_select_language_title' => 'Выбери язык',
'account_localization_create_select_language_description' => "Выбранный язык будет использован при создания локализации аккаунта\n\nТы можешь создать 1 локализацию для каждого языка",
'account_localization_create_language_update_success' => 'Язык заменён:',
'account_localization_create_language_update_fail' => 'Не удалось заменить язык',
'account_localization_create_button_name' => 'Имя',
'account_localization_create_name_request' => 'Введи имя',
'account_localization_create_name_request_not_acceptable' => 'Не удалось обработать имя',
'account_localization_create_name_request_too_short' => 'Длина имени должна быть \>\= 2 и \<\= 128',
'account_localization_create_name_request_too_long' => 'Длина имени должна быть \>\= 2 и \<\= 128',
'account_localization_create_name_request_restricted_characters_title' => "Запрещены любые символы кроме букв, тире и пробелов",
'account_localization_create_name_request_restricted_characters_description' => "Удали эти символы:",
'account_localization_create_name_update_success' => 'Имя заменено:',
'account_localization_create_name_update_fail' => 'Не удалось заменить имя',
'account_localization_create_button_confirm' => 'Подтвердить',
'account_localization_create_button_cancel' => 'Отменить',
'account_localization_update_started' => 'Процесс обновления локализации аккаунта запущен',
'account_localization_update_not_started' => 'Процесс обновления локализации аккаунта не запущен',
'account_localization_update_ended' => 'Процесс обновления локализации аккаунта завершён',
'account_localization_update_continiued' => 'Процесс обновления локализации аккаунта найден и продолжен',
'account_localization_update_generation' => 'Генерация записи локализации аккаунта',
'account_localization_update_generation_target' => 'Редактирование',
'account_localization_update_updated' => 'Обновлена запись локализации аккаунта в базе данных',
'account_localization_update_canceled' => 'Процесс обновления локализации аккаунта отменён',
'account_localization_update_completed' => 'Процесс обновления локализации аккаунта завершен',
'account_localization_update_not_updated' => 'Не удалось обновить запись локализации аккаунта в базе данных',
'account_localization_update_not_initialized_localization' => 'Не удалось инициализировать локализацию аккаунта из базы данных',
'account_localization_update_button_name' => 'Имя',
'account_localization_update_name_request' => 'Введи имя',
'account_localization_update_name_request_not_acceptable' => 'Не удалось обработать имя',
'account_localization_update_name_request_too_short' => 'Длина имени должна быть \>\= 2 и \<\= 128',
'account_localization_update_name_request_too_long' => 'Длина имени должна быть \>\= 2 и \<\= 128',
'account_localization_update_name_request_restricted_characters_title' => "Запрещены любые символы кроме букв, тире и пробелов",
'account_localization_update_name_request_restricted_characters_description' => "Удали эти символы:",
'account_localization_update_name_update_success' => 'Имя заменено:',
'account_localization_update_name_update_fail' => 'Не удалось заменить имя',
'account_localization_update_button_confirm' => 'Подтвердить',
'account_localization_update_button_cancel' => 'Отменить',
'account_localization_search' => 'Поиск',
// Настройки языка
'settings_select_language_title' => 'Выбери язык',
'settings_select_language_description' => 'Выбранный язык будет записан в настройки аккаунта',
'settings_language_update_success' => 'Язык заменён:',
'settings_language_update_fail' => 'Не удалось заменить язык',
// Выбор языка
'select_language_title' => 'Выбери язык',
'select_language_description' => 'Выбранный язык будет использован в текущем процессе',
'select_language_button_add' => 'Добавить язык',
// Репозиторий
'repository_title' => 'Репозиторий',
'repository_text' => <<<TXT
Svoboder написан на [PHP](https://www.php.net/) используя [Zanzara](https://github.com/badfarm/zanzara) для Telegram,
мой [MINIMAL](https://git.svoboda.works/mirzaev/minimal) фреймворк для PHP и моя база данных [Baza](https://git.svoboda.works/mirzaev/baza)
Код находится под лицензией [WTFPL](https://en.wikipedia.org/wiki/WTFPL)
Помогай с разработкой или используй мой код бесплатно\!
TXT,
'repository_button_code' => 'Код',
'repository_button_issues' => 'Проблемы',
'repository_button_suggestions' => 'Предложения',
// Автор
'author_title' => 'Автор',
'author_text' => <<<TXT
*Арсен Мирзаев Татьяно\-Мурадович*
Программист, анархист, вегетарианец
TXT,
'author_button_neurojournal' => 'Нейрожурнал',
'author_button_projects' => 'Проекты',
'author_button_twitter' => 'Twitter',
'author_button_bluesky' => 'Bluesky',
'author_button_bastyon' => 'Bastyon',
'author_button_youtube_english' => 'YouTube',
'author_button_youtube_russian' => 'YouTube',
'author_button_message' => 'Отправить сообщение',
// Авторизация
'not_authorized_system' => 'У тебя нет доступа к системе',
'not_authorized_messages' => 'У тебя нет доступа к сообщениям',
'not_authorized_joins' => 'У тебя нет доступа к вступлениям',
'not_authorized_settings' => 'У тебя нет доступа к настройкам',
'not_authorized_system_settings' => 'У тебя нет доступа к системным настройкам',
'not_authorized_system_distributions' => 'У тебя нет доступа к администрированию дистрибутивов',
// Прочее
'why_so_shroomious' => 'почему такой грибъёзный',
];

View File

@@ -0,0 +1,484 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\connection,
svoboda\antivertical\models\telegram,
svoboda\antivertical\models\membership,
svoboda\antivertical\models\interfaces\ar as active_record,
svoboda\antivertical\models\traits\ar as active_record_trait,
svoboda\antivertical\models\enumerations\language,
svoboda\antivertical\models\enumerations\membership\status,
svoboda\antivertical\models\account\localization;
// Svoboda time
use svoboda\time\statement as svoboda;
// Baza database
use mirzaev\baza\database,
mirzaev\baza\column,
mirzaev\baza\record,
mirzaev\baza\enumerations\encoding,
mirzaev\baza\enumerations\type;
// Built-in libraries
use Exception as exception,
RuntimeException as exception_runtime,
LogicException as exception_logic,
InvalidArgumentException as exception_invalid_argument;
/**
* Account
*
* @uses active_record
* @uses active_record_trait
*
* @package svoboda\antivertical\models
*
* @property string $file Path to the database file
* @property database $database The database
* @property record $record The database record
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class account extends core implements active_record
{
use active_record_trait;
/**
* File
*
* @var string $database Path to the database file
*/
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'accounts.baza';
/**
* Database
*
* @var database $database The database
*/
public protected(set) database $database;
/**
* Localization
*
* @var localization $localization The localizations implementator
*/
public protected(set) localization $localization;
/**
* Constructor
*
* @param record|null $record The database 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('name', type::string, ['length' => 64]),
new column('language', type::string, ['length' => 2]),
new column('authorized_system', type::char),
new column('authorized_messages', type::char),
new column('authorized_authonom', type::char),
new column('authorized_structor', type::char),
new column('authorized_volunteer', type::char),
new column('authorized_investor', type::char),
new column('authorized_recruiter', type::char),
new column('authorized_settings', type::char),
new column('authorized_system_accounts', type::char),
new column('authorized_system_distributions', type::char),
new column('authorized_system_settings', type::char),
new column('updated', type::integer_unsigned),
new column('created', type::integer_unsigned)
)
->connect($this->file);
// Initializing the localizations implementator
$this->localization = new localization;
// Initializing the database record
if ($record) $this->record = $record;
}
/**
* Initialize
*
* Searches for the account record by the telegram account in the database,
* and if it does not find it, then create the account record and the connection record
*
* @param telegram $telegram The telegram account
*
* @throws exception_runtime if failed to deactivate the connection between missing account and the telegram account
* @throws exception_runtime if failed to connect the account with the telegram account
* @throws exception_runtime if failed to find the created account
* @throws exception_runtime if failed to create the account
*
* @return static The account record implementator
*/
public function initialize(telegram $telegram): static
{
// Initializing the connection model
$connection = new connection;
// Searching for the connection record between theaccount and the telegram account in the database
$connected = $connection->read(filter: fn(record $record) => $record->telegram === $telegram->identifier);
if ($connected instanceof connection) {
// Found the connection record between the account and the telegram account
// Searching for the account in the database
$account = $this->read(filter: fn(record $record) => $record->identifier === $connected->account);
if ($account instanceof static) {
// Found the account
// Exit (success)
return $account;
} else {
// Not found the account
// Deactivating the connection between missing account and the telegram account
$deactivated = $connected->update(
filter: fn(record $record) => $record->identifier === $connected->identifier,
update: function (record &$record) {
$record->active = 0;
$record->updated = svoboda::timestamp();
}
);
if ($deactivated instanceof connection && $deactivated->active === 0) {
// Deactivated the connection between missing account and the telegram account
// Creating the account
goto create;
} else {
// Failed to deactivate the connection between missing account and the telegram account
// Exit (fail)
throw new exception_runtime('Failed to deactivate the connection between missing account and the telegram account');
}
}
} else {
// Not found the connection record between the account and the telegram account
// Creating the account process start
create:
// Creating the account
$identifier = $this->create("$telegram->name_first $telegram->name_second", language::{$telegram->language ?? language::en->name} ?? language::en);
if ($identifier) {
// Created the account
// Searching for the created account in the database
$account = $this->read(filter: fn(record $record) => $record->identifier === $identifier);
if ($account instanceof static) {
// Found the created account
// Connecting the created account with the telegram account
$connected = $connection->create(account: $account->identifier, telegram: $telegram->identifier);
if ($connected) {
// Connected the created account with the telegram account
// Exit (success)
return $account;
} else {
// Not connected the created account with the telegram account
// Exit (fail)
throw new exception_runtime('Failed to connect the account with the telegram account');
}
} else {
// Not found the created account
// Exit (fail)
throw new exception_runtime('Failed to find the created account');
}
} else {
// Not created the account
// Exit (fail)
throw new exception_runtime('Failed to create the account');
}
}
}
/**
* Create
*
* Creates the account record in the database
*
* @param string $name Name
* @param language $language Language for generating views
*
* @return int|false The record identifier, if created
*/
public function create(string $name, language $language): int|false
{
// Initializing the identifier
$identifier = $this->database->count() + 1;
// Initializing the record
$record = $this->database->record(
$identifier,
$name,
$language->name,
ACCOUNT_ACCESS_SYSTEM,
ACCOUNT_ACCESS_MESSAGES,
ACCOUNT_ACCESS_AUTHONOM,
ACCOUNT_ACCESS_STRUCTOR,
ACCOUNT_ACCESS_VOLUNTEER,
ACCOUNT_ACCESS_INVESTOR,
ACCOUNT_ACCESS_RECRUITER,
ACCOUNT_ACCESS_SETTINGS,
ACCOUNT_ACCESS_SYSTEM_ACCOUNTS,
ACCOUNT_ACCESS_SYSTEM_DISTRIBUTIONS,
ACCOUNT_ACCESS_SYSTEM_SETTINGS,
svoboda::timestamp(),
svoboda::timestamp()
);
// Creating the record in the database
$created = $this->database->write($record);
// Exit (success)
return $created ? $identifier : false;
}
/**
* Distribution
*
* Search for the account distribution
*
* @return distribution|false The account distribution, if found
*/
public function distribution(): distribution|false
{
// Searching for the distribution membership
$membership = $this->memberships(amount: 1, offset: 0)[0] ?? false;
if ($membership instanceof membership) {
// Initialized the distribution membership
// Initializing the distribution model
$model = new distribution();
// Searching for the distribution
$distribution = $model->read(filter: fn(record $record) => $record->identifier === $membership->distribution);
// Exit (success/fail)
return $distribution;
}
// Exit (fail)
return false;
}
/**
* Memberships
*
* @param status $status A membership status
* @param int $amount Amount
* @param int $offset Offset
*
* @return array The account memberships
*/
public function memberships(
status $status = status::joined,
int $amount = 100,
int $offset = 0
): array {
// Initializing the membership model
$model = new membership;
// Initializing the account memberships
$memberships = $model->database->read(
filter: fn(record $record) => $record->account === $this->identifier && $record->status === $status->value,
amount: $amount,
offset: $offset
);
// Declaring the buffer of implemented records
$implemented = [];
foreach ($memberships as $record) {
// Iterating over memberships records
// Initializing the implementator object
$implementator = new membership();
if ($implementator instanceof active_record) {
// The implementator object implements the Active Record pattern
// Writing the record into the implementator object
$implementator->record = $record;
} else {
// The implementator object not implements the Active Record pattern
// Exit (fail)
throw new exception_logic('The implementator object not implements the Active Record pattern');
}
// Writing into the buffer of implemented record;
$implemented[] = $implementator;
}
// Exit (success)
return $implemented;
}
/**
* Structors
*
* @param int $amount Amount
* @param int $offset Offset
*
* @return array Structors
*/
public static function structors(int $amount = 100, int $offset = 0): array
{
// Initializing the membership model
$model = new membership;
// Initializing the account memberships
$memberships = $model->database->read(
filter: fn(record $record) => $record->status === status::joined->value,
amount: $amount,
offset: $offset
);
// Exit (success)
return $memberships;
}
/**
* Planned
*
* @param int $amount Amount
* @param int $offset Offset
*
* @return array Planned
*/
public static function planned(int $amount = 100, int $offset = 0): array
{
// Initializing the membership model
$model = new membership;
// Initializing the account memberships
$memberships = $model->database->read(
filter: fn(record $record) => $record->status === status::planned,
amount: $amount,
offset: $offset
);
// Exit (success)
return $memberships;
}
/**
* Autonoms
*
* @param int $amount Amount
* @param int $offset Offset
*
* @return array Autonoms
*/
public static function autonoms(int $amount = 100, int $offset = 0): array
{
// Initializing the membership model
$model = new membership;
// Initializing the account memberships
$memberships = $model->database->read(
filter: fn(record $record) => $record->status === status::joined,
amount: $amount,
offset: $offset
);
// Exit (success)
return [];
}
/**
* Volunteers
*
* @param int $amount Amount
* @param int $offset Offset
*
* @return array Volunteers
*/
public static function volunteers(int $amount = 100, int $offset = 0): array
{
// Initializing the membership model
$model = new membership;
// Initializing the account memberships
$memberships = $model->database->read(
filter: fn(record $record) => $record->status === status::joined,
amount: $amount,
offset: $offset
);
// Exit (success)
return [];
}
/**
* Investors
*
* @param int $amount Amount
* @param int $offset Offset
*
* @return array Investors
*/
public static function investors(int $amount = 100, int $offset = 0): array
{
// Initializing the membership model
$model = new membership;
// Initializing the account memberships
$memberships = $model->database->read(
filter: fn(record $record) => $record->status === status::joined,
amount: $amount,
offset: $offset
);
// Exit (success)
return [];
}
/**
* Recruiters
*
* @param int $amount Amount
* @param int $offset Offset
*
* @return array Recruiters
*/
public static function recruiters(int $amount = 100, int $offset = 0): array
{
// Initializing the membership model
$model = new membership;
// Initializing the account memberships
$memberships = $model->database->read(
filter: fn(record $record) => $record->status === status::joined,
amount: $amount,
offset: $offset
);
// Exit (success)
return [];
}
}

View File

@@ -0,0 +1,105 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\account;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\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;
/**
* Localization
*
* @package svoboda\antivertical\models\account
*
* @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
{
/**
* File
*
* @var string $database Path to the database file
*/
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'accounts' . DIRECTORY_SEPARATOR . 'localizations.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('account', type::integer_unsigned),
new column('language', type::string, ['length' => 2]),
new column('name', type::string, ['length' => 128]),
new column('updated', type::integer_unsigned),
new column('created', type::integer_unsigned)
)
->connect($this->file);
}
/**
* Create
*
* Creates the account localization record in the database
*
* @param int $account Identifier of the account
* @param language $language Language
* @param string $name Name of the account
*
* @return int|false The record identifier, if created
*/
public function create(int $account, language $language, string $name): int|false
{
// Initializing the identifier
$identifier = $this->database->count() + 1;
// Initializing the record
$record = $this->database->record(
$identifier,
$account,
$language->name,
$name,
svoboda::timestamp(),
svoboda::timestamp()
);
// Creating the record in the database
$created = $this->database->write($record);
// Exit (success)
return $created ? $identifier : false;
}
}

View File

@@ -0,0 +1,128 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\enumerations\entity,
svoboda\antivertical\models\enumerations\membership\status,
svoboda\antivertical\models\interfaces\ar as active_record,
svoboda\antivertical\models\traits\ar as active_record_trait;
// 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;
/**
* Connection between account::class and telegram::class
*
* @uses active_record
* @uses active_record_trait
*
* @package svoboda\antivertical\models
*
* @property string $file Path to the database file
* @property database $database The database
* @property record $record The database record
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class connection extends core implements active_record
{
use active_record_trait;
/**
* File
*
* @var string $database Path to the database file
*/
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'connection.baza';
/**
* Database
*
* Identifier: The record identifier
* Account: The account identifier
* Telegram: The telegram account identifier
* Updated: Timestamp of the last the record update
* Created: Timestamp of the record creating
*
* @var database $database The database
*/
public protected(set) database $database;
/**
* Constructor
*
* @param record|null $record The database record
*
* @return void
*/
public function __construct(?record $record = null)
{
// Initializing the database
$this->database = new database()
->encoding(encoding::ascii)
->columns(
new column('identifier', type::long_long_unsigned),
new column('account', type::long_long_unsigned),
new column('telegram', type::long_long_unsigned),
new column('active', type::char),
new column('updated', type::integer_unsigned),
new column('created', type::integer_unsigned)
)
->connect($this->file);
// Initializing the database record
if ($record) $this->record = $record;
}
/**
* Create
*
* Creates the member record in the database
*
* @param int $account Identifier of the account
* @param int $telegram Identifier of the telegram account
* @param bool $active Is the connection active?
*
* @return int|false The record identifier, if created
*/
public function create(int $account, int $telegram, bool $active = true): int|false
{
// Initializing the identifier
$identifier = $this->database->count() + 1;
// Initializing the record
$record = $this->database->record(
$identifier,
$account,
$telegram,
(int) $active,
svoboda::timestamp(),
svoboda::timestamp()
);
// Creating the record in the database
$created = $this->database->write($record);
// Exit (success)
return $created ? $identifier : false;
}
}

View File

@@ -2,39 +2,31 @@
declare(strict_types=1);
namespace svoboda\negotiator\models;
namespace svoboda\antivertical\models;
// Framework for PHP
use mirzaev\minimal\model;
// Baza database
use mirzaev\baza\database,
mirzaev\baza\column,
mirzaev\baza\enumerations\encoding;
// Built-in libraries
use exception;
/**
* Models core
* Core
*
* @package svoboda\negotiator\models
* @package svoboda\antivertical\models
*
* @method void __construct(bool $initialize) Constructor
* @method void __construct() Constructor
*
* @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>
*/
class core extends model
{
/**
* Constructor
*
* @param bool $initialize Initialize a model?
*
* @return void
*/
public function __construct(bool $initialize = true)
{
// For the extends system
parent::__construct($initialize);
}
/**
* Write
*

View File

@@ -0,0 +1,331 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\distribution\localization,
svoboda\antivertical\models\distribution\message,
svoboda\antivertical\models\enumerations\language,
svoboda\antivertical\models\interfaces\ar as active_record,
svoboda\antivertical\models\traits\ar as active_record_trait,
svoboda\antivertical\models\enumerations\membership\status;
// 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
*
* @uses active_record
* @uses active_record_trait
*
* @package svoboda\antivertical\models
*
* @property string $file Path to the database file
* @property database $database The database
* @property record $record The database record
*
* @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 implements active_record
{
use active_record_trait;
/**
* 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;
/**
* Localization
*
* @var localization $localization The localizations implementator
*/
public protected(set) localization $localization;
/**
* Message
*
* @var localization $localization The messages implementator
*/
public protected(set) message $message;
/**
* Constructor
*
* @param record|null $record The database record
*
* @return void
*/
public function __construct(?record $record = null)
{
// Initializing the database
$this->database = new database()
->encoding(encoding::ascii)
->columns(
new column('identifier', type::long_long_unsigned),
new column('creator', type::long_long_unsigned),
new column('latitude', type::float),
new column('longitude', type::float),
new column('updated', type::integer_unsigned),
new column('created', type::integer_unsigned)
)
->connect($this->file);
// Initializing the localizations implementator
$this->localization = new localization;
// Initializing the messages implementator
$this->message = new message;
// Initializing the database record
if ($record) $this->record = $record;
}
/**
* Create
*
* Creates the distribution record in the database
*
* @param int $creator Identifier of the creator account (svoboda\antivertical\models\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 record in the database
$created = $this->database->write($record);
// Exit (success)
return $created ? $identifier : false;
}
/**
* Localization
*
* Initialize the distribution localization
* Priority: $language argument > english > the distribution creator language > first in the localizations registry
*
* @param language $language Language
*
* @return localization|false The distribtion localization, if initialized
*/
public function localization(language $language): localization|false
{
// Initializing localizations
$localizations = $this->localization->database->read(
filter: fn(record $localization) => $localization->distribution === $this->identifier,
amount: DISTRIBUTIONS_SEARCH_DISTRIBUTION_LOCALIZATIONS_AMOUNT
);
if (count($localizations) > 0) {
// Initialized the distributions localizations
foreach ($localizations as $record) {
// Iterating over localizations
if ($record->language === $language->name) {
// Found localization by the account language
// Initializing localization by the account language
$this->localization->record = $record;
// Exit (success)
break;
}
}
if (!isset($this->localization->record)) {
// Not initialized localization by the account language
foreach ($localizations as $record) {
// Iterating over localizations
if ($record->language === 'en') {
// Found localization by english language
// Initializing localization by english language
$this->localization->record = $record;
// Exit (success)
break;
}
}
if (!isset($this->localization->record)) {
// Not initialized localization by english language
// Initializing the account model
$model_account = new account;
// Initializing the distribution creator account
$creator = $model_account->read(filter: fn(record $account) => $account->identifier === $this->creator);
if ($creator instanceof account) {
// Initialized the distribution creator account
foreach ($localizations as $record) {
// Iterating over localizations
if ($record->language === $creator->language) {
// Found localization by the distribution creator account language
// Initializing localization by the distribution creator account language
$values = $record;
// Exit (success)
break;
}
}
}
if (!isset($this->localization->record)) {
// Not initialized localization by the distribution creator account language
// Initializing localization by the first found record
$this->localization->record = $localizations[0];
}
}
}
}
// Exit (success/fail)
return $this->localization;
}
/**
* Structors
*
* Search for the distribution structors
*
* @param int $amount Amount
* @param int $offset Offest
*
* @return array The distribution structors
*/
public function structors(int $amount = 100, int $offset = 0): array
{
// Initializing the membership model
$model_membership = new membership();
// Searching for memberships
$memberships = $model_membership->database->read(
filter: fn(record $record) => $record->distribution === $this->identifier && $record->status === status::joined->value,
amount: $amount,
offset: $offset
);
// Initializing the account model
$model_account = new account();
// Declaring the buffer of found structors
$structors = [];
foreach ($memberships as $membership) {
// Iterating over memberships
// Searching for the structor account
$structor = $model_account->read(filter: fn(record $record) => $record->identifier === $membership->account);
if ($structor instanceof account) {
// Initialized the structor account
// Writing into the buffer of found structors
$structors[] = $structor;
}
}
// Exit (fail)
return $structors;
}
/**
* Planners
*
* Search for the distribution planners
*
* @param int $amount Amount
* @param int $offset Offest
*
* @return array The distribution planners
*/
public function planners(int $amount = 100, int $offset = 0): array
{
// Initializing the membership model
$model_membership = new membership();
// Searching for memberships
$memberships = $model_membership->database->read(
filter: fn(record $record) => $record->distribution === $this->identifier && $record->status === status::planned->value,
amount: $amount,
offset: $offset
);
// Initializing the account model
$model_account = new account();
// Declaring the buffer of found planners
$planners = [];
foreach ($memberships as $membership) {
// Iterating over memberships
// Searching for the planner account
$planner = $model_account->read(filter: fn(record $record) => $record->identifier === $membership->account);
if ($planner instanceof account) {
// Initialized the planner account
// Writing into the buffer of found planners
$planners[] = $planner;
}
}
// Exit (fail)
return $planners;
}
}

View File

@@ -0,0 +1,116 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\distribution;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\enumerations\language,
svoboda\antivertical\models\interfaces\ar as active_record,
svoboda\antivertical\models\traits\ar as active_record_trait;
// 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;
/**
* Localization
*
* @uses active_record
* @uses active_record_trait
*
* @package svoboda\antivertical\models\distribution
*
* @property string $file Path to the database file
* @property database $database The database
* @property record $record The database record
*
* @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 active_record
{
use active_record_trait;
/**
* File
*
* @var string $database Path to the database file
*/
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'distributions' . DIRECTORY_SEPARATOR . 'localizations.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' => 64]),
new column('updated', type::integer_unsigned),
new column('created', 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 of the distribution
*
* @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 record in the database
$created = $this->database->write($record);
// Exit (success)
return $created ? $identifier : false;
}
}

View File

@@ -0,0 +1,105 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\distribution;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\enumerations\entity;
// 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;
/**
* Message
*
* @package svoboda\antivertical\models\distributions
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class message extends core
{
/**
* File
*
* @var string $database Path to the database file
*/
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'distributions' . DIRECTORY_SEPARATOR . 'messages.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('distribution', type::integer_unsigned),
new column('account', type::integer_unsigned),
new column('text', type::string, ['length' => 512]),
new column('updated', type::integer_unsigned),
new column('created', type::integer_unsigned)
)
->connect($this->file);
}
/**
* Create
*
* Creates the message record in the database
*
* @param int $distribution Identifier of the distribution
* @param int $account Identifier of the account
* @param string $text Text
*
* @return int|false The record identifier, if created
*/
public function create(int $distribution, int $account, string $text): int|false
{
// Initializing the identifier
$identifier = $this->database->count() + 1;
// Initializing the record
$record = $this->database->record(
$identifier,
$distribution,
$account,
$text,
svoboda::timestamp(),
svoboda::timestamp()
);
// Creating the record in the database
$created = $this->database->write($record);
// Exit (success)
return $created ? $identifier : false;
}
}

View File

@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\enumerations;
/**
* Entity
*
* Types of entities
*
* @package svoboda\antivertical\models\enumerations
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
enum entity: int
{
case system = 0;
case account = 1;
case distribution = 2;
}

View File

@@ -2,18 +2,17 @@
declare(strict_types=1);
namespace svoboda\negotiator\models\enumerations;
namespace svoboda\antivertical\models\enumerations;
/**
* Language
*
* Types of languages by ISO 639-1 standart
*
* @package svoboda\negotiator\models\enumerations
* @package svoboda\antivertical\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
{
@@ -28,10 +27,6 @@ enum language
* @param language|null $language Language into which to translate
*
* @return string Translated label of the language
*
* @todo
* 1. More languages
* 2. Cases???
*/
public function label(?language $language = language::en): string
{
@@ -47,4 +42,20 @@ enum language
}
};
}
/**
* Flag
*
* Initialize the flag emoji of the language
*
* @return string The flag emoji of the language
*/
public function flag(): string
{
// Exit (success)
return match ($this) {
language::en => '🇺🇸',
language::ru => '🇷🇺'
};
}
}

View File

@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\enumerations\membership;
/**
* Status
*
* Membership status
*
* @package svoboda\antivertical\models\enumerations\membership
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
enum status: int
{
case unknown = 0;
case planned = 1;
case joined = 2;
/**
* Emoji
*
* Initialize emoji of the status
*
* @return string Emoji of the status
*/
public function emoji(): string
{
// Exit (success)
return match ($this) {
status::unknown => '👽',
status::planned => '📅',
status::joined => '🧳'
};
}
}

View File

@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\enumerations\relation;
/**
* Type
*
* Relation type
*
* @package svoboda\antivertical\models\enumerations\relation
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
enum status: int
{
case unknown = 0;
case recognition = 1;
case unrecognition = 2;
}

View File

@@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\interfaces;
// Files of the project
use svoboda\antivertical\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;
// Built-in libraries
use Exception as exception,
RuntimeException as exception_runtime,
LogicException as exception_logic,
InvalidArgumentException as exception_invalid_argument;
/**
* AR
*
* The "Active Record" architectural pattern
*
* @see https://en.wikipedia.org/wiki/Active_record_pattern Active Record
*
* @package svoboda\antivertical\models\interfaces
*
* @method static|false read(callable $filter) Read from the database
* @method static|false update() Update the record in the database
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
interface ar
{
/**
* Constructor
*
* @throws exception_invalid_argument If not initialized the database columns parameters
*
* @return void
*/
public function __construct();
/**
* Read
*
* Search for the record in the database
*
* @return static|false The record impementator object, if found
*/
public function read(callable $filter): static|false;
/**
* Update
*
* Write the record new values into the database
*
* @return static|false The updated record, if updated (new instance)
*/
public function update(): static|false;
}

View File

@@ -0,0 +1,129 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\interfaces\ar as active_record,
svoboda\antivertical\models\traits\ar as active_record_trait,
svoboda\antivertical\models\enumerations\entity,
svoboda\antivertical\models\enumerations\membership\status;
// 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;
/**
* Membership
*
* @uses active_record
* @uses active_record_trait
*
* @package svoboda\antivertical\models
*
* @property string $file Path to the database file
* @property database $database The database
* @property record $record The database record
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class membership extends core implements active_record
{
use active_record_trait;
/**
* File
*
* @var string $database Path to the database file
*/
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'memberships.baza';
/**
* Database
*
* Identifier: The record identifier
* Distribution: The distribution
* Account: The account
* Status: @see status::class
* Updated: Timestamp of the last the record update
* Created: Timestamp of the record creating
*
* @var database $database The database
*/
public protected(set) database $database;
/**
* Constructor
*
* @param record|null $record The database record
*
* @return void
*/
public function __construct(?record $record = null)
{
// Initializing the database
$this->database = new database()
->encoding(encoding::ascii)
->columns(
new column('identifier', type::long_long_unsigned),
new column('distribution', type::long_long_unsigned),
new column('account', type::long_long_unsigned),
new column('status', type::char),
new column('updated', type::integer_unsigned),
new column('created', type::integer_unsigned)
)
->connect($this->file);
// Initializing the database record
if ($record) $this->record = $record;
}
/**
* Create
*
* Creates the membership record in the database
*
* @param int $distribution Identifier of the distribution
* @param int $account Identifier of the account
* @param status $status The distribution membership status
*
* @return int|false The record identifier, if created
*/
public function create(int $distribution, int $account, status $status = status::unknown): int|false
{
// Initializing the identifier
$identifier = $this->database->count() + 1;
// Initializing the record
$record = $this->database->record(
$identifier,
$distribution,
$account,
$status->value,
svoboda::timestamp(),
svoboda::timestamp()
);
// Creating the record in the database
$created = $this->database->write($record);
// Exit (success)
return $created ? $identifier : false;
}
}

View File

@@ -0,0 +1,113 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\enumerations\entity,
svoboda\antivertical\models\enumerations\member\status;
// 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;
/**
* Relation
*
* @package svoboda\antivertical\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 relation extends core
{
/**
* File
*
* @var string $database Path to the database file
*/
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'relations.baza';
/**
* Database
*
* Identifier: The record identifier
* From: The account identifier
* To: The account identifier
* Type: Type
* Updated: Timestamp of the last the record update
* Created: Timestamp of the record creating
*
* @var database $database The database
*/
public protected(set) database $database;
/**
* Constructor
*
* @return void
*/
public function __construct()
{
// Initializing the database
$this->database = new database()
->encoding(encoding::ascii)
->columns(
new column('identifier', type::long_long_unsigned),
new column('from', type::long_long_unsigned),
new column('to', type::long_long_unsigned),
new column('type', type::char),
new column('updated', type::integer_unsigned),
new column('created', type::integer_unsigned)
)
->connect($this->file);
}
/**
* Create
*
* Creates the member record in the database
*
* @param int $from Identifier of the account (svoboda\antivertical\models\account)
* @param int $to Identifier of the account (svoboda\antivertical\models\account)
* @param type $type Type of the relation
*
* @return int|false The record identifier, if created
*/
public function create(int $from, int $to, type $type): int|false
{
// Initializing the identifier
$identifier = $this->database->count() + 1;
// Initializing the record
$record = $this->database->record(
$identifier,
$distribution,
$account,
$status->value,
svoboda::timestamp(),
svoboda::timestamp()
);
// Creating the record in the database
$created = $this->database->write($record);
// Exit (success)
return $created ? $identifier : false;
}
}

View File

@@ -0,0 +1,217 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\account\localization,
svoboda\antivertical\models\interfaces\ar as active_record,
svoboda\antivertical\models\traits\ar as active_record_trait;
// 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 model;
// Built-in libraries
use Exception as exception,
RuntimeException as exception_runtime;
/**
* Telegram account
*
* @uses active_record
* @uses active_record_trait
*
* @package svoboda\antivertical\models
*
* @property string $file Path to the database file
* @property database $database The database
* @property record $record The database record
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class telegram extends core implements active_record
{
use active_record_trait;
/**
* File
*
* @var string $database Path to the database file
*/
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'telegram.baza';
/**
* Database
*
* @var database $database The database
*/
public protected(set) database $database;
/**
* Localization
*
* @var localization $localization The localizations implementator
*/
public protected(set) localization $localization;
/**
* Constructor
*
* @param record|null $record The database 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('domain', type::string, ['length' => 32]),
new column('name_first', type::string, ['length' => 64]),
new column('name_second', type::string, ['length' => 64]),
new column('language', type::string, ['length' => 2]),
new column('robot', type::char),
new column('updated', type::integer_unsigned),
new column('created', type::integer_unsigned)
)
->connect($this->file);
// Initializing the localizations implementator
$this->localization = new localization;
// Initializing the database record
if ($record) $this->record = $record;
}
/**
* Initialize
*
* Searches for the telegram account record in the database, and if it does not find it, then create
*
* @param model $telegram The telegram account
*
* @throws exception_runtime if update the telegram account record in the database by the telegram account values
* @throws exception_runtime if failed to find the created telegram account
* @throws exception_runtime if failed to create the telegram account
*
* @return static The telegram account record implementator
*/
public function initialize(model $telegram): static
{
// Searching for the account in the database
$instance = $this->read(filter: fn(record $record) => $record->identifier === $telegram->getId());
if ($instance instanceof static) {
// Found the telegram account record
if (
$instance->name_first !== $telegram->getFirstName() ||
$instance->name_second !== $telegram->getLastName() ||
$instance->domain !== $telegram->getUsername()
) {
// The telegram account was updated
// Updating the account in the database
$updated = $this->update(
filter: fn(record $record) => $record->identifier === $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();
}
);
if ($updated instanceof record && $updated->values() !== $instance->record->values()) {
// Updated the account in the database
// Exit (success)
return $updated;
} else {
// Not updated the account in the database
// Exit (fail)
throw new exception_runtime('Failed to update the account record in the database by the telegram account values');
}
}
// Exit (success)
return $instance;
} else {
// Not found the account record
if ($this->create($telegram)) {
// Created the account
// Searching for the created telegram account in the database
$account = $this->read(filter: fn(record $record) => $record->identifier === $telegram->getId());
if ($account instanceof static) {
// Found the created telegram account
// Exit (success)
return $account;
} else {
// Not found the created telegram account
// Exit (fail)
throw new exception_runtime('Failed to find the created telegram account');
}
} else {
// Not created the telegram account
// Exit (fail)
throw new exception_runtime('Failed to create the telegram account');
}
}
}
/**
* Create
*
* Creates the account record in the database
*
* @param model $telegram The telegram account
*
* @return int|false The record identifier, if created
*/
public function create(model $telegram): int|false
{
// Initializing the identifier
$identifier = (int) $telegram->getId();
// Initializing the record
$record = $this->database->record(
$identifier,
$telegram->getUsername(),
$telegram->getFirstName(),
$telegram->getLastName(),
$telegram->getLanguageCode(),
(int) $telegram->isBot(),
svoboda::timestamp(),
svoboda::timestamp()
);
// Creating the record in the database
$created = $this->database->write($record);
// Exit (success)
return $created ? $identifier : false;
}
}

View File

@@ -0,0 +1,160 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\telegram;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\account as model,
svoboda\antivertical\models\enumerations\language;
// Framework for Telegram
use Zanzara\Context as context,
Zanzara\Telegram\Type\Message as message;
// Baza database
use mirzaev\baza\record;
// Built-in libraries
use Error as error;
/**
* Telegram account
*
* @package svoboda\antivertical\models\telegram
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class account extends core
{
/**
* Localizations
*
* Sends a message with the localizations menu
*
* @param context $context Request data from Telegram
*
* @return void
*/
public static function localizations(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 the title
$title = '🗺 *' . $localization['account_localization_title'] . '*';
// Initializing the account model
$model_account = new model;
// Initializing existed account localizations
$existed = $model_account->localization->database->read(
filter: fn(record $localization) => $localization->account === $account->identifier,
amount: ACCOUNT_LOCALIZATION_ACCOUNT_LOCALIZATIONS_AMOUNT
);
// Initializing localizations amount
$amount = '*' . $localization['account_localization_amount'] . ':* ' . count($existed);
// Declaring the buffer of generated keyboard with languages
$keyboard = [];
// Initializing the iterator of rows
$row = 0;
foreach ($existed as $record) {
// Iterating over existed account localizations
try {
// Initializing the localization language
$language = language::{$record->language};
// 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' => "account_localization_update_$language->name"
];
// When reaching 4 buttons in a row, move to the next row
if (count($keyboard[$row]) === 4) ++$row;
} catch (error $error) {
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_create_failted_to_initialize_language'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
if (count($existed) !== count(language::cases())) {
// Not all languages in the registry have localizations created (expected)
// Writing the button for helping lozalizing
$keyboard[$row === 0 && empty($keyboard[0]) ? 0 : ++$row] = [
[
'text' => '✏️ ' . $localization['account_localization_create'],
'callback_data' => 'account_localization_create_start'
]
];
}
// Sending the message
$context->sendMessage(
<<<TXT
$title
$amount
TXT,
[
'reply_markup' => [
'inline_keyboard' => $keyboard,
'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) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
}

View File

@@ -0,0 +1,228 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\telegram\buttons\account\localization;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\enumerations\language,
svoboda\antivertical\models\account,
svoboda\antivertical\models\telegram\selections,
svoboda\antivertical\models\telegram\processes\account\localization\create as process_account_localization_create;
// Framework for Telegram
use Zanzara\Context as context,
Zanzara\Telegram\Type\Message as message;
// Baza database
use mirzaev\baza\record;
/**
* Telegram account localization create buttons
*
* @package svoboda\antivertical\models\telegram\buttons\account\localization
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class create 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 account) {
// 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(process_account_localization_create::PROCESS)
->then(function (?array $process) use ($context, $account, $localization) {
// Readed from the telegram user buffer
if ($process) {
// Found started account localization create process
// Initializing the account model
$model_account = new account;
// Initializing the account localizations
$existed = $model_account->localization->database->read(
filter: fn(record $localization) => $localization->account === $account->identifier,
amount: ACCOUNT_LOCALIZATION_CREATE_ACCOUNT_LOCALIZATIONS_AMOUNT
);
// Declaring the buffer of languages to exclude
$exclude = [];
// Initializing languages to exclude
foreach ($existed as $record) $exclude[] = $record->language;
if (count($exclude) !== count(language::cases())) {
// Not all languages in the registry have localizations created (expected)
// Sending the language selection
selections::language(
context: $context,
prefix: 'account_localization_create_select_language_',
title: '🌏 *' . $localization['account_localization_create_select_language_title'] . '*',
description: '🌏 *' . $localization['account_localization_create_select_language_description'] . '*',
exclude: $exclude
);
} else {
// All languages in the registry have localizations created (expected)
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_create_every_language_created'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not found started account localization create process
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_create_not_started'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
});
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized language
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize language*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* 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 account) {
// Initialized the account
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Reading from the telegram user buffer
$context->getUserDataItem(process_account_localization_create::PROCESS)
->then(function (?array $process) use ($context, $account, $localization) {
// Readed from the telegram user buffer
if ($process) {
// Found started account localization create process
// Sending the message
$context->sendMessage('📄 *' . $localization['account_localization_create_name_request'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Writing into the account localization create buffer
$context->nextStep([process_account_localization_create::class, 'name']);
});
} else {
// Not found started account localization create process
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_create_not_started'] . '*');
}
});
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
}

View File

@@ -0,0 +1,102 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\telegram\buttons\account\localization;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\enumerations\language,
svoboda\antivertical\models\account,
svoboda\antivertical\models\telegram\selections,
svoboda\antivertical\models\telegram\processes\account\localization\update as process_account_localization_update;
// Framework for Telegram
use Zanzara\Context as context,
Zanzara\Telegram\Type\Message as message;
// Baza database
use mirzaev\baza\record;
/**
* Telegram account localization update buttons
*
* @package svoboda\antivertical\models\telegram\buttons\account\localization
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class update extends core
{
/**
* 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 account) {
// Initialized the account
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Reading from the telegram user buffer
$context->getUserDataItem(process_account_localization_update::PROCESS)
->then(function (?array $process) use ($context, $account, $localization) {
// Readed from the telegram user buffer
if ($process) {
// Found started account localization update process
// Sending the message
$context->sendMessage('📄 *' . $localization['account_localization_update_name_request'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Writing into the account localization update buffer
$context->nextStep([process_account_localization_update::class, 'name']);
});
} else {
// Not found started account localization update process
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_update_not_started'] . '*');
}
});
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
}

View File

@@ -0,0 +1,275 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\telegram\buttons\distribution;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\account,
svoboda\antivertical\models\distribution,
svoboda\antivertical\models\telegram\processes\language\select as process_language_select,
svoboda\antivertical\models\telegram\processes\distribution\declaration as process_distribution_declaration,
svoboda\antivertical\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 declaration buttons
*
* @package svoboda\antivertical\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 declaration 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 account) {
// 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(process_distribution_declaration::PROCESS)
->then(function ($distribution) use ($context, $account, $localization) {
// Readed from the telegram user buffer
if ($distribution) {
// Found started declaration process
// Sending the language selection
process_language_select::menu(
context: $context,
prefix: 'distribution_declaration_select_language_',
title: '🌏 *' . $localization['distribution_declaration_select_language_title'] . '*',
description: '🌏 *' . $localization['distribution_declaration_select_language_description'] . '*'
);
} else {
// Not found started declaration process
// Sending the message
$context->sendMessage('⚠️ *' . $localization['distribution_declaration_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 the 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 account) {
// Initialized the account
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Reading from the telegram user buffer
$context->getUserDataItem(process_distribution_declaration::PROCESS)
->then(function ($distribution) use ($context, $account, $localization) {
// Readed from the telegram user buffer
if ($distribution) {
// Found started declaration process
// Sending the message
$context->sendMessage('📄 *' . $localization['distribution_declaration_name_request'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Writing into the distribution declaration buffer
$context->nextStep([process_distribution_declaration::class, 'name']);
});
} else {
// Not found started declaration process
// Sending the message
$context->sendMessage('⚠️ *' . $localization['distribution_declaration_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 the 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 account) {
// Initialized the account
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Reading from the telegram user buffer
$context->getUserDataItem(process_distribution_declaration::PROCESS)
->then(function ($distribution) use ($context, $account, $localization) {
// Readed from the telegram user buffer
if ($distribution) {
// Found started declaration process
// Initializing the message title
$title = '🗺 *' . $localization['distribution_declaration_location_send_title'] . '*';
// Initializing the message description
$description = $localization['distribution_declaration_location_send_description'];
// Sending the message
$context->sendMessage(
<<<TXT
$title
$description
TXT,
[
'reply_markup' => [
'keyboard' => [
[
[
'text' => '🗺 ' . $localization['distribution_declaration_button_location_send'],
'request_location' => true
]
],
],
'disable_notification' => true
]
]
)->then(function (message $message) use ($context) {
// Sended the message
// Writing into the distribution declaration buffer
$context->nextStep([process_distribution_declaration::class, 'location']);
});
} else {
// Not found started declaration process
// Sending the message
$context->sendMessage('⚠️ *' . $localization['distribution_declaration_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 the account*')
->then(function ($message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,276 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\telegram\buttons\distribution;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\telegram\processes\distribution\select as process_distribution_select;
// Framework for Telegram
use Zanzara\Context as context,
Zanzara\Telegram\Type\Message as message;
// Baza database
use mirzaev\baza\record;
/**
* Telegram distribution select buttons
*
* @package svoboda\antivertical\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 select extends core
{
/**
* 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 account) {
// Initialized the account
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Reading from the telegram user buffer
$context->getUserDataItem(process_distribution_select::PROCESS)
->then(function ($select) use ($context, $account, $localization) {
// Readed from the telegram user buffer
if ($select) {
// Found started select process
// Initializing title for the message
$title = '📄 *' . $localization[process_distribution_select::PROCESS . '_name_request_title'] . '*';
// Initializing description for the message
$description = $localization[process_distribution_select::PROCESS . '_name_request_description'];
// Sending the message
$context->sendMessage(<<<TXT
$title
$description
TXT)
->then(function (message $message) use ($context) {
// Sended the message
// Writing into the distribution select buffer
$context->nextStep([process_distribution_select::class, 'name']);
});
} else {
// Not found started select process
// Sending the message
$context->sendMessage('⚠️ *' . $localization[process_distribution_select::PROCESS . '_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 the 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 account) {
// Initialized the account
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Reading from the telegram user buffer
$context->getUserDataItem(process_distribution_select::PROCESS)
->then(function ($select) use ($context, $account, $localization) {
// Readed from the telegram user buffer
if ($select) {
// Found started select process
// Initializing the message title
$title = '🗺 *' . $localization[process_distribution_select::PROCESS . '_location_send_title'] . '*';
// Initializing the message description
$description = $localization[process_distribution_select::PROCESS . '_location_send_description'];
// Sending the message
$context->sendMessage(
<<<TXT
$title
$description
TXT,
[
'reply_markup' => [
'keyboard' => [
[
[
'text' => '🗺 ' . $localization[process_distribution_select::PROCESS . '_button_location_send'],
'request_location' => true
]
],
],
'disable_notification' => true
]
]
)->then(function (message $message) use ($context) {
// Sended the message
// Writing into the distribution select buffer
$context->nextStep([process_distribution_select::class, 'location']);
});
} else {
// Not found started select process
// Sending the message
$context->sendMessage('⚠️ *' . $localization[process_distribution_select::PROCESS . '_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 the account*')
->then(function ($message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Distance
*
* Request to send distance
*
* @param context $context Request data from Telegram
*
* @return void
*/
public static function distance(context $context)
{
// Initializing the account
$account = $context->get('account');
if ($account instanceof account) {
// Initialized the account
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Reading from the telegram user buffer
$context->getUserDataItem(process_distribution_select::PROCESS)
->then(function ($select) use ($context, $account, $localization) {
// Readed from the telegram user buffer
if ($select) {
// Found started select process
// Initializing the message title
$title = '🔭 *' . $localization[process_distribution_select::PROCESS . '_distance_request_title'] . '* \(' . $localization[process_distribution_select::PROCESS . '_km'] . '\)';
// Initializing the message description
$description = $localization[process_distribution_select::PROCESS . '_distance_request_description'];
// Sending the message
$context->sendMessage(
<<<TXT
$title
$description
TXT
)->then(function (message $message) use ($context) {
// Sended the message
// Writing into the distribution select buffer
$context->nextStep([process_distribution_select::class, 'distance']);
});
} else {
// Not found started select process
// Sending the message
$context->sendMessage('⚠️ *' . $localization[process_distribution_select::PROCESS . '_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 the account*')
->then(function ($message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
}
}

View File

@@ -0,0 +1,315 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\telegram\buttons\membership;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\account,
svoboda\antivertical\models\distribution,
svoboda\antivertical\models\telegram\processes\distribution\select as process_distribution_select,
svoboda\antivertical\models\telegram\processes\membership\search as process_membership_search,
svoboda\antivertical\models\enumerations\membership\status,
svoboda\antivertical\models\enumerations\language;
// Framework for Telegram
use Zanzara\Context as context,
Zanzara\Telegram\Type\Message as message,
Zanzara\Telegram\Type\Keyboard\InlineKeyboardMarkup as keyboard_inline,
Zanzara\Telegram\Type\Keyboard\InlineKeyboardButton as keyboard_inline_button;
// Baza database
use mirzaev\baza\record;
/**
* Telegram membership search buttons
*
* @package svoboda\antivertical\models\telegram\buttons\membership
*
* @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
{
/**
* 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 account) {
// Initialized the account
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Reading from the telegram user buffer
$context->getUserDataItem(process_membership_search::PROCESS)
->then(function ($search) use ($context, $account, $localization) {
// Readed from the telegram user buffer
if ($search) {
// Found started search process
// Initializing title for the message
$title = '📄 *' . $localization[process_membership_search::PROCESS . '_name_request_title'] . '*';
// Initializing description for the message
$description = $localization[process_membership_search::PROCESS . '_name_request_description'];
// Sending the message
$context->sendMessage(<<<TXT
$title
$description
TXT)
->then(function (message $message) use ($context) {
// Sended the message
// Writing into the membership search buffer
$context->nextStep([process_membership_search::class, 'name']);
});
} else {
// Not found started search process
// Sending the message
$context->sendMessage('⚠️ *' . $localization[process_membership_search::PROCESS . '_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 the account*')
->then(function ($message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Distribution
*
* Request to choose distribution
*
* @param context $context Request data from Telegram
*
* @return void
*/
public static function distribution(context $context)
{
// Initializing the account
$account = $context->get('account');
if ($account instanceof account) {
// Initialized the account
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Reading from the telegram user buffer
$context->getUserDataItem(process_membership_search::PROCESS)
->then(function ($search) use ($context, $account, $localization) {
// Readed from the telegram user buffer
if ($search) {
// Found started search process
// Starting the distribution selection process
process_distribution_select::start(
context: $context,
select: function (context $context, array $distribution) use ($search) {
if (!empty($distribution['distribution']) && !empty($distribution['localization'])) {
// Initialized the distribution
// Writing the distribution into the process buffer
$search['distribution'] = $distribution;
// Writing to the telegram user buffer
$context->setUserDataItem(process_membership_search::PROCESS, $search)
->then(function () use ($context) {
// Writed into the telegram user buffer
// Sending the list of found distributions and menu
process_membership_search::menu($context);
});
} else {
// Not initialized the distribution
}
},
delete: function (context $context) use ($search) {
// Deleting the distribution from the process buffer
$search['distribution'] = [
'distribution' => null,
'localization' => null
];
// Writing to the telegram user buffer
$context->setUserDataItem(process_membership_search::PROCESS, $search)
->then(function () use ($context) {
// Writed into the telegram user buffer
// Sending the list of found distributions and menu
process_membership_search::menu($context);
});
},
cancel: function (context $context) {
// Sending the list of found distributions and menu
process_membership_search::menu($context);
},
description: $localization[process_membership_search::PROCESS . '_distribution_selection_description']
);
} else {
// Not found started search process
// Sending the message
$context->sendMessage('⚠️ *' . $localization[process_membership_search::PROCESS . '_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 the account*')
->then(function ($message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Status
*
* Request to choose status
*
* @param context $context Request data from Telegram
*
* @return void
*/
public static function status(context $context)
{
// Initializing the account
$account = $context->get('account');
if ($account instanceof account) {
// Initialized the account
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Reading from the telegram user buffer
$context->getUserDataItem(process_membership_search::PROCESS)
->then(function ($search) use ($context, $account, $localization) {
// Readed from the telegram user buffer
if ($search) {
// Found started search process
// Declaring the keyboard buffer
$keyboard = [[]];
// Initializing the amount of buttons in one row
$amount = MEMBERSHIPS_SEARCH_STATUS_ROW_AMOUNT ?? 8;
// Initializing the rows iterator
$row = 0;
foreach (status::cases() as $status) {
// Iterating over statuses
// Skipping the unknown status
if ($status === status::unknown) continue;
// Moving to the next row
if (count($keyboard[$row]) >= $amount) ++$row;
// Initializing the row
$keyboard[$row] ??= [];
// Generating the button and writing into the keyboard buffer
$keyboard[$row][] = [
'text' => $status->emoji() . ' ' . $localization[process_membership_search::PROCESS . "_button_status_$status->value"],
'callback_data' => process_membership_search::PROCESS . "_status_$status->name"
];
}
// Sending the message
$context->sendMessage(
'👤 *' . $localization[process_membership_search::PROCESS . '_status_select_title'] . '*',
[
'reply_markup' => [
'inline_keyboard' => $keyboard,
'disable_notification' => true
]
]
);
} else {
// Not found started search process
// Sending the message
$context->sendMessage('⚠️ *' . $localization[process_membership_search::PROCESS . '_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 the account*')
->then(function ($message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,165 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\telegram;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\account,
svoboda\antivertical\models\distribution as model,
svoboda\antivertical\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\antivertical\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
{
/**
* Distributions
*
* Sends a message with a list of distributions to
* which the account is a creator, membership, planned or volunteer
*
* @param context $context Request data from Telegram
*
* @return void
*/
public static function list(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 the title
$title = '🏘 *' . $localization['distributions_list_title'] . '*';
// Initializing the account model
$model_account = new account;
// Initializing accounts
$accounts = '*' . $localization['menu_accounts'] . ':* ' . ($model_account->database->count() ?? 0);
// Initializing memberships
$memberships = '*' . $localization['menu_memberships'] . ':* ' . 0;
// Initializing trusted memberships
$memberships_trusted = '*' . $localization['menu_memberships_trusted'] . ':* ' . 0;
// Initializing planners
$planners = '*' . $localization['menu_planners'] . ':* ' . 0;
// Initializing volunteers
$volunteers = '*' . $localization['menu_volunteers'] . ':* ' . 0;
// Initializing the distribution model
$model_distribution = new model;
// Initializing distributions
$distributions = '*' . $localization['menu_distributions'] . ':* ' . ($model_distribution->database->count() ?? 0);
// Initializing trusted distributions
$distributions_trusted = '*' . $localization['menu_distributions_trusted'] . ':* ' . 0;
// Initializing distributions messages
$distributions_messages = '*' . $localization['menu_distributions_messages'] . ':* ' . ($model_distribution->message->database->count() ?? 0);
// Sending the message
$context->sendMessage(
<<<TXT
$title
$accounts
$memberships
$memberships_trusted
$planners
$volunteers
$distributions
$distributions_trusted
$distributions_messages
TXT,
[
'reply_markup' => [
'inline_keyboard' => [
[
[
'text' => '🔥 ' . $localization['menu_button_projects'],
'callback_data' => 'projects'
],
[
'text' => '🗺 ' . $localization['menu_button_map'],
'web_app' => [
'url' => 'https://telegram.map.svoboda.works'
]
],
[
'text' => '📺 ' . $localization['menu_button_site'],
'url' => 'https://svoboda.works'
]
],
[
/* [
'text' => '🏗 ' . $localization['menu_button_projects'],
'callback_data' => 'prjects'
], */
[
'text' => '🐣 ' . $localization['menu_button_memberships'],
'callback_data' => 'message'
],
[
'text' => '🏘 ' . $localization['menu_button_distributions'],
'callback_data' => 'distributions'
]
]
],
'disable_notification' => true,
'remove_keyboard' => true
],
]
)->then(function (message $message) use ($context) {
// Sended the message
});
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
}
}

View File

@@ -0,0 +1,727 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\telegram;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\account,
svoboda\antivertical\models\telegram,
svoboda\antivertical\models\enumerations\language;
// Framework for Telegram
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 Error as error;
/**
* Telegram middlewares
*
* @package svoboda\antivertical\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
{
/**
* Telegram account (middleware)
*
* Initialize or registrate the account and write it to the `telegram` variable inside the `$context`
*
* @param context $context
* @param node $next
*
* @return void
*/
public static function telegram(context $context, node $next): void
{
// Is the process stopped?
if ($context->get('stop')) return;
// Initializing the telegram account
$telegram = $context->getEffectiveUser();
// Initializing the telegram model
$model = new telegram();
// Initializing the telegram accont instance
$instance = $model->initialize($telegram);
if ($instance instanceof telegram) {
// Initialized the telegram account
// Writing the account into the context variable
$context->set('telegram', $instance);
// Continuation of the process
$next($context);
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the telegram account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Account (middleware)
*
* Initialize or registrate the account and write it to the `account` variable inside the `$context`
*
* @param context $context
* @param node $next
*
* @return void
*/
public static function account(context $context, node $next): void
{
// Is the process stopped?
if ($context->get('stop')) return;
// Initializing the telegram account
$telegram = $context->get('telegram');
if ($telegram instanceof telegram) {
// Initialized the account
// Initializing the account model
$model = new account();
// Initializing the account
$instance = $model->initialize($telegram);
if ($instance instanceof account) {
// Initialized the account
// Writing the account into the context variable
$context->set('account', $instance);
// Continuation of the process
$next($context);
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the telegram account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the 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) {
// Initialized the language parameter
try {
// Writing the account language into the context variable
$context->set('language', language::{$account->language});
} catch (error $error) {
// Not initialized the language
// Writing the default language into the context variable
$context->set('language', language::en);
}
} else {
// Not initialized the language parameter
// Writing the default language into the context variable
$context->set('language', language::en);
}
// Continuation of the process
$next($context);
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Localization (middleware)
*
* Implement the account language and initialize the localization file
*
* @param context $context
* @param node $next
*
* @return void
*/
public static function localization(context $context, node $next): void
{
// Is the process stopped?
if ($context->get('stop')) return;
// Initializing the account
$account = $context->get('account');
if ($account instanceof 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)) {
// Initializae localization
// Writing localization into the context variable
$context->set('localization', $localization);
// Continuation of the process
$next($context);
} else {
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not found the localization file
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the localization file*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized language
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize language*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* System (middleware)
*
* Check the account for access to the system
*
* @param context $context
* @param node $next
*
* @return void
*/
public static function system(context $context, node $next): void
{
// Is the process stopped?
if ($context->get('stop')) return;
// Initializing the account
$account = $context->get('account');
if ($account instanceof account) {
// Initialized the account
if ($account->authorized_system) {
// Authorized the account to the system
// Continuation of the process
$next($context);
} else {
// Not authorized the account to the system
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Sending the message
$context->sendMessage('⛔ *' . $localization['not_authorized_system'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
// Stopping the process
$context->set('stop', true);
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Contact (middleware)
*
* Check the account for access to contact with the organization
*
* @param context $context
* @param node $next
*
* @return void
*/
public static function contact(context $context, node $next): void
{
// Is the process stopped?
if ($context->get('stop')) return;
// Initializing the account
$account = $context->get('account');
if ($account instanceof account) {
// Initialized the account
if ($account->authorized_contact) {
// Authorized the account to contact with the organization
// Continuation of the process
$next($context);
} else {
// Not authorized the account to contact with the organization
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Sending the message
$context->sendMessage('⛔ *' . $localization['not_authorized_contact'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
// Stopping the process
$context->set('stop', true);
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Membership (middleware)
*
* Check the account for access to memberships
*
* @param context $context
* @param node $next
*
* @return void
*/
public static function memberships(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 localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
if ($account->authorized_memberships) {
// Authorized the account to create memberships
// Continuation of the process
$next($context);
} else {
// Not authorized the account to create memberships
// Sending the message
$context->sendMessage('⛔ *' . $localization['not_authorized_memberships'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
// Stopping the process
$context->set('stop', true);
}
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Settings (middleware)
*
* Check the account for access to 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
if ($account->authorized_settings) {
// Authorized the account to the settings
// Continuation of the process
$next($context);
} else {
// Not authorized the account to the settings
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Sending the message
$context->sendMessage('⛔ *' . $localization['not_authorized_settings'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
// Stopping the process
$context->set('stop', true);
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* 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
if ($account->authorized_system_settings) {
// Authorized the account to the system settings
// Continuation of the process
$next($context);
} else {
// Not authorized the account to the system settings
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Sending the message
$context->sendMessage('⛔ *' . $localization['not_authorized_system_settings'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
// Stopping the process
$context->set('stop', true);
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Distributions administration (middleware)
*
* Check the account for access to distributions administration
*
* @param context $context
* @param node $next
*
* @return void
*/
public static function distributions_administration(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->authorized_system_distributions) {
// Authorized the account to distributions administration
// Continuation of the process
$next($context);
} else {
// Not authorized the account to distributions administration
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Sending the message
$context->sendMessage('⛔ *' . $localization['not_authorized_system_distributions'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
// Stopping the process
$context->set('stop', true);
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
}

View File

@@ -0,0 +1,911 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\telegram\processes\account\localization;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\account,
svoboda\antivertical\models\telegram\account as telegram_account,
svoboda\antivertical\models\telegram\buttons\account\localization\create as button_account_localization_create,
svoboda\antivertical\models\enumerations\language,
svoboda\antivertical\models\telegram\commands;
// Framework for Telegram
use Zanzara\Context as context,
Zanzara\Telegram\Type\Message as message;
// Baza database
use mirzaev\baza\record;
// Build-in libraries
use Error as error;
/**
* Account localization create process
*
* @package svoboda\antivertical\models\telegram\processes\account\localization
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class create extends core
{
/**
* Process
*
* @var const string PROCESS Name of the process in the telegram user buffer
*/
public const string PROCESS = 'account_localization_create';
/**
* Start
*
* Starting the account localization creating 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 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
// Reading from the telegram user buffer
$context->getUserDataItem(static::PROCESS)
->then(function (?array $process) use ($context, $account, $language, $localization) {
// Readed from the telegram user buffer
if ($process) {
// Found started account localization create process
// Sending the message
$context->sendMessage('📂 *' . $localization['account_localization_create_continiued'] . '*')
->then(function (message $message) use ($context, $account, $language, $localization) {
// Sended the message
// Sending the account localization create menu
static::menu($context);
});
} else {
// Not found started account localization create process
// 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];
// Initializing the account model
$model_account = new account;
// Initializing the account localizations
$existed = $model_account->localization->database->read(
filter: fn(record $localization) => $localization->account === $account->identifier,
amount: ACCOUNT_LOCALIZATION_CREATE_ACCOUNT_LOCALIZATIONS_AMOUNT
);
if (count($existed) !== count(language::cases())) {
// Not all languages in the registry have localizations created (expected)
// Declaring the buffer of languages to exclude
$exclude = [];
// Initializing languages to exclude
foreach ($existed as $record) $exclude[] = $record->language;
if (!empty($exclude)) {
// Initialized languages to exclude
// Deleting excluded languages
$languages = array_filter($languages, fn(language $language) => array_search($language->name, $exclude, strict: true) === false);
}
// Initializing the account localization create buffer
$process = [
'language' => array_values($languages)[0],
'name' => null,
];
// Writing to the telegram user buffer
$context->setUserDataItem(static::PROCESS, $process)
->then(function () use ($context, $account, $localization) {
// Writed to the telegram user buffer
// Sending the message
$context->sendMessage('📂 *' . $localization['account_localization_create_started'] . '*')
->then(function (message $message) use ($context, $account, $localization) {
// Sended the message
// Sending the account localization create menu
static::menu($context);
});
});
} else {
// All languages in the registry have localizations created (expected)
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_create_every_language_created'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
});
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized 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 the account*')
->then(function (message $message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Cancel
*
* Ending the account localization create process
* without creating the localization record in the database
*
* @param context $context Request data from Telegram
*
* @return void
*/
public static function cancel(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
// Reading from the telegram user buffer
$context->getUserDataItem(static::PROCESS)
->then(function (?array $process) use ($context, $localization) {
// Readed from the telegram user buffer
if ($process) {
// Found started account localization create process
// Deleting in the telegram user buffer
$context->deleteUserDataItem(static::PROCESS)
->then(function () use ($context, $localization) {
// Deleted in the telegram user buffer
// Sending the message
$context->sendMessage('🗑 *' . $localization['account_localization_create_canceled'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Sending the account localizations menu
telegram_account::localizations($context);
});
});
} else {
// Not found started account localization create process
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_create_not_started'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Sending the account localizations menu
telegram_account::localizations($context);
});
}
});
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* End
*
* Ending the account localization create process
* and creating the localization record in the database
*
* @param context $context Request data from Telegram
*
* @return void
*/
public static function end(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
// Reading from the telegram user buffer
$context->getUserDataItem(static::PROCESS)
->then(function (?array $process) use ($context, $account, $language, $localization) {
// Readed from the telegram user buffer
if ($process) {
// Found started account localization create process
// Initializing the account model
$model_account = new account;
// Creating the account localization
$created_localization = $model_account->localization->create(
account: $account->identifier,
language: $process['language'],
name: $process['name']
);
if ($created_localization) {
// Created the account localization
// Sending the message
$context->sendMessage('✏️ *' . $localization['account_localization_create_created'] . '*')
->then(function (message $message) use ($context, $account, $language, $localization) {
// Sended the message
// Deleting from the telegram user buffer
$context->deleteUserDataItem(static::PROCESS)
->then(function () use ($context, $localization) {
// Deleted from the telegram user buffer
// Sending the message
$context->sendMessage('✅ *' . $localization['account_localization_create_completed'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Sending the account localizations menu
telegram_account::localizations($context);
});
});
});
} else {
// Not created the account localization
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_create_not_created'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not found started account localization create process
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_create_not_started'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Sending the account localizations menu
telegram_account::localizations($context);
});
}
});
} 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 the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Menu
*
* Sends the account localization create menu with parameters: language, name
* When all parameters was initialized then sends the complete button
*
* @param context $context Request data from Telegram
*
* @return void
*/
protected static function menu(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) {
// Initialized language
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Reading from the telegram user buffer
$context->getUserDataItem(static::PROCESS)
->then(function (?array $process) use ($context, $account, $language, $localization) {
// Readed from the telegram user buffer
if ($process) {
// Found started account localization create process
// Initializing the buffer of generated keyboard with languages
$keyboard = [
[
[
'text' => empty($process['language']) ? '🟢 ' . $localization['account_localization_create_button_language'] : '🟢 ' . $localization['account_localization_create_button_language'] . ': ' . $process['language']->flag() . ' ' . $process['language']->label($language),
'callback_data' => 'account_localization_create_language'
]
],
[
[
'text' => empty($process['name']) ? '🔴 ' . $localization['account_localization_create_button_name'] : '🟢 ' . $localization['account_localization_create_button_name'] . ': ' . $process['name'],
'callback_data' => 'account_localization_create_name'
]
],
];
// Initializing the index of last row
$last = count($keyboard);
// Initializing the last row
$keyboard[$last] ??= [];
// Initializing the button for canceling the generation process
$keyboard[$last][] = [
'text' => '❎ ' . $localization['account_localization_create_button_cancel'],
'callback_data' => 'account_localization_create_cancel'
];
if (
!empty($process['language']) &&
!empty($process['name'])
) {
// Initialized all requeired parameters
// Initializing the button for completing the generation process
$keyboard[$last][] = [
'text' => '✅ ' . $localization['account_localization_create_button_confirm'],
'callback_data' => 'account_localization_create_end'
];
}
// Ending the conversation process
$context->endConversation()
->then(function () use ($context, $localization, $keyboard) {
// Deinitialized the conversation process
// Sending the message
$context->sendMessage(
'📀 *' . $localization['account_localization_create_generation'] . '*',
[
'reply_markup' => [
'inline_keyboard' => $keyboard,
'disable_notification' => true,
'remove_keyboard' => true
],
]
);
});
} else {
// Not found started account localization create process
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_create_not_started'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Sending the account localizations menu
telegram_account::localizations($context);
});
}
});
} 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 the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Language
*
* Write language into the account localization create buffer
*
* @param context $context Request data from Telegram
* @param language $new The language
*
* @return void
*/
public static function language(context $context, language $new): 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
// Reading from the telegram user buffer
$context->getUserDataItem(static::PROCESS)
->then(function (?array $process) use ($context, $account, $language, $localization, $new) {
// Readed from the telegram user buffer
if ($process) {
// Found started account localization create process
try {
// Initializing the old language
$old = $process['language'];
// Writing into the account localization create process buffer
$process['language'] = $new;
// Writing to the telegram user buffer
$context->setUserDataItem(static::PROCESS, $process)
->then(function () use ($context, $account, $language, $localization, $new, $old) {
// Writed to the telegram user buffer
// Sending the message
$context->sendMessage('✅ *' . $localization['account_localization_create_language_update_success'] . '* ' . ($old->flag() ? $old->flag() . ' ' : '') . $old->label($language) . ' → *' . ($new->flag() ? $new->flag() . ' ' : '') . $new->label($language) . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Sending the account localization create menu
static::menu($context);
});
});
} catch (error $error) {
// Failed to send the message about language update
// Sending the message
$context->sendMessage('❎ *' . $localization['account_localization_create_language_update_fail'])
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not found started account localization create process
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_create_not_started'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Sending the account localizations menu
telegram_account::localizations($context);
});
}
});
} 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 the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Name
*
* Write name into the account localization create buffer
*
* @param context $context Request data from Telegram
*
* @return void
*/
public static function name(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
// Reading from the telegram user buffer
$context->getUserDataItem(static::PROCESS)
->then(function (?array $process) use ($context, $account, $localization) {
// Readed from the telegram user buffer
if ($process) {
// Found started account localization create process
// Initializing the new name
$new = $context->getMessage()->getText();
if (!empty($new)) {
// Initialized the new name
if (mb_strlen($new) >= 2) {
// Passed minimum length check
if (mb_strlen($new) <= 128) {
// Passed maximum length check
// Search for restricted characters
preg_match_all('/[\W\d]/u', $new, $matches);
// Declaring the buffer of found restricted characters
$characters = [];
foreach ($matches[0] as $match) {
// Iterating over found restricted characters
if (match ($match) {
' ', '-' => false,
default => true
}) {
// Found a restricted character
// Writing into the buffer of found restricted characters
$characters[] = $match;
}
}
if (empty($characters)) {
// Not found restricted characters
try {
// Initializing the old name
$old = empty($process['name']) ? '_' . $localization['empty'] . '_' : $process['name'];
// Writing into the account localization create process buffer
$process['name'] = $new;
// Writing to the telegram user buffer
$context->setUserDataItem(static::PROCESS, $process)
->then(function () use ($context, $account, $localization, $new, $old) {
// Writed to the telegram user buffer
// Escaping characters for markdown
$escaped = str_replace('-', '\\-', $new);
// Sending the message
$context->sendMessage('✅ *' . $localization['account_localization_create_name_update_success'] . "* $old → *$escaped*")
->then(function (message $message) use ($context) {
// Sended the message
// Sending the account localization create menu
static::menu($context);
});
});
} catch (error $error) {
// Failed to send the message about name update
// Sending the message
$context->sendMessage('❎ *' . $localization['account_localization_create_name_update_fail'])
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Found restricted characters
// Initializing title of the message
$title = '⚠️ *' . $localization['account_localization_create_name_request_restricted_characters_title'] . '*';
// Initializing description of the message
$description = '*' . $localization['account_localization_create_name_request_restricted_characters_description'] . '* \\' . implode(', \\', $characters);
// Sending the message
$context->sendMessage(
<<<TXT
$title
$description
TXT
)
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Requesting to enter name again
button_account_localization_create::name($context);
});
}
} else {
// Not passed maximum length check
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_create_name_request_too_long'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Requesting to enter name again
button_account_localization_create::name($context);
});
}
} else {
// Not passed minimum length check
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_create_name_request_too_short'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Requesting to enter name again
button_account_localization_create::name($context);
});
}
} else {
// Failed to initialize the new name
// Sending the message
$context->sendMessage('📄 *' . $localization['account_localization_create_name_request_not_acceptable'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Requesting to enter name again
button_account_localization_create::name($context);
});
}
} else {
// Not found started account localization create process
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_create_not_started'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Sending the account localizations menu
telegram_account::localizations($context);
});
}
});
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
}

View File

@@ -0,0 +1,776 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\telegram\processes\account\localization;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\account,
svoboda\antivertical\models\telegram\account as telegram_account,
svoboda\antivertical\models\telegram\buttons\account\localization\update as button_account_localization_update,
svoboda\antivertical\models\enumerations\language,
svoboda\antivertical\models\telegram\commands;
// Framework for Telegram
use Zanzara\Context as context,
Zanzara\Telegram\Type\Message as message;
// Svoboda time
use svoboda\time\statement as svoboda;
// Baza database
use mirzaev\baza\record;
// Build-in libraries
use Error as error;
/**
* Account localization update process
*
* @package svoboda\antivertical\models\telegram\processes\account\localization
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class update extends core
{
/**
* Process
*
* @var const string PROCESS Name of the process in the telegram user buffer
*/
public const string PROCESS = 'account_localization_update';
/**
* Start
*
* Starting the account localization creating process
*
* @param context $context Request data from Telegram
* @param language $target The language
*
* @return void
*/
public static function start(context $context, language $target): 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
// Reading from the telegram user buffer
$context->getUserDataItem(static::PROCESS)
->then(function (?array $process) use ($context, $account, $language, $target, $localization) {
// Readed from the telegram user buffer
if ($process) {
// Found started account localization update process
// Sending the message
$context->sendMessage('📂 *' . $localization['account_localization_update_continiued'] . '*')
->then(function (message $message) use ($context, $account, $language, $localization) {
// Sended the message
// Sending the account localization update menu
static::menu($context);
});
} else {
// Not found started account localization update process
// Initializing the account model
$model_account = new account;
// Initializing the account localization
$record = $model_account->localization->database->read(
filter: fn(record $localization) => $localization->account === $account->identifier && $localization->language === $target->name,
amount: 1
)[0] ?? null;
if ($record instanceof record) {
// Initialized the account localization
// Initializing the account localization update buffer
$process = [
'record' => $record,
'language' => $target,
'name' => $record?->name,
];
// Writing to the telegram user buffer
$context->setUserDataItem(static::PROCESS, $process)
->then(function () use ($context, $account, $localization) {
// Writed to the telegram user buffer
// Sending the message
$context->sendMessage('📂 *' . $localization['account_localization_update_started'] . '*')
->then(function (message $message) use ($context, $account, $localization) {
// Sended the message
// Sending the account localization update menu
static::menu($context);
});
});
} else {
// Not initialized the account localization
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_update_not_initialized_localization'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
});
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized 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 the account*')
->then(function (message $message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Cancel
*
* Ending the account localization update process
* without creating the localization record in the database
*
* @param context $context Request data from Telegram
*
* @return void
*/
public static function cancel(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
// Reading from the telegram user buffer
$context->getUserDataItem(static::PROCESS)
->then(function (?array $process) use ($context, $localization) {
// Readed from the telegram user buffer
if ($process) {
// Found started account localization update process
// Deleting in the telegram user buffer
$context->deleteUserDataItem(static::PROCESS)
->then(function () use ($context, $localization) {
// Deleted in the telegram user buffer
// Sending the message
$context->sendMessage('🗑 *' . $localization['account_localization_update_canceled'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Sending the account localizations menu
telegram_account::localizations($context);
});
});
} else {
// Not found started account localization update process
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_update_not_started'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Sending the account localizations menu
telegram_account::localizations($context);
});
}
});
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* End
*
* Ending the account localization update process
* and creating the localization record in the database
*
* @param context $context Request data from Telegram
*
* @return void
*/
public static function end(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
// Reading from the telegram user buffer
$context->getUserDataItem(static::PROCESS)
->then(function (?array $process) use ($context, $account, $language, $localization) {
// Readed from the telegram user buffer
if ($process) {
// Found started account localization update process
// Initializing the account model
$model_account = new account;
// Updating the account localization
$updated_localization = $model_account->localization->database->read(
filter: fn(record $localization) => $localization->identifier === $process['record']->identifier,
update: function (record &$localization) use ($process) {
$localization->name = $process['name'];
$localization->updated = svoboda::timestamp();
},
amount: 1
);
if ($updated_localization) {
// Updated the account localization
// Sending the message
$context->sendMessage('✏️ *' . $localization['account_localization_update_updated'] . '*')
->then(function (message $message) use ($context, $account, $language, $localization) {
// Sended the message
// Deleting from the telegram user buffer
$context->deleteUserDataItem(static::PROCESS)
->then(function () use ($context, $localization) {
// Deleted from the telegram user buffer
// Sending the message
$context->sendMessage('✅ *' . $localization['account_localization_update_completed'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Sending the account localizations menu
telegram_account::localizations($context);
});
});
});
} else {
// Not updated the account localization
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_update_not_updated'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not found started account localization update process
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_update_not_started'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Sending the account localizations menu
telegram_account::localizations($context);
});
}
});
} 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 the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Menu
*
* Sends the account localization update menu with parameters: language, name
* When all parameters was initialized then sends the complete button
*
* @param context $context Request data from Telegram
*
* @return void
*/
protected static function menu(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) {
// Initialized language
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Reading from the telegram user buffer
$context->getUserDataItem(static::PROCESS)
->then(function (?array $process) use ($context, $account, $language, $localization) {
// Readed from the telegram user buffer
if ($process) {
// Found started account localization update process
// Initializing the buffer of generated keyboard with languages
$keyboard = [
[
[
'text' => empty($process['name']) ? '🔴 ' . $localization['account_localization_update_button_name'] : '🟢 ' . $localization['account_localization_update_button_name'] . ': ' . $process['name'],
'callback_data' => 'account_localization_update_name'
]
],
];
// Initializing the index of last row
$last = count($keyboard);
// Initializing the last row
$keyboard[$last] ??= [];
// Initializing the button for canceling the generation process
$keyboard[$last][] = [
'text' => '❎ ' . $localization['account_localization_update_button_cancel'],
'callback_data' => 'account_localization_update_cancel'
];
if (
!empty($process['record']) &&
!empty($process['name'])
) {
// Initialized all requeired parameters
// Initializing the button for completing the generation process
$keyboard[$last][] = [
'text' => '✅ ' . $localization['account_localization_update_button_confirm'],
'callback_data' => 'account_localization_update_end'
];
}
// Ending the conversation process
$context->endConversation()
->then(function () use ($context, $language, $localization, $keyboard, $process) {
// Deinitialized the conversation process
// Initializing the message title
$title = '📀 *' . $localization['account_localization_update_generation'] . '*';
// Initializing the message target
$target = '*' . $localization['account_localization_update_generation_target'] . ':* ' . $process['language']->flag() . ' *' . $process['language']->label($language) . '* \(' . $process['record']->identifier . '\)';
// Sending the message
$context->sendMessage(
<<<TXT
$title
$target
TXT,
[
'reply_markup' => [
'inline_keyboard' => $keyboard,
'disable_notification' => true,
'remove_keyboard' => true
],
]
);
});
} else {
// Not found started account localization update process
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_update_not_started'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Sending the account localizations menu
telegram_account::localizations($context);
});
}
});
} 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 the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Name
*
* Write name into the account localization update buffer
*
* @param context $context Request data from Telegram
*
* @return void
*/
public static function name(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
// Reading from the telegram user buffer
$context->getUserDataItem(static::PROCESS)
->then(function (?array $process) use ($context, $account, $localization) {
// Readed from the telegram user buffer
if ($process) {
// Found started account localization update process
// Initializing the new name
$new = $context->getMessage()->getText();
if (!empty($new)) {
// Initialized the new name
if (mb_strlen($new) >= 2) {
// Passed minimum length check
if (mb_strlen($new) <= 128) {
// Passed maximum length check
// Search for restricted characters
preg_match_all('/[\W\d]/u', $new, $matches);
// Declaring the buffer of found restricted characters
$characters = [];
foreach ($matches[0] as $match) {
// Iterating over found restricted characters
if (match ($match) {
' ', '-' => false,
default => true
}) {
// Found a restricted character
// Writing into the buffer of found restricted characters
$characters[] = $match;
}
}
if (empty($characters)) {
// Not found restricted characters
try {
// Initializing the old name
$old = empty($process['name']) ? '_' . $localization['empty'] . '_' : $process['name'];
// Writing into the account localization update process buffer
$process['name'] = $new;
// Writing to the telegram user buffer
$context->setUserDataItem(static::PROCESS, $process)
->then(function () use ($context, $account, $localization, $new, $old) {
// Writed to the telegram user buffer
// Escaping characters for markdown
$escaped = str_replace('-', '\\-', $new);
// Sending the message
$context->sendMessage('✅ *' . $localization['account_localization_update_name_update_success'] . "* $old → *$escaped*")
->then(function (message $message) use ($context) {
// Sended the message
// Sending the account localization update menu
static::menu($context);
});
});
} catch (error $error) {
// Failed to send the message about name update
// Sending the message
$context->sendMessage('❎ *' . $localization['account_localization_update_name_update_fail'])
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Found restricted characters
// Initializing title of the message
$title = '⚠️ *' . $localization['account_localization_update_name_request_restricted_characters_title'] . '*';
// Initializing description of the message
$description = '*' . $localization['account_localization_update_name_request_restricted_characters_description'] . '* \\' . implode(', \\', $characters);
// Sending the message
$context->sendMessage(
<<<TXT
$title
$description
TXT
)
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Requesting to enter name again
button_account_localization_update::name($context);
});
}
} else {
// Not passed maximum length check
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_update_name_request_too_long'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Requesting to enter name again
button_account_localization_update::name($context);
});
}
} else {
// Not passed minimum length check
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_update_name_request_too_short'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Requesting to enter name again
button_account_localization_update::name($context);
});
}
} else {
// Failed to initialize the new name
// Sending the message
$context->sendMessage('📄 *' . $localization['account_localization_update_name_request_not_acceptable'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Requesting to enter name again
button_account_localization_update::name($context);
});
}
} else {
// Not found started account localization update process
// Sending the message
$context->sendMessage('⚠️ *' . $localization['account_localization_update_not_started'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
// Sending the account localizations menu
telegram_account::localizations($context);
});
}
});
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,239 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\telegram\processes\distribution;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\enumerations\language,
svoboda\antivertical\models\telegram\commands;
// 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\antivertical\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 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
// 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 the 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 account) {
// 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 the account*')
->then(function (message $message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
// Exit (success)
return [];
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,150 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\telegram\processes\language;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\enumerations\language;
// Framework for Telegram
use Zanzara\Context as context,
Zanzara\Telegram\Type\Message as message;
// Baza database
use mirzaev\baza\record;
/**
* Telegram language select
*
* @package svoboda\antivertical\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 account) {
// 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/svoboda/antivertical/src/branch/stable/svoboda/antivertical/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 the account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,156 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\telegram;
// Files of the project
use svoboda\antivertical\models\core,
svoboda\antivertical\models\account,
svoboda\antivertical\models\enumerations\language,
svoboda\antivertical\models\telegram\middlewares;
// Framework for Telegram
use Zanzara\Zanzara,
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 Error as error;
/**
* Telegram settings
*
* @package svoboda\antivertical\models\telegram
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class settings extends core
{
/**
* Language
*
* Write language into the account record
*
* @param context $context Request data from Telegram
* @param language $language The language
*
* @return void
*/
public static function language(context $context, language $language): void
{
// Initializing the account
$account = $context->get('account');
if ($account instanceof account) {
// Initialized the account
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Initializing the account model
$model = new account();
// Updating the account in the database
$updated = $model->database->read(
filter: fn(record $record) => $record->identifier === $account->identifier,
update: function (record &$record) use ($language) {
// Writing new language value into the record
$record->language = $language->name;
},
amount: 1
)[0] ?? null;
if ($updated instanceof record) {
// Updated the account in the database
// Writing the updated account into the context variable
$context->set('account', $updated);
middlewares::language($context, new node(function (context $context) use ($account, $updated) {
// Updated language
middlewares::localization($context, new node(function (context $context) use ($account, $updated) {
// Updated localization
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
try {
// Initializing the old language
$old = language::{$account->language};
// Initializing the new language
$new = language::{$updated->language};
// Sending the message
$context->sendMessage('✅ *' . $localization['settings_language_update_success'] . '* ' . ($old->flag() ? $old->flag() . ' ' : '') . $old->label($new) . ' → *' . ($new->flag() ? $new->flag() . ' ' : '') . $new->label($new) . '*')
->then(function (message $message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
} catch (error $error) {
// Failed to send the message about language update
// Sending the message
$context->sendMessage('❎ *' . $localization['settings_language_update_fail'])
->then(function (message $message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
}));
}));
} else {
// Not updated the account in the database
// Sending the message
$context->sendMessage('❎ *' . $localization['settings_language_update_fail'])
->then(function (message $message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the account*')
->then(function (message $message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
}
}

View File

@@ -0,0 +1,157 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\traits;
// Files of the project
use svoboda\antivertical\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;
// Built-in libraries
use Exception as exception,
RuntimeException as exception_runtime,
LogicException as exception_logic,
InvalidArgumentException as exception_invalid_argument;
/**
* AR
*
* The "Active Record" architectural pattern
*
* @see https://en.wikipedia.org/wiki/Active_record_pattern Active Record
*
* @package svoboda\antivertical\models\traits
*
* @method self __construct(?record $record) Constructor
* @method static|false read(callable $filter) Read from the database
* @method static|false update() Update the record in the database
* @method void __set(string $name, mixed $value = null) Write into the database record property
* @method mixed __get(string $name) Read from the database record property
* @method bool __isset(string $name) Check that the database record property is initialized
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
trait ar
{
/**
* Read
*
* Search for the record in the database
*
* @return static|false The record impementator object, if found
*/
public function read(callable $filter): static|false
{
// Reading from the database
$record = $this->database->read(
filter: $filter,
amount: 1,
offset: 0
)[0] ?? false;
if ($record instanceof record) {
// Initialized the record
// Exit (success)
return new static($record);
}
// Exit (fail)
return false;
}
/**
* Update
*
* Write the record new values into the database
*
* @return static|false The updated record, if updated (new instance)
*/
public function update(): static|false
{
// Writing into the database
$record = $this->database->read(
filter: fn(record $record) => $record->identifier === $this->record->identifier,
update: function (record &$record) {
$this->record->updated = svoboda::timestamp();
$record = $this->record;
},
amount: 1,
offset: 0
)[0] ?? false;
if ($record instanceof record) {
// Initialized the record
// Exit (success)
return new static($record);
}
// Exit (fail)
return false;
}
/**
* Write
*
* Write into the database record property
*
* @param string $name Name of the property
* @param mixed $value Value of the property
*
* @return void
*/
public function __set(string $name, mixed $value = null): void
{
match ($name) {
'record' => $this->record = $value,
default => $this->record->{$name} = $value
};
}
/**
* Read
*
* Read from the database record property
*
* @param string $name Name of the property
*
* @return mixed Content of the property, if they are found
*/
public function __get(string $name): mixed
{
return match ($name) {
'record' => $this->record,
default => $this->record->{$name}
};
}
/**
* Check for initialization
*
* Check that the database record property is initialized
*
* @param string $name Name of the property
*
* @return bool The property is initialized?
*/
public function __isset(string $name): bool
{
// Check of initialization of the property and exit (success)
return match ($name) {
'record' => isset($this->record),
default => isset($this->record->{$name})
};
}
}

View File

@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical\models\traits;
/**
* Coordinates
*
* Storage of data in the document from ArangoDB
*
* @method int|float distance(float $from_latitude, float $from_longitude, float $to_latitude, float $to_longitude, int $planet)
*
* @package svoboda\antivertical\models\traits
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
trait coordinates
{
/**
* Distance
*
* Calculate the distance between coordinates using the Vincenty formula
*
* @see https://en.wikipedia.org/wiki/Great-circle_distance
*
* @param float $from_latitude From latitude
* @param float $from_longitude From longitude
* @param float $to_latitude To latitude
* @param float $to_longitude To longitude
* @param int $planet Radius of the planet
*
* @return int|float Calculated distance between coordinates (meters)
*/
public static function distance(
float $from_latitude,
float $from_longitude,
float $to_latitude,
float $to_longitude,
int $planet = 6371000
): int|float {
// Initializing the from coordinates
$from = [
'latitude' => deg2rad($from_latitude),
'longitude' => deg2rad($from_longitude)
];
// Initializing the to coordinates
$to = [
'latitude' => deg2rad($to_latitude),
'longitude' => deg2rad($to_longitude)
];
// Calculating longitude delta
$delta = $to['longitude'] - $from['longitude'];
// Calculating (wtf)
$biba = pow(cos($to['latitude']) * sin($delta), 2) + pow(cos($from['latitude']) * sin($to['latitude']) - sin($from['latitude']) * cos($to['latitude']) * cos($delta), 2);
$boba = sin($from['latitude']) * sin($to['latitude']) + cos($from['latitude']) * cos($to['latitude']) * cos($delta);
$angle = atan2(sqrt($biba), $boba);
// Exit (success)
return $angle * $planet;
}
}

View File

@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical;
// Files of the project
use svoboda\antivertical\models\distribution,
svoboda\antivertical\models\localization\distribution as distribution_localization,
svoboda\antivertical\models\telegram\middlewares,
svoboda\antivertical\models\telegram\commands,
svoboda\antivertical\models\telegram\buttons,
svoboda\antivertical\models\telegram\selections,
svoboda\antivertical\models\telegram\settings,
svoboda\antivertical\models\enumerations\language,
svoboda\antivertical\models\telegram\processes\distribution\registration as process_distribution_registration,
svoboda\antivertical\models\telegram\processes\distribution\search as process_distribution_search,
svoboda\antivertical\models\telegram\buttons\distribution\registration as button_distribution_registration,
svoboda\antivertical\models\telegram\buttons\distribution\search as button_distribution_search,
svoboda\antivertical\models\telegram\buttons\distribution\administration as button_distribution_administration,
svoboda\antivertical\models\telegram\processes\distribution\localization as process_distribution_localization;
// Framework for PHP
use mirzaev\minimal\core,
mirzaev\minimal\route;
// 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__);
// 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 key
define('TELEGRAM_KEY', require(SETTINGS . DIRECTORY_SEPARATOR . 'telegram.php'));
// Initializing dependencies
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
// Initializing core
$$core = new core(namespace: __NAMESPACE__);
// Initializing routes
$$core->router
->write('/', new route('index', 'index'), 'GET')
->write('/map', new route('map', 'index'), 'GET')
;
// Handling request
$$core->start();

View File

@@ -0,0 +1,198 @@
<?php
declare(strict_types=1);
namespace svoboda\antivertical;
// Files of the project
use svoboda\antivertical\models\distribution,
svoboda\antivertical\models\localization\distribution as distribution_localization,
svoboda\antivertical\models\telegram\middlewares,
svoboda\antivertical\models\telegram\commands,
svoboda\antivertical\models\telegram\buttons,
svoboda\antivertical\models\telegram\account,
svoboda\antivertical\models\telegram\settings,
svoboda\antivertical\models\enumerations\membership\status,
svoboda\antivertical\models\enumerations\language,
svoboda\antivertical\models\telegram\processes\membership\search as process_membership_search,
svoboda\antivertical\models\telegram\buttons\membership\search as button_membership_search,
svoboda\antivertical\models\telegram\processes\distribution\declaration as process_distribution_declaration,
svoboda\antivertical\models\telegram\processes\distribution\search as process_distribution_search,
svoboda\antivertical\models\telegram\processes\distribution\select as process_distribution_select,
svoboda\antivertical\models\telegram\buttons\distribution\declaration as button_distribution_declaration,
svoboda\antivertical\models\telegram\buttons\distribution\search as button_distribution_search,
svoboda\antivertical\models\telegram\buttons\distribution\select as button_distribution_select,
svoboda\antivertical\models\telegram\processes\account\localization\create as process_account_localization_create,
svoboda\antivertical\models\telegram\processes\account\localization\update as process_account_localization_update,
svoboda\antivertical\models\telegram\buttons\account\localization\create as button_account_localization_create,
svoboda\antivertical\models\telegram\buttons\account\localization\update as button_account_localization_update,
svoboda\antivertical\models\telegram\buttons\distribution\administration as button_distribution_administration,
svoboda\antivertical\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;
// 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__);
// 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 key
define('TELEGRAM_KEY', require(SETTINGS . DIRECTORY_SEPARATOR . 'telegram.php'));
// Initializing dependencies
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
// Initializing system settings
require SETTINGS . DIRECTORY_SEPARATOR . 'system.php';
// Initializing the configuration
$config = new config();
$config->setParseMode(config::PARSE_MODE_MARKDOWN);
$config->useReactFileSystem(true);
// Initializing the robot
$robot = new Zanzara(TELEGRAM_KEY, $config);
// Initializing the updates listener
$robot->onUpdate(function (Context $context): void {});
// Initializing the robot middlewares
$robot->middleware([middlewares::class, 'telegram']);
$robot->middleware([middlewares::class, 'account']);
$robot->middleware([middlewares::class, 'language']);
$robot->middleware([middlewares::class, 'localization']);
$robot->middleware([middlewares::class, 'system']);
// Initializing the robot commands handlers
$robot->onCommand('start', [commands::class, 'menu']);
$robot->onCommand('menu', [commands::class, 'menu']);
$robot->onCommand('memberships', [commands::class, 'memberships']);
$robot->onCommand('account', [commands::class, 'account']);
$robot->onCommand('distributions', [commands::class, 'distributions']);
/* $robot->onCommand('request', [telegram::class, 'request_start'])->middleware([telegram::class, 'request']); */
/* $robot->onCommand('svoboda', [commands::class, 'svoboda']);
$robot->onCommand('memberships', [commands::class, 'memberships']); */
$robot->onCommand('language', [commands::class, 'language'])->middleware([middlewares::class, 'settings']);
$robot->onCommand('repository', [commands::class, 'repository']);
/* $robot->onCommand('projects', [commands::class, 'projects']); */
$robot->onCommand('author', [commands::class, 'author']);
$robot->onCommand('society', [commands::class, 'society']);
$robot->onCommand('organisation', [commands::class, 'organisation']);
/* $robot->onCommand('system_settings', [commands::class, 'system_settings'])->middleware([middlewares::class, 'system_settings']); */
// Initializing the robot buttons handlers
$robot->onCbQueryData(['distributions'], [commands::class, 'distributions']); // Remake to buttons?
$robot->onCbQueryData(['distribution_search_start'], [process_distribution_search::class, 'start']);
$robot->onCbQueryData(['distribution_search_name'], [button_distribution_search::class, 'name']);
/* $robot->onCbQueryData(['distribution_search_next'], [process_distribution_search::class, 'text']); */
$robot->onCbQueryData(['distribution_search_end'], [process_distribution_search::class, 'end']);
$robot->onCbQueryData(['distribution_search_location'], [button_distribution_search::class, 'location']);
$robot->onCbQueryData(['distribution_search_distance'], [button_distribution_search::class, 'distance']);
$robot->onCbQueryData(['distribution_search_plan'], [button_distribution_search::class, 'plan'])->middleware([middlewares::class, 'memberships']);
$robot->onCbQueryData(['distribution_search_unplan'], [button_distribution_search::class, 'unplan'])->middleware([middlewares::class, 'memberships']);
$robot->onCbQueryData(['distribution_search_join'], [button_distribution_search::class, 'join'])->middleware([middlewares::class, 'memberships']);
$robot->onCbQueryData(['distribution_search_leave'], [button_distribution_search::class, 'leave'])->middleware([middlewares::class, 'memberships']);
$robot->onCbQueryData(['distribution_search_location'], [button_distribution_search::class, 'location']);
$robot->onCbQueryData(['distribution_search_memberships'], [process_membership_search::class, 'start']);
$robot->onCbQueryData(['distribution_select_name'], [button_distribution_select::class, 'name']);
$robot->onCbQueryData(['distribution_select_location'], [button_distribution_select::class, 'location']);
$robot->onCbQueryData(['distribution_select_distance'], [button_distribution_select::class, 'distance']);
/* $robot->onCbQueryData(['distribution_select_next'], [process_distribution_select::class, 'next']); */
$robot->onCbQueryData(['distribution_select_select'], [process_distribution_select::class, 'select']);
$robot->onCbQueryData(['distribution_select_delete'], [process_distribution_select::class, 'delete']);
$robot->onCbQueryData(['distribution_select_cancel'], [process_distribution_select::class, 'cancel']);
$robot->onCbQueryData(['distribution_declaration_start'], [process_distribution_declaration::class, 'start']);
$robot->onCbQueryData(['distribution_declaration_cancel'], [process_distribution_declaration::class, 'cancel']);
$robot->onCbQueryData(['distribution_declaration_end'], [process_distribution_declaration::class, 'end']);
$robot->onCbQueryData(['distribution_declaration_language'], [button_distribution_declaration::class, 'language']);
foreach (language::cases() as $language)
$robot->onCbQueryData(['distribution_declaration_select_language_' . $language->name], fn(context $context) => process_distribution_declaration::language($context, $language));
$robot->onCbQueryData(['distribution_declaration_name'], [button_distribution_declaration::class, 'name']);
$robot->onCbQueryData(['distribution_declaration_location'], [button_distribution_declaration::class, 'location']);
/* $robot->onCbQueryData(['distribution_accept_toggle'], [button_distribution_administration::class, 'accept'])->middleware([middlewares::class, 'distributions_administration']); */
/* $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']); */
$robot->onCbQueryData(['memberships'], [commands::class, 'memberships']); // Remake to buttons?
$robot->onCbQueryData(['membership_search_start'], [process_membership_search::class, 'start']);
$robot->onCbQueryData(['membership_search_name'], [button_membership_search::class, 'name']);
$robot->onCbQueryData(['membership_search_distribution'], [button_membership_search::class, 'distribution']);
foreach (status::cases() as $status)
$robot->onCbQueryData(['membership_search_status_' . $status->name], fn(context $context) => process_membership_search::status($context, $status));
$robot->onCbQueryData(['membership_search_status'], [button_membership_search::class, 'status']);
$robot->onCbQueryData(['membership_search_end'], [process_membership_search::class, 'end']);
$robot->onCbQueryData(['account_localizations'], [account::class, 'localizations']);
$robot->onCbQueryData(['account_localization_create_start'], [process_account_localization_create::class, 'start']);
$robot->onCbQueryData(['account_localization_create_cancel'], [process_account_localization_create::class, 'cancel']);
$robot->onCbQueryData(['account_localization_create_end'], [process_account_localization_create::class, 'end']);
$robot->onCbQueryData(['account_localization_create_language'], [button_account_localization_create::class, 'language']);
$robot->onCbQueryData(['account_localization_update_cancel'], [process_account_localization_update::class, 'cancel']);
$robot->onCbQueryData(['account_localization_update_end'], [process_account_localization_update::class, 'end']);
foreach (language::cases() as $language) {
$robot->onCbQueryData(['account_localization_create_select_language_' . $language->name], fn(context $context) => process_account_localization_create::language($context, $language));
$robot->onCbQueryData(['account_localization_update_' . $language->name], fn(context $context) => process_account_localization_update::start($context, $language));
}
$robot->onCbQueryData(['account_localization_create_name'], [button_account_localization_create::class, 'name']);
$robot->onCbQueryData(['account_localization_update_name'], [button_account_localization_update::class, 'name']);
/* $robot->onCbQueryData(['account_localizations_search'], [process_account_localization_search::class, 'start']); */
$robot->onCbQueryData(['organisation'], [commands::class, 'organisation']); // Remake to buttons?
// 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();

View File

@@ -1,3 +1,4 @@
*
!system.php
!.gitignore
!*.sample

View File

@@ -0,0 +1,37 @@
<?php
define('MENU_MEMBERSHIPS_AMOUNT', 10000000);
define('DISTRIBUTIONS_SEARCH_PAGE', 3);
define('DISTRIBUTIONS_SEARCH_DISTRIBUTION_DISTANCE', 300);
define('DISTRIBUTIONS_SEARCH_DISTRIBUTION_LOCALIZATIONS_AMOUNT', 100);
define('DISTRIBUTIONS_SEARCH_DISTRIBUTION_NAME_LEVENSHTEIN_DISTANCE', 4);
define('DISTRIBUTIONS_SEARCH_MEMBERSHIP_DEPRECATING_RECORDS_AMOUNT', 500);
define('DISTRIBUTIONS_SEARCH_MEMBERSHIPS_AMOUNT', 10000000);
define('DISTRIBUTIONS_SELECT_PAGE', 10);
define('DISTRIBUTIONS_SELECT_DISTRIBUTION_DISTANCE', 300);
define('DISTRIBUTIONS_SELECT_DISTRIBUTION_LOCALIZATIONS_AMOUNT', 100);
define('DISTRIBUTIONS_SELECT_DISTRIBUTION_NAME_LEVENSHTEIN_DISTANCE', 4);
define('DISTRIBUTIONS_SELECT_MEMBERSHIP_DEPRECATING_RECORDS_AMOUNT', 500);
define('DISTRIBUTIONS_SELECT_MEMBERSHIPS_AMOUNT', 10000000);
define('MEMBERSHIPS_SEARCH_PAGE', 3);
define('MEMBERSHIPS_SEARCH_DISTRIBUTION_LOCALIZATIONS_AMOUNT', 100);
define('MEMBERSHIPS_SEARCH_ACCOUNT_LOCALIZATIONS_AMOUNT', 100);
define('MEMBERSHIPS_SEARCH_MEMBERSHIP_NAME_LEVENSHTEIN_DISTANCE', 4);
define('MEMBERSHIPS_SEARCH_STATUS_ROW_AMOUNT', 3);
define('ACCOUNT_LOCALIZATION_ACCOUNT_LOCALIZATIONS_AMOUNT', 100);
define('ACCOUNT_LOCALIZATION_CREATE_ACCOUNT_LOCALIZATIONS_AMOUNT', 100);
define('ACCOUNT_ACCESS_SYSTEM', 1);
define('ACCOUNT_ACCESS_MESSAGES', 1);
define('ACCOUNT_ACCESS_AUTHONOM', 1);
define('ACCOUNT_ACCESS_STRUCTOR', 1);
define('ACCOUNT_ACCESS_VOLUNTEER', 1);
define('ACCOUNT_ACCESS_INVESTOR', 1);
define('ACCOUNT_ACCESS_RECRUITER', 1);
define('ACCOUNT_ACCESS_SETTINGS', 1);
define('ACCOUNT_ACCESS_SYSTEM_ACCOUNTS', 0);
define('ACCOUNT_ACCESS_SYSTEM_DISTRIBUTIONS', 0);
define('ACCOUNT_ACCESS_SYSTEM_SETTINGS', 0);

View File

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

View File

@@ -0,0 +1,89 @@
<?php
declare(strict_types=1);
namespace svoboda\svoboder\tests;
// Files of the project
use svoboda\svoboder\models\account,
svoboda\svoboder\models\distribution,
svoboda\svoboder\models\telegram;
// 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 . 'system' . 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 key
define('TELEGRAM_KEY', require(SETTINGS . DIRECTORY_SEPARATOR . 'telegram.php'));
// Initializing dependencies
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
// Initializing system settings
require SETTINGS . DIRECTORY_SEPARATOR . 'system.php';
echo <<<TXT
###############################
########### ACCOUNT ###########
###############################
\n
TXT;
// Initializing the account model
$model = new account;
var_dump($model->database->read(
/* filter: fn (record $record) => $record-), */
amount: 1000000
));
echo <<<TXT
\n\n
###############################
###### TELEGRAM ACCOUNT #######
###############################
\n
TXT;
// Initializing the telegram account model
$model = new telegram;
var_dump($model->database->read(
/* filter: fn (record $record) => $record-), */
amount: 1000000
));
echo <<<TXT
\n\n
###############################
######## DISTRIBUTION #########
###############################
\n
TXT;
// Initializing the distribution model
$model = new distribution;
var_dump($model->database->read(
/* filter: fn (record $record) => $record-), */
amount: 1000000
));

View File

@@ -1,21 +0,0 @@
<?php
declare(strict_types=1);
namespace svoboda\negotiator\models\enumerations;
/**
* Session
*
* Types of session verification
*
* @package svoboda\negotiator\models\enumerations
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author svoboda <mail@domain.zone>
*/
enum session
{
case hash_only;
case hash_else_address;
}

View File

@@ -1,48 +0,0 @@
<?php
declare(strict_types=1);
namespace svoboda\negotiator\models;
// Framework for Telegram
use Zanzara\Zanzara,
Zanzara\Context as context,
Zanzara\Telegram\Type\Input\InputFile,
Zanzara\Telegram\Type\File\Document as telegram_document,
Zanzara\Middleware\MiddlewareNode as Node,
Zanzara\Telegram\Type\User as user;
// Built-in libraries
use exception;
/**
* Telegram
*
* @package svoboda\negotiator\models
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author svoboda <mail@domain.zone>
*/
final class telegram extends core
{
/**
* Society
*
* Responce for the command: "/society"
*
* @param context $ctx
*
* @return void
*/
public static function society(context $ctx): void
{
$ctx->sendPhoto(
new InputFile(STORAGE . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'mushroom.jpg'),
[
'caption' => 'why so shroomious',
'disable_notification' => true
]
);
}
}

View File

@@ -1,61 +0,0 @@
<?php
declare(strict_types=1);
namespace svoboda\negotiator;
// Files of the project
use svoboda\negotiator\models\telegram;
// Framework for PHP
use mirzaev\minimal\core;
// Framework for Telegram
use Zanzara\Zanzara,
Zanzara\Context,
Zanzara\Config;
// 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__);
// 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 settings
define('SETTINGS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'settings');
// Initializing path to the storage
define('STORAGE', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'storage');
// Initiailizing telegram key
define('TELEGRAM_KEY', require(SETTINGS . DIRECTORY_SEPARATOR . 'telegram.php'));
// Initializing dependencies
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
var_dump(TELEGRAM_KEY);
// Initializing core
$core = new core(namespace: __NAMESPACE__);
$config = new Config();
$config->setParseMode(Config::PARSE_MODE_MARKDOWN);
$config->useReactFileSystem(true);
$bot = new Zanzara(TELEGRAM_KEY, $config);
$bot->onUpdate(function (Context $ctx): void {
var_dump('biba');
});
/* $bot->onCommand('start', fn($ctx) => telegram::start($ctx)); */
$bot->onCommand('society', fn($ctx) => telegram::society($ctx));
// Starting chat-robot
$bot->run();