gf3 / IRC-js

The best IRC library for node.js
http://irc-js.com
The Unlicense
179 stars 33 forks source link

Decide on API for 2.0 #60

Closed ghost closed 10 years ago

ghost commented 12 years ago

After trying various things with confusing names, I have removed everything except one method, which delegates to a couple of internal ones:

// Simplest regexp match
bot.match(/\bice\s+cream\b/i, function(msg) { msg.reply("Yum, %s. I love ice cream!", msg.from.nick); });

// Regexp match with groups (example from ircjsbot Spotify plugin)
bot.match(/\bspotify(?:\s+(album|artist|track))?\s+((?:\D+)|(?:.+))(?:\s+([1-9]\d*))?$/i,
  function(msg, type, query, index) {
    // Search for <type>s matching <query>, returning the item at <index>.
  });

// Match any message of a certain type
bot.match(irc.COMMAND.PRIVMSG, function(msg) {
  console.log("Got a PRIVMSG:", msg.toString());
});

// Match message for which predicate returns `true`
function isFriday() {
  return new Date().getDay() === 5;
}

bot.match(isFriday, function(msg) {
  msg.reply("Friday!! Friday!!");
});

// Or a combination
bot.match(/\bfriday\b/i, isFriday, function(msg) {
  msg.reply("TGIF");
});

I'm unsure about the name, and the corresponding method that removes handlers currently named ignore. Other than that it’s pretty nice.

What do you think @gf3, fix the naming and settle on this?

gf3 commented 12 years ago

This has been working great so far for us, I think we should stick with it.