Bot Purpose & Code
I finally got an idea on what to make my custom Slack bot based on. I decided to make a hot potato slack bot called Potatpheus. Hot potato + Orpheus = Potatopheus. I set up global variables like gameState and friedLeaderboard to track the game data. I built a function called getRandomSeconds to handle the fuse timing, which works directly into my main explodePotato function to reset the game and log the loss when someone blows up. I added the slash command on the Slack APi called /drop-potato to begin the game. During testing, I encountered a problem which was if someone decided to start a new game while one is already going on. In order to resolve this issue, I used a conditional if statement to check a boolean flag inside my global gameState dictionary and then exited early using a return statement. Specifically, inside the /drop-potato command handler, I set up a restriction that checks if (gameState.isActive). If that boolean evaluates to true, the code uses Slack’s respond function to send a message back to the user (“A game is already active!”), and then directs itself to the return statement to stop itself. This stops the rest of the execution from reaching the setTimeout, ensuring no duplicate timers get created. I will work on the leaderboards and the pass function now.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.