nutgram and improvements, very cool

This commit is contained in:
2026-02-02 23:46:47 +05:00
parent 8e8962d22d
commit e7ccc3616b
30 changed files with 1674 additions and 2005 deletions

View File

@@ -24,7 +24,7 @@
"require": { "require": {
"php": "^8.5", "php": "^8.5",
"mirzaev/minimal": "^3.7", "mirzaev/minimal": "^3.7",
"mirzaev/baza": "^3.3", "mirzaev/baza": "^3.4",
"mirzaev/record": "^1.0", "mirzaev/record": "^1.0",
"mirzaev/languages": "^1.0", "mirzaev/languages": "^1.0",
"mirzaev/currencies": "^2.0", "mirzaev/currencies": "^2.0",
@@ -36,7 +36,8 @@
"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" "irazasyed/telegram-bot-sdk": "^3.15",
"nutgram/nutgram": "^4.40"
}, },
"suggest": { "suggest": {
"mirzaev/files": "Easy working with files", "mirzaev/files": "Easy working with files",

484
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -17,16 +17,12 @@ return [
'account_authorized_settings' => 'Access to settings', 'account_authorized_settings' => 'Access to settings',
'account_authorized_system_settings' => 'System access to the system settings', 'account_authorized_system_settings' => 'System access to the system settings',
// Language setting // Settings: language
'settings_select_language_title' => 'Select language', 'settings_language_title' => 'Select language',
'settings_select_language_description' => 'The selected language will be writed in your account settings', 'settings_language_description' => 'The selected language will be used in the system interface generation',
'settings_language_update_success' => 'Language replaced:', 'settings_language_update_success' => 'Language replaced',
'settings_language_update_fail' => 'Failed to replace language', 'settings_language_update_fail' => 'Failed to replace language',
'settings_language_button_add' => 'Add a language',
// Language selection
'select_language_title' => 'Select language',
'select_language_description' => 'The selected language will be used in the current process',
'select_language_button_add' => 'Add a language',
// Authorization // Authorization
'not_authorized_system' => 'You do not have access to the system', 'not_authorized_system' => 'You do not have access to the system',

View File

@@ -9,9 +9,8 @@ return [
// Главное меню // Главное меню
'menu_title' => 'Главное меню', 'menu_title' => 'Главное меню',
'menu_description_guest' => "*Создайте ваш первый проект* и получите *ориентировочную стоимость* всего за 2 минуты\n\nПосле расчёта *сформируйте заявку* к проджект\-менеджеру для более глубокого анализа и составлении ТЗ\n\nПри желании этот этап можно пропустить сразу *связавшись с оператором* _\(график работы указан в его профиле\)_", 'menu_description_guest' => "🔥 *Создайте ваш первый проект* и получите *ориентировочную стоимость* всего за 2 минуты",
'menu_description_partner' => "Надеемся, что наше сотрудничество оставляет сугубо *положительные эмоции* и способствует *развитию обоих сторон*\n\n*Благодарим за выбор нашей команды*", 'menu_description_partner' => "*Благодарю за выбор нашей команды*. Теперь Вы один из наших %d партнёров!",
'menu_experiment' => "Чат\-робот находится в *экспериментальном* режиме\nросьба сообщать при обнаружении любых проблем, спасибо_",
'menu_update' => 'Последнее обновление', 'menu_update' => 'Последнее обновление',
'menu_button_project_new' => 'Создать', 'menu_button_project_new' => 'Создать',
'menu_button_projects' => 'Проекты', 'menu_button_projects' => 'Проекты',
@@ -23,16 +22,12 @@ return [
'account_authorized_settings' => 'Доступ к изменению настроек', 'account_authorized_settings' => 'Доступ к изменению настроек',
'account_authorized_system_settings' => 'Системный доступ к системным настройкам', 'account_authorized_system_settings' => 'Системный доступ к системным настройкам',
// Настройки языка // Настройки: язык
'settings_select_language_title' => 'Выбери язык', 'settings_language_title' => 'Выбери язык',
'settings_select_language_description' => 'Выбранный язык будет записан в настройки аккаунта', 'settings_language_description' => 'Выбранный язык будет использоваться для генерации системного отображения',
'settings_language_update_success' => 'Язык заменён:', 'settings_language_update_success' => 'Язык заменён',
'settings_language_update_fail' => 'Не удалось заменить язык', 'settings_language_update_fail' => 'Не удалось заменить язык',
'settings_language_button_add' => 'Добавить язык',
// Выбор языка
'select_language_title' => 'Выбери язык',
'select_language_description' => 'Выбранный язык будет использован в текущем процессе',
'select_language_button_add' => 'Добавить язык',
// Авторизация // Авторизация
'not_authorized_system' => 'У тебя нет доступа к системе', 'not_authorized_system' => 'У тебя нет доступа к системе',

View File

@@ -30,7 +30,7 @@ use mirzaev\record\interfaces\record as record_interface,
use svoboda\time\statement as svoboda; use svoboda\time\statement as svoboda;
// Framework for Telegram // Framework for Telegram
use Zanzara\Telegram\Type\User as telegram_user; use SergiX44\Nutgram\Telegram\Types\User\User as telegram_user;
// Built-in libraries // Built-in libraries
use Exception as exception, use Exception as exception,
@@ -51,7 +51,7 @@ final class account extends core implements record_interface
/** /**
* File * File
* *
* @var string $database Path to the database file * @var string $file Path to the database file
*/ */
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'accounts.baza'; protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'accounts.baza';
@@ -107,26 +107,26 @@ final class account extends core implements record_interface
public function initialize(telegram_user $telegram): ?static public function initialize(telegram_user $telegram): ?static
{ {
// Searching for the account in the database // Searching for the account in the database
$account = $this->database->read(filter: fn(record $record) => $record->identifier_telegram === $telegram->getId(), amount: 1)[0] ?? null; $account = $this->database->read(filter: fn(record $record) => $record->identifier_telegram === $telegram->id, amount: 1)[0] ?? null;
if ($account instanceof record) { if ($account instanceof record) {
// Found the account record // Found the account record
if ( if (
$account->domain !== (string) $telegram->getUsername() || $account->domain !== (string) $telegram->username ||
$account->name_first !== (string) $telegram->getFirstName() || $account->name_first !== (string) $telegram->first_name ||
$account->name_second !== (string) $telegram->getLastName() $account->name_second !== (string) $telegram->last_name
) { ) {
// The telegram account was updated // The telegram account was updated
// Updating the account in the database // Updating the account in the database
$updated = $this->database->read( $updated = $this->database->read(
filter: fn(record $record) => $record->identifier_telegram === $telegram->getId(), filter: fn(record $record) => $record->identifier_telegram === $telegram->id,
update: function (record &$record) use ($telegram) { update: function (record &$record) use ($telegram) {
// Writing new values into the record // Writing new values into the record
$record->domain = (string) $telegram->getUsername(); $record->domain = (string) $telegram->username;
$record->name_first = (string) $telegram->getFirstName(); $record->name_first = (string) $telegram->first_name;
$record->name_second = (string) $telegram->getLastName(); $record->name_second = (string) $telegram->last_name;
$record->updated = svoboda::timestamp(); $record->updated = svoboda::timestamp();
}, },
amount: 1 amount: 1
@@ -166,7 +166,7 @@ final class account extends core implements record_interface
// Registered the account // Registered the account
// Searching for the registered account in the database // Searching for the registered account in the database
$registered = $this->database->read(filter: fn(record $record) => $record->identifier_telegram === $telegram->getId(), amount: 1)[0] ?? null; $registered = $this->database->read(filter: fn(record $record) => $record->identifier_telegram === $telegram->id, amount: 1)[0] ?? null;
if ($registered instanceof record) { if ($registered instanceof record) {
// Found the registered account // Found the registered account
@@ -207,12 +207,12 @@ final class account extends core implements record_interface
{ {
// Creating the record // Creating the record
$record = $this->write( $record = $this->write(
telegram_identifier: (int) $telegram->getId(), telegram_identifier: (int) $telegram->id,
name_first: (string) $telegram->getFirstName(), name_first: (string) $telegram->first_name,
name_second: (string) $telegram->getLastName(), name_second: (string) $telegram->last_name,
domain: (string) $telegram->getUsername(), domain: (string) $telegram->username,
language: (string) $telegram->getLanguageCode(), language: (string) $telegram->language_code,
robot: (bool) $telegram->isBot() robot: (bool) $telegram->is_bot
); );
if ($record instanceof record) { if ($record instanceof record) {
@@ -396,4 +396,55 @@ final class account extends core implements record_interface
// Exit (success/fail) // Exit (success/fail)
return $projects; return $projects;
} }
/**
* Partners
*
* Search for accounts that have at least one project in development
*
* @param int $amount Maximum amount
*
* @return array Partners accounts without duplicates
*/
public static function partners(int $amount = PHP_INT_MAX): array
{
try {
// Search for projects
$projects = new project()->database->read(
filter: fn(record $record) =>
$record->active === 1
&& match (project_status::{$record->status}) {
project_status::developing, project_status::developed, project_status::launched => true,
default => false
},
amount: $amount
);
// Declaring the registry of partners accounts
$partners = [];
foreach ($projects as $project) {
// Iterating over projects
if (isset($partners[$project->account])) {
// The partner account is already was in the partners accounts registry
// Skipping the iteration
continue;
}
// Searching the partner account and writing into the partners accounts registry
$partners[$project->account] = new account()->read(filter: fn(record $record) => $record->identifier === $project->account);
}
// Exit (success)
return $partners;
} catch (exception $exception) {
// Writing the exception into the errors output buffer
error_log((string) $exception);
}
// Exit (fail)
return [];
}
} }

View File

@@ -21,9 +21,6 @@ use mirzaev\record\interfaces\record as record_interface,
// Svoboda time // Svoboda time
use svoboda\time\statement as svoboda; use svoboda\time\statement as svoboda;
// Framework for Telegram
use Zanzara\Telegram\Type\User as telegram;
// Built-in libraries // Built-in libraries
use Exception as exception, use Exception as exception,
RuntimeException as exception_runtime; RuntimeException as exception_runtime;
@@ -43,7 +40,7 @@ final class authorizations extends core implements record_interface
/** /**
* File * File
* *
* @var string $database Path to the database file * @var string $file Path to the database file
*/ */
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'authorizations.baza'; protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'authorizations.baza';

View File

@@ -41,4 +41,3 @@ class core extends model
{ {
} }
} }

View File

@@ -0,0 +1,201 @@
<?php
declare(strict_types=1);
namespace kodorvan\constructor\models;
// Files of the project
use kodorvan\constructor\models\core;
// Baza database
use mirzaev\baza\database,
mirzaev\baza\column,
mirzaev\baza\record,
mirzaev\baza\enumerations\encoding,
mirzaev\baza\enumerations\type;
// The library for languages support
use mirzaev\languages\language;
// Built-in libraries
use ArrayAccess as array_access,
Exception as exception,
RuntimeException as exception_runtime,
LogicException as exception_logic;
/**
* Localization
*
* @package kodorvan\constructor\models
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class localization extends core implements array_access
{
/**
* File
*
* @var string $file Path to the localization file
*/
protected string $file;
/**
* Language
*
* @var language $language The localization language
*/
public readonly language $language;
/**
* Registry
*
* @var array $registry The localization records
*/
protected array $registry;
/**
* Constructor
*
* @method language $language The language
*
* @throws exception_runtime If failed to initialize the localization file
*
* @return void
*/
public function __construct(language $language)
{
// Initializing the localization language
$this->language = $language;
// Initializing the path to the localization file
$this->file = LOCALIZATIONS . DIRECTORY_SEPARATOR . strtolower($this->language->label()) . '.php';
if (file_exists($this->file) && is_readable($this->file)) {
// Found the localization file
// Initializing the localization registry
$this->registry = require($this->file);
} else {
// Not found the localization file
// Exit (fail)
throw new exception_runtime('Failed to initialize the localization file');
}
}
/**
* Write as array
*
* @param mixed $offset The record name
* @param mixed $value The record value
*
* @return void
*/
public function offsetSet(mixed $offset, mixed $value): void
{
if (is_null($offset)) {
// Not received name of the localization record
// Exit (fail)
throw new exception_logic('Failed to initialized the localization record name');
} else {
// Received name of the localization record
// Writing the record into into the registry
$this->registry[$offset] = $value;
}
}
/**
* Read as from array
*
* @param mixed $offset The record name
*
* @return mixed The record value
*/
public function offsetGet(mixed $offset): mixed
{
// Reading the record from the registry and exit (success)
return $this->registry[$offset] ?? null;
}
/**
* Check for initializing as array
*
* @param mixed $offset The record name
*
* @return bool Is the record initialized?
*/
public function offsetExists(mixed $offset): bool
{
// Checking the record existance in the registry and exit (success)
return isset($this->registry[$offset]);
}
/**
* Delete as from array
*
* @param mixed $offset The record name
*
* @return void
*/
public function offsetUnset(mixed $offset): void
{
// Deleting the record from the registry and exit (succes)
unset($this->registry[$offset]);
}
/**
* Write
*
* @param string $name The record name
* @param mixed $value The record value
*
* @return void
*/
public function __set(string $name, mixed $value = null): void
{
// Writing the record into the registry
$this->registry[$name] = $value;
}
/**
* Read
*
* @param string $name The record name
*
* @return mixed The record value
*/
public function __get(string $name): mixed
{
// Reading the record from the registry and exit (success)
return $this->registry[$name];
}
/**
* Check for initializing
*
* @param string $name The record name
*
* @return bool Is the record initialized?
*/
public function __isset(string $name): bool
{
// Check for initializing of the property and exit (success)
return isset($this->registry[$name]);
}
/**
* Delete
*
* @param string $name The record name
*
* @return void
*/
public function __unset(string $name): void
{
// Deleting the record from the registry and exit (success)
unset($this->registry[$name]);
}
}

View File

@@ -42,7 +42,7 @@ final class project extends core implements record_interface
/** /**
* File * File
* *
* @var string $database Path to the database file * @var string $file Path to the database file
*/ */
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'project.baza'; protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'project.baza';

View File

@@ -21,6 +21,9 @@ enum status
case creating; case creating;
case calculated; case calculated;
case requested; case requested;
case invoiced;
case developing; case developing;
case developed; case developed;
case launched; case launched;

View File

@@ -40,7 +40,7 @@ final class settings extends core implements record_interface
/** /**
* File * File
* *
* @var string $database Path to the database file * @var string $file Path to the database file
*/ */
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'settings.baza'; protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'settings.baza';

View File

@@ -31,127 +31,6 @@ use Zanzara\Context as context,
*/ */
final class commands extends core final class commands extends core
{ {
/**
* Start
*
* Responce for command: "/start"
*
* @param context $context Request data from Telegram
*
* @return void
*/
public static function start(context $context): void
{
// Initializing the account
$account = $context->get('account');
if ($account instanceof account) {
// Initialized the account
// Initializing the language
$language = $context->get('language');
if ($language instanceof language) {
// Initialized the language
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Initializing the message title text
$title = '📋 *' . $localization['menu_title'] . '*';
// Initializing the keyboard array
/* $keyboard = [];
foreach (project) */
// Calculating amount of projects
$projects = count($account->projects());
// Initializing the message description text
$description = $projects > 0 ? $localization['menu_description_partner'] : ('🔥 ' . $localization['menu_description_guest']);
// Initializing the message experiment text
$experiment = '⚠️ ' . $localization['menu_experiment'];
// Initializing the message last update text
exec(command: 'git log --oneline $(git describe --tags --abbrev=0 @^ --always)..@ -1 --format="%at" | xargs -I{} date -d @{} "+%Y.%m.%d %H:%M"', output: $git);
$update = empty($git[0]) ? '' : "\n\n🔏 *" . $localization['menu_update'] . ':* ' . unmarkdown($git[0]);
// Sending the message
$context->sendMessage(
<<<TXT
$title
$description
$experiment$update
TXT,
[
'reply_markup' => [
'inline_keyboard' => [
[
[
'text' => '📂 ' . $localization['menu_button_project_new'],
'callback_data' => 'project_create'
],
[
'text' => '🗂 ' . $localization['menu_button_projects'] . ': ' . $projects,
'callback_data' => 'projects'
]
],
[
[
'text' => '📡 ' . $localization['menu_button_operator'],
'callback_data' => 'operator'
]
]
],
'disable_notification' => true,
'remove_keyboard' => true
],
]
)->then(function (message $message) use ($context) {
// Sended the message
});
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized language
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize language*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
->then(function (message $message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
}
/** /**
* Account * Account
* *
@@ -239,135 +118,4 @@ final class commands extends core
}); });
} }
} }
/**
* Language
*
* Responce for the command: "/language"
*
* Send the language selection menu
*
* @param context $context Request data from Telegram
*
* @return void
*/
public static function language(context $context): void
{
// Initializing the account
$account = $context->get('account');
if ($account instanceof account) {
// Initialized the account
// Initializing language
$language = $context->get('language');
if ($language instanceof language) {
// Initialized language
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Sending the language selection
process_language_select::menu(
context: $context,
prefix: 'settings_language_',
title: '🌏 *' . $localization['settings_select_language_title'] . '*',
description: '🌏 *' . $localization['settings_select_language_description'] . '*'
);
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized language
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize language*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Society
*
* Responce for the command: "/society"
*
* Sends the "mushroom" image and the localized text "why so shroomious"
*
* @param context $context Request data from Telegram
*
* @return void
*/
public static function society(context $context): void
{
// Initializing the account
$account = $context->get('account');
if ($account instanceof account) {
// Initialized the account
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Sending the message
$context->sendPhoto(
new file_input(STORAGE . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'mushroom.jpg'),
[
'caption' => $localization['why_so_shroomious'],
'disable_notification' => true
]
);
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
->then(function (message $message) use ($context) {
// Ending the conversation process
$context->endConversation();
});
}
}
} }

View File

@@ -0,0 +1,172 @@
<?php
declare(strict_types=1);
namespace kodorvan\constructor\models\telegram\commands;
// Files of the project
use kodorvan\constructor\models\core,
kodorvan\constructor\models\account,
kodorvan\constructor\models\settings,
kodorvan\constructor\models\localization,
kodorvan\constructor\models\telegram\processes\language\select as process_language_select;
// Library for languages support
use mirzaev\languages\language as type;
// The library for escaping all markdown symbols
use function mirzaev\unmarkdown;
// Framework for Telegram
use SergiX44\Nutgram\Nutgram as telegram,
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode,
SergiX44\Nutgram\Telegram\Types\Message\Message as message,
SergiX44\Nutgram\Handlers\Type\Command as command,
SergiX44\Nutgram\Telegram\Types\Internal\InputFile as input,
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardMarkup as keyboard,
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardButton as button;
/**
* Command: language
*
* @package kodorvan\constructor\models\telegram\commands
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class language extends command
{
/**
* Command
*
* @var string $name Name of the command
*/
protected string $command = 'language';
/**
* Description
*
* @var string $description
*/
protected ?string $description = 'System language';
/**
* Localizations
*
* Descriptions of the command
*
* @var array $localizedDescriptions
*/
protected array $localizedDescriptions = [
'ru' => 'Язык системы',
'*' => 'System language'
];
/**
* Handle
*
* Processing the command
*
* @param telegram $robot The chat-robot instance
*
* @return void
*/
public function handle(telegram $robot): void
{
// Initializing the language
$language = $robot->get('language') ?? LANGUAGE_DEFAULT;
// Initializing the localization
$localization = $robot->get('localization') ?? new localization($language);
$this::menu(
robot: $robot,
prefix: 'settings_language_',
title: "🌏 *$localization->settings_language_title*",
description: $localization->settings_language_description,
language: $language
);
}
/**
* Menu
*
* Generate and send the language selection menu
*
* @param telegram $robot The chat-robot instance
* @param string|null $prefix The process prefix
* @param string|null $title The menu message title
* @param string|null $description The menu message description (main content)
* @param array $exclude Languages that will be excluded ['ru', 'en'...]
* @param type $language The menu message language
*
* @return void
*/
public static function menu(telegram $robot, ?string $prefix = null, ?string $title = null, ?string $description = null, array $exclude = [], type $language = LANGUAGE_DEFAULT): void
{
// Initializing the menu message localization
$localization = $robot->get('localization') ?? new localization($language);
// Initializing the keyboard
$keyboard = keyboard::make();
// Initializing the row
$row = [];
// Initializing the maximum amount of buttons in a row
$length = 4;
// Initializing buffer of languages
$languages = type::cases();
// 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;
// Writing the language choose button into the buffer of generated keyboard with languages
$row[] = button::make(
text: ($language->flag() ? $language->flag() . ' ' : '') . $language->label($language),
callback_data: $prefix . $language->name
);
if (count($row) >= $length) {
// Reached the limit of buttons in a row
// Writing the row into the keyboard
$keyboard->addRow(...$row);
// Reinitializing the row
$row = [];
}
}
if (count($row) / $length < 1) {
// The row was not writed
// Writing the row into the keyboard
$keyboard->addRow(...$row);
}
// Writing the row into the keyboard
$keyboard->addRow(button::make(
text: '🗂 ' . $localization->settings_language_button_add,
url: PROJECT_REPOSITORY_LANGUAGE_ADD
));
// Sending the message
$robot->sendMessage(
text: ($title ?? "🌏 *$localization->settings_language_title*") . "\n\n" . ($description ?? $localization->settings_language_description),
parse_mode: mode::MARKDOWN,
disable_notification: true,
reply_markup: $keyboard,
);
}
}

View File

@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
namespace kodorvan\constructor\models\telegram\commands;
// Files of the project
use kodorvan\constructor\models\core,
kodorvan\constructor\models\account,
kodorvan\constructor\models\settings,
kodorvan\constructor\models\telegram\processes\language\select as process_language_select;
// Library for languages support
use mirzaev\languages\language;
// The library for escaping all markdown symbols
use function mirzaev\unmarkdown;
// Framework for Telegram
use SergiX44\Nutgram\Nutgram as telegram,
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode,
SergiX44\Nutgram\Telegram\Types\Message\Message as message,
SergiX44\Nutgram\Handlers\Type\Command as command,
SergiX44\Nutgram\Telegram\Types\Internal\InputFile as input;
/**
* Command: society
*
* @package kodorvan\constructor\models\telegram\commands
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class society extends command
{
/**
* Command
*
* @var string $name Name of the command
*/
protected string $command = 'society';
/**
* Description
*
* @var string $description
*/
protected ?string $description = 'thing about it';
/**
* Localizations
*
* Descriptions of the command
*
* @var array $localizedDescriptions
*/
protected array $localizedDescriptions = [
'*' => 'thing about it'
];
/**
* Handle
*
* Processing the command
*
* @param telegram $robot The chat-robot instance
*
* @return void
*/
public function handle(telegram $robot): void
{
$robot->sendPhoto(
photo: input::make(STORAGE . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'mushroom.jpg'),
caption: $robot->get('localization')['why_so_shroomious'] ?? 'why so shroomious',
disable_notification: true,
parse_mode: mode::MARKDOWN
);
}
}

View File

@@ -8,6 +8,7 @@ namespace kodorvan\constructor\models\telegram\commands;
use kodorvan\constructor\models\core, use kodorvan\constructor\models\core,
kodorvan\constructor\models\account, kodorvan\constructor\models\account,
kodorvan\constructor\models\settings, kodorvan\constructor\models\settings,
kodorvan\constructor\models\localization,
kodorvan\constructor\models\telegram\processes\language\select as process_language_select; kodorvan\constructor\models\telegram\processes\language\select as process_language_select;
// Library for languages support // Library for languages support
@@ -17,7 +18,13 @@ use mirzaev\languages\language;
use function mirzaev\unmarkdown; use function mirzaev\unmarkdown;
// Framework for Telegram // Framework for Telegram
use Telegram\Bot\Commands\Command as command; use SergiX44\Nutgram\Nutgram as telegram,
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode,
SergiX44\Nutgram\Telegram\Types\Message\Message as message,
SergiX44\Nutgram\Handlers\Type\Command as command,
SergiX44\Nutgram\Telegram\Types\Internal\InputFile as input,
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardMarkup as keyboard,
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardButton as button;
/** /**
* Command: start * Command: start
@@ -30,18 +37,96 @@ use Telegram\Bot\Commands\Command as command;
final class start extends command final class start extends command
{ {
/** /**
* Start * Command
* *
* @var string $name Name of the command * @var string $name Name of the command
*/ */
protected string $name = 'start'; protected string $command = 'start';
protected string $description = 'Start Command to get you started'; /**
* Description
*
* @var string $description
*/
protected ?string $description = 'Main menu';
public function handle() /**
* Localizations
*
* Descriptions of the command
*
* @var array $localizedDescriptions
*/
protected array $localizedDescriptions = [
'ru' => 'Главное меню',
'*' => 'Main menu'
];
/**
* Handle
*
* Processing the command
*
* @param telegram $robot The chat-robot instance
*
* @return void
*/
public function handle(telegram $robot): void
{ {
$this->replyWithMessage([ // Initializing the language
'text' => 'Hey, there! Welcome to our bot!', $language = $robot->get('language') ?? LANGUAGE_DEFAULT;
]);
// Initializing the menu message localization
$localization = $robot->get('localization') ?? new localization($language);
// Initializing the account
$account = $robot->get('account');
// Initializing the message last update text
exec(command: 'git log --oneline $(git describe --tags --abbrev=0 @^ --always)..@ -1 --format="%at" | xargs -I{} date -d @{} "+%Y.%m.%d %H:%M"', output: $git);
$update = empty($git[0]) ? '' : "🔏 *$localization->menu_update:* " . unmarkdown($git[0]);
// Calculating amount of projects
$projects = count($account->projects());
// Calculating amount of partners
$partners = count(account::partners());
// Initializing the keyboard
$keyboard = keyboard::make();
// Writing the row into the keyboard
$keyboard->addRow(
button::make(
text: "📂 $localization->menu_button_project_new",
callback_data: 'project_create'
),
button::make(
text: "🗂 $localization->menu_button_projects: $projects",
callback_data: 'projects'
),
);
// Writing the row into the keyboard
$keyboard->addRow(
button::make(
text: "📡 $localization->menu_button_operator",
callback_data: 'operator'
)
);
$robot->sendMessage(
text: implode(
"\n\n",
[
"📋 *$localization->menu_title*",
$projects > 0 ? printf($localization->menu_description_partner, $partners) : $localization->menu_description_guest,
$update
]
),
parse_mode: mode::MARKDOWN,
disable_notification: true,
reply_markup: $keyboard
);
} }
} }

View File

@@ -1,469 +0,0 @@
<?php
declare(strict_types=1);
namespace kodorvan\constructor\models\telegram;
// Files of the project
use kodorvan\constructor\models\core,
kodorvan\constructor\models\account,
kodorvan\constructor\models\authorizations;
// The library for languages support
use mirzaev\languages\language;
// The library for escaping all markdown symbols
use function mirzaev\unmarkdown;
// Framework for Telegram
use Zanzara\Context as context,
Zanzara\Telegram\Type\Message as message,
Zanzara\Middleware\MiddlewareNode as node;
// Built-in libraries
use Error as error;
/**
* Telegram middlewares
*
* @package kodorvan\constructor\models\telegram
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class middlewares extends core
{
/**
* Account (middleware)
*
* Initialize or registrate the account and write it into the `account` variable inside the `$context`
*
* @param context $context
* @param node $next
*
* @return void
*/
public static function account(context $context, node $next): void
{
// Is the process stopped?
if ($context->get('stop')) return;
// Initializing the telegram account
$telegram = $context->getEffectiveUser();
// Initializing the account
$account = new account()->initialize($telegram);
if ($account instanceof account) {
// Initialized the account
// Writing the account into the context variable
$context->set('account', $account);
// Continuation of the process
$next($context);
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Authorizations (middleware)
*
* Initialize the account authorizations and write them into the `authorizations` variable inside the `$context`
*
* @param context $context
* @param node $next
*
* @return void
*/
public static function authorizations(context $context, node $next): void
{
// Is the process stopped?
if ($context->get('stop')) return;
// Initializing the account
$account = $context->get('account');
if ($account instanceof account) {
// Initialized the account
// Initializing the account authorizations
$authorizations = $account->authorizations();
if ($authorizations instanceof authorizations) {
// Initialized the account authorizations
// Writing the account authorizations into the context variable
$context->set('authorizations', $authorizations);
// Continuation of the process
$next($context);
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize your Telegram account authorizations*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Language (middleware)
*
* Implement the account language
*
* @param context $context
* @param node $next
*
* @return void
*/
public static function language(context $context, node $next): void
{
// Is the process stopped?
if ($context->get('stop')) return;
// Initializing the account
$account = $context->get('account');
if ($account instanceof account) {
// Initialized the account
if ($account->language instanceof language) {
// Initialized the language parameter
try {
// Writing the account language into the context variable
$context->set('language', $account->language);
} catch (error $error) {
// Not initialized the language
// Writing the default language into the context variable
$context->set('language', LANGUAGE_DEFAULT ?? language::en);
}
} else {
// Not initialized the language parameter
// Writing the default language into the context variable
$context->set('language', LANGUAGE_DEFAULT ?? language::en);
}
// Continuation of the process
$next($context);
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Localization (middleware)
*
* Implement the account language and initialize the localization file
*
* @param context $context
* @param node $next
*
* @return void
*/
public static function localization(context $context, node $next): void
{
// Is the process stopped?
if ($context->get('stop')) return;
// Initializing the account
$account = $context->get('account');
if ($account instanceof account) {
// Initialized the account
// Initializing the language
$language = $context->get('language');
if ($language instanceof language) {
// Initialized the language
// Initializing path to the localization file
$file = LOCALIZATIONS . DIRECTORY_SEPARATOR . strtolower($language->label()) . '.php';
if (file_exists($file) && is_readable($file)) {
// Found the localization file
// Initializing localization
$localization = require($file);
if (is_array($localization)) {
// Initialized the localization
// Writing localization into the context variable
$context->set('localization', $localization);
// Continuation of the process
$next($context);
} else {
// Not initialized the localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not found the localization file
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize the localization file*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized language
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize language*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* Settings (middleware)
*
* Check the account for access to the settings
*
* @param context $context
* @param node $next
*
* @return void
*/
public static function settings(context $context, node $next): void
{
// Is the process stopped?
if ($context->get('stop')) return;
// Initializing the account
$account = $context->get('account');
if ($account instanceof account) {
// Initialized the account
// Initializing the account authorizations
$authorizations = $context->get('authorizations');
if ($authorizations instanceof authorizations) {
// Initialized the account authorizations
if ($authorizations->settings) {
// Authorized the account to the settings
// Continuation of the process
$next($context);
} else {
// Not authorized the account to the settings
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Sending the message
$context->sendMessage('⛔ *' . $localization['not_authorized_settings'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
// Stopping the process
$context->set('stop', true);
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
} else {
// Not initialized the account authorizations
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize your Telegram account authorizations*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
/**
* System settings (middleware)
*
* Check the account for access to the system settings
*
* @param context $context
* @param node $next
*
* @return void
*/
public static function system_settings(context $context, node $next): void
{
// Is the process stopped?
if ($context->get('stop')) return;
// Initializing the account
$account = $context->get('account');
if ($account instanceof account) {
// Initialized the account
// Initializing the account authorizations
$authorizations = $context->get('authorizations');
if ($authorizations instanceof authorizations) {
// Initialized the account authorizations
if ($authorizations->system_settings) {
// Authorized the account to the system settings
// Continuation of the process
$next($context);
} else {
// Not authorized the account to the system settings
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Sending the message
$context->sendMessage('⛔ *' . $localization['not_authorized_system_settings'] . '*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
// Stopping the process
$context->set('stop', true);
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize your Telegram account authorizations*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
}

View File

@@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
namespace kodorvan\constructor\models\telegram\middlewares;
// Files of the project
use kodorvan\constructor\models\core,
kodorvan\constructor\models\account as model,
kodorvan\constructor\models\authorizations;
// The library for languages support
use mirzaev\languages\language;
// The library for escaping all markdown symbols
use function mirzaev\unmarkdown;
// Framework for Telegram
use SergiX44\Nutgram\Nutgram as telegram,
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode;
// Built-in libraries
use Error as error;
/**
* Telegram middleware: account
*
* @package kodorvan\constructor\models\telegram\middlewares
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class account extends core
{
/**
* Account
*
* Initialize or registrate the account and write it into the `account` variable inside the `$robot`
*
* @param telegram $robot
* @param $next
*
* @return void
*/
public function __invoke(telegram $robot, $next): void
{
// Is the process stopped?
if ($robot->get('stop')) return;
// Initializing the telegram account
$telegram = $robot->user();
// Initializing the account
$account = new model()->initialize(telegram: $telegram);
if ($account instanceof model) {
// Initialized the account
// Writing the account into the robot variable
$robot->set('account', $account);
// Continuation of the process
$next($robot);
} else {
// Not initialized the account
// Sending the message
$robot->sendMessage(
text: '⚠️ *Failed to initialize your Telegram account*',
parse_mode: mode::MARKDOWN
);
// Ending the conversation process
$robot->endConversation();
}
}
}

View File

@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
namespace kodorvan\constructor\models\telegram\middlewares;
// Files of the project
use kodorvan\constructor\models\core,
kodorvan\constructor\models\account,
kodorvan\constructor\models\authorizations as model;
// The library for languages support
use mirzaev\languages\language;
// The library for escaping all markdown symbols
use function mirzaev\unmarkdown;
// Framework for Telegram
use SergiX44\Nutgram\Nutgram as telegram,
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode;
// Built-in libraries
use Error as error;
/**
* Telegram middleware: authorizations
*
* @package kodorvan\constructor\models\telegram\middlewares
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class authorizations extends core
{
/**
* Authorizations
*
* Initialize the account authorizations and write them into the `authorizations` variable inside the `$robot`
*
* @param telegram $robot
* @param $next
*
* @return void
*/
public function __invoke(telegram $robot, $next): void
{
// Is the process stopped?
if ($robot->get('stop')) return;
// Initializing the account
$account = $robot->get('account');
if ($account instanceof account) {
// Initialized the account
// Initializing the account authorizations
$authorizations = $account->authorizations();
if ($authorizations instanceof model) {
// Initialized the account authorizations
// Writing the account authorizations into the robot variable
$robot->set('authorizations', $authorizations);
// Continuation of the process
$next($robot);
} else {
// Not initialized the account authorizations
// Sending the message
$robot->sendMessage(
text: '⚠️ *Failed to initialize your Telegram account authorizations*',
parse_mode: mode::MARKDOWN
);
// Ending the conversation process
$robot->endConversation();
}
}
}
}

View File

@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
namespace kodorvan\constructor\models\telegram\middlewares;
// Files of the project
use kodorvan\constructor\models\core,
kodorvan\constructor\models\account,
kodorvan\constructor\models\authorizations;
// The library for languages support
use mirzaev\languages\language as type;
// The library for escaping all markdown symbols
use function mirzaev\unmarkdown;
// Framework for Telegram
use SergiX44\Nutgram\Nutgram as telegram,
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode;
// Built-in libraries
use Error as error;
/**
* Telegram middleware: language
*
* @package kodorvan\constructor\models\telegram\middlewares
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class language extends core
{
/**
* Language
*
* Implement the account language
*
* @param telegram $robot
* @param $next
*
* @return void
*/
public function __invoke(telegram $robot, $next): void
{
// Is the process stopped?
if ($robot->get('stop')) return;
// Initializing the account
$account = $robot->get('account');
if ($account instanceof account) {
// Initialized the account
if ($account->language instanceof type) {
// Initialized the language parameter
try {
// Writing the account language into the robot variable
$robot->set('language', $account->language);
} catch (error $error) {
// Not initialized the language
// Writing the default language into the robot variable
$robot->set('language', LANGUAGE_DEFAULT ?? type::en);
}
} else {
// Not initialized the language parameter
// Writing the default language into the robot variable
$robot->set('language', LANGUAGE_DEFAULT ?? type::en);
}
// Continuation of the process
$next($robot);
}
}
}

View File

@@ -0,0 +1,91 @@
<?php
declare(strict_types=1);
namespace kodorvan\constructor\models\telegram\middlewares;
// Files of the project
use kodorvan\constructor\models\core,
kodorvan\constructor\models\account,
kodorvan\constructor\models\localization as model,
kodorvan\constructor\models\authorizations;
// The library for languages support
use mirzaev\languages\language;
// The library for escaping all markdown symbols
use function mirzaev\unmarkdown;
// Framework for Telegram
use SergiX44\Nutgram\Nutgram as telegram,
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode;
// Built-in libraries
use Exception as exception,
Error as error;
/**
* Telegram middleware: localization
*
* @package kodorvan\constructor\models\telegram\middlewares
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class localization extends core
{
/**
* Localization
*
* Implement the account language and initialize the localization file
*
* @param telegram $robot
* @param $next
*
* @return void
*/
public function __invoke(telegram $robot, $next): void
{
// Is the process stopped?
if ($robot->get('stop')) return;
// Initializing the account
$account = $robot->get('account');
if ($account instanceof account) {
// Initialized the account
// Initializing the language
$language = $robot->get('language');
if ($language instanceof language) {
// Initialized the language
try {
// Initializing the localization
$localization = new model($language);
// Writing localization into the robot variable
$robot->set('localization', $localization);
// Continuation of the process
$next($robot);
} catch (exception $exception) {
// Not initialized the localization
// Writing the exception into the errors output buffer
error_log((string) $exception);
// Sending the message
$robot->sendMessage(
text: '⚠️ *Failed to initialize the localization*',
parse_mode: mode::MARKDOWN
);
// Ending the conversation process
$robot->endConversation();
}
}
}
}
}

View File

@@ -0,0 +1,92 @@
<?php
declare(strict_types=1);
namespace kodorvan\constructor\models\telegram\middlewares;
// Files of the project
use kodorvan\constructor\models\core,
kodorvan\constructor\models\account,
kodorvan\constructor\models\authorizations;
// The library for languages support
use mirzaev\languages\language;
// The library for escaping all markdown symbols
use function mirzaev\unmarkdown;
// Framework for Telegram
use SergiX44\Nutgram\Nutgram as telegram,
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode;
// Built-in libraries
use Error as error;
/**
* Telegram middleware: language
*
* @package kodorvan\constructor\models\telegram\middlewares
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class settings extends core
{
/**
* Settings
*
* Implement the account language
*
* @param telegram $robot
* @param $next
*
* @return void
*/
public function __invoke(telegram $robot, $next): void
{
// Is the process stopped?
if ($robot->get('stop')) return;
// Initializing the account
$account = $robot->get('account');
if ($account instanceof account) {
// Initialized the account
// Initializing the account authorizations
$authorizations = $robot->get('authorizations');
if ($authorizations instanceof authorizations) {
// Initialized the account authorizations
if ($authorizations->settings) {
// Authorized the account to the settings
// Continuation of the process
$next($robot);
} else {
// Not authorized the account to the settings
// Initializing localization
$localization = $robot->get('localization');
if ($localization) {
// Initialized localization
// Sending the message
$robot->sendMessage(
text: '⛔ *' . $localization['not_authorized_settings'] . '*',
parse_mode: mode::MARKDOWN
);
// Ending the conversation process
$robot->endConversation();
// Stopping the process
$robot->set('stop', true);
}
}
}
}
}
}

View File

@@ -0,0 +1,92 @@
<?php
declare(strict_types=1);
namespace kodorvan\constructor\models\telegram\middlewares\system;
// Files of the project
use kodorvan\constructor\models\core,
kodorvan\constructor\models\account,
kodorvan\constructor\models\authorizations;
// The library for languages support
use mirzaev\languages\language;
// The library for escaping all markdown symbols
use function mirzaev\unmarkdown;
// Framework for Telegram
use SergiX44\Nutgram\Nutgram as telegram,
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode;
// Built-in libraries
use Error as error;
/**
* Telegram middleware: language
*
* @package kodorvan\constructor\models\telegram\middlewares\system
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class settings extends core
{
/**
* System settings (middleware)
*
* Check the account for access to the system settings
*
* @param telegram $robot
* @param $next
*
* @return void
*/
public function __invoke(telegram $robot, $next): void
{
// Is the process stopped?
if ($robot->get('stop')) return;
// Initializing the account
$account = $robot->get('account');
if ($account instanceof account) {
// Initialized the account
// Initializing the account authorizations
$authorizations = $robot->get('authorizations');
if ($authorizations instanceof authorizations) {
// Initialized the account authorizations
if ($authorizations->system_settings) {
// Authorized the account to the system settings
// Continuation of the process
$next($robot);
} else {
// Not authorized the account to the system settings
// Initializing localization
$localization = $robot->get('localization');
if ($localization) {
// Initialized localization
// Sending the message
$robot->sendMessage(
text: '⛔ *' . $localization['not_authorized_system_settings'] . '*',
parse_mode: mode::MARKDOWN
);
// Ending the conversation process
$robot->endConversation();
// Stopping the process
$robot->set('stop', true);
}
}
}
}
}
}

View File

@@ -1,152 +0,0 @@
<?php
declare(strict_types=1);
namespace kodorvan\constructor\models\telegram\processes\language;
// Files of the project
use kodorvan\constructor\models\core;
// Library for languages support
use mirzaev\languages\language;
// Baza database
use mirzaev\baza\record;
// Framework for Telegram
use Zanzara\Context as context,
Zanzara\Telegram\Type\Message as message;
/**
* Telegram language select
*
* @package kodorvan\constructor\models\telegram\processes\language
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class select extends core
{
/**
* Language
*
* Send the language choose menu
*
* @param context $context Request data from Telegram
* @param string $prefix Prefix for 'callback_data' (`$prefix . $language->name`)
* @param string $title Title of the message
* @param string $description Description of the message
* @param array $exclude Languages that will be excluded ['ru', 'en'...]
*
* @return void
*/
public static function menu(context $context, string $prefix, string $title, string $description, array $exclude = []): void
{
// Initializing the account
$account = $context->get('account');
if ($account instanceof record) {
// Initialized the account
// Initializing language
$language = $context->get('language');
if ($language) {
// Initialized language
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Declaring the buffer of generated keyboard with languages
$keyboard = [];
// Initializing the iterator of rows
$row = 0;
// Initializing buffer of languages
$languages = language::cases();
// Deleting the actual language from buffer of languages
unset($languages[array_search($language, $languages, strict: true)]);
// Sorting buffer of languages by the actual language
$languages = [$language, ...$languages];
foreach ($languages as $language) {
// Iterating over languages
// Skipping excluded languages
if (array_search($language->name, $exclude, strict: true) !== false) continue;
// Initializing the row
$keyboard[$row] ??= [];
// Writing the language choose button into the buffer of generated keyboard with languages
$keyboard[$row][] = [
'text' => ($language->flag() ? $language->flag() . ' ' : '') . $language->label($language),
'callback_data' => $prefix . $language->name
];
// When reaching 4 buttons in a row, move to the next row
if (count($keyboard[$row]) === 4) ++$row;
}
// Writing the button for helping lozalizing
$keyboard[$row === 0 && empty($keyboard[0]) ? 0 : ++$row] = [
[
'text' => '🗂 ' . $localization['select_language_button_add'],
'url' => 'https://git.svoboda.works/kodorvan\constructor/src/branch/stable/kodorvan/neurobot/system/localizations'
]
];
// Sending the message
$context->sendMessage(
$title ?? '🌏 *' . $localization['select_language_title'] . "*\n" . ($description ?? $localization['select_language_description']),
[
'reply_markup' => [
'inline_keyboard' => $keyboard,
'disable_notification' => true
],
]
);
} else {
// Not initialized localization
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize localization*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized language
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize language*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
} else {
// Not initialized the account
// Sending the message
$context->sendMessage('⚠️ *Failed to initialize your Telegram account*')
->then(function (message $message) use ($context) {
// Sended the message
// Ending the conversation process
$context->endConversation();
});
}
}
}

View File

@@ -1,894 +0,0 @@
<?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();
});
}
}
}

View File

@@ -0,0 +1,123 @@
<?php
declare(strict_types=1);
namespace kodorvan\constructor\models\telegram;
// Files of the project
use kodorvan\constructor\models\core,
kodorvan\constructor\models\account,
kodorvan\constructor\models\localization,
kodorvan\constructor\models\settings as model,
kodorvan\constructor\models\telegram\processes\language\select as process_language_select;
// Library for languages support
use mirzaev\languages\language;
// The library for escaping all markdown symbols
use function mirzaev\unmarkdown;
// Framework for Telegram
use SergiX44\Nutgram\Nutgram as telegram,
SergiX44\Nutgram\Telegram\Properties\ParseMode as mode,
SergiX44\Nutgram\Telegram\Types\Message\Message as message,
SergiX44\Nutgram\Handlers\Type\Command as command,
SergiX44\Nutgram\Telegram\Types\Internal\InputFile as input,
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardMarkup as keyboard,
SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardButton as button;
// Built-in libraries
use Error as error;
/**
* Telegram settings
*
* @package kodorvan\constructor\models\telegram
*
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
final class settings extends core
{
/**
* Language
*
* Write the language into the account and the robot instance
*
* @param telegram $robot The chat-robot instance
* @param language $language The language
*
* @return void
*/
public static function language(telegram $robot, language $language = LANGUAGE_DEFAULT): void
{
// Initializing the account
$account = $robot->get('account');
if ($account instanceof account) {
// Initialized the account
// Initializing the menu message localization
$localization = new localization($language);
if ($localization instanceof localization) {
// Initialized the localization
// Initializing the account old language
$from = $account->language;
// Writing the language into the account
$account->language = $language;
// Serializing the account
$account->serialize();
// Writing the account into the database;
$updated = $account->update();
// Deserializing the account
$account->deserialize();
if ($updated instanceof account) {
// Writed the account into the database
// Writing the account into the robot instance
$robot->set('account', $account);
try {
// Initializing the account new language
$to = $account->language;
// Sending the message
$robot->sendMessage(
text: "✅ *$localization->settings_language_update_success:* " . trim($from->flag() . ' ' . $from->label($to)) . ' → *' . trim($to->flag() . ' ' . $to->label($to)) . '*',
parse_mode: mode::MARKDOWN,
disable_notification: true
);
// Sending the message
$robot->answerCallbackQuery(
text: $to->label($to),
show_alert: false
);
} catch (error $error) {
// Failed to send the message about language update
// Writing into the errors output buffer
error_log((string) $error);
// Sending the message
$robot->sendMessage(
text: "❎ *$localization->settings_language_update_fail*",
parse_mode: mode::MARKDOWN,
disable_notification: true
);
// Ending the conversation process
$robot->endConversation();
}
}
}
}
}
}

View File

@@ -18,7 +18,10 @@ use mirzaev\minimal\core,
mirzaev\minimal\route; mirzaev\minimal\route;
// Framework for Telegram // Framework for Telegram
use Telegram\Bot\BotsManager as telegram; /* use Telegram\Bot\BotsManager as telegram; */
use SergiX44\Nutgram\Nutgram as telegram,
SergiX44\Nutgram\RunningMode\Webhook as webhook,
SergiX44\Nutgram\Telegram\Types\Internal\InputFile as input;
// Enabling debugging // Enabling debugging
/* ini_set('error_reporting', E_ALL); /* ini_set('error_reporting', E_ALL);
@@ -55,7 +58,19 @@ 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 robots manager settings // Initializing the robot
$robot = new telegram(TELEGRAM['constructor']['key']);
$robot->setWebhook(
url: 'https://' . PROJECT_DOMAIN . '/telegram/constructor/webhook.php',
certificate: new input(resource: PROJECT_CERTIFICATE),
ip_address: SERVER_IP_ADDRESS,
max_connections: 10,
drop_pending_updates: false,
secret_token: 'bebra228'
);
/* // Initializing the robots manager settings
$settings = [ $settings = [
'bots' => [ 'bots' => [
'constructor' => [ 'constructor' => [
@@ -78,6 +93,8 @@ $updates = $telegram->bot('constructor')->setWebhook([
'url' => 'https://' . PROJECT_DOMAIN . '/telegram/constructor/webhook.php', 'url' => 'https://' . PROJECT_DOMAIN . '/telegram/constructor/webhook.php',
'certificate' => PROJECT_CERTIFICATE 'certificate' => PROJECT_CERTIFICATE
]); ]);
*/
/* // Initializing the updates listener /* // Initializing the updates listener
$robot->onUpdate(function (context $context): void {}); $robot->onUpdate(function (context $context): void {});

View File

@@ -6,9 +6,15 @@ 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\settings,
kodorvan\constructor\models\telegram\commands\start, kodorvan\constructor\models\telegram\commands\start as command_start,
kodorvan\constructor\models\telegram\settings; kodorvan\constructor\models\telegram\commands\society as command_society,
kodorvan\constructor\models\telegram\commands\language as command_language,
kodorvan\constructor\models\telegram\middlewares\account as middleware_account,
kodorvan\constructor\models\telegram\middlewares\language as middleware_language,
kodorvan\constructor\models\telegram\middlewares\localization as middleware_localization,
kodorvan\constructor\models\telegram\middlewares\settings as middleware_settings,
kodorvan\constructor\models\telegram\middlewares\authorizations as middleware_authorizations;
// Library for languages support // Library for languages support
use mirzaev\languages\language; use mirzaev\languages\language;
@@ -18,7 +24,9 @@ use mirzaev\minimal\core,
mirzaev\minimal\route; mirzaev\minimal\route;
// Framework for Telegram // Framework for Telegram
use Telegram\Bot\BotsManager as telegram; /* use Telegram\Bot\BotsManager as telegram; */
use SergiX44\Nutgram\Nutgram as telegram,
SergiX44\Nutgram\RunningMode\Webhook as webhook;
// Enabling debugging // Enabling debugging
/* ini_set('error_reporting', E_ALL); /* ini_set('error_reporting', E_ALL);
@@ -55,55 +63,38 @@ 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 robots manager settings // Initializing the robot
$settings = [ $robot = new telegram(TELEGRAM['constructor']['key']);
'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 $webhook = new webhook(secretToken: 'bebra228');
$telegram = new telegram($settings); $webhook->setSafeMode(true);
var_dump($updates = $telegram->bot('constructor')->getWebhookUpdate()); $robot->setRunningMode($webhook);
/* // Initializing the updates listener $robot->middleware(middleware_account::class);
$robot->onUpdate(function (context $context): void {}); $robot->middleware(middleware_language::class);
$robot->middleware(middleware_localization::class);
$robot->middleware(middleware_authorizations::class);
// 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 // Initializing the robot commands handlers
$robot->onCommand('start', [commands::class, 'start']); $robot->registerCommand(command_start::class);
$robot->onCommand('start telegram voronka', [commands::class, 'start']); $robot->onCommand('start telegram voronka', command_start::class);
$robot->onCommand('start parser', [commands::class, 'start']); $robot->onCommand('start parser', command_start::class);
$robot->onCommand('start calculator', [commands::class, 'start']); $robot->onCommand('start calculator', command_start::class);
$robot->onCommand('language', [commands::class, 'language'])->middleware([middlewares::class, 'settings']); $robot->registerCommand(command_language::class)->middleware(middleware_settings::class);
$robot->onCommand('society', [commands::class, 'society']); $robot->registerCommand(command_society::class);
// Initializing the robot settings language buttons handlers // Initializing the robot settings language buttons handlers
foreach (language::cases() as $language) { foreach (language::cases() as $language) {
// Iterating over languages // Iterating over languages
// Initializing language buttons // Initializing language buttons
$robot->onCbQueryData(["settings_language_$language->name"], fn(context $context) => settings::language($context, $language)); $robot->onCallbackQueryData("settings_language_$language->name", fn(telegram $robot) => settings::language(robot: $robot, language: $language));
}; };
$robot->onCbQueryData('project_create', ['process_project_create', 'name']); /* $robot->onCbQueryData('project_create', ['process_project_create', 'name']); */
// Starting chat-robot $robot->run();
$robot->run(); */

View File

@@ -6,8 +6,16 @@ use mirzaev\languages\language;
// Initializing dependencies // Initializing dependencies
require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'; require ROOT . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
define('PROJECT_NAME', ''); define('SERVER_IP_ADDRESS', '5.140.110.25');
define('PROJECT_DOMAIN', '');
define('PROJECT_CREATOR', 'kodorvan');
define('PROJECT_NAME', 'constructor');
define('PROJECT_DOMAIN', 'constructor.kodorvan.tech');
define('PROJECT_CERTIFICATE', SETTINGS . DIRECTORY_SEPARATOR . 'certificate' . DIRECTORY_SEPARATOR . 'public.pem');
define('REPOSITORY', 'https://git.svoboda.works');
define('PROJECT_REPOSITORY', REPOSITORY . '/' . PROJECT_CREATOR . '/' . PROJECT_NAME);
define('PROJECT_REPOSITORY_LANGUAGE_ADD', PROJECT_REPOSITORY . '/src/branch/stable/' . PROJECT_CREATOR . '/' . PROJECT_NAME . '/system/localizations');
/* define('PROJECT_CERTIFICATE', SETTINGS . DIRECTORY_SEPARATOR . 'cert.pem'); */
define('LANGUAGE_DEFAULT', language::en); define('LANGUAGE_DEFAULT', language::en);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

2
logs/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*
!.gitignore