🧹 PEP updating

This commit is contained in:
Nikolaj
2021-06-14 21:00:10 +02:00
parent 8f6c8b06be
commit 8c253aca3d
43 changed files with 343 additions and 333 deletions

View File

@ -28,11 +28,11 @@ class HexGame():
await ctx.send("You can't surrender when you're not a player.")
else:
opponent = (players.index(user) + 1) % 2
opponentName = self.bot.databaseFuncs.getName(players[opponent])
opponentName = self.bot.database_funcs.getName(players[opponent])
self.bot.database["hex games"].update_one({"_id":channel},{"$set":{"winner":opponent + 1}})
await ctx.send(f"{ctx.author.display_name} surrendered")
with open(f"resources/games/oldImages/hex{channel}", "r") as f:
with open(f"resources/games/old_images/hex{channel}", "r") as f:
oldImage = await ctx.channel.fetch_message(int(f.read()))
if oldImage is not None:
@ -44,7 +44,7 @@ class HexGame():
filePath = f"resources/games/hexBoards/board{channel}.png"
oldImage = await ctx.channel.send(file = discord.File(filePath))
with open(f"resources/games/oldImages/hex{channel}", "w") as f:
with open(f"resources/games/old_images/hex{channel}", "w") as f:
f.write(str(oldImage.id))
self.bot.database["hex games"].delete_one({"_id":channel})
@ -72,10 +72,10 @@ class HexGame():
opponent = game["players"][::-1][game["turn"]-1]
gwendoTurn = (opponent == f"#{self.bot.user.id}")
opponentName = self.bot.databaseFuncs.getName(opponent)
opponentName = self.bot.database_funcs.getName(opponent)
await ctx.send(f"The color of the players were swapped. It is now {opponentName}'s turn")
with open(f"resources/games/oldImages/hex{channel}", "r") as f:
with open(f"resources/games/old_images/hex{channel}", "r") as f:
oldImage = await ctx.channel.fetch_message(int(f.read()))
if oldImage is not None:
@ -87,7 +87,7 @@ class HexGame():
filePath = f"resources/games/hexBoards/board{channel}.png"
oldImage = await ctx.channel.send(file = discord.File(filePath))
with open(f"resources/games/oldImages/hex{channel}", "w") as f:
with open(f"resources/games/old_images/hex{channel}", "w") as f:
f.write(str(oldImage.id))
if gwendoTurn:
@ -105,7 +105,7 @@ class HexGame():
if game != None:
sendMessage = "There's already a hex game going on in this channel"
logMessage = "There was already a game going on"
log_message = "There was already a game going on"
canStart = False
else:
if type(opponent) == int:
@ -117,7 +117,7 @@ class HexGame():
opponent = f"#{self.bot.user.id}"
else:
sendMessage = "Difficulty doesn't exist"
logMessage = "They tried to play against a difficulty that doesn't exist"
log_message = "They tried to play against a difficulty that doesn't exist"
canStart = False
elif type(opponent) == discord.member.Member:
@ -131,7 +131,7 @@ class HexGame():
opponent = f"#{self.bot.user.id}"
else:
sendMessage = "You can't challenge a bot!"
logMessage = "They tried to challenge a bot"
log_message = "They tried to challenge a bot"
canStart = False
else:
# Opponent is another player
@ -142,11 +142,11 @@ class HexGame():
diffText = ""
else:
sendMessage = "You can't play against yourself"
logMessage = "They tried to play against themself"
log_message = "They tried to play against themself"
canStart = False
else:
canStart = False
logMessage = f"Opponent was neither int or member. It was {type(opponent)}"
log_message = f"Opponent was neither int or member. It was {type(opponent)}"
sendMessage = "Something went wrong"
if canStart:
@ -167,18 +167,18 @@ class HexGame():
gwendoTurn = (players[0] == f"#{self.bot.user.id}")
startedGame = True
turnName = self.bot.databaseFuncs.getName(players[0])
turnName = self.bot.database_funcs.getName(players[0])
sendMessage = f"Started Hex game against {opponentName}{diffText}. It's {turnName}'s turn"
logMessage = "Game started"
log_message = "Game started"
await ctx.send(sendMessage)
self.bot.log(logMessage)
self.bot.log(log_message)
if startedGame:
filePath = f"resources/games/hexBoards/board{ctx.channel_id}.png"
newImage = await ctx.channel.send(file = discord.File(filePath))
with open(f"resources/games/oldImages/hex{ctx.channel_id}", "w") as f:
with open(f"resources/games/old_images/hex{ctx.channel_id}", "w") as f:
f.write(str(newImage.id))
if gwendoTurn:
@ -199,7 +199,7 @@ class HexGame():
else:
players = game["players"]
if user not in players:
sendMessage = f"You can't place when you're not in the game. The game's players are: {self.bot.databaseFuncs.getName(game['players'][0])} and {self.bot.databaseFuncs.getName(game['players'][1])}."
sendMessage = f"You can't place when you're not in the game. The game's players are: {self.bot.database_funcs.getName(game['players'][0])} and {self.bot.database_funcs.getName(game['players'][1])}."
self.bot.log("They aren't in the game")
elif players[game["turn"]-1] != user:
sendMessage = "It's not your turn"
@ -228,12 +228,12 @@ class HexGame():
if winner == 0: # Continue with the game.
gameWon = False
sendMessage = self.bot.databaseFuncs.getName(game["players"][player-1])+" placed at "+position.upper()+". It's now "+self.bot.databaseFuncs.getName(game["players"][turn-1])+"'s turn."# The score is "+str(score)
sendMessage = self.bot.database_funcs.getName(game["players"][player-1])+" placed at "+position.upper()+". It's now "+self.bot.database_funcs.getName(game["players"][turn-1])+"'s turn."# The score is "+str(score)
else: # Congratulations!
gameWon = True
self.bot.database["hex games"].update_one({"_id":channel},{"$set":{"winner":winner}})
sendMessage = self.bot.databaseFuncs.getName(game["players"][player-1])+" placed at "+position.upper()+" and won!"
sendMessage = self.bot.database_funcs.getName(game["players"][player-1])+" placed at "+position.upper()+" and won!"
if game["players"][winner-1] != f"#{self.bot.user.id}":
winAmount = game["difficulty"]*10
sendMessage += " Adding "+str(winAmount)+" GwendoBucks to their account."
@ -258,7 +258,7 @@ class HexGame():
# Update the board
self.draw.drawHexPlacement(channel,player, position)
with open(f"resources/games/oldImages/hex{channel}", "r") as f:
with open(f"resources/games/old_images/hex{channel}", "r") as f:
oldImage = await ctx.channel.fetch_message(int(f.read()))
if oldImage is not None:
@ -281,7 +281,7 @@ class HexGame():
self.bot.database["hex games"].delete_one({"_id":channel})
else:
with open(f"resources/games/oldImages/hex{channel}", "w") as f:
with open(f"resources/games/old_images/hex{channel}", "w") as f:
f.write(str(oldImage.id))
if gwendoTurn:
@ -321,7 +321,7 @@ class HexGame():
sendMessage = "It's not your turn"
else:
turn = game["turn"]
self.bot.log("Undoing {}'s last move".format(self.bot.databaseFuncs.getName(user)))
self.bot.log("Undoing {}'s last move".format(self.bot.database_funcs.getName(user)))
lastMove = game["gameHistory"].pop()
game["board"][lastMove[0]][lastMove[1]] = 0
@ -337,7 +337,7 @@ class HexGame():
await ctx.send(sendMessage)
if undid:
with open(f"resources/games/oldImages/hex{channel}", "r") as f:
with open(f"resources/games/old_images/hex{channel}", "r") as f:
oldImage = await ctx.channel.fetch_message(int(f.read()))
if oldImage is not None:
@ -349,7 +349,7 @@ class HexGame():
filePath = f"resources/games/hexBoards/board{channel}.png"
oldImage = await ctx.channel.send(file = discord.File(filePath))
with open(f"resources/games/oldImages/hex{channel}", "w") as f:
with open(f"resources/games/old_images/hex{channel}", "w") as f:
f.write(str(oldImage.id))
@ -556,7 +556,7 @@ class DrawHex():
game = self.bot.database["hex games"].find_one({"_id":channel})
for p in [1,2]:
playername = self.bot.databaseFuncs.getName(game["players"][p-1])
playername = self.bot.database_funcs.getName(game["players"][p-1])
# Draw name
x = self.XNAME[p]
x -= self.NAMEFONT.getsize(playername)[0] if p==2 else 0 # player2's name is right-aligned
@ -620,7 +620,7 @@ class DrawHex():
# Write player names and color
for p in [1,2]:
playername = self.bot.databaseFuncs.getName(game["players"][p%2])
playername = self.bot.database_funcs.getName(game["players"][p%2])
x = self.XNAME[p]
x -= self.NAMEFONT.getsize(playername)[0] if p==2 else 0 # player2's name is right-aligned