fix
This commit is contained in:
118
mirzaev/spetsresurs/telegram/robot/entry/system/public/robot.php
Normal file
118
mirzaev/spetsresurs/telegram/robot/entry/system/public/robot.php
Normal file
@@ -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(180);
|
||||
|
||||
$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();
|
4
mirzaev/spetsresurs/telegram/robot/entry/system/settings/.gitignore
vendored
Executable file
4
mirzaev/spetsresurs/telegram/robot/entry/system/settings/.gitignore
vendored
Executable file
@@ -0,0 +1,4 @@
|
||||
*
|
||||
!*/
|
||||
!.gitignore
|
||||
!*.sample
|
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
return '';
|
3
mirzaev/spetsresurs/telegram/robot/entry/system/settings/workers/.gitignore
vendored
Normal file
3
mirzaev/spetsresurs/telegram/robot/entry/system/settings/workers/.gitignore
vendored
Normal file
@@ -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 [
|
||||
'ДАННЫЕ (сотрудников)'
|
||||
];
|
Reference in New Issue
Block a user