From e389eb3210a24729a44bad7238966c4ad1c6277f Mon Sep 17 00:00:00 2001 From: Lkeme <19500576+lkeme@users.noreply.github.com> Date: Fri, 27 Dec 2019 03:00:09 +0800 Subject: [PATCH] [fix] Sleep --- CHANGELOG.md | 1 + src/plugin/Sleep.php | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f28e14..a7ca49a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - 修复抽奖数据异常 - 修复部分已知BUG - 修复获奖推送通知 +- 修复休眠中心异常 - ## v0.0.5.191223 alpha (2019-12-23) diff --git a/src/plugin/Sleep.php b/src/plugin/Sleep.php index cb7a5c4..132b41a 100644 --- a/src/plugin/Sleep.php +++ b/src/plugin/Sleep.php @@ -28,24 +28,33 @@ class Sleep { if (getenv('USE_SLEEP') == 'false' || self::getLock() > time()) { return; + }; + if (!self::isPause() && !self::isRefuse()) { + self::setLock(5 * 60); } - self::isPause(); - self::isRefuse(); - self::setLock(5 * 60); } - private static function isPause() + /** + * @use 检查休眠 + * @return bool + */ + private static function isPause(): bool { self::$sleep_section = empty(self::$filter_type) ? explode(',', getenv('SLEEP_SECTION')) : self::$sleep_section; if (in_array(date('H'), self::$sleep_section)) { $unlock_time = 60 * 60; self::stopProc($unlock_time); Log::warning('进入自定义休眠时间范围,暂停非必要任务,自动开启!'); + return true; } - return; + return false; } - private static function isRefuse() + /** + * @use 检查封禁 + * @return bool + */ + private static function isRefuse(): bool { $payload = []; $raw = Curl::get('https://api.live.bilibili.com/mobile/freeSilverAward', Sign::api($payload)); @@ -56,8 +65,9 @@ class Sleep Log::warning('账号拒绝访问,暂停非必要任务,自动开启!'); // 推送被ban信息 Notice::push('banned', floor($unlock_time / 60 / 60)); + return true; } - return; + return false; } /**