Coder Social home page Coder Social logo

twitch-spambot's Introduction

twitch-spambot

CI

Coverage - statements Coverage - branches Coverage - functions Coverage - lines

Releases downloads GitHub release (latest SemVer) GitHub Release Date License GitHub open issues GitHub closed issues

An automated twitch spammer

Idea

The idea of this small project is to process the messages from given channel and simply spam whichever phrase is currently the most popular.

We can achieve this by constantly monitoring the chat with IRC from Twitch's Node.js library tmi.js.

We also fetch sub emotes from that channel to reject messages containing them, if we're not subbed.

How to run the program

Node.js is required, the program works under Windows, Ubuntu and macOS, with Node v14, v15 and the new v16 release.

.env file is required to provide data for the api and the config. Create an .env file consiting of values as shown below:

TWITCH_USERNAME=YourUsername
CLIENT_TOKEN=oauth:YourOAuthCodeGoesHere
CLIENT_ID=YourClientIdCodeGoesHere

Client token can be retrieved from here.

Client ID can be retrieved by making a HTTP request to an endpoint: https://api.twitch.tv/kraken and reading it from the response JSON in the client_id field:

{
    "token": {
        "valid": true,
        "authorization": {
            "scopes": [
                ...
            ],
            "created_at": ...,
            "updated_at": ...
        },
        "user_name": "USERNAME",
        "user_id": "ID",
        "client_id": "CLIENT_ID"
    }
}

You need to add additional data to the request's headers:

  • Accept: application/vnd.twitchtv.v5+json
  • Authorization: OAuth <YOURTOKEN>

Replace the <YOURTOKEN> part with the OAuth token you got earlier without the oauth: part.

An example CURL request:

curl -H 'Accept: application/vnd.twitchtv.v5+json' \
-H 'Authorization: OAuth <YOURTOKEN>' \
-X GET https://api.twitch.tv/kraken

Getting the Client ID might get automated in the future.

Release version

If you're running a release downloaded from the releases page:

yarn install --production

yarn start CHANNEL_NAME
# or
yarn start CHANNEL_NAME 3000 30000 5

Master version

Otherwise if you're running the current master build:

yarn install

and then:

  • if you want to edit the code and made your own changes, run the TypeScript version
yarn run dev CHANNEL_NAME
# or
yarn run dev CHANNEL_NAME 3000 30000 5
  • if you want to compile the TypeScript to pure JavaScript
yarn run tsc # to make a build directory

yarn start:dev CHANNEL_NAME
# or
yarn start:dev CHANNEL_NAME 3000 30000 5

The program has 4 available arguments:

  • channelName (required) - channel to which we connect to
  • readInterval: default = 5000 ms - the amount of time during which we gather channel messages and try to find the most popular spam
  • sleepInterval: default = 30000 ms - duration of sleep after sending the message to the channel
  • messageScore: default = 5 - score required for the most popular message to be sent (every message read within readInterval can contribute from 0 to 1 to the score and in case messages are the same, 2 will be added instead)
  • mentionResponse: when provided, results in an auto response (response takes randomly from 2 to 4s) to the person who mentioned your nickname in their message

The arguments are passed as:

yarn start CHANNEL_NAME READ_INTERVAL SLEEP_INTERVAL MESSAGE_SCORE MENTION_RESPONSE

If you wish to omit a particular argument (except the channelName), just pass a JavaScript falsy value, or an argument that is not a number, for example:

yarn start CHANNEL_NAME - - 6 -

which will result in running the script with default values for readInterval, sleepInterval and mentionResponse, but will change the default value of messageScore from 5 to 6.

You can also just run:

yarn start CHANNEL_NAME

to run the program with the default arguments. Adjust the arguments to match the desired channel's chat speed and activity.

You can also run multiple instances of the script at once by joining yarn start CHANNEL_NAME commands with & like:

yarn start CHANNEL_NAME & yarn start CHANNEL_NAME2 & yarn start CHANNEL_NAME3

Additional ignored words

You can add additional words to ignore (they will count towards message score, but will not be sent if they end up with the highest score). I found that feature useful since you might want to censor some words yourself.

My example cases were:

  • a streamer got banned, but people could still use his emotes, while they could not be fetched from the api
  • a 3rd party chat app (such as Chatterino for example), allows to easily whisper people without using the @ character before their username, which is hard to filter out - constantly keeping the user list cached would take a lot of resources and requests in bigger chats, so you might want to ignore usernames that are often whispered to avoid unintentional pings

To use this feature edit the json file called ignoredWords.json in the src/utils directory of the project, with structure as shown below:

{
  "ignoredWords": ["forsen1", "forsen2", "forsen3"] // 3 example words to ignore
}

with an array of ignored words of your choice.

Whitelist sub emotes

If you're subscired to a streamer and want to user their emotes with this bot, add their channel ID to whitelistEmotes.json file in the src/utils directory.

Since it would be troublesome for many people to create their own credentials for Twitch API requests you have to add the ID instead of the channel to simplify the process.

At the moment being one example website that allows finding channel IDs by providing usernames can be found here. After getting the channel ID paste it in as:

{
  "channels": ["62300805"] // Example channel ID for NymN's channel
}

Otherwise just leave the channels entry as an empty array.

Known problems

  1. yarn.ps1 cannot be loaded because running scripts is disabled on this system

Error on Windows that doesn't allow the user to install the libraries with yarn:

Open up Windows PowerShell and in the terminal type:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

After that, yarn should properly install dependencies.

Contributing

Please review the contributing guidelines. We reserve the right to refuse a Pull Request if it does not meet the requirements.

twitch-spambot's People

Contributors

frozentear7 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.