Fixed duplicate actions
This commit is contained in:
@@ -55,7 +55,7 @@ public class Program
|
||||
private static async Task PrepareConsole()
|
||||
{
|
||||
|
||||
AnsiConsole.MarkupLine($"[yellow]Running on version: {Application.CurrentApplication.ApplicationEnvironmentVariables["Version"]}[/]");
|
||||
AnsiConsole.MarkupLine($"[yellow]Running on version: {Assembly.GetExecutingAssembly().GetName().Version}[/]");
|
||||
AnsiConsole.MarkupLine("[yellow]Git SethBot: https://github.com/andreitdr/SethDiscordBot [/]");
|
||||
AnsiConsole.MarkupLine("[yellow]Git Plugins: https://github.com/andreitdr/SethPlugins [/]");
|
||||
|
||||
@@ -80,7 +80,6 @@ public class Program
|
||||
private static async Task LoadComponents(string[] args)
|
||||
{
|
||||
await Application.CreateApplication();
|
||||
Application.CurrentApplication.ApplicationEnvironmentVariables["Version"] = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
|
||||
AppUpdater updater = new();
|
||||
var update = await updater.CheckForUpdates();
|
||||
|
||||
@@ -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!;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user