generated from mirzaev/pot
do not know what is there
This commit is contained in:
@@ -33,7 +33,8 @@
|
|||||||
"svoboda/time": "^1.0",
|
"svoboda/time": "^1.0",
|
||||||
"badfarm/zanzara": "^0.9.1",
|
"badfarm/zanzara": "^0.9.1",
|
||||||
"nyholm/psr7": "^1.8",
|
"nyholm/psr7": "^1.8",
|
||||||
"react/filesystem": "^0.1.2"
|
"react/filesystem": "^0.1.2",
|
||||||
|
"mirzaev/record": "^2.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ return [
|
|||||||
// Main menu
|
// Main menu
|
||||||
'menu_title' => 'Main menu',
|
'menu_title' => 'Main menu',
|
||||||
'menu_accounts' => 'Accounts',
|
'menu_accounts' => 'Accounts',
|
||||||
|
'menu_accounts_experience' => 'Experience',
|
||||||
|
|
||||||
// Account
|
// Account
|
||||||
'account_title' => 'Account',
|
'account_title' => 'Account',
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ return [
|
|||||||
// Main menu
|
// Main menu
|
||||||
'menu_title' => 'Главное меню',
|
'menu_title' => 'Главное меню',
|
||||||
'menu_accounts' => 'Аккаунты',
|
'menu_accounts' => 'Аккаунты',
|
||||||
|
'menu_accounts_experience' => 'Опыт',
|
||||||
|
|
||||||
// Аккаунт
|
// Аккаунт
|
||||||
'account_title' => 'Аккаунт',
|
'account_title' => 'Аккаунт',
|
||||||
|
|||||||
@@ -5,7 +5,12 @@ declare(strict_types=1);
|
|||||||
namespace kodorvan\brainrot\models;
|
namespace kodorvan\brainrot\models;
|
||||||
|
|
||||||
// Files of the project
|
// Files of the project
|
||||||
use kodorvan\brainrot\models\core;
|
use kodorvan\brainrot\models\core,
|
||||||
|
kodorvan\brainrot\models\authorizations;
|
||||||
|
|
||||||
|
// Active Record pattern
|
||||||
|
use mirzaev\record\interfaces\record as record_interface,
|
||||||
|
mirzaev\record\traits\record as record_trait;
|
||||||
|
|
||||||
// Svoboda time
|
// Svoboda time
|
||||||
use svoboda\time\statement as svoboda;
|
use svoboda\time\statement as svoboda;
|
||||||
@@ -32,8 +37,9 @@ use Exception as exception,
|
|||||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
*/
|
*/
|
||||||
final class account extends core
|
final class account extends core implements record_interface
|
||||||
{
|
{
|
||||||
|
use record_trait;
|
||||||
/**
|
/**
|
||||||
* File
|
* File
|
||||||
*
|
*
|
||||||
@@ -51,9 +57,11 @@ final class account extends core
|
|||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
|
* @method record|null $record The record
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct(?record $record = null)
|
||||||
{
|
{
|
||||||
// Initializing the database
|
// Initializing the database
|
||||||
$this->database = new database()
|
$this->database = new database()
|
||||||
@@ -66,14 +74,15 @@ final class account extends core
|
|||||||
new column('name_second', type::string, ['length' => 64]),
|
new column('name_second', type::string, ['length' => 64]),
|
||||||
new column('language', type::string, ['length' => 2]),
|
new column('language', type::string, ['length' => 2]),
|
||||||
new column('robot', type::char),
|
new column('robot', type::char),
|
||||||
new column('authorized_system', type::char),
|
new column('experience', type::long_long_unsigned),
|
||||||
new column('authorized_settings', type::char),
|
new column('slots', type::integer_unsigned),
|
||||||
new column('authorized_system_accounts', type::char),
|
|
||||||
new column('authorized_system_settings', type::char),
|
|
||||||
new column('updated', type::integer_unsigned),
|
new column('updated', type::integer_unsigned),
|
||||||
new column('created', type::integer_unsigned)
|
new column('created', type::integer_unsigned)
|
||||||
)
|
)
|
||||||
->connect($this->file);
|
->connect($this->file);
|
||||||
|
|
||||||
|
// Initializing the record
|
||||||
|
$record instanceof record and $this->record = $record;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,16 +107,16 @@ final class account extends core
|
|||||||
// Found the account record
|
// Found the account record
|
||||||
|
|
||||||
if (
|
if (
|
||||||
$account->name_first !== $telegram->getFirstName() ||
|
$account->name_first !== $telegram->getFirstName() ||
|
||||||
$account->name_second !== $telegram->getLastName() ||
|
$account->name_second !== $telegram->getLastName() ||
|
||||||
$account->domain !== $telegram->getUsername()
|
$account->domain !== $telegram->getUsername()
|
||||||
) {
|
) {
|
||||||
// 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->getId(),
|
||||||
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->name_first = $telegram->getFirstName();
|
$record->name_first = $telegram->getFirstName();
|
||||||
$record->name_second = $telegram->getLastName();
|
$record->name_second = $telegram->getLastName();
|
||||||
@@ -167,11 +176,16 @@ final class account extends core
|
|||||||
* Creates the account record in the database
|
* Creates the account record in the database
|
||||||
*
|
*
|
||||||
* @param telegram $telegram The telegram account
|
* @param telegram $telegram The telegram account
|
||||||
|
* @param int $experience The player experience
|
||||||
|
* @param int $slots The player avaiable slots
|
||||||
*
|
*
|
||||||
* @return int|false The record identifier, if created
|
* @return int|false The record identifier, if created
|
||||||
*/
|
*/
|
||||||
public function registrate(telegram $telegram): int|false
|
public function registrate(
|
||||||
{
|
telegram $telegram,
|
||||||
|
int $experience = 0,
|
||||||
|
int $slots = 1
|
||||||
|
): int|false {
|
||||||
// Initializing the identifier
|
// Initializing the identifier
|
||||||
$identifier = $this->database->count() + 1;
|
$identifier = $this->database->count() + 1;
|
||||||
|
|
||||||
@@ -184,10 +198,8 @@ final class account extends core
|
|||||||
(string) $telegram->getUsername(),
|
(string) $telegram->getUsername(),
|
||||||
(string) $telegram->getLanguageCode(),
|
(string) $telegram->getLanguageCode(),
|
||||||
(int) $telegram->isBot(),
|
(int) $telegram->isBot(),
|
||||||
1,
|
$experience,
|
||||||
1,
|
$slots,
|
||||||
0,
|
|
||||||
0,
|
|
||||||
svoboda::timestamp(),
|
svoboda::timestamp(),
|
||||||
svoboda::timestamp()
|
svoboda::timestamp()
|
||||||
);
|
);
|
||||||
@@ -198,4 +210,33 @@ final class account extends core
|
|||||||
// Exit (success)
|
// Exit (success)
|
||||||
return $created ? $identifier : false;
|
return $created ? $identifier : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Authorizations
|
||||||
|
*
|
||||||
|
* Search for the account authorizations
|
||||||
|
*
|
||||||
|
* @return authorizations|null The account authorizations
|
||||||
|
*/
|
||||||
|
public function authorizations(): ?authorizations
|
||||||
|
{
|
||||||
|
// Initializing the authorizations model
|
||||||
|
$authorizations = new authorizations();
|
||||||
|
|
||||||
|
// Search for the account authorizations
|
||||||
|
$record = $authorizations->database->read(filter: fn(record $record) => $record->account === $this->identifier, amount: 1)[0] ?? null;
|
||||||
|
|
||||||
|
if ($record instanceof record) {
|
||||||
|
// Found the account authorizations
|
||||||
|
|
||||||
|
// Writing the found authorizations record into the record object
|
||||||
|
$authorizations->record = $record;
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return $authorizations;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
133
kodorvan/brainrot/system/models/authorizations.php
Normal file
133
kodorvan/brainrot/system/models/authorizations.php
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace kodorvan\neurobot\models;
|
||||||
|
|
||||||
|
// Files of the project
|
||||||
|
use kodorvan\neurobot\models\core;
|
||||||
|
|
||||||
|
// Svoboda time
|
||||||
|
use svoboda\time\statement as svoboda;
|
||||||
|
|
||||||
|
// Baza database
|
||||||
|
use mirzaev\baza\database,
|
||||||
|
mirzaev\baza\column,
|
||||||
|
mirzaev\baza\record,
|
||||||
|
mirzaev\baza\enumerations\encoding,
|
||||||
|
mirzaev\baza\enumerations\type;
|
||||||
|
|
||||||
|
// Active Record pattern
|
||||||
|
use mirzaev\record\interfaces\record as record_interface,
|
||||||
|
mirzaev\record\traits\record as record_trait;
|
||||||
|
|
||||||
|
// Framework for Telegram
|
||||||
|
use Zanzara\Telegram\Type\User as telegram;
|
||||||
|
|
||||||
|
// Built-in libraries
|
||||||
|
use Exception as exception,
|
||||||
|
RuntimeException as exception_runtime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Authorizations
|
||||||
|
*
|
||||||
|
* @package kodorvan\neurobot\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 authorizations extends core implements record_interface
|
||||||
|
{
|
||||||
|
use record_trait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File
|
||||||
|
*
|
||||||
|
* @var string $database Path to the database file
|
||||||
|
*/
|
||||||
|
protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'authorizations.baza';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database
|
||||||
|
*
|
||||||
|
* @var database $database The database
|
||||||
|
*/
|
||||||
|
public protected(set) database $database;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @method record|null $record The record
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(?record $record = null)
|
||||||
|
{
|
||||||
|
// Initializing the database
|
||||||
|
$this->database = new database()
|
||||||
|
->encoding(encoding::utf8)
|
||||||
|
->columns(
|
||||||
|
new column('identifier', type::long_long_unsigned),
|
||||||
|
new column('account', type::long_long_unsigned),
|
||||||
|
new column('system', type::char),
|
||||||
|
new column('settings', type::char),
|
||||||
|
new column('chat', type::char),
|
||||||
|
new column('generations', type::char),
|
||||||
|
new column('arena', type::char),
|
||||||
|
new column('system_accounts', type::char),
|
||||||
|
new column('system_settings', type::char),
|
||||||
|
new column('updated', type::integer_unsigned),
|
||||||
|
new column('created', type::integer_unsigned)
|
||||||
|
)
|
||||||
|
->connect($this->file);
|
||||||
|
|
||||||
|
// Initializing the record
|
||||||
|
$record instanceof record and $this->record = $record;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write
|
||||||
|
*
|
||||||
|
* @param int $account The account identifier
|
||||||
|
* @param int $system
|
||||||
|
* @param int $settings
|
||||||
|
* @param int $chat
|
||||||
|
* @param int $generations
|
||||||
|
* @param int $arena
|
||||||
|
* @param int $system_accounts
|
||||||
|
* @param int $system_settings
|
||||||
|
*
|
||||||
|
* @return int|false The record identifier, if created
|
||||||
|
*/
|
||||||
|
public function write(
|
||||||
|
int $account,
|
||||||
|
int $system = 1,
|
||||||
|
int $settings = 1,
|
||||||
|
int $chat = 1,
|
||||||
|
int $generations = 1,
|
||||||
|
int $arena = 0,
|
||||||
|
int $system_accounts = 0,
|
||||||
|
int $system_settings = 0,
|
||||||
|
): int|false
|
||||||
|
{
|
||||||
|
$record = $this->database->record(
|
||||||
|
$this->database->count() + 1,
|
||||||
|
$account,
|
||||||
|
$system,
|
||||||
|
$settings,
|
||||||
|
$chat,
|
||||||
|
$generations,
|
||||||
|
$arena,
|
||||||
|
$system_accounts,
|
||||||
|
$system_settings,
|
||||||
|
svoboda::timestamp(),
|
||||||
|
svoboda::timestamp()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Writing the record into the database
|
||||||
|
$created = $this->database->write($record);
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return $created ? $record->identifier : false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,10 +32,25 @@ use Zanzara\Context as context,
|
|||||||
*/
|
*/
|
||||||
final class commands extends core
|
final class commands extends core
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Start
|
||||||
|
*
|
||||||
|
* Responce for the commands: '/start'
|
||||||
|
*
|
||||||
|
* @param context $context Request data from Telegram
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function start(context $context): void
|
||||||
|
{
|
||||||
|
// Processing the menu method and exit (success)
|
||||||
|
static::menu(context: $context);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Menu
|
* Menu
|
||||||
*
|
*
|
||||||
* Responce for the commands: "/start", '/menu'
|
* Responce for the commands: '/menu'
|
||||||
*
|
*
|
||||||
* @param context $context Request data from Telegram
|
* @param context $context Request data from Telegram
|
||||||
*
|
*
|
||||||
@@ -55,32 +70,83 @@ final class commands extends core
|
|||||||
if ($localization) {
|
if ($localization) {
|
||||||
// Initialized localization
|
// Initialized localization
|
||||||
|
|
||||||
// Initializing the title
|
// Initializing the title message text
|
||||||
$title = '📋 *' . $localization['menu_title'] . '*';
|
$title = '📋 *' . $localization['menu_title'] . '*';
|
||||||
|
|
||||||
// Initializing accounts
|
// Initializing the accounts message text
|
||||||
$accounts = '*' . $localization['menu_accounts'] . ':* ' . ((new account)->database->count() ?? 0);
|
/* $accounts = '*' . $localization['menu_accounts'] . ':* ' . ((new account)->database->count() ?? 0); */
|
||||||
|
|
||||||
|
// Initializing the experience message text
|
||||||
|
$experience = '*' . $localization['menu_accounts_experience'] . ':*' . $account->experience;
|
||||||
|
|
||||||
|
// Initializing the player avaiable slots
|
||||||
|
$slots = $account->slots;
|
||||||
|
|
||||||
|
// Declaring the message keyboard
|
||||||
|
$keyboard = [];
|
||||||
|
|
||||||
|
// Initializing the registry of buttons amount in a row
|
||||||
|
$row_amount = 2;
|
||||||
|
|
||||||
|
// Initializing the row iterator
|
||||||
|
$row = 0;
|
||||||
|
|
||||||
|
foreach ([] as $key => $brainrot) {
|
||||||
|
// Iterating over the player brainrots
|
||||||
|
|
||||||
|
// Initializing the row
|
||||||
|
$keyboard[$row] ??= [];
|
||||||
|
|
||||||
|
// Initializing the keyboard brainrot button
|
||||||
|
$keybord[$row][] = [
|
||||||
|
'text' => 'sperma',
|
||||||
|
'callback_data' => 'brainrot_profile_dolboeb'
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($keyboard[$row] >= $row_amount) {
|
||||||
|
// Reached the row buttons limit
|
||||||
|
|
||||||
|
// POHUY
|
||||||
|
++$row;
|
||||||
|
}
|
||||||
|
|
||||||
|
// POHUY
|
||||||
|
--$slots;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; $slots > 0; --$slots) {
|
||||||
|
// Iterating over remain slots
|
||||||
|
|
||||||
|
// Initializing the row
|
||||||
|
$keyboard[$row] ??= [];
|
||||||
|
|
||||||
|
// Initializing the keyboard brainrot button
|
||||||
|
$keybord[$row][] = [
|
||||||
|
'text' => $localization['empty'],
|
||||||
|
'callback_data' => 'brainrot_create'
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($keyboard[$row] >= $row_amount) {
|
||||||
|
// Reached the row buttons limit
|
||||||
|
|
||||||
|
// POHUY
|
||||||
|
++$row;
|
||||||
|
}
|
||||||
|
|
||||||
|
// POHUY
|
||||||
|
--$slots;
|
||||||
|
}
|
||||||
|
|
||||||
// Sending the message
|
// Sending the message
|
||||||
$context->sendMessage(
|
$context->sendMessage(
|
||||||
<<<TXT
|
<<<TXT
|
||||||
$title
|
$title
|
||||||
|
|
||||||
$accounts
|
$experience
|
||||||
TXT,
|
TXT,
|
||||||
[
|
[
|
||||||
'reply_markup' => [
|
'reply_markup' => [
|
||||||
'inline_keyboard' => [
|
'inline_keyboard' => $keyboard,
|
||||||
[
|
|
||||||
[
|
|
||||||
'text' => '🐣 ' . $localization['kodorvan'],
|
|
||||||
'web_app' => [
|
|
||||||
'url' => 'https://brainrot.svoboda.works'
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'disable_notification' => true,
|
'disable_notification' => true,
|
||||||
'remove_keyboard' => true
|
'remove_keyboard' => true
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user