2 Commits
1.0.1 ... 1.2.0

Author SHA1 Message Date
56528707ee do not know what is there 2025-12-04 12:43:10 +03:00
351bec9ffc delete some commands 2025-10-26 16:06:13 +03:00
7 changed files with 280 additions and 160 deletions

View File

@@ -33,7 +33,8 @@
"svoboda/time": "^1.0",
"badfarm/zanzara": "^0.9.1",
"nyholm/psr7": "^1.8",
"react/filesystem": "^0.1.2"
"react/filesystem": "^0.1.2",
"mirzaev/record": "^2.0"
},
"autoload": {
"psr-4": {

View File

@@ -13,6 +13,7 @@ return [
// Main menu
'menu_title' => 'Main menu',
'menu_accounts' => 'Accounts',
'menu_accounts_experience' => 'Experience',
// Account
'account_title' => 'Account',

View File

@@ -13,6 +13,7 @@ return [
// Main menu
'menu_title' => 'Главное меню',
'menu_accounts' => 'Аккаунты',
'menu_accounts_experience' => 'Опыт',
// Аккаунт
'account_title' => 'Аккаунт',

View File

@@ -5,7 +5,12 @@ declare(strict_types=1);
namespace kodorvan\brainrot\models;
// 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
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
* @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
*
@@ -51,9 +57,11 @@ final class account extends core
/**
* Constructor
*
* @method record|null $record The record
*
* @return void
*/
public function __construct()
public function __construct(?record $record = null)
{
// Initializing the database
$this->database = new database()
@@ -66,14 +74,15 @@ final class account extends core
new column('name_second', type::string, ['length' => 64]),
new column('language', type::string, ['length' => 2]),
new column('robot', type::char),
new column('authorized_system', type::char),
new column('authorized_settings', type::char),
new column('authorized_system_accounts', type::char),
new column('authorized_system_settings', type::char),
new column('experience', type::long_long_unsigned),
new column('slots', type::integer_unsigned),
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;
}
/**
@@ -98,16 +107,16 @@ final class account extends core
// Found the account record
if (
$account->name_first !== $telegram->getFirstName() ||
$account->name_second !== $telegram->getLastName() ||
$account->domain !== $telegram->getUsername()
$account->name_first !== $telegram->getFirstName() ||
$account->name_second !== $telegram->getLastName() ||
$account->domain !== $telegram->getUsername()
) {
// The telegram account was updated
// Updating the account in the database
$updated = $this->database->read(
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
$record->name_first = $telegram->getFirstName();
$record->name_second = $telegram->getLastName();
@@ -167,11 +176,16 @@ final class account extends core
* Creates the account record in the database
*
* @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
*/
public function registrate(telegram $telegram): int|false
{
public function registrate(
telegram $telegram,
int $experience = 0,
int $slots = 1
): int|false {
// Initializing the identifier
$identifier = $this->database->count() + 1;
@@ -184,10 +198,8 @@ final class account extends core
(string) $telegram->getUsername(),
(string) $telegram->getLanguageCode(),
(int) $telegram->isBot(),
1,
1,
0,
0,
$experience,
$slots,
svoboda::timestamp(),
svoboda::timestamp()
);
@@ -198,4 +210,33 @@ final class account extends core
// Exit (success)
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;
}
}

View 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;
}
}

View File

@@ -32,10 +32,25 @@ use Zanzara\Context as context,
*/
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
*
* Responce for the commands: "/start", '/menu'
* Responce for the commands: '/menu'
*
* @param context $context Request data from Telegram
*
@@ -55,32 +70,83 @@ final class commands extends core
if ($localization) {
// Initialized localization
// Initializing the title
// Initializing the title message text
$title = '📋 *' . $localization['menu_title'] . '*';
// Initializing accounts
$accounts = '*' . $localization['menu_accounts'] . ':* ' . ((new account)->database->count() ?? 0);
// Initializing the accounts message text
/* $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
$context->sendMessage(
<<<TXT
$title
$accounts
$experience
TXT,
[
'reply_markup' => [
'inline_keyboard' => [
[
[
'text' => '🐣 ' . $localization['kodorvan'],
'web_app' => [
'url' => 'https://brainrot.svoboda.works'
]
]
]
],
'inline_keyboard' => $keyboard,
'disable_notification' => true,
'remove_keyboard' => true
],
@@ -160,27 +226,12 @@ final class commands extends core
// Trimming the last line break character
$authorizations = trim($authorizations, "\n");
// Initializing the data export for the message
$export = '📤 ' . $localization['account_export'];
// Initializing the data security for the message
$data = $localization['account_data'];
// Initializing the data security repository for the message
$security = '📁 [' . $localization['account_security_repository'] . '](https://git.svoboda.works/mirzaev/security) \([' . $localization['account_security_repository_mirror_github'] . '](https://github.com/mature-woman/security)\)';
// Sending the message
$context->sendMessage(
<<<TXT
$title
$authorizations
$export
$data
$security
TXT,
[
'reply_markup' => [
@@ -325,123 +376,17 @@ final class commands extends core
[
[
'text' => '🏛️ ' . $localization['repository_button_code'],
'url' => 'https://git.mirzaev.sexy/kodorvan/brainrot'
'url' => 'https://git.svoboda.works/kodorvan/brainrot'
]
],
[
[
'text' => '⚠️ ' . $localization['repository_button_issues'],
'url' => 'https://git.mirzaev.sexy/kodorvan/brainrot/issues'
'url' => 'https://git.svoboda.works/kodorvan/brainrot/issues'
],
[
'text' => '🌱 ' . $localization['repository_button_suggestions'],
'url' => 'https://git.mirzaev.sexy/kodorvan/brainrot/issues'
]
]
],
'remove_keyboard' => true,
'disable_notification' => true
],
'link_preview_options' => [
'is_disabled' => 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();
});
}
}
/**
* Author
*
* Responce for the command: "/author"
*
* Sends
*
* @param context $context Request data from Telegram
*
* @return void
*/
public static function author(context $context): void
{
// Initializing the account
$account = $context->get('account');
if ($account instanceof record) {
// Initialized the account
// Initializing localization
$localization = $context->get('localization');
if ($localization) {
// Initialized localization
// Initializing title of the message
$title = '👽 ' . $localization['author_title'];
// Sending the message
$context->sendMessage($title . "\n\n" . $localization['author_text'], [
'reply_markup' => [
'inline_keyboard' => [
[
[
'text' => '📚 ' . $localization['author_button_neurojournal'],
'url' => 'https://mirzaev.sexy'
],
[
'text' => '🤟 ' . $localization['author_button_projects'],
'url' => 'https://git.svoboda.works/mirzaev?tab=activity'
]
],
[
[
'text' => '📣 ' . $localization['author_button_telegram'],
'url' => 'https://t.me/blog_mirzaev_sexy'
],
[
'text' => '✖️ ' . $localization['author_button_twitter'],
'url' => 'https://x.com/mirzaev_sexy'
],
[
'text' => '🦋 ' . $localization['author_button_bluesky'],
'url' => 'https://bsky.app/profile/mirzaev.bsky.social'
],
[
'text' => '⛓️ ' . $localization['author_button_bastyon'],
'url' => 'https://bsky.app/profile/mirzaev.bsky.social'
]
],
[
[
'text' => '🇺🇸 ' . $localization['author_button_youtube_english'],
'url' => 'https://www.youtube.com/@MIRZAEV'
],
[
'text' => '🇷🇺 ' . $localization['author_button_youtube_russian'],
'url' => 'https://www.youtube.com/@MIRZAEV'
]
],
[
[
'text' => '✉️ ' . $localization['author_button_message'],
'url' => 'https://t.me/mirzaev_sexy'
'url' => 'https://git.svoboda.works/kodorvan/brainrot/issues'
]
]
],

View File

@@ -85,8 +85,6 @@ $robot->onCommand('menu', [commands::class, 'menu']);
$robot->onCommand('account', [commands::class, 'account']);
$robot->onCommand('language', [commands::class, 'language'])->middleware([middlewares::class, 'settings']);
$robot->onCommand('repository', [commands::class, 'repository']);
/* $robot->onCommand('projects', [commands::class, 'projects']); */
$robot->onCommand('author', [commands::class, 'author']);
$robot->onCommand('society', [commands::class, 'society']);
/* $robot->onCommand('system_settings', [commands::class, 'system_settings'])->middleware([middlewares::class, 'system_settings']); */