1
0

add basic create and list reminder api

This commit is contained in:
2023-08-03 13:57:12 +07:00
parent e5693edc49
commit 4d16a67a2b
8 changed files with 190 additions and 246 deletions

View File

@@ -0,0 +1,44 @@
using Budet_cho_bot.Helpers;
using Budet_cho_bot.Models;
using Budet_cho_bot.Repositories;
using Discord;
using Discord_Bot;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Budet_cho_bot.Services
{
internal class ReminderService
{
private readonly CronRepository _cronRepository = new CronRepository();
private const long DAY_PERIOD = 24 * 60 * 60 * 1000; // 10 * 1000; //
private Timer reminderTimer;
public async void SendReminder(object? state)
{
var users = Functions.GetConfigItem("users").ToString();
//await ReplyAsync($"{users}\nБудет чо?");
}
public async Task<int> CreateTask(CronRecord record)
{
var cron = await _cronRepository.GetCronTask("reminder");
var cronUnpacked = Utility.UnpackTimetableFromString(cron);
var result = await _cronRepository.SetCronTask("reminder", Utility.PackTimetableIntoString(cronUnpacked.Append(record).ToArray()));
return result;
}
public async Task<CronRecord[]> GetTasks()
{
var cron = await _cronRepository.GetCronTask("reminder");
var cronUnpacked = Utility.UnpackTimetableFromString(cron);
return cronUnpacked;
}
}
}