예제 #1
0
파일: CommandSeeker.cs 프로젝트: binn/Meru
        public CommandEntity GetCommandsFromAttributeAsync()
        {
            CommandEntity commandHierarchyList = new CommandEntity();

            commandHierarchyList.Id = "root";

            Assembly asm = Assembly.GetEntryAssembly();

            var modules = asm.GetTypes()
                          .Where(m => m.GetTypeInfo().GetCustomAttributes <ModuleAttribute>().Any() && !m.IsNested)
                          .ToArray();

            int modulesLoaded    = 0;
            int subModulesLoaded = 0;
            int commandsLoaded   = 0;

            foreach (var m in modules)
            {
                CommandEntity entity = GetChildrenFromModule(m);
                commandHierarchyList.Children.Add(entity);

                modulesLoaded++;

                subModulesLoaded += entity.Children.Count(x => (x as Module) != null);
                commandsLoaded   += entity.GetAllEntitiesOf <Command>().Count;
            }
            return(commandHierarchyList);
        }
예제 #2
0
        public CommandProcessor(CommandProcessorConfiguration config)
        {
            this.config = config;

            if (config.AutoSearchForCommands)
            {
                CommandSeeker s = new CommandSeeker();
                hierarchyRoot  = s.GetCommandsFromAttributeAsync();
                cachedCommands = hierarchyRoot.GetAllEntitiesOf <Command>();
            }

            if (config.MentionAsPrefix)
            {
                if (config.DefaultPrefix != "")
                {
                    prefixes.Add(new Prefix(config.DefaultPrefix)
                    {
                        Configurable = config.DefaultConfigurable
                    });
                }
                prefixes.Add(new MentionPrefix());
            }
            else
            {
                prefixes.Add(new Prefix(config.DefaultPrefix)
                {
                    Configurable = config.DefaultConfigurable
                });
            }
        }
예제 #3
0
        public CommandProcessor(CommandProcessorConfiguration config)
        {
            _prefixes.Add(new Prefix(config.DefaultPrefix));

            if (config.AutoSearchForCommands)
            {
                CommandSeeker s = new CommandSeeker();
                hierarchyRoot  = s.GetCommandsFromAttributeAsync();
                cachedCommands = hierarchyRoot.GetAllEntitiesOf <Command>();
            }
        }