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

twitch-irc-lite

v1.0.4

Published

IRC library specifically for Twitch.tv

Downloads

10

Readme

Node Version

Disclaimer: Twitch is a trademark or registered trademark of Twitch Interactive, Inc. in the U.S. and/or other countries. "Twitch-IRC-Lite" is not operated by, sponsored by, or affiliated with Twitch Interactive, Inc. in any way.

I've been developing a Twitch chat bot for a streamer that I mod. The popular IRC package available from npm (not naming any names...), although excellent, I found difficult to work with. It's dependency on node-gyp and iconv presented incompatibility issues with webpack and webpack-dev-server.

There are other options, but I found them to be either incomplete or complete overkill for my application. So, I chose to make my own Twitch.tv dedicated IRC package that I could share with all of you!

Features

Twitch-IRC-Lite is a simple, lightweight Twitch IRC package,

  • compatible with module bundlers like webpack,

  • already minified for browser applications,

  • has no dependencies,

  • and only takes 2 lines of code to get started.

Most useful of all, Twitch-IRC-Lite returns already parsed Object representations of all Twitch server responses!

npm install --save twitch-irc-lite

Basics

// include the npm library
var IRC = require('twitch-irc-lite')

// connect to Twitch
var myChatBot = new IRC('oauth:samplew49fu0sve908gjsample', 'aGreatUserName')

// join a channel
myChatBot.join('anAwesomeChannel')

// get live chat messages to your application
myChatBot.chatEvents.addListener('message', function(channel, from, message){
  /* your code here */
});

// THAT's IT!

Connect to Twitch

var myChatBot = new IRC(oauth, username);
/*
 Example:
 var myChatBot = new IRC('oauth:example23ewuojv309ujfexample', 'myusername');
*/

Note: You can get your oauth key at Twitch Authentication Docs

Join a Channel

myChatBot.join(channel);

Note: Twitch-IRC supports joining multiple channels concurrently

Send a Chat Message

myChatBot.chat(message, channel);

/*
  DEFAULT: channel = null
    if channel is omitted, chat() will default to the last channel joined
*/
myChatBot.chat(message);

List Joined channels

/*
  returns a list of joined channels & outputs them to the console
*/
var myChannels = myChatBot.getChannels()

Leave a Channel

myChatBot.leave(channel);

/*
  DEFAULT: channel = null
    if channel is omitted, leave() will default to the last channel joined
*/
myChatBot.leave();

Get Live Chat Messages

myChatBot.chatEvents.addListener('message', function(channel, from, message){

  /* your code here

      *channel*  String of the current channel
      *from*     String of the sending username
      *message*  String of the chat message received

     your code here */

});

If your IRC instance is in Debug_Mode, you will get a Msg object with a parsed Twitch server response. Check the code comments in /src/msg.js for more information.

myChatBot.chatEvents.addListener('message', function(Msg_Object) {
  /* your code here */
})

Chat Message History

When called outputs a chat history to the console and returns the chat history as an array.

If set to true, Verbose will return & output all Msg objects received from the server.

var myHistory = myChatBot.getChatHistory(verbose)

/*
  DEFAULT: verbose = false
    if verbose is omitted, getChatHistory() will default to only Twitch PRIVMSGs
*/
var myHistory = myChatBot.getChatHistory()

If false or omitted, will return a String array of only chat history (or Twitch PRIVMSGs) like this:

[AGreatChannel] imAUser: this is a sample chat message :)

Purpose & Design

This package aims only to provide IRC communication between Twitch servers and your application following Twitch's Chat and IRC development guidelines. No automatic Twitch commands or similar are implemented here. That's a job for your bot ;)

It should also be said, again, that this IRC package is meant specifically for Twitch.tv using the IRC Protocol (RCF1459) as defined by the Twitch Development Site. Twitch-IRC-Lite is not meant for other IRC applications. You've been warned. :P

File Structure & Implementation

/build is the compiled and minified JavaScript library for general use.

/src is the main development library. It's written in Babel and is not included in npm install.

I spent a lot of time commenting my code well. If you have any questions, please check the code comments in /src before you post an issue <3

Commands

npm run dev

dev command configured in package.json to "hot" compile all /lib directory Babel files to the /build directory when changes are made and saved

npm run build

build command configured in package.json to compile the /lib directory to /build without "hot" compiling

Personal Development Environment 12 May 2017

Version 2.0

Ongoing

  • [ ] Offer more debug logging based on HTTP status codes

If you have any suggestions on how to make this library better, go ahead and open an issue. I'd love to hear from you :)