public void RegisterAttributeCommands() { Assembly assembly = Assembly.GetEntryAssembly(); var modules = assembly.GetTypes() .Where(m => m.GetCustomAttributes <ModuleAttribute>().Count() > 0) .ToArray(); foreach (var m in modules) { RuntimeModule newModule = new RuntimeModule(); object instance = null; try { instance = Activator.CreateInstance(Type.GetType(m.AssemblyQualifiedName), newModule); } catch { instance = Activator.CreateInstance(Type.GetType(m.AssemblyQualifiedName)); } newModule.EventSystem = this; ModuleAttribute mAttrib = m.GetCustomAttribute <ModuleAttribute>(); newModule.Name = mAttrib.module.Name.ToLower(); newModule.Nsfw = mAttrib.module.Nsfw; newModule.CanBeDisabled = mAttrib.module.CanBeDisabled; var methods = m.GetMethods() .Where(t => t.GetCustomAttributes <CommandAttribute>().Count() > 0) .ToArray(); foreach (var x in methods) { RuntimeCommandEvent newEvent = new RuntimeCommandEvent(); CommandAttribute commandAttribute = x.GetCustomAttribute <CommandAttribute>(); newEvent = commandAttribute.command; newEvent.ProcessCommand = async(context) => await(Task) x.Invoke(instance, new object[] { context }); newEvent.Module = newModule; ICommandEvent foundCommand = newModule.Events.Find(c => c.Name == newEvent.Name); if (foundCommand != null) { if (commandAttribute.on != "") { foundCommand.On(commandAttribute.On, newEvent.ProcessCommand); } else { foundCommand.Default(newEvent.ProcessCommand); } } else { newModule.AddCommand(newEvent); } } newModule.InstallAsync(bot).GetAwaiter().GetResult(); } }
internal RuntimeModule Add(RuntimeModule module) { throw new NotImplementedException(); }