Fixed Internal Actions to refresh after external actions are loaded
This commit is contained in:
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user