83 lines
2.4 KiB
C#
83 lines
2.4 KiB
C#
using NLog;
|
|
using System;
|
|
using System.Reflection;
|
|
using System.Runtime.CompilerServices;
|
|
using ChaosBot.Discord;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
[assembly: InternalsVisibleTo("ChaosBot.UnitTests")]
|
|
namespace ChaosBot
|
|
{
|
|
internal static class Program
|
|
{
|
|
private static ILogger _logger;
|
|
public static IConfiguration AppSettingsHandler;
|
|
|
|
private static string _appSettingsPath;
|
|
|
|
private static void Main(string[] args)
|
|
{
|
|
_appSettingsPath = args.Length > 0 ? args[0] : "./appsettings.json";
|
|
|
|
try
|
|
{
|
|
/*
|
|
* Load configuration from AppSettings.Json and save as Cfg
|
|
*/
|
|
AppSettingsHandler = LoadConfiguration(_appSettingsPath);
|
|
|
|
/*
|
|
* Initialize the _logger for logging purposes
|
|
*/
|
|
_logger = Logging.GenLog(AppSettingsHandler);
|
|
_logger.Trace("Logger initialized");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.Write($"{MethodBase.GetCurrentMethod()?.ReflectedType?.FullName}: Exception [{ex}] thrown, <[{ex.Message}]>.\n{ex.StackTrace}");
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* Initialize the Discord Client and Login
|
|
*/
|
|
Configuration config = new Configuration();
|
|
_logger.Info($"Starting Up {config.GetValue<string>("Bot:Name")} v{config.GetValue<string>("Bot:Version")}");
|
|
|
|
try
|
|
{
|
|
Task discordBot = LoadDiscord();
|
|
LoadWebServer(args);
|
|
discordBot.GetAwaiter().GetResult();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LoggingFacade.Exception(ex);
|
|
}
|
|
}
|
|
|
|
public static ILogger GetLogger()
|
|
{
|
|
return _logger;
|
|
}
|
|
|
|
private static IConfiguration LoadConfiguration(string appSettingsPath)
|
|
{
|
|
return new ConfigurationBuilder()
|
|
.SetBasePath(System.IO.Directory.GetCurrentDirectory())
|
|
.AddJsonFile(appSettingsPath, optional: false, reloadOnChange: true).Build();
|
|
}
|
|
|
|
private static void LoadWebServer(string[] args)
|
|
{
|
|
WebServer.WebServer.Start(args);
|
|
}
|
|
|
|
private static Task LoadDiscord()
|
|
{
|
|
return DiscordConnect.StartUp();
|
|
}
|
|
}
|
|
}
|