Update API
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user