mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-19 00:01:00 +08:00
donated user ignore H&R
This commit is contained in:
@@ -12,14 +12,14 @@ class HitAndRunUpdateStatus extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'hr:update_status {--uid=} {--torrent_id=}';
|
||||
protected $signature = 'hr:update_status {--uid=} {--torrent_id=} {--ignore_time=}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Update H&R status, options: --uid, --torrent_id';
|
||||
protected $description = 'Update H&R status, options: --uid, --torrent_id, --ignore_time';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
@@ -40,11 +40,12 @@ class HitAndRunUpdateStatus extends Command
|
||||
{
|
||||
$uid = $this->option('uid');
|
||||
$torrentId = $this->option('torrent_id');
|
||||
$ignoreTime = $this->option('ignore_time');
|
||||
$rep = new HitAndRunRepository();
|
||||
$result = $rep->cronjobUpdateStatus($uid, $torrentId);
|
||||
$result = $rep->cronjobUpdateStatus($uid, $torrentId, $ignoreTime);
|
||||
$log = sprintf(
|
||||
'[%s], %s, uid: %s, torrentId: %s, result: %s',
|
||||
REQUEST_ID, __METHOD__, $uid, $torrentId, var_export($result, true)
|
||||
'[%s], %s, uid: %s, torrentId: %s, ignoreTime: %s, result: %s',
|
||||
REQUEST_ID, __METHOD__, $uid, $torrentId, $ignoreTime, var_export($result, true)
|
||||
);
|
||||
$this->info($log);
|
||||
do_log($log);
|
||||
|
||||
@@ -28,6 +28,7 @@ class Kernel extends ConsoleKernel
|
||||
$schedule->command('exam:checkout_cronjob')->everyMinute();
|
||||
$schedule->command('backup:cronjob')->everyMinute();
|
||||
$schedule->command('hr:update_status')->everyMinute();
|
||||
$schedule->command('hr:update_status --ignore_time=1')->hourly();
|
||||
$schedule->command('user:delete_expired_token')->dailyAt('04:00');
|
||||
}
|
||||
|
||||
|
||||
@@ -367,4 +367,12 @@ class User extends Authenticatable
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isDonating()
|
||||
{
|
||||
if ($this->donoruntil && $this->donoruntil >= Carbon::now()->toDateTimeString()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,8 +12,9 @@ use Illuminate\Support\Facades\DB;
|
||||
class HitAndRunRepository extends BaseRepository
|
||||
{
|
||||
|
||||
public function cronjobUpdateStatus($uid = null, $torrentId = null)
|
||||
public function cronjobUpdateStatus($uid = null, $torrentId = null, $ignoreTime = false): bool|int
|
||||
{
|
||||
do_log("uid: $uid, torrentId: $torrentId, ignoreTime: " . var_export($ignoreTime, true));
|
||||
$size = 1000;
|
||||
$page = 1;
|
||||
$setting = Setting::get('hr');
|
||||
@@ -31,11 +32,10 @@ class HitAndRunRepository extends BaseRepository
|
||||
}
|
||||
$query = HitAndRun::query()
|
||||
->where('status', HitAndRun::STATUS_INSPECTING)
|
||||
->where('created_at', '<', Carbon::now()->subHours($setting['inspect_time']))
|
||||
->with([
|
||||
'torrent' => function ($query) {$query->select(['id', 'size', 'name']);},
|
||||
'snatch',
|
||||
'user' => function ($query) {$query->select(['id', 'username', 'lang', 'class']);},
|
||||
'user' => function ($query) {$query->select(['id', 'username', 'lang', 'class', 'donoruntil']);},
|
||||
'user.language',
|
||||
]);
|
||||
if (!is_null($uid)) {
|
||||
@@ -44,6 +44,9 @@ class HitAndRunRepository extends BaseRepository
|
||||
if (!is_null($torrentId)) {
|
||||
$query->where('torrent_id', $torrentId);
|
||||
}
|
||||
if (!$ignoreTime) {
|
||||
$query->where('created_at', '<', Carbon::now()->subHours($setting['inspect_time']));
|
||||
}
|
||||
$successCounts = 0;
|
||||
while (true) {
|
||||
$logPrefix = "page: $page, size: $size";
|
||||
@@ -54,23 +57,23 @@ class HitAndRunRepository extends BaseRepository
|
||||
break;
|
||||
}
|
||||
foreach ($rows as $row) {
|
||||
$logPrefix = "[HANDLING] " . $row->toJson();
|
||||
$currentLog = "$logPrefix, [HANDLING] " . $row->toJson();
|
||||
do_log($logPrefix);
|
||||
if (!$row->user) {
|
||||
do_log("$logPrefix, user not exists, skip!", 'error');
|
||||
do_log("$currentLog, user not exists, skip!", 'error');
|
||||
continue;
|
||||
}
|
||||
if (!$row->snatch) {
|
||||
do_log("$logPrefix, snatch not exists, skip!", 'error');
|
||||
do_log("$currentLog, snatch not exists, skip!", 'error');
|
||||
continue;
|
||||
}
|
||||
if (!$row->torrent) {
|
||||
do_log("$logPrefix, torrent not exists, skip!", 'error');
|
||||
do_log("$currentLog, torrent not exists, skip!", 'error');
|
||||
continue;
|
||||
}
|
||||
|
||||
//If is VIP or above, pass
|
||||
if ($row->user->class >= HitAndRun::MINIMUM_IGNORE_USER_CLASS) {
|
||||
//If is VIP or above OR donated, pass
|
||||
if ($row->user->class >= HitAndRun::MINIMUM_IGNORE_USER_CLASS || $row->user->isDonating()) {
|
||||
$result = $this->reachedBySpecialUserClass($row);
|
||||
if ($result) {
|
||||
$successCounts++;
|
||||
@@ -81,7 +84,7 @@ class HitAndRunRepository extends BaseRepository
|
||||
//check seed time
|
||||
$targetSeedTime = $row->snatch->seedtime;
|
||||
$requireSeedTime = bcmul($setting['seed_time_minimum'], 3600);
|
||||
do_log("targetSeedTime: $targetSeedTime, requireSeedTime: $requireSeedTime");
|
||||
do_log("$currentLog, targetSeedTime: $targetSeedTime, requireSeedTime: $requireSeedTime");
|
||||
if ($targetSeedTime >= $requireSeedTime) {
|
||||
$result = $this->reachedBySeedTime($row);
|
||||
if ($result) {
|
||||
@@ -93,7 +96,7 @@ class HitAndRunRepository extends BaseRepository
|
||||
//check share ratio
|
||||
$targetShareRatio = bcdiv($row->snatch->uploaded, $row->torrent->size, 4);
|
||||
$requireShareRatio = $setting['ignore_when_ratio_reach'];
|
||||
do_log("targetShareRatio: $targetShareRatio, requireShareRatio: $requireShareRatio");
|
||||
do_log("$currentLog, targetShareRatio: $targetShareRatio, requireShareRatio: $requireShareRatio");
|
||||
if ($targetShareRatio >= $requireShareRatio) {
|
||||
$result = $this->reachedByShareRatio($row);
|
||||
if ($result) {
|
||||
|
||||
@@ -79,7 +79,7 @@ $seeder = ($left == 0) ? "yes" : "no";
|
||||
|
||||
// check passkey
|
||||
if (!$az = $Cache->get_value('user_passkey_'.$passkey.'_content')){
|
||||
$res = sql_query("SELECT id, downloadpos, enabled, uploaded, downloaded, class, parked, clientselect, showclienterror, passkey FROM users WHERE passkey=". sqlesc($passkey)." LIMIT 1");
|
||||
$res = sql_query("SELECT id, downloadpos, enabled, uploaded, downloaded, class, parked, clientselect, showclienterror, passkey, donoruntil FROM users WHERE passkey=". sqlesc($passkey)." LIMIT 1");
|
||||
$az = mysql_fetch_array($res);
|
||||
do_log("[check passkey], currentUser: " . nexus_json_encode($az), 'error');
|
||||
$Cache->cache_value('user_passkey_'.$passkey.'_content', $az, 950);
|
||||
@@ -436,7 +436,12 @@ elseif(isset($self))
|
||||
->first();
|
||||
if ($snatchInfo) {
|
||||
sql_query("UPDATE snatched SET uploaded = uploaded + $trueupthis, downloaded = downloaded + $truedownthis, to_go = $left, $announcetime, last_action = ".$dt." $finished_snatched WHERE torrentid = $torrentid AND userid = $userid") or err("SL Err 2");
|
||||
if ($event == "completed" && $az['class'] < \App\Models\HitAndRun::MINIMUM_IGNORE_USER_CLASS) {
|
||||
if (
|
||||
$event == 'completed'
|
||||
&& $az['class'] < \App\Models\HitAndRun::MINIMUM_IGNORE_USER_CLASS
|
||||
&& (empty($az['donoruntil']) || $az['donoruntil'] === '0000-00-00 00:00:00' || $az['donoruntil'] < date("Y-m-d H:i:s"))
|
||||
) {
|
||||
//think about H&R
|
||||
$hrMode = get_setting('hr.mode');
|
||||
if ($hrMode == \App\Models\HitAndRun::MODE_GLOBAL || ($hrMode == \App\Models\HitAndRun::MODE_MANUAL && $torrent['hr'] == \App\Models\Torrent::HR_YES)) {
|
||||
$sql = "insert into hit_and_runs (uid, torrent_id, snatched_id) values ($userid, $torrentid, {$snatchInfo->id}) on duplicate key update updated_at = " . sqlesc(date('Y-m-d H:i:s'));
|
||||
|
||||
@@ -12,7 +12,7 @@ return [
|
||||
|
||||
'reached_by_seed_time_comment' => 'Up to::now,seed time: :seed_time Hour(s) reached :seed_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, ignore this H&R",
|
||||
'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!',
|
||||
'reached_message_content' => 'Congratulation! The torrent: :torrent_name(ID: :torrent_id) you download at: :completed_at has reach the requirement.',
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ return [
|
||||
|
||||
'reached_by_seed_time_comment' => '截止::now,做种时间: :seed_time Hour(s) 已达标 :seed_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_by_special_user_class_comment' => "你是::user_class_text 或捐赠用户,无视此 H&R",
|
||||
'reached_message_subject' => 'H&R(ID: :hit_and_run_id) 已达标!',
|
||||
'reached_message_content' => '你于 :completed_at 下载完成的种子::torrent_name(ID: :torrent_id) H&R 已达标,恭喜!',
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ return [
|
||||
|
||||
'reached_by_seed_time_comment' => '截止::now,做種時間: :seed_time Hour(s) 已達標 :seed_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_by_special_user_class_comment' => "你是::user_class_text 或捐贈用戶,無視此 H&R",
|
||||
'reached_message_subject' => 'H&R(ID: :hit_and_run_id) 已達標!',
|
||||
'reached_message_content' => '你於 :completed_at 下載完成的種子::torrent_name(ID: :torrent_id) H&R 已達標,恭喜!',
|
||||
|
||||
|
||||
Reference in New Issue
Block a user