[update] Schedule

This commit is contained in:
Lkeme 2020-04-24 20:09:55 +08:00
parent d6b2792485
commit fa58953d93
18 changed files with 273 additions and 71 deletions

View File

@ -1,6 +1,22 @@
# Release Notes # Release Notes
# 本项目Log # 本项目Log
## v0.3.0.200424 alpha (2020-04-24)
### Added
- 抽出独立小黑屋
- 提前引入BV2AV
-
### Changed
- 优化监控推送
- 优化登陆参数
- 同步黑屋提醒
### Fixed
- 修复监控输出
-
## v0.3.0.200421 alpha (2020-04-21) ## v0.3.0.200421 alpha (2020-04-21)
### Added ### Added

View File

@ -19,6 +19,7 @@ use Socket\Raw\Factory;
class AloneTcpClient class AloneTcpClient
{ {
use TimeLock; use TimeLock;
private static $heart_lock = 0; private static $heart_lock = 0;
private static $client = null; private static $client = null;
private static $server_addr = null; private static $server_addr = null;
@ -33,6 +34,7 @@ class AloneTcpClient
if (self::getLock() > time() || getenv('USE_ALONE_SERVER') == 'false') { if (self::getLock() > time() || getenv('USE_ALONE_SERVER') == 'false') {
return; return;
} }
self::setPauseStatus();
self::init(); self::init();
self::heartBeat(); self::heartBeat();
self::receive(); self::receive();

View File

@ -145,9 +145,13 @@ class AnchorRaffle extends BaseRaffle
$data = $result['source']; $data = $result['source'];
$content = $result['content']; $content = $result['content'];
$de_raw = json_decode($content, true); $de_raw = json_decode($content, true);
// {"code":-403,"data":null,"message":"访问被拒绝","msg":"访问被拒绝"}
if (isset($de_raw['code']) && $de_raw['code'] == 0) { if (isset($de_raw['code']) && $de_raw['code'] == 0) {
Statistics::addSuccessList(self::ACTIVE_TITLE); Statistics::addSuccessList(self::ACTIVE_TITLE);
Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": 参与抽奖成功~"); Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": 参与抽奖成功~");
} elseif (isset($de_raw['msg']) && $de_raw['code'] == -403 && $de_raw['msg'] == '访问被拒绝') {
Log::debug("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": {$de_raw['message']}");
self::pauseLock();
} else { } else {
Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": {$de_raw['message']}"); Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": {$de_raw['message']}");
} }

View File

@ -12,7 +12,9 @@
namespace BiliHelper\Plugin; namespace BiliHelper\Plugin;
use BiliHelper\Core\Log; use BiliHelper\Core\Log;
use BiliHelper\Core\Curl;abstract class BaseRaffle use BiliHelper\Core\Curl;
abstract class BaseRaffle
{ {
const ACTIVE_TITLE = ''; const ACTIVE_TITLE = '';
const ACTIVE_SWITCH = ''; const ACTIVE_SWITCH = '';
@ -30,6 +32,7 @@ use BiliHelper\Core\Curl;abstract class BaseRaffle
if (static::getLock() > time()) { if (static::getLock() > time()) {
return; return;
} }
static::setPauseStatus();
static::startLottery(); static::startLottery();
} }
@ -172,6 +175,10 @@ use BiliHelper\Core\Curl;abstract class BaseRaffle
if (getenv(static::ACTIVE_SWITCH) == 'false') { if (getenv(static::ACTIVE_SWITCH) == 'false') {
return false; return false;
} }
// 黑屋
if (static::getPauseStatus()) {
return false;
}
$current_rid = (int)$data['rid']; $current_rid = (int)$data['rid'];
// 去重 // 去重
if (static::toRepeatLid($current_rid, false)) { if (static::toRepeatLid($current_rid, false)) {

View File

@ -27,19 +27,19 @@ class DataTreating
return; return;
} }
switch ($data['raffle_type']) { switch ($data['raffle_type']) {
case "storm": case 'storm':
// 风暴 // 风暴
StormRaffle::pushToQueue($info); StormRaffle::pushToQueue($info);
break; break;
case "raffle": case 'raffle':
// 礼物 // 礼物
GiftRaffle::pushToQueue($info); GiftRaffle::pushToQueue($info);
break; break;
case "guard": case 'guard':
// 舰长 // 舰长
GuardRaffle::pushToQueue($info); GuardRaffle::pushToQueue($info);
break; break;
case "small_tv": case 'small_tv':
// 电视 // 电视
GiftRaffle::pushToQueue($info); GiftRaffle::pushToQueue($info);
break; break;

View File

@ -23,6 +23,7 @@ class GiftHeart
if (self::getLock() > time()) { if (self::getLock() > time()) {
return; return;
} }
self::setPauseStatus();
if (self::giftHeart()) { if (self::giftHeart()) {
self::setLock(60 * 60); self::setLock(60 * 60);
return; return;
@ -44,6 +45,12 @@ class GiftHeart
$raw = Curl::get('app', $url, Sign::common($payload)); $raw = Curl::get('app', $url, Sign::common($payload));
$de_raw = json_decode($raw, true); $de_raw = json_decode($raw, true);
// {"code":400,"msg":"访问被拒绝","message":"访问被拒绝","data":[]}
if (isset($de_raw['msg']) && $de_raw['code'] == 400 && $de_raw['msg'] == '访问被拒绝') {
self::pauseLock();
return false;
}
if ($de_raw['code'] == -403) { if ($de_raw['code'] == -403) {
Log::info($de_raw['msg']); Log::info($de_raw['msg']);
$payload = [ $payload = [

View File

@ -111,6 +111,7 @@ class GiftRaffle extends BaseRaffle
$data = $result['source']; $data = $result['source'];
$content = $result['content']; $content = $result['content'];
$de_raw = json_decode($content, true); $de_raw = json_decode($content, true);
// { "code": -403, "data": null, "message": "访问被拒绝", "msg": "访问被拒绝", }
if (isset($de_raw['code']) && !$de_raw['code']) { if (isset($de_raw['code']) && !$de_raw['code']) {
// 推送中奖信息 // 推送中奖信息
if ($de_raw['data']['award_name'] != '辣条' && $de_raw['data']['award_name'] != '') { if ($de_raw['data']['award_name'] != '辣条' && $de_raw['data']['award_name'] != '') {
@ -119,6 +120,9 @@ class GiftRaffle extends BaseRaffle
} }
Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": {$de_raw['data']['award_name']}x{$de_raw['data']['award_num']}"); Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": {$de_raw['data']['award_name']}x{$de_raw['data']['award_num']}");
Statistics::addSuccessList(self::ACTIVE_TITLE); Statistics::addSuccessList(self::ACTIVE_TITLE);
} elseif (isset($de_raw['msg']) && $de_raw['code'] == -403 && $de_raw['msg'] == '访问被拒绝') {
Log::debug("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": {$de_raw['msg']}");
self::pauseLock();
} else { } else {
Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": {$de_raw['msg']}"); Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": {$de_raw['msg']}");
} }

View File

@ -125,9 +125,13 @@ class GuardRaffle extends BaseRaffle
$data = $result['source']; $data = $result['source'];
$content = $result['content']; $content = $result['content'];
$de_raw = json_decode($content, true); $de_raw = json_decode($content, true);
// {"code":-403,"data":null,"message":"访问被拒绝","msg":"访问被拒绝"}
if (isset($de_raw['code']) && $de_raw['code'] == 0) { if (isset($de_raw['code']) && $de_raw['code'] == 0) {
Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": " . $de_raw['data']['award_name'] . "x" . $de_raw['data']['award_num']); Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": " . $de_raw['data']['award_name'] . "x" . $de_raw['data']['award_num']);
Statistics::addSuccessList(self::ACTIVE_TITLE); Statistics::addSuccessList(self::ACTIVE_TITLE);
} elseif (isset($de_raw['msg']) && $de_raw['code'] == -403 && $de_raw['msg'] == '访问被拒绝') {
Log::debug("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": {$de_raw['msg']}");
self::pauseLock();
} else { } else {
Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": {$de_raw['msg']}"); Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": {$de_raw['msg']}");
} }

View File

@ -152,8 +152,8 @@ class Login
$url = 'https://passport.snm0516.aisee.tv/api/tv/login'; $url = 'https://passport.snm0516.aisee.tv/api/tv/login';
$payload = [ $payload = [
'channel' => 'master', 'channel' => 'master',
'token' => '5598158bcd8511e2', 'token' => '5598158bcd8511e9',
'guid' => 'XYEBAA3E54D502E37BD606F0589A356902FCF', 'guid' => 'XYEBAA3E54D502E73BD606F0589A356902FCF',
'username' => $user, 'username' => $user,
'password' => base64_encode($crypt), 'password' => base64_encode($crypt),
'captcha' => $captcha, 'captcha' => $captcha,
@ -201,7 +201,7 @@ class Login
Log::info('登录需要验证, 启动验证码登录!'); Log::info('登录需要验证, 启动验证码登录!');
$url = 'https://passport.snm0516.aisee.tv/api/captcha'; $url = 'https://passport.snm0516.aisee.tv/api/captcha';
$payload = [ $payload = [
'token' => '5598158bcd8511e2' 'token' => '5598158bcd8511e9'
]; ];
$headers = [ $headers = [
'Accept' => 'application/json, text/plain, */*', 'Accept' => 'application/json, text/plain, */*',

View File

@ -112,8 +112,8 @@ class Notice
break; break;
case 'banned': case 'banned':
$info = [ $info = [
'title' => '账号封禁', 'title' => '任务小黑屋',
'content' => '[' . $now_time . ']' . ' 用户: ' . self::$uname . ' 账号被封禁: 程序开始睡眠,凌晨自动唤醒,距离唤醒还有' . self::$result . '小时', 'content' => '[' . $now_time . ']' . ' 用户: ' . self::$uname . ' 小黑屋: ' . self::$result,
]; ];
break; break;
case 'error': case 'error':

View File

@ -118,6 +118,9 @@ class PkRaffle extends BaseRaffle
if (isset($de_raw['code']) && $de_raw['code'] == 0) { if (isset($de_raw['code']) && $de_raw['code'] == 0) {
Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": {$de_raw['data']['award_text']}"); Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": {$de_raw['data']['award_text']}");
Statistics::addSuccessList(self::ACTIVE_TITLE); Statistics::addSuccessList(self::ACTIVE_TITLE);
} elseif (isset($de_raw['msg']) && $de_raw['code'] == -403 && $de_raw['msg'] == '访问被拒绝') {
Log::debug("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": {$de_raw['message']}");
self::pauseLock();
} else { } else {
Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": {$de_raw['message']}"); Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} " . self::ACTIVE_TITLE . ": {$de_raw['message']}");
} }

View File

@ -11,99 +11,141 @@
namespace BiliHelper\Plugin; namespace BiliHelper\Plugin;
use BiliHelper\Core\Log; use BiliHelper\Core\Log;
use BiliHelper\Core\Curl;
use BiliHelper\Util\TimeLock; use BiliHelper\Util\TimeLock;
class Schedule class Schedule
{ {
use TimeLock; use TimeLock;
// TODO 黑白名单|考虑添加到每个插件内部自动添加|优化RUN逻辑代码 // TODO 黑白名单|考虑添加到每个插件内部自动添加|优化RUN逻辑代码
private static $unlock_hour = 24; private static $unlock_hour = 24;
private static $unlock_time = 0; private static $unlock_timers = [];
private static $fillable = ['Login', 'Schedule', 'Daily', 'Judge', 'MasterSite', 'GiftSend', 'Task', 'Silver2Coin', 'GroupSignIn', 'AwardRecord', 'Statistics'];
private static $guarded = ['Barrage', 'GiftHeart', 'Heart', 'Silver', 'MaterialObject', 'AloneTcpClient', 'ZoneTcpClient', 'StormRaffle', 'GuardRaffle', 'PkRaffle', 'GiftRaffle', 'AnchorRaffle'];
private static $sleep_section = []; private static $sleep_section = [];
// 日常类
private static $fillable = ['Login', 'Schedule', 'Daily', 'Judge', 'MasterSite', 'GiftSend', 'Task', 'Silver2Coin', 'GroupSignIn', 'AwardRecord', 'Statistics'];
// 任务类
private static $guarded_first = ['Barrage', 'GiftHeart', 'Heart', 'Silver', 'MaterialObject'];
// 监控类
private static $guarded_second = ['AloneTcpClient', 'ZoneTcpClient',];
// 抽奖类
private static $guarded_third = ['StormRaffle', 'GuardRaffle', 'PkRaffle', 'GiftRaffle', 'AnchorRaffle'];
public static function run() public static function run()
{ {
if (self::getLock() > time()) { if (self::getLock() > time()) {
return; return;
} else { }
self::isSleep();
self::isSpecialPause();
self::setLock(1 * 60); self::setLock(1 * 60);
} }
// 封禁逻辑
if (self::$unlock_time < time()) {
if (!self::isRefuse()) {
self::setLock(5 * 60);
} else {
self::setLock(1 * 60);
return;
}
}
// 休眠逻辑
if (getenv('USE_SLEEP') != 'false' && self::$unlock_time < time() && self::$unlock_hour != date('H')) {
if (!self::isPause()) {
self::setLock(5 * 60);
} else {
self::setLock(1 * 60);
return;
}
};
}
/** /**
* @use 检查休眠 * @use 检查休眠
* @return bool
*/ */
private static function isPause(): bool private static function isSleep()
{ {
self::$sleep_section = empty(self::$filter_type) ? explode(',', getenv('SLEEP_SECTION')) : self::$sleep_section; if (getenv('USE_SLEEP') != 'false' && self::$unlock_hour != date('H')) {
if (in_array(date('H'), self::$sleep_section)) { self::$sleep_section = empty(self::$sleep_section) ? explode(',', getenv('SLEEP_SECTION')) : self::$sleep_section;
$unlock_time = 60 * 60; if (!in_array(date('H'), self::$sleep_section)) {
self::stopProc($unlock_time); return false;
Log::warning('进入自定义休眠时间范围,暂停非必要任务,自动开启!'); };
self::handleBan('sleep');
};
return true; return true;
} }
return false;
}
/** /**
* @use 检查封禁 * @use 特殊暂停
* @return bool
*/ */
private static function isRefuse(): bool private static function isSpecialPause()
{ {
$url = 'https://api.live.bilibili.com/mobile/freeSilverAward'; foreach (self::$guarded_second as $classname) {
$payload = []; $status = call_user_func(array(__NAMESPACE__ . '\\' . $classname, 'getPauseStatus'));
$raw = Curl::get('app', $url, Sign::common($payload)); if ($status) {
$de_raw = json_decode($raw, true);
if ($de_raw['msg'] == '访问被拒绝') {
$unlock_time = strtotime(date("Y-m-d", strtotime("+1 day", time()))) - time();
self::stopProc($unlock_time);
Log::warning('账号拒绝访问,暂停非必要任务,自动开启!');
// 推送被ban信息
Notice::push('banned', floor($unlock_time / 60 / 60));
return true; return true;
} }
}
foreach (self::$guarded_third as $classname) {
$status = call_user_func(array(__NAMESPACE__ . '\\' . $classname, 'getPauseStatus'));
if (!$status) {
return false; return false;
} }
}
self::handleBan('special');
return true;
}
/** /**
* @use 停止运行 * @use 处理禁令
* @param int $unlock_time * @param $action
* @param string $classname
*/ */
private static function stopProc(int $unlock_time) private static function handleBan($action, $classname = '')
{ {
self::$unlock_time = time() + $unlock_time; switch ($action) {
self::$unlock_hour = date('H'); // 休眠
case 'sleep':
foreach (self::$fillable as $classname) { foreach (self::$fillable as $classname) {
Log::info("插件 {$classname} 白名单,保持当前状态继续"); Log::info("插件 {$classname} 白名单,保持当前状态继续");
} }
foreach (self::$guarded as $classname) { $unlock_time = 60 * 60;
Log::info("插件 {$classname} 黑名单,锁定状态将于" . date("Y-m-d H:i", time() + $unlock_time) . "解除"); self::$unlock_hour = date('H');
call_user_func(array(__NAMESPACE__ . '\\' . $classname, 'setLock'), $unlock_time + 3 * 60); $classname_list = array_merge(self::$guarded_first, self::$guarded_second, self::$guarded_third);
self::stopProc($classname_list, $unlock_time, true);
Log::warning('进入自定义休眠时间范围,暂停非必要任务,自动开启!');
break;
// 暂停访问
case 'pause':
// 访问拒绝 统一时间 第二天0点
$unlock_time = strtotime(date("Y-m-d", strtotime("+1 day", time()))) - time();
self::stopProc([$classname], $unlock_time);
Log::warning("{$classname} 任务拒绝访问,暂停任务,自动开启!");
// 推送被ban信息
$time = floor($unlock_time / 60 / 60);
Notice::push('banned', "任务 {$classname} 暂停,{$time} 小时后自动恢复!");
break;
// 特殊类
case 'special':
// 访问拒绝 统一时间 第二天0点
$unlock_time = strtotime(date("Y-m-d", strtotime("+1 day", time()))) - time();
self::stopProc(self::$guarded_second, $unlock_time);
Log::warning("所有抽奖任务拒绝访问,暂停监控任务,自动开启!");
break;
default:
break;
} }
} }
/**
* @use 停止运行
* @param array $classname_list
* @param int $unlock_time
* @param bool $force
*/
private static function stopProc(array $classname_list, int $unlock_time, bool $force = false)
{
foreach ($classname_list as $classname) {
Log::info("插件 {$classname} 黑名单,锁定状态将于" . date("Y-m-d H:i", time() + $unlock_time) . "解除");
// 强制 无视小黑屋设定
if ($force) {
call_user_func(array(__NAMESPACE__ . '\\' . $classname, 'setPauseStatus'), false);
}
call_user_func(array(__NAMESPACE__ . '\\' . $classname, 'setLock'), $unlock_time + 3 * 60);
call_user_func(array(__NAMESPACE__ . '\\' . $classname, 'setPauseStatus'), true);
}
}
/**
* @use 触发封禁
* @param string $classname
*/
public static function triggerRefused(string $classname)
{
self::handleBan('pause', $classname);
}
} }

View File

@ -17,6 +17,7 @@ use BiliHelper\Util\TimeLock;
class Silver class Silver
{ {
use TimeLock; use TimeLock;
protected static $task = []; protected static $task = [];
public static function run() public static function run()
@ -24,6 +25,7 @@ class Silver
if (self::getLock() > time()) { if (self::getLock() > time()) {
return; return;
} }
self::setPauseStatus();
if (empty(self::$task)) { if (empty(self::$task)) {
self::getSilverBox(); self::getSilverBox();
@ -81,6 +83,12 @@ class Silver
$data = Curl::get('app', $url, Sign::common($payload)); $data = Curl::get('app', $url, Sign::common($payload));
$data = json_decode($data, true); $data = json_decode($data, true);
// {"code":400,"msg":"访问被拒绝","message":"访问被拒绝","data":[]}
if (isset($data['msg']) && $data['code'] == 400 && $data['msg'] == '访问被拒绝') {
self::pauseLock();
return;
}
if ($data['code'] == -800) { if ($data['code'] == -800) {
self::setLock(12 * 60 * 60); self::setLock(12 * 60 * 60);
Log::warning("领取宝箱失败,{$data['message']}!"); Log::warning("领取宝箱失败,{$data['message']}!");

View File

@ -131,7 +131,8 @@ class StormRaffle extends BaseRaffle
break; break;
} }
if (isset($de_raw['data']) && empty($de_raw['data'])) { if (isset($de_raw['data']) && empty($de_raw['data'])) {
Log::notice(self::formatInfo($raffle['raffle_id'], $num, '节奏风暴在小黑屋')); Log::debug(self::formatInfo($raffle['raffle_id'], $num, '节奏风暴在小黑屋'));
self::pauseLock();
break; break;
} }
if ($de_raw['msg'] == '你错过了奖励,下次要更快一点哦~') { if ($de_raw['msg'] == '你错过了奖励,下次要更快一点哦~') {

View File

@ -42,6 +42,7 @@ class ZoneTcpClient
if (self::getLock() > time() || getenv('USE_ZONE_SERVER') == 'false') { if (self::getLock() > time() || getenv('USE_ZONE_SERVER') == 'false') {
return; return;
} }
self::setPauseStatus();
self::init(); self::init();
self::updateConnection(); self::updateConnection();
self::heartBeat(); self::heartBeat();
@ -353,8 +354,9 @@ class ZoneTcpClient
if (!isset(self::$raffle_list[$data['raffle_type']])) { if (!isset(self::$raffle_list[$data['raffle_type']])) {
self::$raffle_list[$data['raffle_type']] = []; self::$raffle_list[$data['raffle_type']] = [];
} }
$data['area_id'] = self::$area_id;
array_push(self::$raffle_list[$data['raffle_type']], $data); array_push(self::$raffle_list[$data['raffle_type']], $data);
// Log::info("获取到分区 #" . self::$area_id . "# {$data['source']}"); Log::info("监测到 @分区 {$data['area_id']} @房间 {$data['room_id']} @抽奖 {$data['raffle_title']}");
// print_r($data); // print_r($data);
} }
} }

57
src/tool/BvToAv.php Normal file
View File

@ -0,0 +1,57 @@
<?php
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2020 ~ 2021
* Source: https://github.com/anhao/bv2av/
*/
namespace BiliHelper\Tool;
use BiliHelper\Core\Log;
class BvToAv
{
protected $tr = "fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF";
protected $xor = 177451812;
protected $add = 8728348608;
protected $s = [11, 10, 3, 8, 4, 6];
/**
* BV AV
*
* @param $bv
* @return int
*/
public function dec($bv)
{
$r = 0;
$tr = array_flip(str_split($this->tr));
for ($i = 0; $i < 6; $i++) {
$r += $tr[$bv[$this->s[$i]]] * (pow(58, $i));
}
return ($r - $this->add) ^ $this->xor;
}
/**
*
* AV BV
*
* @param $av
* @return string
*/
public function enc($av)
{
$tr = str_split($this->tr);
$bv = 'BV1 4 1 7 ';
$av = ($av ^ $this->xor) + $this->add;
for ($i = 0; $i < 6; $i++) {
$bv[$this->s[$i]] = $tr[floor($av / pow(58, $i) % 58)];
}
return $bv;
}
}

View File

@ -4,7 +4,9 @@
namespace BiliHelper\Tool; namespace BiliHelper\Tool;
use BiliHelper\Core\Log; use BiliHelper\Core\Log;
use BiliHelper\Core\Curl;class DumpMemory use BiliHelper\Core\Curl;
class DumpMemory
{ {
public static function dd($title) public static function dd($title)
{ {

View File

@ -11,10 +11,12 @@
namespace BiliHelper\Util; namespace BiliHelper\Util;
use Amp\Delayed; use Amp\Delayed;
use BiliHelper\Plugin\Schedule;
trait TimeLock trait TimeLock
{ {
public static $lock = 0; public static $lock = 0;
public static $pause_status = false;
/** /**
* @use 设置时间 * @use 设置时间
@ -22,8 +24,10 @@ trait TimeLock
*/ */
public static function setLock(int $lock) public static function setLock(int $lock)
{ {
if (!static::getpauseStatus()) {
static::$lock = time() + $lock; static::$lock = time() + $lock;
} }
}
/** /**
* @use 获取时间 * @use 获取时间
@ -54,4 +58,43 @@ trait TimeLock
return strtotime('tomorrow') + ($hour * 60 * 60) - time(); return strtotime('tomorrow') + ($hour * 60 * 60) - time();
} }
/**
* @use 暂停
*/
public static function pauseLock()
{
// 备份几种获取方式 get_called_class()
// basename(str_replace('\\', '/', $class));
// substr(strrchr($class, "\\"), 1);
// substr($class, strrpos($class, '\\') + 1);
// array_pop(explode('\\', $class));
Schedule::triggerRefused((new \ReflectionClass(static::class))->getShortName());
}
/**
* @use 取消暂停
*/
public static function cancelPause()
{
static::$lock = false;
}
/**
* @use 暂停状态
* @return bool
*/
public static function getPauseStatus()
{
return static::$pause_status;
}
/**
* @use 设置状态
* @param bool $status
*/
public static function setPauseStatus(bool $status = false)
{
self::$pause_status = $status;
}
} }