External commands

This commit is contained in:
2024-05-21 21:33:42 +03:00
parent a5e65a5ea5
commit 4c8fd1a672
3 changed files with 36 additions and 5 deletions

View File

@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
@@ -7,6 +9,18 @@ namespace DiscordBot;
public static class Entry
{
/// <summary>
/// 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) => {
foreach (var plugin in Directory.GetFiles("./Data/Plugins", "*.dll", SearchOption.AllDirectories))
{
File.Delete(plugin);
}
})
];
private static readonly string logo =
#if DEBUG
@"
@@ -36,12 +50,9 @@ public static class Entry
public static void Main(string[] args)
{
#if DEBUG
if (args.Length == 1 && args[0] == "/purge_plugins" )
if (args.Length > 0)
{
foreach (var plugin in Directory.GetFiles("./Data/Plugins", "*.dll", SearchOption.AllDirectories))
{
File.Delete(plugin);
}
StartupActions.FirstOrDefault(action => action.Command == args[0], null)?.RunAction(args[..1]);
}
#endif

View File

@@ -0,0 +1,10 @@
using System;
namespace DiscordBot
{
internal interface IStartupAction
{
string Command { get; init; }
Action<string[]> RunAction { get; init; }
}
}

View File

@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DiscordBot
{
internal record StartupAction(string Command, Action<string[]> RunAction) : IStartupAction;
}