generated from mirzaev/pot-php-telegram
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e8962d22d | |||
| a1b5b463c2 |
@@ -35,7 +35,8 @@
|
|||||||
"twig/extra-bundle": "^3.7",
|
"twig/extra-bundle": "^3.7",
|
||||||
"twig/intl-extra": "^3.10",
|
"twig/intl-extra": "^3.10",
|
||||||
"react/filesystem": "^0.1.2",
|
"react/filesystem": "^0.1.2",
|
||||||
"nyholm/psr7": "^1.8"
|
"nyholm/psr7": "^1.8",
|
||||||
|
"irazasyed/telegram-bot-sdk": "^3.15"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"mirzaev/files": "Easy working with files",
|
"mirzaev/files": "Easy working with files",
|
||||||
|
|||||||
1573
composer.lock
generated
1573
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,7 @@ return [
|
|||||||
|
|
||||||
// Main menu
|
// Main menu
|
||||||
'menu_title' => 'Main menu',
|
'menu_title' => 'Main menu',
|
||||||
|
'menu_update' => 'Last update',
|
||||||
|
|
||||||
// Account
|
// Account
|
||||||
'account_title' => 'Account',
|
'account_title' => 'Account',
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ namespace kodorvan\constructor\models;
|
|||||||
use kodorvan\constructor\models\core,
|
use kodorvan\constructor\models\core,
|
||||||
kodorvan\constructor\models\authorizations,
|
kodorvan\constructor\models\authorizations,
|
||||||
kodorvan\constructor\models\settings,
|
kodorvan\constructor\models\settings,
|
||||||
kodorvan\constructor\models\projects;
|
kodorvan\constructor\models\project,
|
||||||
|
kodorvan\constructor\models\project\enumerations\type as project_type,
|
||||||
|
kodorvan\constructor\models\project\enumerations\status as project_status;
|
||||||
|
|
||||||
// The library for languages support
|
// The library for languages support
|
||||||
use mirzaev\languages\language;
|
use mirzaev\languages\language;
|
||||||
@@ -229,11 +231,11 @@ final class account extends core implements record_interface
|
|||||||
$settings->write(account: $record->identifier);
|
$settings->write(account: $record->identifier);
|
||||||
|
|
||||||
// Writing the record into the database
|
// Writing the record into the database
|
||||||
$record = $this->database->read(
|
/* $record = $this->database->read(
|
||||||
filter: fn(record $_record) => $_record->identifier === $record->identifier,
|
filter: fn(record $_record) => $_record->identifier === $record->identifier,
|
||||||
update: fn(record &$_record) => $_record = $record,
|
update: fn(record &$_record) => $_record = $record,
|
||||||
amount: 1
|
amount: 1
|
||||||
)[0] ?? null;
|
)[0] ?? null; */
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $record;
|
return $record;
|
||||||
@@ -370,14 +372,26 @@ final class account extends core implements record_interface
|
|||||||
*
|
*
|
||||||
* Search for the account projects
|
* Search for the account projects
|
||||||
*
|
*
|
||||||
|
* @param project_type|null $type Type of the project
|
||||||
|
* @param project_status|null $status Status of the project
|
||||||
* @param int $amount Maximum amount
|
* @param int $amount Maximum amount
|
||||||
*
|
*
|
||||||
* @return array The account projects
|
* @return array The account projects
|
||||||
*/
|
*/
|
||||||
public function projects(int $amount = 20): array
|
public function projects(
|
||||||
{
|
?project_type $type = null,
|
||||||
|
?project_status $status = null,
|
||||||
|
int $amount = 20
|
||||||
|
): array {
|
||||||
// Search for the account projects
|
// Search for the account projects
|
||||||
$projects = new project()->database->read(filter: fn(record $record) => $record->active === 1 && $record->account === $this->identifier, amount: $amount);
|
$projects = new project()->database->read(
|
||||||
|
filter: fn(record $record) =>
|
||||||
|
$record->active === 1
|
||||||
|
&& $record->account === $this->identifier
|
||||||
|
&& ($type === null || $record->type === $type->name)
|
||||||
|
&& ($status === null || $record->status === $status->name),
|
||||||
|
amount: $amount
|
||||||
|
);
|
||||||
|
|
||||||
// Exit (success/fail)
|
// Exit (success/fail)
|
||||||
return $projects;
|
return $projects;
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ final class authorizations extends core implements record_interface
|
|||||||
* @param bool $system_settings
|
* @param bool $system_settings
|
||||||
* @param bool $active Is the record active?
|
* @param bool $active Is the record active?
|
||||||
*
|
*
|
||||||
* @return int|false The record identifier, if created
|
* @return int|false The record, if created
|
||||||
*/
|
*/
|
||||||
public function write(
|
public function write(
|
||||||
int $account,
|
int $account,
|
||||||
@@ -100,7 +100,7 @@ final class authorizations extends core implements record_interface
|
|||||||
bool $settings = true,
|
bool $settings = true,
|
||||||
bool $system_settings = false,
|
bool $system_settings = false,
|
||||||
bool $active = true,
|
bool $active = true,
|
||||||
): int|false
|
): record|false
|
||||||
{
|
{
|
||||||
$record = $this->database->record(
|
$record = $this->database->record(
|
||||||
$this->database->count() + 1,
|
$this->database->count() + 1,
|
||||||
@@ -117,7 +117,7 @@ final class authorizations extends core implements record_interface
|
|||||||
$created = $this->database->write($record);
|
$created = $this->database->write($record);
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $created ? $record->identifier : false;
|
return $created ? $record : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ declare(strict_types=1);
|
|||||||
namespace kodorvan\constructor\models;
|
namespace kodorvan\constructor\models;
|
||||||
|
|
||||||
// Files of the project
|
// Files of the project
|
||||||
use kodorvan\constructor\models\core;
|
use kodorvan\constructor\models\core,
|
||||||
|
kodorvan\constructor\models\project\enumerations\status as project_status,
|
||||||
|
kodorvan\constructor\models\project\enumerations\status as project_type;
|
||||||
|
|
||||||
// Baza database
|
// Baza database
|
||||||
use mirzaev\baza\database,
|
use mirzaev\baza\database,
|
||||||
@@ -66,6 +68,8 @@ final class project extends core implements record_interface
|
|||||||
->columns(
|
->columns(
|
||||||
new column('identifier', type::long_long_unsigned),
|
new column('identifier', type::long_long_unsigned),
|
||||||
new column('account', type::long_long_unsigned),
|
new column('account', type::long_long_unsigned),
|
||||||
|
new column('status', type::string, ['length' => 16]),
|
||||||
|
new column('type', type::string, ['length' => 32]),
|
||||||
new column('name', type::string, ['length' => 64]),
|
new column('name', type::string, ['length' => 64]),
|
||||||
/* new column('', type::), */
|
/* new column('', type::), */
|
||||||
new column('active', type::char),
|
new column('active', type::char),
|
||||||
@@ -82,19 +86,32 @@ final class project extends core implements record_interface
|
|||||||
* Write
|
* Write
|
||||||
*
|
*
|
||||||
* @param int $account The account identifier
|
* @param int $account The account identifier
|
||||||
* @param string $name Name of the project
|
* @param project_status $status Status of the project
|
||||||
|
* @param project_type $status Type of the project
|
||||||
|
* @param string|null $name Name of the project
|
||||||
* @param int $active Is the record active?
|
* @param int $active Is the record active?
|
||||||
*
|
*
|
||||||
* @return int|false The record identifier, if created
|
* @return record|false The record, if created
|
||||||
*/
|
*/
|
||||||
public function write(
|
public function write(
|
||||||
int $account,
|
int $account,
|
||||||
string $name = '',
|
project_status $status = project_status::creating,
|
||||||
|
project_type $type = project_type::special,
|
||||||
|
?string $name = null,
|
||||||
bool $active = true,
|
bool $active = true,
|
||||||
): int|false {
|
): record|false {
|
||||||
|
if (empty($name)) {
|
||||||
|
// Not received the project name
|
||||||
|
|
||||||
|
// Generating the project name
|
||||||
|
$name = 'Project №' . count(new account()->read(filter: fn(record $record) => $record->active === 1 && $record->account === $account)?->projects() ?? []);
|
||||||
|
}
|
||||||
|
|
||||||
$record = $this->database->record(
|
$record = $this->database->record(
|
||||||
$this->database->count() + 1,
|
$this->database->count() + 1,
|
||||||
$account,
|
$account,
|
||||||
|
$status->name,
|
||||||
|
$type->name,
|
||||||
$name,
|
$name,
|
||||||
(int) $active,
|
(int) $active,
|
||||||
svoboda::timestamp(),
|
svoboda::timestamp(),
|
||||||
@@ -105,7 +122,7 @@ final class project extends core implements record_interface
|
|||||||
$created = $this->database->write($record);
|
$created = $this->database->write($record);
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $created ? $record->identifier : false;
|
return $created ? $record : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -115,8 +132,20 @@ final class project extends core implements record_interface
|
|||||||
*/
|
*/
|
||||||
public function serialize(): self
|
public function serialize(): self
|
||||||
{
|
{
|
||||||
|
if ($this->serialized) {
|
||||||
|
// The record implementor is serialized
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception_runtime('The record implementor is already serialized');
|
||||||
|
}
|
||||||
|
|
||||||
// Serializing the record parameters
|
// Serializing the record parameters
|
||||||
$this->record->active = (int) $this->record->active;
|
$this->record->active = (int) $this->record->active;
|
||||||
|
$this->record->status = $this->record->status->name;
|
||||||
|
$this->record->type = $this->record->type->name;
|
||||||
|
|
||||||
|
// Writing the status of serializing
|
||||||
|
$this->serialized = true;
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $this;
|
return $this;
|
||||||
@@ -129,11 +158,52 @@ final class project extends core implements record_interface
|
|||||||
*/
|
*/
|
||||||
public function deserialize(): self
|
public function deserialize(): self
|
||||||
{
|
{
|
||||||
|
if (!$this->serialized) {
|
||||||
|
// The record implementor is deserialized
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception_runtime('The record implementor is already deserialized');
|
||||||
|
}
|
||||||
|
|
||||||
// Deserializing the record parameters
|
// Deserializing the record parameters
|
||||||
$this->record->active = (bool) $this->record->active;
|
$this->record->active = (bool) $this->record->active;
|
||||||
|
$this->record->status = project_status::{$this->record->status};
|
||||||
|
$this->record->type = project_status::{$this->record->type};
|
||||||
|
|
||||||
|
// Writing the status of serializing
|
||||||
|
$this->serialized = false;
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parameters
|
||||||
|
*
|
||||||
|
* Search for all the project properties
|
||||||
|
*
|
||||||
|
* @return self The instance from which the method was called (fluent interface)
|
||||||
|
*/
|
||||||
|
public function parameters(): self
|
||||||
|
{
|
||||||
|
// Deserializing the record parameters
|
||||||
|
$this->record->active = (bool) $this->record->active;
|
||||||
|
$this->record->status = project_status::{$this->record->status};
|
||||||
|
|
||||||
|
if (!$this->serialized) {
|
||||||
|
// Not serialized
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Serialized
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception('The project implementator is serialized');
|
||||||
|
}
|
||||||
|
/* if ($this->record->type === '') */
|
||||||
|
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\project\enumerations;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use InvalidArgumentException as exception_argument,
|
||||||
|
DomainException as exception_domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status
|
||||||
|
*
|
||||||
|
* @package kodorvan\neurobot\models\project\enumerations
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
enum status
|
||||||
|
{
|
||||||
|
case creating;
|
||||||
|
case calculated;
|
||||||
|
case requested;
|
||||||
|
case developing;
|
||||||
|
case developed;
|
||||||
|
case launched;
|
||||||
|
}
|
||||||
@@ -83,12 +83,12 @@ final class settings extends core implements record_interface
|
|||||||
* @param int $account The account identifier
|
* @param int $account The account identifier
|
||||||
* @param int $active Is the record active?
|
* @param int $active Is the record active?
|
||||||
*
|
*
|
||||||
* @return int|false The record identifier, if created
|
* @return int|false The record, if created
|
||||||
*/
|
*/
|
||||||
public function write(
|
public function write(
|
||||||
int $account,
|
int $account,
|
||||||
bool $active = true,
|
bool $active = true,
|
||||||
): int|false {
|
): record|false {
|
||||||
$record = $this->database->record(
|
$record = $this->database->record(
|
||||||
$this->database->count() + 1,
|
$this->database->count() + 1,
|
||||||
$account,
|
$account,
|
||||||
@@ -101,7 +101,7 @@ final class settings extends core implements record_interface
|
|||||||
$created = $this->database->write($record);
|
$created = $this->database->write($record);
|
||||||
|
|
||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $created ? $record->identifier : false;
|
return $created ? $record : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,4 +132,3 @@ final class settings extends core implements record_interface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,8 +78,8 @@ final class commands extends core
|
|||||||
$experiment = '⚠️ ' . $localization['menu_experiment'];
|
$experiment = '⚠️ ' . $localization['menu_experiment'];
|
||||||
|
|
||||||
// Initializing the message last update text
|
// Initializing the message last update text
|
||||||
exec(command: 'git log --oneline $(git describe --tags --abbrev=0 @^)..@ -1 --format="%at" | xargs -I{} date -d @{} "+%Y.%m.%d %H:%M"', output: $git);
|
exec(command: 'git log --oneline $(git describe --tags --abbrev=0 @^ --always)..@ -1 --format="%at" | xargs -I{} date -d @{} "+%Y.%m.%d %H:%M"', output: $git);
|
||||||
$update = empty($git) ? '' : "\n*" . $localization['menu_update'] . ':* ' . $git;
|
$update = empty($git[0]) ? '' : "\n\n🔏 *" . $localization['menu_update'] . ':* ' . unmarkdown($git[0]);
|
||||||
|
|
||||||
// Sending the message
|
// Sending the message
|
||||||
$context->sendMessage(
|
$context->sendMessage(
|
||||||
@@ -96,7 +96,7 @@ final class commands extends core
|
|||||||
[
|
[
|
||||||
[
|
[
|
||||||
'text' => '📂 ' . $localization['menu_button_project_new'],
|
'text' => '📂 ' . $localization['menu_button_project_new'],
|
||||||
'callback_data' => 'calculator'
|
'callback_data' => 'project_create'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'text' => '🗂 ' . $localization['menu_button_projects'] . ': ' . $projects,
|
'text' => '🗂 ' . $localization['menu_button_projects'] . ': ' . $projects,
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\telegram\commands;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\core,
|
||||||
|
kodorvan\constructor\models\account,
|
||||||
|
kodorvan\constructor\models\settings,
|
||||||
|
kodorvan\constructor\models\telegram\processes\language\select as process_language_select;
|
||||||
|
|
||||||
|
// Library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// The library for escaping all markdown symbols
|
||||||
|
use function mirzaev\unmarkdown;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use Telegram\Bot\Commands\Command as command;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command: start
|
||||||
|
*
|
||||||
|
* @package kodorvan\constructor\models\telegram\commands
|
||||||
|
*
|
||||||
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
|
*/
|
||||||
|
final class start extends command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Start
|
||||||
|
*
|
||||||
|
* @var string $name Name of the command
|
||||||
|
*/
|
||||||
|
protected string $name = 'start';
|
||||||
|
|
||||||
|
protected string $description = 'Start Command to get you started';
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$this->replyWithMessage([
|
||||||
|
'text' => 'Hey, there! Welcome to our bot!',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,894 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor\models\telegram\processes\project;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\core,
|
||||||
|
kodorvan\constructor\models\account,
|
||||||
|
kodorvan\constructor\models\settings,
|
||||||
|
kodorvan\constructor\models\project,
|
||||||
|
kodorvan\constructor\models\project\enumerations\status as project_status;
|
||||||
|
|
||||||
|
// Library for projects support
|
||||||
|
use mirzaev\projects\project;
|
||||||
|
|
||||||
|
// Baza database
|
||||||
|
use mirzaev\baza\record;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use Zanzara\Context as context,
|
||||||
|
Zanzara\Telegram\Type\Message as message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Telegram project create
|
||||||
|
*
|
||||||
|
* @package kodorvan\constructor\models\telegram\processes\project
|
||||||
|
*
|
||||||
|
* @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
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
|
||||||
|
// Searching for the project
|
||||||
|
$project = $account->projects(status: project_status::creation, amount: 1)[0] ?? null;
|
||||||
|
|
||||||
|
if ($project instanceof project) {
|
||||||
|
// Found the project
|
||||||
|
|
||||||
|
// Sending the project creation menu
|
||||||
|
static::menu($context);
|
||||||
|
} else {
|
||||||
|
// Not found the project
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ namespace kodorvan\constructor;
|
|||||||
// Files of the project
|
// Files of the project
|
||||||
use kodorvan\constructor\models\account,
|
use kodorvan\constructor\models\account,
|
||||||
kodorvan\constructor\models\telegram\middlewares,
|
kodorvan\constructor\models\telegram\middlewares,
|
||||||
kodorvan\constructor\models\telegram\commands,
|
kodorvan\constructor\models\telegram\commands\start,
|
||||||
kodorvan\constructor\models\telegram\settings;
|
kodorvan\constructor\models\telegram\settings;
|
||||||
|
|
||||||
// Library for languages support
|
// Library for languages support
|
||||||
@@ -18,9 +18,7 @@ use mirzaev\minimal\core,
|
|||||||
mirzaev\minimal\route;
|
mirzaev\minimal\route;
|
||||||
|
|
||||||
// Framework for Telegram
|
// Framework for Telegram
|
||||||
use Zanzara\Zanzara as zanzara,
|
use Telegram\Bot\BotsManager as telegram;
|
||||||
Zanzara\Context as context,
|
|
||||||
Zanzara\Config as config;
|
|
||||||
|
|
||||||
// Enabling debugging
|
// Enabling debugging
|
||||||
/* ini_set('error_reporting', E_ALL);
|
/* ini_set('error_reporting', E_ALL);
|
||||||
@@ -52,20 +50,33 @@ define('DATABASES', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '
|
|||||||
define('LOCALIZATIONS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'localizations');
|
define('LOCALIZATIONS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'localizations');
|
||||||
|
|
||||||
// Initiailizing Telegram chat-robot settings
|
// Initiailizing Telegram chat-robot settings
|
||||||
require(SETTINGS . DIRECTORY_SEPARATOR . 'telegram.php');
|
define('TELEGRAM', require(SETTINGS . DIRECTORY_SEPARATOR . 'telegram.php'));
|
||||||
|
|
||||||
// Initializing dependencies
|
// Initializing dependencies
|
||||||
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||||
|
|
||||||
// Initializing the configuration
|
// Initializing the robots manager settings
|
||||||
$config = new config();
|
$settings = [
|
||||||
$config->setParseMode(config::PARSE_MODE_MARKDOWN);
|
'bots' => [
|
||||||
$config->useReactFileSystem(true);
|
'constructor' => [
|
||||||
|
'token' => TELEGRAM['constructor']['key'],
|
||||||
|
'certificate_path' => PROJECT_CERTIFICATE,
|
||||||
|
'webhook_url' => 'https://' . PROJECT_DOMAIN . '/telegram/constructor.php',
|
||||||
|
'commands' => [
|
||||||
|
start::class,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'async_requests' => true,
|
||||||
|
'base_bot_url' => 'https://' . PROJECT_DOMAIN . '/telegram',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
// Initializing the robot
|
// Initializing the robots manager
|
||||||
$robot = new Zanzara(ROBOT['key'], $config);
|
$robot = new telegram($settings);
|
||||||
|
|
||||||
// Initializing the updates listener
|
var_dump($telegram->bot('constructor')->getWebhookUpdate());
|
||||||
|
|
||||||
|
/* // Initializing the updates listener
|
||||||
$robot->onUpdate(function (context $context): void {});
|
$robot->onUpdate(function (context $context): void {});
|
||||||
|
|
||||||
// Initializing the robot middlewares
|
// Initializing the robot middlewares
|
||||||
@@ -92,5 +103,7 @@ foreach (language::cases() as $language) {
|
|||||||
$robot->onCbQueryData(["settings_language_$language->name"], fn(context $context) => settings::language($context, $language));
|
$robot->onCbQueryData(["settings_language_$language->name"], fn(context $context) => settings::language($context, $language));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$robot->onCbQueryData('project_create', ['process_project_create', 'name']);
|
||||||
|
|
||||||
// Starting chat-robot
|
// Starting chat-robot
|
||||||
$robot->run();
|
$robot->run(); */
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\account,
|
||||||
|
kodorvan\constructor\models\telegram\middlewares,
|
||||||
|
kodorvan\constructor\models\telegram\commands\start,
|
||||||
|
kodorvan\constructor\models\telegram\settings;
|
||||||
|
|
||||||
|
// Library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// Framework for PHP
|
||||||
|
use mirzaev\minimal\core,
|
||||||
|
mirzaev\minimal\route;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use Telegram\Bot\BotsManager as 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 . '..');
|
||||||
|
|
||||||
|
// Initializing path to the project root directory
|
||||||
|
define('ROOT', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
|
||||||
|
|
||||||
|
// Initializing path to the directory of views
|
||||||
|
define('VIEWS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'views');
|
||||||
|
|
||||||
|
// Initializing path to the directory of settings
|
||||||
|
define('SETTINGS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'settings');
|
||||||
|
|
||||||
|
// Initializing system settings
|
||||||
|
require SETTINGS . DIRECTORY_SEPARATOR . 'system.php';
|
||||||
|
|
||||||
|
// Initializing path to the directory of the storage
|
||||||
|
define('STORAGE', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'storage');
|
||||||
|
|
||||||
|
// Initializing path to the databases directory
|
||||||
|
define('DATABASES', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'databases');
|
||||||
|
|
||||||
|
// Initializing path to the localizations directory
|
||||||
|
define('LOCALIZATIONS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'localizations');
|
||||||
|
|
||||||
|
// Initiailizing Telegram chat-robot settings
|
||||||
|
define('TELEGRAM', require(SETTINGS . DIRECTORY_SEPARATOR . 'telegram.php'));
|
||||||
|
|
||||||
|
// Initializing dependencies
|
||||||
|
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||||
|
|
||||||
|
// Initializing the robots manager settings
|
||||||
|
$settings = [
|
||||||
|
'bots' => [
|
||||||
|
'constructor' => [
|
||||||
|
'token' => TELEGRAM['constructor']['key'],
|
||||||
|
'certificate_path' => PROJECT_CERTIFICATE,
|
||||||
|
'webhook_url' => 'https://' . PROJECT_DOMAIN . '/telegram/constructor/webhook.php',
|
||||||
|
'commands' => [
|
||||||
|
start::class,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'async_requests' => true,
|
||||||
|
'base_bot_url' => 'https://' . PROJECT_DOMAIN . '/telegram',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
// Initializing the robots manager
|
||||||
|
$telegram = new telegram($settings);
|
||||||
|
|
||||||
|
$updates = $telegram->bot('constructor')->setWebhook([
|
||||||
|
'url' => 'https://' . PROJECT_DOMAIN . '/telegram/constructor/webhook.php',
|
||||||
|
'certificate' => PROJECT_CERTIFICATE
|
||||||
|
]);
|
||||||
|
|
||||||
|
/* // Initializing the updates listener
|
||||||
|
$robot->onUpdate(function (context $context): void {});
|
||||||
|
|
||||||
|
// Initializing the robot middlewares
|
||||||
|
$robot->middleware([middlewares::class, 'account']);
|
||||||
|
$robot->middleware([middlewares::class, 'language']);
|
||||||
|
$robot->middleware([middlewares::class, 'localization']);
|
||||||
|
$robot->middleware([middlewares::class, 'authorizations']);
|
||||||
|
|
||||||
|
// Initializing the robot commands handlers
|
||||||
|
$robot->onCommand('start', [commands::class, 'start']);
|
||||||
|
|
||||||
|
$robot->onCommand('start telegram voronka', [commands::class, 'start']);
|
||||||
|
$robot->onCommand('start parser', [commands::class, 'start']);
|
||||||
|
$robot->onCommand('start calculator', [commands::class, 'start']);
|
||||||
|
|
||||||
|
$robot->onCommand('language', [commands::class, 'language'])->middleware([middlewares::class, 'settings']);
|
||||||
|
$robot->onCommand('society', [commands::class, 'society']);
|
||||||
|
|
||||||
|
// Initializing the robot settings language buttons handlers
|
||||||
|
foreach (language::cases() as $language) {
|
||||||
|
// Iterating over languages
|
||||||
|
|
||||||
|
// Initializing language buttons
|
||||||
|
$robot->onCbQueryData(["settings_language_$language->name"], fn(context $context) => settings::language($context, $language));
|
||||||
|
};
|
||||||
|
|
||||||
|
$robot->onCbQueryData('project_create', ['process_project_create', 'name']);
|
||||||
|
|
||||||
|
// Starting chat-robot
|
||||||
|
$robot->run(); */
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\constructor;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\constructor\models\account,
|
||||||
|
kodorvan\constructor\models\telegram\middlewares,
|
||||||
|
kodorvan\constructor\models\telegram\commands\start,
|
||||||
|
kodorvan\constructor\models\telegram\settings;
|
||||||
|
|
||||||
|
// Library for languages support
|
||||||
|
use mirzaev\languages\language;
|
||||||
|
|
||||||
|
// Framework for PHP
|
||||||
|
use mirzaev\minimal\core,
|
||||||
|
mirzaev\minimal\route;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use Telegram\Bot\BotsManager as 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 . '..');
|
||||||
|
|
||||||
|
// Initializing path to the project root directory
|
||||||
|
define('ROOT', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
|
||||||
|
|
||||||
|
// Initializing path to the directory of views
|
||||||
|
define('VIEWS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'views');
|
||||||
|
|
||||||
|
// Initializing path to the directory of settings
|
||||||
|
define('SETTINGS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'settings');
|
||||||
|
|
||||||
|
// Initializing system settings
|
||||||
|
require SETTINGS . DIRECTORY_SEPARATOR . 'system.php';
|
||||||
|
|
||||||
|
// Initializing path to the directory of the storage
|
||||||
|
define('STORAGE', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'storage');
|
||||||
|
|
||||||
|
// Initializing path to the databases directory
|
||||||
|
define('DATABASES', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'databases');
|
||||||
|
|
||||||
|
// Initializing path to the localizations directory
|
||||||
|
define('LOCALIZATIONS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'localizations');
|
||||||
|
|
||||||
|
// Initiailizing Telegram chat-robot settings
|
||||||
|
define('TELEGRAM', require(SETTINGS . DIRECTORY_SEPARATOR . 'telegram.php'));
|
||||||
|
|
||||||
|
// Initializing dependencies
|
||||||
|
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||||
|
|
||||||
|
// Initializing the robots manager settings
|
||||||
|
$settings = [
|
||||||
|
'bots' => [
|
||||||
|
'constructor' => [
|
||||||
|
'token' => TELEGRAM['constructor']['key'],
|
||||||
|
'certificate_path' => PROJECT_CERTIFICATE,
|
||||||
|
'webhook_url' => 'https://' . PROJECT_DOMAIN . ':443/telegram/constructor.php',
|
||||||
|
'commands' => [
|
||||||
|
start::class,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'async_requests' => true,
|
||||||
|
'base_bot_url' => 'https://' . PROJECT_DOMAIN . '/telegram',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
// Initializing the robots manager
|
||||||
|
$telegram = new telegram($settings);
|
||||||
|
|
||||||
|
var_dump($updates = $telegram->bot('constructor')->getWebhookUpdate());
|
||||||
|
|
||||||
|
/* // Initializing the updates listener
|
||||||
|
$robot->onUpdate(function (context $context): void {});
|
||||||
|
|
||||||
|
// Initializing the robot middlewares
|
||||||
|
$robot->middleware([middlewares::class, 'account']);
|
||||||
|
$robot->middleware([middlewares::class, 'language']);
|
||||||
|
$robot->middleware([middlewares::class, 'localization']);
|
||||||
|
$robot->middleware([middlewares::class, 'authorizations']);
|
||||||
|
|
||||||
|
// Initializing the robot commands handlers
|
||||||
|
$robot->onCommand('start', [commands::class, 'start']);
|
||||||
|
|
||||||
|
$robot->onCommand('start telegram voronka', [commands::class, 'start']);
|
||||||
|
$robot->onCommand('start parser', [commands::class, 'start']);
|
||||||
|
$robot->onCommand('start calculator', [commands::class, 'start']);
|
||||||
|
|
||||||
|
$robot->onCommand('language', [commands::class, 'language'])->middleware([middlewares::class, 'settings']);
|
||||||
|
$robot->onCommand('society', [commands::class, 'society']);
|
||||||
|
|
||||||
|
// Initializing the robot settings language buttons handlers
|
||||||
|
foreach (language::cases() as $language) {
|
||||||
|
// Iterating over languages
|
||||||
|
|
||||||
|
// Initializing language buttons
|
||||||
|
$robot->onCbQueryData(["settings_language_$language->name"], fn(context $context) => settings::language($context, $language));
|
||||||
|
};
|
||||||
|
|
||||||
|
$robot->onCbQueryData('project_create', ['process_project_create', 'name']);
|
||||||
|
|
||||||
|
// Starting chat-robot
|
||||||
|
$robot->run(); */
|
||||||
@@ -1,7 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Robot
|
// Telegram API chat-robot
|
||||||
define('ROBOT', [
|
return [
|
||||||
'identifier' => null,
|
'constructor' => [
|
||||||
'key' => ''
|
'identifier' => 0,
|
||||||
]);
|
'domain' => '',
|
||||||
|
'key' => '',
|
||||||
|
'database' => [
|
||||||
|
'host' => '/run/mysqld/mysqld.sock',
|
||||||
|
'port' => 3306,
|
||||||
|
'user' => '',
|
||||||
|
'password' => '',
|
||||||
|
'database' => '',
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user