Началр работы с переработкой

This commit is contained in:
RedHood
2020-07-10 01:17:26 +10:00
parent 64e03a380b
commit 8635fbb301
50 changed files with 7855 additions and 2594 deletions

29
sources/API/LongPoll.php Normal file
View 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();
}
}

View File

@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace VK\API;
abstract class LongPollAbstract
{
abstract public function __construct(object $robot, array $params = []);
}

View 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()
{
}
}

View 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();
}

View 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;
}
}