This repository contains a Go application that serves as a chat bot for Twitch. It listens to the chat of a specific channel and responds to a specific command with a random Chuck Norris fact.
Before you start, please ensure you have Go installed on your computer. You can download and install Go from here.
You should copy the placeholders in the credentials.json.example
into credentials.json
file with your actual
Twitch username, OAuth token, and channel name. Here's an example of what it might look like:
{
"username": "mytwitchusername",
"oauth_token": "oauth:myoauthtoken",
"channel_name": "mytwitchchannel"
}
The bot will use these credentials to connect to the Twitch api. Remember to never share this file, as it contains your
sensitive data. It is ignored by git in the .gitignore
file.
To build the project, navigate to root of the project and use the Go build command:
go build
This will create an executable file in the same directory.
To start the bot, simply run the executable that you built in the installation step:
./dev
The bot uses the standard Go libraries to connect to the Twitch IRC server over SSL. It then joins the specified
channel and listens for messages. If a message matches the !chucknorris
command, the bot fetches a random fact from
the Chuck Norris API and sends it to the channel.
The bot runs asynchronously, using goroutines to handle incoming messages and API responses. It also handles PING/PONG messages from the Twitch server to avoid disconnection. It is designed to comply with the Twitch API rate limits.
The bot has a suite of unit tests that can be run using the Go test command:
go test -v ./...
In order to run the conn_test.go
file you will need to create a certificate and key file for the bot to use.
You can do this by running the following command in teh conn
directory:
openssl req -x509 -nodes -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365