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-chat.js

v2.0.2

Published

A simple twitch API wrapper

Downloads

14

Readme

Twitch-chat.js

A simple Twitch API wrapper

Contents

Installing

npm i twitch-chat.js --save
  • Node version "16.18.0" or newer is required

Getting Starting

const { Client } = require('twitch-chat.js');
const client = new Client({
	client_name: 'YOUR_BOT_NAME',
	client_id: 'CLIENT_ID',
	channels: ['foo']
})

.on('ready', () => {
	console.log(`Hello ${client.user.login_name}`)
})

.on('message', message => {
	if(message.channel.type !== 'whisper') return;
	if(message.content === '!ping') return message.channel.send(`Websocket: ${client.ping}ms`)
})

client.login('BOT_TOKEN')

Creating a Command and Event Handlers

const { Client, Collection } = require('twitch-chat.js');
const { Command, Event } = require('@twitchchatjs/handlers');

const client = new Client({
	client_name: 'YOUR_BOT_NAME',
	client_id: 'CLIENT_ID',
	channels: ['foo']
})

client.commands = new Collection()
client.aliases = new Collection()

/* 
Handlers Examples
'./path/to/folder/'
Example:
*/

let commands = new Command(client, './test/commands/')
let event = new Event(client, './test/events/')
event.load()
commands.load()

client.login('BOT_TOKEN')

Note: You need to create a folder for your commands and events

| Option (Handler) | Argument | Description | Default | | ------------------- | ------------ | ------------------------ | ----------- | | subFolder | Boolean | Enable/Disable subfolder | false |

First Event

module.exports = class Message {
	run(message) {
		if(message.channel.type == 'whisper') return;
		if(!message.content.startsWith('!')) return;
		const args = message.content
		.trim()
		.slice(1)
		.split(/ +/g);
	const command = args.shift().toLowerCase();    

	let commands = global.client.commands.get(command) || global.client.aliases.get(command)
	let ctx = {
		client: global.client,
		message: message,
		args: args
	}
	if(!commands) return;
	commands.run(ctx)
	}
}

First Command

module.exports = class PingCommand {
	constructor() {
		this.name = 'ping',
		this.aliases = ['pong'],
		this.run = this.run
	}

	run(ctx) {
		return ctx.message.channel.send(`Pong! WebSocket ping: ${ctx.client.ping}ms`)
	}
}

Advenced

You can create a ".env" file for set CLIENT_TOKEN & CLIENT_ID

Creating an env file

CLIENT_TOKEN=TOKEN_HERE
CLIENT_ID=CLIENT_ID_HERE

Example main file

const { Client } = require('twitch-chat.js');

const client = new Client({
	client_name: 'CLIENT_NAME',
	channels: ['foo']
})

client.login()

Releases

Packages

[email protected]

Bug Fixed

  • join() doesn't work correctly and stop the code

Added (Methods)

  • Channel.edit()
  • Channel.deleteMessages()
  • Channel.moderators()
  • Client.user.block()
  • Client.user.unblock()
  • Message.channel.stream.ads()
  • Message.channel.stream.ban()
  • Message.channel.stream.block()
  • Message.channel.stream.thumbnailURL()
  • Message.channel.stream.unban()
  • Message.channel.stream.user.ban()
  • Message.channel.stream.user.unban()
  • Message.delete()

Added (Properties)

  • Client.id
  • Client.token
  • Message.channel.stream.user
  • User.email

Added (Events)

  • punishment
  • unpunishment

Removed (ENV and options)

  • TWITCH_NAME
  • CHANNELS

Change (ENV and options)

  • TWITCH_TOKEN to CLIENT_TOKEN
  • OptionsClient = { name: 'foo'} to OptionsClient = { client_name: 'foo'}

Change (Methods)

  • Message.channel.createClip() to Message.channel.stream.createClip()
  • Message.channel.clip() to Message.channel.stream.clip()
  • Client.join() to Client.user.join()