Compare commits

..

No commits in common. "stable" and "1.2.0" have entirely different histories.

3 changed files with 29 additions and 45 deletions

View File

@ -1,5 +1,3 @@
# Telegram chat-robot for task registering
# Telegram-robot for registering for tasks
Chat-robot Telegram for accepting applications for employees from [mirzaev/ebala](https://git.mirzaev.sexy/mirzaev/ebala)
**DEVELOPMENT COMPLETED. PROJECT CLOSED.**
Synchronizes accounts with the site, displays a list of published applications with a selection by date, and also register to tasks

View File

@ -236,11 +236,10 @@ function generateMenu(Context $ctx): void
* @param int $amount Количество
* @param ?string $date За какую дату (unixtime)
* @param int $page Страница
* @param _document $worker Сотрудник
*
* @return Cursor
*/
function requests(int $amount = 5, ?string $date = null, int $page = 1, _document $worker): Cursor
function requests(int $amount = 5, ?string $date = null, int $page = 1): Cursor
{
global $arangodb;
@ -261,12 +260,11 @@ function requests(int $amount = 5, ?string $date = null, int $page = 1, _documen
[
'query' => sprintf(
// d.date < %s там специально, не менять на <=
"FOR d IN task FILTER ((d.date >= %s && d.date < %s && d.start >= '05:00') || (d.date >= %s && d.date < %s && d.start < '05:00')) && d.worker == null && d.market != null && d.confirmed != true && d.published == true && d.completed != true && (FOR m IN market FILTER m.id == d.market && IS_ARRAY(m.bans) SORT m.created DESC, m._key DESC LIMIT 1 RETURN !POSITION(m.bans, \"%s\"))[0] SORT d.created DESC, d._key DESC LIMIT %d, %d RETURN d",
"FOR d IN task FILTER ((d.date >= %s && d.date < %s && d.start >= '05:00') || (d.date >= %s && d.date < %s && d.start < '05:00')) && d.worker == null && d.market != null && d.confirmed != true && d.published == true && d.completed != true SORT d.created DESC, d._key DESC LIMIT %d, %d RETURN d",
$from = (new DateTime("@$date"))->setTime(0, 0)->format('U'),
$to = (new DateTime("@$date"))->modify('+1 day')->setTime(0, 0)->format('U'),
$to,
(new DateTime("@$date"))->modify('+2 day')->setTime(0, 0)->format('U'),
$worker->id,
$offset,
$amount + $offset - ($page > 0)
),
@ -346,10 +344,7 @@ function request_confirmed(Context $ctx): void
// Прочитана запрашиваемая заявка
// Инициализация инстанции task в базе данных (выбранного задания)
$task = collection::search($arangodb->session, sprintf("FOR d IN task FILTER d._key == '%s' && d.published == true && d.completed != true && worker == null RETURN d", $_key));
if ($task instanceof _document) {
// Найдена заявка (подразумевается, что не занята)
$task = collection::search($arangodb->session, sprintf("FOR d IN task FILTER d._key == '%s' && d.published == true && d.completed != true RETURN d", $_key));
if ($worker ??= worker($account->getId())) {
// Найден сотрудник
@ -386,9 +381,6 @@ function request_confirmed(Context $ctx): void
} else $ctx->sendMessage("❎ *Не удалось принять заявку:* \#$_key", ['reply_markup' => ['remove_keyboard' => true]])->then(function () use ($ctx) {
generateMenu($ctx);
});
} else $ctx->sendMessage("❎ *Не удалось принять заявку:* \#$_key", ['reply_markup' => ['remove_keyboard' => true]])->then(function () use ($ctx) {
generateMenu($ctx);
});
});
}
}
@ -467,7 +459,7 @@ function search(Context $ctx): void
else {
// Активен аккаунт
$ctx->getChatDataItem('requests_page')->then(function ($page) use ($ctx, $arangodb, $worker) {
$ctx->getChatDataItem('requests_page')->then(function ($page) use ($ctx, $arangodb) {
// Найдена текущая страница
// Значение страницы по умолчанию
@ -476,9 +468,9 @@ function search(Context $ctx): void
$ctx->setChatDataItem('requests_page', 1);
}
$generate = function ($date) use ($ctx, $page, $arangodb, $worker) {
$generate = function ($date) use ($ctx, $page, $arangodb) {
// Поиск заявок в ArangoDB
$tasks = requests(4, (string) $date, $page, $worker);
$tasks = requests(4, (string) $date, $page);
// Подсчёт количества прочитанных заявок из базы данных
$count = $tasks->getCount();

View File

@ -1,9 +1,6 @@
[Unit]
Description=Telegram-robot
Wants=network.target
After=syslog.target network-online.target
[Service]
ExecStart=sudo -u www-data /usr/bin/php /var/www/spetsresurs-telegram-registry-requests/mirzaev/spetsresurs/telegram/registry/requests/system/public/robot.php
PIDFile=/var/run/php/telegram-robot.pid
@ -11,6 +8,3 @@ RemainAfterExit=no
RuntimeMaxSec=3600s
Restart=always
RestartSec=5s
[Install]
WantedBy=multi-user.target