diff --git a/Gwendolyn.py b/Gwendolyn.py index 291b322..6f98186 100644 --- a/Gwendolyn.py +++ b/Gwendolyn.py @@ -38,17 +38,22 @@ async def blackjackLoop(channel,gameRound): if allStanding: await asyncio.sleep(5) else: - await asyncio.sleep(30) + await asyncio.sleep(120) with open("resources/games/games.json", "r") as f: - realRound = json.load(f)["blackjack games"][str(channel)]["round"] + data = json.load(f) - if gameRound == realRound: - if gamedone == False: - await blackjackLoop(channel,gameRound+1) + if str(channel) in data["blackjack games"]: + realRound = data["blackjack games"][str(channel)]["round"] + + if gameRound == realRound: + if gamedone == False: + await blackjackLoop(channel,gameRound+1) + else: + new_message = blackjackFinish(str(channel)) + await channel.send(new_message) else: - new_message = blackjackFinish(str(channel)) - await channel.send(new_message) + logThis("Ending loop on round "+str(gameRound)) else: logThis("Ending loop on round "+str(gameRound)) @@ -460,7 +465,7 @@ async def parseCommands(message,content): # Hitting elif content.startswith("blackjack hit"): if content == "blackjack hit" or content == "blackjack hit ": - response = blackjackHit(str(message.channel),message.author.display_name) + response= blackjackHit(str(message.channel),message.author.display_name) else: commands = content.split(" ") try: @@ -469,39 +474,64 @@ async def parseCommands(message,content): handNumber = 0 response = blackjackHit(str(message.channel),message.author.display_name,handNumber) - if response == "accept": + if response.startswith("accept"): await message.add_reaction("👍") + try: + if response[6] == "T": + await blackjackLoop(message.channel,int(response[7:])+1) + except: + logThis("Something fucked up") + await message.channel.send("something fucked up") else: await message.channel.send(response) + # Standing elif content.startswith("blackjack stand"): response = blackjackStand(str(message.channel),message.author.display_name,0) - if response == "accept": + + if response.startswith("accept"): await message.add_reaction("👍") + try: + if response[6] == "T": + await blackjackLoop(message.channel,int(response[7:])+1) + except: + logThis("Something fucked up") + await message.channel.send("something fucked up") else: await message.channel.send(response) # Doubling bet elif content.startswith("blackjack double"): - if content == "blackjack hit" or content == "blackjack hit ": - response = blackjackDouble(str(message.channel),message.author.display_name) - else: - commands = content.split(" ") - try: - handNumber = int(commands[2]) - except: - handNumber = 0 - response = blackjackDouble(str(message.channel),message.author.display_name,handNumber) + commands = content.split(" ") + try: + handNumber = int(commands[2]) + except: + handNumber = 0 + response, roundDone = blackjackDouble(str(message.channel),message.author.display_name,handNumber) - await message.channel.send(response) + await message.channel.send(response) + + try: + if roundDone[0] == "T": + await blackjackLoop(message.channel,int(roundDone[1:])+1) + except: + logThis("Something fucked up") + await message.channel.send("something fucked up") # Splitting hand elif content.startswith("blackjack split"): - response = blackjackSplit(str(message.channel),message.author.display_name) + response, roundDone = blackjackSplit(str(message.channel),message.author.display_name) await message.channel.send(response) + #try: + if roundDone[0] == "T": + await blackjackLoop(message.channel,int(roundDone[1:])+1) + #except: + # logThis("Something fucked up") + # await message.channel.send("something fucked up") + # Returning current hi-lo value elif content.startswith("blackjack hilo") and message.author.display_name == "Nikolaj": with open("resources/games/hilo.txt", "r") as f: diff --git a/funcs/games/blackjack.py b/funcs/games/blackjack.py index 608c66a..33bcf6e 100644 --- a/funcs/games/blackjack.py +++ b/funcs/games/blackjack.py @@ -180,7 +180,7 @@ def blackjackContinue(channel): firstRoundMessage = ". You can also double down with \"!blackjack double\" or split with \"!blackjack split\"" else: firstRoundMessage = "" - return "You have 30 seconds to either hit or stand with \"!blackjack hit\" or \"!blackjack stand\""+firstRoundMessage+". It's assumed you're standing if you don't make a choice.", False, done + return "You have 2 minutes to either hit or stand with \"!blackjack hit\" or \"!blackjack stand\""+firstRoundMessage+". It's assumed you're standing if you don't make a choice.", False, done # When players try to hit def blackjackHit(channel,user,handNumber = 0): @@ -225,7 +225,18 @@ def blackjackHit(channel,user,handNumber = 0): with open("resources/games/games.json", "w") as f: json.dump(data,f,indent=4) - return "accept" + response = "accept" + roundDone = True + + for person in data["blackjack games"][channel]["user hands"].values(): + if person["hit"] == False and person["standing"] == False: + roundDone = False + + if person["split"]: + if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False: + roundDone = False + + return response + str(roundDone)[0] + str(data["blackjack games"][channel]["round"]) else: logThis(user+" is already standing") return "You can't hit when you're standing" @@ -259,10 +270,10 @@ def blackjackDouble(channel,user,handNumber = 0): otherHand = True else: logThis(user+" tried to double without specifying which hand") - return "You have to specify the hand you're doubling down." + return "You have to specify the hand you're doubling down.","" else: logThis(user+" tried to double without specifying which hand") - return "You have to specify the hand you're doubling down." + return "You have to specify the hand you're doubling down.","" correctRound = 2 @@ -295,22 +306,33 @@ def blackjackDouble(channel,user,handNumber = 0): with open("resources/games/games.json", "w") as f: json.dump(data,f,indent=4) - return "Adding another "+str(bet)+" GwendoBucks to "+user+"'s bet and drawing another card." + roundDone = True + + for person in data["blackjack games"][channel]["user hands"].values(): + if person["hit"] == False and person["standing"] == False: + roundDone = False + + if person["split"]: + if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False: + roundDone = False + + + return "Adding another "+str(bet)+" GwendoBucks to "+user+"'s bet and drawing another card.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"]) else: logThis(user+" doesn't have enough GwendoBucks") - return "You don't have enough GwendoBucks" + return "You don't have enough GwendoBucks","" else: logThis(user+" tried to double on round "+str(data["blackjack games"][channel]["round"])) - return "You can only double down on the first round" + return "You can only double down on the first round","" else: logThis(user+" is already standing") - return "You can't double when you're standing" + return "You can't double when you're standing","" else: logThis(user+" has already hit this round") - return "You've already hit this round" + return "You've already hit this round","" else: logThis(user+" tried to double on the 0th round") - return "You can't double down before you see your cards" + return "You can't double down before you see your cards","" # When players try to stand def blackjackStand(channel,user,handNumber = 0): @@ -326,7 +348,18 @@ def blackjackStand(channel,user,handNumber = 0): with open("resources/games/games.json", "w") as f: json.dump(data,f,indent=4) - return "accept" + response = "accept" + roundDone = True + + for person in data["blackjack games"][channel]["user hands"].values(): + if person["hit"] == False and person["standing"] == False: + roundDone = False + + if person["split"]: + if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False: + roundDone = False + + return response + str(roundDone)[0] + str(data["blackjack games"][channel]["round"]) else: logThis(user+" is already standing") return "You're already standing" @@ -385,25 +418,35 @@ def blackjackSplit(channel,user): with open("resources/games/games.json", "w") as f: json.dump(data,f,indent=4) - return "Splitting "+user+"'s hand into 2. Adding their original bet to the second hand. You can use \"!Blackjack hit/stand/double 1\" and \"!Blackjack hit/stand/double 2\" to play the different hands." + roundDone = True + + for person in data["blackjack games"][channel]["user hands"].values(): + if person["hit"] == False and person["standing"] == False: + roundDone = False + + if person["split"]: + if person["other hand"]["hit"] == False and person["other hand"]["standing"] == False: + roundDone = False + + return "Splitting "+user+"'s hand into 2. Adding their original bet to the second hand. You can use \"!Blackjack hit/stand/double 1\" and \"!Blackjack hit/stand/double 2\" to play the different hands.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"]) else: logThis(user+" doesn't have enough GwendoBucks") - return "You don't have enough GwendoBucks" + return "You don't have enough GwendoBucks","" else: logThis(user+" tried to split 2 different cards") - return "Your cards need to have the same value to split" + return "Your cards need to have the same value to split","" else: logThis(user+" tried to split on round "+data["blackjack games"][channel]["round"]) - return "You can only split on the first round" + return "You can only split on the first round","" else: logThis(user+" is already standing") - return "You can't split when you're standing" + return "You can't split when you're standing","" else: logThis(user+" has already hit this round") - return "You've already hit this round" + return "You've already hit this round","" else: logThis(user+" tried to split on the 0th round") - return "You can't split before you see your cards" + return "You can't split before you see your cards","" # Player enters the game and draws a hand def blackjackPlayerDrawHand(channel,user,bet):