mirror of
https://github.com/NoiTheCat/BirthdayBot.git
synced 2024-10-16 07:59:57 +00:00
Noi
2f0fe8641a
The BirthdayBot class has been split up into ShardInstance and ShardManager. Several other things have been reorganized so that shards may act independently. The overall goal of these changes made is to limit failures to sections that can easily be discarded and replaced.
47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BirthdayBot
|
|
{
|
|
class Program
|
|
{
|
|
private static ShardManager _bot;
|
|
public static DateTimeOffset BotStartTime { get; private set; }
|
|
|
|
static async Task Main()
|
|
{
|
|
BotStartTime = DateTimeOffset.UtcNow;
|
|
var cfg = new Configuration();
|
|
|
|
Console.CancelKeyPress += OnCancelKeyPressed;
|
|
_bot = new ShardManager(cfg);
|
|
|
|
await Task.Delay(-1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sends a formatted message to console.
|
|
/// </summary>
|
|
public static void Log(string source, string message)
|
|
{
|
|
var ts = DateTime.UtcNow;
|
|
var ls = new string[]{ "\r\n", "\n" };
|
|
foreach (var item in message.Split(ls, StringSplitOptions.None))
|
|
Console.WriteLine($"{ts:u} [{source}] {item}");
|
|
}
|
|
|
|
private static bool _dispose = false;
|
|
private static void OnCancelKeyPressed(object sender, ConsoleCancelEventArgs e)
|
|
{
|
|
e.Cancel = true;
|
|
if (_dispose) return;
|
|
_dispose = true;
|
|
var dispose = Task.Run(_bot.Dispose);
|
|
if (!dispose.Wait(90000))
|
|
{
|
|
Log("Shutdown", "Normal shutdown has not concluded after 90 seconds. Will force quit.");
|
|
}
|
|
Environment.Exit(0);
|
|
}
|
|
}
|
|
}
|