🧹 Cleaning up blackjack
This commit is contained in:
@ -48,13 +48,32 @@ class BlackjackCog(commands.Cog):
|
||||
|
||||
@cog_ext.cog_subcommand(**params["blackjackStand"])
|
||||
async def blackjackStand(self, ctx, hand = ""):
|
||||
await ctx.defer()
|
||||
await self.bot.games.blackjack.parseBlackjack(f"stand {hand}", ctx)
|
||||
await self.bot.games.blackjack.stand(ctx, hand)
|
||||
|
||||
@cog_ext.cog_subcommand(**params["blackjackHit"])
|
||||
async def blackjackHit(self, ctx, hand = 0):
|
||||
await self.bot.games.blackjack.hit(ctx, hand)
|
||||
|
||||
@cog_ext.cog_subcommand(**params["blackjackDouble"])
|
||||
async def blackjackDouble(self, ctx, hand = 0):
|
||||
await self.bot.games.blackjack.double(ctx, hand)
|
||||
|
||||
@cog_ext.cog_subcommand(**params["blackjackSplit"])
|
||||
async def blackjackSplit(self, ctx, hand = 0):
|
||||
await self.bot.games.blackjack.split(ctx, hand)
|
||||
|
||||
@cog_ext.cog_subcommand(**params["blackjackHilo"])
|
||||
async def blackjackHilo(self, ctx):
|
||||
await self.bot.games.blackjack.hilo(ctx)
|
||||
|
||||
@cog_ext.cog_subcommand(**params["blackjackShuffle"])
|
||||
async def blackjackShuffle(self, ctx):
|
||||
await self.bot.games.blackjack.shuffle(ctx)
|
||||
|
||||
@cog_ext.cog_subcommand(**params["blackjackCards"])
|
||||
async def blackjackCards(self, ctx):
|
||||
await self.bot.games.blackjack.cards(ctx)
|
||||
|
||||
|
||||
class ConnectFourCog(commands.Cog):
|
||||
def __init__(self,bot):
|
||||
|
@ -18,7 +18,7 @@ class Blackjack():
|
||||
def blackjackShuffle(self, decks, channel):
|
||||
self.bot.log("Shuffling the blackjack deck")
|
||||
|
||||
with open("resources/games/deckofCards.txt","r") as f:
|
||||
with open("resources/games/deckOfCards.txt","r") as f:
|
||||
deck = f.read()
|
||||
|
||||
allDecks = deck.split("\n") * decks
|
||||
@ -228,7 +228,7 @@ class Blackjack():
|
||||
else:
|
||||
logMessage = "They tried to hit without being in the game"
|
||||
sendMessage = "You have to enter the game before you can hit"
|
||||
|
||||
|
||||
await ctx.send(sendMessage)
|
||||
self.bot.log(logMessage)
|
||||
|
||||
@ -238,119 +238,155 @@ class Blackjack():
|
||||
await self.blackjackLoop(ctx.channel, game["round"]+1, gameID)
|
||||
|
||||
# When players try to double down
|
||||
def blackjackDouble(self,channel,user,handNumber = 0):
|
||||
async def double(self, ctx, handNumber = 0):
|
||||
try:
|
||||
await ctx.defer()
|
||||
except:
|
||||
self.bot.log("Defer failed")
|
||||
channel = str(ctx.channel_id)
|
||||
user = f"#{ctx.author.id}"
|
||||
roundDone = False
|
||||
|
||||
game = self.bot.database["blackjack games"].find_one({"_id":channel})
|
||||
|
||||
if user in game["user hands"]:
|
||||
hand, handNumber = self.getHandNumber(game["user hands"][user],handNumber)
|
||||
|
||||
if hand != None:
|
||||
if game["round"] > 0:
|
||||
if hand["hit"] == False:
|
||||
if hand["standing"] == False:
|
||||
if len(hand["hand"]) == 2:
|
||||
bet = hand["bet"]
|
||||
if self.bot.money.checkBalance(user) >= bet:
|
||||
self.bot.money.addMoney(user,-1 * bet)
|
||||
|
||||
hand["hand"].append(self.drawCard(channel))
|
||||
hand["hit"] = True
|
||||
hand["doubled"] = True
|
||||
hand["bet"] += bet
|
||||
|
||||
handValue = self.calcHandValue(hand["hand"])
|
||||
|
||||
|
||||
if handValue > 21:
|
||||
hand["busted"] = True
|
||||
|
||||
if handNumber == 2:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".other hand":hand}})
|
||||
elif handNumber == 3:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".third hand":hand}})
|
||||
elif handNumber == 4:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".fourth hand":hand}})
|
||||
else:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user:hand}})
|
||||
|
||||
roundDone = self.isRoundDone(self.bot.database["blackjack games"].find_one({"_id":channel}))
|
||||
|
||||
return "Adding another "+str(bet)+" GwendoBucks to "+self.bot.databaseFuncs.getName(user)+"'s bet and drawing another card.",str(roundDone)[0] + str(game["round"])
|
||||
else:
|
||||
self.bot.log(user+" doesn't have enough GwendoBucks")
|
||||
return "You don't have enough GwendoBucks",""
|
||||
else:
|
||||
self.bot.log(user+" tried to double on round "+str(game["round"]))
|
||||
return "You can only double down on the first round",""
|
||||
else:
|
||||
self.bot.log(user+" is already standing")
|
||||
return "You can't double when you're standing",""
|
||||
else:
|
||||
self.bot.log(user+" has already hit this round")
|
||||
return "You've already hit this round",""
|
||||
else:
|
||||
self.bot.log(user+" tried to double on the 0th round")
|
||||
return "You can't double down before you see your cards",""
|
||||
if hand == None:
|
||||
logMessage = "They didn't specify a hand"
|
||||
sendMessage = "You need to specify a hand"
|
||||
elif game["round"] <= 0:
|
||||
logMessage = "They tried to hit on the 0th round"
|
||||
sendMessage = "You can't hit before you see your cards"
|
||||
elif hand["hit"]:
|
||||
logMessage = "They've already hit this round"
|
||||
sendMessage = "You've already hit this round"
|
||||
elif hand["standing"]:
|
||||
logMessage = "They're already standing"
|
||||
sendMessage = "You can't hit when you're standing"
|
||||
elif len(hand["hand"]) != 2:
|
||||
logMessage = "They tried to double after round 1"
|
||||
sendMessage = "You can only double on the first round"
|
||||
else:
|
||||
self.bot.log(user+" didn't specify a hand")
|
||||
return "You need to specify which hand"
|
||||
bet = hand["bet"]
|
||||
if self.bot.money.checkBalance(user) < bet:
|
||||
logMessage = "They tried to double without being in the game"
|
||||
sendMessage = "You can't double when you're not in the game"
|
||||
else:
|
||||
self.bot.money.addMoney(user,-1 * bet)
|
||||
|
||||
hand["hand"].append(self.drawCard(channel))
|
||||
hand["hit"] = True
|
||||
hand["doubled"] = True
|
||||
hand["bet"] += bet
|
||||
|
||||
handValue = self.calcHandValue(hand["hand"])
|
||||
|
||||
|
||||
if handValue > 21:
|
||||
hand["busted"] = True
|
||||
|
||||
if handNumber == 2:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".other hand":hand}})
|
||||
elif handNumber == 3:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".third hand":hand}})
|
||||
elif handNumber == 4:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".fourth hand":hand}})
|
||||
else:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user:hand}})
|
||||
|
||||
roundDone = self.isRoundDone(self.bot.database["blackjack games"].find_one({"_id":channel}))
|
||||
|
||||
sendMessage = f"Adding another {bet} GwendoBucks to {self.bot.databaseFuncs.getName(user)}'s bet and drawing another card."
|
||||
logMessage = "They succeeded"
|
||||
else:
|
||||
self.bot.log(user+" tried to double without being in the game")
|
||||
return "You can't double when you're not in the game",""
|
||||
logMessage = "They tried to double without being in the game"
|
||||
sendMessage = "You can't double when you're not in the game"
|
||||
|
||||
await ctx.send(sendMessage)
|
||||
self.bot.log(logMessage)
|
||||
|
||||
if roundDone:
|
||||
gameID = game["gameID"]
|
||||
self.bot.log("Double calling self.blackjackLoop()", channel)
|
||||
await self.blackjackLoop(ctx.channel, game["round"]+1, gameID)
|
||||
|
||||
# When players try to stand
|
||||
def blackjackStand(self,channel,user,handNumber = 0):
|
||||
async def stand(self, ctx, handNumber = 0):
|
||||
try:
|
||||
await ctx.defer()
|
||||
except:
|
||||
self.bot.log("Defer failed")
|
||||
channel = str(ctx.channel_id)
|
||||
user = f"#{ctx.author.id}"
|
||||
roundDone = False
|
||||
|
||||
game = self.bot.database["blackjack games"].find_one({"_id":channel})
|
||||
|
||||
if user in game["user hands"]:
|
||||
|
||||
hand, handNumber = self.getHandNumber(game["user hands"][user],handNumber)
|
||||
|
||||
if hand != None:
|
||||
if game["round"] > 0:
|
||||
if hand["hit"] == False:
|
||||
if hand["standing"] == False:
|
||||
hand["standing"] = True
|
||||
|
||||
if handNumber == 2:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".other hand":hand}})
|
||||
elif handNumber == 3:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".third hand":hand}})
|
||||
elif handNumber == 4:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".fourth hand":hand}})
|
||||
else:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user:hand}})
|
||||
|
||||
response = "accept"
|
||||
roundDone = self.isRoundDone(self.bot.database["blackjack games"].find_one({"_id":channel}))
|
||||
|
||||
return response + str(roundDone)[0] + str(game["round"])
|
||||
else:
|
||||
self.bot.log(user+" is already standing")
|
||||
return "You're already standing"
|
||||
else:
|
||||
self.bot.log(user+" has already hit this round")
|
||||
return "You've already hit this round"
|
||||
else:
|
||||
self.bot.log(user+" tried to stand on the first round")
|
||||
return "You can't stand before you see your cards"
|
||||
if hand == None:
|
||||
sendMessage = "You need to specify which hand"
|
||||
logMessage = "They didn't specify a hand"
|
||||
elif game["round"] <= 0:
|
||||
sendMessage = "You can't stand before you see your cards"
|
||||
logMessage = "They tried to stand on round 0"
|
||||
elif hand["hit"]:
|
||||
sendMessage = "You've already hit this round"
|
||||
logMessage = "They'd already hit this round"
|
||||
elif hand["standing"]:
|
||||
sendMessage = "You're already standing"
|
||||
logMessage = "They're already standing"
|
||||
else:
|
||||
self.bot.log(user+" didn't specify a hand")
|
||||
return "You need to specify which hand"
|
||||
hand["standing"] = True
|
||||
|
||||
if handNumber == 2:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".other hand":hand}})
|
||||
elif handNumber == 3:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".third hand":hand}})
|
||||
elif handNumber == 4:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".fourth hand":hand}})
|
||||
else:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user:hand}})
|
||||
|
||||
roundDone = self.isRoundDone(self.bot.database["blackjack games"].find_one({"_id":channel}))
|
||||
|
||||
sendMessage = f"{ctx.author.display_name} is standing"
|
||||
logMessage = "They succeeded"
|
||||
|
||||
else:
|
||||
self.bot.log(user+" tried to stand without being in the game")
|
||||
return "You have to enter the game before you can stand"
|
||||
logMessage = "They tried to stand without being in the game"
|
||||
sendMessage = "You have to enter the game before you can stand"
|
||||
|
||||
await ctx.send(sendMessage)
|
||||
self.bot.log(logMessage)
|
||||
|
||||
if roundDone:
|
||||
gameID = game["gameID"]
|
||||
self.bot.log("Stand calling self.blackjackLoop()", channel)
|
||||
await self.blackjackLoop(ctx.channel, game["round"]+1, gameID)
|
||||
|
||||
# When players try to split
|
||||
def blackjackSplit(self,channel,user,handNumber = 0):
|
||||
async def split(self, ctx, handNumber = 0):
|
||||
try:
|
||||
await ctx.defer()
|
||||
except:
|
||||
self.bot.log("Defer failed")
|
||||
channel = str(ctx.channel_id)
|
||||
user = f"#{ctx.author.id}"
|
||||
roundDone = False
|
||||
handNumberError = False
|
||||
|
||||
game = self.bot.database["blackjack games"].find_one({"_id":channel})
|
||||
|
||||
if game["user hands"][user]["split"] == 0:
|
||||
@ -359,111 +395,115 @@ class Blackjack():
|
||||
handNumber = 0
|
||||
otherHand = 2
|
||||
else:
|
||||
if handNumber != 0:
|
||||
if handNumber == 1:
|
||||
hand = game["user hands"][user]
|
||||
elif handNumber == 2:
|
||||
hand = game["user hands"][user]["other hand"]
|
||||
elif handNumber == 3:
|
||||
hand = game["user hands"][user]["third hand"]
|
||||
else:
|
||||
self.bot.log(user+" tried to hit without specifying which hand")
|
||||
return "You have to specify the hand you're hitting with."
|
||||
|
||||
if game["user hands"][user]["split"] == 1:
|
||||
newHand = game["user hands"][user]["third hand"]
|
||||
otherHand = 3
|
||||
else:
|
||||
newHand = game["user hands"][user]["fourth hand"]
|
||||
otherHand = 4
|
||||
if handNumber == 1:
|
||||
hand = game["user hands"][user]
|
||||
elif handNumber == 2:
|
||||
hand = game["user hands"][user]["other hand"]
|
||||
elif handNumber == 3:
|
||||
hand = game["user hands"][user]["third hand"]
|
||||
else:
|
||||
self.bot.log(user+" tried to split without specifying which hand")
|
||||
return "You have to specify the hand you're splitting.",""
|
||||
handNumberError = True
|
||||
|
||||
if game["user hands"][user]["split"] < 3:
|
||||
if game["round"] != 0:
|
||||
if hand["hit"] == False:
|
||||
if hand["standing"] == False:
|
||||
if len(hand["hand"]) == 2:
|
||||
firstCard = self.calcHandValue([hand["hand"][0]])
|
||||
secondCard = self.calcHandValue([hand["hand"][1]])
|
||||
if firstCard == secondCard:
|
||||
bet = hand["bet"]
|
||||
if self.bot.money.checkBalance(user) >= bet:
|
||||
self.bot.money.addMoney(user,-1 * bet)
|
||||
|
||||
hand["hit"] = True
|
||||
newHand["hit"] = True
|
||||
|
||||
newHand = {
|
||||
"hand":[],"bet":0,"standing":False,"busted":False,
|
||||
"blackjack":False,"hit":True,"doubled":False}
|
||||
|
||||
newHand["bet"] = hand["bet"]
|
||||
|
||||
newHand["hand"].append(hand["hand"].pop(1))
|
||||
newHand["hand"].append(self.drawCard(channel))
|
||||
hand["hand"].append(self.drawCard(channel))
|
||||
|
||||
handValue = self.calcHandValue(hand["hand"])
|
||||
otherHandValue = self.calcHandValue(newHand["hand"])
|
||||
if handValue > 21:
|
||||
hand["busted"] = True
|
||||
elif handValue == 21:
|
||||
hand["blackjack"] = True
|
||||
|
||||
if otherHandValue > 21:
|
||||
newHand["busted"] = True
|
||||
elif otherHandValue == 21:
|
||||
newHand["blackjack"] = True
|
||||
|
||||
if handNumber == 2:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".other hand":hand}})
|
||||
elif handNumber == 3:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".third hand":hand}})
|
||||
else:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user:hand}})
|
||||
|
||||
if otherHand == 3:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".third hand":newHand}})
|
||||
elif otherHand == 4:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".fourth hand":newHand}})
|
||||
else:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".other hand":newHand}})
|
||||
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$inc":{"user hands."+user+".split":1}})
|
||||
|
||||
roundDone = self.isRoundDone(self.bot.database["blackjack games"].find_one({"_id":channel}))
|
||||
|
||||
return "Splitting "+self.bot.databaseFuncs.getName(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(game["round"])
|
||||
else:
|
||||
self.bot.log(user+" doesn't have enough GwendoBucks")
|
||||
return "You don't have enough GwendoBucks",""
|
||||
else:
|
||||
self.bot.log(user+" tried to split 2 different cards")
|
||||
return "Your cards need to have the same value to split",""
|
||||
else:
|
||||
self.bot.log(user+" tried to split later than they could")
|
||||
return "You can only split on the first round",""
|
||||
else:
|
||||
self.bot.log(user+" is already standing")
|
||||
return "You can't split when you're standing",""
|
||||
else:
|
||||
self.bot.log(user+" has already hit this round")
|
||||
return "You've already hit this round",""
|
||||
if game["user hands"][user]["split"] == 1:
|
||||
newHand = game["user hands"][user]["third hand"]
|
||||
otherHand = 3
|
||||
else:
|
||||
self.bot.log(user+" tried to split on the 0th round")
|
||||
return "You can't split before you see your cards",""
|
||||
newHand = game["user hands"][user]["fourth hand"]
|
||||
otherHand = 4
|
||||
|
||||
if handNumberError:
|
||||
logMessage = "They didn't specify a hand"
|
||||
sendMessage = "You have to specify the hand you're hitting with"
|
||||
elif game["round"] == 0:
|
||||
logMessage = "They tried to split on round 0"
|
||||
sendMessage = "You can't split before you see your cards"
|
||||
elif game["user hands"][user]["split"] > 3:
|
||||
logMessage = "They tried to split more than three times"
|
||||
sendMessage = "You can only split 3 times"
|
||||
elif hand["hit"]:
|
||||
logMessage = "They've already hit"
|
||||
sendMessage = "You've already hit"
|
||||
elif hand["standing"]:
|
||||
logMessage = "They're already standing"
|
||||
sendMessage = "You're already standing"
|
||||
elif len(hand["hand"]) != 2:
|
||||
logMessage = "They tried to split after the first round"
|
||||
sendMessage = "You can only split on the first round"
|
||||
else:
|
||||
self.bot.log(user+" tried to split more than three times")
|
||||
return "You can only split 3 times",""
|
||||
firstCard = self.calcHandValue([hand["hand"][0]])
|
||||
secondCard = self.calcHandValue([hand["hand"][1]])
|
||||
if firstCard != secondCard:
|
||||
logMessage = "They tried to split two different cards"
|
||||
sendMessage = "You can only split if your cards have the same value"
|
||||
else:
|
||||
bet = hand["bet"]
|
||||
if self.bot.money.checkBalance(user) < bet:
|
||||
logMessage = "They didn't have enough GwendoBucks"
|
||||
sendMessage = "You don't have enough GwendoBucks"
|
||||
else:
|
||||
self.bot.money.addMoney(user,-1 * bet)
|
||||
|
||||
hand["hit"] = True
|
||||
newHand["hit"] = True
|
||||
|
||||
newHand = {
|
||||
"hand":[],"bet":0,"standing":False,"busted":False,
|
||||
"blackjack":False,"hit":True,"doubled":False}
|
||||
|
||||
newHand["bet"] = hand["bet"]
|
||||
|
||||
newHand["hand"].append(hand["hand"].pop(1))
|
||||
newHand["hand"].append(self.drawCard(channel))
|
||||
hand["hand"].append(self.drawCard(channel))
|
||||
|
||||
handValue = self.calcHandValue(hand["hand"])
|
||||
otherHandValue = self.calcHandValue(newHand["hand"])
|
||||
if handValue > 21:
|
||||
hand["busted"] = True
|
||||
elif handValue == 21:
|
||||
hand["blackjack"] = True
|
||||
|
||||
if otherHandValue > 21:
|
||||
newHand["busted"] = True
|
||||
elif otherHandValue == 21:
|
||||
newHand["blackjack"] = True
|
||||
|
||||
if handNumber == 2:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".other hand":hand}})
|
||||
elif handNumber == 3:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".third hand":hand}})
|
||||
else:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user:hand}})
|
||||
|
||||
if otherHand == 3:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".third hand":newHand}})
|
||||
elif otherHand == 4:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".fourth hand":newHand}})
|
||||
else:
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$set":{"user hands."+user+".other hand":newHand}})
|
||||
|
||||
self.bot.database["blackjack games"].update_one({"_id":channel},
|
||||
{"$inc":{"user hands."+user+".split":1}})
|
||||
|
||||
roundDone = self.isRoundDone(self.bot.database["blackjack games"].find_one({"_id":channel}))
|
||||
|
||||
sendMessage = f"Splitting {self.bot.databaseFuncs.getName(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."
|
||||
logMessage = "They succeeded"
|
||||
|
||||
await ctx.send(sendMessage)
|
||||
self.bot.log(logMessage)
|
||||
|
||||
if roundDone:
|
||||
gameID = game["gameID"]
|
||||
self.bot.log("Stand calling self.blackjackLoop()", channel)
|
||||
await self.blackjackLoop(ctx.channel, game["round"]+1, gameID)
|
||||
|
||||
|
||||
# Player enters the game and draws a hand
|
||||
async def playerDrawHand(self, ctx, bet : int):
|
||||
@ -512,10 +552,10 @@ class Blackjack():
|
||||
"busted":False, "blackjack":blackjackHand, "hit":True,
|
||||
"doubled":False, "split":0, "other hand":{},
|
||||
"third hand":{}, "fourth hand":{}}
|
||||
|
||||
|
||||
function = {"$set":{f"user hands.{user}":newHand}}
|
||||
collection.update_one({"_id":channel}, function)
|
||||
|
||||
|
||||
enterGameText = "entered the game with a bet of"
|
||||
betText = f"{bet} GwendoBucks"
|
||||
sendMessage = f"{userName} {enterGameText} {betText}"
|
||||
@ -775,95 +815,34 @@ class Blackjack():
|
||||
else:
|
||||
await ctx.channel.send(new_message)
|
||||
|
||||
# Standing
|
||||
elif content.startswith("stand"):
|
||||
if content == "hit":
|
||||
response = self.blackjackStand(str(channel),"#"+str(ctx.author.id))
|
||||
else:
|
||||
commands = content.split(" ")
|
||||
try:
|
||||
handNumber = int(commands[1])
|
||||
except:
|
||||
handNumber = 0
|
||||
response = self.blackjackStand(str(channel),"#"+str(ctx.author.id),handNumber)
|
||||
|
||||
if response.startswith("accept"):
|
||||
await ctx.send(f"{ctx.author.display_name} is standing")
|
||||
#try:
|
||||
if response[6] == "T":
|
||||
gameID = self.bot.database["blackjack games"].find_one({"_id":str(channel)})["gameID"]
|
||||
self.bot.log("Stand calling self.blackjackLoop()",str(channel))
|
||||
await self.blackjackLoop(ctx.channel,int(response[7:])+1,gameID)
|
||||
#except:
|
||||
# self.bot.log("Something fucked up (error code 1320)",str(channel))
|
||||
else:
|
||||
await ctx.send(response)
|
||||
|
||||
# Doubling bet
|
||||
elif content.startswith("double"):
|
||||
commands = content.split(" ")
|
||||
try:
|
||||
handNumber = int(commands[1])
|
||||
except:
|
||||
handNumber = 0
|
||||
response, roundDone = self.blackjackDouble(str(channel),"#"+str(ctx.author.id),handNumber)
|
||||
|
||||
await ctx.send(response)
|
||||
|
||||
try:
|
||||
if roundDone[0] == "T":
|
||||
gameID = self.bot.database["blackjack games"].find_one({"_id":str(channel)})["gameID"]
|
||||
self.bot.log("Double calling self.blackjackLoop()",str(channel))
|
||||
await self.blackjackLoop(ctx.channel,int(roundDone[1:])+1,gameID)
|
||||
except:
|
||||
self.bot.log("Something fucked up (error code 1320)",str(channel))
|
||||
|
||||
# Splitting hand
|
||||
elif content.startswith("split"):
|
||||
commands = content.split(" ")
|
||||
try:
|
||||
handNumber = int(commands[1])
|
||||
except:
|
||||
handNumber = 0
|
||||
response, roundDone = self.blackjackSplit(str(channel),"#"+str(ctx.author.id),handNumber)
|
||||
|
||||
await ctx.send(response)
|
||||
|
||||
try:
|
||||
if roundDone[0] == "T":
|
||||
gameID = self.bot.database["blackjack games"].find_one({"_id":str(channel)})["gameID"]
|
||||
self.bot.log("Split calling self.blackjackLoop()",str(channel))
|
||||
await self.blackjackLoop(ctx.channel,int(roundDone[1:])+1,gameID)
|
||||
except:
|
||||
self.bot.log("Something fucked up (error code 1320)")
|
||||
|
||||
# Returning current hi-lo value
|
||||
elif content.startswith("hilo"):
|
||||
data = self.bot.database["hilo"].find_one({"_id":str(channel)})
|
||||
if data != None:
|
||||
hilo = str(data["hilo"])
|
||||
else:
|
||||
hilo = "0"
|
||||
await ctx.send(hilo, hidden=True)
|
||||
|
||||
# Shuffles the blackjack deck
|
||||
elif content.startswith("shuffle"):
|
||||
self.blackjackShuffle(blackjackDecks,str(channel))
|
||||
self.bot.log("Shuffling the blackjack deck...",str(channel))
|
||||
await ctx.send("Shuffling the deck...")
|
||||
|
||||
|
||||
# Tells you the amount of cards left
|
||||
elif content.startswith("cards"):
|
||||
cardsLeft = 0
|
||||
cards = self.bot.database["blackjack cards"].find_one({"_id":str(channel)})
|
||||
if cards != None:
|
||||
cardsLeft = len(cards["cards"])
|
||||
|
||||
decksLeft = round(cardsLeft/52,1)
|
||||
await ctx.send(str(cardsLeft)+" cards, "+str(decksLeft)+" decks", hidden=True)
|
||||
|
||||
# Returning current hi-lo value
|
||||
async def hilo(self, ctx):
|
||||
channel = ctx.channel_id
|
||||
data = self.bot.database["hilo"].find_one({"_id":str(channel)})
|
||||
if data != None:
|
||||
hilo = str(data["hilo"])
|
||||
else:
|
||||
self.bot.log("Not a command (error code 1301)")
|
||||
await ctx.send("I didn't quite understand that (error code 1301)")
|
||||
hilo = "0"
|
||||
await ctx.send(f"Hi-lo value: {hilo}", hidden=True)
|
||||
|
||||
# Shuffles the blackjack deck
|
||||
async def shuffle(self, ctx):
|
||||
blackjackDecks = 4
|
||||
channel = ctx.channel_id
|
||||
self.blackjackShuffle(blackjackDecks,str(channel))
|
||||
self.bot.log("Shuffling the blackjack deck...",str(channel))
|
||||
await ctx.send("Shuffling the deck...")
|
||||
|
||||
|
||||
# Tells you the amount of cards left
|
||||
async def cards(self, ctx):
|
||||
channel = ctx.channel_id
|
||||
cardsLeft = 0
|
||||
cards = self.bot.database["blackjack cards"].find_one({"_id":str(channel)})
|
||||
if cards != None:
|
||||
cardsLeft = len(cards["cards"])
|
||||
|
||||
decksLeft = round(cardsLeft/52,1)
|
||||
await ctx.send(f"Cards left:\n{cardsLeft} cards, {decksLeft} decks", hidden=True)
|
||||
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Kommandoen `/blackjack` starter et spil blackjack. `/blackjack bet [beløb]` lader dig vædde en mængde af dine GwendoBucks. Du bruger `/blackjack hit`, `/blackjack stand`, `/blackjack split` og `/blackjack double` i løbet af spillet.
|
||||
Kommandoen `/blackjack start` starter et spil blackjack. `/blackjack bet [beløb]` lader dig vædde en mængde af dine GwendoBucks. Du bruger `/blackjack hit`, `/blackjack stand`, `/blackjack split` og `/blackjack double` i løbet af spillet.
|
@ -40,6 +40,29 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"blackjackCards" : {
|
||||
"base" : "blackjack",
|
||||
"name" : "cards",
|
||||
"description" : "Get a count of the cards used in blackjack games"
|
||||
},
|
||||
"blackjackDouble" : {
|
||||
"base" : "blackjack",
|
||||
"name" : "double",
|
||||
"description" : "Double your bet in blackjack",
|
||||
"options" : [
|
||||
{
|
||||
"name" : "hand",
|
||||
"description" : "The number of the hand to double your bet on",
|
||||
"type" : 4,
|
||||
"required" : "false"
|
||||
}
|
||||
]
|
||||
},
|
||||
"blackjackHilo" : {
|
||||
"base" : "blackjack",
|
||||
"name" : "hilo",
|
||||
"description" : "Get the current hi-lo value for the cards used in blackjack games"
|
||||
},
|
||||
"blackjackHit" : {
|
||||
"base" : "blackjack",
|
||||
"name" : "hit",
|
||||
@ -53,6 +76,24 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"blackjackShuffle" : {
|
||||
"base" : "blackjack",
|
||||
"name" : "shuffle",
|
||||
"description" : "Shuffle the cards used in blackjack games"
|
||||
},
|
||||
"blackjackSplit" : {
|
||||
"base" : "blackjack",
|
||||
"name" : "split",
|
||||
"description" : "Split your hand in blackjack",
|
||||
"options" : [
|
||||
{
|
||||
"name" : "hand",
|
||||
"description" : "The number of the hand to split, in case you've already split once",
|
||||
"type" : 4,
|
||||
"required" : "false"
|
||||
}
|
||||
]
|
||||
},
|
||||
"blackjackStand" : {
|
||||
"base" : "blackjack",
|
||||
"name" : "stand",
|
||||
|
Reference in New Issue
Block a user