mirror of
https://github.com/lkeme/BiliHelper-personal.git
synced 2025-12-19 01:20:08 +08:00
[add] New Plugin #AwardRecords
This commit is contained in:
parent
b1865da819
commit
57a5b7d727
31
README.md
31
README.md
@ -76,21 +76,22 @@ Group: [602815575](https://jq.qq.com/?_wv=1027&k=UaalVexM) | **请不要来问
|
||||
<details open>
|
||||
<summary>点击展开</summary>
|
||||
|
||||
| plugin | version | description | author | pid | cycle | status |
|
||||
|-----------------|---------|--------------------------|--------|------|-------------|--------|
|
||||
| CheckUpdate | 0.0.1 | 检查版本更新 | Lkeme | 1000 | 24(小时) | √ |
|
||||
| Login | 0.0.1 | 账号登录、刷新、保活 | Lkeme | 1001 | 2(小时) | √ |
|
||||
| MainSite | 0.0.1 | 主站任务(观看\分享\投币) | Lkeme | 1100 | 24(小时) | √ |
|
||||
| Manga | 0.0.1 | 漫画签到/分享 | Lkeme | 1101 | 24(小时) | √ |
|
||||
| LoveClub | 0.0.1 | 友爱社签到 | Lkeme | 1102 | 24(小时) | √ |
|
||||
| LiveSignIn | 0.0.1 | 直播签到 | Lkeme | 1103 | 24(小时) | √ |
|
||||
| GameForecast | 0.0.1 | 游戏赛事预测(破产机) | Lkeme | 1104 | 24(小时) | √ |
|
||||
| Silver2Coin | 0.0.1 | 银瓜子兑换硬币 | Lkeme | 1105 | 24(小时) | √ |
|
||||
| Judge | 0.0.1 | 風機委員投票 | Lkeme | 1106 | 15-30(分钟) | √ |
|
||||
| VipPrivilege | 0.0.1 | 领取大会员权益 | Lkeme | 1107 | 24(小时) | √ |
|
||||
| BpConsumption | 0.0.1 | 大会员B币券消费 | Lkeme | 1108 | 24(小时) | √ |
|
||||
| LiveReservation | 0.0.1 | 预约直播有奖 | Lkeme | 1109 | 1-3(小时) | √ |
|
||||
| LiveGoldBox | 0.0.1 | 直播金色宝箱(实物抽奖) | Lkeme | 1110 | 6-10(分钟) | √ |
|
||||
| plugin | version | description | author | pid | cycle | status |
|
||||
|-----------------|---------|----------------|--------|------|-----------|--------|
|
||||
| CheckUpdate | 0.0.1 | 检查版本更新 | Lkeme | 1000 | 24(小时) | √ |
|
||||
| Login | 0.0.1 | 账号登录、刷新、保活 | Lkeme | 1001 | 2(小时) | √ |
|
||||
| MainSite | 0.0.1 | 主站任务(观看\分享\投币) | Lkeme | 1100 | 24(小时) | √ |
|
||||
| Manga | 0.0.1 | 漫画签到/分享 | Lkeme | 1101 | 24(小时) | √ |
|
||||
| LoveClub | 0.0.1 | 友爱社签到 | Lkeme | 1102 | 24(小时) | √ |
|
||||
| LiveSignIn | 0.0.1 | 直播签到 | Lkeme | 1103 | 24(小时) | √ |
|
||||
| GameForecast | 0.0.1 | 游戏赛事预测(破产机) | Lkeme | 1104 | 24(小时) | √ |
|
||||
| Silver2Coin | 0.0.1 | 银瓜子兑换硬币 | Lkeme | 1105 | 24(小时) | √ |
|
||||
| Judge | 0.0.1 | 風機委員投票 | Lkeme | 1106 | 15-30(分钟) | √ |
|
||||
| VipPrivilege | 0.0.1 | 领取大会员权益 | Lkeme | 1107 | 24(小时) | √ |
|
||||
| BpConsumption | 0.0.1 | 大会员B币券消费 | Lkeme | 1108 | 24(小时) | √ |
|
||||
| LiveReservation | 0.0.1 | 预约直播有奖 | Lkeme | 1109 | 1-3(小时) | √ |
|
||||
| LiveGoldBox | 0.0.1 | 直播金色宝箱(实物抽奖) | Lkeme | 1110 | 6-10(分钟) | √ |
|
||||
| AwardRecords | 0.0.1 | 获奖记录 | Lkeme | 1111 | 5(分钟) | √ |
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
255
plugin/AwardRecords/AwardRecords.php
Normal file
255
plugin/AwardRecords/AwardRecords.php
Normal file
@ -0,0 +1,255 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Website: https://mudew.com/
|
||||
* Author: Lkeme
|
||||
* License: The MIT License
|
||||
* Email: Useri@live.cn
|
||||
* Updated: 2022 ~ 2023
|
||||
*
|
||||
* _____ _ _ _ _ _ _____ _ _____ _____ _____
|
||||
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & /l、
|
||||
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、 。 7
|
||||
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ / \、゙ ~ヽ *
|
||||
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \ じしf_, )ノ
|
||||
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
|
||||
*/
|
||||
|
||||
use Bhp\Api\Lottery\V1\ApiAward;
|
||||
use Bhp\Api\XLive\LotteryInterface\V1\ApiAnchor;
|
||||
use Bhp\Api\XLive\Revenue\V1\ApiWallet;
|
||||
use Bhp\Cache\Cache;
|
||||
use Bhp\Log\Log;
|
||||
use Bhp\Notice\Notice;
|
||||
use Bhp\Plugin\BasePlugin;
|
||||
use Bhp\Plugin\Plugin;
|
||||
use Bhp\TimeLock\TimeLock;
|
||||
|
||||
class AwardRecords extends BasePlugin
|
||||
{
|
||||
/**
|
||||
* @var array|array[]
|
||||
*/
|
||||
protected array $records = [];
|
||||
|
||||
/**
|
||||
* @var array|int[]
|
||||
*/
|
||||
protected array $locks = [
|
||||
'operation' => 0,
|
||||
'award' => 0,
|
||||
'celestial' => 0,
|
||||
'bonus' => 0,
|
||||
];
|
||||
|
||||
/**
|
||||
* 插件信息
|
||||
* @var array|string[]
|
||||
*/
|
||||
protected ?array $info = [
|
||||
'hook' => __CLASS__, // hook
|
||||
'name' => 'AwardRecords', // 插件名称
|
||||
'version' => '0.0.1', // 插件版本
|
||||
'desc' => '获奖记录', // 插件描述
|
||||
'author' => 'Lkeme',// 作者
|
||||
'priority' => 1111, // 插件优先级
|
||||
'cycle' => '5(分钟)', // 运行周期
|
||||
];
|
||||
|
||||
/**
|
||||
* @param Plugin $plugin
|
||||
*/
|
||||
public function __construct(Plugin &$plugin)
|
||||
{
|
||||
// 时间锁
|
||||
TimeLock::initTimeLock();
|
||||
// 缓存
|
||||
Cache::initCache();
|
||||
// $this::class
|
||||
$plugin->register($this, 'execute');
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行
|
||||
* @return void
|
||||
*/
|
||||
public function execute(): void
|
||||
{
|
||||
if (TimeLock::getTimes() > time() || !getEnable('award_records')) return;
|
||||
//
|
||||
$this->awardRecordsTask();
|
||||
//
|
||||
TimeLock::setTimes(5 * 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function awardRecordsTask(): void
|
||||
{
|
||||
// 缓存开始
|
||||
$this->records = ($tmp = Cache::get('records')) ? $tmp : $this->initRecords();
|
||||
//
|
||||
if ($this->locks['operation'] < time()) {
|
||||
$this->operation();
|
||||
}
|
||||
if ($this->locks['award'] < time()) {
|
||||
$this->award();
|
||||
}
|
||||
if ($this->locks['celestial'] < time()) {
|
||||
$this->celestial();
|
||||
}
|
||||
if ($this->locks['bonus'] < time()) {
|
||||
$this->bonus();
|
||||
}
|
||||
// 缓存结束
|
||||
Cache::set('records', $this->records);
|
||||
}
|
||||
|
||||
/**
|
||||
* 运营奖惩|false#6|true#24
|
||||
* @param string $title
|
||||
* @return bool
|
||||
*/
|
||||
protected function operation(string $title = '运营奖惩'): bool
|
||||
{
|
||||
$response = ApiWallet::apCenterList();
|
||||
//
|
||||
if ($response['code']) {
|
||||
Log::warning("获奖记录: 获取{$title}失败 {$response['code']} -> {$response['message']}");
|
||||
$this->locks['operation'] = time() + 6 * 60 * 60;
|
||||
return false;
|
||||
}
|
||||
//
|
||||
$now = date("m") . '月' . date("d") . '日';
|
||||
foreach ($response['data']['list'] as $data) {
|
||||
$info = $data['md'] . '-' . $data['desc'];
|
||||
//
|
||||
if (!in_array($info, $this->records['operation'])) {
|
||||
$this->records['operation'][] = $info;
|
||||
}
|
||||
// 需要通知
|
||||
if ($now != $data['md']) continue;
|
||||
Log::notice($info);
|
||||
Notice::push($title, $info);
|
||||
}
|
||||
$this->locks['operation'] = time() + 24 * 60 * 60;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获奖记录|false#1|true#6
|
||||
* @param string $title
|
||||
* @return bool
|
||||
*/
|
||||
protected function award(string $title = '获奖记录'): bool
|
||||
{
|
||||
$response = ApiAward::awardList();
|
||||
//
|
||||
if ($response['code']) {
|
||||
Log::warning("获奖记录: 获取{$title}失败 {$response['code']} -> {$response['message']}");
|
||||
$this->locks['award'] = time() + 60 * 60;
|
||||
return false;
|
||||
}
|
||||
//
|
||||
foreach ($response['data']['list'] as $data) {
|
||||
$info = $data['create_time'] . '-' . $data['id'] . '-' . $data['source'] . '-' . $data['gift_name'];
|
||||
//
|
||||
if (!in_array($info, $this->records['award'])) {
|
||||
$this->records['award'][] = $info;
|
||||
}
|
||||
//
|
||||
$create_time = strtotime($data['create_time']); //礼物时间
|
||||
$day = ceil((time() - $create_time) / 86400); //60s*60min*24h
|
||||
//
|
||||
// 范围
|
||||
if ($day <= 2 && $data['update_time'] == '') {
|
||||
Log::notice($info);
|
||||
Notice::push($title, $info);
|
||||
}
|
||||
}
|
||||
$this->locks['award'] = time() + 6 * 60 * 60;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 天选时刻|false#30m|true#10m
|
||||
* @param string $title
|
||||
* @return bool
|
||||
*/
|
||||
protected function celestial(string $title = '天选时刻'): bool
|
||||
{
|
||||
$response = ApiAnchor::awardRecord();
|
||||
//
|
||||
if ($response['code']) {
|
||||
Log::warning("获奖记录: 获取{$title}失败 {$response['code']} -> {$response['message']}");
|
||||
$this->locks['celestial'] = time() + 30 * 60;
|
||||
return false;
|
||||
}
|
||||
//
|
||||
foreach ($response['data']['list'] as $data) {
|
||||
$info = $data['end_time'] . '-' . $data['id'] . '-' . $data['anchor_name'] . '-' . $data['award_name'];
|
||||
//
|
||||
if (!in_array($info, $this->records['celestial'])) {
|
||||
$this->records['celestial'][] = $info;
|
||||
}
|
||||
//
|
||||
$end_time = strtotime($data['end_time']); //礼物时间
|
||||
$day = ceil((time() - $end_time) / 86400); //60s*60min*24h
|
||||
// 范围
|
||||
if ($day <= 2) {
|
||||
Log::notice($info);
|
||||
Notice::push($title, $info);
|
||||
}
|
||||
}
|
||||
$this->locks['celestial'] = time() + 10 * 60;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 航海回馈|false#6|true#24
|
||||
* @param string $title
|
||||
* @return bool
|
||||
*/
|
||||
protected function bonus(string $title = '航海回馈'): bool
|
||||
{
|
||||
$response = ApiAnchor::awardRecord();
|
||||
//
|
||||
if ($response['code']) {
|
||||
Log::warning("获奖记录: 获取{$title}失败 {$response['code']} -> {$response['message']}");
|
||||
$this->locks['bonus'] = time() + 6 * 30 * 60;
|
||||
return false;
|
||||
}
|
||||
//
|
||||
foreach ($response['data']['list'] as $data) {
|
||||
$info = $data['settlement_time'] . '-' . $data['win_id'] . '-' . $data['anchor_name'] . '-' . $data['award_name'];
|
||||
//
|
||||
if (!in_array($info, $this->records['bonus'])) {
|
||||
$this->records['bonus'][] = $info;
|
||||
}
|
||||
//
|
||||
$settlement_time = strtotime($data['settlement_time']); //礼物时间
|
||||
// 范围
|
||||
if (time() < $settlement_time) {
|
||||
Log::notice($info);
|
||||
Notice::push($title, $info);
|
||||
}
|
||||
}
|
||||
$this->locks['bonus'] = time() + 24 * 60 * 60;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
* @return array[]
|
||||
*/
|
||||
protected function initRecords(): array
|
||||
{
|
||||
return [
|
||||
'operation' => [],
|
||||
'award' => [],
|
||||
'celestial' => [],
|
||||
'bonus' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -63,4 +63,3 @@ class PluginTemplate extends BasePlugin
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -95,6 +95,10 @@ vmids = 9617619
|
||||
[live_gold_box]
|
||||
enable = true
|
||||
|
||||
; 获取记录
|
||||
[award_records]
|
||||
enable = true
|
||||
|
||||
#######################
|
||||
# 通知设置 #
|
||||
#######################
|
||||
|
||||
41
src/Api/Lottery/V1/ApiAward.ctp
Normal file
41
src/Api/Lottery/V1/ApiAward.ctp
Normal file
@ -0,0 +1,41 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Website: https://mudew.com/
|
||||
* Author: Lkeme
|
||||
* License: The MIT License
|
||||
* Email: Useri@live.cn
|
||||
* Updated: 2022 ~ 2023
|
||||
*
|
||||
* _____ _ _ _ _ _ _____ _ _____ _____ _____
|
||||
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & /l、
|
||||
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、 。 7
|
||||
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ / \、゙ ~ヽ *
|
||||
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \ じしf_, )ノ
|
||||
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
|
||||
*/
|
||||
|
||||
namespace Bhp\Api\Lottery\V1;
|
||||
|
||||
use Bhp\Request\Request;
|
||||
|
||||
class ApiAward
|
||||
{
|
||||
/**
|
||||
* 获奖记录
|
||||
* @return array
|
||||
*/
|
||||
public static function awardList(): array
|
||||
{
|
||||
$url = 'https://api.live.bilibili.com/lottery/v1/Award/award_list';
|
||||
$payload = [
|
||||
'page' => 1,
|
||||
'month' => ''
|
||||
];
|
||||
$headers = [
|
||||
'origin' => 'https://link.bilibili.com',
|
||||
'referer' => 'https://link.bilibili.com/p/center/index'
|
||||
];
|
||||
return Request::getJson(true, 'pc', $url, $payload, $headers);
|
||||
}
|
||||
}
|
||||
41
src/Api/XLive/GeneralInterface/V1/ApiGuardBenefit.ctp
Normal file
41
src/Api/XLive/GeneralInterface/V1/ApiGuardBenefit.ctp
Normal file
@ -0,0 +1,41 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Website: https://mudew.com/
|
||||
* Author: Lkeme
|
||||
* License: The MIT License
|
||||
* Email: Useri@live.cn
|
||||
* Updated: 2022 ~ 2023
|
||||
*
|
||||
* _____ _ _ _ _ _ _____ _ _____ _____ _____
|
||||
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & /l、
|
||||
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、 。 7
|
||||
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ / \、゙ ~ヽ *
|
||||
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \ じしf_, )ノ
|
||||
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
|
||||
*/
|
||||
|
||||
namespace Bhp\Api\XLive\GeneralInterface\V1;
|
||||
|
||||
use Bhp\Request\Request;
|
||||
|
||||
class ApiGuardBenefit
|
||||
{
|
||||
/**
|
||||
* 航海回馈
|
||||
* @return array
|
||||
*/
|
||||
public static function winListByUser(): array
|
||||
{
|
||||
$url = 'https://api.live.bilibili.com/xlive/general-interface/v1/guardBenefit/WinListByUser';
|
||||
$payload = [
|
||||
'page' => 1,
|
||||
];
|
||||
$headers = [
|
||||
'origin' => 'https://link.bilibili.com',
|
||||
'referer' => 'https://link.bilibili.com/p/center/index'
|
||||
];
|
||||
// {"code":0,"message":"0","ttl":1,"data":{"count":1,"page_count":1,"list":[{"win_id":16211,"recipient_name":"","phone":"","address":"","info_type":1,"award_name":"【韩小沐】月度舰长福利","ruid":642922,"anchor_name":"韩小沐","settlement_time":"2022-08-07 20:57:29"}]}}
|
||||
return Request::getJson(true, 'pc', $url, $payload, $headers);
|
||||
}
|
||||
}
|
||||
40
src/Api/XLive/LotteryInterface/V1/ApiAnchor.ctp
Normal file
40
src/Api/XLive/LotteryInterface/V1/ApiAnchor.ctp
Normal file
@ -0,0 +1,40 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Website: https://mudew.com/
|
||||
* Author: Lkeme
|
||||
* License: The MIT License
|
||||
* Email: Useri@live.cn
|
||||
* Updated: 2022 ~ 2023
|
||||
*
|
||||
* _____ _ _ _ _ _ _____ _ _____ _____ _____
|
||||
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & /l、
|
||||
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、 。 7
|
||||
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ / \、゙ ~ヽ *
|
||||
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \ じしf_, )ノ
|
||||
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
|
||||
*/
|
||||
|
||||
namespace Bhp\Api\XLive\LotteryInterface\V1;
|
||||
|
||||
use Bhp\Request\Request;
|
||||
|
||||
class ApiAnchor
|
||||
{
|
||||
/**
|
||||
* 天选时刻
|
||||
* @return array
|
||||
*/
|
||||
public static function awardRecord(): array
|
||||
{
|
||||
$url = 'https://api.live.bilibili.com/xlive/lottery-interface/v1/Anchor/AwardRecord';
|
||||
$payload = [
|
||||
'page' => 1,
|
||||
];
|
||||
$headers = [
|
||||
'origin' => 'https://link.bilibili.com',
|
||||
'referer' => 'https://link.bilibili.com/p/center/index'
|
||||
];
|
||||
return Request::getJson(true, 'pc', $url, $payload, $headers);
|
||||
}
|
||||
}
|
||||
40
src/Api/XLive/Revenue/V1/ApiWallet.ctp
Normal file
40
src/Api/XLive/Revenue/V1/ApiWallet.ctp
Normal file
@ -0,0 +1,40 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Website: https://mudew.com/
|
||||
* Author: Lkeme
|
||||
* License: The MIT License
|
||||
* Email: Useri@live.cn
|
||||
* Updated: 2022 ~ 2023
|
||||
*
|
||||
* _____ _ _ _ _ _ _____ _ _____ _____ _____
|
||||
* | _ \ | | | | | | | | | | | ____| | | | _ \ | ____| | _ \ & /l、
|
||||
* | |_| | | | | | | | | |_| | | |__ | | | |_| | | |__ | |_| | (゚、 。 7
|
||||
* | _ { | | | | | | | _ | | __| | | | ___/ | __| | _ / \、゙ ~ヽ *
|
||||
* | |_| | | | | |___ | | | | | | | |___ | |___ | | | |___ | | \ \ じしf_, )ノ
|
||||
* |_____/ |_| |_____| |_| |_| |_| |_____| |_____| |_| |_____| |_| \_\
|
||||
*/
|
||||
|
||||
namespace Bhp\Api\XLive\Revenue\V1;
|
||||
|
||||
use Bhp\Request\Request;
|
||||
|
||||
class ApiWallet
|
||||
{
|
||||
/**
|
||||
* 运营奖惩
|
||||
* @return array
|
||||
*/
|
||||
public static function apCenterList(): array
|
||||
{
|
||||
$url = 'https://api.live.bilibili.com/xlive/revenue/v1/wallet/apcenterList';
|
||||
$payload = [
|
||||
'page' => 1,
|
||||
];
|
||||
$headers = [
|
||||
'origin' => 'https://link.bilibili.com',
|
||||
'referer' => 'https://link.bilibili.com/p/center/index'
|
||||
];
|
||||
return Request::getJson(true, 'pc', $url, $payload, $headers);
|
||||
}
|
||||
}
|
||||
@ -187,8 +187,8 @@ class Notice extends SingleTon
|
||||
'content' => "[$now_time] 用户: $uname 详情: $msg ,请及时关注風機委員连任状态哦~"
|
||||
],
|
||||
default => [
|
||||
'title' => '推送消息异常记录',
|
||||
'content' => "[$now_time] 用户: $uname 推送消息key错误: $type->$msg"
|
||||
'title' => $type,
|
||||
'content' => "[$now_time] 用户: $uname 详情: $msg"
|
||||
],
|
||||
};
|
||||
// 添加前缀
|
||||
@ -404,7 +404,7 @@ class Notice extends SingleTon
|
||||
{
|
||||
Log::info('使用weComApp推送消息');
|
||||
$corp_id = getConf('notify_we_com_app.corp_id');
|
||||
$corp_secret = getConf('notify_we_com_app.corp_secret' );
|
||||
$corp_secret = getConf('notify_we_com_app.corp_secret');
|
||||
$agent_id = getConf('notify_we_com_app.agent_id');
|
||||
$to_user = getConf('notify_we_com_app.to_user') ?? '@all';
|
||||
|
||||
@ -474,4 +474,3 @@ class Notice extends SingleTon
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user