Skip to content

Commit

Permalink
🌮 0.9.1 添加扭蛋机、应援团签到功能
Browse files Browse the repository at this point in the history
  • Loading branch information
metowolf committed May 9, 2018
1 parent 85e1bed commit d3b6a12
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 29 deletions.
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: php

matrix:
fast_finish: true

include:
- php: '5.6'
- php: '7.0'
- php: '7.1'
- php: '7.2'
- php: 'nightly'

allow_failures:
- php: 'nightly'

sudo: false

script:
- find -L . -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# Release Notes

## v0.9.0 (2018-05-07)
## v0.9.1 (2018-05-09)

### Added
- 添加应援团签到功能
- 添加扭蛋机功能(暂时支持普通扭蛋币)

### Changed
- [dev] 当配置文件为空时跳过写入
- 当回调地址为空时跳过

### Fixed
- 兼容 PHP 5.6 版本测试 ([#37](https://github.com/metowolf/BilibiliHelper/issues/37))
- 修复部分接口逻辑问题


## v0.9.0-pre (2018-05-07)

**该版本为非兼容更新,从 0.8.x 升级需要重新覆盖配置文件**

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ B 站直播实用脚本
|plugin |version |description |
|---------|---------|--------------|
|Auth |18.05.07 |帐号登录组件 |
|Capsule |18.05.09 |扭蛋机(普通) |
|DailyBag |18.05.07 |每日礼包领取 |
|Group |18.05.09 |应援团签到 |
|Heart |18.05.07 |双端直播间心跳 |
|Silver |18.05.07 |免费宝箱领取 |
|SmallTV |18.05.07 |小电视抽奖 |
|SmallTV |18.05.08 |小电视抽奖 |
|Task |18.05.07 |每日任务 |


## 未完成功能
|待续|
|-------|
|扭蛋机|
|总督检测|
|节奏风暴|
|应援团签到|


## 环境依赖
Expand Down
32 changes: 22 additions & 10 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,37 @@
/*!
* metowolf BilibiliHelper
* https://i-meto.com/
* Version 0.9.0
* Version 0.9.1
*
* Copyright 2018, metowolf
* Released under the MIT license
*/

require 'vendor/autoload.php';

$plugins = [
'websocket',
'auth',
'capsule',
'dailyBag',
'giftSend',
'group',
'heart',
'silver',
'smallTV',
'task',
];

$filename = isset($argv[1]) ? $argv[1] : 'config';

$app = new BilibiliHelper\Lib\Helper();
$t = $app->get('config');
$config = $t::parse($filename);

$config = $app->get('config')::parse('config');
while (true) {
$app->get('websocket')::run($config);
$app->get('auth')::run($config);
$app->get('heart')::run($config);
$app->get('dailyBag')::run($config);
$app->get('task')::run($config);
$app->get('giftSend')::run($config);
$app->get('silver')::run($config);
$app->get('smallTV')::run($config);
foreach ($plugins as $plugin) {
$t = $app->get($plugin);
$t::run($config);
}
sleep(10);
}
2 changes: 1 addition & 1 deletion src/plugins/Config.php → src/libs/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Released under the MIT license
*/

namespace BilibiliHelper\Plugin;
namespace BilibiliHelper\Lib;

use Dotenv\Dotenv;

Expand Down
13 changes: 8 additions & 5 deletions src/libs/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
namespace BilibiliHelper\Lib;

use BilibiliHelper\Plugin\Auth;
use BilibiliHelper\Plugin\Config;
use BilibiliHelper\Plugin\Capsule;
use BilibiliHelper\Plugin\DailyBag;
use BilibiliHelper\Plugin\Danmaku;
use BilibiliHelper\Plugin\GiftSend;
use BilibiliHelper\Plugin\Group;
use BilibiliHelper\Plugin\Heart;
use BilibiliHelper\Plugin\Silver;
use BilibiliHelper\Plugin\SmallTV;
use BilibiliHelper\Plugin\Task;
use BilibiliHelper\Plugin\Websocket;

class Helper
{
Expand All @@ -33,14 +34,16 @@ public function __construct()
private function registerAll()
{
$this->set('auth', Auth::getInstance());
$this->set('capsule', Capsule::getInstance());
$this->set('config', Config::getInstance());
$this->set('heart', Heart::getInstance());
$this->set('dailyBag', DailyBag::getInstance());
$this->set('task', Task::getInstance());
$this->set('giftSend', GiftSend::getInstance());
$this->set('group', Group::getInstance());
$this->set('heart', Heart::getInstance());
$this->set('silver', Silver::getInstance());
$this->set('smallTV', SmallTV::getInstance());
$this->set('websocket', Websocket::getInstance());
$this->set('task', Task::getInstance());
$this->set('websocket', Danmaku::getInstance());
}

public function get($name)
Expand Down
3 changes: 3 additions & 0 deletions src/libs/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public static function error($message, array $context = [])

public static function callback($levelId, $level, $message)
{
if (empty(static::$config['config']['CALLBACK_URL'])) {
return;
}
$callback_level = intval(static::$config['config']['CALLBACK_LEVEL']);
if ($levelId >= $callback_level) {
$url = str_replace('{account}', self::prefix(), static::$config['config']['CALLBACK_URL']);
Expand Down
13 changes: 7 additions & 6 deletions src/plugins/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ public static function run(&$config)
protected static function config($key, $value = null)
{
if (!is_null($value)) {
file_put_contents(static::$config['path'], preg_replace(
'/^'.$key.'=\S*/m',
$key.'='.$value,
file_get_contents(static::$config['path'])
));
if (!empty(static::$config['path'])) {
file_put_contents(static::$config['path'], preg_replace(
'/^'.$key.'=\S*/m',
$key.'='.$value,
file_get_contents(static::$config['path'])
));
}
static::$config['config'][$key] = $value;
}
return static::$config['config'][$key];
Expand Down Expand Up @@ -82,7 +84,6 @@ protected static function sign($payload)
'mobi_app' => 'iphone',
'platform' => 'ios',
'ts' => time(),
'type' => 'json',
];
$payload = array_merge($payload, $default);
if (isset($payload['sign'])) {
Expand Down
83 changes: 83 additions & 0 deletions src/plugins/Capsule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

/*!
* metowolf BilibiliHelper
* https://i-meto.com/
*
* Copyright 2018, metowolf
* Released under the MIT license
*/

namespace BilibiliHelper\Plugin;

use BilibiliHelper\Lib\Log;
use BilibiliHelper\Lib\Curl;

class Capsule extends Base
{
const PLUGIN_NAME = 'capsule';

protected static function init()
{
if (!static::data('lock')) {
static::data('lock', time());
}
}

protected static function work()
{
if (static::data('lock') > time()) {
return;
}

$count = static::info();
$step = 100;
while ($count && $step) {
while ($count >= $step) {
$count = static::open($step);
sleep(mt_rand(0, 5));
}
$step = intval($step / 10);
}

static::data('lock', time() + 86400);
}

public static function info()
{
$payload = [];
$data = Curl::post('https://api.live.bilibili.com/AppUser/capsuleInfo', static::sign($payload));
$data = json_decode($data, true);

if (isset($data['code']) && $data['code']) {
Log::warning("扭蛋币余额查询异常");
return 0;
}
Log::info("当前还有 {$data['data']['normal']['coin']} 枚扭蛋币");

return $data['data']['normal']['coin'];
}

public static function open($num)
{
$payload = [
'count' => $num,
'type' => 'normal',
];
$data = Curl::get('https://api.live.bilibili.com/AppUser/capsuleInfoOpen', static::sign($payload));
$data = json_decode($data, true);

if (isset($data['code']) && $data['code']) {
Log::warning("扭蛋失败,稍后重试");
return 0;
}

if (isset($data['data']['text'])) {
foreach ($data['data']['text'] as $vo) {
Log::notice("扭蛋成功,获得 {$vo['num']}{$vo['name']}");
}
}

return isset($data['data']['coin']) ? $data['data']['coin'] : 0;
}
}
4 changes: 2 additions & 2 deletions src/plugins/Websocket.php → src/plugins/Danmaku.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use BilibiliHelper\Lib\Curl;
use Wrench\Client;

class Websocket extends Base
class Danmaku extends Base
{
const PLUGIN_NAME = 'websocket';
const PLUGIN_NAME = 'danmaku';

protected static function init()
{
Expand Down
87 changes: 87 additions & 0 deletions src/plugins/Group.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

/*!
* metowolf BilibiliHelper
* https://i-meto.com/
*
* Copyright 2018, metowolf
* Released under the MIT license
*/

namespace BilibiliHelper\Plugin;

use BilibiliHelper\Lib\Log;
use BilibiliHelper\Lib\Curl;

class Group extends Base
{
const PLUGIN_NAME = 'group';

protected static function init()
{
if (!static::data('lock')) {
static::data('lock', time());
}
}

protected static function work()
{
if (static::data('lock') > time()) {
return;
}

$groups = static::list();
$count = count($groups);
foreach ($groups as $group) {
$count -= static::signIn($group);
}

if ($count == 0) {
static::data('lock', strtotime(date('Y-m-d 23:59:59')) + 600);
} else {
static::data('lock', time() + 3600);
}
}

public static function list()
{
$payload = [];
$data = Curl::post('https://api.vc.bilibili.com/link_group/v1/member/my_groups', static::sign($payload));
$data = json_decode($data, true);

if (isset($data['code']) && $data['code']) {
Log::warning("查询应援团名单异常");
return [];
}

if (empty($data['data']['list'])) {
Log::notice('没有需要签到的应援团');
return [];
}

return $data['data']['list'];
}

public static function signIn($value)
{
$payload = [
'group_id' => $value['group_id'],
'owner_id' => $value['owner_uid'],
];
$data = Curl::post('https://api.vc.bilibili.com/link_setting/v1/link_setting/sign_in', static::sign($payload));
$data = json_decode($data, true);

if (isset($data['code']) && $data['code']) {
Log::warning("应援团 {$value['group_name']} 签到异常");
return false;
}

if ($data['data']['status']) {
Log::notice("应援团 {$value['group_name']} 已经签到过了");
} else {
Log::notice("应援团 {$value['group_name']} 签到成功,增加 {$de_raw['data']['add_num']} 点亲密度");
}

return true;
}
}
2 changes: 1 addition & 1 deletion src/plugins/SmallTV.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected static function init()

protected static function work()
{
foreach (static::$config['data']['websocket']['smalltv'] as $tvid => $roomid) {
foreach (static::$config['data']['danmaku']['smalltv'] as $tvid => $roomid) {
static::$config['data'][static::PLUGIN_NAME]['smallTV'][$tvid] = [
'roomid' => $roomid,
'tvid' => $tvid,
Expand Down

0 comments on commit d3b6a12

Please sign in to comment.