🃏 Converted full blackjack functionality to slash commands
This commit is contained in:
@ -504,7 +504,6 @@ class Blackjack():
|
||||
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):
|
||||
try:
|
||||
@ -565,10 +564,31 @@ class Blackjack():
|
||||
await ctx.send(logMessage)
|
||||
|
||||
# Starts a game of blackjack
|
||||
def blackjackStart(self, channel:str):
|
||||
async def start(self, ctx):
|
||||
try:
|
||||
await ctx.defer()
|
||||
except:
|
||||
self.bot.log("Defer failed")
|
||||
channel = str(ctx.channel_id)
|
||||
blackjackMinCards = 50
|
||||
blackjackDecks = 4
|
||||
|
||||
await ctx.send("Starting a new game of blackjack")
|
||||
cardsLeft = 0
|
||||
cards = self.bot.database["blackjack cards"].find_one({"_id":channel})
|
||||
if cards != None:
|
||||
cardsLeft = len(cards["cards"])
|
||||
|
||||
# Shuffles if not enough cards
|
||||
if cardsLeft < blackjackMinCards:
|
||||
self.blackjackShuffle(blackjackDecks, channel)
|
||||
self.bot.log("Shuffling the blackjack deck...", channel)
|
||||
await ctx.channel.send("Shuffling the deck...")
|
||||
|
||||
game = self.bot.database["blackjack games"].find_one({"_id":channel})
|
||||
|
||||
self.bot.log("Trying to start a blackjack game in "+channel)
|
||||
gameStarted = False
|
||||
|
||||
if game == None:
|
||||
|
||||
@ -584,10 +604,39 @@ class Blackjack():
|
||||
|
||||
copyfile("resources/games/blackjackTable.png","resources/games/blackjackTables/blackjackTable"+channel+".png")
|
||||
|
||||
return "started"
|
||||
gameStarted = True
|
||||
|
||||
if gameStarted:
|
||||
sendMessage = "Blackjack game started. Use \"/blackjack bet [amount]\" to enter the game within the next 30 seconds."
|
||||
await ctx.channel.send(sendMessage)
|
||||
filePath = f"resources/games/blackjackTables/blackjackTable{channel}.png"
|
||||
|
||||
oldImage = await ctx.channel.send(file = discord.File(filePath))
|
||||
|
||||
with open("resources/games/oldImages/blackjack"+channel, "w") as f:
|
||||
f.write(str(oldImage.id))
|
||||
|
||||
await asyncio.sleep(30)
|
||||
|
||||
gamedone = False
|
||||
|
||||
game = self.bot.database["blackjack games"].find_one({"_id":str(channel)})
|
||||
|
||||
if len(game["user hands"]) == 0:
|
||||
gamedone = True
|
||||
await ctx.channel.send("No one entered the game. Ending the game.")
|
||||
gameID = game["gameID"]
|
||||
|
||||
# Loop of game rounds
|
||||
if gamedone == False:
|
||||
self.bot.log("start() calling blackjackLoop()", channel)
|
||||
await self.blackjackLoop(ctx.channel,1,gameID)
|
||||
else:
|
||||
new_message = self.blackjackFinish(channel)
|
||||
await ctx.channel.send(new_message)
|
||||
else:
|
||||
self.bot.log("There is already a blackjack game going on in "+channel)
|
||||
return "There's already a blackjack game going on. Try again in a few minutes."
|
||||
await ctx.channel.send("There's already a blackjack game going on. Try again in a few minutes.")
|
||||
self.bot.log("There was already a game going on")
|
||||
|
||||
# Ends the game and calculates winnings
|
||||
def blackjackFinish(self,channel):
|
||||
@ -764,58 +813,7 @@ class Blackjack():
|
||||
else:
|
||||
self.bot.log("Ending loop on round "+str(gameRound),str(channel.id))
|
||||
|
||||
async def parseBlackjack(self, content, ctx):
|
||||
# Blackjack shuffle variables
|
||||
blackjackMinCards = 50
|
||||
blackjackDecks = 4
|
||||
|
||||
channel = ctx.channel_id
|
||||
# Starts the game
|
||||
if content == "":
|
||||
await ctx.send("Starting a new game of blackjack")
|
||||
cardsLeft = 0
|
||||
cards = self.bot.database["blackjack cards"].find_one({"_id":str(channel)})
|
||||
if cards != None:
|
||||
cardsLeft = len(cards["cards"])
|
||||
|
||||
# Shuffles if not enough cards
|
||||
if cardsLeft < blackjackMinCards:
|
||||
self.blackjackShuffle(blackjackDecks,str(channel))
|
||||
self.bot.log("Shuffling the blackjack deck...",str(channel))
|
||||
await ctx.channel.send("Shuffling the deck...")
|
||||
|
||||
new_message = self.blackjackStart(str(channel))
|
||||
if new_message == "started":
|
||||
|
||||
new_message = "Blackjack game started. Use \"/blackjack bet [amount]\" to enter the game within the next 30 seconds."
|
||||
await ctx.channel.send(new_message)
|
||||
oldImage = await ctx.channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(channel)+".png"))
|
||||
|
||||
with open("resources/games/oldImages/blackjack"+str(channel), "w") as f:
|
||||
f.write(str(oldImage.id))
|
||||
|
||||
await asyncio.sleep(30)
|
||||
|
||||
gamedone = False
|
||||
|
||||
game = self.bot.database["blackjack games"].find_one({"_id":str(channel)})
|
||||
|
||||
if len(game["user hands"]) == 0:
|
||||
gamedone = True
|
||||
await ctx.channel.send("No one entered the game. Ending the game.")
|
||||
gameID = game["gameID"]
|
||||
|
||||
# Loop of game rounds
|
||||
if gamedone == False:
|
||||
self.bot.log("/blackjack calling self.blackjackLoop()",str(channel))
|
||||
await self.blackjackLoop(ctx.channel,1,gameID)
|
||||
else:
|
||||
new_message = self.blackjackFinish(str(channel))
|
||||
await ctx.channel.send(new_message)
|
||||
else:
|
||||
await ctx.channel.send(new_message)
|
||||
|
||||
# Returning current hi-lo value
|
||||
# Returning current hi-lo value
|
||||
async def hilo(self, ctx):
|
||||
channel = ctx.channel_id
|
||||
data = self.bot.database["hilo"].find_one({"_id":str(channel)})
|
||||
|
Reference in New Issue
Block a user