82 lines
2.4 KiB
C#
82 lines
2.4 KiB
C#
using NLog;
|
|
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using ChaosBot.Discord;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
[assembly: InternalsVisibleTo("ChaosBot.UnitTests")]
|
|
namespace ChaosBot
|
|
{
|
|
internal 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";
|
|
new Program().MainFunction().GetAwaiter().GetResult();
|
|
}
|
|
|
|
public static ILogger GetLogger()
|
|
{
|
|
return _logger;
|
|
}
|
|
|
|
private async Task MainFunction()
|
|
{
|
|
try
|
|
{
|
|
/*
|
|
* Load configuration from AppSettings.Json and save as Cfg
|
|
*/
|
|
IConfiguration configurationHandler = LoadConfiguration(_appsettingsPath);
|
|
|
|
/*
|
|
* Initialize the _logger for logging purposes
|
|
*/
|
|
_logger = Logging.GenLog(configurationHandler);
|
|
|
|
/*
|
|
* Set AppSettingsHandler on ConfigurationRepository
|
|
*/
|
|
AppSettingsHandler = configurationHandler;
|
|
|
|
/*
|
|
* Initialize the Discord Client and Login
|
|
*/
|
|
_logger.Info($"Starting Up {AppSettingsHandler.GetValue<string>("Bot:Name")} v{AppSettingsHandler.GetValue<string>("Bot:Version")}");
|
|
|
|
|
|
var discordBot = LoadDiscord();
|
|
LoadWebServer();
|
|
await discordBot;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex, $"Program.MainFunction: Exception [{ex}] thrown, <[{ex.Message}]>.");
|
|
}
|
|
}
|
|
|
|
public static IConfiguration LoadConfiguration(string appsettingsPath)
|
|
{
|
|
return new ConfigurationBuilder()
|
|
.SetBasePath(System.IO.Directory.GetCurrentDirectory())
|
|
.AddJsonFile(appsettingsPath, optional: false, reloadOnChange: true).Build();
|
|
}
|
|
|
|
public static void LoadWebServer()
|
|
{
|
|
WebServer.WebServer.Start(new string[]{});
|
|
}
|
|
|
|
public static Task LoadDiscord()
|
|
{
|
|
return DiscordConnect.StartUp();
|
|
}
|
|
}
|
|
}
|