From 1104d2bfa468b7b21cd09128cb8237aec6b1e21b Mon Sep 17 00:00:00 2001 From: NikolajDanger Date: Wed, 29 Jul 2020 14:13:13 +0200 Subject: [PATCH] :sparkles: Added shuffle and hilo commands --- .gitignore | 1 + Gwendolyn.py | 30 +++++++++++++++++++++--------- funcs/games/blackjack.py | 15 +++++++++++++-- funcs/miscFuncs.py | 11 +++++++++++ 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 2e92a77..286a5f4 100644 --- a/.gitignore +++ b/.gitignore @@ -153,6 +153,7 @@ token.txt resources/swcharacters.json resources/games/games.json resources/games/blackjackCards.txt +resources/games/hilo.txt resources/destinyPoints.txt resources/games/blackjackTables/ resources/games/4InARowBoards/ diff --git a/Gwendolyn.py b/Gwendolyn.py index 7f63fe7..d9f614d 100644 --- a/Gwendolyn.py +++ b/Gwendolyn.py @@ -474,7 +474,19 @@ async def parseCommands(message,content): response = blackjackSplit(str(message.channel),message.author.display_name) await message.channel.send(response) - + + # 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: + data = f.read() + await message.channel.send(data) + + # Shuffles the blackjack deck + elif content.startswith("blackjack shuffle"): + blackjackShuffle(blackjackDecks) + logThis("Shuffling the blackjack deck...") + await message.channel.send("Shuffling the deck...") + else: await message.channel.send("I didn't quite understand that") @@ -513,14 +525,14 @@ async def on_ready(): # Reads messages and tests if they are Gwendolyn commands @client.event async def on_message(message): - try: - content = message.content - if content.startswith(commandPrefix): - logThis(message.author.display_name+" ran \""+content+"\"") - await parseCommands(message,content.lower()[1:]) - except: - logThis("Something fucked up (error code 000)") - await message.channel.send("Something fucked up (error code 000)") + #try: + content = message.content + if content.startswith(commandPrefix): + logThis(message.author.display_name+" ran \""+content+"\"") + await parseCommands(message,content.lower()[1:]) + #except: + # logThis("Something fucked up (error code 000)") + # await message.channel.send("Something fucked up (error code 000)") # Is a bit sassy sometimes if ("gwendolyn" in message.content.lower() or message.content.startswith(commandPrefix)) and any(x in message.content.lower() for x in meanWords) and "ikke" not in message.content.lower() and "not" not in message.content.lower(): diff --git a/funcs/games/blackjack.py b/funcs/games/blackjack.py index 2876860..a61d01c 100644 --- a/funcs/games/blackjack.py +++ b/funcs/games/blackjack.py @@ -56,12 +56,23 @@ def drawCard(): logThis("drawing a card") with open("resources/games/blackjackCards.txt","r") as f: cards = f.read().split("\n") + with open("resources/games/hilo.txt", "r") as f: + data = int(f.read()) drawnCard = cards.pop(0) - data = "\n".join(cards) + deck = "\n".join(cards) + + value = calcHandValue([drawnCard]) + + if value <= 6: + data += 1 + elif value >= 10: + data -= 1 with open("resources/games/blackjackCards.txt","w") as f: - f.write(data) + f.write(deck) + with open("resources/games/hilo.txt", "w") as f: + f.write(str(data)) return drawnCard diff --git a/funcs/miscFuncs.py b/funcs/miscFuncs.py index 670b766..0a40a41 100644 --- a/funcs/miscFuncs.py +++ b/funcs/miscFuncs.py @@ -165,6 +165,17 @@ def makeFiles(): finally: f.close() + # Creates blackjackCards.txt if it doesn't exist + try: + f = open("resources/games/hilo.txt","r") + except: + logThis("hilo.txt didn't exist. Making it now.") + data = "" + with open("resources/games/hilo.txt","w") as f: + f.write(data) + finally: + f.close() + # Creates destinyPoints.txt if it doesn't exist try: f = open("resources/destinyPoints.txt","r")