🃏 Created blackjack game

This commit is contained in:
NikolajDanger
2020-07-28 01:58:04 +02:00
parent 5c31877656
commit 3db053be12
69 changed files with 530 additions and 24 deletions

View File

@ -11,6 +11,7 @@ import random
import funcs
funcs.makeFiles()
funcs.shuffle()
# Gets secret bot token
with open("token.txt","r") as f:
@ -53,12 +54,13 @@ async def on_message(message):
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
await message.channel.send("Logging out...")
with open("resources/games.json","r") as f:
with open("resources/games/games.json","r") as f:
data = json.load(f)
data["trivia questions"] = {}
data["blackjack games"] = {}
with open("resources/games.json","w") as f:
with open("resources/games/games.json","w") as f:
json.dump(data,f,indent=4)
await client.logout()
@ -254,11 +256,11 @@ async def on_message(message):
funcs.triviaCountPoints(str(message.channel))
with open("resources/games.json", "r") as f:
with open("resources/games/games.json", "r") as f:
data = json.load(f)
del data["trivia questions"][str(message.channel)]
with open("resources/games.json", "w") as f:
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
funcs.logThis("Time's up for the trivia question in "+str(message.channel))
@ -282,7 +284,11 @@ async def on_message(message):
elif message.content.lower().startswith("!balance"):
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
response = funcs.checkBalance(message.author.name.lower())
await message.channel.send(message.author.name + " has " + str(response) + " GwendoBucks")
if response == 1:
new_message = message.author.name + " has " + str(response) + " GwendoBuck"
else:
new_message = message.author.name + " has " + str(response) + " GwendoBucks"
await message.channel.send(new_message)
#gives money to other player
elif message.content.lower().startswith("!give "):
@ -300,6 +306,75 @@ async def on_message(message):
funcs.logThis("I didn't understand that")
await message.channel.send("I didn't understand that")
elif message.content.lower().startswith("!blackjack"):
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
if message.content.lower() == "!blackjack" or message.content.lower() == "!blackjack ":
new_message = funcs.blackjackStart(str(message.channel))
if new_message == "started":
cardsLeft = 0
with open("resources/games/blackjackCards.txt","r") as f:
for line in f:
cardsLeft += 1
if cardsLeft < 50:
funcs.shuffle()
await message.channel.send("Shuffling the deck...")
new_message = "Blackjack game started. Use \"!blackjack bet [amount]\" to enter the game within the next 30 seconds."
await message.channel.send(new_message)
await message.channel.send(file = discord.File("resources/games/tables/blackjackTable"+str(message.channel)+".png"))
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(message.channel)]["user hands"]) == 0:
gamedone = True
await message.channel.send("No one entered the game. Ending the game.")
while gamedone == False:
new_message, allStanding, gamedone = funcs.blackjackContinue(str(message.channel))
await message.channel.send(new_message)
if gamedone == False:
await message.channel.send(file = discord.File("resources/games/tables/blackjackTable"+str(message.channel)+".png"))
if allStanding:
await asyncio.sleep(5)
else:
await asyncio.sleep(20)
new_message = funcs.blackjackFinish(str(message.channel))
await message.channel.send(new_message)
else:
await message.channel.send(new_message)
if message.content.lower().startswith("!blackjack bet"):
commands = message.content.lower().split(" ")
try:
amount = int(commands[2])
response = funcs.blackjackPlayerDrawHand(str(message.channel),message.author.name,amount)
except:
funcs.logThis("I didn't understand that")
response = "I didn't understand that"
await message.channel.send(response)
if message.content.lower().startswith("!blackjack hit"):
response = funcs.blackjackHit(str(message.channel),message.author.name)
if response == "accept":
await message.add_reaction("👍")
else:
await message.channel.send(response)
if message.content.lower().startswith("!blackjack stand"):
response = funcs.blackjackStand(str(message.channel),message.author.name)
if response == "accept":
await message.add_reaction("👍")
else:
await message.channel.send(response)
# Is a bit sassy sometimes
meanWords = ["stupid", "bitch", "fuck", "dumb", "idiot"]