コード例 #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
ファイル: CommandProcessor.cs プロジェクト: miki-archive/Meru
        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>();
            }
        }