Skip to content
This repository was archived by the owner on Nov 8, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
e56228d
`null` in fetchTwitchEmotes crashes
mkody Dec 25, 2019
955e480
Fix ident
mkody Dec 25, 2019
e194a56
Support TwitchEmotes's v4 API
mkody Dec 30, 2019
43e9601
Fix tests
mkody Dec 30, 2019
63ef551
Update package.json
ngajhede Feb 13, 2020
a02c7d2
Chanegd to request-promise
ngajhede Feb 13, 2020
5af9fdd
Changed to request-promise
ngajhede Feb 13, 2020
7ef469c
Update EmoteFetcher.js
ngajhede Feb 13, 2020
ebcc3f6
Update EmoteFetcher.js
ngajhede Feb 13, 2020
cba48a7
Upgrade devdeps and fix lint
mkody Feb 13, 2020
0979d05
Build new docs
mkody Feb 13, 2020
f85c904
Update package.json
ngajhede Feb 13, 2020
cdf48ca
Chanegd to request-promise
ngajhede Feb 13, 2020
2a4e5fa
Changed to request-promise
ngajhede Feb 13, 2020
b250968
Update EmoteFetcher.js
ngajhede Feb 13, 2020
707cae1
Update EmoteFetcher.js
ngajhede Feb 13, 2020
3abedba
Merge branch 'ngajhede'
mkody Feb 13, 2020
52364eb
Missing request dep
mkody Feb 13, 2020
1c0f534
update typings
mkody Mar 11, 2020
a6e8579
Link to my repo
mkody Mar 11, 2020
5da9233
Publish
mkody Aug 26, 2020
1de9855
Oops, left a typo in the README
mkody Aug 26, 2020
fc0f678
Bump lodash from 4.17.15 to 4.17.20
dependabot[bot] Sep 3, 2020
bbe6548
fix(typings): module name
ssut Oct 15, 2020
98545a2
Should support BTTV v3 API; Support ID for FFZ
mkody Jan 25, 2021
f858896
Use Github Actions instead of travis; Edit README
mkody Jan 25, 2021
f78c2ff
Bump version; Upgrade Deps; Gen docs
mkody Jan 25, 2021
68ab613
Add important note in README
mkody Jan 25, 2021
760e788
I copy/pasted that line a bit too fast
mkody Jan 25, 2021
c6c69e3
Fix require to use in README/docs
mkody Jan 25, 2021
4d4905a
Update package-lock.json
mkody Jan 25, 2021
7efbc87
Remove package-lock since we're working with yarn
mkody May 6, 2021
1579a0d
Replace request (Close #9); Fallback for Global
mkody May 6, 2021
1a21adc
Update docs and bump version
mkody May 6, 2021
3e4c30b
Add dependabot
mkody May 6, 2021
84efca0
Fix missing input?
mkody May 6, 2021
3f09375
Bump eslint from 7.18.0 to 7.25.0 (#10)
dependabot[bot] May 6, 2021
5a2d47c
Bump eslint from 7.25.0 to 7.26.0 (#11)
dependabot[bot] May 10, 2021
b9d3857
Remove normal dependabot or it will be too noisy
mkody May 10, 2021
c09021e
fix: twitch emote fetching (#12)
Killusions May 25, 2021
5786b71
Change fallback request to `.body` too
mkody May 25, 2021
c51a21c
Bump version; Upgrade deps; Regen docs
mkody May 25, 2021
f500b03
feat: use twitch api
Killusions Oct 19, 2021
96e0102
Merge branch 'fork' into feat/use-twitch-api
mkody Oct 19, 2021
6188754
Update tests; Regen docs
mkody Oct 19, 2021
7b29783
Regen HTML docs
mkody Oct 19, 2021
750293d
Minor update to tests; Load secrets to GH Actions
mkody Oct 19, 2021
270da78
Always test fetchTwitchEmotes without API keys
mkody Oct 19, 2021
b3900e6
Fix typings; Update readme and contributors
mkody Oct 23, 2021
082a986
Upgrade deps; Split BTTV and FFZ tests
mkody Jan 31, 2022
564b760
Bump got from 11.8.3 to 11.8.5 (#16)
dependabot[bot] Jul 1, 2022
f4851f1
Use new Twitch CDN template
mkody Jul 20, 2022
8fd2f61
Fix Twitch test
mkody Jul 20, 2022
df28841
Upgrade deps
mkody Jul 20, 2022
8cfb330
Bump to 2.5.0
mkody Jul 20, 2022
68774e0
FFZ is now ID-only; Add 7TV support
mkody Jul 21, 2022
6fea24e
Fix typo in typings
mkody Aug 21, 2022
cf661cc
Fix class name: SevenTV => SevenTVEmote
mkody Dec 15, 2022
9ebaf8a
Add support for 7tv with the v3 API
mkody Dec 15, 2022
0d4200c
Add more examples
mkody Dec 15, 2022
d811841
Bump to 2.6.0
mkody Dec 15, 2022
a64333f
Update docs with correct version
mkody Dec 15, 2022
fbffb50
Create codeql.yml
mkody Dec 20, 2022
d021e1a
Create eslint.yml
mkody Dec 20, 2022
a8f5bb5
CodeQL: Ignore test and docs paths
mkody Dec 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 6
"ecmaVersion": 2018
},
"env": {
"es6": true,
Expand Down Expand Up @@ -83,7 +83,6 @@
"array-bracket-spacing": "error",
"block-spacing": "error",
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
"capitalized-comments": ["error", "always", { "ignoreConsecutiveComments": true }],
"comma-dangle": ["error", "never"],
"comma-spacing": "error",
"comma-style": "error",
Expand Down
5 changes: 5 additions & 0 deletions .github/codeql/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: "CodeQL config"

paths-ignore:
- docs
- test
50 changes: 50 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: "CodeQL"

on:
push:
branches: [ "fork" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "fork" ]
schedule:
- cron: '23 11 * * 0'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
config-file: ./.github/codeql/codeql-config.yml
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
51 changes: 51 additions & 0 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# ESLint is a tool for identifying and reporting on patterns
# found in ECMAScript/JavaScript code.
# More details at https://github.com/eslint/eslint
# and https://eslint.org

name: ESLint

on:
push:
branches: [ "fork" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "fork" ]
schedule:
- cron: '26 14 * * 6'

jobs:
eslint:
name: Run eslint scanning
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install ESLint
run: |
npm install eslint@8.29.0
npm install @microsoft/eslint-formatter-sarif@3.0.0

- name: Run ESLint
run: npx eslint ./src ./test
--config .eslintrc.json
--ext .js,.jsx,.ts,.tsx
--format @microsoft/eslint-formatter-sarif
--output-file eslint-results.sarif
continue-on-error: true

- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v2
if: ${{ !env.ACT }}
with:
sarif_file: eslint-results.sarif
wait-for-processing: true
17 changes: 17 additions & 0 deletions .github/workflows/yarn-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Yarn Test

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- run: yarn
- run: yarn test
env:
TWITCH_ID: ${{ secrets.TWITCH_ID }}
TWITCH_SECRET: ${{ secrets.TWITCH_SECRET }}
5 changes: 5 additions & 0 deletions .jsdoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@
"plugins": ["plugins/markdown"],
"markdown": {
"hardwrap": true
},
"docdash": {
"scopeInOutputPath": false,
"nameInOutputPath": false,
"versionInOutputPath": false
}
}
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2017 1Computer1
Copyright (c) 2019 André "Kody" Fernandes

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
123 changes: 108 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,130 @@
# twitch-emoticons

Get a Twitch channel's Twitch emotes, BTTV emotes, and FFZ emotes!
Gets Twitch, BTTV, FFZ and 7TV emotes as well as parsing text to emotes!

### Example
### Migrating from upstream
You must now use a Twitch user ID instead of the username to fetch user's emotes.
You can use [this page to quickly grab it](https://s.kdy.ch/twitchid/).

To fetch Twitch emotes you need to get a client and secret from Twitch [here](https://dev.twitch.tv/console/apps/create), it's free.
If you are only using BetterTTV, FrankerFaceZ and 7TV you don't need to provide Twitch app keys as they are independent from the Twitch API.

### Install
```sh
npm install @mkody/twitch-emoticons
# or
yarn add @mkody/twitch-emoticons
```

### Examples

#### Basic Twitch emote parsing

```js
const { EmoteFetcher, EmoteParser } = require('twitch-emoticons');
// With ESM import
import TwitchEmoticons from '@mkody/twitch-emoticons';
const { EmoteFetcher, EmoteParser } = TwitchEmoticons;
// ... or require()
const { EmoteFetcher, EmoteParser } = require('@mkody/twitch-emoticons');

const fetcher = new EmoteFetcher();
// Your Twitch app keys
const clientId = '<your client id>';
const clientSecret = '<your client secret>';

const fetcher = new EmoteFetcher(clientId, clientSecret);
const parser = new EmoteParser(fetcher, {
type: 'markdown',
match: /:(.+?):/g
});

fetcher.fetchTwitchEmotes().then(() => {
fetcher.fetchTwitchEmotes(null).then(() => {
const kappa = fetcher.emotes.get('Kappa').toLink();
console.log(kappa);
// https://static-cdn.jtvnw.net/emoticons/v1/25/1.0
// https://static-cdn.jtvnw.net/emoticons/v2/25/default/dark/1.0

const text = 'Hello :PogChamp:!';
const text = 'Hello :CoolCat:!';
const parsed = parser.parse(text);
console.log(parsed);
// Hello ![PogChamp](https://static-cdn.jtvnw.net/emoticons/v1/88/1.0 "PogChamp")!
// Hello ![CoolCat](https://static-cdn.jtvnw.net/emoticons/v2/58127/default/dark/1.0 "CoolCat")!
});
```

#### All providers, global + channel, custom template and match pattern

```js
const { EmoteFetcher, EmoteParser } = require('@mkody/twitch-emoticons');

// Your channel ID
const channelId = 44317909;

// Your Twitch app keys
const clientId = '<your client id>';
const clientSecret = '<your client secret>';

const fetcher = new EmoteFetcher(clientId, clientSecret);
const parser = new EmoteParser(fetcher, {
template: '<img class="emote" alt="{name}" src="{link}">', // Custom HTML format
match: /(\w+)+?/g // Match without :colons:
});

Promise.all([
// Twitch global
fetcher.fetchTwitchEmotes(),
// Twitch channel
fetcher.fetchTwitchEmotes(channelId),
// BTTV global
fetcher.fetchBTTVEmotes(),
// BTTV channel
fetcher.fetchBTTVEmotes(channelId),
// 7TV global
fetcher.fetchSevenTVEmotes(),
// 7TV channel
fetcher.fetchSevenTVEmotes(channelId),
// FFZ channel
fetcher.fetchFFZEmotes(channelId)
]).then(() => {
const globalEmotes = parser.parse('EZ Clap way too easy LUL now for the last bost monkaS');
console.log(globalEmotes);
// <img class="emote" alt="EZ" src="https://cdn.7tv.app/emote/6320bf2ad461b9ebf9413812/1x.webp"> <img class="emote" alt="Clap" src="https://cdn.7tv.app/emote/636b877aada75990352334c7/1x.webp"> way too easy <img class="emote" alt="LUL" src="https://static-cdn.jtvnw.net/emoticons/v2/425618/default/dark/1.0"> now for the last bost <img class="emote" alt="monkaS" src="https://cdn.betterttv.net/emote/56e9f494fff3cc5c35e5287e/1x">

const channelEmotes = parser.parse('KEKW that was 3Head TeriPoint');
console.log(channelEmotes);
// <img class="emote" alt="KEKW" src="https://cdn.betterttv.net/emote/5e9c6c187e090362f8b0b9e8/1x"> that was <img class="emote" alt="3Head" src="https://cdn.frankerfacez.com/emote/274406/1"> <img class="emote" alt="TeriPoint" src="https://cdn.7tv.app/emote/61dc299b600369a98b38ebef/1x.webp">
}).catch(err => {
console.error('Error loading emotes...');
console.error(err);
});
```

#### 7TV formats

7TV v3 delivers emotes in either WEBP or AVIF.
By default we'll return WEBP emotes but you can override this.

```js
const { EmoteFetcher } = require('@mkody/twitch-emoticons');
const fetcher = new EmoteFetcher();

// Fetch global emotes in AVIF (channel id has to be `null` for global)
fetcher.fetchSevenTVEmotes(null, 'avif');

// Fetch 0kody's emotes with the package's default format (WEBP)
fetcher.fetchSevenTVEmotes(44317909);

// ... which is currently the same as
fetcher.fetchSevenTVEmotes(44317909, 'webp');

// Fetch Anatole's emotes in AVIF
fetcher.fetchSevenTVEmotes(24377667, 'avif');
```

### Links

- [Github](https://github.com/1Computer1/twitch-emoticons)
- [Documentation](https://1computer1.github.io/twitch-emoticons/)
- [Changelog](https://github.com/1Computer1/twitch-emoticons/releases)
- [Github](https://github.com/mkody/twitch-emoticons)
- [Documentation](https://mkody.github.io/twitch-emoticons/)
- [Changelog](https://github.com/mkody/twitch-emoticons/releases)

This library uses the following:
- [Twitch Emotes API](https://twitchemotes.com/apidocs)
- [BetterTTV API](https://api.betterttv.net/)
- [FrankerFaceZ API](http://www.frankerfacez.com/developers)
This library uses the following:
- [BetterTTV API](https://betterttv.com/)
- [FrankerFaceZ API](https://www.frankerfacez.com/developers)
- [7TV API](https://7tv.app/)
Loading