How To Connect Nightbot To Splatoon 2’s SplatNet

Mathew Chan
6 min readSep 11, 2020

Set up a free python server so Nightbot can tell Twitch chat your SplatNet Information such as your match KDs, ranks, and more.

Nightbot can show information about your recent matches, ranks, rotations, and more.

Requirements

  • Repl.it account (free tier)
  • MongoDB Atlas (free tier)
  • Uptime Robot (free tier)
  • Nightbot (free)

For this guide we are going to use the free tier of Repl.it with Uptime Robot to ensure the server is constantly running. If you want to create hidden repos, you will have to upgrade to the $5 plan, but for paid plans I recommend Pythonanywhere or Digital Ocean (which offer $5 plans with a lot more features like always on). We will host our database on MongoDB Atlas to store our Nintendo Session Tokens and Stat.ink API Token.

Note: I have no affiliation with the companies above.

Step 1: Getting Your Stat.ink API Token

After you register and login to Stat.ink, click on your name on the navigation bar and select Profile and Settings. On the redirected page, Click Show your API Token to copy your API token.

Step 2: Getting Your Nintendo Session Token

To keep things simple, we will get the Nintendo Session Token with frozenpandaman’s Splatnet2statink application.

Follow Setup Instructions on the page and once you run the application, you will be prompted for your Stat.ink API Token in Step 1 and required to navigate to a Nintendo portal on your browser and paste the login link back to the command line. If everything works, you should find your Nintendo Session Token in your config.txt file, which is in the same folder as the application executable. Copy the values of cookie and session_token. We will need these later.

Step 3: Storing Your Tokens on MongoDB Atlas

Register a MongoDB Atlas account and create a free tier MongoDB cluster.

Now create a database user for your cluster.

Enter a username and password. This is the credentials to access your database (not the credentials to login to MongoDB Atlas).

Click the connect button on your cluster. Here, change the whitelist options to Allow Access from Anywhere.

Now click on Collections of your Cluster and select Add My Own Data. We are going to create a database named splatoon-2 with a collection named tokens.

Insert a document and switch to {} view. Here, enter 3 key-value pairs as shown below: api_key in Step 1, as well as session_token and cookie copied from your config.txt in Step 2.

Press INSERT DOCUMENT on the far right of your tokens collection

After you have created this document, return to your cluster, click CONNECT and select Connect your application.

Copy the connection string in the next window. Paste it in a text file. Replace the <username> and <password> with your database username and password.

Crop out the front part of the connection string and replace <dbname> with splatoon-2

Step 4: Check to see if the API works

Navigate to the SplatNetConnector repo on Repl.it and fork the repo. Add a file called .env and insert the following.

CONNECTION_STRING=<your-database-connection-string>
Replace <your-database-connection-string> with the connection string of your database

Everything written in .env is private to your account. If your collection or database name is different from this guide, you might also need to update the values of DB and USER_COLLECTION in this file.

Once you forked the repo, you will now have your own source code and API server which is connected to your newly created database. Press Run on top of the code editor and you should see the main page load on the right. If you’ve successfully forked the repo, you should have your own base url on top of the iframe webpage. It should look different from the one shown below.

With a successful fork, your own username should be in place of the yuispl2 subdomain

Now let’s check the KDs of your most recent match. Copy your website’s url and add the following.

/recent_kd

Press enter and if you see something similar to the following, your server is good and running.

All the endpoints will be noted at the end of this guide and you can add and modify your own with the files splatnet.py and main.py.

Step 5: Connecting to Nightbot

Navigate to Nightbot’s Custom Command page and click Add Command on the top right. Name your command as you please and fill in Message with the following format

$(urlfetch <url> )

Replace <url> with one of your API endpoints. Creating your command here in Nighbot’s admin panel will keep your database credentials a secret.

Step 6: Test your new command!

You can change the format of the output by modifying the file splatnet.py in the source code

If you’re having trouble thus far, feel free to contact me via twitter.

Step 7: Keeping The Server Running

Servers created on Repl.it shut down after 1 hour of inactivity, so we need Uptime Robot to keep it running. Create a free tier account on Uptime Robot and once you’ve logged in, click Add New Monitor in your Dashboard. Select HTTP as its type, give it a name, and for URL enter the base url of your server (that returns ‘Hello World’).

Once the monitor is created, the server will stay alive.

Appendix I: Available Endpoints

  • /recent: returns your KD and paint the previous match.
  • /recent_kd: returns the KDs of each of your team members
  • /recent_power: returns the estimated league power
  • /recent_salmon: returns the result of your previous Salmon Run
  • /salmon_streak: returns your win rate in the current Salmon Run rotation
  • /ranks: returns your current ranks

--

--