0.4.3 • Published 5 months ago

twitch-chat-emotes v0.4.3

Weekly downloads
35
License
ISC
Repository
github
Last release
5 months ago

twitch-chat-emotes

Connects to twitch chat and emits emotes as they're typed in twitch chat.

Supports all twitch emotes, animated twitch emotes are now operational!

Supported third party emotes:

  • BTTV (channel and global)
  • 7TV (channel, all emotes are static/not animated)
  • FFZ (channel)

This is a library created specifically for projects that run in the browser and require BTTV GIF emote support for Canvas and WebGL instances.

If you're looking for a more standard library to interact with twitch chat, you should look into tmi.js, which this library is based off of.

 

Example implementation

yarn add twitch-chat-emotes
import Chat from "twitch-chat-emotes";

// a default array of twitch channels to join
let channels = ["moonmoon"];

// the following few lines of code will allow you to add ?channels=channel1,channel2,channel3 to the URL in order to override the default array of channels
const query_vars = {};
const query_parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
	query_vars[key] = value;
});
if (query_vars.channels) {
	channels = query_vars.channels.split(",");
}

// create our chat instance
const ChatInstance = new Chat({
	channels,
	duplicateEmoteLimit: 5,
});

// add the word "TEST" as a custom emote
ChatInstance.addCustomEmote("TEST", "https://example.com/image.png");

// add a callback function for when a new message with emotes is sent
ChatInstance.on("emotes", (emotes) => {
	console.log(emotes);
});

 

External server dependency

An external API runs at https://gif-emotes.opl.io/v2/. Emotes are passed through this server in order to offload GIF processing from the client in an attempt to improve performance in an OBS browser source to avoid frame drops. The server source code will be released at a later date so that users of the library can run it themselves if needed.

The API is heavily cached behind CloudFlare, and should withstand an unreasonable amount of traffic.


Documentation

const ChatInstance = new Chat({config...})
PropertyDescription
channelsAn array of twitch chat channels to connect to
maximumEmoteLimitThe limit of emotes per message
maximumEmoteLimit_plebmaximumEmoteLimit, but for users who are not subscribed, mods, or VIPs
duplicateEmoteLimitThe maximum amount of times the same emote can be repeated in the same message
duplicateEmoteLimit_plebSimilar to maximumEmoteLimit_pleb
gifAPIDefine the location of your own self-hosted emote API

 

Events

ChatInstance.on(event, callback)

...

ChatInstance.on("Emotes", (emotes, data) => {
	console.log(data.user.username + ': ' + data.message, emotes);
})
EventDescription
emotesReturns an array of emote objects every time a message is sent in twitch chat that contains matched emotes, an optional second argument contains message and user data

Objects

Emote | Property | Description | | - | - | | url | The "unique ID" of the emote, either it's name or a URL | | name | The name of the emote (Example: Kappa, FeelsGoodMan, KomodoHype) | | canvas | The emotes canvas, there is only one unique canvas element for each emote (adding it multiple times in the DOM will just move it between elements) |

0.4.3

5 months ago

0.4.1

1 year ago

0.4.0

1 year ago

0.4.2

1 year ago

0.3.0

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.3

2 years ago

0.2.6

2 years ago

0.2.3

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.1.33

3 years ago

0.1.34

3 years ago

0.1.31

3 years ago

0.1.32

3 years ago

0.1.30

4 years ago

0.1.29

4 years ago

0.1.26

4 years ago

0.1.27

4 years ago

0.1.28

4 years ago

0.1.25

4 years ago

0.1.20

4 years ago

0.1.21

4 years ago

0.1.22

4 years ago

0.1.23

4 years ago

0.1.19

4 years ago

0.1.17

4 years ago

0.1.18

4 years ago

0.1.16

4 years ago

0.1.14

4 years ago

0.1.15

4 years ago

0.1.13

4 years ago

0.1.10

4 years ago

0.1.11

4 years ago

0.1.12

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago