done
This commit is contained in:
parent
ac000c88bb
commit
821a39b681
|
@ -0,0 +1 @@
|
|||
vendor
|
|
@ -1,3 +1,3 @@
|
|||
# spetsresurs-telegram-robot-chat
|
||||
# Чат-робот
|
||||
|
||||
Чат-робот Telegram для допуска только найденных в google-excel таблице по идентификатору
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"name": "mirzaev/spetsresurs-telegram-robot-entry",
|
||||
"type": "robot",
|
||||
"license": "WTFPL",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"mirzaev\\spetsresurs\\\\telegram\\robot\\entry\\": "mirzaev/spetsresurs/telegram/robot/entry/system/"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Arsen Mirzaev Tatyano-Muradovich",
|
||||
"email": "arsen@mirzaev.sexy"
|
||||
}
|
||||
],
|
||||
"minimum-stability": "stable",
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"php-http/discovery": true
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"flow-php/etl-adapter-google-sheet": "1.x@dev",
|
||||
"triagens/arangodb": "^3.8",
|
||||
"mirzaev/arangodb": "^1.0.0",
|
||||
"badfarm/zanzara": "^0.9.1",
|
||||
"nyholm/psr7": "^1.8",
|
||||
"react/promise-timer": "^1.10",
|
||||
"react/promise": "^3.1"
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
|
||||
// Фреймворк Telegram
|
||||
use Zanzara\Zanzara;
|
||||
use Zanzara\Context;
|
||||
use Zanzara\Config;
|
||||
|
||||
// Фреймворк для Google Sheets
|
||||
use Flow\ETL\Adapter\GoogleSheet\GoogleSheetRange,
|
||||
Flow\ETL\Adapter\GoogleSheet\GoogleSheetExtractor,
|
||||
Flow\ETL\Adapter\GoogleSheet\Columns,
|
||||
Flow\ETL\Flow,
|
||||
Flow\ETL\Config as _config,
|
||||
Flow\ETL\FlowContext,
|
||||
Flow\ETL\Row\Entry,
|
||||
Flow\ETL\Row,
|
||||
Flow\ETL\DSL\To,
|
||||
Flow\ETL\DSL\From;
|
||||
|
||||
// Фреймворк для Google API
|
||||
use Google\Client,
|
||||
Google\Service\Sheets,
|
||||
Google\Service\Sheets\ValueRange;
|
||||
|
||||
|
||||
require __DIR__ . '/../../../../../../vendor/autoload.php';
|
||||
|
||||
/* ini_set('error_reporting', E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1); */
|
||||
|
||||
$config = new Config();
|
||||
$config->setParseMode(Config::PARSE_MODE_MARKDOWN);
|
||||
|
||||
$bot = new Zanzara(require(__DIR__ . '/../settings/key.php'), $config);
|
||||
|
||||
$timer;
|
||||
|
||||
$member;
|
||||
|
||||
$bot->onMessage(function (Context $ctx) {
|
||||
if ($members = $ctx->getMessage()->getNewChatMembers()) {
|
||||
// Новый аккаунт в чате
|
||||
|
||||
$ctx->sendMessage('⚠️ Введите ваш табельный номер для авторизации', ['reply_to_message_id' => $ctx->getMessage()->getMessageId()])
|
||||
->then(function () use ($ctx, $members) {
|
||||
|
||||
global $member;
|
||||
|
||||
// Инициализация идентификатора сотрудника
|
||||
$member = $id = $members[0]->getId();
|
||||
|
||||
global $timer;
|
||||
|
||||
$timer = React\Promise\Timer\sleep(30);
|
||||
|
||||
$timer->then(
|
||||
function ($value) use ($ctx, $id) {
|
||||
// Изгнание из чата
|
||||
$ctx->kickChatMember($ctx->getMessage()->getChat()->getId(), $id);
|
||||
|
||||
$ctx->wipeCache();
|
||||
|
||||
$ctx->endConversation();
|
||||
},
|
||||
function () {
|
||||
}
|
||||
);
|
||||
|
||||
$ctx->nextStep('check');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function check(Context $ctx)
|
||||
{
|
||||
global $member;
|
||||
|
||||
if ($member === $ctx->getMessage()->getFrom()->getId()) {
|
||||
// Отправителем табельного номера является тот кто подключился к серверу
|
||||
|
||||
$id = $ctx->getMessage()->getText();
|
||||
|
||||
$settings = json_decode(require(__DIR__ . '/../settings/workers/google.php'), true);
|
||||
$document = require(__DIR__ . '/../settings/workers/document.php');
|
||||
$sheets = require(__DIR__ . '/../settings/workers/sheets.php');
|
||||
|
||||
$client = new Client();
|
||||
$client->setScopes(Sheets::SPREADSHEETS);
|
||||
$client->setAuthConfig($settings);
|
||||
$api = new Sheets($client);
|
||||
|
||||
foreach ($sheets as $sheet) {
|
||||
$rows = (new Flow())->read(new GoogleSheetExtractor($api, $document, new Columns($sheet, 'A', 'A'), true, 1000));
|
||||
|
||||
foreach ($rows->fetch(10000) as $row) {
|
||||
// Перебор строк
|
||||
|
||||
if ($id === $row->toArray()['ID']) {
|
||||
$ctx->sendMessage("✅ Авторизован сотрудник: $id");
|
||||
|
||||
global $timer;
|
||||
|
||||
// Отмена блокировки
|
||||
$timer->cancel();
|
||||
|
||||
$ctx->endConversation();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$ctx->sendMessage("⛔ Не найден сотрудник: $id");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$bot->run();
|
|
@ -0,0 +1,4 @@
|
|||
*
|
||||
!*/
|
||||
!.gitignore
|
||||
!*.sample
|
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
|
||||
return '';
|
|
@ -0,0 +1,3 @@
|
|||
*
|
||||
!.gitignore
|
||||
!*.sample
|
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
|
||||
return '';
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
return <<<'JSON'
|
||||
{
|
||||
"type": "",
|
||||
"project_id": "",
|
||||
"private_key_id": "",
|
||||
"private_key": "",
|
||||
"client_email": "",
|
||||
"client_id": "",
|
||||
"auth_uri": "",
|
||||
"token_uri": "",
|
||||
"auth_provider_x509_cert_url": "",
|
||||
"client_x509_cert_url": "",
|
||||
"universe_domain": ""
|
||||
}
|
||||
JSON;
|
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'ДАННЫЕ (сотрудников)'
|
||||
];
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue