2022-09-30 09:40:42 -07:00

47 lines
1.4 KiB
C#

using Church.Net.Utility;
using System;
using System.Threading.Tasks;
using WebAPI.Services.Interfaces;
namespace WebAPI.Services.ScheduledTask
{
public class MorningPrayer : IScheduledTask
{
private readonly LineAutoBotService lineAutoBotService;
private readonly ILoggingService loggingService;
private DateTime? nextRunningTime = null;
public MorningPrayer(
LineAutoBotService lineAutoBotService,
ILoggingService loggingService
)
{
this.lineAutoBotService = lineAutoBotService;
this.loggingService = loggingService;
this.SetNextRunningTime();
}
public string Description => "Sent out Ark Morning Prayer";
public bool CheckTime(DateTime time)
{
if(nextRunningTime == null)
{
this.SetNextRunningTime();
return true;
}
return time >= nextRunningTime.Value;
}
public Task<bool> RunTask()
{
SetNextRunningTime();
return lineAutoBotService.PushCommandMessage(LineGroup.Ark, "#pray");
}
private void SetNextRunningTime()
{
nextRunningTime = DateTimeHelper.Today().AddDays(1).AddHours(8);
loggingService.Log($"Scheduled Task {this.Description}", nextRunningTime.Value);
}
}
}