node-irc-framework
v1.0.1
Published
A small boilerplate wrapping node-irc package in a comfortable easy and fast to start with template
Downloads
2
Maintainers
Readme
Node IRC Framework
How To Use It
- create a new config:
{
"host": "chat.freenode.net",
"port": 6697,
"useSSL": true,
"useSASL": false,
"autoRejoin": false,
"nick": "whiterabbit",
"admins": [
"neo",
"trinity"
],
"blacklist": [
"agentsmith"
],
"channels": [
"#matrix"
],
"nickserv": false,
"nickservPassword": "foobar",
"nickservEmail": "[email protected]",
"useAdmins": false
}
- create a new script:
var framework = require('node-irc-framework'),
path = require('path'),
cfgPath = path.join(__dirname, 'configFile.json'),
// initialize config
config = framework.config(cfgPath),
// initialize irc client
irc = framework.irc(cfgPath, {
// optional irc extensions
}, function() {
// optional scoped operations on NodeIRC.Client
this.on('error', function(err) {
console.log("[IRC]", err);
});
this.on('registered', function() {
console.log('[IRC]', 'connected.');
});
this.on('pm', function(f, m) {
console.log('[IRC]', `new private message from ${f}: ${m}`);
});
});
// add kill listeners to graceful shutdown irc client
process.on('SIGTERM', function() { irc.shutdown('SIGTERM'); });
process.on('SIGINT', function() { irc.shutdown('SIGINT'); });
// now you can connect
irc.connect();
- run it:
$ node ./YourScript.js
How To Customize It
If you plan on working with this Frawork you might want to customize the behavior of the IRC Client in this package. You can do so by extending the client and add events or operate on the client itself.
For this you can write the following code:
// when initializing the client you can append an object and a callback
var framework = require('node-irc-framework'),
tools = framework.tools,
irc = framework.irc(cfgPath, {
// optional irc extensions
knownClients: new tools.UniqueArray(),
greetKnown: function(message) {
this.knownClients.forEach(function(client) {
this.say(client, message);
}, this);
}
}, function() {
// optional scoped operations on NodeIRC.Client
// here you can run ioperations which are scoped on the client itself:
// hook error event of IRC Client
this.on('error', function(err) {
// do something with the error
console.log("[IRC]", err);
});
this.on('message', (from) => {
this.knownClients.add(from);
if (m == '!greet') {
this.greetKnown('hey! I`m just saying hello, because '+from+' ran the command `!greet`');
}
});
});
What Is Shipped With This Module?
This module consists of 3 parts:
irc
- the smart and customizable irc clientconfig
- a preconfigured and defaulting configuration provider including Union-Array lists for special settingstools
- a set of core tools which provide helping functions
Which Are Valid Settings?
A full configuration of this framework consists of the following settings:
host
: ip or domain which IRC Client shall connect toport
: port on which IRC Client shall connect touseSSL
: Wheter to use SSL protocoluseSASL
: Wheter to use SASL AuthenticationautoRejoin
: Wheter to rejoin on channels after being kicked or notnick
: That's the name of your client in the chat ;)admins
: A list of admins who are eliglible for issueing commandsblacklist
: A list of clients who shall be ignoredchannels
: A list of channels IRC Client shall join / rejoinnickserv
: Whether to auto identify with nickserv (using given credentials)nickservPassword
: Password to use forNickserv
authenticationnickservEmail
: Email to use forNickserv
authenticationuseAdmins
: Enable or Disable restricted command access