mirror of
https://github.com/lkeme/BiliHelper-personal.git
synced 2025-12-24 13:10:08 +08:00
[feat] GameForecast
This commit is contained in:
parent
708dd717e6
commit
91b2eb53bd
176
plugin/GameForecast/GameForecast.php
Normal file
176
plugin/GameForecast/GameForecast.php
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
<?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\Esports\ApiGuess;
|
||||||
|
use Bhp\Log\Log;
|
||||||
|
use Bhp\Plugin\BasePlugin;
|
||||||
|
use Bhp\Plugin\Plugin;
|
||||||
|
use Bhp\TimeLock\TimeLock;
|
||||||
|
|
||||||
|
class GameForecast extends BasePlugin
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 插件信息
|
||||||
|
* @var array|string[]
|
||||||
|
*/
|
||||||
|
protected ?array $info = [
|
||||||
|
'hook' => __CLASS__, // hook
|
||||||
|
'name' => 'GameForecast', // 插件名称
|
||||||
|
'version' => '0.0.1', // 插件版本
|
||||||
|
'desc' => '赛事预测(破产机)', // 插件描述
|
||||||
|
'author' => 'Lkeme',// 作者
|
||||||
|
'priority' => 1104, // 插件优先级
|
||||||
|
'cycle' => '24(小时)', // 运行周期
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Plugin $plugin
|
||||||
|
*/
|
||||||
|
public function __construct(Plugin &$plugin)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
TimeLock::initTimeLock();
|
||||||
|
// $this::class
|
||||||
|
$plugin->register($this, 'execute');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 执行
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function execute(): void
|
||||||
|
{
|
||||||
|
if (TimeLock::getTimes() > time() || !getEnable('game_forecast')) return;
|
||||||
|
//
|
||||||
|
$this->startStake();
|
||||||
|
//
|
||||||
|
TimeLock::setTimes(TimeLock::timing(1, 30));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 获取预测赛事列表
|
||||||
|
* @param int $pm
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function fetchCollectionQuestions(int $pm = 10): array
|
||||||
|
{
|
||||||
|
$questions = [];
|
||||||
|
for ($i = 1; $i < $pm; $i++) {
|
||||||
|
$response = ApiGuess::collectionQuestion($i);
|
||||||
|
//
|
||||||
|
if ($response['code']) {
|
||||||
|
Log::warning("赛事预测: 获取赛事列表失败 {$response['code']} -> {$response['message']}");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
if (count($response['data']['list']) == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// 添加到集合
|
||||||
|
foreach ($response['data']['list'] as $question) {
|
||||||
|
// 判断是否有效 正2分钟
|
||||||
|
if (($question['contest']['stime'] - 600 - 120) > time()) {
|
||||||
|
$questions[] = $question;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 和页面的不匹配 跳出
|
||||||
|
if (count($response['data']['list']) != $response['data']['page']['size']) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log::info('赛事预测: 获取到 ' . count($questions) . ' 个有效赛事');
|
||||||
|
return $questions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 预计猜测结果
|
||||||
|
* @param array $question
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function parseQuestion(array $question): array
|
||||||
|
{
|
||||||
|
$guess = [];
|
||||||
|
$guess['oid'] = $question['contest']['id'];
|
||||||
|
$guess['main_id'] = $question['questions'][0]['id'];
|
||||||
|
$details = $question['questions'][0]['details'];
|
||||||
|
$guess['count'] = (($count = getConf('game_forecast.max_coin', 0, 'int')) <= 10) ? $count : 10;
|
||||||
|
$guess['title'] = $question['questions'][0]['title'];
|
||||||
|
foreach ($details as $detail) {
|
||||||
|
$guess['title'] .= " 队伍: {$detail['option']} 赔率: {$detail['odds']}";
|
||||||
|
}
|
||||||
|
array_multisort(array_column($details, "odds"), SORT_ASC, $details);
|
||||||
|
switch (getConf('game_forecast.bet', 3, 'int')) {
|
||||||
|
case 1:
|
||||||
|
// 压大
|
||||||
|
$detail = array_pop($details);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
// 压小
|
||||||
|
$detail = array_shift($details);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
// 随机
|
||||||
|
$detail = $details[array_rand($details)];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// 乱序
|
||||||
|
shuffle($details);
|
||||||
|
$detail = $details[array_rand($details)];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$guess['detail_id'] = $detail['detail_id'];
|
||||||
|
$profit = ceil($guess['count'] * $detail['odds']);
|
||||||
|
$guess['estimate'] = "竞猜队伍: {$detail['option']} 预计下注: {$guess['count']} 预计赚取: $profit 预计亏损: {$guess['count']} (硬币)";
|
||||||
|
return $guess;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 开始破产
|
||||||
|
*/
|
||||||
|
protected function startStake(): void
|
||||||
|
{
|
||||||
|
$questions = $this->fetchCollectionQuestions();
|
||||||
|
//
|
||||||
|
$max_guess = getConf('game_forecast.max_num', 0, 'int');
|
||||||
|
foreach ($questions as $index => $question) {
|
||||||
|
if ($index >= $max_guess) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$guess = $this->parseQuestion($question);
|
||||||
|
$this->addGuess($guess);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 添加竞猜
|
||||||
|
* @param array $guess
|
||||||
|
*/
|
||||||
|
protected function addGuess(array $guess): void
|
||||||
|
{
|
||||||
|
Log::info($guess['title']);
|
||||||
|
Log::info($guess['estimate']);
|
||||||
|
//
|
||||||
|
$response = ApiGuess::guessAdd($guess['oid'], $guess['main_id'], $guess['detail_id'], $guess['count']);
|
||||||
|
// {"code":0,"message":"0","ttl":1}
|
||||||
|
if ($response['message'] == 0) {
|
||||||
|
Log::notice('赛事预测: 破产成功');
|
||||||
|
} else {
|
||||||
|
Log::warning("赛事预测: 破产失败 {$response['code']} -> {$response['message']}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -80,7 +80,10 @@ class LiveSignIn extends BasePlugin
|
|||||||
Log::notice("直播签到: 今日已经签到过了哦~ 已连续签到 {$response['data']['hadSignDays']} 天");
|
Log::notice("直播签到: 今日已经签到过了哦~ 已连续签到 {$response['data']['hadSignDays']} 天");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//
|
// 您被封禁了,无法进行操作
|
||||||
|
// {"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根辣条,50根辣条","specialText":"","allDays":31,"hadSignDays":20,"isBonusDay":1}}
|
||||||
$response = ApiXLiveSign::doSign();
|
$response = ApiXLiveSign::doSign();
|
||||||
if ($response['code']) {
|
if ($response['code']) {
|
||||||
Log::warning("直播签到: 签到失败 {$response['code']} -> {$response['message']}");
|
Log::warning("直播签到: 签到失败 {$response['code']} -> {$response['message']}");
|
||||||
|
|||||||
@ -49,6 +49,13 @@ enable = true
|
|||||||
[live_sign_in]
|
[live_sign_in]
|
||||||
enable =true
|
enable =true
|
||||||
|
|
||||||
|
; 游戏赛事竞猜预测(破产机)/每日竞猜次数/每次竞猜硬币(1-10)/下注(1.压大,2.压小,3.随机)
|
||||||
|
[game_forecast]
|
||||||
|
enable = false
|
||||||
|
max_num = 20
|
||||||
|
max_coin = 10
|
||||||
|
bet = 1
|
||||||
|
|
||||||
#######################
|
#######################
|
||||||
# 通知设置 #
|
# 通知设置 #
|
||||||
#######################
|
#######################
|
||||||
|
|||||||
78
src/Api/Esports/ApiGuess.php
Normal file
78
src/Api/Esports/ApiGuess.php
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<?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\Esports;
|
||||||
|
|
||||||
|
use Bhp\Request\Request;
|
||||||
|
use Bhp\User\User;
|
||||||
|
|
||||||
|
class ApiGuess
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @use 获取赛事竞猜
|
||||||
|
* @param int $pn
|
||||||
|
* @param int $ps
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function collectionQuestion(int $pn, int $ps = 50): array
|
||||||
|
{
|
||||||
|
$url = 'https://api.bilibili.com/x/esports/guess/collection/question';
|
||||||
|
$payload = [
|
||||||
|
'pn' => $pn,
|
||||||
|
'ps' => $ps,
|
||||||
|
'stime' => date("Y-m-d H:i:s", strtotime(date("Y-m-d", time()))),
|
||||||
|
'etime' => date("Y-m-d H:i:s", strtotime(date("Y-m-d", time())) + 86400 - 1)
|
||||||
|
];
|
||||||
|
$headers = [
|
||||||
|
'origin' => 'https://www.bilibili.com',
|
||||||
|
'referer' => 'https://www.bilibili.com/v/game/match/competition',
|
||||||
|
];
|
||||||
|
return Request::getjSON(true, 'pc', $url, $payload, $headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @use 竞猜
|
||||||
|
* @param int $oid
|
||||||
|
* @param int $main_id
|
||||||
|
* @param int $detail_id
|
||||||
|
* @param int $count
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function guessAdd(int $oid, int $main_id, int $detail_id, int $count): array
|
||||||
|
{
|
||||||
|
$user = User::parseCookie();
|
||||||
|
//
|
||||||
|
$url = 'https://api.bilibili.com/x/esports/guess/add';
|
||||||
|
$payload = [
|
||||||
|
'oid' => $oid,
|
||||||
|
'main_id' => $main_id,
|
||||||
|
'detail_id' => $detail_id,
|
||||||
|
'count' => $count,
|
||||||
|
'is_fav' => 0,
|
||||||
|
'csrf' => $user['csrf'],
|
||||||
|
'csrf_token' => $user['csrf'],
|
||||||
|
];
|
||||||
|
$headers = [
|
||||||
|
'origin' => 'https://www.bilibili.com',
|
||||||
|
'referer' => 'https://www.bilibili.com/v/game/match/competition'
|
||||||
|
];
|
||||||
|
return Request::postJson(true, 'pc', $url, $payload, $headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user