Added autoinstall for modules

This commit is contained in:
2024-07-14 21:24:49 +03:00
parent 3f8590b8f3
commit 13900bb3f3
10 changed files with 153 additions and 40 deletions

View File

@@ -6,6 +6,7 @@ using System.Threading.Tasks;
using DiscordBotCore.Interfaces.Logger;
using DiscordBotCore.Interfaces.Modules;
using DiscordBotCore.Loaders;
using DiscordBotCore.Others.Exceptions;
namespace DiscordBotCore.Modules
{
@@ -23,7 +24,10 @@ namespace DiscordBotCore.Modules
public T GetModule<T>() where T : IBaseModule
{
if(!LoadedModules.ContainsKey(typeof(T)))
throw new Exception($"No module loaded with this signature: {nameof(T)}");
throw new ModuleNotFoundException<T>();
if (!LoadedModules[typeof(T)].Any())
throw new ModuleNotFoundException<T>();
IModule<T> module = (IModule<T>)LoadedModules[typeof(T)][0];
return module.Module;