From fa4ae37159038c35ce47c82d7a14d27d10606c0a Mon Sep 17 00:00:00 2001 From: Lkeme <19500576+lkeme@users.noreply.github.com> Date: Fri, 18 Feb 2022 10:31:16 +0800 Subject: [PATCH] [perf] tune-up --- CHANGELOG.md | 21 ++++++++- README.md | 83 ++++++++++++++++++---------------- conf/bili.yaml | 4 +- conf/user.ini.example | 3 +- data/latest_version.json | 6 +-- src/core/App.php | 1 - src/core/Curl.php | 6 +-- src/plugin/AnchorRaffle.php | 14 +++--- src/plugin/AwardRecord.php | 8 ++-- src/plugin/Competition.php | 2 +- src/plugin/DataTreating.php | 4 ++ src/plugin/Forward.php | 6 +-- src/plugin/GiftRaffle.php | 6 +-- src/plugin/GuardRaffle.php | 6 +-- src/plugin/Judge.php | 20 +++++--- src/plugin/Live.php | 38 ++++++++++++++-- src/plugin/Login.php | 2 +- src/plugin/MainSite.php | 10 ++-- src/plugin/MaterialObject.php | 8 ++-- src/plugin/Notice.php | 8 +++- src/plugin/PkRaffle.php | 9 ++-- src/plugin/RedPocketRaffle.php | 81 +++++++++++++++++++++++++++++++++ src/plugin/Schedule.php | 2 +- src/plugin/Statistics.php | 6 +-- src/plugin/StormRaffle.php | 2 +- src/plugin/User.php | 4 +- src/plugin/ZoneTcpClient.php | 22 +++++++-- src/tool/Faker.php | 4 +- src/tool/File.php | 2 +- src/util/BaseRaffle.php | 10 ++-- 30 files changed, 281 insertions(+), 117 deletions(-) create mode 100644 src/plugin/RedPocketRaffle.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 026a90d..f4dac13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,25 @@ [comment]: <> () +## v1.1.0.220218 alpha (2022-02-18) + +### Added + +- + +### Changed + +- + +### Fixed + +- + +### Remarks + +- 注意文档文件、配置文件有些许改动 +- + ## v1.0.2.211115 alpha (2021-11-15) ### Added @@ -250,7 +269,7 @@ ### Changed - 删除过期活动 -- 更新风纪委员 +- 更新風機委員 - 更新银瓜子兑换硬币 - 更新点亮勋章 - 更新部分日志打印输出 diff --git a/README.md b/README.md index 61a2ea9..afdd59c 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@

- + @@ -67,44 +67,49 @@ Group: [163955623](https://jq.qq.com/?_wv=1027&k=1QMFTUEO) | **请不要来问 以下任务都是按设定周期自动执行,`true`为正常使用,`false`为暂停使用或抛弃。 -| plugin | status | version | cycle | description | -|-----------------|--------|----------|--------|---------------------------------------------| -| CheckUpdate | true | 21.11.15 | 待整理 | 程序检查更新 | -| Login | true | 21.11.15 | 待整理 | 账号登录、刷新、维持 | -| Schedule | true | 21.11.15 | 待整理 | 控制插件运行周期 | -| MainSite | true | 21.11.15 | 待整理 | 投币、观看、分享视频 (速升6级不是梦) | -| DailyBag | true | 21.11.15 | 待整理 | 双端领取日常/周常礼包 | -| ManGa | true | 21.11.15 | 待整理 | 漫画签到、分享 | -| ActivityLottery | true | 21.11.15 | 待整理 | 主站活动九宫格抽奖 | -| Competition | true | 21.11.15 | 待整理 | 游戏赛事竞猜 | -| DoubleHeart | true | 21.11.15 | 待整理 | 双端心跳 (姥爷直播经验) | -| DailyTask | true | 21.11.15 | 待整理 | 直播每日任务(签到、观看) | -| Barrage | true | 21.11.15 | 待整理 | 保持活跃弹幕 | -| Silver2Coin | true | 21.11.15 | 待整理 | 银瓜子兑换硬币 | -| Judge | true | 21.11.15 | 待整理 | 风纪委员投票 | -| GiftSend | true | 21.11.15 | 待整理 | 礼物赠送、维持每日勋章亲密度 | -| GroupSignIn | true | 21.11.15 | 待整理 | 友爱社签到 | -| GiftHeart | true | 21.11.15 | 待整理 | 日常心跳每日礼包礼物 | -| SmallHeart | true | 21.11.15 | 待整理 | 直播挂机,每日24个小心心 | -| MaterialObject | true | 21.11.15 | 待整理 | 直播金色宝箱实物抽奖 | -| AloneTcpClient | true | 21.11.15 | 待整理 | 作者的独立直播监控(可支持本项目哦) | -| ZoneTcpClient | true | 21.11.15 | 待整理 | 官方的分区直播监控 | -| StormRaffle | true | 21.11.15 | 待整理 | 直播节奏风暴抽奖、亿元 | -| GiftRaffle | true | 21.11.15 | 待整理 | 直播礼物抽奖 | -| PkRaffle | true | 21.11.15 | 待整理 | 直播大乱斗抽奖 | -| GuardRaffle | true | 21.11.15 | 待整理 | 直播大航海抽奖 | -| AnchorRaffle | true | 21.11.15 | 待整理 | 直播天选时刻抽奖 | -| GiftRaffle | true | 21.11.15 | 待整理 | 直播礼物抽奖 | -| AwardRecord | true | 21.11.15 | 待整理 | 最新的中奖纪录通知 | -| Forward | true | 21.11.15 | 待整理 | 主站动态抽奖转发 | -| CapsuleLottery | true | 21.11.15 | 待整理 | 直播扭蛋活动抽奖 | -| PolishTheMedal | true | 21.11.15 | 待整理 | 每日自动点亮灰色勋章 | -| CapsuleLottery | true | 21.11.15 | 待整理 | 直播扭蛋活动抽奖 | -| VipPrivilege | true | 21.11.15 | 待整理 | 每月领取年度大会员特权(B币券、会员购优惠券) | -| BpConsumption | true | 21.11.15 | 待整理 | 每月消费使用年度大会员特权的B币券 | -| Statistics | true | 21.11.15 | 待整理 | 全局抽奖结果统计 | -| LiveReservation | true | 21.11.15 | 待整理 | 直播预约有奖 | -| Silver | false | 21.03.27 | 待整理 | 直播银瓜子自动开启宝箱 | +

+点击展开 + +| plugin | status | version | cycle | description | +|-----------------|--------|----------|-------|-------------------------| +| CheckUpdate | true | 22.01.18 | 待整理 | 程序检查更新 | +| Login | true | 22.01.18 | 待整理 | 账号登录、刷新、维持 | +| Schedule | true | 22.01.18 | 待整理 | 控制插件运行周期 | +| MainSite | true | 22.01.18 | 待整理 | 投币、观看、分享视频 (速升6级不是梦) | +| DailyBag | true | 22.01.18 | 待整理 | 双端领取日常/周常礼包 | +| ManGa | true | 22.01.18 | 待整理 | 漫画签到、分享 | +| ActivityLottery | true | 22.01.18 | 待整理 | 主站活动九宫格抽奖 | +| Competition | true | 22.01.18 | 待整理 | 游戏赛事竞猜 | +| DoubleHeart | true | 22.01.18 | 待整理 | 双端心跳 (姥爷直播经验) | +| DailyTask | true | 22.01.18 | 待整理 | 直播每日任务(签到、观看) | +| Barrage | true | 22.01.18 | 待整理 | 保持活跃弹幕 | +| Silver2Coin | true | 22.01.18 | 待整理 | 银瓜子兑换硬币 | +| Judge | true | 22.01.18 | 待整理 | 風機委員投票 | +| GiftSend | true | 22.01.18 | 待整理 | 礼物赠送、维持每日勋章亲密度 | +| GroupSignIn | true | 22.01.18 | 待整理 | 友爱社签到 | +| GiftHeart | true | 22.01.18 | 待整理 | 日常心跳每日礼包礼物 | +| SmallHeart | true | 22.01.18 | 待整理 | 直播挂机,每日24个小心心 | +| MaterialObject | true | 22.01.18 | 待整理 | 直播金色宝箱实物抽奖 | +| AloneTcpClient | true | 22.01.18 | 待整理 | 作者的独立直播监控(可支持本项目哦) | +| ZoneTcpClient | true | 22.01.18 | 待整理 | 官方的分区直播监控 | +| StormRaffle | true | 22.01.18 | 待整理 | 直播节奏风暴抽奖、亿元 | +| GiftRaffle | true | 22.01.18 | 待整理 | 直播礼物抽奖 | +| PkRaffle | true | 22.01.18 | 待整理 | 直播大乱斗抽奖 | +| GuardRaffle | true | 22.01.18 | 待整理 | 直播大航海抽奖 | +| AnchorRaffle | true | 22.01.18 | 待整理 | 直播天选时刻抽奖 | +| GiftRaffle | true | 22.01.18 | 待整理 | 直播礼物抽奖 | +| AwardRecord | true | 22.01.18 | 待整理 | 最新的中奖纪录通知 | +| Forward | true | 22.01.18 | 待整理 | 主站动态抽奖转发 | +| CapsuleLottery | true | 22.01.18 | 待整理 | 直播扭蛋活动抽奖 | +| PolishTheMedal | true | 22.01.18 | 待整理 | 每日自动点亮灰色勋章 | +| CapsuleLottery | true | 22.01.18 | 待整理 | 直播扭蛋活动抽奖 | +| VipPrivilege | true | 22.01.18 | 待整理 | 每月领取年度大会员特权(B币券、会员购优惠券) | +| BpConsumption | true | 22.01.18 | 待整理 | 每月消费使用年度大会员特权的B币券 | +| Statistics | true | 22.01.18 | 待整理 | 全局抽奖结果统计 | +| LiveReservation | true | 22.01.18 | 待整理 | 直播预约有奖 | +| Silver | false | 21.03.27 | 待整理 | 直播银瓜子自动开启宝箱 | + +
## 🖥️星图 diff --git a/conf/bili.yaml b/conf/bili.yaml index 4c935ee..2e8ce39 100644 --- a/conf/bili.yaml +++ b/conf/bili.yaml @@ -3,8 +3,8 @@ bili_version: 0.0.1 # Android bili_a: package: "tv.danmaku.bili" - version: "6.59.0" - build: "6590300" + version: "6.60.0" + build: "6600300" channel: "bili" device: "phone" mobi_app: "android" diff --git a/conf/user.ini.example b/conf/user.ini.example index 61262d5..1e351ea 100644 --- a/conf/user.ini.example +++ b/conf/user.ini.example @@ -134,9 +134,10 @@ content = [manga] enable = false -; 风纪委员投票|需要实名认证|慎用 +; 風機委員投票|需要实名认证|慎用 [judgement] enable = false +auto_apply = false ; 大会员权益|年度大会员专享 [vip_privilege] diff --git a/data/latest_version.json b/data/latest_version.json index 836aedc..fc60b4a 100644 --- a/data/latest_version.json +++ b/data/latest_version.json @@ -5,10 +5,10 @@ "source": "https://github.com/lkeme/BiliHelper-personal", "raw_url": "https://cdn.jsdelivr.net/gh/lkeme/BiliHelper-personal@master/data/latest_version.json", "purge_url": "https://purge.jsdelivr.net/gh/lkeme/BiliHelper-personal@master/data/latest_version.json", - "version": "1.0.2.211115", + "version": "1.1.0.220218", "des": "程序有更新,请及时线上查看更新哦~", - "time": "2021年11月15日15:40:35", + "time": "2022年2月18日10:40:35", "ini_version": "0.0.1", "ini_des": "配置有更新,请及时线上查看更新哦~", - "ini_time": "2021年11月15日15:40:35" + "ini_time": "2022年2月18日10:40:35" } \ No newline at end of file diff --git a/src/core/App.php b/src/core/App.php index 8297a09..b2ce8d1 100644 --- a/src/core/App.php +++ b/src/core/App.php @@ -10,7 +10,6 @@ namespace BiliHelper\Core; -use BiliHelper\Plugin\Live; use Throwable; use Amp\Loop; use BiliHelper\Script\BaseTask; diff --git a/src/core/Curl.php b/src/core/Curl.php index 2f70a4b..048a373 100644 --- a/src/core/Curl.php +++ b/src/core/Curl.php @@ -102,7 +102,7 @@ class Curl 'tasks' => $tasks, 'counter' => 1, 'count' => count($tasks), - 'concurrency' => count($tasks) < 10 ? count($tasks) : 10 + 'concurrency' => min(count($tasks), 10) ]; Log::debug("ASYNC: $url"); $headers = self::getHeaders($os, $headers); @@ -120,10 +120,10 @@ class Curl 'fulfilled' => function ($response, $index) { $res = $response->getBody(); // Log::notice("启动多线程 {$index}"); - array_push(self::$results, [ + self::$results[] = [ 'content' => $res, 'source' => self::$async_opt['tasks'][$index]['source'] - ]); + ]; self::countedAndCheckEnded(); }, 'rejected' => function ($reason, $index) { diff --git a/src/plugin/AnchorRaffle.php b/src/plugin/AnchorRaffle.php index 417779a..fc61a4e 100644 --- a/src/plugin/AnchorRaffle.php +++ b/src/plugin/AnchorRaffle.php @@ -76,11 +76,11 @@ class AnchorRaffle extends BaseRaffle User::setUserFollow($need_follow_uid); User::tagAddUsers($need_follow_uid, self::$group_id); // 添加到检测中奖 - array_push(self::$wait_un_follows, [ + self::$wait_un_follows[] = [ 'uid' => $need_follow_uid, 'anchor_id' => $anchor_id, 'time' => $time, - ]); + ]; } } @@ -96,7 +96,7 @@ class AnchorRaffle extends BaseRaffle if ($wait_un_follow['uid'] == $uid && $wait_un_follow['uid'] == $anchor_id) { continue; } - array_push($new_list, $wait_un_follow); + $new_list[] = $wait_un_follow; } self::$wait_un_follows = $new_list; } @@ -113,7 +113,7 @@ class AnchorRaffle extends BaseRaffle // 如果获取默认关注错误 或者 为空则补全一个 self::$default_follows = User::fetchTagFollowings(); if (empty(self::$default_follows)) { - array_push(self::$default_follows, 1); + self::$default_follows[] = 1; } return self::$default_follows; } @@ -183,7 +183,7 @@ class AnchorRaffle extends BaseRaffle ]; // Statistics::addPushList($data['raffle_name']); Statistics::addPushList(self::ACTIVE_TITLE); - array_push(self::$wait_list, $data); + self::$wait_list[] = $data; return true; } @@ -205,14 +205,14 @@ class AnchorRaffle extends BaseRaffle 'csrf' => getCsrf(), 'visit_id' => '' ]; - array_push($tasks, [ + $tasks[] = [ 'payload' => Sign::common($payload), 'source' => [ 'room_id' => $raffle['room_id'], 'raffle_id' => $raffle['raffle_id'], 'raffle_name' => $raffle['raffle_name'] ] - ]); + ]; } // print_r($results); return Curl::async('app', $url, $tasks); diff --git a/src/plugin/AwardRecord.php b/src/plugin/AwardRecord.php index 436899f..50ce2fe 100644 --- a/src/plugin/AwardRecord.php +++ b/src/plugin/AwardRecord.php @@ -59,7 +59,7 @@ class AwardRecord // 防止异常 if (!isset($de_raw['data']) || !isset($de_raw['data']['list'])) { Log::warning("获取天选时刻获奖记录错误: " . json_encode($de_raw, JSON_FORCE_OBJECT)); - self::$anchor_lock = time() + 1 * 60 * 60; + self::$anchor_lock = time() + 60 * 60; return; } foreach ($de_raw['data']['list'] as $anchor) { @@ -75,7 +75,7 @@ class AwardRecord Log::notice("天选时刻于" . $anchor['end_time'] . "获奖: $info ,请留意查看..."); Notice::push('anchor', $info); } - array_push(self::$anchor_list, $anchor['id']); + self::$anchor_list[] = $anchor['id']; } // 处理取关操作 foreach (AnchorRaffle::$wait_un_follows as $wait_un_follow) { @@ -108,7 +108,7 @@ class AwardRecord // 防止异常 if (!isset($de_raw['data']) || !isset($de_raw['data']['list']) || $de_raw['code']) { Log::warning("获取实物奖励获奖记录错误: " . $de_raw['msg']); - self::$raffle_lock = time() + 1 * 60 * 60; + self::$raffle_lock = time() + 60 * 60; return; } foreach ($de_raw['data']['list'] as $raffle) { @@ -124,7 +124,7 @@ class AwardRecord Log::notice("实物奖励于" . $raffle['create_time'] . "获奖: $info ,请留意查看..."); Notice::push('raffle', $info); } - array_push(self::$raffle_list, $raffle['id']); + self::$raffle_list[] = $raffle['id']; } self::$raffle_lock = time() + 6 * 60 * 60; } diff --git a/src/plugin/Competition.php b/src/plugin/Competition.php index 57fe45d..3f12b07 100644 --- a/src/plugin/Competition.php +++ b/src/plugin/Competition.php @@ -151,7 +151,7 @@ class Competition foreach ($de_raw['data']['list'] as $question) { // 判断是否有效 正2分钟 if (($question['contest']['stime'] - 600 - 120) > time()) { - array_push($questions, $question); + $questions[] = $question; } } // 和页面的不匹配 跳出 diff --git a/src/plugin/DataTreating.php b/src/plugin/DataTreating.php index 753adb0..097a0d1 100644 --- a/src/plugin/DataTreating.php +++ b/src/plugin/DataTreating.php @@ -53,6 +53,10 @@ class DataTreating // 天选时刻 AnchorRaffle::pushToQueue($info); break; + case 'red_pocket': + // 利是包 + RedPocketRaffle::pushToQueue($info); + break; default: break; } diff --git a/src/plugin/Forward.php b/src/plugin/Forward.php index d65a89a..0e99ea6 100644 --- a/src/plugin/Forward.php +++ b/src/plugin/Forward.php @@ -162,7 +162,7 @@ class Forward if ($flag) { self::$del_dynamic[$did] = $msg; if (isset($card['origin_user']['info']['uid'])) { - array_push(self::$un_follows, $card['origin_user']['info']['uid']); + self::$un_follows[] = $card['origin_user']['info']['uid']; } } } @@ -261,7 +261,7 @@ class Forward // 如果获取默认关注错误 或者 为空则补全一个 self::$default_follows = User::fetchTagFollowings(); if (empty(self::$default_follows)) { - array_push(self::$default_follows, 1); + self::$default_follows[] = 1; } return self::$default_follows; } @@ -275,7 +275,7 @@ class Forward $data = json(self::$repository); // 给个默认值 $data = $data->find("DynamicForward.default", []); - array_push($data, getConf('auto_reply_text', 'dynamic')); + $data[] = getConf('auto_reply_text', 'dynamic'); return $data; } diff --git a/src/plugin/GiftRaffle.php b/src/plugin/GiftRaffle.php index e5efd3f..6ab1f81 100644 --- a/src/plugin/GiftRaffle.php +++ b/src/plugin/GiftRaffle.php @@ -56,7 +56,7 @@ class GiftRaffle extends BaseRaffle 'wait' => $gift['time_wait'] + time(), ]; Statistics::addPushList($data['raffle_name']); - array_push(self::$wait_list, $data); + self::$wait_list[] = $data; } return true; } @@ -82,14 +82,14 @@ class GiftRaffle extends BaseRaffle 'csrf' => getCsrf(), 'visit_id' => '' ]; - array_push($tasks, [ + $tasks[] = [ 'payload' => Sign::common($payload), 'source' => [ 'room_id' => $raffle['room_id'], 'raffle_id' => $raffle['raffle_id'], 'raffle_name' => $raffle['raffle_name'] ] - ]); + ]; } // print_r($results); return Curl::async('app', $url, $tasks); diff --git a/src/plugin/GuardRaffle.php b/src/plugin/GuardRaffle.php index 2d20813..ff18bc0 100644 --- a/src/plugin/GuardRaffle.php +++ b/src/plugin/GuardRaffle.php @@ -73,7 +73,7 @@ class GuardRaffle extends BaseRaffle 'wait' => time() + mt_rand(5, 30) ]; Statistics::addPushList($data['raffle_name']); - array_push(self::$wait_list, $data); + self::$wait_list[] = $data; } return true; } @@ -96,14 +96,14 @@ class GuardRaffle extends BaseRaffle 'csrf' => getCsrf(), 'visit_id' => '' ]; - array_push($tasks, [ + $tasks[] = [ 'payload' => Sign::common($payload), 'source' => [ 'room_id' => $raffle['room_id'], 'raffle_id' => $raffle['raffle_id'], 'raffle_name' => $raffle['raffle_name'] ] - ]); + ]; } // print_r($results); return Curl::async('app', $url, $tasks); diff --git a/src/plugin/Judge.php b/src/plugin/Judge.php index a566cb3..fc145dc 100644 --- a/src/plugin/Judge.php +++ b/src/plugin/Judge.php @@ -139,9 +139,10 @@ class Judge $de_raw = json_decode($raw, true); // {"code":0,"message":"0","ttl":1} if (isset($de_raw['code']) && $de_raw['code']) { - Log::warning("申请连任失败 $raw"); + Log::warning("提交連任申請失敗 $raw"); } else { - Log::notice("申请连任成功 $raw"); + Log::notice("提交連任申請成功 $raw"); + Notice::push('jury_auto_apply', '提交連任申請成功'); } } @@ -203,8 +204,8 @@ class Judge // {"code":0,"message":"0","ttl":1,"data":{"case_id":"AC1xx411c7At"}} // {"code":25008,"message":"真给力 , 移交众裁的举报案件已经被处理完了","ttl":1} // {"code":25014,"message":"25014","ttl":1} - // {"code":25005,"message":"请成为风纪委员后再试","ttl":1} - // {"code":25006,"message":"风纪委员资格已过期","ttl":1} + // {"code":25005,"message":"请成为風機委員后再试","ttl":1} + // {"code":25006,"message":"風機委員资格已过期","ttl":1} if (isset($de_raw['code']) && $de_raw['code']) { switch ($de_raw['code']) { case 25005: @@ -245,7 +246,7 @@ class Judge $payload = []; $raw = Curl::get('pc', $url, $payload, self::$default_headers); $de_raw = json_decode($raw, true); - // {"code":25005,"message":"请成为风纪委员后再试","ttl":1} + // {"code":25005,"message":"请成为風機委員后再试","ttl":1} // {"code":0,"message":"0","ttl":1,"data":{"uname":"","face":"http://i2.hdslb.com/bfs/face/.jpg","case_total":,"term_end":,"status":1}} if (isset($de_raw['code']) && $de_raw['code']) { return false; @@ -256,12 +257,17 @@ class Judge // "apply_status": 0 申请连任后 // "apply_status": 5 审核连任中 // "apply_status": 3 连任成功后 - +// "apply_status": 4 申请连任失败(?) // 理论上正常 if ($de_raw['data']['status'] == 1) { - Log::info('你可以参与社区众裁,共创良好环境哦~'); + Log::info('你可以參與社區衆裁,共創良好環境哦~'); return true; } + // 只是嘗試 + if ($de_raw['data']['apply_status'] == -1 && getConf('auto_apply', 'judgement')) { + self::juryApply(); + } + return false; } diff --git a/src/plugin/Live.php b/src/plugin/Live.php index 859e6ba..9f1d818 100644 --- a/src/plugin/Live.php +++ b/src/plugin/Live.php @@ -36,7 +36,7 @@ class Live $areas = range(1, 6); } else { foreach ($de_raw['data'] as $area) { - array_push($areas, $area['id']); + $areas[] = $area['id']; } } return $areas; @@ -405,7 +405,7 @@ class Live // 去除永久礼物 if ($vo['corner_mark'] == '永久') continue; if ($vo['gift_id'] == $gift_id && $vo['gift_name'] == $gift_name) { - array_push($new_bag_list, $vo); + $new_bag_list[] = $vo; } } } @@ -471,7 +471,7 @@ class Live if ($de_raw['code'] == 0) { foreach ($de_raw['data']['list'] as $room) { - array_push($room_ids, $room['roomid']); + $room_ids[] = $room['roomid']; } } return $room_ids; @@ -509,6 +509,38 @@ class Live return json_decode($raw, true); } + /** + * @use 直播间抽奖检查 + * @param int $room_id + * @return array + */ + public static function getLotteryCheck(int $room_id): array + { + $url = 'https://api.live.bilibili.com/xlive/lottery-interface/v1/lottery/Check'; + $payload = [ + 'roomid' => $room_id, + ]; + $raw = Curl::get('other', $url, $payload); + return json_decode($raw, true); + } + + + /** + * @use 获取直播间抽奖信息 + * @param int $room_id + * @return array + */ + public static function getLotteryInfoWeb(int $room_id): array + { + $url = 'https://api.live.bilibili.com/xlive/lottery-interface/v1/lottery/getLotteryInfoWeb'; + $payload = [ + 'roomid' => $room_id, + ]; + $raw = Curl::get('other', $url, $payload); + return json_decode($raw, true); + } + + /** * @use 获取用户关注数 * @param int $mid diff --git a/src/plugin/Login.php b/src/plugin/Login.php index f7d6151..4c8f4ae 100644 --- a/src/plugin/Login.php +++ b/src/plugin/Login.php @@ -518,7 +518,7 @@ class Login $cookies = []; foreach ($headers as $header) { preg_match_all('/^(.*);/iU', $header, $cookie); - array_push($cookies, $cookie[0][0]); + $cookies[] = $cookie[0][0]; } return implode("", array_reverse($cookies)); } diff --git a/src/plugin/MainSite.php b/src/plugin/MainSite.php index 49ce2de..27bc7e7 100644 --- a/src/plugin/MainSite.php +++ b/src/plugin/MainSite.php @@ -119,7 +119,7 @@ class MainSite // 库存数量 $stock_num = self::getCoin(); // 实际数量 处理硬币库存少于预计数量 - $actual_num = intval($estimate_num > $stock_num ? $stock_num : $estimate_num) - self::coinLog(); + $actual_num = intval(min($estimate_num, $stock_num)) - self::coinLog(); Log::info("当前硬币库存 $stock_num 预计投币 $estimate_num 实际投币 $actual_num"); // 上限 if ($actual_num <= 0) { @@ -186,7 +186,7 @@ class MainSite if ($index >= $num) { break; } - array_push($aids, $card['desc']['rid']); + $aids[] = $card['desc']['rid']; } // 此处补全缺失 if (count($aids) < $num) { @@ -220,12 +220,12 @@ class MainSite if (in_array($rand_num, $rand_nums)) { continue; } else { - array_push($rand_nums, $rand_num); + $rand_nums[] = $rand_num; break; } } $aid = $de_raw['data']['list'][$rand_nums[$i]]['aid']; - array_push($aids, $aid); + $aids[] = $aid; } return $aids; @@ -256,7 +256,7 @@ class MainSite $temps = array_rand($de_raw['data']['archives'], $num); } foreach ($temps as $temp) { - array_push($aids, $de_raw['data']['archives'][$temp]['aid']); + $aids[] = $de_raw['data']['archives'][$temp]['aid']; } return $aids; } diff --git a/src/plugin/MaterialObject.php b/src/plugin/MaterialObject.php index 381025d..5070fc0 100644 --- a/src/plugin/MaterialObject.php +++ b/src/plugin/MaterialObject.php @@ -121,13 +121,13 @@ class MaterialObject $last_round = end($rounds); // 最后抽奖轮次无效 if ($last_round['join_end_time'] < time()) { - array_push(self::$invalid_aids, $probe_aid); + self::$invalid_aids[] = $probe_aid; continue; } // 过滤敏感词 $title = $response['data']['title']; if (self::filterTitleWords($title)) { - array_push(self::$invalid_aids, $probe_aid); + self::$invalid_aids[] = $probe_aid; continue; } // 过滤抽奖轮次 @@ -135,10 +135,10 @@ class MaterialObject if ($round_num == 0) { continue; } - array_push($lottery_list, [ + $lottery_list[] = [ 'aid' => $probe_aid, 'num' => $round_num, - ]); + ]; } // 缓存结束 需要的数据的放进缓存 setCache('invalid_aids', self::$invalid_aids); diff --git a/src/plugin/Notice.php b/src/plugin/Notice.php index f3d2cc4..bd8d34a 100644 --- a/src/plugin/Notice.php +++ b/src/plugin/Notice.php @@ -122,8 +122,12 @@ class Notice 'content' => "[$now_time] 用户: $uname 详情: $result" ], 'jury_leave_office' => [ - 'title' => '已卸任风纪委员', - 'content' => "[$now_time] 用户: $uname 详情: $result ,请及时关注风纪委员连任状态哦~" + 'title' => '已卸任風機委員', + 'content' => "[$now_time] 用户: $uname 详情: $result ,请及时关注風機委員连任状态哦~" + ], + 'jury_auto_apply' => [ + 'title' => '嘗試連任風機委員', + 'content' => "[$now_time] 用户: $uname 详情: $result ,请及时关注風機委員连任状态哦~" ], default => [ 'title' => '推送消息异常记录', diff --git a/src/plugin/PkRaffle.php b/src/plugin/PkRaffle.php index e06664e..dd56165 100644 --- a/src/plugin/PkRaffle.php +++ b/src/plugin/PkRaffle.php @@ -12,7 +12,6 @@ namespace BiliHelper\Plugin; use BiliHelper\Core\Log; use BiliHelper\Core\Curl; -use BiliHelper\Util\TimeLock; use BiliHelper\Util\BaseRaffle; class PkRaffle extends BaseRaffle @@ -58,7 +57,7 @@ class PkRaffle extends BaseRaffle 'wait' => time() + mt_rand(5, 25) ]; Statistics::addPushList($data['raffle_name']); - array_push(self::$wait_list, $data); + self::$wait_list[] = $data; } return true; } @@ -79,14 +78,14 @@ class PkRaffle extends BaseRaffle 'csrf_token' => getCsrf(), "csrf" => getCsrf(), ]; - array_push($tasks, [ + $tasks[] = [ 'payload' => Sign::common($payload), 'source' => [ 'room_id' => $raffle['room_id'], 'raffle_id' => $raffle['raffle_id'], 'raffle_name' => $raffle['raffle_name'] ] - ]); + ]; } // print_r($results); return Curl::async('app', $url, $tasks); @@ -112,7 +111,7 @@ class PkRaffle extends BaseRaffle if (isset($de_raw['code']) && $de_raw['code'] == 0) { Statistics::addSuccessList($data['raffle_name']); $award_text = $de_raw['data']['award_text']; - Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} {$data['raffle_name']}: {$award_text}"); + Log::notice("房间 {$data['room_id']} 编号 {$data['raffle_id']} {$data['raffle_name']}: $award_text"); // 收益 Statistics::addProfitList($data['raffle_name'] . '-' . explode('X', $award_text)[0], $de_raw['data']['award_num']); } elseif (isset($de_raw['msg']) && $de_raw['code'] == -403 && $de_raw['msg'] == '访问被拒绝') { diff --git a/src/plugin/RedPocketRaffle.php b/src/plugin/RedPocketRaffle.php new file mode 100644 index 0000000..4720543 --- /dev/null +++ b/src/plugin/RedPocketRaffle.php @@ -0,0 +1,81 @@ + $raffle['ruid'], + 'room_id' => $raffle['room_id'], + 'lot_id' => $raffle['lot_id'], + 'spm_id' => '444.8.red_envelope.extract', + 'jump_from' => '', + 'session_id' => '', + 'csrf_token' => getCsrf(), + 'csrf' => getCsrf(), + 'visit_id' => '' + ]; + // {"code":0,"message":"0","ttl":1,"data":{"join_status":1}} + $tasks[] = [ + 'payload' => Sign::common($payload), + 'source' => [ + 'room_id' => $raffle['room_id'], + 'raffle_id' => $raffle['raffle_id'], + 'raffle_name' => $raffle['raffle_name'] + ] + ]; + } + // print_r($results); + return Curl::async('app', $url, $tasks); + } + + /** + * @use 解析抽奖信息 + * @param array $results + * @return mixed + */ + protected static function parseLottery(array $results): mixed + { + return ''; + } +} \ No newline at end of file diff --git a/src/plugin/Schedule.php b/src/plugin/Schedule.php index b3f8ee1..3500cfb 100644 --- a/src/plugin/Schedule.php +++ b/src/plugin/Schedule.php @@ -46,7 +46,7 @@ class Schedule } self::isSleep(); self::isSpecialPause(); - self::setLock(1 * 60); + self::setLock(60); } /** diff --git a/src/plugin/Statistics.php b/src/plugin/Statistics.php index a83f9cd..1443c95 100644 --- a/src/plugin/Statistics.php +++ b/src/plugin/Statistics.php @@ -217,7 +217,7 @@ class Statistics '参与' => self::getResults(self::$join_list, $key) . '/' . self::getResult(self::$join_list, $key), '成功' => self::getResults(self::$success_list, $key) . '/' . self::getResult(self::$success_list, $key), ]; - array_push($tr_list_count, $td); + $tr_list_count[] = $td; } } // 收益数量 @@ -229,7 +229,7 @@ class Statistics '奖品' => explode('-', $key)[1], '更新时间' => self::timeTran(self::getResult(self::$profit_list, $key, 'updated_time')), ]; - array_push($tr_list_profit, $td); + $tr_list_profit[] = $td; } } return [self::unique_arr($tr_list_count), self::unique_arr($tr_list_profit)]; @@ -257,7 +257,7 @@ class Statistics $renderer = new ArrayToTextTable($data); foreach (explode("\n", $renderer->getTable()) as $value) { if ($value) { - array_push($th_list, $value); + $th_list[] = $value; } } } diff --git a/src/plugin/StormRaffle.php b/src/plugin/StormRaffle.php index d883dfd..e33169a 100644 --- a/src/plugin/StormRaffle.php +++ b/src/plugin/StormRaffle.php @@ -63,7 +63,7 @@ class StormRaffle extends BaseRaffle 'wait' => time() ]; Statistics::addPushList($data['raffle_name']); - array_push(self::$wait_list, $data); + self::$wait_list[] = $data; return true; } diff --git a/src/plugin/User.php b/src/plugin/User.php index e6db29b..79ebd65 100644 --- a/src/plugin/User.php +++ b/src/plugin/User.php @@ -135,7 +135,7 @@ class User $de_raw = json_decode($raw, true); if ($de_raw['code'] == 0 && isset($de_raw['data']['list'])) { foreach ($de_raw['data']['list'] as $user) { - array_push($followings, $user['mid']); + $followings[] = $user['mid']; } if (count($followings) == $de_raw['data']['total']) { break; @@ -173,7 +173,7 @@ class User $de_raw = json_decode($raw, true); if ($de_raw['code'] == 0 && isset($de_raw['data'])) { foreach ($de_raw['data'] as $user) { - array_push($followings, $user['mid']); + $followings[] = $user['mid']; } if (count($de_raw['data']) != $page_size || empty($de_raw['data'])) { break; diff --git a/src/plugin/ZoneTcpClient.php b/src/plugin/ZoneTcpClient.php index f64b293..862240e 100644 --- a/src/plugin/ZoneTcpClient.php +++ b/src/plugin/ZoneTcpClient.php @@ -89,7 +89,7 @@ class ZoneTcpClient { Log::debug("Reconnect Reason: {$area_data['area_id']} -> $reason"); self::$client_maps["server" . $area_data['area_id']]['status'] = false; - array_push(self::$trigger_restart, $area_data); + self::$trigger_restart[] = $area_data; } /** @@ -104,7 +104,7 @@ class ZoneTcpClient break; } if (time() < $area_data['wait_time']) { - array_push(self::$trigger_restart, $area_data); + self::$trigger_restart[] = $area_data; continue; } Log::notice("update_connections triggered, info: {$area_data['area_id']}"); @@ -193,6 +193,20 @@ class ZoneTcpClient $data = []; $update_room = false; switch ($de_raw['cmd']) { + case 'POPULARITY_RED_POCKET_WINNER_LIST': + // winner_info[] -> busers[] -> uid + Log::debug(json_encode($de_raw, true)); + break; + case 'POPULARITY_RED_POCKET_START': + Log::debug(json_encode($de_raw, true)); + $data = [ + 'room_id' => self::$room_id, + 'raffle_id' => $de_raw['lot_id'], + 'raffle_title' => '利是包', + 'raffle_type' => 'red_pocket', + 'source' => $msg + ]; + break; case 'TV_START': // 小电视飞船(1) $data = [ @@ -354,7 +368,7 @@ class ZoneTcpClient self::$raffle_list[$data['raffle_type']] = []; } $data['area_id'] = self::$area_id; - array_push(self::$raffle_list[$data['raffle_type']], $data); + self::$raffle_list[$data['raffle_type']][] = $data; Log::info("监测到 @分区 {$data['area_id']} @房间 {$data['room_id']} @抽奖 {$data['raffle_title']}"); // print_r($data); } @@ -607,7 +621,7 @@ class ZoneTcpClient $length = $head['packlen'] ?? 16; $body = substr($data, $step + 16, $length - 16); $step += $length; - array_push($list, $body); + $list[] = $body; } return $list; } diff --git a/src/tool/Faker.php b/src/tool/Faker.php index 501c2c3..1d0111c 100644 --- a/src/tool/Faker.php +++ b/src/tool/Faker.php @@ -24,8 +24,8 @@ class Faker */ public static function numberBetween(int $int1 = 0, int $int2 = 2147483647): int { - $min = $int1 < $int2 ? $int1 : $int2; - $max = $int1 < $int2 ? $int2 : $int1; + $min = min($int1, $int2); + $max = max($int1, $int2); return mt_rand($min, $max); } diff --git a/src/tool/File.php b/src/tool/File.php index 221caf9..62e0989 100644 --- a/src/tool/File.php +++ b/src/tool/File.php @@ -268,7 +268,7 @@ class File if (is_file($filename) && is_writeable($filename)) { // 创建文件句柄, 以读写方式打开 $handler = fopen($filename, 'rb+'); - $length = $length < 0 ? 0 : $length; + $length = max($length, 0); ftruncate($handler, $length); fclose($handler); } diff --git a/src/util/BaseRaffle.php b/src/util/BaseRaffle.php index 584c7d7..c3e5453 100644 --- a/src/util/BaseRaffle.php +++ b/src/util/BaseRaffle.php @@ -65,14 +65,14 @@ abstract class BaseRaffle break; } if ($raffle['wait'] > time()) { - array_push(static::$wait_list, $raffle); + static::$wait_list[] = $raffle; break; } if (count($raffle_list) > 200) { break; } - array_push($room_list, $raffle['room_id']); - array_push($raffle_list, $raffle); + $room_list[] = $raffle['room_id']; + $raffle_list[] = $raffle; // 有备注要单独处理 if (isset($raffle['remarks'])) { Statistics::addJoinList($raffle['remarks']); @@ -171,7 +171,7 @@ abstract class BaseRaffle static::$all_list = array_values(array_splice(static::$all_list, 2000, 2000)); } if ($filter) { - array_push(static::$all_list, $lid); + static::$all_list[] = $lid; } return false; } @@ -202,7 +202,7 @@ abstract class BaseRaffle } $banned_status = Live::fishingDetection($current_rid); if ($banned_status) { - array_push(static::$banned_rids, $current_rid); + static::$banned_rids[] = $current_rid; return false; } // 实际检测