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
Dmitrii Kollerov 784ece36cd initial
2023-07-14 20:19:56 +07:00

82 lines
2.6 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;
namespace Discord_Bot
{
public class ReminderModule : ModuleBase<SocketCommandContext>
{
private long dayPeriod = 24 * 60 * 60 * 1000;
private Timer reminderTimer;
[Command("remindertime")]
public async Task ReminderTime([Remainder]string message = "")
{
SaveToConfig("reminderTime", message);
var time = message.Split(":");
SetReminderTime(int.Parse(time[0]), int.Parse(time[1]));
await ReplyAsync($"Заебись");
}
[Command("calltime")]
public async Task CallTime([Remainder]string message = "")
{
SaveToConfig("callTime", message);
var time = message.Split(":");
SetReminderTime(int.Parse(time[0]), int.Parse(time[1]));
await ReplyAsync($"Заебись");
}
[Command("users")]
public async Task Users([Remainder]string message = "")
{
SaveToConfig("users", message);
var time = message.Split(":");
SetReminderTime(int.Parse(time[0]), int.Parse(time[1]));
await ReplyAsync($"Заебись");
}
public void SetReminderTime(int hours, int minutes)
{
var now = DateTime.Now;
var nextReminder = new DateTime(now.Year, now.Month, now.Day, hours, minutes, 0);
var span = (nextReminder - now).TotalMilliseconds;
reminderTimer = new Timer(SendReminder, "sd", (long)span, dayPeriod);
ReloadTimers();
}
public void SetCallTime(int hours, int minutes)
{
var now = DateTime.Now;
var nextReminder = new DateTime(now.Year, now.Month, now.Day, hours, minutes, 0);
var span = (nextReminder - now).TotalMilliseconds;
reminderTimer = new Timer(SendReminder, "sd", (long)span, dayPeriod);
ReloadTimers();
}
private async void SendReminder(object? state)
{
var users = Functions.GetConfig()["users"].ToString();
await ReplyAsync($"{users}\nБудет чо?");
}
private async void SendCall(object? state)
{
await ReplyAsync($"?");
}
private void SaveToConfig(string key, string data)
{
var config = Functions.GetConfig();
config[key] = data;
Functions.SaveConfig(config);
}
private void ReloadTimers()
{
}
}
}