Nationwide Polamorous Matrimony
    Have ideas to improve npm?Join in the discussion! »

    twitch-irc-lite

    1.0.4 • Public • Published

    Node Version

    Twitch-IRC-Lite

    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.

    Motivation

    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!

    Install

    npm install --save twitch-irc-lite

    Getting Started

    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!

    Usage

    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 :)

    Development Notes

    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

    Future Development

    Version 2.0

    Ongoing

    • Offer more debug logging based on HTTP status codes

    Suggestions?

    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 :)

    Keywords

    none

    Install

    npm i twitch-irc-lite

    DownloadsWeekly Downloads

    3

    Version

    1.0.4

    License

    GPL-3.0

    Last publish

    Collaborators

    • avatar