Removed old web ui plugin

This commit is contained in:
2024-08-31 17:27:19 +03:00
parent f7ba5f94ff
commit 30e92b742c
26 changed files with 117 additions and 620 deletions

View File

@@ -1,10 +1,65 @@
using DiscordBotCore;
using DiscordBotCore.Others.Exceptions;
using System.Reflection;
using DiscordBotWebUI.Components;
using DiscordBotWebUI.Components.Pages.Setup;
using DiscordBotWebUI.DiscordBot;
using DiscordBotWebUI.StartupActions;
using Radzen;
string logo =
@"
_____ _ _ _____ _ _ ____ _
/ ____| | | | | | __ \(_) | | | _ \ | |
| (___ ___| |_| |__ | | | |_ ___ ___ ___ _ __ __| | | |_) | ___ | |_
\___ \ / _ \ __| '_ \ | | | | / __|/ __/ _ \| '__/ _` | | _ < / _ \| __|
____) | __/ |_| | | | | |__| | \__ \ (_| (_) | | | (_| | | |_) | (_) | |_
|_____/ \___|\__|_| |_| |_____/|_|___/\___\___/|_| \__,_| |____/ \___/ \__|
(WEB Edition)
";
var currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += LoadFromSameFolder;
static Assembly LoadFromSameFolder(object sender, ResolveEventArgs args)
{
Directory.CreateDirectory("./Libraries");
string requestingAssembly = args.RequestingAssembly?.GetName().Name;
var folderPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, $"Libraries/{requestingAssembly}");
var assemblyName = new AssemblyName(args.Name).Name + ".dll";
var assemblyPath = Path.Combine(folderPath, assemblyName);
if (File.Exists(assemblyPath))
{
var fileAssembly = Assembly.LoadFrom(assemblyPath);
return fileAssembly;
}
return null;
}
// Start startup actions if any
if (args.Length > 0)
{
// get all classes that derive from IStartupAction
var startupActions = Assembly.GetExecutingAssembly()
.GetTypes()
.Where(t => t.IsSubclassOf(typeof(IStartupAction)))
.Select(t => Activator.CreateInstance(t) as IStartupAction)
.ToList();
foreach(var argument in args)
{
startupActions.FirstOrDefault(action => action?.Command == argument)?.RunAction(argument.Split(' ')[1..]);
}
}
Console.Clear();
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine(logo);
Console.ResetColor();
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.

View File

@@ -0,0 +1,16 @@
namespace DiscordBotWebUI.StartupActions.Actions;
public class PurgePlugins : IStartupAction
{
public string Command => "purge_plugins";
public void RunAction(string[] args)
{
foreach (var plugin in Directory.GetFiles("./Data/Plugins", "*.dll", SearchOption.AllDirectories))
{
File.Delete(plugin);
}
File.Delete("./Data/Resources/plugins.json");
Directory.Delete("./Libraries/", true);
}
}

View File

@@ -0,0 +1,20 @@
namespace DiscordBotWebUI.StartupActions.Actions;
public class UpdateCleanup : IStartupAction
{
public string Command => "update-cleanup";
public void RunAction(string[] args)
{
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");
}
}

View File

@@ -0,0 +1,7 @@
namespace DiscordBotWebUI.StartupActions;
internal interface IStartupAction
{
string Command { get; }
void RunAction(string[] args);
}