Added autoinstall for modules
This commit is contained in:
@@ -4,6 +4,10 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
using DiscordBot.Utilities;
|
||||
|
||||
using DiscordBotCore.Modules;
|
||||
|
||||
namespace DiscordBot;
|
||||
|
||||
|
||||
@@ -13,7 +17,7 @@ public static class Entry
|
||||
/// Some startup actions that can are executed when the console first starts. This actions are invoked externally at application launch
|
||||
/// </summary>
|
||||
private static readonly List<IStartupAction> StartupActions = [
|
||||
new StartupAction("/purge_plugins", (args) => {
|
||||
new StartupAction("/purge_plugins", () => {
|
||||
foreach (var plugin in Directory.GetFiles("./Data/Plugins", "*.dll", SearchOption.AllDirectories))
|
||||
{
|
||||
File.Delete(plugin);
|
||||
@@ -34,6 +38,12 @@ public static class Entry
|
||||
}
|
||||
|
||||
Directory.Delete("temp");
|
||||
}),
|
||||
|
||||
new StartupAction("--module-install", (args) => {
|
||||
ModuleDownloader moduleDownloader = new ModuleDownloader(args[0]);
|
||||
|
||||
ConsoleUtilities.ExecuteTaskWithBuiltInProgress(moduleDownloader.DownloadModule, "Downloading logger module").Wait();
|
||||
})
|
||||
];
|
||||
|
||||
@@ -51,14 +61,12 @@ public static class Entry
|
||||
";
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
#if DEBUG
|
||||
if (args.Length > 0)
|
||||
{
|
||||
StartupActions.FirstOrDefault(action => action.Command == args[0], null)?.RunAction(args[..1]);
|
||||
|
||||
StartupActions.FirstOrDefault(action => action.Command == args[0], null)?.RunAction(args[1..]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Console.Clear();
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.DarkYellow;
|
||||
|
||||
@@ -90,26 +90,8 @@ public class Program
|
||||
await ConsoleUtilities.ExecuteTaskWithBuiltInProgress(updater.SelfUpdate, update, "Discord Bot Update");
|
||||
return;
|
||||
}
|
||||
|
||||
Application.CurrentApplication.Logger.OnFormattedLog += (sender, logMessage) =>
|
||||
{
|
||||
var messageColor = logMessage.Type switch
|
||||
{
|
||||
LogType.INFO => "[green]",
|
||||
LogType.WARNING => "[yellow]",
|
||||
LogType.ERROR => "[red]",
|
||||
LogType.CRITICAL => "[red]",
|
||||
_ => "[white]"
|
||||
};
|
||||
|
||||
if (logMessage.Message.Contains('[') || logMessage.Message.Contains(']'))
|
||||
{
|
||||
logMessage.Message = logMessage.Message.Replace("[", "<").Replace("]", ">");
|
||||
}
|
||||
|
||||
string messageToPrint = $"{messageColor}{logMessage.Message}[/]";
|
||||
AnsiConsole.MarkupLine(messageToPrint);
|
||||
};
|
||||
Application.CurrentApplication.Logger.SetOutFunction(AnsiConsole.MarkupLine);
|
||||
|
||||
|
||||
if (!Application.CurrentApplication.ApplicationEnvironmentVariables.ContainsKey("ServerID") ||
|
||||
|
||||
@@ -46,4 +46,22 @@ internal static class ConsoleUtilities
|
||||
|
||||
}
|
||||
|
||||
public static async Task ExecuteTaskWithBuiltInProgress(Func<IProgress<float>, Task> method, string taskMessage)
|
||||
{
|
||||
await AnsiConsole.Progress()
|
||||
.AutoClear(false) // Do not remove the task list when done
|
||||
.HideCompleted(false) // Hide tasks as they are completed
|
||||
.Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn())
|
||||
.StartAsync(
|
||||
async ctx =>
|
||||
{
|
||||
var task = ctx.AddTask(taskMessage);
|
||||
IProgress<float> progress = new Progress<float>(x => task.Value = x);
|
||||
await method(progress);
|
||||
task.Value = 100;
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user