1.0.0-beta.6 • Published 7 years ago

irclib v1.0.0-beta.6

Weekly downloads
7
License
GPL-3.0
Repository
github
Last release
7 years ago

irclib

Library for making IRC clients

Table of Contents

  1. Installation
  2. Usage
    1. Options
    2. Events
    3. Components
  3. API Reference

Installation

$ npm install --save irclib

Usage

const { Client } = require('irclib')
const options = {
    //... See doc below
}

const client = new Client(options)
client.start()

Options

OptionDescriptionDefault valueMandatory
hostIP Address or hostnameN/AYes
portPort6667No
sslSSL engineNoNo
channelsList of default join channels[]No
partMessageMessage when the lib parts from a channel[IrcLib] Good Bye.No
quitMessageMessage when the lib disconnects from the server[IrcLib] Good Bye.No
passwordPassword of the server''No
encodingText encodingutf8No
versionResponse text of the CTCP versionVersion info in the package.json of your applicationNo
userUser informationN/AYes
nicknameInitial nicknameN/AYes
realnameReal nameN/AYes
alternativeAlternative nicknameNickname + _No
usernameUser nameN/AYes
nickservNickServ password if the nickname is registeredN/ANo
extraCustom application data for this client (must be an object){}No
debugLevelDebug Level code (error, warning, info, debug)warningNo

Events

EventDescription
pubmsgEvent received when a message is sent to a channel
privmsgEvent received when a message is sent to the user
pubnoticeEvent received when a notice is sent to a channel
privnoticeEvent received when a notice is sent to the user
joinEvent received when an user joins a channel
partEvent received when another user parts from a channel
quitEvent receievd when another user quits
errorEvent received when the IRC server emits an error
nickEvent received when an user changes his nickname
kickEvent received when an user is kicked from a channel
pingEvent received on a PING request
inviteEvent received when another user invites the user on a channel
modeEvent received when a mode is changed

Every event callback takes 4 arguments :

  • sender: User information of the sender
  • middle: Middle information of the message
  • params: Array with other middle information
  • trailing: Trailing text of the message

There is a complete list of other events on this page. Every event can be bound by its numeric code or by a short version of the name. Example : RPL_WELCOME is bound to the welcome event.

Components

You can use components to make your code clear.

pubmsg.js

module.exports = (client) => {
    client.on('pubmsg', (sender, channel, message) => {
        console.log(`Message received from ${sender} on ${channel}: ${message}`)
    })
}

index.js

client.component(require('./pubmsg'))

API Reference

Class Client

on(event, callback)

Registers an event with a callback. Returns the client to allow event chaining.

start()

Starts the client by establishing the connection and listening for incoming data.

privmsg(target, message)

Sends a message to a channel or an user identified by target.

notice(target, message)

Sends a notice to a channel or an user identified by target.

action(target, message)

Sends a mIRC-styled action message (/me) to a channel or a user identified by target.

join(target)

Sends a join message to enter a channel identified by target.

part(target, message)

Sends a part message to leave a channel identified by target before leaving the channel.

quit(message)

Sends a quit message to the server before quitting the network.

mode(channel, modificators, targets = [])

Sends a mode message on a channel with inline modificators, eventually applied to targets.