using SecondBotEvents.Services; using System; using System.Linq; using System.Reflection; using System.Threading; namespace SecondBotEvents { internal class Startup { static void Main(string[] args) { Console.WriteLine("Welcome to Secondbot [Events build] version: " + AssemblyInfo.GetGitHash()); EventsSecondBot worker = new EventsSecondBot(args); while(worker.exit() == false) { Thread.Sleep(1000); } } } internal class EventsSecondBot { public http HttpService = null; public BotClient botClient = null; public string getVersion() { return AssemblyInfo.GetGitHash(); } public bool fromEnv = false; public string fromFolder = ""; protected bool exitNow = false; public EventsSecondBot(string[] args) { if (SecondbotHelpers.notempty(Environment.GetEnvironmentVariable("basic_username")) == true) { fromEnv = true; } fromFolder = "defaultBot"; if (args.Length == 1) { fromFolder = args[0]; } restartServices(); } public void restartServices() { stopServices(); startServices(); } protected void startServices() { HttpService = new http(this); HttpService.start(); botClient = new BotClient(this); if(botClient.basicCfg.isLoaded() == false) { Console.WriteLine("Config is not loaded :("); exitNow = true; return; } botClient.start(); } protected void stopServices() { if (HttpService != null) { HttpService.stop(); } if(botClient != null) { botClient.stop(); } HttpService = null; botClient = null; } public bool exit() { return exitNow; } } public static class AssemblyInfo { /// Gets the git hash value from the assembly /// or null if it cannot be found. public static string GetGitHash() { var asm = typeof(AssemblyInfo).Assembly; var attrs = asm.GetCustomAttributes(); return attrs.FirstOrDefault(a => a.Key == "GitHash")?.Value; } } }