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.
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
TWITCH_PASSWORD=oauth:YourOAuthCodeGoesHere
CLIENT_ID=YourClientId
CLIENT_SECRET=YourClientSecret
CLIENT_TOKEN=YourClientToken
Twitch password OAuth token (TWITCH_PASSWORD
) can be retrieved from here.
Client variables require you to register your own application.
After you're done, copy the Client ID given to the application as well as the Client Secret.
Then you can retrieve your client token (CLIENT_TOKEN
) via Twitch CLI.
If you're running a release downloaded from the releases page:
yarn --production
yarn start CHANNEL_NAME
# or
yarn start CHANNEL_NAME 3000 30000 5
Otherwise if you're running the current master build:
yarn
and then:
- if you want to edit the code and made your own changes, run the TypeScript version
yarn dev CHANNEL_NAME
# or
yarn dev CHANNEL_NAME 3000 30000 5
- if you want to compile the TypeScript to pure JavaScript
yarn 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
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.
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.
- 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.
Please review the contributing guidelines. We reserve the right to refuse a Pull Request if it does not meet the requirements.