1
0
This repository has been archived on 2023-08-03. You can view files and clone it, but cannot push or open issues or pull requests.
budet-cho-bot/Budet-cho-bot/Modules/ReminderModule.cs
2023-07-25 19:06:46 +08:00

76 lines
2.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Discord.Commands;
using Discord.Commands.Builders;
using Newtonsoft.Json.Linq;
namespace Discord_Bot
{
public class ReminderModule : ModuleBase<SocketCommandContext>
{
private const long DAY_PERIOD = 24 * 60 * 60 * 1000; // 10 * 1000; //
private Timer reminderTimer;
protected override void OnModuleBuilding(CommandService commandService, ModuleBuilder builder)
{
base.OnModuleBuilding(commandService, builder);
Console.WriteLine($"{DateTime.Now.TimeOfDay:hh\\:mm\\:ss} | hello world ");
ReloadTimers();
}
[Command("remindertime")]
private async Task SetReminderTime([Remainder]string message = "")
{
SaveToConfig("reminderTime", Utility.ParseMessage(message));
ReloadTimers();
await ReplyAsync($"Заебись");
}
[Command("sequence")]
private async Task SetSequence([Remainder]string message = "")
{
SaveToConfig("sequence", message);
await ReplyAsync($"Заебись");
}
[Command("users")]
private async Task Users([Remainder]string message = "")
{
SaveToConfig("users", message);
await ReplyAsync($"Заебись");
}
private void ReloadTimers()
{
var time = Functions.GetConfigItem("reminderTime");
if (time.Type == JTokenType.Boolean)
return;
var nextReminder = Utility.ParseTime(time.ToString());
var now = DateTime.Now;
var span = (nextReminder - now).TotalMilliseconds;
if (span < 0)
{
// skip to next day
nextReminder = nextReminder.AddDays(1);
span = (nextReminder - now).TotalMilliseconds;
}
reminderTimer = new Timer(SendReminder, "sd", (long)span, DAY_PERIOD);
}
private async void SendReminder(object? state)
{
//check sequence
var users = Functions.GetConfigItem("users").ToString();
await ReplyAsync($"{users}\nБудет чо?");
}
private void SaveToConfig(string key, string data)
{
var config = Functions.GetConfig();
config[key] = data;
Functions.SaveConfig(config);
}
}
}