Началр работы с переработкой
This commit is contained in:
29
sources/API/LongPoll.php
Normal file
29
sources/API/LongPoll.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace VK\API;
|
||||
|
||||
class LongPoll extends LongPollAbstract
|
||||
{
|
||||
public function __construct(object $robot, array $params = [])
|
||||
{
|
||||
return;
|
||||
echo get_class($robot), PHP_EOL;
|
||||
die;
|
||||
if ($_ENV['ROBOT_TYPE']) {
|
||||
$this->vk->auth_type = 'user';
|
||||
$this->user_id = $data['id'];
|
||||
} else {
|
||||
$this->vk->auth_type = 'group';
|
||||
$this->group_id = $this->vk->request('groups.getById', [])[0]['id'];
|
||||
$this->vk->request('groups.setLongPollSettings', [
|
||||
'group_id' => $this->group_id,
|
||||
'enabled' => 1,
|
||||
'api_version' => $this->vk->version,
|
||||
'message_new' => 1,
|
||||
]);
|
||||
}
|
||||
$this->getLongPollServer();
|
||||
}
|
||||
}
|
10
sources/API/LongPollAbstract.php
Normal file
10
sources/API/LongPollAbstract.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace VK\API;
|
||||
|
||||
abstract class LongPollAbstract
|
||||
{
|
||||
abstract public function __construct(object $robot, array $params = []);
|
||||
}
|
38
sources/API/Methods/Message.php
Normal file
38
sources/API/Methods/Message.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace VK\API\Methods;
|
||||
|
||||
use VK\Core;
|
||||
use VK\API\Traits\Request;
|
||||
|
||||
class Message
|
||||
{
|
||||
use Request;
|
||||
|
||||
private const METHOD = 'messages.send';
|
||||
|
||||
public static function post($from, $to, $message, $trolling)
|
||||
{
|
||||
if (is_int($from)) $from = Core::init()->get($from);
|
||||
|
||||
$params = [
|
||||
'message' => $message,
|
||||
'peer_id' => $to,
|
||||
'access_token' => $from->token,
|
||||
'v' => $from->version,
|
||||
'random_id' => $trolling
|
||||
];
|
||||
|
||||
self::request(self::METHOD, $params, $from->getBrowser());
|
||||
}
|
||||
|
||||
public static function get()
|
||||
{
|
||||
}
|
||||
|
||||
public static function delete()
|
||||
{
|
||||
}
|
||||
}
|
12
sources/API/Methods/MethodAbstract.php
Normal file
12
sources/API/Methods/MethodAbstract.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace VK\API\Methods;
|
||||
|
||||
abstract class MethodAbstract
|
||||
{
|
||||
abstract public static function post();
|
||||
abstract public static function get();
|
||||
abstract public static function delete();
|
||||
}
|
36
sources/API/Traits/Request.php
Normal file
36
sources/API/Traits/Request.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace VK\API\Traits;
|
||||
|
||||
use VK\Browsers\BrowserAbstract;
|
||||
use Exception;
|
||||
/**
|
||||
* Паттерн registry
|
||||
*/
|
||||
trait Request
|
||||
{
|
||||
private static function request(string $method, array $params, BrowserAbstract $browser)
|
||||
{
|
||||
$url = 'https://api.vk.com/method/' . $method;
|
||||
|
||||
foreach ($params as $key => $value) {
|
||||
$post[$key] = $value;
|
||||
}
|
||||
|
||||
// while (True) {
|
||||
// try {
|
||||
return $browser::post($url, $post);
|
||||
// } catch (Exception $e) {
|
||||
// // if (in_array($e->getCode(), $this->request_ignore_error)) {
|
||||
// // sleep(1);
|
||||
// // continue;
|
||||
// // } else
|
||||
// // throw new Exception($e->getMessage(), $e->getCode());
|
||||
// throw new Exception('Жопа');
|
||||
// }
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user