trying to start a plugin, but missing the understanding of how the parts play together and their data formats
-
You can always put a console.log(data) before the the
filter:post.shouldQueue
hook and see what is being sent to the plugins. In this case it gets the the below data I removed some of the bigger objects.{ uuid: 'b98bdadb-df49-40c6-a0f3-5bc0c03b544d', tid: '4706', content: 'a sample post with a markdown link [spam](https://spamsite.com)', toPid: null, uid: 1, req: { // request object }, timestamp: 1661795452133, fromQueue: false }
As you can see the content is in data.content. So a plugin using this hook would look like the below.
myPlugin.filterShouldQueue = async (hookData) => { if (hookData.data.content.contains('foo')) { hookData.shouldQueue = true; } return hookData; }
-
@baris thanks .. thats what I am trying to do (add the console.log)
my plug in installed, and 'activated'
but doesn't seem to be called.
my plugins.json{ "id": "nodebb-plugin-moderation_on_links", "url": "https://github.com/sdetweil/nodebb-plugin-moderation_on_links", "library": "./library.js", "hooks": [ { "hook": "static:app.load", "method": "init" }, { "hook": "filter:admin.header.build", "method": "addAdminNavigation" }, { "hook":"filter:post.shouldQueue", "method": "postQueue" } ], "staticDirs": { "static": "./static" }, "less": [ "static/style.less" ], "acpScripts": [ "static/lib/admin.js" ], "templates": "static/templates" }
my library.js for the postQueue
``
plugin= {}
plugin.postQueue = function (postData) {
try {
// assume no links, or good links
// let the post pass on thru
console.log("postQueue="+JSON.stringify(postData,null,2))
postData.shouldQueue = false;
{
} catch (error) {
console.error("oops. postQueue error=",error)
}return postData;
};
module.exports = plugin;
...should always override the postQueue in this simple test , but doesn't
i thought I should be able to see this in the logs, when logged on as admin, but don't see it..
dont see output on browser dev console or terminal window
-
-
Libraries come from core nodebb, https://github.com/NodeBB/NodeBB/tree/master/src.
To get the
Posts
object in your plugin you would add this at the top.const Posts = require.main.require('./src/posts');
Then you can use the methods in the Posts object like
parsePost
.Some other ones would be
const Topics = require.main.require('./src/topics'); const Categories = require.main.require('./src/categories'); const Groups = require.main.require('./src/groups'); /// etc...
-
@baris said in trying to start a plugin, but missing the understanding of how the parts play together and their data formats:
const Posts = require.main.require('./src/posts')
thanks.. how could I discover that myself?
nothing talks about the core libs in the creating a plugin section.,.
just trying to be self sufficient..
-
You need to be familiar with the nodebb core code at https://github.com/NodeBB/NodeBB/tree/master/src. The libraries are all in those folders for posts, topics, categories, users, groups etc.
https://docs.nodebb.org/development/plugins/ Has a section that mentions how to load core libraries.