Inspiration

Two of us - Advait "Adi" Budaraju and Grant Strickland - are part of the Purdue University Battling Association, where over 60+ members compete in an online turn-based "half-chess half-poker" game on the website Pokemon Showdown. When official matches are played, the club officers sometimes need to be up at ungodly hours so that they can join the match and save the replay and post the results afterwards. We wanted to give them a hand in that process.

What it does

PUBA-Helper is a Discord bot that waits for a match link to pop up in the PUBA Discord server, then joins the match and waits till completion. Once the match is finished, it saves the match replay, determines basic match statistics, and message the result in one of the official "results" channels.

How we built it

PUBA-Helper was built solely in Python, and hosted on Heroku. The python script for the bot uses discord.py (the Discord API), showdownpy (the Pokemon Showdown API), and pygsheets (the Google Sheets API wrapper). It waits for a message, and if the message is a link, it creates a new custom-built Showdown client to observe the replay, waiting for the match to end. Once the match ends, the script parses through the client logs to figure out the match result and stats, and searches on Google Sheets for the corresponding team name for the Showdown username. Finally, the script sends a message in the results channels with the relevant match information.

Challenges we ran into

  • The Google Sheets API has a quota limit per key, so we spend a while trying to dance around the quota before finally figuring out a way to greatly decrease the amount of requests we made.
  • The main project development was done while SSH'd onto a data.cs.purdue.edu Linux machine, whose packages were not all up to date and even caused a segmentation fault (in Python, of all languages!) while trying to perform certain imports. We narrowed down which package was causing the problem and finally figured out that it was an incompatible version with other project packages - we had to change its version before the program worked.
  • Additionally, installing the Heroku CLI requires root access, which we didn't have on the student Linux machine - so we had to find a workaround to put Heroku in a separate directory and add it to the PATH, with a couple extra steps in between.
  • The Discord bot needs to continuously run, but so does the Pokemon Showdown client that the program creates to check if the match ends. Thus, we needed to carefully organize the order of our initializations for the program thread not to get stuck somewhere.

Accomplishments that we're proud of

  • Building a fully-functioning project with actual applications in less than 24 hours
  • Integrating three extremely different APIs together in one single python script
  • Designing a scraping algorithm that effectively draws information from relevant Google Sheets
  • Getting the project up-and-running on Heroku

What we learned

  • How to troubleshoot package dependency and version issues
  • How to work with the discord.py, showdownpy, and pygsheets APIs
  • How to properly control thread flow in Python
  • How to deploy a project on Heroku

What's next for PUBA-Helper

  • Adding it to the PUBA server: Since the project was just finalized, we don't blame the PUBA Officers for wanting to wait a little to add such a bot to a big club server, though hopefully it will be on there within the next couple of days.
  • Adding commands to check league standings: This requires more Google Sheets scraping, and was intentionally left out now so as to not exceed the quota mentioned in the challenges. We'll try to find a way around that quota in order to implement this.

Built With

Share this project:

Updates