DEV Community

Vincent Cunningham
Vincent Cunningham

Posted on

A Guessing Game for Twitch Chat

Several months ago a friend approached me about building a Twitch chat bot to run a guessing game in their chat while they were playing a randomizer. It would give chat something to do to interact with the game besides just watching what would show up and hoping for the absolute worst combination of items requiring the longest playtime for that run.

I took it on and got it to a quite workable state he was happy with. After that though I started to think that this might be something other people would like to have a chance to use too. So I started to work on a web-based version that didn't require the bot to be running locally on the user's computer.

You can head over to the Guessing Game website to give it a try yourself. I apologize for the fact that it isn't very visually pleasing, and no doubt does not have a responsive design at all. At this current point it is in the Minimal Viable Product state.

I also have started a Patreon page to try to help fund the project so I can spend more time working on it. This is probably also the best place to get a quick run-down on how to use the website and the bot.

The rest of this post is about my journey to getting the website to this point.

Beginnings

At first I wanted to try to just wrap a web interface around the bot I had already created for my friend. It sounds nice, sounds easy too. Unfortunately the existing bot was tied too closely to his specific needs and trying to write everything around that was time-consuming and would require a lot of work to even get it to a state of parity. Beyond that scaling something designed for a single user up to be used by many users all at once is difficult considering all the assumptions you made while writing it for the single person.

Beyond that I had experimented with technologies I had never used before. Namely a NoSQL database (MongoDB) and that caused many headaches on its own even before this point. I do not advise your first attempt at using something new to be for a larger project. I definitely should have worked on several smaller applications to learn the quirks of MongoDB before trying to actually use it.

Starting From Scratch

You've probably heard you should never rewrite an application from scratch. I'm not saying I disagree with that philosophy at all. If you continue to rebuild from scratch over and over you'll never actually add and improve to your software. You'll just end up writing the same software several different ways, all of which have something you don't like about them. However I do believe there is a time and place for everything.

  1. If you are far more comfortable with another technology than the one you are currently using and you know you can perform work faster using it.

  2. "A chat bot that lets a user run guessing games" and "A website that allows countless users to start and manage guessing games in their chats" are very different enough goals.

With this Guessing Game website I felt both of these very strongly. I am far more familiar with SQL databases and would be able to work with them a lot easier than the NoSQL database I had used for the solo bot. As for the second, it is very possible that users of the website will want it to take a different path than the solo bot did considering it was written with very specific requirements tailored to my friend that not everyone else would necessarily be doing. With these in mind, I chose to start over completely.

Choosing My Tech

Language

With the decision to start over came the question of "What do I use to write it?" When it comes to web development most of my familiarity is with Java and PHP. I could have chosen one of those, however I had actually been contributing to and referencing the code for the Ocarina of Time Randomizer quite often as of recently and all of the actual randomizer code is in Python so I had grown a fair bit accustomed to it at the time. I also really didn't want to try and set up a Java development environment.

Web Framework

Trying to re-implement everything required to run a website backend would just be silly. I chose to go with Flask. Django was tempting, but it also has a lot of stuff I'm not sure I'd need. Flask lets me either implement or install a package of anything I need when I need it.

Data Storage

As I had said I attempted to use NoSQL for the solo bot but wanted to go back to a SQL database for this website as I was far more familiar with them. I chose to go with PostgreSQL over other options for no other reason that familiarity.

However, I also needed a way to share volatile information between the website and the bot(s) that would actually be joining the chats and running the guessing games. I had some passing familiarity with Redis at a prior job, and while I didn't actually do a whole lot of work with it, some quick testing applications allowed me to get familiar enough with it that I felt fine using it.

Hosting

I didn't want to have to run a VPS and keep it up to date all the time. I've had a Heroku account for a long time. I wanted to actually give it some use.

Deciding What Was Minimally Viable

This was probably one of the biggest differences between trying to tack a web interface onto the old bot, and starting one from scratch. Throwing one over top of the old one I felt as if I needed to make sure every feature of the bot was capable of being managed from the web interface. This would have been a lot of work and I couldn't be sure who all would even use the more specific features or not.

It was much easier to decide on what would be the absolute minimum to be useful with the new Guessing Game.

  • Log in with Twitch to create an account.
  • Enable and Disable the bot to have it Join and Part your Twitch chat on demand.
  • Create "Guessables" -- the items you could try to guess.
  • Allow several different variations for codes that would work as sometimes you want to give items shorter nicknames to make them easier to type.
  • Have a chat bot that could:
    • Start Guessing Games.
    • Accept Guesses during a Guessing Game.
    • Accept Answers during a Guessing Game.
    • Provide users with correct guesses a point.
    • Allow users to see how many points they have acquired during the active guessing game.
    • Finish Guessing Games.
    • Allow users to see how many total points they have.

It is still a fair bit of functionality, but it gave me a solid goal to work towards.


This post have gotten quite long, so I think I'll finish it up here for now. As you can see I've managed to implement all of these pieces of functionality I wanted to add. It didn't take very long either, I managed to get it all done within the last month or so.

I don't know if anyone finds any of this interesting. If you do I could go into more detail about other aspects of the Guessing Game as well. Hopefully there is something here you found interesting, and maybe you managed to make your way through all this text too for which I congratulate you. I had no idea I was going to write so much. I hope I didn't ramble too much.

Thank you for reading!

Top comments (1)

Collapse
 
alangervin profile image
AlanGervin

I have been thinking about writing a bot to run a binary guessing game on my channel. I like how you took the idea farther in that you wanted a website that could dispense your bot instead of having end users download and run it. For sure an idea that had not crossed my mind but could be a fun additional project.