diff --git a/.eslintrc.json b/.eslintrc.json index a701be1..939fbfa 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,7 +1,7 @@ { "extends": "eslint:recommended", "parserOptions": { - "ecmaVersion": 6 + "ecmaVersion": 2018 }, "env": { "es6": true, @@ -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", diff --git a/.github/codeql/codeql-config.yml b/.github/codeql/codeql-config.yml new file mode 100644 index 0000000..f7d992d --- /dev/null +++ b/.github/codeql/codeql-config.yml @@ -0,0 +1,5 @@ +name: "CodeQL config" + +paths-ignore: + - docs + - test \ No newline at end of file diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..13fcfcf --- /dev/null +++ b/.github/workflows/codeql.yml @@ -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}}" diff --git a/.github/workflows/eslint.yml b/.github/workflows/eslint.yml new file mode 100644 index 0000000..a53b473 --- /dev/null +++ b/.github/workflows/eslint.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/yarn-test.yml b/.github/workflows/yarn-test.yml new file mode 100644 index 0000000..7c17e62 --- /dev/null +++ b/.github/workflows/yarn-test.yml @@ -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 }} diff --git a/.jsdoc.json b/.jsdoc.json index c1396aa..d67ca40 100644 --- a/.jsdoc.json +++ b/.jsdoc.json @@ -30,5 +30,10 @@ "plugins": ["plugins/markdown"], "markdown": { "hardwrap": true + }, + "docdash": { + "scopeInOutputPath": false, + "nameInOutputPath": false, + "versionInOutputPath": false } } diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b278bdb..0000000 --- a/.travis.yml +++ /dev/null @@ -1,4 +0,0 @@ -language: node_js -node_js: - - "6" - - "7" diff --git a/LICENSE b/LICENSE index 8c39968..239d617 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.md b/README.md index fb83e35..6c64e9f 100644 --- a/README.md +++ b/README.md @@ -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 = ''; +const clientSecret = ''; + +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 = ''; +const clientSecret = ''; + +const fetcher = new EmoteFetcher(clientId, clientSecret); +const parser = new EmoteParser(fetcher, { + template: '{name}', // 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); + // EZ Clap way too easy LUL now for the last bost monkaS + + const channelEmotes = parser.parse('KEKW that was 3Head TeriPoint'); + console.log(channelEmotes); + // KEKW that was 3Head TeriPoint +}).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/) diff --git a/docs/BTTVEmote.html b/docs/BTTVEmote.html index a4258d8..d6d5bf9 100644 --- a/docs/BTTVEmote.html +++ b/docs/BTTVEmote.html @@ -1,9 +1,11 @@ + BTTVEmote - Documentation - + + + + + @@ -21,8 +26,11 @@ -