Ejemplo n.º 1
0
        public static List <SlashModuleInfo> InstantiateSubModules(Type rootModule, SlashModuleInfo rootModuleInfo, SlashCommandService slashCommandService, IServiceProvider services)
        {
            // Instantiate all of the nested modules.
            var commandGroups = new List <SlashModuleInfo>();

            foreach (var commandGroupType in rootModule.GetNestedTypes())
            {
                if (!TryGetCommandGroupAttribute(commandGroupType, out var commandGroup))
                {
                    continue;
                }
                //var commandGroupTypeInfo = commandGroupType.GetTypeInfo();

                var groupInfo = new SlashModuleInfo(slashCommandService, services);
                groupInfo.SetModuleType(commandGroupType);

                //var instance = ReflectionUtils.CreateObject<ISlashCommandModule>(commandGroupTypeInfo, slashCommandService, services);
                //object instance = commandGroupType.GetConstructor(Type.EmptyTypes).Invoke(null);
                //groupInfo.SetCommandModule(instance);

                groupInfo.MakeCommandGroup(commandGroup, rootModuleInfo);
                groupInfo.MakePath();
                groupInfo.isGlobal = IsCommandModuleGlobal(commandGroupType);

                groupInfo.SetSubCommandGroups(InstantiateSubModules(commandGroupType, groupInfo, slashCommandService, services));
                commandGroups.Add(groupInfo);
            }

            return(commandGroups);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create an instance of each user-defined module
        /// </summary>
        public static Dictionary <Type, SlashModuleInfo> InstantiateModules(IReadOnlyList <TypeInfo> types, SlashCommandService slashCommandService, IServiceProvider services)
        {
            var result = new Dictionary <Type, SlashModuleInfo>();

            // Here we get all modules thate are NOT sub command groups and instantiate them.
            foreach (var userModuleType in types)
            {
                //var userModuleTypeInfo = userModuleType.GetTypeInfo();

                var moduleInfo = new SlashModuleInfo(slashCommandService, services);
                moduleInfo.SetModuleType(userModuleType);

                // If they want a constructor with different parameters, this is the place to add them.
                //var instance = ReflectionUtils.CreateObject<ISlashCommandModule>(userModuleTypeInfo, slashCommandService, services);
                //object instance = userModuleType.GetConstructor(Type.EmptyTypes).Invoke(null);
                //moduleInfo.SetCommandModule(instance);
                moduleInfo.isGlobal = IsCommandModuleGlobal(userModuleType);

                moduleInfo.SetSubCommandGroups(InstantiateSubModules(userModuleType, moduleInfo, slashCommandService, services));
                result.Add(userModuleType, moduleInfo);
            }

            return(result);
        }