Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add NumberOfProtectedCoins #560

Merged
merged 3 commits into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Ray.BiliBiliTool.Config/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public static Dictionary<string, string> GetCommandLineMappingsDic()
{"--randomSleep","Security:RandomSleepMaxMin"},

{"--numberOfCoins", "DailyTaskConfig:NumberOfCoins"},
{"--numberOfProtectedCoins", "DailyTaskConfig:NumberOfProtectedCoins"},
{"--saveCoinsWhenLv6", "DailyTaskConfig:SaveCoinsWhenLv6"},
{"--selectLike", "DailyTaskConfig:SelectLike"},
{"--supportUpIds", "DailyTaskConfig:SupportUpIds"},
Expand Down
5 changes: 5 additions & 0 deletions src/Ray.BiliBiliTool.Config/Options/DailyTaskOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public class DailyTaskOptions
/// </summary>
public int NumberOfCoins { get; set; } = 5;

/// <summary>
/// 要保留的硬币数量 [0,int_max]
/// </summary>
public int NumberOfProtectedCoins { get; set; } = 0;

/// <summary>
/// 达到六级后是否开始白嫖
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Ray.BiliBiliTool.Console/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,会从关注和排行耪中随机获取支持视频
Expand Down
19 changes: 19 additions & 0 deletions src/Ray.BiliBiliTool.DomainService/DonateCoinDomainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,44 @@ IVideoApi videoApi
public async Task AddCoinsForVideos()
{
int needCoins = await GetNeedDonateCoinNum();
int protectedCoins = _dailyTaskOptions.NumberOfProtectedCoins;
if (needCoins <= 0) return;

//投币前硬币余额
decimal coinBalance = await _coinDomainService.GetCoinBalance();
_logger.LogInformation("【投币前余额】 : {coinBalance}", coinBalance);
_ = int.TryParse(decimal.Truncate(coinBalance - protectedCoins).ToString(), out int unprotectedCoins);

if (coinBalance <= 0)
{
_logger.LogInformation("因硬币余额不足,今日暂不执行投币任务");
return;
}

if (coinBalance <= protectedCoins)
{
_logger.LogInformation("因硬币余额达到或低于保留值,今日暂不执行投币任务");
return;
}

//余额小于目标投币数,按余额投
if (coinBalance < needCoins)
{
_ = int.TryParse(decimal.Truncate(coinBalance).ToString(), out needCoins);
_logger.LogInformation("因硬币余额不足,目标投币数调整为: {needCoins}", needCoins);
}

//投币后余额小于等于保护值,按保护值允许投
if (coinBalance - needCoins <= protectedCoins)
{
//排除需投等于保护后可投数量相等时的情况
if (unprotectedCoins != needCoins)
{
needCoins = unprotectedCoins;
_logger.LogInformation("因硬币余额投币后将达到或低于保留值,目标投币数调整为: {needCoins}", needCoins);
}
}

int success = 0;
int tryCount = 10;
for (int i = 1; i <= tryCount && success < needCoins; i++)
Expand Down