🧹 Moved blacjack function
This commit is contained in:
181
cogs/GamesCog.py
181
cogs/GamesCog.py
@ -1,7 +1,7 @@
|
||||
import discord, asyncio, os, json
|
||||
from discord.ext import commands
|
||||
|
||||
from funcs import logThis, triviaAnswer, triviaCountPoints, triviaStart, deleteGame, checkBalance, giveMoney, blackjackShuffle, blackjackStart, blackjackPlayerDrawHand, blackjackHit, blackjackDouble, blackjackFinish, blackjackSplit, blackjackStand, parseInvest, blackjackLoop, fiar, runMonopoly, runHex, runHangman
|
||||
from funcs import logThis, triviaAnswer, triviaCountPoints, triviaStart, deleteGame, checkBalance, giveMoney, parseBlackjack, parseInvest, fiar, runMonopoly, runHex, runHangman
|
||||
|
||||
class GamesCog(commands.Cog):
|
||||
|
||||
@ -78,184 +78,7 @@ class GamesCog(commands.Cog):
|
||||
# Runs a game of blackjack
|
||||
@commands.command(aliases = ["bj"])
|
||||
async def blackjack(self, ctx, *, content = ""):
|
||||
# Blackjack shuffle variables
|
||||
blackjackMinCards = 50
|
||||
blackjackDecks = 4
|
||||
|
||||
channel = ctx.message.channel.id
|
||||
# Starts the game
|
||||
if content == "":
|
||||
cardsLeft = 0
|
||||
if os.path.exists("resources/games/blackjackCards/"+str(channel)+".txt"):
|
||||
with open("resources/games/blackjackCards/"+str(channel)+".txt","r") as f:
|
||||
for _ in f:
|
||||
cardsLeft += 1
|
||||
|
||||
# Shuffles if not enough cards
|
||||
if cardsLeft < blackjackMinCards:
|
||||
blackjackShuffle(blackjackDecks,str(channel))
|
||||
logThis("Shuffling the blackjack deck...",str(channel))
|
||||
await ctx.send("Shuffling the deck...")
|
||||
|
||||
new_message = 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.send(new_message)
|
||||
oldImage = await ctx.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
|
||||
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
if len(data["blackjack games"][str(channel)]["user hands"]) == 0:
|
||||
gamedone = True
|
||||
await ctx.send("No one entered the game. Ending the game.")
|
||||
gameID = data["blackjack games"][str(channel)]["id"]
|
||||
|
||||
# Loop of game rounds
|
||||
if gamedone == False:
|
||||
logThis("!blackjack calling blackjackLoop()",str(channel))
|
||||
await blackjackLoop(ctx.message.channel,1,gameID)
|
||||
else:
|
||||
new_message = blackjackFinish(str(channel))
|
||||
await ctx.send(new_message)
|
||||
else:
|
||||
await ctx.send(new_message)
|
||||
|
||||
# Entering game and placing bet
|
||||
elif content.startswith("bet"):
|
||||
commands = content.split(" ")
|
||||
amount = int(commands[1])
|
||||
response = blackjackPlayerDrawHand(str(channel),"#"+str(ctx.message.author.id),amount)
|
||||
await ctx.send(response)
|
||||
|
||||
# Hitting
|
||||
elif content.startswith("hit"):
|
||||
if content == "hit":
|
||||
response = blackjackHit(str(channel),"#"+str(ctx.message.author.id))
|
||||
else:
|
||||
commands = content.split(" ")
|
||||
try:
|
||||
handNumber = int(commands[1])
|
||||
except:
|
||||
handNumber = 0
|
||||
response = blackjackHit(str(channel),"#"+str(ctx.message.author.id),handNumber)
|
||||
|
||||
if response.startswith("accept"):
|
||||
await ctx.message.add_reaction("👍")
|
||||
try:
|
||||
if response[6] == "T":
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
gameID = json.load(f)["blackjack games"][str(channel)]["id"]
|
||||
logThis("Hit calling blackjackLoop()",str(channel))
|
||||
await blackjackLoop(ctx.message.channel,int(response[7:])+1,gameID)
|
||||
except:
|
||||
logThis("Something fucked up (error code 1320)",str(channel))
|
||||
else:
|
||||
await ctx.send(response)
|
||||
|
||||
|
||||
# Standing
|
||||
elif content.startswith("stand"):
|
||||
if content == "hit":
|
||||
response = blackjackStand(str(channel),"#"+str(ctx.message.author.id))
|
||||
else:
|
||||
commands = content.split(" ")
|
||||
try:
|
||||
handNumber = int(commands[1])
|
||||
except:
|
||||
handNumber = 0
|
||||
response = blackjackStand(str(channel),"#"+str(ctx.message.author.id),handNumber)
|
||||
|
||||
if response.startswith("accept"):
|
||||
await ctx.message.add_reaction("👍")
|
||||
try:
|
||||
if response[6] == "T":
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
gameID = json.load(f)["blackjack games"][str(channel)]["id"]
|
||||
logThis("Stand calling blackjackLoop()",str(channel))
|
||||
await blackjackLoop(ctx.message.channel,int(response[7:])+1,gameID)
|
||||
except:
|
||||
logThis("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 = blackjackDouble(str(channel),"#"+str(ctx.message.author.id),handNumber)
|
||||
|
||||
await ctx.send(response)
|
||||
|
||||
try:
|
||||
if roundDone[0] == "T":
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
gameID = json.load(f)["blackjack games"][str(channel)]["id"]
|
||||
logThis("Double calling blackjackLoop()",str(channel))
|
||||
await blackjackLoop(ctx.message.channel,int(roundDone[1:])+1,gameID)
|
||||
except:
|
||||
logThis("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 = blackjackSplit(str(channel),"#"+str(ctx.message.author.id),handNumber)
|
||||
|
||||
await ctx.send(response)
|
||||
|
||||
try:
|
||||
if roundDone[0] == "T":
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
gameID = json.load(f)["blackjack games"][str(channel)]["id"]
|
||||
logThis("Split calling blackjackLoop()",str(channel))
|
||||
await blackjackLoop(ctx.message.channel,int(roundDone[1:])+1,gameID)
|
||||
except:
|
||||
logThis("Something fucked up (error code 1320)")
|
||||
|
||||
# Returning current hi-lo value
|
||||
elif content.startswith("hilo") and "#"+str(ctx.message.author.id) == "#266269899859427329":
|
||||
if os.path.exists("resources/games/blackjackCards/"+str(channel)+".txt"):
|
||||
with open("resources/games/hilo/"+str(channel)+".txt", "r") as f:
|
||||
data = f.read()
|
||||
else:
|
||||
data = "0"
|
||||
await ctx.send(data)
|
||||
|
||||
# Shuffles the blackjack deck
|
||||
elif content.startswith("shuffle"):
|
||||
blackjackShuffle(blackjackDecks,str(channel))
|
||||
logThis("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
|
||||
if os.path.exists("resources/games/blackjackCards/"+str(channel)+".txt"):
|
||||
with open("resources/games/blackjackCards/"+str(channel)+".txt","r") as f:
|
||||
for _ in f:
|
||||
cardsLeft += 1
|
||||
|
||||
decksLeft = round(cardsLeft/52,1)
|
||||
await ctx.send(str(cardsLeft)+" cards, "+str(decksLeft)+" decks")
|
||||
|
||||
else:
|
||||
logThis("Not a command (error code 1301)")
|
||||
await ctx.send("I didn't quite understand that (error code 1301)")
|
||||
await parseBlackjack(content,ctx)
|
||||
|
||||
# Runs a game of Connect four
|
||||
@commands.command(aliases = ["fiar","connect4","connectfour","4iar","4inarow"])
|
||||
|
Reference in New Issue
Block a user