node-irc-framework

1.0.1 • Public • Published

Node IRC Framework npm version

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": "neo@matrix.foo",
    "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 (== '!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 client
  • config - a preconfigured and defaulting configuration provider including Union-Array lists for special settings
  • tools - 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 to
  • port: port on which IRC Client shall connect to
  • useSSL: Wheter to use SSL protocol
  • useSASL: Wheter to use SASL Authentication
  • autoRejoin: Wheter to rejoin on channels after being kicked or not
  • nick: That's the name of your client in the chat ;)
  • admins: A list of admins who are eliglible for issueing commands
  • blacklist: A list of clients who shall be ignored
  • channels: A list of channels IRC Client shall join / rejoin
  • nickserv: Whether to auto identify with nickserv (using given credentials)
  • nickservPassword: Password to use for Nickserv authentication
  • nickservEmail: Email to use for Nickserv authentication
  • useAdmins: Enable or Disable restricted command access

Package Sidebar

Install

npm i node-irc-framework

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • bricksoftapps