From bc45c0b6a424d99a8ea58123d6f8917a6c7697c0 Mon Sep 17 00:00:00 2001 From: Joe4evr Date: Fri, 14 Oct 2016 18:41:13 +0200 Subject: [PATCH] Exclude abstract types from being loaded as modules. --- src/Discord.Net.Commands/CommandService.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs index a76c7bdc3..59586d923 100644 --- a/src/Discord.Net.Commands/CommandService.cs +++ b/src/Discord.Net.Commands/CommandService.cs @@ -70,13 +70,16 @@ namespace Discord.Commands await _moduleLock.WaitAsync().ConfigureAwait(false); try { - if (_moduleDefs.ContainsKey(typeof(T))) - throw new ArgumentException($"This module has already been added."); - var typeInfo = typeof(T).GetTypeInfo(); if (!_moduleTypeInfo.IsAssignableFrom(typeInfo)) throw new ArgumentException($"Modules must inherit ModuleBase."); + if (typeInfo.IsAbstract) + throw new InvalidOperationException("Modules must not be abstract."); + + if (_moduleDefs.ContainsKey(typeof(T))) + throw new ArgumentException($"This module has already been added."); + return AddModuleInternal(typeInfo, dependencyMap); } finally @@ -98,7 +101,7 @@ namespace Discord.Commands if (_moduleTypeInfo.IsAssignableFrom(typeInfo)) { var dontAutoLoad = typeInfo.GetCustomAttribute(); - if (dontAutoLoad == null) + if (dontAutoLoad == null && !typeInfo.IsAbstract) moduleDefs.Add(AddModuleInternal(typeInfo, dependencyMap)); } }