Example #1
0
        public void BuildCommand(MethodInfo Method, ModuleInfo moduleInfo)
        {
            //DEBUG
            Type             magicType   = Method.DeclaringType;
            CommandAttribute CommandAttr = (CommandAttribute)Method.GetCustomAttribute(typeof(CommandAttribute));

            Command.MainAlias = CommandAttr.Name;
            Command.Aliases   = new List <string>();
            AliasAttribute AliasAttr = (AliasAttribute)Method.GetCustomAttribute(typeof(AliasAttribute));

            if (AliasAttr != null)
            {
                foreach (string alias in AliasAttr.Aliases)
                {
                    Command.Aliases.Add(alias.ToLower());
                }
            }

            OnlyRoleAttribute OnlyRolesAttr = (OnlyRoleAttribute)Method.GetCustomAttribute(typeof(OnlyRoleAttribute));

            if (OnlyRolesAttr != null)
            {
                Command.OnlyRoles = new List <string>();
                Command.OnlyRoles.AddRange(OnlyRolesAttr.Roles);
            }

            ExpectRoleAttribute expectRoleAttribute = (ExpectRoleAttribute)Method.GetCustomAttribute(typeof(ExpectRoleAttribute));

            if (expectRoleAttribute != null)
            {
                Command.ExpectRoles = new List <string>();
                Command.ExpectRoles.AddRange(expectRoleAttribute.Roles);
            }

            Command.Method     = Method;
            Command.moduleInfo = moduleInfo;
            moduleInfo.AddCommand(Command);
            CommandService.RegisterCommand(Command);
            foreach (System.Reflection.ParameterInfo parameterinfo in Method.GetParameters())
            {
                if (parameterinfo.ParameterType != typeof(CommandContext))
                {
                    AddParameter(parameterinfo);
                }
            }
            //CommandAttr.
            //Method.Invoke(magicClassObject, null);
        }