Fixed Internal Actions to refresh after external actions are loaded
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Discord.Net" Version="3.11.0"/>
|
||||
<PackageReference Include="pythonnet" Version="3.0.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PluginManager\PluginManager.csproj"/>
|
||||
|
||||
@@ -44,7 +44,9 @@ public class Program
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Debug mode enabled");
|
||||
internalActionManager.Initialize().Wait();
|
||||
internalActionManager.Execute("plugin", "load").Wait(); // Load plugins at startup
|
||||
internalActionManager.Refresh().Wait();
|
||||
#endif
|
||||
|
||||
while (true)
|
||||
@@ -139,9 +141,7 @@ public class Program
|
||||
var b = await StartNoGui();
|
||||
try
|
||||
{
|
||||
internalActionManager = new InternalActionManager("./Data/Actions", "*.dll");
|
||||
await internalActionManager.Initialize();
|
||||
|
||||
internalActionManager = new InternalActionManager("./Data/Plugins", "*.dll");
|
||||
NoGUI();
|
||||
}
|
||||
catch ( IOException ex )
|
||||
|
||||
@@ -15,7 +15,7 @@ public class ActionsLoader
|
||||
|
||||
private readonly string actionExtension = "dll";
|
||||
|
||||
private readonly string actionFolder = @"./Data/Actions/";
|
||||
private readonly string actionFolder = @"./Data/Plugins/";
|
||||
|
||||
public ActionsLoader(string path, string extension)
|
||||
{
|
||||
|
||||
@@ -18,23 +18,31 @@ public class InternalActionManager
|
||||
|
||||
public async Task Initialize()
|
||||
{
|
||||
loader.ActionLoadedEvent += OnActionLoaded;
|
||||
//loader.ActionLoadedEvent += OnActionLoaded;
|
||||
var m_actions = await loader.Load();
|
||||
if (m_actions == null) return;
|
||||
foreach (var action in m_actions)
|
||||
Actions.Add(action.ActionName, action);
|
||||
}
|
||||
|
||||
private void OnActionLoaded(string name, string typeName, bool success, Exception? e)
|
||||
{
|
||||
if (!success)
|
||||
{
|
||||
Config.Logger.Error(e);
|
||||
return;
|
||||
Actions.TryAdd(action.ActionName, action);
|
||||
}
|
||||
|
||||
Config.Logger.Log($"Action {name} loaded successfully", LogLevel.INFO, true);
|
||||
}
|
||||
|
||||
public async Task Refresh()
|
||||
{
|
||||
Actions.Clear();
|
||||
await Initialize();
|
||||
}
|
||||
|
||||
// private void OnActionLoaded(string name, string typeName, bool success, Exception? e)
|
||||
// {
|
||||
// if (!success)
|
||||
// {
|
||||
// Config.Logger.Error(e);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// Config.Logger.Log($"Action {name} loaded successfully", LogLevel.INFO, true);
|
||||
// }
|
||||
|
||||
public async Task<string> Execute(string actionName, params string[]? args)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using Discord.Commands;
|
||||
using System.Linq;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using PluginManager.Bot;
|
||||
|
||||
namespace PluginManager.Others;
|
||||
|
||||
@@ -13,6 +16,30 @@ public class DBCommandExecutingArguments
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
public DBCommandExecutingArguments(SocketUserMessage? message, DiscordSocketClient client)
|
||||
{
|
||||
this.context = new SocketCommandContext(client, message);
|
||||
int pos = 0;
|
||||
if (message.HasMentionPrefix(client.CurrentUser, ref pos))
|
||||
{
|
||||
var mentionPrefix = "<@" + client.CurrentUser.Id + ">";
|
||||
this.cleanContent = message.Content.Substring(mentionPrefix.Length + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.cleanContent = message.Content.Substring(Config.DiscordBot.botPrefix.Length);
|
||||
}
|
||||
|
||||
var split = this.cleanContent.Split(' ');
|
||||
|
||||
string[]? argsClean = null;
|
||||
if (split.Length > 1)
|
||||
argsClean = string.Join(' ', split, 1, split.Length - 1).Split(' ');
|
||||
|
||||
this.commandUsed = split[0];
|
||||
this.arguments = argsClean;
|
||||
}
|
||||
|
||||
public SocketCommandContext context { get; init; }
|
||||
public string cleanContent { get; init; }
|
||||
public string commandUsed { get; init; }
|
||||
|
||||
@@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MusicPlayer", "..\SethPlugi
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LevelingSystem", "..\SethPlugins\LevelingSystem\LevelingSystem.csproj", "{BFE3491C-AC01-4252-B242-6451270FC548}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PythonCompatibilityLayer", "..\SethPlugins\PythonCompatibilityLayer\PythonCompatibilityLayer.csproj", "{81ED4953-13E5-4950-96A8-8CEF5FD59559}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -35,6 +37,10 @@ Global
|
||||
{BFE3491C-AC01-4252-B242-6451270FC548}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BFE3491C-AC01-4252-B242-6451270FC548}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BFE3491C-AC01-4252-B242-6451270FC548}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{81ED4953-13E5-4950-96A8-8CEF5FD59559}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{81ED4953-13E5-4950-96A8-8CEF5FD59559}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{81ED4953-13E5-4950-96A8-8CEF5FD59559}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{81ED4953-13E5-4950-96A8-8CEF5FD59559}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -42,6 +48,7 @@ Global
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{1690CBBC-BDC0-4DD8-B701-F8817189D9D5} = {78B6D390-F61A-453F-B38D-E4C054321615}
|
||||
{BFE3491C-AC01-4252-B242-6451270FC548} = {78B6D390-F61A-453F-B38D-E4C054321615}
|
||||
{81ED4953-13E5-4950-96A8-8CEF5FD59559} = {78B6D390-F61A-453F-B38D-E4C054321615}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {3FB3C5DE-ED21-4D2E-ABDD-3A00EE4A2FFF}
|
||||
|
||||
Reference in New Issue
Block a user