Skip to content

Commit

Permalink
新增观看、分享任务开关
Browse files Browse the repository at this point in the history
  • Loading branch information
RayWangQvQ committed Mar 13, 2021
1 parent 8dd7c58 commit 7b51682
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 8 deletions.
1 change: 1 addition & 0 deletions Ray.BiliBiliTool.sln
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{61613EF4-3644-42D4-A620-70547291FB38}"
ProjectSection(SolutionItems) = preProject
.github\workflows\bilibili-daily-task.yml = .github\workflows\bilibili-daily-task.yml
.github\workflows\live-lottery-task.yml = .github\workflows\live-lottery-task.yml
.github\workflows\publish-release.yml = .github\workflows\publish-release.yml
.github\workflows\repo-sync.yml = .github\workflows\repo-sync.yml
EndProjectSection
Expand Down
10 changes: 9 additions & 1 deletion src/Ray.BiliBiliTool.Application/DailyTaskAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class DailyTaskAppService : AppService, IDailyTaskAppService
private readonly ILiveDomainService _liveDomainService;
private readonly IVipPrivilegeDomainService _vipPrivilegeDomainService;
private readonly IChargeDomainService _chargeDomainService;
private readonly DailyTaskOptions _dailyTaskOptions;
private readonly ICoinDomainService _coinDomainService;
private readonly SecurityOptions _securityOptions;

Expand All @@ -33,8 +34,9 @@ public DailyTaskAppService(
IVipPrivilegeDomainService vipPrivilegeDomainService,
IChargeDomainService chargeDomainService,
IOptionsMonitor<SecurityOptions> securityOptions,
IOptionsMonitor<DailyTaskOptions> dailyTaskOptions,
ICoinDomainService coinDomainService
)
)
{
_logger = logger;
_loginDomainService = loginDomainService;
Expand All @@ -44,6 +46,7 @@ ICoinDomainService coinDomainService
_liveDomainService = liveDomainService;
_vipPrivilegeDomainService = vipPrivilegeDomainService;
_chargeDomainService = chargeDomainService;
_dailyTaskOptions = dailyTaskOptions.CurrentValue;
_coinDomainService = coinDomainService;
_securityOptions = securityOptions.CurrentValue;
}
Expand Down Expand Up @@ -99,6 +102,11 @@ private DailyTaskInfo GetDailyTaskStatus()
[TaskInterceptor("观看、分享视频", false)]
private void WatchAndShareVideo(DailyTaskInfo dailyTaskInfo)
{
if (!_dailyTaskOptions.IsWatchVideo && !_dailyTaskOptions.IsShareVideo)
{
_logger.LogInformation("已配置为关闭,跳过任务");
return;
}
_videoDomainService.WatchAndShareVideo(dailyTaskInfo);
}

Expand Down
49 changes: 45 additions & 4 deletions src/Ray.BiliBiliTool.Config/Options/DailyTaskOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace Ray.BiliBiliTool.Config.Options
{
Expand All @@ -7,6 +8,16 @@ namespace Ray.BiliBiliTool.Config.Options
/// </summary>
public class DailyTaskOptions
{
/// <summary>
/// 是否观看视频
/// </summary>
public bool IsWatchVideo { get; set; }

/// <summary>
/// 是否分享视频
/// </summary>
public bool IsShareVideo { get; set; }

/// <summary>
/// 每日设定的投币数 [0,5]
/// </summary>
Expand All @@ -30,12 +41,20 @@ public class DailyTaskOptions
/// <summary>
/// 充电Up主Id
/// </summary>
public string AutoChargeUpId { get; set; } = "220893216";
public string AutoChargeUpId { get; set; } = "1585227649";

private string _chargeComment;
/// <summary>
/// 充电后留言
/// </summary>
public string ChargeComment { get; set; } = "加油~";
public string ChargeComment
{
get =>
string.IsNullOrWhiteSpace(_chargeComment)
? DefaultComments[new Random().Next(0, DefaultComments.Count)]
: _chargeComment;
set => _chargeComment = value;
}

/// <summary>
/// 每月几号自动领取会员权益的[-1,31],-1表示不指定,默认每月1号;0表示不自动领取
Expand All @@ -50,7 +69,7 @@ public class DailyTaskOptions
/// <summary>
/// 执行客户端操作时的平台 [ios,android]
/// </summary>
public string DevicePlatform { get; set; } = "ios";
public string DevicePlatform { get; set; } = "android";


public List<long> SupportUpIdList
Expand All @@ -72,5 +91,27 @@ public List<long> SupportUpIdList
}
}

private static List<string> DefaultComments = new List<string>
{
"棒",
"棒唉",
"棒耶",
"加油~",
"UP加油!",
"支持~",
"支持支持!",
"催更啦",
"顶顶",
"留下脚印~",
"干杯",
"bilibili干杯",
"o(* ̄▽ ̄*)o",
"(。・∀・)ノ゙嗨",
"(●ˇ∀ˇ●)",
"( •̀ ω •́ )y",
"(ง •_•)ง",
">.<",
"^_~",
};
}
}
4 changes: 3 additions & 1 deletion src/Ray.BiliBiliTool.Console/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

//程序自定义个性化配置
"DailyTaskConfig": {
"IsWatchVideo": true, //是否观看视频
"IsShareVideo": true, //是否分享视频
"NumberOfCoins": 5, //每日设定的投币数 [0,5]
"SelectLike": true, //投币时是否同时点赞[false,true]
"SupportUpIds": ",341688380,1585227649,", //优先选择支持的up主Id集合,多个以英文逗号分隔,如:"123,456"。配置后会优先从指定的up主下挑选视频进行观看、分享和投币,不配置或配置为-1则表示没有特别支持的up,会从关注和排行耪中随机获取支持视频
"DayOfAutoCharge": -1, //每月几号自动充电[-1,31],-1表示不指定,默认月底最后一天;0表示不充电
"AutoChargeUpId": "1585227649", //指定支持的UP主Id,-1表示自己
"ChargeComment": "加油~", //充电后留言
"ChargeComment": "", //充电后留言
"DayOfReceiveVipPrivilege": 1, //每月几号自动领取会员权益的[-1,31],-1表示不指定,默认每月1号;0表示不自动领取
"DayOfExchangeSilver2Coin": 0, //每月几号执行银瓜子兑换硬币[-1,31],-1表示不指定,默认每月最后一天;-2表示每天;0表示不进行兑换
"DevicePlatform": "android" //执行客户端操作时的平台 [ios,android]
Expand Down
4 changes: 2 additions & 2 deletions src/Ray.BiliBiliTool.DomainService/VideoDomainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ public void WatchAndShareVideo(DailyTaskInfo dailyTaskStatus)
_logger.LogInformation("获取随机视频:{title}", targetVideo.Title);
}

if (!dailyTaskStatus.Watch)
if (!dailyTaskStatus.Watch && _dailyTaskOptions.IsWatchVideo)
WatchVideo(targetVideo);
else
_logger.LogInformation("今天已经观看过了,不需要再看啦");

if (!dailyTaskStatus.Share)
if (!dailyTaskStatus.Share && _dailyTaskOptions.IsShareVideo)
ShareVideo(targetVideo);
else
_logger.LogInformation("今天已经分享过了,不用再分享啦");
Expand Down
33 changes: 33 additions & 0 deletions test/ConfigTest/TestDefaultValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Text.Json;
using System.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Ray.BiliBiliTool.Config;
using Ray.BiliBiliTool.Config.Options;
using Ray.BiliBiliTool.Console;
using Xunit;
using Ray.BiliBiliTool.Infrastructure;
using Microsoft.Extensions.Hosting;
using System.Collections.Generic;

namespace ConfigTest
{
public class TestDefaultValue
{
public TestDefaultValue()
{
Program.CreateHost(null);
}

[Fact]
public void Test1()
{
using var scope = Global.ServiceProviderRoot.CreateScope();

var options = scope.ServiceProvider.GetRequiredService<IOptionsMonitor<DailyTaskOptions>>();
var re = options.CurrentValue.ChargeComment;
Debug.WriteLine(re);
}
}
}

0 comments on commit 7b51682

Please sign in to comment.