✨ Uses channel ID istead of name
This commit is contained in:
98
gameLoops.py
98
gameLoops.py
@ -20,34 +20,34 @@ async def deleteMessage(imageLocation,channel):
|
||||
# Runs Hex
|
||||
async def runHex(channel,command,user):
|
||||
try:
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = parseHex(command,str(channel),user)
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = parseHex(command,str(channel.id),user)
|
||||
except:
|
||||
logThis("Error parsing command (error code 1510)")
|
||||
|
||||
await channel.send(response)
|
||||
logThis(response,str(channel))
|
||||
logThis(response,str(channel.id))
|
||||
if showImage:
|
||||
if deleteImage:
|
||||
try:
|
||||
oldImage = await deleteMessage("hex"+str(channel),channel)
|
||||
oldImage = await deleteMessage("hex"+str(channel.id),channel)
|
||||
except:
|
||||
logThis("Error deleting old image (error code 1501)")
|
||||
oldImage = await channel.send(file = discord.File("resources/games/hexBoards/board"+str(channel)+".png"))
|
||||
oldImage = await channel.send(file = discord.File("resources/games/hexBoards/board"+str(channel.id)+".png"))
|
||||
if not gameDone:
|
||||
if gwendoTurn:
|
||||
try:
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = hexAI(str(channel))
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = hexAI(str(channel.id))
|
||||
except:
|
||||
logThis("AI error (error code 1520)")
|
||||
await channel.send(response)
|
||||
logThis(response,str(channel))
|
||||
logThis(response,str(channel.id))
|
||||
if showImage:
|
||||
if deleteImage:
|
||||
await oldImage.delete()
|
||||
oldImage = await channel.send(file = discord.File("resources/games/hexBoards/board"+str(channel)+".png"))
|
||||
oldImage = await channel.send(file = discord.File("resources/games/hexBoards/board"+str(channel.id)+".png"))
|
||||
|
||||
else:
|
||||
with open("resources/games/oldImages/hex"+str(channel), "w") as f:
|
||||
with open("resources/games/oldImages/hex"+str(channel.id), "w") as f:
|
||||
f.write(str(oldImage.id))
|
||||
|
||||
if gameDone:
|
||||
@ -55,52 +55,52 @@ async def runHex(channel,command,user):
|
||||
data = json.load(f)
|
||||
|
||||
try:
|
||||
with open("resources/games/oldImages/hex"+str(channel), "r") as f:
|
||||
with open("resources/games/oldImages/hex"+str(channel.id), "r") as f:
|
||||
oldImage = await channel.fetch_message(int(f.read()))
|
||||
await oldImage.delete()
|
||||
except:
|
||||
logThis("The old image was already deleted")
|
||||
|
||||
winner = data["hex games"][str(channel)]["winner"]
|
||||
winner = data["hex games"][str(channel.id)]["winner"]
|
||||
if winner != 0:
|
||||
addMoney(data["hex games"][str(channel)]["players"][winner-1].lower(),20)
|
||||
addMoney(data["hex games"][str(channel.id)]["players"][winner-1].lower(),20)
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f) #why is this here?
|
||||
|
||||
deleteGame("hex games",str(channel))
|
||||
deleteGame("hex games",str(channel.id))
|
||||
|
||||
|
||||
|
||||
# Runs Four in a Row
|
||||
async def fiar(channel,command,user):
|
||||
try:
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = parseFourInARow(command,str(channel),user)
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = parseFourInARow(command,str(channel.id),user)
|
||||
except:
|
||||
logThis("Error parsing command (error code 1410)")
|
||||
|
||||
await channel.send(response)
|
||||
logThis(response,str(channel))
|
||||
logThis(response,str(channel.id))
|
||||
if showImage:
|
||||
if deleteImage:
|
||||
try:
|
||||
oldImage = await deleteMessage("fourInARow"+str(channel),channel)
|
||||
oldImage = await deleteMessage("fourInARow"+str(channel.id),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.id)+".png"))
|
||||
if gameDone == False:
|
||||
if gwendoTurn:
|
||||
try:
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = fourInARowAI(str(channel))
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = fourInARowAI(str(channel.id))
|
||||
except:
|
||||
logThis("AI error (error code 1420)")
|
||||
await channel.send(response)
|
||||
logThis(response,str(channel))
|
||||
logThis(response,str(channel.id))
|
||||
if showImage:
|
||||
if deleteImage:
|
||||
await oldImage.delete()
|
||||
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.id)+".png"))
|
||||
if gameDone == False:
|
||||
with open("resources/games/oldImages/fourInARow"+str(channel), "w") as f:
|
||||
with open("resources/games/oldImages/fourInARow"+str(channel.id), "w") as f:
|
||||
f.write(str(oldImage.id))
|
||||
try:
|
||||
reactions = ["1️⃣","2️⃣","3️⃣","4️⃣","5️⃣","6️⃣","7️⃣"]
|
||||
@ -111,7 +111,7 @@ async def fiar(channel,command,user):
|
||||
logThis("Image deleted before I could react to all of them")
|
||||
|
||||
else:
|
||||
with open("resources/games/oldImages/fourInARow"+str(channel), "w") as f:
|
||||
with open("resources/games/oldImages/fourInARow"+str(channel.id), "w") as f:
|
||||
f.write(str(oldImage.id))
|
||||
try:
|
||||
reactions = ["1️⃣","2️⃣","3️⃣","4️⃣","5️⃣","6️⃣","7️⃣"]
|
||||
@ -125,39 +125,39 @@ async def fiar(channel,command,user):
|
||||
data = json.load(f)
|
||||
|
||||
try:
|
||||
with open("resources/games/oldImages/fourInARow"+str(channel), "r") as f:
|
||||
with open("resources/games/oldImages/fourInARow"+str(channel.id), "r") as f:
|
||||
oldImage = await channel.fetch_message(int(f.read()))
|
||||
|
||||
await oldImage.delete()
|
||||
except:
|
||||
logThis("The old image was already deleted")
|
||||
|
||||
winner = data["4 in a row games"][str(channel)]["winner"]
|
||||
difficulty = int(data["4 in a row games"][str(channel)]["difficulty"])
|
||||
winner = data["4 in a row games"][str(channel.id)]["winner"]
|
||||
difficulty = int(data["4 in a row games"][str(channel.id)]["difficulty"])
|
||||
reward = difficulty**2 + 5
|
||||
if winner != 0:
|
||||
if data["4 in a row games"][str(channel)]["players"][winner-1].lower() != "gwendolyn":
|
||||
addMoney(data["4 in a row games"][str(channel)]["players"][winner-1].lower(),reward)
|
||||
if data["4 in a row games"][str(channel.id)]["players"][winner-1].lower() != "gwendolyn":
|
||||
addMoney(data["4 in a row games"][str(channel.id)]["players"][winner-1].lower(),reward)
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f) #why is this here?
|
||||
|
||||
deleteGame("4 in a row games",str(channel))
|
||||
deleteGame("4 in a row games",str(channel.id))
|
||||
|
||||
# Loop of blackjack game rounds
|
||||
async def blackjackLoop(channel,gameRound,gameID):
|
||||
logThis("Loop "+str(gameRound),str(channel))
|
||||
logThis("Loop "+str(gameRound),str(channel.id))
|
||||
|
||||
with open("resources/games/oldImages/blackjack"+str(channel), "r") as f:
|
||||
with open("resources/games/oldImages/blackjack"+str(channel.id), "r") as f:
|
||||
oldImage = await channel.fetch_message(int(f.read()))
|
||||
|
||||
new_message, allStanding, gamedone = blackjackContinue(str(channel))
|
||||
new_message, allStanding, gamedone = blackjackContinue(str(channel.id))
|
||||
if new_message != "":
|
||||
logThis(new_message,str(channel))
|
||||
logThis(new_message,str(channel.id))
|
||||
await channel.send(new_message)
|
||||
if gamedone == False:
|
||||
await oldImage.delete()
|
||||
oldImage = await channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(channel)+".png"))
|
||||
with open("resources/games/oldImages/blackjack"+str(channel), "w") as f:
|
||||
oldImage = await channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(channel.id)+".png"))
|
||||
with open("resources/games/oldImages/blackjack"+str(channel.id), "w") as f:
|
||||
f.write(str(oldImage.id))
|
||||
|
||||
try:
|
||||
@ -171,41 +171,41 @@ async def blackjackLoop(channel,gameRound,gameID):
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
if str(channel) in data["blackjack games"]:
|
||||
realRound = data["blackjack games"][str(channel)]["round"]
|
||||
realGameID = data["blackjack games"][str(channel)]["id"]
|
||||
if str(channel.id) in data["blackjack games"]:
|
||||
realRound = data["blackjack games"][str(channel.id)]["round"]
|
||||
realGameID = data["blackjack games"][str(channel.id)]["id"]
|
||||
|
||||
if gameRound == realRound and realGameID == gameID:
|
||||
if gamedone == False:
|
||||
logThis("Loop "+str(gameRound)+" calling blackjackLoop()",str(channel))
|
||||
logThis("Loop "+str(gameRound)+" calling blackjackLoop()",str(channel.id))
|
||||
await blackjackLoop(channel,gameRound+1,gameID)
|
||||
else:
|
||||
try:
|
||||
new_message = blackjackFinish(str(channel))
|
||||
new_message = blackjackFinish(str(channel.id))
|
||||
except:
|
||||
logThis("Something fucked up (error code 1310)")
|
||||
await channel.send(new_message)
|
||||
else:
|
||||
logThis("Ending loop on round "+str(gameRound),str(channel))
|
||||
logThis("Ending loop on round "+str(gameRound),str(channel.id))
|
||||
else:
|
||||
logThis("Ending loop on round "+str(gameRound),str(channel))
|
||||
logThis("Ending loop on round "+str(gameRound),str(channel.id))
|
||||
|
||||
async def runMonopoly(channel, command, user):
|
||||
try:
|
||||
response, showImage, deleteImage, gameStarted, gameContinue = parseMonopoly(command,str(channel),user)
|
||||
response, showImage, deleteImage, gameStarted, gameContinue = parseMonopoly(command,str(channel.id),user)
|
||||
except:
|
||||
logThis("Error parsing command (error code 1610)")
|
||||
if response != "":
|
||||
await channel.send(response)
|
||||
logThis(response,str(channel))
|
||||
logThis(response,str(channel.id))
|
||||
if showImage:
|
||||
if deleteImage:
|
||||
try:
|
||||
oldImage = await deleteMessage("monopoly"+str(channel),channel)
|
||||
oldImage = await deleteMessage("monopoly"+str(channel.id),channel)
|
||||
except:
|
||||
logThis("Error deleting message (error code 1601)")
|
||||
oldImage = await channel.send(file = discord.File("resources/games/monopolyBoards/monopolyBoard"+str(channel)+".png"))
|
||||
with open("resources/games/oldImages/monopoly"+str(channel), "w") as f:
|
||||
oldImage = await channel.send(file = discord.File("resources/games/monopolyBoards/monopolyBoard"+str(channel.id)+".png"))
|
||||
with open("resources/games/oldImages/monopoly"+str(channel.id), "w") as f:
|
||||
f.write(str(oldImage.id))
|
||||
|
||||
if gameContinue:
|
||||
@ -213,17 +213,17 @@ async def runMonopoly(channel, command, user):
|
||||
await asyncio.sleep(60)
|
||||
else:
|
||||
await asyncio.sleep(5)
|
||||
response, showImage, deleteImage, gameDone = monopolyContinue(str(channel))
|
||||
response, showImage, deleteImage, gameDone = monopolyContinue(str(channel.id))
|
||||
em = discord.Embed(description=response,colour = 0x59f442)
|
||||
await channel.send(embed=em)
|
||||
if showImage:
|
||||
if deleteImage:
|
||||
try:
|
||||
oldImage = await deleteMessage("monopoly"+str(channel),channel)
|
||||
oldImage = await deleteMessage("monopoly"+str(channel.id),channel)
|
||||
except:
|
||||
logThis("Error deleting message (error code 1601)")
|
||||
oldImage = await channel.send(file = discord.File("resources/games/monopolyBoards/monopolyBoard"+str(channel)+".png"))
|
||||
with open("resources/games/oldImages/monopoly"+str(channel), "w") as f:
|
||||
oldImage = await channel.send(file = discord.File("resources/games/monopolyBoards/monopolyBoard"+str(channel.id)+".png"))
|
||||
with open("resources/games/oldImages/monopoly"+str(channel.id), "w") as f:
|
||||
f.write(str(oldImage.id))
|
||||
if gameDone == False:
|
||||
try:
|
||||
|
Reference in New Issue
Block a user