From 5623accd47350b132bb6b5f709dd15ba499431ec Mon Sep 17 00:00:00 2001 From: jona605a Date: Tue, 11 Aug 2020 21:31:50 +0200 Subject: [PATCH] :bug: --- funcs/games/hex.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/funcs/games/hex.py b/funcs/games/hex.py index ee5360b..1c7cc12 100644 --- a/funcs/games/hex.py +++ b/funcs/games/hex.py @@ -17,6 +17,9 @@ HEX_DIRECTIONS = [(0,1),(-1,1),(-1,0),(0,-1),(1,-1),(1,0)] # Parses command def parseHex(command, channel, user): commands = command.lower().split() + with open("resources/games/hexGames.json", "r") as f: + data = json.load(f) + if command == "" or command == " ": return "I didn't get that. Use \"!hex start [opponent]\" to start a game.", False, False, False, False @@ -27,11 +30,12 @@ def parseHex(command, channel, user): logThis("Starting a hex game with hexStart(). "+str(user)+" challenged "+commands[1]) return hexStart(channel,user,commands[1]) # commands[1] is the opponent + # If using a command with no game, return error + elif channel not in data: + return "There's no game in this channel", False, False, False, False + # Stopping the game elif commands[0] == "stop": - with open("resources/games/hexGames.json", "r") as f: - data = json.load(f) - if user in data[channel]["players"]: return "Ending game.", False, False, True, False else: @@ -50,8 +54,6 @@ def parseHex(command, channel, user): # Surrender elif commands[0] == "surrender": - with open("resources/games/hexGames.json", "r") as f: - data = json.load(f) players = data[channel]["players"] if user in players: opponent = (players.index(user) + 1) % 2 @@ -62,8 +64,6 @@ def parseHex(command, channel, user): # Swap elif commands[0] == "swap": - with open("resources/games/hexGames.json", "r") as f: - data = json.load(f) if len(data[channel]["gameHistory"]) == 1: # Only after the first move data[channel]["players"] = data[channel]["players"][::-1] # Swaps their player-number # Swaps the color of the hexes on the board drawing: