🥅 More error codes

This commit is contained in:
NikolajDanger
2020-08-02 13:22:49 +02:00
parent 04b5d55414
commit 4aaa19472f
2 changed files with 175 additions and 156 deletions

View File

@ -23,17 +23,26 @@ meanWords = ["stupid", "bitch", "fuck", "dumb", "idiot"]
# Runs Four in a Row # Runs Four in a Row
async def fiar(channel,command,user): async def fiar(channel,command,user):
response, showImage, deleteImage, gameDone, gwendoTurn = parseFourInARow(command,str(channel),user) try:
response, showImage, deleteImage, gameDone, gwendoTurn = parseFourInARow(command,str(channel),user)
except:
logThis("Error parsing command (error code 1410)")
await channel.send(response) await channel.send(response)
logThis(response,str(channel)) logThis(response,str(channel))
if showImage: if showImage:
if deleteImage: if deleteImage:
oldImage = await deleteMessage("fourInARow"+str(channel),channel) try:
oldImage = await deleteMessage("fourInARow"+str(channel),channel)
except:
logThis("Error deleting message (error code 1401)")
oldImage = await channel.send(file = discord.File("resources/games/4InARowBoards/board"+str(channel)+".png")) oldImage = await channel.send(file = discord.File("resources/games/4InARowBoards/board"+str(channel)+".png"))
if gameDone == False: if gameDone == False:
if gwendoTurn: if gwendoTurn:
await asyncio.sleep(1) try:
response, showImage, deleteImage, gameDone, gwendoTurn = fourInARowAI(str(channel)) response, showImage, deleteImage, gameDone, gwendoTurn = fourInARowAI(str(channel))
except:
logThis("AI error (error code 1420)")
await channel.send(response) await channel.send(response)
logThis(response,str(channel)) logThis(response,str(channel))
if showImage: if showImage:
@ -501,187 +510,194 @@ async def parseCommands(message,content):
# Runs a game of Blackjack # Runs a game of Blackjack
elif content.startswith("blackjack"): elif content.startswith("blackjack"):
# Starts the game try:
if content == "blackjack" or content == "blackjack ": # Starts the game
cardsLeft = 0 if content == "blackjack" or content == "blackjack ":
if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"): cardsLeft = 0
with open("resources/games/blackjackCards/"+str(message.channel)+".txt","r") as f: if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"):
for _ in f: with open("resources/games/blackjackCards/"+str(message.channel)+".txt","r") as f:
cardsLeft += 1 for _ in f:
cardsLeft += 1
# Shuffles if not enough cards
if cardsLeft < blackjackMinCards: # Shuffles if not enough cards
blackjackShuffle(blackjackDecks,str(message.channel)) if cardsLeft < blackjackMinCards:
logThis("Shuffling the blackjack deck...",str(message.channel)) blackjackShuffle(blackjackDecks,str(message.channel))
await message.channel.send("Shuffling the deck...") logThis("Shuffling the blackjack deck...",str(message.channel))
await message.channel.send("Shuffling the deck...")
new_message = blackjackStart(str(message.channel))
if new_message == "started": new_message = blackjackStart(str(message.channel))
if new_message == "started":
new_message = "Blackjack game started. Use \""+commandPrefix+"blackjack bet [amount]\" to enter the game within the next 30 seconds." new_message = "Blackjack game started. Use \""+commandPrefix+"blackjack bet [amount]\" to enter the game within the next 30 seconds."
await message.channel.send(new_message)
oldImage = await message.channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(message.channel)+".png"))
with open("resources/games/oldImages/blackjack"+str(message.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(message.channel)]["user hands"]) == 0:
gamedone = True
await message.channel.send("No one entered the game. Ending the game.")
gameID = data["blackjack games"][str(message.channel)]["id"]
# Loop of game rounds
if gamedone == False:
logThis("!blackjack calling blackjackLoop()",str(message.channel))
await blackjackLoop(message.channel,1,gameID)
else:
new_message = blackjackFinish(str(message.channel))
await message.channel.send(new_message) await message.channel.send(new_message)
else: oldImage = await message.channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(message.channel)+".png"))
await message.channel.send(new_message)
# Entering game and placing bet with open("resources/games/oldImages/blackjack"+str(message.channel), "w") as f:
elif content.startswith("blackjack bet"): f.write(str(oldImage.id))
commands = content.split(" ")
try: await asyncio.sleep(30)
amount = int(commands[2])
except: gamedone = False
logThis("I didn't understand that",str(message.channel))
response = "I didn't understand that" with open("resources/games/games.json", "r") as f:
else: data = json.load(f)
response = blackjackPlayerDrawHand(str(message.channel),message.author.display_name,amount) if len(data["blackjack games"][str(message.channel)]["user hands"]) == 0:
await message.channel.send(response) gamedone = True
await message.channel.send("No one entered the game. Ending the game.")
# Hitting gameID = data["blackjack games"][str(message.channel)]["id"]
elif content.startswith("blackjack hit"):
if content == "blackjack hit" or content == "blackjack hit ": # Loop of game rounds
response = blackjackHit(str(message.channel),message.author.display_name) if gamedone == False:
else: logThis("!blackjack calling blackjackLoop()",str(message.channel))
await blackjackLoop(message.channel,1,gameID)
else:
new_message = blackjackFinish(str(message.channel))
await message.channel.send(new_message)
else:
await message.channel.send(new_message)
# Entering game and placing bet
elif content.startswith("blackjack bet"):
commands = content.split(" ")
try:
amount = int(commands[2])
except:
logThis("I didn't understand that",str(message.channel))
response = "I didn't understand that"
else:
response = blackjackPlayerDrawHand(str(message.channel),message.author.display_name,amount)
await message.channel.send(response)
# Hitting
elif content.startswith("blackjack hit"):
if content == "blackjack hit" or content == "blackjack hit ":
response = blackjackHit(str(message.channel),message.author.display_name)
else:
commands = content.split(" ")
try:
handNumber = int(commands[2])
except:
handNumber = 0
response = blackjackHit(str(message.channel),message.author.display_name,handNumber)
if response.startswith("accept"):
await message.add_reaction("👍")
try:
if response[6] == "T":
with open("resources/games/games.json", "r") as f:
gameID = json.load(f)["blackjack games"][str(message.channel)]["id"]
logThis("Hit calling blackjackLoop()",str(message.channel))
await blackjackLoop(message.channel,int(response[7:])+1,gameID)
except:
logThis("Something fucked up")
await message.channel.send("something fucked up",str(message.channel))
else:
await message.channel.send(response)
# Standing
elif content.startswith("blackjack stand"):
if content == "blackjack hit" or content == "blackjack hit ":
response = blackjackStand(str(message.channel),message.author.display_name)
else:
commands = content.split(" ")
try:
handNumber = int(commands[2])
except:
handNumber = 0
response = blackjackStand(str(message.channel),message.author.display_name,handNumber)
if response.startswith("accept"):
await message.add_reaction("👍")
try:
if response[6] == "T":
with open("resources/games/games.json", "r") as f:
gameID = json.load(f)["blackjack games"][str(message.channel)]["id"]
logThis("Stand calling blackjackLoop()",str(message.channel))
await blackjackLoop(message.channel,int(response[7:])+1,gameID)
except:
logThis("Something fucked up",str(message.channel))
await message.channel.send("something fucked up")
else:
await message.channel.send(response)
# Doubling bet
elif content.startswith("blackjack double"):
commands = content.split(" ") commands = content.split(" ")
try: try:
handNumber = int(commands[2]) handNumber = int(commands[2])
except: except:
handNumber = 0 handNumber = 0
response = blackjackHit(str(message.channel),message.author.display_name,handNumber) response, roundDone = blackjackDouble(str(message.channel),message.author.display_name,handNumber)
if response.startswith("accept"):
await message.add_reaction("👍")
try:
if response[6] == "T":
with open("resources/games/games.json", "r") as f:
gameID = json.load(f)["blackjack games"][str(message.channel)]["id"]
logThis("Hit calling blackjackLoop()",str(message.channel))
await blackjackLoop(message.channel,int(response[7:])+1,gameID)
except:
logThis("Something fucked up")
await message.channel.send("something fucked up",str(message.channel))
else:
await message.channel.send(response) await message.channel.send(response)
# Standing
elif content.startswith("blackjack stand"):
if content == "blackjack hit" or content == "blackjack hit ":
response = blackjackStand(str(message.channel),message.author.display_name)
else:
commands = content.split(" ")
try: try:
handNumber = int(commands[2]) if roundDone[0] == "T":
except:
handNumber = 0
response = blackjackStand(str(message.channel),message.author.display_name,handNumber)
if response.startswith("accept"):
await message.add_reaction("👍")
try:
if response[6] == "T":
with open("resources/games/games.json", "r") as f: with open("resources/games/games.json", "r") as f:
gameID = json.load(f)["blackjack games"][str(message.channel)]["id"] gameID = json.load(f)["blackjack games"][str(message.channel)]["id"]
logThis("Stand calling blackjackLoop()",str(message.channel)) logThis("Double calling blackjackLoop()",str(message.channel))
await blackjackLoop(message.channel,int(response[7:])+1,gameID) await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID)
except: except:
logThis("Something fucked up",str(message.channel)) logThis("Something fucked up",str(message.channel))
await message.channel.send("something fucked up") await message.channel.send("something fucked up")
else:
# Splitting hand
elif content.startswith("blackjack split"):
response, roundDone = blackjackSplit(str(message.channel),message.author.display_name)
await message.channel.send(response) await message.channel.send(response)
# Doubling bet
elif content.startswith("blackjack double"):
commands = content.split(" ")
try:
handNumber = int(commands[2])
except:
handNumber = 0
response, roundDone = blackjackDouble(str(message.channel),message.author.display_name,handNumber)
await message.channel.send(response) #try:
try:
if roundDone[0] == "T": if roundDone[0] == "T":
with open("resources/games/games.json", "r") as f: with open("resources/games/games.json", "r") as f:
gameID = json.load(f)["blackjack games"][str(message.channel)]["id"] gameID = json.load(f)["blackjack games"][str(message.channel)]["id"]
logThis("Double calling blackjackLoop()",str(message.channel)) logThis("Split calling blackjackLoop()",str(message.channel))
await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID) await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID)
except: #except:
logThis("Something fucked up",str(message.channel)) # logThis("Something fucked up")
await message.channel.send("something fucked up") # await message.channel.send("something fucked up")
# Splitting hand
elif content.startswith("blackjack split"):
response, roundDone = blackjackSplit(str(message.channel),message.author.display_name)
await message.channel.send(response) # Returning current hi-lo value
elif content.startswith("blackjack hilo") and message.author.display_name == "Nikolaj":
if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"):
with open("resources/games/hilo/"+str(message.channel)+".txt", "r") as f:
data = f.read()
else:
data = "0"
await message.channel.send(data)
#try: # Shuffles the blackjack deck
if roundDone[0] == "T": elif content.startswith("blackjack shuffle"):
with open("resources/games/games.json", "r") as f: blackjackShuffle(blackjackDecks,str(message.channel))
gameID = json.load(f)["blackjack games"][str(message.channel)]["id"] logThis("Shuffling the blackjack deck...",str(message.channel))
logThis("Split calling blackjackLoop()",str(message.channel)) await message.channel.send("Shuffling the deck...")
await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID)
#except:
# logThis("Something fucked up") # Tells you the amount of cards left
# await message.channel.send("something fucked up") elif content.startswith("blackjack cards"):
cardsLeft = 0
if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"):
with open("resources/games/blackjackCards/"+str(message.channel)+".txt","r") as f:
for _ in f:
cardsLeft += 1
decksLeft = round(cardsLeft/52,1)
await message.channel.send(str(cardsLeft)+" cards, "+str(decksLeft)+" decks")
# Returning current hi-lo value
elif content.startswith("blackjack hilo") and message.author.display_name == "Nikolaj":
if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"):
with open("resources/games/hilo/"+str(message.channel)+".txt", "r") as f:
data = f.read()
else: else:
data = "0" logThis("Not a command (error code 1301)")
await message.channel.send(data) await message.channel.send("I didn't quite understand that (error code 1301)")
except:
# Shuffles the blackjack deck logThis("Something went wrong (error code 1300)")
elif content.startswith("blackjack shuffle"):
blackjackShuffle(blackjackDecks,str(message.channel))
logThis("Shuffling the blackjack deck...",str(message.channel))
await message.channel.send("Shuffling the deck...")
# Tells you the amount of cards left
elif content.startswith("blackjack cards"):
cardsLeft = 0
if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"):
with open("resources/games/blackjackCards/"+str(message.channel)+".txt","r") as f:
for _ in f:
cardsLeft += 1
decksLeft = round(cardsLeft/52,1)
await message.channel.send(str(cardsLeft)+" cards, "+str(decksLeft)+" decks")
else:
await message.channel.send("I didn't quite understand that")
# Runs a game of four in a row # Runs a game of four in a row
elif content.startswith("fourinarow"): elif content.startswith("fourinarow"):
command = content.replace("fourinarow","") try:
await fiar(message.channel,command,message.author.display_name) command = content.replace("fourinarow","")
await fiar(message.channel,command,message.author.display_name)
except:
logThis("Something went wrong (error code 1400)")

View File

@ -87,4 +87,7 @@
1300 - Unspecified 1300 - Unspecified
14 - Four in a row 14 - Four in a row
600 - Unspecified 1400 - Unspecified
1401 - Error deleting old image
1410 - Unspecified parsing error
1420 - Unspecified AI error