Don't create topic based on post text?



  • I am working on making a profanity filter type plugin that disallows certain words from being posted.

    I'm hooking on to these hooks and returning an error if profanity exists in the data.

            { "hook": "filter:topic.create", "method": "profanityHook" },
            { "hook": "filter:topic.reply", "method": "profanityHook" },
            { "hook": "filter:post.edit", "method": "profanityHook" },
            { "hook": "filter:post.save", "method": "profanityHook" }
    

    and here's how my hook works:

    profanityHook:function(data,next){
                if (!data){
                    return next(null,data);//no data no profanity lol
                }
                //check content
                if (data.content){
                    if(hasProfanity(data.content)){
                        return next(new Error('Profanity found'),data);
                    };
                }
                //check topic title
                if (data.topic && data.topic.title){
                    if( hasProfanity(data.topic.title) ){
                         return next(new Error('Profanity found'),data);
                    }
                }
                //all ok I guess
                return next(null,data);
            }
    

    So here's the problem: if there's profanity in the post, but not in the topic title, the topic still gets created with 0 posts in it.

    So, how can I stop the topic from being created with 0 posts?


  • GNU/Linux

    Observing this code I'd say you should use the filter:topic.post and check its title and content payload.

    Using the filter:topic.create would be more or less obsolete then since it might only catch topics created by bad plugins that don't respect this line.



  • Wow awesome, that seems to have done the trick :+1:

    Thank you so much for the help.


Log in to reply
 

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