External commands
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
|
|
||||||
@@ -7,6 +9,18 @@ namespace DiscordBot;
|
|||||||
|
|
||||||
public static class Entry
|
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 =
|
private static readonly string logo =
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
@"
|
@"
|
||||||
@@ -36,12 +50,9 @@ public static class Entry
|
|||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#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))
|
StartupActions.FirstOrDefault(action => action.Command == args[0], null)?.RunAction(args[..1]);
|
||||||
{
|
|
||||||
File.Delete(plugin);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
10
DiscordBot/IStartupAction.cs
Normal file
10
DiscordBot/IStartupAction.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace DiscordBot
|
||||||
|
{
|
||||||
|
internal interface IStartupAction
|
||||||
|
{
|
||||||
|
string Command { get; init; }
|
||||||
|
Action<string[]> RunAction { get; init; }
|
||||||
|
}
|
||||||
|
}
|
||||||
10
DiscordBot/StartupAction.cs
Normal file
10
DiscordBot/StartupAction.cs
Normal 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user