totallymike / ircnode

Extensible IRC bot written with node.js
https://github.com/totallymike/ircnode/wiki
MIT License
4 stars 2 forks source link

Swappable basic mechanisms #15

Closed totallymike closed 11 years ago

totallymike commented 12 years ago

Should be able to leverage the plugin system in order to handle basic bot functionality, such as logging, seen users history, etc. This way users can enable different logging mechanisms based on personal choice, and expand to handle more.

sigv commented 12 years ago

To accomplish this, plugins need to be able to listen to all incoming messages. Currently they can add a listener to the emitter, but it is not a good way as the data is sent to all the functions at the same time and the bot is therefor slowed down.

My idea is that plugins that need to listen to all incoming messages, would call irc.listenRaw(func) which would add the function passed in the func argument to the queue. All functions there would be called synchronously from inside the main PRIVMSG listener. The function would receive an argument (possibly called msg, short for message) which would be similar to the act argument plugins receive inside their handlers, but instead of cmd and params values, would have a words value which would contain an array of words divided by spaces.

Any comments or suggestions are appreciated.

sigv commented 11 years ago

Closing issue as this has been implemented in master.

In current implementation, you can listen to any message from the server by adding a hook with the name of the command you want to listen to (e.g. PRIVMSG, JOIN, QUIT, NOTICE) and the function will be called with one argument - action - which matches the action being returned to regular command listeners with the exception that action.cmd now is set to the command received from server (e.g. PRIVMSG, JOIN, QUIT, NOTICE) and action.params are set to an array containing the raw content of said message split at spaces.

// Plugin example to respond to all messages which read as "Hello".
var irc = global.irc;
exports.name = 'hello';
exports.hooks = {
  'PRIVMSG': function (act) {
    var msg = act.params.join(' ').toLowerCase();
    if (msg === 'hello')
      irc.privmsg(act.source, 'Hello!');
  }
};