44 lines
1008 B
C#
44 lines
1008 B
C#
using System;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Text.Json;
|
|
|
|
namespace ZaoBot
|
|
{
|
|
class Program
|
|
{
|
|
static BotService bot;
|
|
static JsonDocument config;
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
|
|
config = LoadConfig();
|
|
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);
|
|
}
|
|
}
|
|
}
|