From 047376c21f5722265e5627c045b8b2fe37951bad Mon Sep 17 00:00:00 2001 From: Initial-heart-1 Date: Thu, 8 Jun 2023 13:51:22 +0800 Subject: [PATCH 1/3] feat: add NumberOfProtectedCoins --- .../Options/DailyTaskOptions.cs | 5 +++++ src/Ray.BiliBiliTool.Console/appsettings.json | 1 + .../DonateCoinDomainService.cs | 15 +++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/Ray.BiliBiliTool.Config/Options/DailyTaskOptions.cs b/src/Ray.BiliBiliTool.Config/Options/DailyTaskOptions.cs index da828c8e7..cfca61066 100644 --- a/src/Ray.BiliBiliTool.Config/Options/DailyTaskOptions.cs +++ b/src/Ray.BiliBiliTool.Config/Options/DailyTaskOptions.cs @@ -23,6 +23,11 @@ public class DailyTaskOptions /// public int NumberOfCoins { get; set; } = 5; + /// + /// 要保留的硬币数量 [0,int_max] + /// + public int NumberOfProtectedCoins { get; set; } = 0; + /// /// 达到六级后是否开始白嫖 /// diff --git a/src/Ray.BiliBiliTool.Console/appsettings.json b/src/Ray.BiliBiliTool.Console/appsettings.json index 89740733a..3eea38f84 100644 --- a/src/Ray.BiliBiliTool.Console/appsettings.json +++ b/src/Ray.BiliBiliTool.Console/appsettings.json @@ -7,6 +7,7 @@ "IsWatchVideo": true, //是否观看视频 "IsShareVideo": true, //是否分享视频 "NumberOfCoins": 5, //每日设定的投币数 [0,5] + "NumberOfProtectedCoins": 0, // 要保留的硬币数量 [0,int_max],0 为不保留,int_max 通常取 (2^31)-1 "SaveCoinsWhenLv6": false, //达到六级后是否开始白嫖[false,true] "SelectLike": true, //投币时是否同时点赞[false,true] "SupportUpIds": "", //优先选择支持的up主Id集合,多个以英文逗号分隔,如:"123,456"。配置后会优先从指定的up主下挑选视频进行观看、分享和投币,不配置或配置为-1则表示没有特别支持的up,会从关注和排行耪中随机获取支持视频 diff --git a/src/Ray.BiliBiliTool.DomainService/DonateCoinDomainService.cs b/src/Ray.BiliBiliTool.DomainService/DonateCoinDomainService.cs index 387afb54c..c838c2721 100644 --- a/src/Ray.BiliBiliTool.DomainService/DonateCoinDomainService.cs +++ b/src/Ray.BiliBiliTool.DomainService/DonateCoinDomainService.cs @@ -70,6 +70,7 @@ IVideoApi videoApi public async Task AddCoinsForVideos() { int needCoins = await GetNeedDonateCoinNum(); + int protectedCoins = _dailyTaskOptions.NumberOfProtectedCoins; if (needCoins <= 0) return; //投币前硬币余额 @@ -82,6 +83,12 @@ public async Task AddCoinsForVideos() return; } + if (coinBalance <= protectedCoins) + { + _logger.LogInformation("因硬币余额达到或低于保留值,今日暂不执行投币任务"); + return; + } + //余额小于目标投币数,按余额投 if (coinBalance < needCoins) { @@ -89,6 +96,14 @@ public async Task AddCoinsForVideos() _logger.LogInformation("因硬币余额不足,目标投币数调整为: {needCoins}", needCoins); } + //投币后余额小于等于保护值,按保护值允许投 + if (coinBalance - needCoins <= protectedCoins) + { + //余额除去保护部分后还可以投多少 + _ = int.TryParse(decimal.Truncate(coinBalance - protectedCoins).ToString(), out needCoins); + _logger.LogInformation("因硬币余额投币后将达到或低于保留值,目标投币数调整为: {needCoins}", needCoins); + } + int success = 0; int tryCount = 10; for (int i = 1; i <= tryCount && success < needCoins; i++) From f91f2b20b234c576e66078a01d9f5f0b042b00e0 Mon Sep 17 00:00:00 2001 From: Initial-heart-1 Date: Thu, 8 Jun 2023 13:51:46 +0800 Subject: [PATCH 2/3] fix: allow command line pass in arg --- src/Ray.BiliBiliTool.Config/Constants.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Ray.BiliBiliTool.Config/Constants.cs b/src/Ray.BiliBiliTool.Config/Constants.cs index 870682bbe..80ca1a946 100644 --- a/src/Ray.BiliBiliTool.Config/Constants.cs +++ b/src/Ray.BiliBiliTool.Config/Constants.cs @@ -81,6 +81,7 @@ public static Dictionary GetCommandLineMappingsDic() {"--randomSleep","Security:RandomSleepMaxMin"}, {"--numberOfCoins", "DailyTaskConfig:NumberOfCoins"}, + {"--numberOfProtectedCoins", "DailyTaskConfig:NumberOfProtectedCoins"}, {"--saveCoinsWhenLv6", "DailyTaskConfig:SaveCoinsWhenLv6"}, {"--selectLike", "DailyTaskConfig:SelectLike"}, {"--supportUpIds", "DailyTaskConfig:SupportUpIds"}, From 09cdcb6591fb938eacd21847463c6f2e467560c4 Mon Sep 17 00:00:00 2001 From: Initial-heart-1 Date: Thu, 8 Jun 2023 14:12:34 +0800 Subject: [PATCH 3/3] fix: unnecessary logs --- .../DonateCoinDomainService.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Ray.BiliBiliTool.DomainService/DonateCoinDomainService.cs b/src/Ray.BiliBiliTool.DomainService/DonateCoinDomainService.cs index c838c2721..8e5114749 100644 --- a/src/Ray.BiliBiliTool.DomainService/DonateCoinDomainService.cs +++ b/src/Ray.BiliBiliTool.DomainService/DonateCoinDomainService.cs @@ -76,6 +76,7 @@ public async Task AddCoinsForVideos() //投币前硬币余额 decimal coinBalance = await _coinDomainService.GetCoinBalance(); _logger.LogInformation("【投币前余额】 : {coinBalance}", coinBalance); + _ = int.TryParse(decimal.Truncate(coinBalance - protectedCoins).ToString(), out int unprotectedCoins); if (coinBalance <= 0) { @@ -99,9 +100,12 @@ public async Task AddCoinsForVideos() //投币后余额小于等于保护值,按保护值允许投 if (coinBalance - needCoins <= protectedCoins) { - //余额除去保护部分后还可以投多少 - _ = int.TryParse(decimal.Truncate(coinBalance - protectedCoins).ToString(), out needCoins); - _logger.LogInformation("因硬币余额投币后将达到或低于保留值,目标投币数调整为: {needCoins}", needCoins); + //排除需投等于保护后可投数量相等时的情况 + if (unprotectedCoins != needCoins) + { + needCoins = unprotectedCoins; + _logger.LogInformation("因硬币余额投币后将达到或低于保留值,目标投币数调整为: {needCoins}", needCoins); + } } int success = 0;