npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-irc

v1.0.3

Published

irc socket wrapper for node.js

Downloads

12

Readme

simple-irc

An easy-to-use IRC socket wrapper for node.js, written in JavaScript of course!

Installation

npm install simple-irc

Basic Usage

const irc = require("simple-irc");

const bot = new irc({
	server: { address: "irc.snoonet.org", port: 6667 },
	userInfo: { nick: "SimpleIRCBot56622", auth: { type: irc().authType.none } },
	channels: [
		{ name: "#botwars" }
	]
});

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!" );
}

Function Reference

bot.joinChannel({ channel[, key] })

  • channel {string}
  • key {string} [optional]

Joins channel using the optional secret key

bot.joinChannel({ channel: "#test", key: "secret" });

bot.leaveChannel({ channel[, message] })

  • channel {string}
  • message {string} [optional]

Leaves channel with an optional message

bot.leaveChannel({ channel: "#test", message: "bye" });

bot.sendMessage({ message, to })

  • 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" });

bot.sendNotice({ message, to })

  • 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" });

bot.kickUser({ channel, nick[, message] })

  • 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" });

bot.inviteUser({ channel, nick })

  • channel {string}
  • nick {string}

Invites nick to join channel

bot.inviteUser({ channel: "#channel", nick: "goodguy" });

bot.setTopic({ channel, topic })

  • channel {string}
  • topic {string}

Changes the topic in channel to topic

bot.setTopic({ channel: "#channel", topic: "welcome!" });

Events Reference

event.onChannelJoined( e )

  • e.channel {string}

Emitted when the channel e.channel has been joined

bot.onChannelJoined = function( e ){  };

event.onChannelLeft( e )

  • e.channel {string}

Emitted when the channel e.channel has been parted

bot.onChannelLeft = function( e ){  };

event.onChannelTopicChanged( 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 ){  };

event.onConnect()

Emitted when the socket connection is established, regardless of IRC state

bot.onConnect = function(){ console.log( "Socket connected" ) };

event.onConnected()

Emitted when the connection to IRC has succeeded

bot.onConnected = function(){ console.log( "Connected to IRC" ) };

event.onConnected()

Emitted when the connection to IRC has succeeded

bot.onConnected = function(){ console.log( "Connected to IRC" ) };

event.onData( e )

  • e.data {string}

Emitted when socket has received an IRC packet

bot.onData = function( e ){ console.log( e.data ) };

event.onDisconnect()

Emitted when socket has disconnected

bot.onDisconnect = function( e ){  };

event.onError( e )

  • e.message {string}

Emitted when there has been a fatal error

bot.onError = function( e ){ console.log( e.message ) };

event.onModeChanged( e )

  • 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: "[email protected]" }

bot.onModeChanged = function( e ){  };

event.onNickChanged( e )

  • e.old {string}
  • e.new {string}

Emitted when the user e.old changes nicks to e.new

bot.onNickChanged = function( e ){  };

event.onNotice( 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!" );
};

event.onNumeric( e )

  • 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!" );
};

event.onPrivmsg( e )

  • 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!" );
};

event.onProtocolError( e )

  • 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" );
};

event.onUserJoined( e )

  • 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 );
};

event.onUserKicked( e )

  • 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 );
};

event.onUserLeft( e )

  • 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 );
};

event.onUserQuit( e )

  • 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 );
};