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

tw-irc

v6.1.3

Published

TypeScript library for working with Twitch IRC

Downloads

18

Readme

tw-irc

NPM version Dependencies Size Version

Overview

Here is a library that handles connection to Twitch IRC. It allows you to join or leave channels, detect and send new messages and other.

Compatible for both node and browser.

Table of contents

Install

npm install --save tw-irc
yarn add tw-irc

Usage

To start working with Twitch IRC, we have to create a client. You can specify if connection is secure, pass channels which client will automatically join on connection established, or pass auth data which is required to send messages from someones face.

Basic

import Client, {ECommand} from 'tw-irc';

const {Message} = ECommand;

// Create IRC client
const client = new Client();

// Bind events before connect. Just watch for incoming messages
client.on(Message, ({message, displayName}) => {
  console.log(`User ${displayName} said: "${message}"`);
});

// When socket connection is successfully opened, join channel
client.onConnected(() => {
  client.channels.join('rxnexus');
});

// Connect client to IRC
client.connect();

Authenticated client

import Client from 'tw-irc';

// Create authenticated IRC client
const client = new Client({
  channels: ['rxnexus'],
  secure: true, // secure connection recommended
  auth: {
    login: 'twitchfan', // your Twitch login
    password: 'oauth:...', // oauth token. Get it here: https://twitchapps.com/tmi/
  },
});

client.onConnected(() => {
  // Say hi!
  client.channels.say('Hello @rxnexus!', 'rxnexus');
});

client.connect();

Using channel commands

tw-irc supports all of the channel modes and commands.

import Client from 'tw-irc';

const client = new Client();

client.onConnected(() => {
  client.channels.join('rxnexus');

  // Ban someone
  client.channels.ban('troll123', 'rxnexus');

  // Set emote-only mode
  client.channels.emoteOnly.enable('rxnexus');
});

client.connect();

Forking channels

For easier usage you can create channels controllers from client.

import Client from 'tw-irc';

const client = new Client();

client.onConnected(() => {
  // Create channel controller
  const channel = client.fork('rxnexus');
  
  // Join channel
  channel.join();

  // Say hi
  channel.say('Hello!');

  // Set emote only mode
  channel.emoteOnly.enable();

  // Ban some troll in channel
  channel.ban('troll123');
});

client.connect();

Getting full control

If you want full control over the messages coming from IRC, you can use this trick:

import Client from 'tw-irc';
import {prepareIRCMessage, parseIRCMessage} from 'tw-irc/utils';

const client = new Client();

client.onMessage(event => {
  // Convert raw socket message to array of messages. We need this action 
  // because commands can be concatenated in one message and doing this, 
  // we just detect them. 
  const messages = prepareIRCMessage(event.data);

  // Parse each of the messages  
  const parsedMessages = messages.map(parseIRCMessage);

  parsedMessages.forEach(message => {
    // You can react however you want after all of messages are parsed. 
  });
});

client.connect();

Example

There are 2 examples for node and browser.

Running node version:

  1. Clone repo;
  2. Type yarn dev-node or npm run dev-node;

Running browser version:

  1. Clone repo;
  2. Type yarn dev or npm run dev;
  3. Open browser and go to http://localhost:9000;
  4. Open console;

Updates history

You can find updates history here.

License

MIT