Hacker's bash Twitch chatbot script. Allow twitch bot creation entierly written in pure BASH.
This is a pure bash twitch-bot. It can connect to some twitch channel, and respond to commands. It can also be plugged over MQTT, or other protocols (SMS, Mail.... anything you want). Twitch's chat uses IRC.
This bot has been created live on Twitch (see replay here: https://www.twitch.tv/videos/843197384). For more informations, checkout my blog at tixlegeek.io, or follow me on Twitter @tixlegeek
The bot creates two named pipes, which are then bound to networking subsystem. You can tweak the name of those named pipes:
IRC_INPUT=ircinput
IRC_OUTPUT=ircoutputIRC Configuration is quite straight-forward. Just generate an Oauth token linked to your twitch account, using https://twitchapps.com/tmi/. The oauth token must be written in "./pass", which will be red by the bot. You must use your twitch user name to be allowed on the server.
IRC_HOST="irc.chat.twitch.tv"
IRC_PORT="6667"
IRC_NICK="tixlegeek"
IRC_USER="tixlegeek"
IRC_PASS=$(cat ./pass)
IRC_CHANNEL="#tixlegeek"
IRC_NOFLOOD_MAXWAIT=5The bot is mqtt-ready if you have installed mosquitto-client. Here is the parameters:
MQTT_ALLOW=false
MQTT_HOST="HOST"
MQTT_PORT="PORT"
MQTT_USER="USER"
MQTT_PASSWORD="PASSWORD"The bot uses some custom log functions:
function irc_log()
function irc_in_log()
function irc_out_log()
function sys_log()
function bot_log()
function err_log()Here are randomized response. random_wait is here to randomize response-time. The max response-time can be tweaked by IRC_NOFLOOD_MAXWAIT.
function irc_random_nope()
function irc_random_ok()
function random_wait()The end-function is called by trap over SIGINT messages.
function IRC_QUIT ()This function is just a helper which feeds the socket.
function irc_send()