Fixed Internal Actions to refresh after external actions are loaded

This commit is contained in:
2023-08-15 16:17:32 +03:00
parent ee527bb36f
commit 6315d13d18
6 changed files with 59 additions and 16 deletions

View File

@@ -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)
{

View File

@@ -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)
{

View File

@@ -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; }