A simple twitch bot for my stream.
Install Go on your machine and then setup a Supabase project for the bot. This bot uses a PostgreSQL database as its backend.
Step 1: Clone the repo
// with https
git clone https://github.com/kirontoo/rxkiro.git
// ssh
git clone git@github.com:kirontoo/rxkiro.gitStep 2: Make sure to install all Go modules
go mod download
Make a environment file called bot.env.
Here are all the environment variables you need to get started.
AUTH_TOKEN=your twitch auth login token
BOT_NAME=bot name or user you are logging in as
STREAMER=channel name (streamer you want to connet the bot to)
DB_API_URL=supabase rest api url
DB_TOKEN=supabase api token
AUTH_TOKENis the twitch auth token. You can grab one with this linkBOT_NAMEis the username of your twitch account that you want to log in asSTREAMERis the channel name/streamer you want to connect the bot toDB_API_URLis the supabase rest api urlDB_TOKENis the supabase api token
To find the DB_API_URL and the DB_TOKEN, you need to go into the Settings of your Supabase project.
- Under
Project API Keys, copy theanon publickey and set it as theDB_TOKEN. - Below this in
Configuration, copy theURLand set it as theDB_API_URL
Here is a official guide if my instructions are confusing.
The bot currently only uses the Commands table to look for commands. The bot
will first check for default commands that's been hard coded. If
that command is not found, then it will check the database for the correct command.
The Commands table should have these columns:
id, name, counter, isCounter, value, created_at
type Command struct {
ID int64 `json:"id"`
Name string `json:"name"`
Counter int64 `json:"counter"`
Value string `json:"value"`
IsCounter bool `json:"isCounter"`
CreatedAt string `json:"created_at"`
}Run this comand
go run main.goRight now, there is only 1 valid command variable user which will replace
command variable with the username of the user who invoked the command.
For Example:
!lurk has the value of ${user} is lurking!. The !lurk command will
replace ${user} with a username. The output will look like this: Kironto is lurking!.
There is a built in command for animal facts and fun facts, they are the
same but uses different tables depending on which type of fact you want.
In the future I might combine these tables and add a column for 'fact type'.
Here are columns that need to be defined for these tables:
{
id: int8,
created_at: timestampz,
value: text
}These commands can be invoked in the chat with !animalfact or !mefact.
For now, to properly use these commands, you'll need to create a custom function in Supabase.
In the SQL Editor tab of the Supabase dashboard, create a new query called "Rand Animal Fact"
and then paste this code.
create or replace function rand_animal_fact()
returns text
language sql
as $$
SELECT value FROM "AnimalFacts" ORDER BY RANDOM() limit 1;
$$Run this query in the SQL editor and the custom function should be added to
your db. Do the same for the fun facts except replace rand_animal_fact with
rand_fun_fact and AnimalFacts with FunFact.
!animalfact and !mefact commands should work now.
This project is licensed under the MIT License - see the LICENSE.md file for details