SC2 MMR Twitch Chat Bot

feardragon64 Code and Eng DK30 Quarantine 2020 3 2

Description

Make a bot that let’s a streamer set a minimum MMR threshold in StarCraft 2 for someone to have in order to talk. Chatters will have to authenticate their battle net account to get approved and everyone not authenticated or below the MMR level will automatically get timed out.

Recent Updates

feardragon64 5 years ago

Day 21:

FINISHED! Ended up having more free time than expected today as the family was pretty busy so I was able to get some filming done. I filmed the outro, tinkered with it a bit, finished editing and it’s rendered and ready to go up. I also added a kill switch to the application so I can distribute it and take it down at any point.

My best viewership times on youtube are when I publish videos around 9am Pacific on weekdays so I’ll hold off on publishing it Sunday and schedule it for Monday. Happy to be all done and set to go!

Very simple website for the project: https://feardragon.com/projects/tcgm

Video: https://www.youtube.com/watch?v=AQkuBqsicbE

feardragon64 5 years ago

Day 20:

Filming and editing is progressing! I finished filming and editing the intro and core section of the video but was delayed a lot due to not having enough clips of people using the bot. Unfortunately, twitch chat is…pretty good in most streams??? Who would have thunk. I still managed to find some good clips from a stream I did testing out the bot initially so all that’s left is wrap up and getting a bit of feedback before releasing it! Things looking good to finish within the next 4-5 days.

feardragon64 5 years ago

Day 15:

Script and written and filming has begun. I’ve given the application to roughly 9 people now and unfortunately only one of them(MCanning) has used it much so I’m lacking clips to use for the video. I’m reaching out to more folks to see if they will be more interested in using it.

As far as filming, I’ve finished the intro filming(and edited a first draft of it for feedback before I get too deep into it) and need to start filming the core explanation section. I also still need to write the ending for the script but I don’t want to do that until I see the app actually used more by some streamers.

Overall, looks like I’m looking relatively on track! Still a lot of work to do but weekend has been productive so far despite having lots of other stuff to do.

feardragon64 5 years ago

Day 13: I’ve distributed the early version of the app to a few streamers with more…aggressive…chats and found some bugs and fixed them!

I’ve also started on the beginning section of the script for the video. I’ll be passing it along to some my usual contacts for feedback before filming while I work on optimizing and improving the application. I think I’ll also add in a kill switch so I can make this project public and kill it if/when I feel its usage has become toxic.

Feeling good about trying to finish up the video in the next 2 weeks since I think that’s how long it’ll take to get a final verison to distribute, gather enough clips for the video and finish the epilogue + editing touch ups.

feardragon64 5 years ago

Day 11

Oops I finished it. Lost track of time and worked on it until 4am. Quick ui(very unpolished though) preview:

Uh…guess I’ll work on the video and do some server optimizations!

feardragon64 5 years ago

Day 10? Ok so some weird changes.

Getting external links and proper permissions for the Twitch Extension was getting more complicated than it was worth. It was also bringing up questions of how large the load on my server was going to be. I found a nicer solution that will also let me limit who can use this since I don’t actually want to make a toxic chat environment.

By making the app run locally on a user’s pc, I can deliver the url via twitch whispers to the user and inform them in chat that they’re going to be whispered. I still need to figure out how to handle users who have their whispers closed but that’s a problem for tomorrow.

So how far did I get? I uh…nearly finished it? All of the basic functionality is working so I plan to bug test and give a beta version to one or two streamers to test before releasing it to 7-8 streamers and start scripting for the video! Hooray!

feardragon64 5 years ago

Hey there handsome. Ready for some SICK day 6 updates?

MMR HAS BEEN GOT! Server is set up to fetch a user’s mmr once they authenticate with battle net and it’s stored in the database. I also have my endpoint to fetch the list of users who have authenticated and some basic caching of users and mmr.

I’ve tested this with a few different people in weird situations. Players that tend to play multiple races on multiple servers, players that are unranked, and everything inbetween. The server fetches your highest mmr on any server and if you’re just unranked everywhere it’ll return an mmr of 0.

Next up is the twitch extension! Looks like I’m a day ahead and tomorrow is a weekend so I don’t have worrrrrrkkkkkk so I can maybe get a head start on that. #blessed #fortnite #hippopotamus

feardragon64 5 years ago

Day 5 update:

Before working on the extension I decided to investigate further into the battle net authentication flow for actually getting a user’s mmr from them authenticating with battle net and if I could link it to a twitch account. After a lot of headaches from bad documentation, I figured it out! It did bring up some light scaling concerns due to having to call ~5 battle net endpoints just to get a user’s sc2_profile_id and their sc_ladder_id but I’ll handle those when I need to. I think I can just store those in the database and worry about making a cronjob to update them later.

With the flow figured out, I think the easiest way to test this is to worry about the extension later and setup the backend logic for storing the account info + mmr for people that authenticate in a database. Once I have that, I can make the api for the streamer to request the mmr of a specific user. After that I can work on a hyper simple version of the extension that shows mmr and times out users below a certain threshold.

Looking promising though since I’ve now verified its all possible!

feardragon64 5 years ago

Day 2 update:

Inspiration struck!

I was thinking about this wrong. There is a simpler, more iterative and useful way to implement this project. Instead of just having a bot that has a certain mmr level that’s running on the streamer’s PC, this can all be put into a channel extension panel(not overlay). Twitch panels can link outside(important for bnet authentication) and can send messages to my webserver. THEN through the panel settings(instead of an app running on their pc) the broadcaster can turn on/off battle net sc2 account linking for their chats and the extension itself can timeout messages from users who have not yet linked their battle net accounts.

This allows for a few things:

  1. The panel itself for viewers can also act as an mmr leaderboard. I imagine two tabs: highest mmr for authenticated viewers and highest mmr for viewers currently in the chat.
  2. The panel itself can have twitch chat moderation power so it can issue the timeouts and not require additional software(or setup) on the broadcaster’s side.
  3. Allows for variety of uses. Either everyone must be authenticated with an mmr threshold(memes), authenticated with no mmr filter(potential spam account filter too?), no authentication but leaderboards available and no mass authentication required BUT broadcaster forces a specific user to authenticate to speak(if they are heavily backseating for example and get called out).

I don’t actually imagine this project to have extremely long term use and I still think it’s mostly a fun meme but I have to say thanks to Olimoley if this all works out because she heavily inspired the idea for this usecase being more practical when I explained the concept to her.

I’m going to reshift the goals due to these changes. My first step will be getting a panel that let’s a viewer authenticate their battle net account. Then I need to store that data on my website as a fetchable endpoint. After that I can setup a broadcaster’s settings page view to turn on/off authentication required. Then I can add the leaderboard and other modes.

feardragon64 5 years ago

After some investigation, I found out that only overlay extensions cannot link out to external sites. So I can make a panel extension for users to pair their battle net account to their twitch accounts instead! This will be a way simpler flow since users won’t have to also authenticate their twitch accounts or even go to my website directly, I can just rely on the callback.

feardragon64 5 years ago

Day 0: I think I can reuse some existing code from a bot I made for UpATreeZelda(that enabled “non sub only mode” and timed out any users that WERE subscribed to the channel) to get a framework for the first part of things.

The difficult part is going to be figuring out a smooth way for users to let the bot know which twitch account is linked to which battle net account(and proving it by authenticating with battle net). My first thought was using a Twitch Extension but my understanding is that twitch extensions don’t actually let you leave the page, which is a neccessary step for authenticating with battle net.

For now, I think I’ll just set up a page on feardragon.com for authenticating and then figure out how to get feardragon.com to notify the bot(with either websockets or long polling for updates) which users are what mmr. I can probably set up a new database table for it to store the battle net account to twitch username pairing on the website and fetch the updated list each time the app starts. Then I can call sc2unmasked’s api to batch fetch the mmr for each player(or ideally just call battle net api directly if possible the first time a particular twitch user sends a message in chat that session). After that, the MMR can be stored locally on the bot and verify if the user should be timed out.

My biggest concern right now will be traffic load to the website but since I only plan to use this for a short time, if the load seems too heavy I can reserve a separate AWS or GCC instance instead and just pay for it for a single month to hold the app.

Fingers crossed! Start work on the chat client portion today!

Estimated Timeframe

Apr 25th - May 25th

Week 1 Goal

Develop client to timeout users and figure out(but unimplemented) way for users to authenticate/register their battle net accounts with the bot.

Develop a twitch extension panel that allows viewers to authenticate their battle net account and link it to their twitch account in my web server’s database.

Week 2 Goal

Implement battle net authentication for each twitch chatter and have it sent to the bot.

Add an endpoint to fetch the list of authenticated users as a dictionary of twitch id: mmr. Perform the mmr lookup every 10 minutes server-side.

Week 3 Goal

Implement MMR lookup for each twitch chatter

Implement a basic leaderboard of the mmr on accounts and an on/off switch on the broadcaster’s settings page for the panel to turn on/off mandatory battle net authentication to chat.

Week 4 Goal

Stress test and package solution so it’s usable for other approved people. Also start working on comical video if there’s time for it.

Stress test and implement additional features such as mmr minimum requirement instead of on/off, user callouts, etc. depending on time available.

Tags

  • twitch starcraft sc2 mmr bot coding