✨ Separate blackjack cards for each chann
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@ -152,8 +152,8 @@ static
|
|||||||
token.txt
|
token.txt
|
||||||
resources/swcharacters.json
|
resources/swcharacters.json
|
||||||
resources/games/games.json
|
resources/games/games.json
|
||||||
resources/games/blackjackCards.txt
|
resources/games/blackjackCards/
|
||||||
resources/games/hilo.txt
|
resources/games/hilo/
|
||||||
resources/destinyPoints.txt
|
resources/destinyPoints.txt
|
||||||
resources/games/blackjackTables/
|
resources/games/blackjackTables/
|
||||||
resources/games/oldImages/
|
resources/games/oldImages/
|
||||||
|
31
Gwendolyn.py
31
Gwendolyn.py
@ -8,6 +8,7 @@ import string
|
|||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import math
|
import math
|
||||||
|
import os
|
||||||
|
|
||||||
from funcs import *
|
from funcs import *
|
||||||
|
|
||||||
@ -415,13 +416,14 @@ async def parseCommands(message,content):
|
|||||||
# Starts the game
|
# Starts the game
|
||||||
if content == "blackjack" or content == "blackjack ":
|
if content == "blackjack" or content == "blackjack ":
|
||||||
cardsLeft = 0
|
cardsLeft = 0
|
||||||
with open("resources/games/blackjackCards.txt","r") as f:
|
if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"):
|
||||||
for line in f:
|
with open("resources/games/blackjackCards/"+str(message.channel)+".txt","r") as f:
|
||||||
cardsLeft += 1
|
for line in f:
|
||||||
|
cardsLeft += 1
|
||||||
|
|
||||||
# Shuffles if not enough cards
|
# Shuffles if not enough cards
|
||||||
if cardsLeft < blackjackMinCards:
|
if cardsLeft < blackjackMinCards:
|
||||||
blackjackShuffle(blackjackDecks)
|
blackjackShuffle(blackjackDecks,str(message.channel))
|
||||||
logThis("Shuffling the blackjack deck...",str(message.channel))
|
logThis("Shuffling the blackjack deck...",str(message.channel))
|
||||||
await message.channel.send("Shuffling the deck...")
|
await message.channel.send("Shuffling the deck...")
|
||||||
|
|
||||||
@ -560,21 +562,27 @@ async def parseCommands(message,content):
|
|||||||
|
|
||||||
# Returning current hi-lo value
|
# Returning current hi-lo value
|
||||||
elif content.startswith("blackjack hilo") and message.author.display_name == "Nikolaj":
|
elif content.startswith("blackjack hilo") and message.author.display_name == "Nikolaj":
|
||||||
with open("resources/games/hilo.txt", "r") as f:
|
if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"):
|
||||||
data = f.read()
|
with open("resources/games/hilo/"+str(message.channel)+".txt", "r") as f:
|
||||||
|
data = f.read()
|
||||||
|
else:
|
||||||
|
data = "0"
|
||||||
await message.channel.send(data)
|
await message.channel.send(data)
|
||||||
|
|
||||||
# Shuffles the blackjack deck
|
# Shuffles the blackjack deck
|
||||||
elif content.startswith("blackjack shuffle"):
|
elif content.startswith("blackjack shuffle"):
|
||||||
blackjackShuffle(blackjackDecks)
|
blackjackShuffle(blackjackDecks,str(message.channel))
|
||||||
logThis("Shuffling the blackjack deck...",str(message.channel))
|
logThis("Shuffling the blackjack deck...",str(message.channel))
|
||||||
await message.channel.send("Shuffling the deck...")
|
await message.channel.send("Shuffling the deck...")
|
||||||
|
|
||||||
|
|
||||||
|
# Tells you the amount of cards left
|
||||||
elif content.startswith("blackjack cards"):
|
elif content.startswith("blackjack cards"):
|
||||||
cardsLeft = 0
|
cardsLeft = 0
|
||||||
with open("resources/games/blackjackCards.txt","r") as f:
|
if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"):
|
||||||
for line in f:
|
with open("resources/games/blackjackCards/"+str(message.channel)+".txt","r") as f:
|
||||||
cardsLeft += 1
|
for line in f:
|
||||||
|
cardsLeft += 1
|
||||||
|
|
||||||
decksLeft = round(cardsLeft/52,1)
|
decksLeft = round(cardsLeft/52,1)
|
||||||
await message.channel.send(str(cardsLeft)+" cards, "+str(decksLeft)+" decks")
|
await message.channel.send(str(cardsLeft)+" cards, "+str(decksLeft)+" decks")
|
||||||
@ -618,9 +626,6 @@ async def parseCommands(message,content):
|
|||||||
# Makes files if they don't exist yet
|
# Makes files if they don't exist yet
|
||||||
makeFiles()
|
makeFiles()
|
||||||
|
|
||||||
# Shuffling cards
|
|
||||||
blackjackShuffle(4)
|
|
||||||
|
|
||||||
# Gets secret bot token
|
# Gets secret bot token
|
||||||
with open("token.txt","r") as f:
|
with open("token.txt","r") as f:
|
||||||
token = f.read().replace("\n","")
|
token = f.read().replace("\n","")
|
||||||
|
@ -9,7 +9,7 @@ from funcs import logThis, replaceMultiple
|
|||||||
from . import money, blackjackDraw
|
from . import money, blackjackDraw
|
||||||
|
|
||||||
# Shuffles the blackjack cards
|
# Shuffles the blackjack cards
|
||||||
def blackjackShuffle(decks):
|
def blackjackShuffle(decks,channel):
|
||||||
logThis("Shuffling the blackjack deck")
|
logThis("Shuffling the blackjack deck")
|
||||||
|
|
||||||
with open("resources/games/deckofCards.txt","r") as f:
|
with open("resources/games/deckofCards.txt","r") as f:
|
||||||
@ -19,13 +19,13 @@ def blackjackShuffle(decks):
|
|||||||
random.shuffle(allDecks)
|
random.shuffle(allDecks)
|
||||||
data = "\n".join(allDecks)
|
data = "\n".join(allDecks)
|
||||||
|
|
||||||
with open("resources/games/blackjackCards.txt","w") as f:
|
with open("resources/games/blackjackCards/"+channel+".txt","w") as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
|
|
||||||
# Creates hilo.txt
|
# Creates hilo file
|
||||||
logThis("creating hilo.txt.")
|
logThis("creating hilo/"+channel+".txt.")
|
||||||
data = "0"
|
data = "0"
|
||||||
with open("resources/games/hilo.txt","w") as f:
|
with open("resources/games/hilo/"+channel+".txt","w") as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -59,11 +59,11 @@ def calcHandValue(hand : list):
|
|||||||
return handValue
|
return handValue
|
||||||
|
|
||||||
# Draws a card from the deck
|
# Draws a card from the deck
|
||||||
def drawCard():
|
def drawCard(channel):
|
||||||
logThis("drawing a card")
|
logThis("drawing a card")
|
||||||
with open("resources/games/blackjackCards.txt","r") as f:
|
with open("resources/games/blackjackCards/"+channel+".txt","r") as f:
|
||||||
cards = f.read().split("\n")
|
cards = f.read().split("\n")
|
||||||
with open("resources/games/hilo.txt", "r") as f:
|
with open("resources/games/hilo/"+channel+".txt", "r") as f:
|
||||||
data = int(f.read())
|
data = int(f.read())
|
||||||
|
|
||||||
drawnCard = cards.pop(0)
|
drawnCard = cards.pop(0)
|
||||||
@ -76,9 +76,9 @@ def drawCard():
|
|||||||
elif value >= 10:
|
elif value >= 10:
|
||||||
data -= 1
|
data -= 1
|
||||||
|
|
||||||
with open("resources/games/blackjackCards.txt","w") as f:
|
with open("resources/games/blackjackCards/"+channel+".txt","w") as f:
|
||||||
f.write(deck)
|
f.write(deck)
|
||||||
with open("resources/games/hilo.txt", "w") as f:
|
with open("resources/games/hilo/"+channel+".txt", "w") as f:
|
||||||
f.write(str(data))
|
f.write(str(data))
|
||||||
|
|
||||||
return drawnCard
|
return drawnCard
|
||||||
@ -92,7 +92,7 @@ def dealerDraw(channel):
|
|||||||
dealerHand = data["blackjack games"][channel]["dealer hand"]
|
dealerHand = data["blackjack games"][channel]["dealer hand"]
|
||||||
|
|
||||||
if calcHandValue(dealerHand) < 17:
|
if calcHandValue(dealerHand) < 17:
|
||||||
data["blackjack games"][channel]["dealer hand"].append(drawCard())
|
data["blackjack games"][channel]["dealer hand"].append(drawCard(channel))
|
||||||
else:
|
else:
|
||||||
done = True
|
done = True
|
||||||
|
|
||||||
@ -211,7 +211,7 @@ def blackjackHit(channel,user,handNumber = 0):
|
|||||||
if data["blackjack games"][channel]["round"] > 0:
|
if data["blackjack games"][channel]["round"] > 0:
|
||||||
if hand["hit"] == False:
|
if hand["hit"] == False:
|
||||||
if hand["standing"] == False:
|
if hand["standing"] == False:
|
||||||
hand["hand"].append(drawCard())
|
hand["hand"].append(drawCard(channel))
|
||||||
hand["hit"] = True
|
hand["hit"] = True
|
||||||
|
|
||||||
handValue = calcHandValue(hand["hand"])
|
handValue = calcHandValue(hand["hand"])
|
||||||
@ -289,7 +289,7 @@ def blackjackDouble(channel,user,handNumber = 0):
|
|||||||
with open("resources/games/games.json", "r") as f:
|
with open("resources/games/games.json", "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
hand["hand"].append(drawCard())
|
hand["hand"].append(drawCard(channel))
|
||||||
hand["hit"] = True
|
hand["hit"] = True
|
||||||
hand["doubled"] = True
|
hand["doubled"] = True
|
||||||
hand["bet"] += bet
|
hand["bet"] += bet
|
||||||
@ -418,8 +418,8 @@ def blackjackSplit(channel,user):
|
|||||||
data["blackjack games"][channel]["user hands"][user]["other hand"]["bet"] = data["blackjack games"][channel]["user hands"][user]["bet"]
|
data["blackjack games"][channel]["user hands"][user]["other hand"]["bet"] = data["blackjack games"][channel]["user hands"][user]["bet"]
|
||||||
|
|
||||||
data["blackjack games"][channel]["user hands"][user]["other hand"]["hand"].append(data["blackjack games"][channel]["user hands"][user]["hand"].pop(1))
|
data["blackjack games"][channel]["user hands"][user]["other hand"]["hand"].append(data["blackjack games"][channel]["user hands"][user]["hand"].pop(1))
|
||||||
data["blackjack games"][channel]["user hands"][user]["other hand"]["hand"].append(drawCard())
|
data["blackjack games"][channel]["user hands"][user]["other hand"]["hand"].append(drawCard(channel))
|
||||||
data["blackjack games"][channel]["user hands"][user]["hand"].append(drawCard())
|
data["blackjack games"][channel]["user hands"][user]["hand"].append(drawCard(channel))
|
||||||
|
|
||||||
handValue = calcHandValue(data["blackjack games"][channel]["user hands"][user]["hand"])
|
handValue = calcHandValue(data["blackjack games"][channel]["user hands"][user]["hand"])
|
||||||
otherHandValue = calcHandValue(data["blackjack games"][channel]["user hands"][user]["other hand"]["hand"])
|
otherHandValue = calcHandValue(data["blackjack games"][channel]["user hands"][user]["other hand"]["hand"])
|
||||||
@ -481,7 +481,7 @@ def blackjackPlayerDrawHand(channel,user,bet):
|
|||||||
if bet >= 0:
|
if bet >= 0:
|
||||||
if money.checkBalance(user) >= bet:
|
if money.checkBalance(user) >= bet:
|
||||||
money.addMoney(user,-1 * bet)
|
money.addMoney(user,-1 * bet)
|
||||||
playerHand = [drawCard(),drawCard()]
|
playerHand = [drawCard(channel),drawCard(channel)]
|
||||||
|
|
||||||
handValue = calcHandValue(playerHand)
|
handValue = calcHandValue(playerHand)
|
||||||
|
|
||||||
@ -534,7 +534,7 @@ def blackjackStart(channel:str):
|
|||||||
|
|
||||||
if channel not in data["blackjack games"]:
|
if channel not in data["blackjack games"]:
|
||||||
|
|
||||||
dealerHand = [drawCard(),drawCard()]
|
dealerHand = [drawCard(channel),drawCard(channel)]
|
||||||
gameID = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
|
gameID = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
|
||||||
|
|
||||||
data["blackjack games"][channel] = {"dealer hand": dealerHand,"dealer busted":False,"dealer blackjack":False,"user hands": {},"all standing":False,"round":0,"id":gameID}
|
data["blackjack games"][channel] = {"dealer hand": dealerHand,"dealer busted":False,"dealer blackjack":False,"user hands": {},"all standing":False,"round":0,"id":gameID}
|
||||||
|
@ -159,17 +159,6 @@ def makeFiles():
|
|||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
# Creates blackjackCards.txt if it doesn't exist
|
|
||||||
try:
|
|
||||||
f = open("resources/games/blackjackCards.txt","r")
|
|
||||||
except:
|
|
||||||
logThis("blackjackCards.txt didn't exist. Making it now.")
|
|
||||||
data = ""
|
|
||||||
with open("resources/games/blackjackCards.txt","w") as f:
|
|
||||||
f.write(data)
|
|
||||||
finally:
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
# Creates destinyPoints.txt if it doesn't exist
|
# Creates destinyPoints.txt if it doesn't exist
|
||||||
try:
|
try:
|
||||||
f = open("resources/destinyPoints.txt","r")
|
f = open("resources/destinyPoints.txt","r")
|
||||||
@ -200,12 +189,22 @@ def makeFiles():
|
|||||||
# Creates the 4InARowBoards foulder if it doesn't exist
|
# Creates the 4InARowBoards foulder if it doesn't exist
|
||||||
if os.path.isdir("resources/games/4InARowBoards") == False:
|
if os.path.isdir("resources/games/4InARowBoards") == False:
|
||||||
os.makedirs("resources/games/4InARowBoards")
|
os.makedirs("resources/games/4InARowBoards")
|
||||||
logThis("The tables directory didn't exist")
|
logThis("The 4 in a row boards directory didn't exist")
|
||||||
|
|
||||||
# Creates the 4InARowBoards foulder if it doesn't exist
|
# Creates the oldImages foulder if it doesn't exist
|
||||||
if os.path.isdir("resources/games/oldImages") == False:
|
if os.path.isdir("resources/games/oldImages") == False:
|
||||||
os.makedirs("resources/games/oldImages")
|
os.makedirs("resources/games/oldImages")
|
||||||
logThis("The tables directory didn't exist")
|
logThis("The old images directory didn't exist")
|
||||||
|
|
||||||
|
# Creates the blackjackCards foulder if it doesn't exist
|
||||||
|
if os.path.isdir("resources/games/blackjackCards") == False:
|
||||||
|
os.makedirs("resources/games/blackjackCards")
|
||||||
|
logThis("The blackjack cards directory didn't exist")
|
||||||
|
|
||||||
|
# Creates the hilo foulder if it doesn't exist
|
||||||
|
if os.path.isdir("resources/games/hilo") == False:
|
||||||
|
os.makedirs("resources/games/hilo")
|
||||||
|
logThis("The hi-lo directory didn't exist")
|
||||||
|
|
||||||
# Replaces multiple things with the same thing
|
# Replaces multiple things with the same thing
|
||||||
def replaceMultiple(mainString, toBeReplaces, newString):
|
def replaceMultiple(mainString, toBeReplaces, newString):
|
||||||
|
Reference in New Issue
Block a user