Skip to content

Instantly share code, notes, and snippets.

@gf3
Created Jul 27, 2009
Embed
What would you like to do?
Proposed syntax for IRC bot
// Proposed syntax for IRC bot
// ---------------------------
jerk(function() {
// `watch_for` takes a regular expression, and matches it against everything that is said
watch_for(/^api (\w+)\.(\w+)/, function(message) {
// Message object has properties: match_data, channel, user, text
// `say` replies in the channel that the message was heard in
say(message.user.nick + ": Something " + message.match_data[1]);
});
// `watch_for` can also match strings
watch_for("help", function(message) {
say("Help topics: ...");
});
}).connect(options);
// Options
var options = {
// Required
server: "127.0.0.1",
// Optional
port: 6667,
encoding: "ascii",
nick: "js-irc",
channels: ["#runlevel6"],
user: {
username: "js-irc",
hostname: "thetubes",
servername: "tube1",
realname: "Javascript Bot"
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment