first initialization
This commit is contained in:
parent
c41a723af7
commit
bc13716fed
|
@ -1,16 +1,17 @@
|
||||||
{
|
{
|
||||||
"name": "mirzaev/spetsresurs-telegram-registry-requests",
|
"name": "mirzaev/mashtrash",
|
||||||
"type": "robot",
|
"type": "robot",
|
||||||
"require": {
|
"require": {
|
||||||
"triagens/arangodb": "^3.8",
|
"triagens/arangodb": "^3.8",
|
||||||
"mirzaev/arangodb": "^1.0",
|
"mirzaev/arangodb": "^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"
|
||||||
},
|
},
|
||||||
"license": "WTFPL",
|
"license": "WTFPL",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"mirzaev\\spetsresurs\\telegram\\registry\\requests\\": "mirzaev/spetsresurs/telegram/registry/requests/system/"
|
"mirzaev\\mashtrash\\": "mirzaev/mashtrash/system/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"authors": [
|
"authors": [
|
||||||
|
@ -22,7 +23,8 @@
|
||||||
"minimum-stability": "stable",
|
"minimum-stability": "stable",
|
||||||
"config": {
|
"config": {
|
||||||
"allow-plugins": {
|
"allow-plugins": {
|
||||||
"php-http/discovery": true
|
"php-http/discovery": true,
|
||||||
|
"wyrihaximus/composer-update-bin-autoload-path": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,388 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Фреймворк ArangoDB
|
||||||
|
use mirzaev\arangodb\connection,
|
||||||
|
mirzaev\arangodb\collection,
|
||||||
|
mirzaev\arangodb\document;
|
||||||
|
|
||||||
|
// Библиотека для ArangoDB
|
||||||
|
use ArangoDBClient\Document as _document,
|
||||||
|
ArangoDBClient\Cursor,
|
||||||
|
ArangoDBClient\Statement as _statement;
|
||||||
|
|
||||||
|
// Фреймворк Telegram
|
||||||
|
use Zanzara\Zanzara,
|
||||||
|
Zanzara\Context,
|
||||||
|
Zanzara\Config,
|
||||||
|
Zanzara\Middleware\MiddlewareNode as Node;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../../../vendor/autoload.php';
|
||||||
|
|
||||||
|
$arangodb = new connection(require __DIR__ . '/../settings/arangodb.php');
|
||||||
|
|
||||||
|
ini_set('error_reporting', E_ALL);
|
||||||
|
ini_set('display_errors', 1);
|
||||||
|
ini_set('display_startup_errors', 1);
|
||||||
|
|
||||||
|
// Версия робота
|
||||||
|
define('VERSION', '1.0.0');
|
||||||
|
|
||||||
|
function unmarkdown(string $text, array $exceptions = []): string
|
||||||
|
{
|
||||||
|
// Инициализация реестра символом для конвертации
|
||||||
|
$from = array_diff(
|
||||||
|
[
|
||||||
|
'#',
|
||||||
|
'*',
|
||||||
|
'_',
|
||||||
|
'=',
|
||||||
|
'.',
|
||||||
|
'[',
|
||||||
|
']',
|
||||||
|
'(',
|
||||||
|
')',
|
||||||
|
'-',
|
||||||
|
'>',
|
||||||
|
'<',
|
||||||
|
'!',
|
||||||
|
'`'
|
||||||
|
],
|
||||||
|
$exceptions
|
||||||
|
);
|
||||||
|
|
||||||
|
// Инициализация реестра целей для конвертации
|
||||||
|
$to = [];
|
||||||
|
foreach ($from as $symbol) $to[] = "\\$symbol";
|
||||||
|
|
||||||
|
// Конвертация и выход (успех)
|
||||||
|
return str_replace($from, $to, $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
function phrase(): string
|
||||||
|
{
|
||||||
|
// Инициализация фраз
|
||||||
|
$phrases = [
|
||||||
|
'son became wife',
|
||||||
|
'daughter became husband',
|
||||||
|
'i am a crispy chip',
|
||||||
|
'you will never have a boyfriend',
|
||||||
|
'you will never have a girlfriend',
|
||||||
|
'i can write here whatever i want',
|
||||||
|
'if you can not get a girlfriend, be someone else`s girlfriend',
|
||||||
|
'if you can not get a boyfriend, be someone else`s boyfriend',
|
||||||
|
'yeah',
|
||||||
|
'Mareux - The Perfect Girl (The Motion Retrowave Remix, slowed + reverb)',
|
||||||
|
'please do not read this anymore',
|
||||||
|
'my profiles were not approved by anyone, so i created my own robot and approved it myself 😎',
|
||||||
|
'🥸',
|
||||||
|
'psst psst psst psst',
|
||||||
|
'nihao ochinchin gomenasaaai!!!!! 💞',
|
||||||
|
'black are no 🫵',
|
||||||
|
'why are you gay',
|
||||||
|
'я знаю чем ты здесь занимаешься',
|
||||||
|
'🤡',
|
||||||
|
'⚰️',
|
||||||
|
'⛔ *You are banned*',
|
||||||
|
'bruh',
|
||||||
|
'Egor Rodin',
|
||||||
|
'maybe you are the problem?',
|
||||||
|
'after winter',
|
||||||
|
'gay sex',
|
||||||
|
'porno mama',
|
||||||
|
'Maybe i should add the dilf category?',
|
||||||
|
'One day a cool girl from my city offered me to do ASMR for me in real life, but i refused and regret it all my life 😭',
|
||||||
|
'GET OUT',
|
||||||
|
'amongus',
|
||||||
|
'skibidi fortnite',
|
||||||
|
'Your profile will remain here even after your death ⌛',
|
||||||
|
'fun fact i sold your data to the government',
|
||||||
|
'maybe i should create a chat generator and invite there those who match each other according to our algorithms here? what do you think?',
|
||||||
|
'i masturbate while looking at your profiles',
|
||||||
|
'hi mom',
|
||||||
|
'just admit that you will be alone for the rest of your miserable life',
|
||||||
|
'do you think you are safe?',
|
||||||
|
'do you think i can not do anything to you?',
|
||||||
|
'Welcome back! 🎉',
|
||||||
|
'Maybe you are overestimating the importance of relationships in your life and you just need to find yourself a job?',
|
||||||
|
'bebra',
|
||||||
|
'бебра',
|
||||||
|
'FUN FACT I DID NOT UNDERSTAND YOUR SLANG',
|
||||||
|
'If you write your profile badly, i will shadow ban you',
|
||||||
|
'touch the grass',
|
||||||
|
'Please forgive me for these inscriptions. I really need to assert myself somewhere.',
|
||||||
|
'Real women always have a penis 💪',
|
||||||
|
'I sold your phone number to debt collectors',
|
||||||
|
'you will not even be able to install Gentoo 🤓',
|
||||||
|
'Maybe i should create a tab for 18+ photos in profiles?',
|
||||||
|
'YOU CAN NOT STOP ME',
|
||||||
|
'YOU WILL NEVER CATCH ME',
|
||||||
|
'One day my friend jerked off 11 times in a row and because of it he could not go to school',
|
||||||
|
'gay cat',
|
||||||
|
'fuck please i just want a girlfriend. please',
|
||||||
|
'brawl stars datings',
|
||||||
|
'why do people in the west play roblox?',
|
||||||
|
'just not whatsapp',
|
||||||
|
'kissing in the forest',
|
||||||
|
'KISSING IN THE FOREST',
|
||||||
|
'✨ KISSING IN THE FOREST ✨',
|
||||||
|
'🌲✨ KISSING IN THE FOREST ✨🌲🌲',
|
||||||
|
'🌲🌲✨ KISSING IN THE FOREST ✨🌲🌲🌲🐻🌲',
|
||||||
|
'амонгус',
|
||||||
|
'Maybe i should sell psychotherapist ads here?',
|
||||||
|
'boobs or butt and hips and or belly or',
|
||||||
|
'i have three cats: Dio, Jonathan and Soupchik. they are really funny.',
|
||||||
|
'Maybe i should create a minecraft server with private worlds for those who match each other according to our algorithms here? what do you think?',
|
||||||
|
'The Lord of the Rings',
|
||||||
|
'My ex-girlfriend lied to me about her age. She was 14 💀',
|
||||||
|
'I did not understand why there was no word for a female friend in English. That is why i once said i had an 11-year-old girlfriend. At that moment, no one laughed, everyone was silent.',
|
||||||
|
'fun fuckt i created first version of this robot in a one day and even sold simplified copy to someone',
|
||||||
|
'just masturbate already',
|
||||||
|
'rip GWENT i fucking loved you',
|
||||||
|
'free primogems',
|
||||||
|
'[overwatch porn](https://rt.pornhub.com/video/search?search=overwatch+porn)'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Выход и возврат случайной фразы (успех)
|
||||||
|
return unmarkdown($phrases[rand(0, count($phrases) - 1)], ['*', '(', ')', '[', ']']);
|
||||||
|
}
|
||||||
|
|
||||||
|
function journal (string $_id, string $action = 'update', array $data = [], bool $initialization = true): bool {
|
||||||
|
global $arangodb;
|
||||||
|
|
||||||
|
if (collection::init($arangodb->session, 'account')) {
|
||||||
|
if (collection::init($arangodb->session, 'journal')) {
|
||||||
|
if (collection::init($arangodb->session, 'connect', true)) {
|
||||||
|
if (collection::init($arangodb->session, 'entry', true)) {
|
||||||
|
if ($journal = collection::search($arangodb->session, sprintf("", $_id))) {
|
||||||
|
// Найден журнал
|
||||||
|
} else if ($initialization) {
|
||||||
|
// Не найден журнал и запрошена его инициализация
|
||||||
|
|
||||||
|
// Создание записи в журнале
|
||||||
|
$journal = document::write($arangodb->session, 'journal', ['action' => $action, 'data' => $data]);
|
||||||
|
|
||||||
|
// Создание записи о подключении журнала к аккаунту
|
||||||
|
$connect = document::write($arangodb->session, 'connect' ['_from' => $_id, '_to' => $journal]);
|
||||||
|
|
||||||
|
// Запись в журнал (без инициализации)
|
||||||
|
return journal($_id, $action, $data, false);
|
||||||
|
} else {
|
||||||
|
// Не найден журнал и не запрошена его инициализация
|
||||||
|
|
||||||
|
// Выход (провал)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else throw new exception('Не удалось инициализировать коллекцию: entry');
|
||||||
|
} else throw new exception('Не удалось инициализировать коллекцию: connect');
|
||||||
|
} else throw new exception('Не удалось инициализировать коллекцию: journal');
|
||||||
|
} else throw new exception('Не удалось инициализировать коллекцию: account');
|
||||||
|
|
||||||
|
// Выход (провал)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function message (string $_id, Message $message): bool {
|
||||||
|
global $arangodb;
|
||||||
|
|
||||||
|
if (collection::init($arangodb->session, 'account')) {
|
||||||
|
if (collection::init($arangodb->session, 'chat')) {
|
||||||
|
if (collection::init($arangodb->session, 'message', true)) {
|
||||||
|
|
||||||
|
} else throw new exception('Не удалось инициализировать коллекцию: message ');
|
||||||
|
} else throw new exception('Не удалось инициализировать коллекцию: chat');
|
||||||
|
} else throw new exception('Не удалось инициализировать коллекцию: account');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Авторизация
|
||||||
|
*
|
||||||
|
* @param string $id Идентификатор Telegram
|
||||||
|
* @param bool $registration Регистрация, если аккаунт не найден
|
||||||
|
*
|
||||||
|
* @return _document|null Инстанция аккаунта, если найден
|
||||||
|
*/
|
||||||
|
function authorization(string $id, bool $registration = true): _document|null
|
||||||
|
{
|
||||||
|
global $arangodb;
|
||||||
|
|
||||||
|
if (collection::init($arangodb->session, 'account')) {
|
||||||
|
if ($account = collection::search($arangodb->session, sprintf("FOR d IN account FILTER d.id == '%s' RETURN d", $id))) {
|
||||||
|
// Найден аккаунт
|
||||||
|
|
||||||
|
// Возврат (успех)
|
||||||
|
return $account;
|
||||||
|
} else if ($registration) {
|
||||||
|
// Не найден аккаунт и запрошена его регистрация
|
||||||
|
|
||||||
|
// Создание аккаунта
|
||||||
|
document::write($arangodb->session, 'account', ['id' => $id, 'banned' => false, 'version' => VERSION]);
|
||||||
|
|
||||||
|
// Авторизация (без регистрации)
|
||||||
|
return authorization($id, false);
|
||||||
|
} else {
|
||||||
|
// Не найден аккаунт и не запрошена его регистрация
|
||||||
|
|
||||||
|
// Выход (провал)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else throw new exception('Не удалось инициализировать коллекцию: account');
|
||||||
|
|
||||||
|
// Выход (провал)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Главное меню
|
||||||
|
*
|
||||||
|
* Команда: /start
|
||||||
|
*
|
||||||
|
* @param Context $ctx
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function menu(Context $ctx): void
|
||||||
|
{
|
||||||
|
// Инициализация аккаунта
|
||||||
|
$account = $ctx->get('account');
|
||||||
|
|
||||||
|
if (empty($account->profile)) {
|
||||||
|
// Не инициализирован профиль акканта
|
||||||
|
|
||||||
|
$ctx->sendMessage(phrase(), [
|
||||||
|
'reply_markup' => [
|
||||||
|
'inline_keyboard' => [
|
||||||
|
[
|
||||||
|
['text' => '🔍 Search', 'callback_data' => 'search']
|
||||||
|
],
|
||||||
|
[
|
||||||
|
['text' => '👽 Create a profile', 'callback_data' => 'profile'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
['text' => '🙈 Anonymous mode', 'callback_data' => 'mode'],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'remove_keyboard' => true
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
// Инициализирован профиль аккаунта
|
||||||
|
|
||||||
|
// Инициализация переменных с данными аккаунта
|
||||||
|
$views = $matches = $invites = 0;
|
||||||
|
|
||||||
|
$ctx->sendMessage(<<<TXT
|
||||||
|
*Views:* $views
|
||||||
|
|
||||||
|
${phrase()}
|
||||||
|
TXT, [
|
||||||
|
'reply_markup' => [
|
||||||
|
'inline_keyboard' => [
|
||||||
|
[
|
||||||
|
['text' => '🔍 Search', 'callback_data' => 'search']
|
||||||
|
],
|
||||||
|
[
|
||||||
|
['text' => "❤️ Matches: $matches", 'callback_data' => 'matches'],
|
||||||
|
['text' => "💬 Invites: $invites", 'callback_data' => 'invites']
|
||||||
|
],
|
||||||
|
[
|
||||||
|
['text' => '👽 Profile', 'callback_data' => 'profile'],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
['text' => $account->anonymous ? '🙈 Anonymous mode' : '🐵 Public mode', 'callback_data' => 'mode'],
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'remove_keyboard' => true
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Репозиторий
|
||||||
|
*
|
||||||
|
* Команда: /repository
|
||||||
|
*
|
||||||
|
* @param Context $ctx
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function repository(Context $ctx): void
|
||||||
|
{
|
||||||
|
$ctx->sendMessage(<<<TXT
|
||||||
|
MashTrash is written in [PHP](https://www.php.net/) using [Zanzara](https://github.com/badfarm/zanzara) framework\.
|
||||||
|
You can take part in the development, or freely use my code\!
|
||||||
|
|
||||||
|
The code is under the [WTFPL](https://en.wikipedia.org/wiki/WTFPL) license 🪽
|
||||||
|
TXT, [
|
||||||
|
'reply_markup' => [
|
||||||
|
'inline_keyboard' => [
|
||||||
|
[
|
||||||
|
['text' => '🏛️ The code', 'url' => 'https://git.mirzaev.sexy/mirzaev/mashtrash']
|
||||||
|
],
|
||||||
|
[
|
||||||
|
['text' => '⚠️ Issues', 'url' => 'https://git.mirzaev.sexy/mirzaev/mashtrash/issues'],
|
||||||
|
['text' => '🌱 Suggestions', 'url' => 'https://git.mirzaev.sexy/mirzaev/mashtrash/issues']
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'remove_keyboard' => true
|
||||||
|
],
|
||||||
|
'link_preview_options' => [
|
||||||
|
'is_disabled' => true
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$config = new Config();
|
||||||
|
$config->setParseMode(Config::PARSE_MODE_MARKDOWN);
|
||||||
|
|
||||||
|
$bot = new Zanzara(require(__DIR__ . '/../settings/key.php'), $config);
|
||||||
|
|
||||||
|
$account = function(Context $ctx, Node $next) {
|
||||||
|
// Выполнение заблокировано?
|
||||||
|
if ($ctx->get('stop')) return;
|
||||||
|
|
||||||
|
// Авторизация аккаунта
|
||||||
|
$account = authorization($ctx->getEffectiveUser()->getId());
|
||||||
|
|
||||||
|
if ($account instanceof _document) {
|
||||||
|
// Инициализирован аккаунт (подразумевается)
|
||||||
|
|
||||||
|
if ($account->banned) {
|
||||||
|
// Заблокирован аккаунт
|
||||||
|
|
||||||
|
// Отправка сообщения
|
||||||
|
$ctx->sendMessage('⛔ *You are banned*');
|
||||||
|
|
||||||
|
// Завершение диалога
|
||||||
|
$ctx->endConversation();
|
||||||
|
|
||||||
|
// Блокировка дальнейшего выполнения
|
||||||
|
$ctx->set('stop', true);
|
||||||
|
} else {
|
||||||
|
// Не заблокирован аккаунт
|
||||||
|
|
||||||
|
// Запись в буфер
|
||||||
|
$ctx->set('account', $account);
|
||||||
|
|
||||||
|
// Продолжение выполнения
|
||||||
|
$next($ctx);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Не инициализирован аккаунт
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$bot->onCommand('start', function (Context $ctx): void {
|
||||||
|
// Главное меню
|
||||||
|
menu($ctx);
|
||||||
|
});
|
||||||
|
|
||||||
|
$bot->onUpdate(function (Context $ctx): void {});
|
||||||
|
|
||||||
|
|
||||||
|
$bot->onCommand('repository', fn ($ctx) => repository($ctx));
|
||||||
|
$bot->onCommand('author', fn ($ctx) => author($ctx));
|
||||||
|
|
||||||
|
$bot->middleware($account)->run();
|
|
@ -15,13 +15,13 @@ use Zanzara\Zanzara;
|
||||||
use Zanzara\Context;
|
use Zanzara\Context;
|
||||||
use Zanzara\Config;
|
use Zanzara\Config;
|
||||||
|
|
||||||
require __DIR__ . '/../../../../../../../vendor/autoload.php';
|
require __DIR__ . '/../../../../vendor/autoload.php';
|
||||||
|
|
||||||
$arangodb = new connection(require __DIR__ . '/../settings/arangodb.php');
|
$arangodb = new connection(require __DIR__ . '/../settings/arangodb.php');
|
||||||
|
|
||||||
/* ini_set('error_reporting', E_ALL);
|
ini_set('error_reporting', E_ALL);
|
||||||
ini_set('display_errors', 1);
|
ini_set('display_errors', 1);
|
||||||
ini_set('display_startup_errors', 1); */
|
ini_set('display_startup_errors', 1);
|
||||||
|
|
||||||
function escape(string $text)
|
function escape(string $text)
|
||||||
{
|
{
|
Loading…
Reference in New Issue