🥅 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 # Shuffles if not enough cards
if cardsLeft < blackjackMinCards: if cardsLeft < blackjackMinCards:
blackjackShuffle(blackjackDecks,str(message.channel))
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 = "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)
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(" ")
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:
if roundDone[0] == "T":
with open("resources/games/games.json", "r") as f:
gameID = json.load(f)["blackjack games"][str(message.channel)]["id"]
logThis("Double calling blackjackLoop()",str(message.channel))
await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID)
except:
logThis("Something fucked up",str(message.channel))
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)
#try:
if roundDone[0] == "T":
with open("resources/games/games.json", "r") as f:
gameID = json.load(f)["blackjack games"][str(message.channel)]["id"]
logThis("Split calling blackjackLoop()",str(message.channel))
await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID)
#except:
# logThis("Something fucked up")
# await message.channel.send("something fucked up")
# 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)
# Shuffles the blackjack deck
elif content.startswith("blackjack shuffle"):
blackjackShuffle(blackjackDecks,str(message.channel)) blackjackShuffle(blackjackDecks,str(message.channel))
logThis("Shuffling the blackjack deck...",str(message.channel)) logThis("Shuffling the blackjack deck...",str(message.channel))
await message.channel.send("Shuffling the deck...") await message.channel.send("Shuffling the deck...")
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." # Tells you the amount of cards left
await message.channel.send(new_message) elif content.startswith("blackjack cards"):
oldImage = await message.channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(message.channel)+".png")) 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
with open("resources/games/oldImages/blackjack"+str(message.channel), "w") as f: decksLeft = round(cardsLeft/52,1)
f.write(str(oldImage.id)) await message.channel.send(str(cardsLeft)+" cards, "+str(decksLeft)+" decks")
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)
else: else:
await message.channel.send(new_message) logThis("Not a command (error code 1301)")
await message.channel.send("I didn't quite understand that (error code 1301)")
# Entering game and placing bet except:
elif content.startswith("blackjack bet"): logThis("Something went wrong (error code 1300)")
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(" ")
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:
if roundDone[0] == "T":
with open("resources/games/games.json", "r") as f:
gameID = json.load(f)["blackjack games"][str(message.channel)]["id"]
logThis("Double calling blackjackLoop()",str(message.channel))
await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID)
except:
logThis("Something fucked up",str(message.channel))
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)
#try:
if roundDone[0] == "T":
with open("resources/games/games.json", "r") as f:
gameID = json.load(f)["blackjack games"][str(message.channel)]["id"]
logThis("Split calling blackjackLoop()",str(message.channel))
await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID)
#except:
# logThis("Something fucked up")
# await message.channel.send("something fucked up")
# 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)
# Shuffles the blackjack deck
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