Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
15f4979cf7 | |||
![]() |
c7fe3623e7 |
@@ -11,7 +11,7 @@
|
|||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Arsen Mirzaev Tatyano-Muradovich",
|
"name": "Arsen Mirzaev Tatyano-Muradovich",
|
||||||
"email": "red@hood.su",
|
"email": "arsen@mirzaev.sexy",
|
||||||
"homepage": "https://hood.su/mirzaev",
|
"homepage": "https://hood.su/mirzaev",
|
||||||
"role": "Programmer"
|
"role": "Programmer"
|
||||||
}
|
}
|
||||||
@@ -21,12 +21,12 @@
|
|||||||
"issues": "https://git.hood.su/mirzaev/vk/issues"
|
"issues": "https://git.hood.su/mirzaev/vk/issues"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": "~8.0",
|
"php": "~8.1",
|
||||||
"psr/log": "~1.0",
|
"psr/log": "~1.0",
|
||||||
"mirzaev/accounts": "~0.1.x-dev",
|
"mirzaev/accounts": "~1.2.x-dev",
|
||||||
"monolog/monolog": "~1.6",
|
"monolog/monolog": "~1.6",
|
||||||
"jasny/error-handler": "~0.2",
|
"jasny/error-handler": "~0.2",
|
||||||
"guzzlehttp/guzzle": "~7.2"
|
"guzzlehttp/guzzle": "~7.4.5"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "~9.5"
|
"phpunit/phpunit": "~9.5"
|
||||||
|
618
composer.lock
generated
618
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
// declare(strict_types=1);
|
// declare(strict_types=1);
|
||||||
|
|
||||||
// namespace Hood\VK\API;
|
// namespace mirzaev\vk\API;
|
||||||
|
|
||||||
// class CallBack extends CallBackAbstract
|
// class CallBack extends CallBackAbstract
|
||||||
// {
|
// {
|
||||||
|
@@ -7,7 +7,8 @@ namespace mirzaev\vk\api;
|
|||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
use mirzaev\vk\core,
|
use mirzaev\vk\core,
|
||||||
mirzaev\vk\robots\robot;
|
mirzaev\vk\robots\robot,
|
||||||
|
mirzaev\vk\robots\group;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LongPoll
|
* LongPoll
|
||||||
@@ -25,7 +26,7 @@ use mirzaev\vk\core,
|
|||||||
* @see https://vk.com/dev/groups.setLongPollSettings
|
* @see https://vk.com/dev/groups.setLongPollSettings
|
||||||
*
|
*
|
||||||
* @package mirzaev\vk\api
|
* @package mirzaev\vk\api
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <red@hood.su>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
*
|
*
|
||||||
* @todo Добавить обработку ошибок ($request['errors];)
|
* @todo Добавить обработку ошибок ($request['errors];)
|
||||||
*/
|
*/
|
||||||
@@ -36,14 +37,14 @@ final class longpoll
|
|||||||
*
|
*
|
||||||
* @see $this->get()
|
* @see $this->get()
|
||||||
*/
|
*/
|
||||||
private string $key;
|
private readonly string $key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Сервер (URL)
|
* Сервер (URL)
|
||||||
*
|
*
|
||||||
* @see $this->get()
|
* @see $this->get()
|
||||||
*/
|
*/
|
||||||
private string $server;
|
private readonly string $server;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Идентификатор последнего события
|
* Идентификатор последнего события
|
||||||
@@ -59,7 +60,7 @@ final class longpoll
|
|||||||
*
|
*
|
||||||
* $robot Робот
|
* $robot Робот
|
||||||
*/
|
*/
|
||||||
public function __construct(private robot $robot)
|
public function __construct(private robot&group $robot)
|
||||||
{
|
{
|
||||||
// Инициализация
|
// Инициализация
|
||||||
if (empty($robot->id)) throw new Exception('Необходимо указать идентификатор ВКонтакте');
|
if (empty($robot->id)) throw new Exception('Необходимо указать идентификатор ВКонтакте');
|
||||||
|
@@ -11,6 +11,18 @@ use mirzaev\vk\robots\robot;
|
|||||||
use mirzaev\vk\api\data;
|
use mirzaev\vk\api\data;
|
||||||
use mirzaev\vk\robots\group;
|
use mirzaev\vk\robots\group;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Режимы отправки сообщений
|
||||||
|
*/
|
||||||
|
enum mode
|
||||||
|
{
|
||||||
|
/** Быстро - случайный идентификатор (умножение на rand()) */
|
||||||
|
case random;
|
||||||
|
|
||||||
|
/** Надёжно - проверка отправки (поиск сообщения через messages.getById) */
|
||||||
|
case search;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Сообщение
|
* Сообщение
|
||||||
*
|
*
|
||||||
@@ -20,16 +32,16 @@ use mirzaev\vk\robots\group;
|
|||||||
* @see https://vk.com/dev/messages.getById
|
* @see https://vk.com/dev/messages.getById
|
||||||
*
|
*
|
||||||
* @package mirzaev\vk\api
|
* @package mirzaev\vk\api
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <red@hood.su>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
*
|
*
|
||||||
* @todo Доработать строгий режим отправки: проверку сообщения в беседе (не имеет ID сообщений)
|
* @todo Доработать строгий режим отправки: проверку сообщения в беседе (не имеет ID сообщений)
|
||||||
*/
|
*/
|
||||||
final class messages extends method
|
final class messages extends method
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var int $mode Режим отправки
|
* @var mode $mode Режим отправки сообщений
|
||||||
*/
|
*/
|
||||||
protected int $mode = 1;
|
protected mode $mode = mode::random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array[int] Сообщения для пересылки
|
* @var array[int] Сообщения для пересылки
|
||||||
@@ -119,8 +131,9 @@ final class messages extends method
|
|||||||
// Идентификатор
|
// Идентификатор
|
||||||
$random_id = time();
|
$random_id = time();
|
||||||
|
|
||||||
if ($this->mode = 1) {
|
if ($this->mode === mode::random) {
|
||||||
// Перемножение (по умолчанию)
|
// Быстрая отправка сообщения
|
||||||
|
|
||||||
$random_id *= rand();
|
$random_id *= rand();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +143,7 @@ final class messages extends method
|
|||||||
// Цель отправки
|
// Цель отправки
|
||||||
$this->robot->api->destination($destination);
|
$this->robot->api->destination($destination);
|
||||||
|
|
||||||
// Инициализация идентификатора (защита от повторных отправок) в настройках API
|
// Инициализация идентификатора сообщения (защита от повторных отправок) в настройках API
|
||||||
$this->robot->api['random_id'] = $random_id;
|
$this->robot->api['random_id'] = $random_id;
|
||||||
|
|
||||||
// Инициализация текста в настройках API
|
// Инициализация текста в настройках API
|
||||||
@@ -165,8 +178,8 @@ final class messages extends method
|
|||||||
throw new Exception('Вконтакте: ' . $request->error->error_msg, $request->error->error_code);
|
throw new Exception('Вконтакте: ' . $request->error->error_msg, $request->error->error_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->mode >= 2) {
|
if ($this->mode === mode::search) {
|
||||||
// Если установлен режим 2 (усиленная проверка отправленного сообщения)
|
// Надёжная доставка сообщения
|
||||||
|
|
||||||
if (!empty($request["response"])) {
|
if (!empty($request["response"])) {
|
||||||
// Ответ получен
|
// Ответ получен
|
||||||
@@ -177,7 +190,6 @@ final class messages extends method
|
|||||||
// Запрашиваемые сообщения
|
// Запрашиваемые сообщения
|
||||||
$this->robot->api['message_ids'] = $request["response"];
|
$this->robot->api['message_ids'] = $request["response"];
|
||||||
|
|
||||||
// Запрос
|
|
||||||
if ($this->robot->browser->request('POST', 'messages.getById', ['form_params' => $this->robot->api->settings])['response']['count'] === 0) {
|
if ($this->robot->browser->request('POST', 'messages.getById', ['form_params' => $this->robot->api->settings])['response']['count'] === 0) {
|
||||||
// Сообщения не существует
|
// Сообщения не существует
|
||||||
//!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
//!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
@@ -15,7 +15,7 @@ use mirzaev\vk\robots\robot;
|
|||||||
* @method protected static delete(string $url, ...$params) Удалить
|
* @method protected static delete(string $url, ...$params) Удалить
|
||||||
*
|
*
|
||||||
* @package mirzaev\vk\api\methods
|
* @package mirzaev\vk\api\methods
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <red@hood.su>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
*/
|
*/
|
||||||
abstract class method
|
abstract class method
|
||||||
{
|
{
|
||||||
|
@@ -20,7 +20,7 @@ use mirzaev\accounts\vk as account;
|
|||||||
* @see https://vk.com/dev/messages.getById
|
* @see https://vk.com/dev/messages.getById
|
||||||
*
|
*
|
||||||
* @package mirzaev\vk\api\methods
|
* @package mirzaev\vk\api\methods
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <red@hood.su>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
*
|
*
|
||||||
* @todo Добавить обработку ошибок ($request['errors];)
|
* @todo Добавить обработку ошибок ($request['errors];)
|
||||||
*/
|
*/
|
||||||
|
@@ -21,7 +21,7 @@ use mirzaev\vk\robots\robot;
|
|||||||
* 1. Создать __isset(), __unset()
|
* 1. Создать __isset(), __unset()
|
||||||
*
|
*
|
||||||
* @package mirzaev\vk\api
|
* @package mirzaev\vk\api
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <red@hood.su>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
*/
|
*/
|
||||||
class settings implements ArrayAccess
|
class settings implements ArrayAccess
|
||||||
{
|
{
|
||||||
|
@@ -24,7 +24,7 @@ use exception;
|
|||||||
* @method public function get($id = null) Чтение из реестра
|
* @method public function get($id = null) Чтение из реестра
|
||||||
*
|
*
|
||||||
* @package mirzaev\vk
|
* @package mirzaev\vk
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <red@hood.su>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
*/
|
*/
|
||||||
final class core
|
final class core
|
||||||
{
|
{
|
||||||
@@ -45,22 +45,22 @@ final class core
|
|||||||
*
|
*
|
||||||
* Используется в логировании
|
* Используется в логировании
|
||||||
*/
|
*/
|
||||||
private string $timezone;
|
private readonly string $timezone;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Путь до корня проекта
|
* Путь до корня проекта
|
||||||
*/
|
*/
|
||||||
private string $path_root;
|
private readonly string $path_root;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Путь до папки журналов
|
* Путь до папки журналов
|
||||||
*/
|
*/
|
||||||
private string $path_logs;
|
private readonly string $path_logs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Путь до временной папки
|
* Путь до временной папки
|
||||||
*/
|
*/
|
||||||
private string $path_temp;
|
private readonly string $path_temp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Запись в журнал
|
* Запись в журнал
|
||||||
|
@@ -21,7 +21,7 @@ use mirzaev\vk\core,
|
|||||||
* @see Jasny\ErrorHandler
|
* @see Jasny\ErrorHandler
|
||||||
*
|
*
|
||||||
* @package mirzaev\vk\loggers
|
* @package mirzaev\vk\loggers
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <red@hood.su>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
*/
|
*/
|
||||||
final class jasmo extends logger
|
final class jasmo extends logger
|
||||||
{
|
{
|
||||||
|
@@ -8,7 +8,7 @@ namespace mirzaev\vk\loggers;
|
|||||||
* Абстрактный класс журналиста
|
* Абстрактный класс журналиста
|
||||||
*
|
*
|
||||||
* @package mirzaev\vk\loggers
|
* @package mirzaev\vk\loggers
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <red@hood.su>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
*/
|
*/
|
||||||
abstract class logger
|
abstract class logger
|
||||||
{
|
{
|
||||||
|
@@ -22,7 +22,7 @@ use mirzaev\vk\robots\robot,
|
|||||||
* @method public function __isset($name) Проверка на инициализированность свойства
|
* @method public function __isset($name) Проверка на инициализированность свойства
|
||||||
*
|
*
|
||||||
* @package mirzaev\vk\robots
|
* @package mirzaev\vk\robots
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <red@hood.su>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
*/
|
*/
|
||||||
final class group extends robot
|
final class group extends robot
|
||||||
{
|
{
|
||||||
@@ -38,8 +38,8 @@ final class group extends robot
|
|||||||
* @param string|null $key Ключ
|
* @param string|null $key Ключ
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected int|null $id = null,
|
protected ?int $id = null,
|
||||||
protected string|null $key = null
|
protected ?string $key = null
|
||||||
) {
|
) {
|
||||||
parent::__construct($id, $key);
|
parent::__construct($id, $key);
|
||||||
|
|
||||||
|
@@ -39,39 +39,39 @@ use GuzzleHttp\Client as browser;
|
|||||||
* @method public function __toString() Конвертация в строку
|
* @method public function __toString() Конвертация в строку
|
||||||
*
|
*
|
||||||
* @package mirzaev\vk\robots
|
* @package mirzaev\vk\robots
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <red@hood.su>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
*/
|
*/
|
||||||
abstract class robot
|
abstract class robot
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Сессия
|
* @var int $session Сессия
|
||||||
*/
|
*/
|
||||||
protected int $session;
|
protected readonly int $session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Аккаунт
|
* @var account $account Аккаунт ВКонтакте
|
||||||
*/
|
*/
|
||||||
private account $account;
|
private readonly account $account;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $messages_mode Режим отправки сообщений
|
* @var api $api API ВКонтакте
|
||||||
*/
|
*/
|
||||||
protected int $messages_mode = 1;
|
protected readonly api $api;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var api API ВКонтакте
|
* @var browser $browser Браузер
|
||||||
*/
|
*/
|
||||||
protected api $api;
|
protected readonly browser $browser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Конструктор
|
* Конструктор
|
||||||
*
|
*
|
||||||
* @param int|null $id Идентификатор
|
* @param int|null $id Идентификатор робота
|
||||||
* @param string|null $key Ключ
|
* @param string|null $key Ключ API ВКонтакте
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected int|null $id = null,
|
protected ?int $id = null,
|
||||||
protected string|null $key = null
|
protected ?string $key = null
|
||||||
) {
|
) {
|
||||||
// Инициализация ядра
|
// Инициализация ядра
|
||||||
$core = core::init();
|
$core = core::init();
|
||||||
@@ -183,14 +183,13 @@ abstract class robot
|
|||||||
public function __set(string $name, mixed $value): void
|
public function __set(string $name, mixed $value): void
|
||||||
{
|
{
|
||||||
match ($name) {
|
match ($name) {
|
||||||
'id' => isset($this->id) ? throw new Exception('Запрещено перезаписывать идентификатор', 500) : $this->id = (int) $value,
|
'id' => empty($this->id) ?: $this->id = $value,
|
||||||
'session' => isset($this->session) ? throw new Exception('Запрещено перезаписывать сессию', 500) : $this->session = (int) $value,
|
'session' => empty($this->session) ?: $this->session = $value,
|
||||||
'key' => $this->key((string) $value),
|
'key' => $this->key((string) $value),
|
||||||
'account' => $this->account($value),
|
'account' => $this->account($value),
|
||||||
'api' => $this->api(),
|
'api' => $this->api(),
|
||||||
'browser' => isset($this->browser) ? throw new Exception('Запрещено перезаписывать браузер', 500) : $this->browser = $value,
|
'browser' => empty($this->browser) ?: $this->browser = $value,
|
||||||
'messages_new' => $this->messages_new = (int) $value,
|
'messages_new' => $this->messages_new = (int) $value
|
||||||
default => throw new Exception("Свойство $name не найдено", 404)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,23 +218,16 @@ abstract class robot
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Проверить свойство на инициализированность
|
* Проверить на инициализированность
|
||||||
*
|
*
|
||||||
* @param string $name Название
|
* @param mixed $name Название
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
*/
|
||||||
public function __isset(string $name): bool
|
public function __isset(string $name): bool
|
||||||
{
|
{
|
||||||
return match ($name) {
|
return match ($name) {
|
||||||
'id' => isset($this->id),
|
'id' => isset($this->id),
|
||||||
'session' => isset($this->session),
|
|
||||||
'key' => isset($this->key),
|
'key' => isset($this->key),
|
||||||
'account' => isset($this->account),
|
default => false
|
||||||
'api' => isset($this->api),
|
|
||||||
'browser' => isset($this->browser),
|
|
||||||
'messages_new' => isset($this->messages_new),
|
|
||||||
default => throw new Exception("Свойство $name не найдено", 404)
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -12,7 +12,7 @@ use mirzaev\accounts\vk as account;
|
|||||||
* Робот-пользователь
|
* Робот-пользователь
|
||||||
*
|
*
|
||||||
* @package mirzaev\vk\robots
|
* @package mirzaev\vk\robots
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <red@hood.su>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
*/
|
*/
|
||||||
final class user extends robot
|
final class user extends robot
|
||||||
{
|
{
|
||||||
@@ -23,8 +23,8 @@ final class user extends robot
|
|||||||
* @param string|null $key Ключ
|
* @param string|null $key Ключ
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected int|null $id = null,
|
protected readonly int|null $id = null,
|
||||||
protected string|null $key = null
|
protected readonly string|null $key = null
|
||||||
) {
|
) {
|
||||||
parent::__construct($id, $key);
|
parent::__construct($id, $key);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user