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