Fixed duplicate actions

This commit is contained in:
2024-06-14 17:09:02 +03:00
parent e5e156f371
commit 1881102fb7
4 changed files with 23 additions and 5 deletions
+4 -2
View File
@@ -6,14 +6,16 @@ using DiscordBotCore.Plugin;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
namespace DiscordBotCore
{
public class Application
/// <summary>
/// The main Application and its components
/// </summary>
public sealed class Application
{
public static Application CurrentApplication { get; private set; } = null!;
+12
View File
@@ -38,6 +38,18 @@ public class PluginLoader
public async Task LoadPlugins()
{
if (_Client == null)
{
Application.CurrentApplication.Logger.Log("Discord client is null", this, LogType.ERROR);
return;
}
Commands.Clear();
Events.Clear();
SlashCommands.Clear();
Actions.Clear();
Application.CurrentApplication.Logger.Log("Loading plugins...", this);
var loader = new Loader();
@@ -13,12 +13,17 @@ public class InternalActionManager
public async Task Initialize()
{
Actions.Clear();
PluginLoader.Actions.ForEach(action =>
{
if (action.RunType == InternalActionRunType.ON_CALL || action.RunType == InternalActionRunType.BOTH)
{
if (this.Actions.ContainsKey(action.ActionName))
return; // ingore duplicates
{
// This should never happen. If it does, log it and return
Application.CurrentApplication.Logger.Log($"Action {action.ActionName} already exists", this, LogType.ERROR);
return;
}
this.Actions.Add(action.ActionName, action);
}