48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Text.Json;
|
|
using System.Threading;
|
|
|
|
namespace ZaoBot
|
|
{
|
|
class Program
|
|
{
|
|
static BotService bot;
|
|
static JsonDocument config;
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
|
|
config = LoadConfig();
|
|
var receiver = new NotificationReceiver(config);
|
|
var notificationThread = new Thread(new ThreadStart(receiver.Run));
|
|
notificationThread.Start();
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
bot = new BotService(config);
|
|
bot.Run();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
// Тут ловим всё, при ошибках просто заново поднимаем бота
|
|
Console.WriteLine("Exception: " + e.Message);
|
|
Console.WriteLine(e.StackTrace);
|
|
Console.WriteLine("Restarting bot");
|
|
}
|
|
}
|
|
}
|
|
|
|
private static JsonDocument LoadConfig()
|
|
{
|
|
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
var config = Path.Combine(assemblyFolder, "zaobot.json");
|
|
string configStr = File.ReadAllText(config);
|
|
return JsonDocument.Parse(configStr);
|
|
}
|
|
}
|
|
}
|