A Twitch Bot is a program that hangs out in your Twitch chat waiting for a command whether that be deleting spam comments or responding to someone asking how long you’ve been streaming. In my case, it was going to listen for color commands.
Building the color commands:
I wanted people to be able to easily change the colors of the lights. After trying to find a Pantone color list with hex values, I moved onto a well known list of colors: HTML Web Safe colors (I modified this list). Using this list allowed me to have a nice hex color code reference for all of the named colors. Example: Chartreuse is #7fff00. In order to easily decipher between normal chat and a color command I went with a text format I’ve seen used of adding an “!” before the command. I also wanted to give the user a choice of a custom color, so I also added “#” to signify a custom hex color. This basis around hex would become the core of the application.
Messages:
Building the Twitch bot was straight forward using the TMI library. I checked if the message started with a “!” or “#”, then checked if the “!” command was in my list of colors, if not the program moves on. If the command starts with a “#” the program checks it is a valid hex. Once this was working, I built out a class to send data internally, and used it to send data to the Express Server. At this point, I decided to establish a data schema that would persist throughout the application and hashing using MD5 usernames, so I could determine the number of unique users while not storing their names.
Schema: source, msgUsername, validColor, hex, “#HEXVALUE”. Eventually this would be updated to:
{ source: source, username: MD5(“username”), validColor: True/False, hex: True/False, color: ‘#000000”, red: RedValue, green: GreenValue, blue: BlueValue dateTime: new Date() };
Architecture Status:
At this point, the local Express server is sending the color messages it received to a MongoDb database directly. I knew this would become an issue but moved onto the website component.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.