From 84b554f1022c2fb8be26aa636a76eff4e9edfffc Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Fri, 18 Jul 2025 12:17:15 +0700 Subject: [PATCH] H&R: add reach by leech time --- .../SettingResource/Pages/EditSetting.php | 1 + app/Repositories/HitAndRunRepository.php | 28 +++++++++++++++++++ include/constants.php | 2 +- resources/lang/en/hr.php | 1 + resources/lang/en/label.php | 2 ++ resources/lang/zh_CN/hr.php | 1 + resources/lang/zh_CN/label.php | 2 ++ resources/lang/zh_TW/hr.php | 1 + resources/lang/zh_TW/label.php | 2 ++ 9 files changed, 39 insertions(+), 1 deletion(-) diff --git a/app/Filament/Resources/System/SettingResource/Pages/EditSetting.php b/app/Filament/Resources/System/SettingResource/Pages/EditSetting.php index 4c8871bb..29c887a6 100644 --- a/app/Filament/Resources/System/SettingResource/Pages/EditSetting.php +++ b/app/Filament/Resources/System/SettingResource/Pages/EditSetting.php @@ -212,6 +212,7 @@ class EditSetting extends Page implements Forms\Contracts\HasForms Forms\Components\Radio::make('hr.mode')->options(HitAndRun::listModes(true))->inline(true)->label(__('label.setting.hr.mode')), Forms\Components\TextInput::make('hr.inspect_time')->helperText(__('label.setting.hr.inspect_time_help'))->label(__('label.setting.hr.inspect_time'))->integer(), Forms\Components\TextInput::make('hr.seed_time_minimum')->helperText(__('label.setting.hr.seed_time_minimum_help'))->label(__('label.setting.hr.seed_time_minimum'))->integer(), + Forms\Components\TextInput::make('hr.leech_time_minimum')->helperText(__('label.setting.hr.leech_time_minimum_help'))->label(__('label.setting.hr.leech_time_minimum'))->integer(), Forms\Components\TextInput::make('hr.ignore_when_ratio_reach')->helperText(__('label.setting.hr.ignore_when_ratio_reach_help'))->label(__('label.setting.hr.ignore_when_ratio_reach'))->integer(), Forms\Components\TextInput::make('hr.ban_user_when_counts_reach')->helperText(__('label.setting.hr.ban_user_when_counts_reach_help'))->label(__('label.setting.hr.ban_user_when_counts_reach'))->integer(), Forms\Components\TextInput::make('hr.include_rate')->helperText(__('label.setting.hr.include_rate_help'))->label(__('label.setting.hr.include_rate'))->numeric(), diff --git a/app/Repositories/HitAndRunRepository.php b/app/Repositories/HitAndRunRepository.php index 90ead2e7..cae72169 100644 --- a/app/Repositories/HitAndRunRepository.php +++ b/app/Repositories/HitAndRunRepository.php @@ -202,6 +202,20 @@ class HitAndRunRepository extends BaseRepository continue; } + //check leech time + if (isset($setting['leech_time_minimum']) && $setting['leech_time_minimum'] > 0) { + $targetLeechTime = $row->snatch->leechtime; + $requireLeechTime = bcmul($setting['leech_time_minimum'], 3600); + do_log("$currentLog, targetLeechTime: $targetLeechTime, requireLeechTime: $requireLeechTime"); + if ($targetLeechTime >= $requireLeechTime) { + $result = $this->reachedByLeechTime($row, $setting); + if ($result) { + $successCounts++; + } + continue; + } + } + //check share ratio $targetShareRatio = bcdiv($row->snatch->uploaded, $row->torrent->size, 4); $requireShareRatio = $setting['ignore_when_ratio_reach']; @@ -273,6 +287,20 @@ class HitAndRunRepository extends BaseRepository return $this->inspectingToReached($hitAndRun, $update, __FUNCTION__); } + private function reachedByLeechTime(HitAndRun $hitAndRun, array $setting): bool + { + do_log(__METHOD__); + $comment = nexus_trans('hr.reached_by_leech_time_comment', [ + 'now' => Carbon::now()->toDateTimeString(), + 'leech_time' => bcdiv($hitAndRun->snatch->leechtime, 3600, 1), + 'leech_time_minimum' => $setting['leech_time_minimum'], + ], $hitAndRun->user->locale); + $update = [ + 'comment' => $comment + ]; + return $this->inspectingToReached($hitAndRun, $update, __FUNCTION__); + } + private function reachedBySpecialUserClass(HitAndRun $hitAndRun): bool { do_log(__METHOD__); diff --git a/include/constants.php b/include/constants.php index b286ef0f..03398c07 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ 'Global', 'reached_by_seed_time_comment' => 'Up to::now,seed time: :seed_time Hour(s) reached :seed_time_minimum Hour(s)', + 'reached_by_leech_time_comment' => 'Up to::now,leech time: :leech_time Hour(s) reached :leech_time_minimum Hour(s)', 'reached_by_share_ratio_comment' => "Up to::now \nseed time: :seed_time Hour(s) Unreached :seed_time_minimum Hour(s) \nShare ratio: :share_ratio reached standard::ignore_when_ratio_reach", 'reached_by_special_user_class_comment' => "Your user class: :user_class_text or donated user, ignore this H&R", 'reached_message_subject' => 'H&R(ID: :hit_and_run_id) reached!', diff --git a/resources/lang/en/label.php b/resources/lang/en/label.php index 02b7862c..83cd75c3 100644 --- a/resources/lang/en/label.php +++ b/resources/lang/en/label.php @@ -82,6 +82,8 @@ return [ 'inspect_time_help' => 'The duration of the examination is calculated from the completion of the download, in hours', 'seed_time_minimum' => 'Seed time minimum', 'seed_time_minimum_help' => 'The shortest time to do the seeds to meet the standard, in hours, must be less than the length of the expedition', + 'leech_time_minimum' => 'Leech time minimum', + 'leech_time_minimum_help' => 'The minimum download time required to meet the standard, in hours, must be less than the length of the expedition. Set to 0 to disable', 'ignore_when_ratio_reach' => 'Achievement Sharing Rate', 'ignore_when_ratio_reach_help' => 'The minimum sharing rate to meet the standard', 'ban_user_when_counts_reach' => 'H&R counts limit', diff --git a/resources/lang/zh_CN/hr.php b/resources/lang/zh_CN/hr.php index 17723477..b81003be 100644 --- a/resources/lang/zh_CN/hr.php +++ b/resources/lang/zh_CN/hr.php @@ -11,6 +11,7 @@ return [ 'mode_' . \App\Models\HitAndRun::MODE_GLOBAL => '全局', 'reached_by_seed_time_comment' => '截止::now,做种时间: :seed_time Hour(s) 已达标 :seed_time_minimum Hour(s)', + 'reached_by_leech_time_comment' => '截止::now,下载时间: :leech_time Hour(s) 已达标 :leech_time_minimum Hour(s)', 'reached_by_share_ratio_comment' => "截止::now \n做种时间: :seed_time Hour(s) 未达标 :seed_time_minimum Hour(s) \n分享率: :share_ratio 达忽略标准::ignore_when_ratio_reach", 'reached_by_special_user_class_comment' => "你是::user_class_text 或捐赠用户,无视此 H&R", 'reached_message_subject' => 'H&R(ID: :hit_and_run_id) 已达标!', diff --git a/resources/lang/zh_CN/label.php b/resources/lang/zh_CN/label.php index 5dd122a1..261877bd 100644 --- a/resources/lang/zh_CN/label.php +++ b/resources/lang/zh_CN/label.php @@ -82,6 +82,8 @@ return [ 'inspect_time_help' => '考察时长自下载完成后开始计算,单位:小时', 'seed_time_minimum' => '达标做种时长', 'seed_time_minimum_help' => '达标的最短做种时长,单位:小时,必须小于考察时长', + 'leech_time_minimum' => '达标下载时长', + 'leech_time_minimum_help' => '达标的最短下载时长,单位:小时,必须小于考察时长。设置为 0 不启用', 'ignore_when_ratio_reach' => '达标分享率', 'ignore_when_ratio_reach_help' => '达标的最小分享率', 'ban_user_when_counts_reach' => 'H&R 数量上限', diff --git a/resources/lang/zh_TW/hr.php b/resources/lang/zh_TW/hr.php index ab3021e8..c90ee6fc 100644 --- a/resources/lang/zh_TW/hr.php +++ b/resources/lang/zh_TW/hr.php @@ -11,6 +11,7 @@ return [ 'mode_' . \App\Models\HitAndRun::MODE_GLOBAL => '全局', 'reached_by_seed_time_comment' => '截止::now,做種時間: :seed_time Hour(s) 已達標 :seed_time_minimum Hour(s)', + 'reached_by_leech_time_comment' => '截止::now,下載時間: :leech_time Hour(s) 已達標 :leech_time_minimum Hour(s)', 'reached_by_share_ratio_comment' => "截止::now \n做種時間: :seed_time Hour(s) 未達標 :seed_time_minimum Hour(s) \n分享率: :share_ratio 達忽略標準::ignore_when_ratio_reach", 'reached_by_special_user_class_comment' => "你是::user_class_text 或捐贈用戶,無視此 H&R", 'reached_message_subject' => 'H&R(ID: :hit_and_run_id) 已達標!', diff --git a/resources/lang/zh_TW/label.php b/resources/lang/zh_TW/label.php index cc1a2f45..69bc49a4 100644 --- a/resources/lang/zh_TW/label.php +++ b/resources/lang/zh_TW/label.php @@ -82,6 +82,8 @@ return [ 'inspect_time_help' => '考察時長自下載完成後開始計算,單位:小時', 'seed_time_minimum' => '達標做種時長', 'seed_time_minimum_help' => '達標的最短做種時長,單位:小時,必須小於考察時長', + 'leech_time_minimum' => '達標下載時長', + 'leech_time_minimum_help' => '達標的最短下載時長,單位:小時,必須小於考察時長。設置爲 0 不啓用', 'ignore_when_ratio_reach' => '達標分享率', 'ignore_when_ratio_reach_help' => '達標的最小分享率', 'ban_user_when_counts_reach' => 'H&R 數量上限',