Do an action when users go to topics



  • Hello guys. First I need apologize for my bad expression because in this moment I'm learning English and my control of the English language is very poor.

    My problem is the next, I'm developing a plugin that allows users to write special tags in title (For example, "+nsfw" or "+private". This tags grant some features to post. What hook do I need use?

    In this moment I have that, but it doesn't work.

    Plugin.json

    {
      "id": "nodebb-plugin-tagstitle"
    , "name": "Special Tags in Title for NodeBB"
    , "description": "This plugin allows users create new topics with special restrictions with special tags, for example, +hd, +prv, +nsfw..."
    , "url": "https://github.com/rbbau/nodebb-plugin-tags-title"
    , "library": "./library.js"
    ,"hooks": [
    	{ "hook": "filter:category.topics.get", "method": "goPage" },
    ]
    }
    

    Library.js

    Topics = module.parent.require('./topics'),
    User = module.parent.require('./user'),
    
    var TagsTitle = {};
    	
    	TagsTitle.goPage = function(postData) {
    	//Conseguimos el título del post en minúsculas
    	var topicTitle = function() {
    		var topicTitle = postData;
    		var topicTitleLower = topicTitle.toLowerCase();
    		return topicTitleLower;
        };
    	alert(postData);
    	//Analizamos si existe el título o no para aplicar medidas
    	if(topicTitle == null) {  
    	//Don't do anything  
    	console.log('Título sin etiquetas');
        }		
    	else {
    		console.log('Título con etiquetas');
    		if(topicTitle.includes('+hd') == true)
    		{
    			//The topic titles contains +HD
    		}
    		else if(topicTitle.includes('+prv') == true)
    		{
    			//The topic titles contains +prv
    		}
    		else if(topicTitle.includes('+18') == true)
    		{
    			//The topic titles contains +18
    		}
    		else if(topicTitle.includes('+nsfw') == true)
    		{
    			//The topic titles contains +nsfw
    		}		 			
    	}
    	}
    module.exports = TagsTitle;

  • Admin

    Your if statement is wrong. It should be if (topicTitle == null) or if (!topicTitle)



  • Thanks, I have just solved the error.

    But the code doesn't work for now. How can I do execute a function when user go to topic?

    Thanks




Star

Looks like your connection to NodeBB was lost, please wait while we try to reconnect.