🛠️ A better IRC framework for node.js. For bots and full clients.
  • JavaScript 100%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2024-10-08 15:39:13 +02:00
.github/workflows Update dependencies and workflows (#380) 2024-08-29 16:22:15 +01:00
docs whowas: return all responses from the server (#372) 2024-08-29 15:59:45 +01:00
examples Use caseCompare where possible 2020-08-26 12:00:15 +03:00
src add option to pass ca_certificates 2024-10-08 15:39:13 +02:00
test Add support for CLIENTTAGDENY (#368) 2024-08-21 15:35:50 +01:00
.eslintrc.js v4.13.0 (#351) 2023-01-26 13:46:27 +00:00
.gitattributes Switch to eslint 2020-01-02 16:40:21 +02:00
.gitignore Upgrade packages 2020-05-11 22:23:37 +03:00
.npmignore Ignore some folders from npm 2020-04-01 10:25:12 +03:00
babel.config.js rework entrypoints/builds 2019-05-03 16:02:29 -05:00
LICENSE.txt Create LICENSE.txt 2015-12-28 02:07:26 +00:00
package.json v4.14.0 (#387) 2024-09-23 14:05:04 +01:00
README.md Fix example in the README 2022-02-12 20:11:35 +01:00
webpack.config.js Update dependencies and workflows (#380) 2024-08-29 16:22:15 +01:00
yarn.lock Bump path-to-regexp from 6.2.2 to 6.3.0 (#384) 2024-09-23 13:50:02 +01:00

irc-framework

A better IRC framework for node.js. For bots and full clients. Read the documentation.

Aims

  • Lightweight
  • Performant
  • Very easy to get going out of the box
  • Grows as needed for larger applications
  • IRCv3 compliant
  • Multiple (+ auto detected) encoding support
  • Complete test suite

A simple and low-boilerplate framework to build IRC bots.

var bot = new IRC.Client();
bot.connect({
	host: 'irc.freenode.net',
	port: 6667,
	nick: 'prawnsbot'
});

bot.on('message', function(event) {
  	if (event.message.indexOf('hello') === 0) {
  		  event.reply('Hi!');
  	}
  	
  	if (event.message.match(/^!join /)) {
  		var to_join = event.message.split(' ')[1];
  		event.reply('Joining ' + to_join + '..');
  		bot.join(to_join);
  	}
});


// Or a quicker to match messages...
bot.matchMessage(/^hi/, function(event) {
	event.reply('hello there!');
});

Channel/buffer objects. Great for building clients

var bot = new IRC.Client();
bot.connect({
	host: 'irc.freenode.net',
	port: 6667,
	nick: 'prawnsbot'
});

var buffers = [];
bot.on('registered', function() {
	var channel = bot.channel('#prawnsalad');
	buffers.push(channel);
	
	channel.join();
	channel.say('Hi!');
	
	channel.updateUsers(function() {
		console.log(channel.users);
	});

	// Or you could even stream the channel messages elsewhere
	var stream = channel.stream();
	stream.pipe(process.stdout);
});

Middleware

function ExampleMiddleware() {
	return function(client, raw_events, parsed_events) {
		parsed_events.use(theMiddleware);
	}


	function theMiddleware(command, event, client, next) {
		if (command === 'registered') {
			if (client.options.nickserv) {
				var options = client.options.nickserv;
				client.say('nickserv', 'identify ' + options.account + ' ' + options.password);
			}
		}

		if (command === 'message' && client.caseCompare(event.event.nick, 'nickserv')) {
			// Handle success/retries/failures
		}

		next();
	}
}


var irc_bot = new IRC.Client();
irc_bot.use(ExampleMiddleware());