From 787e9a7bdeb7e2177da62578865b7cc147b9e193 Mon Sep 17 00:00:00 2001 From: FunnyRain Date: Wed, 10 Feb 2021 21:22:26 +0300 Subject: [PATCH] =?UTF-8?q?=D1=83=D1=80=D0=B0=20=D1=83=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=BB=20=D0=BA=D1=80=D0=B8=D0=BD=D0=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cache/temp_wallIDS.json | 2 +- src/Wall.php | 35 ++++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/cache/temp_wallIDS.json b/cache/temp_wallIDS.json index 231a36e..43a3180 100644 --- a/cache/temp_wallIDS.json +++ b/cache/temp_wallIDS.json @@ -1 +1 @@ -{"isRemove":false,"deleteTime":1612882798,"temp":[110917,110916,110915,110913,110908,110903,110902,110899,110896,110893]} \ No newline at end of file +{"isRemove":false,"deleteTime":1612882798,"temp":[110917,110916,110915,110913,110908,110903,110902,110899,110896,110893,110972,110970,110968,110966,110962]} \ No newline at end of file diff --git a/src/Wall.php b/src/Wall.php index 45069c9..776672c 100644 --- a/src/Wall.php +++ b/src/Wall.php @@ -4,29 +4,34 @@ class Wall { private $user; private $cache; + private $update_time; public function __construct(User $user) { $this->user = $user; $this->cache = new Cache('temp_wallIDS.json', 30); + $this->update_time = time(); } public function listen($owner_id, $call, int $sleep) { - while ($data = $this->user->VkApiRequest()->api('wall.get', [ - 'owner_id' => $owner_id, - 'count' => 10, - 'filter' => 'owner' - ])) { - $items = $data['items']; - if (count($items) == 0) continue; - - foreach ($items as $key => $item) { + while (true) { + if (time() >= $this->update_time) { + $data = $this->user->VkApiRequest()->api('wall.get', [ + 'owner_id' => $owner_id, + 'count' => 5, + 'filter' => 'owner' + ]); + $items = $data['items']; + if (count($items) == 0) continue; - if (!in_array($item['id'], $this->cache->get()['temp'])) { - $this->cache->set($item['id']); - $call($item); + foreach ($items as $key => $item) { + if (!in_array($item['id'], $this->cache->get()['temp'])) { + $this->cache->set($item['id']); + $call($item); + } } - + $this->update_time = strtotime("+ {$sleep} seconds"); } + } /** * Прошу прощения у матерей, * Чьих возбудил я дочерей. @@ -36,8 +41,8 @@ public function listen($owner_id, $call, int $sleep) { * Короче извините за sleep(), но я хуй знает как сделать задержку пушто шлёт флуд контроль. * Жду героя, который это исправит, а то мне стыдно :) */ - sleep($sleep); - } + // Хахахаха нахуй это отсюда + // sleep($sleep); } } \ No newline at end of file