[fix] GiftSend

This commit is contained in:
Lkeme 2020-01-01 20:52:54 +08:00
parent 2589c77905
commit 9244ae0d29
9 changed files with 172 additions and 47 deletions

View File

@ -1,6 +1,18 @@
# Release Notes # Release Notes
# 本项目Log # 本项目Log
## v0.1.0.200101 alpha (2020-01-01)
### Added
- 任务逻辑引入协程
### Changed
-
### Fixed
- 修复礼物赠送异常
-
## v0.1.0.191227 alpha (2019-12-27) ## v0.1.0.191227 alpha (2019-12-27)
### Added ### Added

4
DOC.md
View File

@ -216,7 +216,9 @@ http://live.bilibili.com/9522051
https://api.live.bilibili.com/room/v1/Room/room_init?id=3 https://api.live.bilibili.com/room/v1/Room/room_init?id=3
``` ```
所有直播间号码小于 1000 的直播间为短号,该脚本在每次启动会自动修正部分功能,特殊标注的请留意, 所有直播间号码小于 1000 的直播间为短号部分4位直播间也为短号
该脚本在每次启动会自动修正部分功能,特殊标注的请留意。
## 相关 ## 相关

View File

@ -7,7 +7,7 @@ Group: [55308141](https://jq.qq.com/?_wv=1027&k=5AIDaJg)
## 公告 ## 公告
Currently for Personal Edition **0.1.0.191227 alpha** Currently for Personal Edition **0.1.0.200101 alpha**
## 文档 ## 文档

View File

@ -13,7 +13,8 @@
"monolog/monolog": "^1.23", "monolog/monolog": "^1.23",
"bramus/monolog-colored-line-formatter": "^2.0", "bramus/monolog-colored-line-formatter": "^2.0",
"clue/socket-raw": "^1.4.1", "clue/socket-raw": "^1.4.1",
"vlucas/phpdotenv": "^4.1" "vlucas/phpdotenv": "^4.1",
"amphp/amp": "^2.4"
}, },
"license": "MIT", "license": "MIT",
"authors": [ "authors": [

85
composer.lock generated
View File

@ -4,8 +4,91 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "6034c5a467eb270c2c7d1ce12d7277fd", "content-hash": "bc4f20d52292405305a8aa3bd6dcf4bd",
"packages": [ "packages": [
{
"name": "amphp/amp",
"version": "v2.4.0",
"source": {
"type": "git",
"url": "https://github.com/amphp/amp.git",
"reference": "13930a582947831bb66ff1aeac28672fd91c38ea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/amphp/amp/zipball/13930a582947831bb66ff1aeac28672fd91c38ea",
"reference": "13930a582947831bb66ff1aeac28672fd91c38ea",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=7"
},
"require-dev": {
"amphp/php-cs-fixer-config": "dev-master",
"amphp/phpunit-util": "^1",
"ext-json": "*",
"phpstan/phpstan": "^0.8.5",
"phpunit/phpunit": "^6.0.9 | ^7",
"react/promise": "^2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Amp\\": "lib"
},
"files": [
"lib/functions.php",
"lib/Internal/functions.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Daniel Lowrey",
"email": "rdlowrey@php.net"
},
{
"name": "Aaron Piotrowski",
"email": "aaron@trowski.com"
},
{
"name": "Bob Weinand",
"email": "bobwei9@hotmail.com"
},
{
"name": "Niklas Keller",
"email": "me@kelunik.com"
}
],
"description": "A non-blocking concurrency framework for PHP applications.",
"homepage": "http://amphp.org/amp",
"keywords": [
"async",
"asynchronous",
"awaitable",
"concurrency",
"event",
"event-loop",
"future",
"non-blocking",
"promise"
],
"time": "2019-11-11T19:32:05+00:00"
},
{ {
"name": "bramus/ansi-php", "name": "bramus/ansi-php",
"version": "3.0.3", "version": "3.0.3",

View File

@ -60,12 +60,12 @@ SLEEP_SECTION=2,3,4,5,6
# 基础设置 # # 基础设置 #
####################### #######################
# 独立推送服务(主) # 独立推送服务(主)|主备冲突
USE_ALONE_SERVER=true USE_ALONE_SERVER=true
ALONE_SERVER_ADDR=tcp://47.102.120.84:10010 ALONE_SERVER_ADDR=tcp://47.102.120.84:10010
ALONE_SERVER_KEY=,*(?PVl]nIbo35sB ALONE_SERVER_KEY=,*(?PVl]nIbo35sB
# 分区推送服务(备) # 分区推送服务(备)|主备冲突
USE_ZONE_SERVER=false USE_ZONE_SERVER=false
ZONE_SERVER_ADDR=tcp://broadcastlv.chat.bilibili.com:2243/sub ZONE_SERVER_ADDR=tcp://broadcastlv.chat.bilibili.com:2243/sub
@ -87,8 +87,9 @@ USE_SCKEY=
# 直播间ID用于礼物赠送 # 直播间ID用于礼物赠送
ROOM_ID=9522051 ROOM_ID=9522051
# 勋章亲密度,测试功能,使用长位房间号,左侧优先,仅支持辣条和亿元 # 勋章亲密度,测试功能,有短位使用短位反之长位,左侧优先,仅支持辣条和亿元
# 是否填满(按时间投喂正常礼物,否则过期礼物)|直播间ID列表|逗号分隔 # 当列表中所有ID都已达到每日上限剩余礼物赠送ROOM_ID指定的直播间
# 是否填满(按时间投喂正常礼物,否则过期礼物)|直播间ID列表|逗号分隔|
FEED_FILL=false FEED_FILL=false
ROOM_LIST=9522051 ROOM_LIST=9522051

View File

@ -10,7 +10,9 @@
namespace BiliHelper\Core; namespace BiliHelper\Core;
use BiliHelper\Plugin; use Amp\Delayed;
use Amp\Loop;
use function Amp\asyncCall;
class App class App
{ {
@ -38,35 +40,54 @@ class App
return $this; return $this;
} }
/**
* @use 新任务
* @param string $classname
*/
public function newTask(string $classname)
{
asyncCall(function () use ($classname) {
while (true) {
call_user_func(array('BiliHelper\Plugin\\' . $classname, 'run'), []);
yield new Delayed(1000);
}
});
}
/** /**
* @use 核心运行 * @use 核心运行
*/ */
public function start() public function start()
{ {
while (true) { $plugins = [
Plugin\Login::run(); 'Login',
Plugin\Sleep::run(); 'Sleep',
Plugin\MasterSite::run(); 'MasterSite',
Plugin\Daily::run(); 'Daily',
Plugin\Heart::run(); 'Heart',
Plugin\Task::run(); 'Task',
Plugin\Silver::run(); 'Silver',
Plugin\Barrage::run(); 'Barrage',
Plugin\Silver2Coin::run(); 'Silver2Coin',
Plugin\GiftSend::run(); 'GiftSend',
Plugin\GroupSignIn::run(); 'GroupSignIn',
Plugin\GiftHeart::run(); 'GiftHeart',
Plugin\MaterialObject::run(); 'MaterialObject',
Plugin\AloneTcpClient::run(); 'AloneTcpClient',
Plugin\ZoneTcpClient::run(); 'ZoneTcpClient',
Plugin\StormRaffle::run(); 'StormRaffle',
Plugin\GiftRaffle::run(); 'GiftRaffle',
Plugin\PkRaffle::run(); 'PkRaffle',
Plugin\GuardRaffle::run(); 'GuardRaffle',
Plugin\AnchorRaffle::run(); 'AnchorRaffle',
Plugin\AwardRecord::run(); 'AwardRecord',
Plugin\Statistics::run(); 'Statistics',
usleep(0.1 * 1000000); ];
foreach ($plugins as $plugin) {
$this->newTask($plugin);
} }
Loop::run();
} }
} }

View File

@ -21,6 +21,7 @@ class GiftSend
protected static $tid = 0; protected static $tid = 0;
protected static $r_uid = 0; protected static $r_uid = 0;
protected static $room_id = 0; protected static $room_id = 0;
protected static $short_id = 0;
protected static $room_list = []; protected static $room_list = [];
protected static $medal_list = []; protected static $medal_list = [];
@ -53,28 +54,30 @@ class GiftSend
return false; return false;
} }
self::getMedalList(); self::getMedalList();
foreach (self::$medal_list as $key => $val) { foreach (self::$medal_list as $room_id => $total_intimacy) {
$bag_list = self::fetchBagList(); $bag_list = self::fetchBagList();
if (getenv('FEED_FILL') == 'false') { if (getenv('FEED_FILL') == 'false') {
$bag_list = self::checkExpireGift($bag_list); $bag_list = self::checkExpireGift($bag_list);
} }
if (count($bag_list)) { if (count($bag_list)) {
self::$tid = $key; self::$tid = $room_id;
self::getRoomInfo(); self::getRoomInfo();
array_multisort(array_column($bag_list, "expire_at"), SORT_ASC, $bag_list); // array_multisort(array_column($bag_list, "expire_at"), SORT_ASC, $bag_list);
} else { } else {
break; break;
} }
$current_intimacy = 0;
foreach ($bag_list as $gift) { foreach ($bag_list as $gift) {
// 是辣条、亿元 && 不是过期礼物 // 是辣条、亿元 && 不是过期礼物
if (!in_array($gift['gift_id'], [1, 6]) && getenv('FEED_FILL') != 'false') { if (!in_array($gift['gift_id'], [1, 6])) {
continue; continue;
} }
$amt = self::calcAmt($gift); Log::notice("直播间 {$room_id} 需赠送亲密度 {$total_intimacy} 剩余亲密度 " . ($total_intimacy - $current_intimacy));
$amt = self::calcAmt($gift, $total_intimacy - $current_intimacy);
self::sendGift($gift, $amt); self::sendGift($gift, $amt);
$val -= $amt; $current_intimacy += ($gift['gift_id'] == 6) ? ($amt * 10) : $amt;
if (!$val) { if (!($current_intimacy - $total_intimacy)) {
Log::notice("直播间 {$key} 亲密度 {$val} 送满啦~送满啦~"); Log::notice("直播间 {$room_id} 亲密度 {$total_intimacy} 送满啦~送满啦~");
break; break;
} }
} }
@ -227,24 +230,26 @@ class GiftSend
Log::info('直播间信息生成完毕!'); Log::info('直播间信息生成完毕!');
self::$r_uid = (string)$data['data']['uid']; self::$r_uid = (string)$data['data']['uid'];
self::$room_id = (string)$data['data']['room_id']; self::$room_id = (string)$data['data']['room_id'];
self::$short_id = $data['data']['short_id'] ? (string)$data['data']['short_id'] : self::$room_id;
} }
/** /**
* @use 计算赠送数量 * @use 计算赠送数量
* @param array $gift * @param array $gift
* @param int $surplus_num
* @return int * @return int
*/ */
protected static function calcAmt(array $gift): int protected static function calcAmt(array $gift, int $surplus_num): int
{ {
$amt = $gift['gift_num']; $amt = $gift['gift_num'];
if ($gift['gift_id'] == 1) { if ($gift['gift_id'] == 1) {
$amt = (self::$medal_list[self::$room_id] > $gift['gift_num']) ? $gift['gift_num'] : self::$medal_list[self::$room_id]; $amt = ($surplus_num > $gift['gift_num']) ? $gift['gift_num'] : floor($surplus_num);
} }
if ($gift['gift_id'] == 6) { if ($gift['gift_id'] == 6) {
$amt = (floor(self::$medal_list[self::$room_id] / 10) > $gift['gift_num']) ? $gift['gift_num'] : floor(self::$medal_list[self::$room_id] / 10); $amt = (floor($surplus_num / 10) > $gift['gift_num']) ? $gift['gift_num'] : floor($surplus_num / 10);
} }
return $amt; return ($amt < 1) ? 1 : $amt;
} }

View File

@ -21,8 +21,8 @@ class Sleep
// TODO 黑白名单|考虑添加到每个插件内部自动添加|优化RUN逻辑代码 // TODO 黑白名单|考虑添加到每个插件内部自动添加|优化RUN逻辑代码
private static $unlock_hour = 24; private static $unlock_hour = 24;
private static $unlock_time = 0; private static $unlock_time = 0;
private static $fillable = ['Login', 'Sleep', 'Daily', 'MasterSite', 'GiftSend', 'Task', 'Silver2Coin', 'GroupSignIn', 'GiftHeart', 'AwardRecord', 'Statistics']; private static $fillable = ['Login', 'Sleep', 'Daily', 'MasterSite', 'GiftSend', 'Task', 'Silver2Coin', 'GroupSignIn', 'AwardRecord', 'Statistics'];
private static $guarded = ['Barrage', 'Heart', 'Silver', 'MaterialObject', 'AloneTcpClient', 'ZoneTcpClient', 'StormRaffle', 'GuardRaffle', 'PkRaffle', 'GiftRaffle', 'AnchorRaffle']; private static $guarded = ['Barrage', 'GiftHeart', 'Heart', 'Silver', 'MaterialObject', 'AloneTcpClient', 'ZoneTcpClient', 'StormRaffle', 'GuardRaffle', 'PkRaffle', 'GiftRaffle', 'AnchorRaffle'];
private static $sleep_section = []; private static $sleep_section = [];