[fix] Backports PHP 8.1 fixes #148

This commit is contained in:
lkeme 2021-12-05 17:48:31 +08:00
parent ab4423a3f0
commit a4eaa63b6d
47 changed files with 465 additions and 85 deletions

2
.gitignore vendored
View File

@ -16,7 +16,6 @@ gen
/vendor/ /vendor/
composer.lock composer.lock
/configs/ /configs/
/tests/
config config
/conf/user*.ini /conf/user*.ini
*.log *.log
@ -29,7 +28,6 @@ conf/user1.ini
/conf/test1.ini /conf/test1.ini
/src/backup/ /src/backup/
script.php script.php
ABOUT.md
task/* task/*
cache/* cache/*

1
ABOUT.md Normal file
View File

@ -0,0 +1 @@
哔哩哔哩BilibiliB 站主站助手、直播助手、直播抽奖、挂机升级、贴心小棉袄脚本、Lv6 离你仅有一步之遥~ - PHP 版Personal

View File

@ -23,7 +23,7 @@
</p> </p>
## 公告通知 ## 📌公告通知
代码开源本地化99.9%,项目不收集或使用任何敏感信息,兴趣所致,一切只为学习。 代码开源本地化99.9%,项目不收集或使用任何敏感信息,兴趣所致,一切只为学习。
@ -32,7 +32,13 @@
---- 只有花大价钱去买到的东西,才会令人信任。 ---- 只有花大价钱去买到的东西,才会令人信任。
``` ```
## 打赏支持 ## 👤游客访问
<p align="center">
<img alingn="center" src="https://profile-counter.glitch.me/BiliHelper-personal/count.svg" />
</p>
## 🎁打赏支持
如果觉得本项目好用,对你有所帮助,欢迎打赏支持本项目哦。 如果觉得本项目好用,对你有所帮助,欢迎打赏支持本项目哦。
@ -40,7 +46,23 @@
[comment]: <> (![Image]&#40;https://i.loli.net/2019/07/13/5d2963e5cc1eb22973.png&#41;) [comment]: <> (![Image]&#40;https://i.loli.net/2019/07/13/5d2963e5cc1eb22973.png&#41;)
## 功能组件 ## 🖨️相关文档
有疑问一定要先看看文档或Issue里是否存在相同的问题再考虑其他渠道咨询。
[comment]: <> (:cherry_blossom: :gift: :gift_heart: :confetti_ball:)
* [使用文档 / DOC.md](./DOC.md)
* [推送文档 / DOC.md](./NOTIFY.md)
* [更新日志 / CHANGELOG.md](./CHANGELOG.md)
* [配置文档 / WIKI.md](https://github.com/lkeme/BiliHelper-personal/wiki/%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E8%AF%A6%E8%A7%A3)
* [常见问题 / WIKI.md](https://github.com/lkeme/BiliHelper-personal/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98)
## 💬交流反馈
Group: [163955623](https://jq.qq.com/?_wv=1027&k=1QMFTUEO) | **请不要来问如何使用, 文档齐全, 仅用于BUG提交反馈**
## 🧑‍🏭功能组件
以下任务都是按设定周期自动执行,`true`为正常使用,`false`为暂停使用或抛弃。 以下任务都是按设定周期自动执行,`true`为正常使用,`false`为暂停使用或抛弃。
@ -83,21 +105,6 @@
| LiveReservation | true | 21.11.15 | 待整理 | 直播预约有奖 | | LiveReservation | true | 21.11.15 | 待整理 | 直播预约有奖 |
| Silver | false | 21.03.27 | 待整理 | 直播银瓜子自动开启宝箱 | | Silver | false | 21.03.27 | 待整理 | 直播银瓜子自动开启宝箱 |
## 交流反馈
Group: [163955623](https://jq.qq.com/?_wv=1027&k=1QMFTUEO) | **请不要来问如何使用, 文档齐全, 仅用于BUG提交反馈**
## 相关文档
有疑问一定要先看看文档或Issue里是否存在相同的问题再考虑其他渠道咨询。
[comment]: <> (:cherry_blossom: :gift: :gift_heart: :confetti_ball:)
* [使用文档 / DOC.md](./DOC.md)
* [推送文档 / DOC.md](./NOTIFY.md)
* [更新日志 / CHANGELOG.md](./CHANGELOG.md)
* [配置文档 / WIKI.md](https://github.com/lkeme/BiliHelper-personal/wiki/%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E8%AF%A6%E8%A7%A3)
* [常见问题 / WIKI.md](https://github.com/lkeme/BiliHelper-personal/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98)
## 🖥️星图 ## 🖥️星图

View File

@ -14,17 +14,16 @@
"bramus/monolog-colored-line-formatter": "^2.0.3", "bramus/monolog-colored-line-formatter": "^2.0.3",
"clue/socket-raw": "^1.5.0", "clue/socket-raw": "^1.5.0",
"amphp/amp": "^2.5.2", "amphp/amp": "^2.5.2",
"guzzlehttp/guzzle": "^6.5.5", "guzzlehttp/guzzle": "^7.4.0",
"mathieuviossat/arraytotexttable": "^1.0.8", "overtrue/pinyin": "~4.0",
"klkvsk/json-decode-stream": "^1.0",
"sven/file-config": "^3.1",
"hassankhan/config": "^2.2",
"lkeme/inifile": "^3.4",
"adhocore/cli": "^0.9.0", "adhocore/cli": "^0.9.0",
"lkeme/inifile": "^3.4",
"symfony/yaml": "^6.0",
"sven/file-config": "^3.1",
"fire015/flintstone": "^2.3", "fire015/flintstone": "^2.3",
"symfony/yaml": "^5.3",
"consolidation/config": "^2.0", "consolidation/config": "^2.0",
"overtrue/pinyin": "~4.0" "lkeme/data": "dev-master",
"phppkg/config": "^1.1"
}, },
"license": "MIT", "license": "MIT",
"authors": [ "authors": [

View File

@ -3,8 +3,8 @@ bili_version: 0.0.1
# Android # Android
bili_a: bili_a:
package: "tv.danmaku.bili" package: "tv.danmaku.bili"
version: "6.48.0" version: "6.51.0"
build: "6480300" build: "6510400"
channel: "bili" channel: "bili"
device: "phone" device: "phone"
mobi_app: "android" mobi_app: "android"

View File

@ -27,6 +27,7 @@ class App
*/ */
public function __construct(string $app_path) public function __construct(string $app_path)
{ {
define('APP_MICROSECOND', 1000000);
define('APP_CONF_PATH', $app_path . '/conf/'); define('APP_CONF_PATH', $app_path . '/conf/');
define('APP_DATA_PATH', $app_path . '/data/'); define('APP_DATA_PATH', $app_path . '/data/');
define('APP_LOG_PATH', $app_path . '/log/'); define('APP_LOG_PATH', $app_path . '/log/');

View File

@ -10,7 +10,7 @@
namespace BiliHelper\Core; namespace BiliHelper\Core;
use Noodlehaus\Config; use function JBZoo\Data\json;
class Env class Env
{ {
@ -78,10 +78,10 @@ class Env
*/ */
private function loadJsonData() private function loadJsonData()
{ {
$conf = new Config($this->repository); $conf = json($this->repository);
$this->app_name = $conf->get('project'); $this->app_name = $conf->get('project', 'BiliHelper-personal');
$this->app_version = $conf->get('version'); $this->app_version = $conf->get('version', '0.0.0.000000');
$this->app_branch = $conf->get('branch'); $this->app_branch = $conf->get('branch', 'master');
$this->app_source = $conf->get('source'); $this->app_source = $conf->get('source', 'https://github.com/lkeme/BiliHelper-personal');
} }
} }

View File

@ -23,10 +23,7 @@ class ActivityLottery
private static string $repository = APP_DATA_PATH . 'activity_infos.json'; private static string $repository = APP_DATA_PATH . 'activity_infos.json';
/** /**
* @throws \JsonDecodeStream\Exception\TokenizerException * @use run
* @throws \JsonDecodeStream\Exception\SelectorException
* @throws \JsonDecodeStream\Exception\CollectorException
* @throws \JsonDecodeStream\Exception\ParserException
*/ */
public static function run() public static function run()
{ {
@ -44,10 +41,6 @@ class ActivityLottery
/** /**
* @use 分配任务 * @use 分配任务
* @return bool * @return bool
* @throws \JsonDecodeStream\Exception\CollectorException
* @throws \JsonDecodeStream\Exception\ParserException
* @throws \JsonDecodeStream\Exception\SelectorException
* @throws \JsonDecodeStream\Exception\TokenizerException
*/ */
private static function allotTasks(): bool private static function allotTasks(): bool
{ {
@ -55,7 +48,9 @@ class ActivityLottery
return false; return false;
} }
$parser = self::loadJsonData(); $parser = self::loadJsonData();
foreach ($parser->items('data[]') as $act) { foreach ($parser->get('data', []) as $act) {
// todo 优化处理
$act = json_decode(json_encode($act));
// 活动无效 // 活动无效
if (is_null($act->sid)) { if (is_null($act->sid)) {
continue; continue;

View File

@ -28,7 +28,7 @@ class AloneTcpClient
private static int $max_errors_num = 0; // 最大连续错误5次 private static int $max_errors_num = 0; // 最大连续错误5次
/** /**
* @use 入口 * @use run
*/ */
public static function run() public static function run()
{ {

View File

@ -25,6 +25,9 @@ class AwardRecord
private static int $gift_lock = 0; private static int $gift_lock = 0;
private static array $gift_list = []; private static array $gift_list = [];
/**
* @use run
*/
public static function run() public static function run()
{ {
if (self::getLock() > time() || !getEnable('award_record')) { if (self::getLock() > time() || !getEnable('award_record')) {

View File

@ -19,6 +19,9 @@ class Barrage
{ {
use TimeLock; use TimeLock;
/**
* @use run
*/
public static function run() public static function run()
{ {
if (self::getLock() > time() || !getEnable('barrage')) { if (self::getLock() > time() || !getEnable('barrage')) {

View File

@ -20,6 +20,9 @@ class BpConsumption
use TimeLock; use TimeLock;
/**
* @use run
*/
public static function run() public static function run()
{ {
if (self::getLock() > time() || !getEnable('bp_consumption')) { if (self::getLock() > time() || !getEnable('bp_consumption')) {

View File

@ -29,10 +29,7 @@ class CapsuleLottery
/** /**
* @throws \JsonDecodeStream\Exception\TokenizerException * @use run
* @throws \JsonDecodeStream\Exception\SelectorException
* @throws \JsonDecodeStream\Exception\ParserException
* @throws \JsonDecodeStream\Exception\CollectorException
*/ */
public static function run() public static function run()
{ {
@ -50,10 +47,6 @@ class CapsuleLottery
/** /**
* @use 分配任务 * @use 分配任务
* @return bool * @return bool
* @throws \JsonDecodeStream\Exception\CollectorException
* @throws \JsonDecodeStream\Exception\ParserException
* @throws \JsonDecodeStream\Exception\SelectorException
* @throws \JsonDecodeStream\Exception\TokenizerException
*/ */
private static function allotTasks(): bool private static function allotTasks(): bool
{ {
@ -61,7 +54,10 @@ class CapsuleLottery
return false; return false;
} }
$parser = self::loadJsonData(); $parser = self::loadJsonData();
foreach ($parser->items('data[]') as $act) { // Converting to array
foreach ($parser->get('data', []) as $act) {
// todo 优化处理
$act = json_decode(json_encode($act));
// 活动无效 // 活动无效
if (is_null($act->coin_id)) { if (is_null($act->coin_id)) {
continue; continue;
@ -248,7 +244,7 @@ class CapsuleLottery
Log::info("获取剩余抽奖次数成功 {$capsule_info['data']['coin']}"); Log::info("获取剩余抽奖次数成功 {$capsule_info['data']['coin']}");
return $capsule_info['data']['coin']; return $capsule_info['data']['coin'];
} }
Log::warning("获取剩余抽奖次数失败 $capsule_info"); Log::warning("获取剩余抽奖次数失败 " . json_encode($capsule_info, true));
return 0; return 0;
} }

View File

@ -10,11 +10,10 @@
namespace BiliHelper\Plugin; namespace BiliHelper\Plugin;
use Noodlehaus\Config;
use Noodlehaus\Parser\Json;
use BiliHelper\Core\Log; use BiliHelper\Core\Log;
use BiliHelper\Core\Curl; use BiliHelper\Core\Curl;
use BiliHelper\Util\TimeLock; use BiliHelper\Util\TimeLock;
use function JBZoo\Data\json;
class CheckUpdate class CheckUpdate
{ {
@ -24,7 +23,9 @@ class CheckUpdate
private static object $latest_conf; private static object $latest_conf;
private static string $repository = APP_DATA_PATH . 'latest_version.json'; private static string $repository = APP_DATA_PATH . 'latest_version.json';
/**
* @use run
*/
public static function run() public static function run()
{ {
if (self::getLock() > time()) { if (self::getLock() > time()) {
@ -77,7 +78,7 @@ class CheckUpdate
$url = self::$current_conf->get('raw_url'); $url = self::$current_conf->get('raw_url');
$payload = []; $payload = [];
$raw = Curl::get('other', $url, $payload); $raw = Curl::get('other', $url, $payload);
self::$latest_conf = Config::load($raw, new Json, true); self::$latest_conf = json(json_decode($raw, true));
} }
/** /**
@ -85,7 +86,7 @@ class CheckUpdate
*/ */
private static function loadJsonData() private static function loadJsonData()
{ {
self::$current_conf = Config::load(self::$repository); self::$current_conf = json(self::$repository);
} }
/** /**

View File

@ -19,7 +19,8 @@ class Competition
use TimeLock; use TimeLock;
/** /**
* @use 赛事入口 https://www.bilibili.com/v/game/match/competition * @use run
* @doc 赛事入口 https://www.bilibili.com/v/game/match/competition
*/ */
public static function run() public static function run()
{ {

View File

@ -18,6 +18,9 @@ class DailyBag
{ {
use TimeLock; use TimeLock;
/**
* @use run
*/
public static function run() public static function run()
{ {
if (self::getLock() > time() || !getEnable('daily_bag')) { if (self::getLock() > time() || !getEnable('daily_bag')) {

View File

@ -18,6 +18,9 @@ class DailyTask
{ {
use TimeLock; use TimeLock;
/**
* @use run
*/
public static function run() public static function run()
{ {
if (self::getLock() > time() || !getEnable('daily_task')) { if (self::getLock() > time() || !getEnable('daily_task')) {
@ -72,6 +75,7 @@ class DailyTask
$payload = []; $payload = [];
$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":1011040,"message":"今日已签到过,无法重复签到","ttl":1,"data":null} // {"code":1011040,"message":"今日已签到过,无法重复签到","ttl":1,"data":null}
// {"code":0,"message":"0","ttl":1,"data":{"text":"3000点用户经验,2根辣条","specialText":"再签到3天可以获得666银瓜子","allDays":31,"hadSignDays":2,"isBonusDay":0}} // {"code":0,"message":"0","ttl":1,"data":{"text":"3000点用户经验,2根辣条","specialText":"再签到3天可以获得666银瓜子","allDays":31,"hadSignDays":2,"isBonusDay":0}}
// {"code":0,"message":"0","ttl":1,"data":{"text":"3000点用户经验,2根辣条,50根辣条","specialText":"","allDays":31,"hadSignDays":20,"isBonusDay":1}} // {"code":0,"message":"0","ttl":1,"data":{"text":"3000点用户经验,2根辣条,50根辣条","specialText":"","allDays":31,"hadSignDays":20,"isBonusDay":1}}

View File

@ -18,6 +18,9 @@ class DoubleHeart
{ {
use TimeLock; use TimeLock;
/**
* @use run
*/
public static function run() public static function run()
{ {
if (self::getLock() > time() || !getEnable('double_heart')) { if (self::getLock() > time() || !getEnable('double_heart')) {

View File

@ -21,7 +21,7 @@ namespace BiliHelper\Plugin;
use BiliHelper\Core\Log; use BiliHelper\Core\Log;
use BiliHelper\Util\TimeLock; use BiliHelper\Util\TimeLock;
use Noodlehaus\Config; use function JBZoo\Data\json;
class Forward class Forward
{ {
@ -42,7 +42,9 @@ class Forward
private static string $repository = APP_DATA_PATH . 'reply_words.json'; private static string $repository = APP_DATA_PATH . 'reply_words.json';
/**
* @use run
*/
public static function run() public static function run()
{ {
@ -270,8 +272,9 @@ class Forward
*/ */
private static function getReplyMsgList(): array private static function getReplyMsgList(): array
{ {
$data = Config::load(self::$repository); $data = json(self::$repository);
$data = $data->get("DynamicForward.default"); // 给个默认值
$data = $data->find("DynamicForward.default", []);
array_push($data, getConf('auto_reply_text', 'dynamic')); array_push($data, getConf('auto_reply_text', 'dynamic'));
return $data; return $data;
} }

View File

@ -18,6 +18,9 @@ class GiftHeart
{ {
use TimeLock; use TimeLock;
/**
* @use run
*/
public static function run() public static function run()
{ {
if (self::getLock() > time() || !getEnable('gift_heart')) { if (self::getLock() > time() || !getEnable('gift_heart')) {

View File

@ -100,7 +100,7 @@ class GiftRaffle extends BaseRaffle
* @param array $results * @param array $results
* @return mixed * @return mixed
*/ */
protected static function parseLottery(array $results):mixed protected static function parseLottery(array $results): mixed
{ {
foreach ($results as $result) { foreach ($results as $result) {
$data = $result['source']; $data = $result['source'];

View File

@ -26,7 +26,9 @@ class GiftSend
protected static array $room_list = []; protected static array $room_list = [];
protected static array $medal_list = []; protected static array $medal_list = [];
/**
* @use run
*/
public static function run() public static function run()
{ {
if (self::getLock() > time() || !self::inTime('23:50:00', '23:59:50')) { if (self::getLock() > time() || !self::inTime('23:50:00', '23:59:50')) {

View File

@ -18,6 +18,9 @@ class GroupSignIn
{ {
use TimeLock; use TimeLock;
/**
* @use run
*/
public static function run() public static function run()
{ {
if (self::getLock() > time() || !getEnable('love_club')) { if (self::getLock() > time() || !getEnable('love_club')) {

View File

@ -114,7 +114,7 @@ class GuardRaffle extends BaseRaffle
* @param array $results * @param array $results
* @return mixed * @return mixed
*/ */
protected static function parseLottery(array $results):mixed protected static function parseLottery(array $results): mixed
{ {
foreach ($results as $result) { foreach ($results as $result) {
$data = $result['source']; $data = $result['source'];

View File

@ -36,6 +36,9 @@ class Judge
private static array $wait_case = []; private static array $wait_case = [];
/**
* @use run
*/
public static function run() public static function run()
{ {
// 基础判断 // 基础判断

View File

@ -18,7 +18,9 @@ class LiveReservation
{ {
use TimeLock; use TimeLock;
/**
* @use run
*/
public static function run() public static function run()
{ {
if (self::getLock() > time() || !getEnable('live_reservation')) { if (self::getLock() > time() || !getEnable('live_reservation')) {
@ -93,10 +95,12 @@ class LiveReservation
$de_raw = json_decode($raw, true); $de_raw = json_decode($raw, true);
// {"code":0,"message":"0","ttl":1,"data":[{"sid":253672,"name":"直播预约:创世之音-虚拟偶像演唱会","total":6382,"stime":1636716437,"etime":1637408100,"is_follow":1,"state":100,"oid":"","type":2,"up_mid":9617619,"reserve_record_ctime":1636731801,"live_plan_start_time":1637406000,"lottery_type":1,"lottery_prize_info":{"text":"预约有奖:小电视年糕抱枕、哔哩哔哩小电视樱花毛绒抱枕大号、哔哩哔哩小夜灯","lottery_icon":"https://i0.hdslb.com/bfs/activity-plat/static/ce06d65bc0a8d8aa2a463747ce2a4752/rgHplMQyiX.png","jump_url":"https://www.bilibili.com/h5/lottery/result?business_id=253672\u0026business_type=10\u0026lottery_id=76240"},"show_total":true,"subtitle":""},{"sid":246469,"name":"直播预约:创世之音-YuNi个人演唱会","total":3555,"stime":1636367836,"etime":1637494500,"is_follow":0,"state":100,"oid":"","type":2,"up_mid":9617619,"reserve_record_ctime":0,"live_plan_start_time":1637492400,"show_total":true,"subtitle":""}]} // {"code":0,"message":"0","ttl":1,"data":[{"sid":253672,"name":"直播预约:创世之音-虚拟偶像演唱会","total":6382,"stime":1636716437,"etime":1637408100,"is_follow":1,"state":100,"oid":"","type":2,"up_mid":9617619,"reserve_record_ctime":1636731801,"live_plan_start_time":1637406000,"lottery_type":1,"lottery_prize_info":{"text":"预约有奖:小电视年糕抱枕、哔哩哔哩小电视樱花毛绒抱枕大号、哔哩哔哩小夜灯","lottery_icon":"https://i0.hdslb.com/bfs/activity-plat/static/ce06d65bc0a8d8aa2a463747ce2a4752/rgHplMQyiX.png","jump_url":"https://www.bilibili.com/h5/lottery/result?business_id=253672\u0026business_type=10\u0026lottery_id=76240"},"show_total":true,"subtitle":""},{"sid":246469,"name":"直播预约:创世之音-YuNi个人演唱会","total":3555,"stime":1636367836,"etime":1637494500,"is_follow":0,"state":100,"oid":"","type":2,"up_mid":9617619,"reserve_record_ctime":0,"live_plan_start_time":1637492400,"show_total":true,"subtitle":""}]}
if (!$de_raw['code']) { if (!$de_raw['code']) {
foreach ($de_raw['data'] as $data) { // data == NULL
$de_data = $de_raw['data'] ?: [];
foreach ($de_data as $data) {
$result = self::checkLottery($data); $result = self::checkLottery($data);
if (!$result) continue; if (!$result) continue;
array_push($reservation_list, $result); $reservation_list[] = $result;
} }
} else { } else {
Log::warning("获取预约列表失败: $raw"); Log::warning("获取预约列表失败: $raw");

View File

@ -25,6 +25,7 @@ class Login
private static string $password; private static string $password;
/** /**
* @use run
* @throws \Jelix\IniFile\IniException * @throws \Jelix\IniFile\IniException
*/ */
public static function run() public static function run()

View File

@ -19,6 +19,9 @@ class MainSite
{ {
use TimeLock; use TimeLock;
/**
* @use run
*/
public static function run() public static function run()
{ {
if (self::getLock() > time() || !getEnable('main_site')) { if (self::getLock() > time() || !getEnable('main_site')) {
@ -53,6 +56,9 @@ class MainSite
]; ];
// {"code":34005,"message":"超过投币上限啦~","ttl":1,"data":{"like":false}} // {"code":34005,"message":"超过投币上限啦~","ttl":1,"data":{"like":false}}
// {"code":0,"message":"0","ttl":1,"data":{"like":false}} // {"code":0,"message":"0","ttl":1,"data":{"like":false}}
// CODE -> 137001 MSG -> 账号封禁中,无法完成操作
// CODE -> -650 MSG -> 用户等级太低
$raw = Curl::post('app', $url, Sign::common($payload), $headers); $raw = Curl::post('app', $url, Sign::common($payload), $headers);
$de_raw = json_decode($raw, true); $de_raw = json_decode($raw, true);
if ($de_raw['code'] == 0) { if ($de_raw['code'] == 0) {

View File

@ -18,6 +18,9 @@ class ManGa
{ {
use TimeLock; use TimeLock;
/**
* @use run
*/
public static function run() public static function run()
{ {
if (self::getLock() > time() || !getEnable('manga')) { if (self::getLock() > time() || !getEnable('manga')) {

View File

@ -24,6 +24,9 @@ class MaterialObject
private static int $start_aid = 0; private static int $start_aid = 0;
private static int $end_aid = 0; private static int $end_aid = 0;
/**
* @use run
*/
public static function run() public static function run()
{ {
if (self::getLock() > time() || !getEnable('live_box')) { if (self::getLock() > time() || !getEnable('live_box')) {

View File

@ -97,7 +97,7 @@ class PkRaffle extends BaseRaffle
* @param array $results * @param array $results
* @return mixed * @return mixed
*/ */
protected static function parseLottery(array $results):mixed protected static function parseLottery(array $results): mixed
{ {
foreach ($results as $result) { foreach ($results as $result) {
$data = $result['source']; $data = $result['source'];

View File

@ -23,6 +23,7 @@ class PolishTheMedal
private static array $grey_fans_medals = []; // 灰色勋章 private static array $grey_fans_medals = []; // 灰色勋章
/** /**
* @use run
*/ */
public static function run() public static function run()
{ {

View File

@ -36,7 +36,9 @@ class Schedule
// 暂定不做处理 大会员类 // 暂定不做处理 大会员类
private static array $guarded_fifth = ['VipPrivilege', 'BpConsumption']; private static array $guarded_fifth = ['VipPrivilege', 'BpConsumption'];
/**
* @use run
*/
public static function run() public static function run()
{ {
if (self::getLock() > time()) { if (self::getLock() > time()) {

View File

@ -20,6 +20,9 @@ class Silver
protected static array $task = []; protected static array $task = [];
/**
* @use run
*/
public static function run() public static function run()
{ {
if (self::getLock() > time()) { if (self::getLock() > time()) {

View File

@ -18,6 +18,9 @@ class Silver2Coin
{ {
use TimeLock; use TimeLock;
/**
* @use run
*/
public static function run() public static function run()
{ {
if (self::getLock() > time() || !getEnable('silver2coin')) { if (self::getLock() > time() || !getEnable('silver2coin')) {
@ -37,7 +40,7 @@ class Silver2Coin
*/ */
protected static function appSilver2coin(): bool protected static function appSilver2coin(): bool
{ {
sleep(0.5); usleep(0.5 * APP_MICROSECOND);
$url = 'https://api.live.bilibili.com/AppExchange/silver2coin'; $url = 'https://api.live.bilibili.com/AppExchange/silver2coin';
$payload = []; $payload = [];
$raw = Curl::post('app', $url, Sign::common($payload)); $raw = Curl::post('app', $url, Sign::common($payload));
@ -53,7 +56,7 @@ class Silver2Coin
*/ */
protected static function pcSilver2coin(): bool protected static function pcSilver2coin(): bool
{ {
sleep(0.5); usleep(0.5 * APP_MICROSECOND);
$payload = [ $payload = [
'csrf_token' => getCsrf(), 'csrf_token' => getCsrf(),
'csrf' => getCsrf(), 'csrf' => getCsrf(),

View File

@ -24,6 +24,9 @@ class SmallHeart
private static int $total_time = 0; private static int $total_time = 0;
private static array|null $metal = null; private static array|null $metal = null;
/**
* @use run
*/
public static function run() public static function run()
{ {
if (!getEnable('small_heart')) { if (!getEnable('small_heart')) {

View File

@ -12,7 +12,7 @@ namespace BiliHelper\Plugin;
use BiliHelper\Core\Log; use BiliHelper\Core\Log;
use BiliHelper\Util\TimeLock; use BiliHelper\Util\TimeLock;
use MathieuViossat\Util\ArrayToTextTable; use BiliHelper\Tool\ArrayToTextTable;
class Statistics class Statistics
{ {
@ -23,7 +23,10 @@ class Statistics
private static array $success_list = []; private static array $success_list = [];
private static array $profit_list = []; private static array $profit_list = [];
// Todo 统计开关 统计时间间隔 统计类型 /**
* @use run
* @todo 统计开关 统计时间间隔 统计类型
*/
public static function run() public static function run()
{ {
if (self::getLock() > time()) { if (self::getLock() > time()) {

View File

@ -154,7 +154,7 @@ class StormRaffle extends BaseRaffle
* @param array $results * @param array $results
* @return mixed * @return mixed
*/ */
protected static function parseLottery(array $results):mixed protected static function parseLottery(array $results): mixed
{ {
foreach ($results as $result) { foreach ($results as $result) {
$data = $result['source']; $data = $result['source'];

View File

@ -24,6 +24,9 @@ class VipPrivilege
2 => '会员购优惠券' 2 => '会员购优惠券'
]; ];
/**
* @use run
*/
public static function run() public static function run()
{ {
if (self::getLock() > time() || !getEnable('vip_privilege')) { if (self::getLock() > time() || !getEnable('vip_privilege')) {

View File

@ -37,7 +37,7 @@ class ZoneTcpClient
/** /**
* @use 入口 * @use run
*/ */
public static function run() public static function run()
{ {

View File

@ -15,6 +15,9 @@ class DelDynamic extends BaseTask
{ {
public static string $description = '批量删除动态默认单次最大清理300个动态.'; public static string $description = '批量删除动态默认单次最大清理300个动态.';
/**
* @use run
*/
public static function run() public static function run()
{ {
Log::error('当前功能未完成'); Log::error('当前功能未完成');

View File

@ -17,6 +17,7 @@ class UnFollow extends BaseTask
public static string $description = '批量清理选定分组关注默认单次最大清理600个关注.'; public static string $description = '批量清理选定分组关注默认单次最大清理600个关注.';
/** /**
* @use run
* @throws \Exception * @throws \Exception
*/ */
public static function run() public static function run()

View File

@ -0,0 +1,222 @@
<?php
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2021 ~ 2022
* Source: EasySwoole\Utility\ArrayToTextTable;
*/
namespace BiliHelper\Tool;
class ArrayToTextTable
{
const AlignLeft = STR_PAD_RIGHT;
const AlignCenter = STR_PAD_BOTH;
const AlignRight = STR_PAD_LEFT;
protected array $data;
protected array $keys;
protected array $widths;
protected string $indentation;
protected bool $displayHeader = true;
protected int $keysAlignment;
protected int $valuesAlignment;
protected mixed $formatter;
public function __construct($data = [])
{
$this->setData($data)
->setIndentation('')
->setKeysAlignment(self::AlignCenter)
->setValuesAlignment(self::AlignLeft)
->setFormatter(null);
}
public function __toString()
{
return $this->getTable();
}
public function getTable($data = null): string
{
if (!is_null($data))
$this->setData($data);
$data = $this->prepare();
$i = $this->indentation;
$table = $i . $this->line('┌', '─', '┬', '┐') . PHP_EOL;
if ($this->displayHeader) {
//绘制table header
$headerRows = array_combine($this->keys, $this->keys);
$table .= $i . $this->row($headerRows, $this->keysAlignment) . PHP_EOL;
$table .= $i . $this->line('├', '─', '┼', '┤') . PHP_EOL;
}
foreach ($data as $row) {
$table .= $i . $this->row($row, $this->valuesAlignment) . PHP_EOL;
}
$table .= $i . $this->line('└', '─', '┴', '┘') . PHP_EOL;
return $table;
}
public function setIndentation($indentation): static
{
$this->indentation = $indentation;
return $this;
}
public function isDisplayHeader(bool $displayHeader): static
{
$this->displayHeader = $displayHeader;
return $this;
}
public function setKeysAlignment($keysAlignment): static
{
$this->keysAlignment = $keysAlignment;
return $this;
}
public function setValuesAlignment($valuesAlignment): static
{
$this->valuesAlignment = $valuesAlignment;
return $this;
}
public function setFormatter($formatter): static
{
$this->formatter = $formatter;
return $this;
}
private function line($left, $horizontal, $link, $right): string
{
$line = $left;
foreach ($this->keys as $key) {
$line .= str_repeat($horizontal, $this->widths[$key] + 2) . $link;
}
if (mb_strlen($line) > mb_strlen($left)) {
$line = mb_substr($line, 0, -mb_strlen($horizontal));
}
return $line . $right;
}
private function row($row, $alignment): string
{
$line = '│';
foreach ($this->keys as $key) {
$value = $row[$key] ?? '';
$line .= ' ' . static::mb_str_pad($value, $this->widths[$key], ' ', $alignment) . ' ' . '│';
}
if (empty($row)) {
$line .= '│';
}
return $line;
}
private function prepare(): array
{
$this->keys = [];
$this->widths = [];
$data = $this->data;
//合并全部数组的key
foreach ($data as $row) {
$this->keys = array_merge($this->keys, array_keys($row));
}
$this->keys = array_unique($this->keys);
//补充缺陷数组
foreach ($data as $index => $row) {
foreach ($this->keys as $key) {
if (!array_key_exists($key, $row)) {
$data[$index][$key] = null;
}
}
}
//执行formatter
if ($this->formatter instanceof \Closure) {
foreach ($data as &$row) {
array_walk($row, $this->formatter);
}
unset($row);
}
foreach ($this->keys as $key) {
$this->setWidth($key, $key);
}
foreach ($data as $row) {
foreach ($row as $columnKey => $columnValue) {
$this->setWidth($columnKey, $columnValue);
}
}
return $data;
}
private function setWidth($key, $value)
{
if (!isset($this->widths[$key])) {
$this->widths[$key] = 0;
}
// Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated
// Deprecated: mb_strlen(): Passing null to parameter #1 ($string) of type string is deprecated
$value = $value ?: '';
$width = (strlen($value) + mb_strlen($value, 'UTF8')) / 2;
if ($width > $this->widths[$key]) {
$this->widths[$key] = $width;
}
}
private static function countCJK($string): bool|int|null
{
return preg_match_all('/[\p{Han}\p{Katakana}\p{Hiragana}\p{Hangul}]/u', $string);
}
private function mb_str_pad($input, $pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT, $encoding = null): string
{
// $encoding = $encoding === null ? mb_internal_encoding() : $encoding;
// $diff = strlen($input) - (strlen($input) + mb_strlen($input, $encoding)) / 2;
// return str_pad($input, $pad_length + $diff, $pad_string, $pad_type);
// https://github.com/viossat/arraytotexttable/blob/6b1af924478cb9c3a903269e304fff006fe0dbf4/src/ArrayToTextTable.php#L255
$encoding = $encoding === null ? mb_internal_encoding() : $encoding;
$pad_before = $pad_type === STR_PAD_BOTH || $pad_type === STR_PAD_LEFT;
$pad_after = $pad_type === STR_PAD_BOTH || $pad_type === STR_PAD_RIGHT;
$pad_length -= mb_strlen($input, $encoding) + static::countCJK($input);
$target_length = $pad_before && $pad_after ? $pad_length / 2 : $pad_length;
$repeat_times = ceil($target_length / mb_strlen($pad_string, $encoding));
$repeated_string = str_repeat($pad_string, max(0, $repeat_times));
$before = $pad_before ? mb_substr($repeated_string, 0, floor($target_length), $encoding) : '';
$after = $pad_after ? mb_substr($repeated_string, 0, ceil($target_length), $encoding) : '';
return $before . $input . $after;
}
private function setData($data): static
{
if (!is_array($data)) {
$data = [];
}
$arrayData = [];
foreach ($data as $row) {
if (is_array($row)) {
$arrayData[] = $row;
} else if (is_object($row)) {
$arrayData[] = get_object_vars($row);
}
}
$this->data = $arrayData;
return $this;
}
}

37
src/tool/Path.php Normal file
View File

@ -0,0 +1,37 @@
<?php
/**
* Website: https://mudew.com/
* Author: Lkeme
* License: The MIT License
* Email: Useri@live.cn
* Updated: 2021 ~ 2022
* Source: https://github.com/anhao/bv2av/
*/
namespace BiliHelper\Tool;
class Path
{
public static function filename(string $path): string
{
return pathinfo($path)['filename'];
}
public static function extension(string $path): string
{
return pathinfo($path)['extension'];
}
public static function basename(string $path): string
{
return pathinfo($path)['basename'];
}
public static function dirname(string $path): string
{
return pathinfo($path)['dirname'];
}
}

View File

@ -10,8 +10,8 @@
namespace BiliHelper\Util; namespace BiliHelper\Util;
use JsonDecodeStream\Parser;
use stdClass; use stdClass;
use PhpPkg\Config\ConfigBox;
trait AllotTasks trait AllotTasks
@ -27,11 +27,10 @@ trait AllotTasks
/** /**
* @use 加载json数据 * @use 加载json数据
* @return Parser
*/ */
protected static function loadJsonData(): Parser protected static function loadJsonData(): ConfigBox
{ {
return Parser::fromFile(static::$repository); return ConfigBox::newFromFile(static::$repository);
} }
/** /**
@ -48,7 +47,7 @@ trait AllotTasks
'act' => $act, 'act' => $act,
'time' => $time 'time' => $time
]; ];
array_push(static::$tasks, $task); static::$tasks[] = $task;
return true; return true;
} }

View File

@ -30,6 +30,9 @@ abstract class BaseRaffle
protected static array $all_list; protected static array $all_list;
protected static array $banned_rids = []; protected static array $banned_rids = [];
/**
* @use run
*/
public static function run() public static function run()
{ {
if (!getEnable(static::ACTIVE_SWITCH)) { if (!getEnable(static::ACTIVE_SWITCH)) {

View File

@ -0,0 +1,48 @@
<?php
namespace BiliHelper\Tool;
use PHPUnit\Framework\TestCase;
class ArrayToTextTableTest extends TestCase
{
public function testGetTable()
{
$data = [
[
'firstname' => 'Mo 啊大苏打allie',
'surname' => 'Alv萨达速度asarez',
'email' => 'molliealvarez@example.com',
],
[
'firstname' => 'Dianna',
'surname' => 'Mcbride',
'age' => 1111,
'email' => 'diannamcbride@example.com',
],
[
'firstname' => '撒旦撒旦asra',
'surname' => 'Muel大大是打算的ler',
'age' => 50,
'email' => 'elviramueller@example.com',
],
[
'firstname' => 'Corine',
'surname' => 'Morton',
'age' => 0,
],
[
'firstname' => 'James',
'surname' => 'Allison',
],
[
'firstname' => 'Bowen这是哥',
'surname' => 'Kelley',
'age' => 50,
'email' => 'bowenkelley@example.com',
],
];
$renderer = new ArrayToTextTable($data);
echo $renderer->getTable();
}
}