2020-10-29 07:53:18 +00:00
|
|
|
|
using BirthdayBot.Data;
|
|
|
|
|
using System;
|
2020-04-02 18:27:55 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace BirthdayBot
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
2020-10-05 04:40:38 +00:00
|
|
|
|
private static ShardManager _bot;
|
2020-04-02 18:27:55 +00:00
|
|
|
|
public static DateTimeOffset BotStartTime { get; private set; }
|
|
|
|
|
|
2020-10-05 04:40:38 +00:00
|
|
|
|
static async Task Main()
|
2020-04-02 18:27:55 +00:00
|
|
|
|
{
|
|
|
|
|
BotStartTime = DateTimeOffset.UtcNow;
|
|
|
|
|
var cfg = new Configuration();
|
|
|
|
|
|
2020-10-29 07:53:18 +00:00
|
|
|
|
await Database.DoInitialDatabaseSetupAsync();
|
|
|
|
|
|
2020-04-02 18:27:55 +00:00
|
|
|
|
Console.CancelKeyPress += OnCancelKeyPressed;
|
2020-10-05 04:40:38 +00:00
|
|
|
|
_bot = new ShardManager(cfg);
|
2020-04-02 18:27:55 +00:00
|
|
|
|
|
2020-10-05 04:40:38 +00:00
|
|
|
|
await Task.Delay(-1);
|
2020-04-02 18:27:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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}");
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-05 04:40:38 +00:00
|
|
|
|
private static bool _dispose = false;
|
2020-04-10 05:48:59 +00:00
|
|
|
|
private static void OnCancelKeyPressed(object sender, ConsoleCancelEventArgs e)
|
2020-04-02 18:27:55 +00:00
|
|
|
|
{
|
|
|
|
|
e.Cancel = true;
|
2020-10-05 04:40:38 +00:00
|
|
|
|
if (_dispose) return;
|
|
|
|
|
_dispose = true;
|
|
|
|
|
var dispose = Task.Run(_bot.Dispose);
|
|
|
|
|
if (!dispose.Wait(90000))
|
2020-04-02 18:27:55 +00:00
|
|
|
|
{
|
2020-10-05 04:40:38 +00:00
|
|
|
|
Log("Shutdown", "Normal shutdown has not concluded after 90 seconds. Will force quit.");
|
2020-04-02 18:27:55 +00:00
|
|
|
|
}
|
|
|
|
|
Environment.Exit(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|