diff --git a/README.md b/README.md index 73ff7cd..f936413 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ Group: [602815575](https://jq.qq.com/?_wv=1027&k=UaalVexM) | **请不要来问 | LiveGoldBox | 0.0.1 | 直播金色宝箱(实物抽奖) | Lkeme | 1110 | 6-10(分钟) | √ | | AwardRecords | 0.0.1 | 获奖记录 | Lkeme | 1111 | 5(分钟) | √ | | VipPoint | 0.0.1 | 大会员积分 | Lkeme | 1112 | 5(分钟) | √ | -| Lottery | 0.0.2 | 抽奖 | MoeHero/Lkeme | 1113 | 5(分钟) | √ | +| Lottery | 0.0.2 | 抽奖 | MoeHero/Lkeme | 1113 | 10-25(分钟) | √ | | DailyGold | 0.0.1 | 每日电池(APP) | Lkeme | 1114 | 24(小时) | √ | | PolishMedal | 0.0.1 | 点亮灰色勋章 | possible318/Lkeme | 1115 | 1(小时) | √ | | BatchUnfollow | 0.0.1 | 批量取消关注 | Lkeme | 1116 | 5-10(分钟) | √ | diff --git a/plugin/ActivityLottery/ActivityLottery.php b/plugin/ActivityLottery/ActivityLottery.php index 41171f3..d29a6eb 100644 --- a/plugin/ActivityLottery/ActivityLottery.php +++ b/plugin/ActivityLottery/ActivityLottery.php @@ -30,7 +30,7 @@ class ActivityLottery extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'ActivityLottery', // 插件名称 'version' => '0.0.1', // 插件版本 @@ -38,9 +38,8 @@ class ActivityLottery extends BasePlugin 'author' => 'Lkeme',// 作者 'priority' => 1117, // 插件优先级 'cycle' => '3-7(分钟)', // 运行周期 - // 新增字段 - 'start' => '08:00:00', // 插件开始日期 - 'end' => '23:00:00', // 插件结束日期 + 'start' => '07:30:00', // 插件运行开始时间 + 'end' => '23:30:00', // 插件运行结束时间 ]; /** @@ -73,44 +72,28 @@ class ActivityLottery extends BasePlugin */ public function execute(): void { - // 时间段限制 - // if (!TimeLock::isWithinTimeRange($this->info['start'], $this->info['end'])) return; // 时间锁限制 if (TimeLock::getTimes() > time() || !getEnable('activity_lottery')) return; - + // 今日执行 + if (isset($this->config[date("Y-m-d")]['add']) && isset($this->config[date("Y-m-d")]['get']) && isset($this->config[date("Y-m-d")]['do'])) return; // $this->initConfig(); - delay(1); - // 获取远程数据 $this->fetchRemoteInfos(); - delay(1); - // 增加次数 $this->addMyTimes(); - delay(1); - // 查询次数 $this->getMyTimes(); - delay(1); - // 执行次数 $this->doMyTimes(); - - // - if (isset($this->config[date("Y-m-d")]['add']) && isset($this->config[date("Y-m-d")]['get']) && isset($this->config[date("Y-m-d")]['do'])) { - TimeLock::setTimes(TimeLock::timing(11) + mt_rand(1, 120) * 60); - } else { - TimeLock::setTimes(mt_rand(3, 7) * 60); - } - // $this->initConfig(true); - + // + TimeLock::setTimes(mt_rand(3, 7) * 60); } diff --git a/plugin/AwardRecords/AwardRecords.php b/plugin/AwardRecords/AwardRecords.php index d6dc1b7..1c0ec72 100644 --- a/plugin/AwardRecords/AwardRecords.php +++ b/plugin/AwardRecords/AwardRecords.php @@ -47,7 +47,7 @@ class AwardRecords extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'AwardRecords', // 插件名称 'version' => '0.0.1', // 插件版本 diff --git a/plugin/BatchUnfollow/BatchUnfollow.php b/plugin/BatchUnfollow/BatchUnfollow.php index 08a5692..6d3faaa 100644 --- a/plugin/BatchUnfollow/BatchUnfollow.php +++ b/plugin/BatchUnfollow/BatchUnfollow.php @@ -27,7 +27,7 @@ class BatchUnfollow extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'BatchUnfollow', // 插件名称 'version' => '0.0.1', // 插件版本 @@ -35,9 +35,6 @@ class BatchUnfollow extends BasePlugin 'author' => 'Lkeme',// 作者 'priority' => 1116, // 插件优先级 'cycle' => '5-10(分钟)', // 运行周期 - // 新增字段 - 'start' => '08:00:00', // 插件开始日期 - 'end' => '23:00:00', // 插件结束日期 ]; /** @@ -64,8 +61,6 @@ class BatchUnfollow extends BasePlugin */ public function execute(): void { - // 时间段限制 - // if (!TimeLock::isWithinTimeRange($this->info['start'], $this->info['end'])) return; // 时间锁限制 if (TimeLock::getTimes() > time() || !getEnable('batch_unfollow')) return; // diff --git a/plugin/BpConsumption/BpConsumption.php b/plugin/BpConsumption/BpConsumption.php index 652d028..7711808 100644 --- a/plugin/BpConsumption/BpConsumption.php +++ b/plugin/BpConsumption/BpConsumption.php @@ -29,7 +29,7 @@ class BpConsumption extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'BpConsumption', // 插件名称 'version' => '0.0.1', // 插件版本 diff --git a/plugin/CheckUpdate/CheckUpdate.php b/plugin/CheckUpdate/CheckUpdate.php index 85ea1b2..4e3dcf1 100644 --- a/plugin/CheckUpdate/CheckUpdate.php +++ b/plugin/CheckUpdate/CheckUpdate.php @@ -30,7 +30,7 @@ class CheckUpdate extends BasePluginRW * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'CheckUpdate', // 插件名称 'version' => '0.0.1', // 插件版本 diff --git a/plugin/DailyGold/DailyGold.php b/plugin/DailyGold/DailyGold.php index f72c77b..bc6aa75 100644 --- a/plugin/DailyGold/DailyGold.php +++ b/plugin/DailyGold/DailyGold.php @@ -29,7 +29,7 @@ class DailyGold extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'DailyGold', // 插件名称 'version' => '0.0.1', // 插件版本 diff --git a/plugin/GameForecast/GameForecast.php b/plugin/GameForecast/GameForecast.php index 7f2f2b4..9d60b39 100644 --- a/plugin/GameForecast/GameForecast.php +++ b/plugin/GameForecast/GameForecast.php @@ -27,7 +27,7 @@ class GameForecast extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'GameForecast', // 插件名称 'version' => '0.0.1', // 插件版本 diff --git a/plugin/Judge/Judge.php b/plugin/Judge/Judge.php index 8279003..a0c12a9 100644 --- a/plugin/Judge/Judge.php +++ b/plugin/Judge/Judge.php @@ -28,7 +28,7 @@ class Judge extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'Judge', // 插件名称 'version' => '0.0.1', // 插件版本 diff --git a/plugin/LiveGoldBox/LiveGoldBox.php b/plugin/LiveGoldBox/LiveGoldBox.php index 8ff6566..0f36206 100644 --- a/plugin/LiveGoldBox/LiveGoldBox.php +++ b/plugin/LiveGoldBox/LiveGoldBox.php @@ -30,7 +30,7 @@ class LiveGoldBox extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'LiveGoldBox', // 插件名称 'version' => '0.0.1', // 插件版本 diff --git a/plugin/LiveReservation/LiveReservation.php b/plugin/LiveReservation/LiveReservation.php index ce474a4..1e54a29 100644 --- a/plugin/LiveReservation/LiveReservation.php +++ b/plugin/LiveReservation/LiveReservation.php @@ -27,7 +27,7 @@ class LiveReservation extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'LiveReservation', // 插件名称 'version' => '0.0.1', // 插件版本 diff --git a/plugin/LiveSignIn/LiveSignIn.php b/plugin/LiveSignIn/LiveSignIn.php index 029ad6d..2a411fa 100644 --- a/plugin/LiveSignIn/LiveSignIn.php +++ b/plugin/LiveSignIn/LiveSignIn.php @@ -28,7 +28,7 @@ class LiveSignIn extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'LiveSignIn', // 插件名称 'version' => '0.0.1', // 插件版本 diff --git a/plugin/Login/Login.php b/plugin/Login/Login.php index 43a836e..882229d 100644 --- a/plugin/Login/Login.php +++ b/plugin/Login/Login.php @@ -36,7 +36,7 @@ class Login extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'Login', // 插件名称 'version' => '0.0.1', // 插件版本 diff --git a/plugin/Lottery/Lottery.php b/plugin/Lottery/Lottery.php index b1aaddc..f45ad08 100644 --- a/plugin/Lottery/Lottery.php +++ b/plugin/Lottery/Lottery.php @@ -34,14 +34,14 @@ class Lottery extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'Lottery', // 插件名称 'version' => '0.0.2', // 插件版本 'desc' => '抽奖', // 插件描述 'author' => 'MoeHero/Lkeme',// 作者 'priority' => 1113, // 插件优先级 - 'cycle' => '2-6(小时)', // 运行周期 + 'cycle' => '10-25(分钟)', // 运行周期 ]; /** @@ -87,8 +87,8 @@ class Lottery extends BasePlugin $this->handleLottery($global_uid); // $this->saveConfig(); - // 2-6小时 未完成6-10秒 - TimeLock::setTimes(mt_rand(6, 16) * 60); + // 10-25分钟 + TimeLock::setTimes(mt_rand(10, 25) * 60); } /** diff --git a/plugin/LoveClub/LoveClub.php b/plugin/LoveClub/LoveClub.php index d5c59a9..4ac54f7 100644 --- a/plugin/LoveClub/LoveClub.php +++ b/plugin/LoveClub/LoveClub.php @@ -28,7 +28,7 @@ class LoveClub extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'LoveClub', // 插件名称 'version' => '0.0.1', // 插件版本 diff --git a/plugin/MainSite/MainSite.php b/plugin/MainSite/MainSite.php index 7163a8f..51a6acc 100644 --- a/plugin/MainSite/MainSite.php +++ b/plugin/MainSite/MainSite.php @@ -41,7 +41,7 @@ class MainSite extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'MainSite', // 插件名称 'version' => '0.0.1', // 插件版本 diff --git a/plugin/Manga/Manga.php b/plugin/Manga/Manga.php index 27ddc72..7863bbb 100644 --- a/plugin/Manga/Manga.php +++ b/plugin/Manga/Manga.php @@ -28,7 +28,7 @@ class Manga extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'Manga', // 插件名称 'version' => '0.0.1', // 插件版本 diff --git a/plugin/PluginTemplate/PluginTemplate.php b/plugin/PluginTemplate/PluginTemplate.php index 076069a..c1622e7 100644 --- a/plugin/PluginTemplate/PluginTemplate.php +++ b/plugin/PluginTemplate/PluginTemplate.php @@ -25,7 +25,7 @@ class PluginTemplate extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'PluginTemplate', // 插件名称 'version' => '0.0.1', // 插件版本 @@ -33,9 +33,9 @@ class PluginTemplate extends BasePlugin 'author' => 'Lkeme',// 作者 'priority' => 9999, // 插件优先级 'cycle' => '1(小时)', // 运行周期 - // 新增字段 - 'start' => '08:00:00', // 插件开始日期 - 'end' => '23:00:00', // 插件结束日期 + // 新增字段|时间段限制|默认全天运行 + // 'start' => '08:00:00', // 插件运行开始时间 + // 'end' => '23:00:00', // 插件运行结束时间 ]; /** @@ -57,8 +57,6 @@ class PluginTemplate extends BasePlugin */ public function execute(): void { - // 时间段限制 - // if (!TimeLock::isWithinTimeRange($this->info['start'], $this->info['end'])) return; // 时间锁限制 // if (TimeLock::getTimes() > time()) return; diff --git a/plugin/PolishMedal/PolishMedal.php b/plugin/PolishMedal/PolishMedal.php index 3272da7..e41ed5c 100644 --- a/plugin/PolishMedal/PolishMedal.php +++ b/plugin/PolishMedal/PolishMedal.php @@ -31,7 +31,7 @@ class PolishMedal extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'PolishMedal', // 插件名称 'version' => '0.0.1', // 插件版本 diff --git a/plugin/Silver2Coin/Silver2Coin.php b/plugin/Silver2Coin/Silver2Coin.php index 3515312..6f2a74e 100644 --- a/plugin/Silver2Coin/Silver2Coin.php +++ b/plugin/Silver2Coin/Silver2Coin.php @@ -28,7 +28,7 @@ class Silver2Coin extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'Silver2Coin', // 插件名称 'version' => '0.0.1', // 插件版本 diff --git a/plugin/VipPoint/VipPoint.php b/plugin/VipPoint/VipPoint.php index 5d49580..aebbb0b 100644 --- a/plugin/VipPoint/VipPoint.php +++ b/plugin/VipPoint/VipPoint.php @@ -47,7 +47,7 @@ class VipPoint extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'VipPoint', // 插件名称 'version' => '0.0.1', // 插件版本 diff --git a/plugin/VipPrivilege/VipPrivilege.php b/plugin/VipPrivilege/VipPrivilege.php index 63297d6..fb4d1b4 100644 --- a/plugin/VipPrivilege/VipPrivilege.php +++ b/plugin/VipPrivilege/VipPrivilege.php @@ -29,7 +29,7 @@ class VipPrivilege extends BasePlugin * 插件信息 * @var array|string[] */ - protected ?array $info = [ + public ?array $info = [ 'hook' => __CLASS__, // hook 'name' => 'VipPrivilege', // 插件名称 'version' => '0.0.1', // 插件版本 diff --git a/src/Plugin/BasePluginInfo.php b/src/Plugin/BasePluginInfo.php index 7d3f83a..90c09bd 100644 --- a/src/Plugin/BasePluginInfo.php +++ b/src/Plugin/BasePluginInfo.php @@ -31,6 +31,8 @@ trait BasePluginInfo 'author' => 'Lkeme',// 作者 'priority' => 0, // 插件优先级 'cycle' => 'cycle', // 运行周期 + 'start' => '07:00:00', // 插件运行开始时间 + 'end' => '23:00:00', // 插件运行结束时间 ]; /** @@ -50,6 +52,30 @@ trait BasePluginInfo return $this; } + /** + * 设置运行周期 + * @param string $value + * @param string $key + * @return $this + */ + protected function setStart(string $value, string $key = 'start'): static + { + $this->info[$key] = $value; + return $this; + } + + /** + * 设置运行周期 + * @param string $value + * @param string $key + * @return $this + */ + protected function setEnd(string $value, string $key = 'end'): static + { + $this->info[$key] = $value; + return $this; + } + /** * 设置名称 * @param string $value diff --git a/src/Plugin/Plugin.php b/src/Plugin/Plugin.php index 067a758..911e930 100644 --- a/src/Plugin/Plugin.php +++ b/src/Plugin/Plugin.php @@ -17,6 +17,8 @@ namespace Bhp\Plugin; +use Bhp\Log\Log; +use Bhp\TimeLock\TimeLock; use Bhp\Util\AsciiTable\AsciiTable; use Bhp\Util\DesignPattern\SingleTon; @@ -91,6 +93,9 @@ class Plugin extends SingleTon $class = &$staff[0]; // 引用过来的类 $method = $staff[1]; // 类下面的方法 if (method_exists($class, $method)) { + // + if (!$this->canItRun($class)) continue; + // $func_result = $class->$method(...$params); if (is_numeric($func_result)) { // 这里判断返回值是不是字符串,如果不是将不进行返回到页面上 @@ -240,4 +245,23 @@ class Plugin extends SingleTon } } + /** + * @param mixed $class + * @return bool + */ + protected function canItRun(mixed $class): bool + { + if (!isset($class->info['start']) || !isset($class->info['end'])) { + // Log::info("插件 {$class->info['name']} 全天运行"); + return true; + } + if (TimeLock::isWithinTimeRange($class->info['start'], $class->info['end'])) { + // Log::info("插件 {$class->info['name']} 运行时间段"); + return true; + } else { + // Log::info("插件 {$class->info['name']} 不在运行时间段"); + return false; + } + } + }