Issues writing a bot plugin
-
I'm trying to write a bot plugin for NodeBB.
The idea is that you type a command and the bot responds as a reply to the post.
I'm running into a few issues.
- The bot is a user account but this user account is running into rate limits. No more than 1 post per 10 seconds, etc. Can I bypass this somehow? Is there a permission I can set on the user?
- I'm using the
action:post.save
hook and them I'm callingTopics.reply
but when the user posts a reply with a bot command, the page does not refresh with the new message from the bot. Is there a way I can force a refresh?
-
@djensen47 posting limits are setup in ACP. They are under ACP -> Settings -> Post
They are setup specifically to stop flooding. It's not per user though.
-
Where do I find ACP?
-
@djensen47 it's admin control panel. Clock the cogs icon in the header after you login as admin or you can go to http://mydomain.com/admin
-
@pichalite Ah, okay, I just didn't recognize the acronym.
I thought it might've meant access control something.
-
@pichalite said:
They are setup specifically to stop flooding. It's not per user though.
Yeah, the problem is that I need to turn it off for just one user.
Is there a way I can force the reply to go through no matter what?
Also, why isn't there an error callback in the
Topics.reply
function? -
@djensen47 don't think you can turn it off for just one user. I think you will have to modify core to force the reply to bypass the restrictions
-
@djensen47 said:
but when the user posts a reply with a bot command, the page does not refresh with the new message from the bot. Is there a way I can force a refresh?
Ah, the socket call to emit the event is not in
Topics.reply
... you'll need to manually call it:https://github.com/NodeBB/NodeBB/blob/master/src/socket.io/posts.js#L48
Make sure to structure
result
in the format as it is shown several lines above -
From where can I get a handle to the current socket?
-
I have this working with the following …
var result = { posts: [postData], privileges: { 'topics:reply': true }, 'reputation:disabled': parseInt(Meta.config['reputation:disabled'], 10) === 1, 'downvote:disabled': parseInt(Meta.config['downvote:disabled'], 10) === 1 }; Sockets.in('uid_'+uid).emit('event:new_post', result);
So, it appears to refresh the page with the new post but only if I scroll up or down, which is standard behavior?
Next, I'm not seeing alerts when the bot posts a message. I think this is due to the fact that I've switched to using
Posts.create
instead ofTopics.reply
-
@baris said:
Hmm, you could still use
Topics.reply
and after the post is made set thelastposttime
property of the bot user toDate.now() - tenSeconds
so it won't be rate limited.That and using
SocketHelpers
instead ofSocket.in
worked like a charm. The bot response is basically instant. -
https://github.com/Schamper/nodebb-plugin-botler
Working bot, just needs some love and a configuration page and extra handlers/events added.
-
@djensen47 yep I noticed that after reading your OP more carefully. The intention of my bot was a 100% configurable bot that would be able to perform actions based on certain events happening and possibly having filters applied to it. It would be waaaay overkill for your use case.
It works in theory but I lost motivation and no one seemed interested in it at the time. If it was actually finished it could easily perform tasks like what you're writing a separate plugin for.