An easy-to-use IRC socket wrapper for node.js, written in JavaScript of course!
npm install simple-irc
const irc = require("simple-irc");
const bot = new irc({
server: { address: "chat.freenode.net" },
userInfo: { nick: "IRCuser123" },
channels: [
{ name: "#test" }
]
});
bot.onChannelJoined = function( e ){
this.sendMessage({ to: e.channel, message: "Hello I am a bot" });
}
bot.onPrivmsg = function( e ){
if( !e.toChannel ) e.reply( "Hello!" );
}
this wrapper supports the following authentication methods:
irc().authType.nickServ
irc().authType.saslPlain
const irc = require("simple-irc");
const bot = new irc({
server: { address: "irc.snoonet.org", port: 6667 },
userInfo: {
nick: "SimpleIRCBot56622",
auth: {
type: irc().authType.nickServ,
user: "MyNickName",
password: "secret"
}
},
channels: [
{ name: "#botwars" }
]
});
const irc = require("simple-irc");
const bot = new irc({
server: { address: "irc.snoonet.org", port: 6667 },
userInfo: {
nick: "SimpleIRCBot56622",
auth: {
type: irc().authType.saslPlain,
user: "MySaslUN",
password: "secret"
}
},
channels: [
{ name: "#botwars" }
]
});
channel
{string}key
{string} [optional]
Joins channel
using the optional secret key
bot.joinChannel({ channel: "#test", key: "secret" });
channel
{string}message
{string} [optional]
Leaves channel
with an optional message
bot.leaveChannel({ channel: "#test", message: "bye" });
message
{string}to
{string}
Sends message
to the user to
to
is the destination of your message, it can be either a channel
or a nick
bot.sendMessage({ message: "hey there", to: "ircuser123" });
message
{string}to
{string}
Sends message
to the user to
to
is the destination of your message, it can be either a channel
or a nick
bot.sendNotice({ message: "hey there", to: "ircuser123" });
channel
{string}nick
{string}message
{string} [optional]
Kicks nick
from channel
with the optional message
bot.kickUser({ channel: "#channel", nick: "badguy", message: "you have been kicked" });
channel
{string}nick
{string}
Invites nick
to join channel
bot.inviteUser({ channel: "#channel", nick: "goodguy" });
channel
{string}topic
{string}
Changes the topic in channel
to topic
bot.setTopic({ channel: "#channel", topic: "welcome!" });
e.channel
{string}
Emitted when the channel e.channel
has been joined
bot.onChannelJoined = function( e ){ };
e.channel
{string}
Emitted when the channel e.channel
has been parted
bot.onChannelLeft = function( e ){ };
e.channel
{string}e.topic
{string}e.user
{userObject}
Emitted when the e.topic
has changed in the channel e.channel
bot.onChannelTopicChanged = function( e ){ };
Emitted when the socket connection is established, regardless of IRC state
bot.onConnect = function(){ console.log( "Socket connected" ) };
Emitted when the connection to IRC has succeeded
bot.onConnected = function(){ console.log( "Connected to IRC" ) };
Emitted when the connection to IRC has succeeded
bot.onConnected = function(){ console.log( "Connected to IRC" ) };
e.data
{string}
Emitted when socket has received an IRC packet
bot.onData = function( e ){ console.log( e.data ) };
Emitted when socket has disconnected
bot.onDisconnect = function( e ){ };
e.message
{string}
Emitted when there has been a fatal error
bot.onError = function( e ){ console.log( e.message ) };
e.for
{string}e.modes
{array}
Emitted when the e.modes
for e.for
has been changed
e.modes
contains an array of changed modes in the form of objects containing mode
, state
and value
.
state is either add
or remove
. value is blank unless applicable.
For example: if [email protected]
was banned in channel #channel
then e.for
would be #channel
and
the array e.modes
would contain an object like { mode: "b", state: "add", value: "bob![email protected]" }
bot.onModeChanged = function( e ){ };
e.old
{string}e.new
{string}
Emitted when the user e.old
changes nicks to e.new
bot.onNickChanged = function( e ){ };
e.from
{string}e.to
{string}e.message
{string}e.toChannel
{boolean}e.reply
{function}
Emitted when the user e.from
sends a notice of e.message
to e.to
, which can be either a nick or channel.
If the notice was to a channel then e.toChannel
will be true.
e.reply
can be used to send an immediate reply of type PRIVMSG to e.to
.
bot.onNotice = function( e ){
if( e.toChannel ) e.reply( e.from + " please don't send channel notices!" );
};
e.number
{integer}e.data
{string}
Emitted when an IRC numerical packet is received.
e.number
is the relevant numerical value and e.data
is the triggering packet
bot.onNumeric = function( e ){
if( e.number == 1 ) console.log( "Got the IRC welcome packet!" );
};
e.from
{string}e.to
{string}e.message
{string}e.toChannel
{boolean}e.reply
{function}
Emitted when the user e.from
sends a privmsg of e.message
to e.to
, which can be either a nick or channel.
If the message was to a channel then e.toChannel
will be true.
e.reply
can be used to send an immediate reply of type PRIVMSG to e.to
.
bot.onPrivmsg = function( e ){
if( !e.toChannel ) e.reply( "I got your PM!" );
};
e.code
{integer}e.message
{string}
Emitted when an IRC numerical error is received.
bot.onProtocolError = function( e ){
if( e.number == 474 ) console.log( "uhoh banned from a channel" );
};
e.user
{string}e.channel
{string}
Emitted when e.user
joins the channel e.channel
bot.onUserJoined = function( e ){
console.log( e.user + " has joined " + e.channel );
};
e.user
{string}e.kicker
{string}e.channel
{string}e.reason
{string}
Emitted when e.user
is kicked from the channel e.channel
by e.kicker
bot.onUserKicked = function( e ){
console.log( e.user + " was kicked from " + e.channel );
};
e.user
{string}e.channel
{string}e.message
{string}
Emitted when e.user
leave the channel e.channel
with the message e.message
bot.onUserLeft = function( e ){
console.log( e.user + " has left " + e.channel );
};
e.user
{string}e.message
{string}
Emitted when e.user
quits IRC with the message e.message
bot.onUserQuit = function( e ){
console.log( e.user + " has quit: " + e.message );
};