The bot is running on the main Thread now

This commit is contained in:
2023-05-28 17:18:55 +03:00
parent c94cdca6eb
commit f16c139362

View File

@@ -5,6 +5,7 @@ using System.IO;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Linq;
using PluginManager; using PluginManager;
using PluginManager.Bot; using PluginManager.Bot;
@@ -43,7 +44,7 @@ public class Program
Installer.GenerateStartupConfig(); Installer.GenerateStartupConfig();
} }
HandleInput(args).Wait(); HandleInput(args.ToList()).Wait();
} }
/// <summary> /// <summary>
@@ -120,7 +121,7 @@ public class Program
} }
catch (Exception ex) catch (Exception ex)
{ {
Config.Logger.Log(ex.ToString(),"Bot",TextType.ERROR); Config.Logger.Log(ex.ToString(), "Bot", TextType.ERROR);
return null; return null;
} }
} }
@@ -129,20 +130,21 @@ public class Program
/// Handle user input arguments from the startup of the application /// Handle user input arguments from the startup of the application
/// </summary> /// </summary>
/// <param name="args">The arguments</param> /// <param name="args">The arguments</param>
private static async Task HandleInput(string[] args) private static async Task HandleInput(List<string> args)
{ {
var len = args.Length;
Console.WriteLine("Loading Core ..."); Console.WriteLine("Loading Core ...");
var b = await StartNoGui(); var b = await StartNoGui();
consoleCommandsHandler = new ConsoleCommandsHandler(b.client); consoleCommandsHandler = new ConsoleCommandsHandler(b.client);
var mainThread = new Thread(() =>
{
try try
{ {
Console.WriteLine("Launching core functions ..."); if(args.Contains("--gui"))
{
// GUI not implemented yet
Console.WriteLine("GUI not implemented yet");
return;
}
NoGUI(); NoGUI();
} }
catch (IOException ex) catch (IOException ex)
@@ -152,11 +154,10 @@ public class Program
if (Config.Data.ContainsKey("LaunchMessage")) if (Config.Data.ContainsKey("LaunchMessage"))
Config.Data.Add("LaunchMessage", Config.Data.Add("LaunchMessage",
"An error occured while closing the bot last time. Please consider closing the bot using the &rsd&c method !\nThere is a risk of losing all data or corruption of the save file, which in some cases requires to reinstall the bot !"); "An error occured while closing the bot last time. Please consider closing the bot using the &rsd&c method !\nThere is a risk of losing all data or corruption of the save file, which in some cases requires to reinstall the bot !");
Config.Logger.Log("An error occured while closing the bot last time. Please consider closing the bot using the &rsd&c method !\nThere is a risk of losing all data or corruption of the save file, which in some cases requires to reinstall the bot !","Bot",TextType.ERROR); Config.Logger.Log("An error occured while closing the bot last time. Please consider closing the bot using the &rsd&c method !\nThere is a risk of losing all data or corruption of the save file, which in some cases requires to reinstall the bot !", "Bot", TextType.ERROR);
} }
} }
}); return;
mainThread.Start();
} }
private static async Task PreLoadComponents(string[] args) private static async Task PreLoadComponents(string[] args)
@@ -199,7 +200,7 @@ public class Program
} }
catch (Exception ex) catch (Exception ex)
{ {
Config.Logger.Log(ex.ToString(),"Bot",TextType.ERROR); Config.Logger.Log(ex.ToString(), "Bot", TextType.ERROR);
} }
} }
@@ -283,7 +284,7 @@ public class Program
} }
catch (Exception ex) catch (Exception ex)
{ {
Config.Logger.Log(ex.Message,"Updater", TextType.ERROR); Config.Logger.Log(ex.Message, "Updater", TextType.ERROR);
if (ex.Message.Contains("Access de")) if (ex.Message.Contains("Access de"))
Config.Logger.Log("Please run the bot as root."); Config.Logger.Log("Please run the bot as root.");
} }