generated from mirzaev/pot
580 lines
23 KiB
PHP
Executable File
580 lines
23 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace deeproots\deeproots\models\telegram\buttons\question;
|
|
|
|
// Files of the project
|
|
use deeproots\deeproots\models\core,
|
|
deeproots\deeproots\models\question,
|
|
deeproots\deeproots\models\telegram\processes\question\search as process_question_search,
|
|
deeproots\deeproots\models\enumerations\membership\status;
|
|
|
|
// Framework for Telegram
|
|
use Zanzara\Context as context,
|
|
Zanzara\Telegram\Type\Message as message;
|
|
|
|
// Svoboda time
|
|
use svoboda\time\statement as svoboda;
|
|
|
|
// Baza database
|
|
use mirzaev\baza\record;
|
|
|
|
/**
|
|
* Telegram system question search buttons
|
|
*
|
|
* @package deeproots\deeproots\models\telegram\buttons\question
|
|
*
|
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
|
*/
|
|
final class search extends core
|
|
{
|
|
/**
|
|
* Process
|
|
*
|
|
* @var const string PROCESS Name of the process in the telegram user buffer
|
|
*/
|
|
public const string PROCESS = process_question_search::PROCESS;
|
|
|
|
/**
|
|
* Identifier
|
|
*
|
|
* Request to enter identifier
|
|
*
|
|
* @param context $context Request data from Telegram
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function identifier(context $context)
|
|
{
|
|
// Initializing the account
|
|
$account = $context->get('account');
|
|
|
|
if ($account instanceof record) {
|
|
// Initialized the account
|
|
|
|
// Initializing localization
|
|
$localization = $context->get('localization');
|
|
|
|
if ($localization) {
|
|
// Initialized localization
|
|
|
|
// Reading from the telegram user buffer
|
|
$context->getUserDataItem(static::PROCESS)
|
|
->then(function ($search) use ($context, $localization) {
|
|
// Readed from the telegram user buffer
|
|
|
|
if ($search) {
|
|
// Found started search process
|
|
|
|
// Sending the message
|
|
$context->sendMessage(
|
|
'📄 *' . $localization[static::PROCESS . '_identifier_request_title'] . '*',
|
|
[
|
|
'reply_markup' => [
|
|
'inline_keyboard' => [
|
|
[
|
|
[
|
|
'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'],
|
|
'callback_data' => 'delete'
|
|
],
|
|
[
|
|
'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'],
|
|
'callback_data' => 'cancel'
|
|
]
|
|
],
|
|
],
|
|
'disable_notification' => true
|
|
]
|
|
]
|
|
)->then(function (message $message) use ($context) {
|
|
// Sended the message
|
|
|
|
// Writing into the distribution search buffer
|
|
$context->nextStep([process_question_search::class, 'identifier']);
|
|
});
|
|
} else {
|
|
// Not found started search process
|
|
|
|
// Sending the message
|
|
$context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*');
|
|
}
|
|
});
|
|
} else {
|
|
// Not initialized localization
|
|
|
|
// Sending the message
|
|
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
|
->then(function ($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) use ($context) {
|
|
// Sended the message
|
|
|
|
// Ending the conversation process
|
|
$context->endConversation();
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Text
|
|
*
|
|
* Request to enter text
|
|
*
|
|
* @param context $context Request data from Telegram
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function text(context $context)
|
|
{
|
|
// Initializing the account
|
|
$account = $context->get('account');
|
|
|
|
if ($account instanceof record) {
|
|
// Initialized the account
|
|
|
|
// Initializing localization
|
|
$localization = $context->get('localization');
|
|
|
|
if ($localization) {
|
|
// Initialized localization
|
|
|
|
// Reading from the telegram user buffer
|
|
$context->getUserDataItem(static::PROCESS)
|
|
->then(function ($search) use ($context, $localization) {
|
|
// Readed from the telegram user buffer
|
|
|
|
if ($search) {
|
|
// Found started search process
|
|
|
|
// Sending the message
|
|
$context->sendMessage(
|
|
'📄 *' . $localization[static::PROCESS . '_text_request_title'] . '*',
|
|
[
|
|
'reply_markup' => [
|
|
'inline_keyboard' => [
|
|
[
|
|
[
|
|
'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'],
|
|
'callback_data' => 'delete'
|
|
],
|
|
[
|
|
'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'],
|
|
'callback_data' => 'cancel'
|
|
]
|
|
],
|
|
],
|
|
'disable_notification' => true
|
|
]
|
|
]
|
|
)->then(function (message $message) use ($context) {
|
|
// Sended the message
|
|
|
|
// Writing into the distribution search buffer
|
|
$context->nextStep([process_question_search::class, 'text']);
|
|
});
|
|
} else {
|
|
// Not found started search process
|
|
|
|
// Sending the message
|
|
$context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*');
|
|
}
|
|
});
|
|
} else {
|
|
// Not initialized localization
|
|
|
|
// Sending the message
|
|
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
|
->then(function ($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) use ($context) {
|
|
// Sended the message
|
|
|
|
// Ending the conversation process
|
|
$context->endConversation();
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* A
|
|
*
|
|
* Request to enter A-answer
|
|
*
|
|
* @param context $context Request data from Telegram
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function a(context $context)
|
|
{
|
|
// Initializing the account
|
|
$account = $context->get('account');
|
|
|
|
if ($account instanceof record) {
|
|
// Initialized the account
|
|
|
|
// Initializing localization
|
|
$localization = $context->get('localization');
|
|
|
|
if ($localization) {
|
|
// Initialized localization
|
|
|
|
// Reading from the telegram user buffer
|
|
$context->getUserDataItem(static::PROCESS)
|
|
->then(function ($search) use ($context, $localization) {
|
|
// Readed from the telegram user buffer
|
|
|
|
if ($search) {
|
|
// Found started search process
|
|
|
|
// Sending the message
|
|
$context->sendMessage(
|
|
'📄 *' . $localization[static::PROCESS . '_a_request_title'] . '*',
|
|
[
|
|
'reply_markup' => [
|
|
'inline_keyboard' => [
|
|
[
|
|
[
|
|
'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'],
|
|
'callback_data' => 'delete'
|
|
],
|
|
[
|
|
'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'],
|
|
'callback_data' => 'cancel'
|
|
]
|
|
],
|
|
],
|
|
'disable_notification' => true
|
|
]
|
|
]
|
|
)->then(function (message $message) use ($context) {
|
|
// Sended the message
|
|
|
|
// Writing into the distribution search buffer
|
|
$context->nextStep([process_question_search::class, 'a']);
|
|
});
|
|
} else {
|
|
// Not found started search process
|
|
|
|
// Sending the message
|
|
$context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*');
|
|
}
|
|
});
|
|
} else {
|
|
// Not initialized localization
|
|
|
|
// Sending the message
|
|
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
|
->then(function ($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) use ($context) {
|
|
// Sended the message
|
|
|
|
// Ending the conversation process
|
|
$context->endConversation();
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* B
|
|
*
|
|
* Request to enter B-answer
|
|
*
|
|
* @param context $context Request data from Telegram
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function b(context $context)
|
|
{
|
|
// Initializing the account
|
|
$account = $context->get('account');
|
|
|
|
if ($account instanceof record) {
|
|
// Initialized the account
|
|
|
|
// Initializing localization
|
|
$localization = $context->get('localization');
|
|
|
|
if ($localization) {
|
|
// Initialized localization
|
|
|
|
// Reading from the telegram user buffer
|
|
$context->getUserDataItem(static::PROCESS)
|
|
->then(function ($search) use ($context, $localization) {
|
|
// Readed from the telegram user buffer
|
|
|
|
if ($search) {
|
|
// Found started search process
|
|
|
|
// Sending the message
|
|
$context->sendMessage(
|
|
'📄 *' . $localization[static::PROCESS . '_b_request_title'] . '*',
|
|
[
|
|
'reply_markup' => [
|
|
'inline_keyboard' => [
|
|
[
|
|
[
|
|
'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'],
|
|
'callback_data' => 'delete'
|
|
],
|
|
[
|
|
'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'],
|
|
'callback_data' => 'cancel'
|
|
]
|
|
],
|
|
],
|
|
'disable_notification' => true
|
|
]
|
|
]
|
|
)->then(function (message $message) use ($context) {
|
|
// Sended the message
|
|
|
|
// Writing into the distribution search buffer
|
|
$context->nextStep([process_question_search::class, 'b']);
|
|
});
|
|
} else {
|
|
// Not found started search process
|
|
|
|
// Sending the message
|
|
$context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*');
|
|
}
|
|
});
|
|
} else {
|
|
// Not initialized localization
|
|
|
|
// Sending the message
|
|
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
|
->then(function ($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) use ($context) {
|
|
// Sended the message
|
|
|
|
// Ending the conversation process
|
|
$context->endConversation();
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* C
|
|
*
|
|
* Request to enter C-answer
|
|
*
|
|
* @param context $context Request data from Telegram
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function c(context $context)
|
|
{
|
|
// Initializing the account
|
|
$account = $context->get('account');
|
|
|
|
if ($account instanceof record) {
|
|
// Initialized the account
|
|
|
|
// Initializing localization
|
|
$localization = $context->get('localization');
|
|
|
|
if ($localization) {
|
|
// Initialized localization
|
|
|
|
// Reading from the telegram user buffer
|
|
$context->getUserDataItem(static::PROCESS)
|
|
->then(function ($search) use ($context, $localization) {
|
|
// Readed from the telegram user buffer
|
|
|
|
if ($search) {
|
|
// Found started search process
|
|
|
|
// Sending the message
|
|
$context->sendMessage(
|
|
'📄 *' . $localization[static::PROCESS . '_c_request_title'] . '*',
|
|
[
|
|
'reply_markup' => [
|
|
'inline_keyboard' => [
|
|
[
|
|
[
|
|
'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'],
|
|
'callback_data' => 'delete'
|
|
],
|
|
[
|
|
'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'],
|
|
'callback_data' => 'cancel'
|
|
]
|
|
],
|
|
],
|
|
'disable_notification' => true
|
|
]
|
|
]
|
|
)->then(function (message $message) use ($context) {
|
|
// Sended the message
|
|
|
|
// Writing into the distribution search buffer
|
|
$context->nextStep([process_question_search::class, 'c']);
|
|
});
|
|
} else {
|
|
// Not found started search process
|
|
|
|
// Sending the message
|
|
$context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*');
|
|
}
|
|
});
|
|
} else {
|
|
// Not initialized localization
|
|
|
|
// Sending the message
|
|
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
|
->then(function ($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) use ($context) {
|
|
// Sended the message
|
|
|
|
// Ending the conversation process
|
|
$context->endConversation();
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* D
|
|
*
|
|
* Request to enter D-answer
|
|
*
|
|
* @param context $context Request data from Telegram
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function d(context $context)
|
|
{
|
|
// Initializing the account
|
|
$account = $context->get('account');
|
|
|
|
if ($account instanceof record) {
|
|
// Initialized the account
|
|
|
|
// Initializing localization
|
|
$localization = $context->get('localization');
|
|
|
|
if ($localization) {
|
|
// Initialized localization
|
|
|
|
// Reading from the telegram user buffer
|
|
$context->getUserDataItem(static::PROCESS)
|
|
->then(function ($search) use ($context, $localization) {
|
|
// Readed from the telegram user buffer
|
|
|
|
if ($search) {
|
|
// Found started search process
|
|
|
|
// Sending the message
|
|
$context->sendMessage(
|
|
'📄 *' . $localization[static::PROCESS . '_d_request_title'] . '*',
|
|
[
|
|
'reply_markup' => [
|
|
'inline_keyboard' => [
|
|
[
|
|
[
|
|
'text' => '🗑 ' . $localization[static::PROCESS . '_button_delete'],
|
|
'callback_data' => 'delete'
|
|
],
|
|
[
|
|
'text' => '❎ ' . $localization[static::PROCESS . '_button_cancel'],
|
|
'callback_data' => 'cancel'
|
|
]
|
|
],
|
|
],
|
|
'disable_notification' => true
|
|
]
|
|
]
|
|
)->then(function (message $message) use ($context) {
|
|
// Sended the message
|
|
|
|
// Writing into the distribution search buffer
|
|
$context->nextStep([process_question_search::class, 'd']);
|
|
});
|
|
} else {
|
|
// Not found started search process
|
|
|
|
// Sending the message
|
|
$context->sendMessage('⚠️ *' . $localization[static::PROCESS . '_not_started'] . '*');
|
|
}
|
|
});
|
|
} else {
|
|
// Not initialized localization
|
|
|
|
// Sending the message
|
|
$context->sendMessage('⚠️ *Failed to initialize localization*')
|
|
->then(function ($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) use ($context) {
|
|
// Sended the message
|
|
|
|
// Ending the conversation process
|
|
$context->endConversation();
|
|
});
|
|
}
|
|
}
|
|
}
|