Added SelfUpdate
This commit is contained in:
@@ -21,6 +21,19 @@ public static class Entry
|
||||
|
||||
File.Delete("./Data/Resources/plugins.json");
|
||||
Directory.Delete("./Libraries/", true);
|
||||
}),
|
||||
|
||||
new StartupAction("--update-cleanup", () => {
|
||||
List<string> files = new List<string>();
|
||||
files.AddRange(Directory.GetFiles("./"));
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
if (file.EndsWith(".bak"))
|
||||
File.Delete(file);
|
||||
}
|
||||
|
||||
Directory.Delete("temp");
|
||||
})
|
||||
];
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using DiscordBot.Bot.Actions.Extra;
|
||||
|
||||
using DiscordBot.Utilities;
|
||||
using DiscordBotCore;
|
||||
using DiscordBotCore.Bot;
|
||||
using DiscordBotCore.Others;
|
||||
@@ -83,19 +83,14 @@ public class Program
|
||||
{
|
||||
await Application.CreateApplication();
|
||||
|
||||
AppUpdater updater = new();
|
||||
var update = await updater.CheckForUpdates();
|
||||
|
||||
if (update != Update.None)
|
||||
AppUpdater updater = new AppUpdater();
|
||||
Update? update = await updater.PrepareUpdate();
|
||||
if(update is not null)
|
||||
{
|
||||
Console.WriteLine($"New update available: {update.UpdateVersion}");
|
||||
Console.WriteLine($"Download link: {update.UpdateUrl}");
|
||||
Console.WriteLine($"Update notes: {update.UpdateNotes}\n\n");
|
||||
|
||||
Console.WriteLine("Waiting 5 seconds ...");
|
||||
await Task.Delay(5000);
|
||||
await ConsoleUtilities.ExecuteTaskWithBuiltInProgress(updater.SelfUpdate, update, "Discord Bot Update");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Application.CurrentApplication.Logger.OnFormattedLog += (sender, logMessage) =>
|
||||
{
|
||||
var messageColor = logMessage.Type switch
|
||||
|
||||
@@ -12,5 +12,11 @@ namespace DiscordBot
|
||||
this.Command = command;
|
||||
this.RunAction = runAction;
|
||||
}
|
||||
|
||||
public StartupAction(string command, Action runAction)
|
||||
{
|
||||
this.Command = command;
|
||||
this.RunAction = (args) => runAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordBotCore.Updater.Application;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace DiscordBot.Utilities;
|
||||
@@ -27,4 +28,22 @@ internal static class ConsoleUtilities
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async Task ExecuteTaskWithBuiltInProgress<T>(Func<T, IProgress<float>, Task> method, T parameter, 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(parameter, progress);
|
||||
task.Value = 100;
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user