🧹 PEP updating
This commit is contained in:
@ -3,4 +3,4 @@
|
||||
__all__ = ["Money", "Games"]
|
||||
|
||||
from .money import Money
|
||||
from .gamesContainer import Games
|
||||
from .games_container import Games
|
||||
|
@ -211,7 +211,7 @@ class Blackjack():
|
||||
|
||||
allStanding = True
|
||||
preAllStanding = True
|
||||
message = self.bot.longStrings["Blackjack all players standing"]
|
||||
message = self.bot.long_strings["Blackjack all players standing"]
|
||||
|
||||
if game["all standing"]:
|
||||
self.bot.log("All are standing")
|
||||
@ -245,11 +245,11 @@ class Blackjack():
|
||||
return "", True, done
|
||||
else:
|
||||
if game["round"] == 0:
|
||||
firstRoundMsg = self.bot.longStrings["Blackjack first round"]
|
||||
firstRoundMsg = self.bot.long_strings["Blackjack first round"]
|
||||
else:
|
||||
firstRoundMsg = ""
|
||||
|
||||
sendMessage = self.bot.longStrings["Blackjack commands"]
|
||||
sendMessage = self.bot.long_strings["Blackjack commands"]
|
||||
print(firstRoundMsg)
|
||||
sendMessage = sendMessage.format(firstRoundMsg)
|
||||
return sendMessage, False, done
|
||||
@ -352,7 +352,7 @@ class Blackjack():
|
||||
winningCalc = (self._calcWinnings(*_calcWinningsParams))
|
||||
winnings, netWinnings, reason = winningCalc
|
||||
|
||||
userName = self.bot.databaseFuncs.getName(user)
|
||||
userName = self.bot.database_funcs.getName(user)
|
||||
|
||||
if winnings < 0:
|
||||
if winnings == -1:
|
||||
@ -569,7 +569,7 @@ class Blackjack():
|
||||
"""
|
||||
self.bot.log("Loop "+str(gameRound), str(channel.id))
|
||||
|
||||
oldImagePath = f"resources/games/oldImages/blackjack{channel.id}"
|
||||
oldImagePath = f"resources/games/old_images/blackjack{channel.id}"
|
||||
with open(oldImagePath, "r") as f:
|
||||
oldImage = await channel.fetch_message(int(f.read()))
|
||||
|
||||
@ -604,15 +604,15 @@ class Blackjack():
|
||||
|
||||
if rightRound:
|
||||
if not gamedone:
|
||||
logMessage = f"Loop {gameRound} calling self._blackjackLoop()"
|
||||
self.bot.log(logMessage, str(channel.id))
|
||||
log_message = f"Loop {gameRound} calling self._blackjackLoop()"
|
||||
self.bot.log(log_message, str(channel.id))
|
||||
await self._blackjackLoop(channel, gameRound+1, gameID)
|
||||
else:
|
||||
new_message = self._blackjackFinish(str(channel.id))
|
||||
await channel.send(new_message)
|
||||
else:
|
||||
logMessage = f"Ending loop on round {gameRound}"
|
||||
self.bot.log(logMessage, str(channel.id))
|
||||
log_message = f"Ending loop on round {gameRound}"
|
||||
self.bot.log(log_message, str(channel.id))
|
||||
|
||||
async def hit(self, ctx: discord_slash.context.SlashContext,
|
||||
handNumber: int = 0):
|
||||
@ -640,16 +640,16 @@ class Blackjack():
|
||||
hand, handNumber = self._getHandNumber(userHands, handNumber)
|
||||
|
||||
if hand is None:
|
||||
logMessage = "They didn't specify a hand"
|
||||
log_message = "They didn't specify a hand"
|
||||
sendMessage = "You need to specify a hand"
|
||||
elif game["round"] <= 0:
|
||||
logMessage = "They tried to hit on the 0th round"
|
||||
log_message = "They tried to hit on the 0th round"
|
||||
sendMessage = "You can't hit before you see your cards"
|
||||
elif hand["hit"]:
|
||||
logMessage = "They've already hit this round"
|
||||
log_message = "They've already hit this round"
|
||||
sendMessage = "You've already hit this round"
|
||||
elif hand["standing"]:
|
||||
logMessage = "They're already standing"
|
||||
log_message = "They're already standing"
|
||||
sendMessage = "You can't hit when you're standing"
|
||||
else:
|
||||
hand["hand"].append(self._drawCard(channel))
|
||||
@ -675,13 +675,13 @@ class Blackjack():
|
||||
roundDone = self._isRoundDone(game)
|
||||
|
||||
sendMessage = f"{ctx.author.display_name} hit"
|
||||
logMessage = "They succeeded"
|
||||
log_message = "They succeeded"
|
||||
else:
|
||||
logMessage = "They tried to hit without being in the game"
|
||||
log_message = "They tried to hit without being in the game"
|
||||
sendMessage = "You have to enter the game before you can hit"
|
||||
|
||||
await ctx.send(sendMessage)
|
||||
self.bot.log(logMessage)
|
||||
self.bot.log(log_message)
|
||||
|
||||
if roundDone:
|
||||
gameID = game["gameID"]
|
||||
@ -713,22 +713,22 @@ class Blackjack():
|
||||
hand, handNumber = self._getHandNumber(*handParams)
|
||||
|
||||
if hand is None:
|
||||
logMessage = "They didn't specify a hand"
|
||||
log_message = "They didn't specify a hand"
|
||||
sendMessage = "You need to specify a hand"
|
||||
elif game["round"] <= 0:
|
||||
logMessage = "They tried to hit on the 0th round"
|
||||
log_message = "They tried to hit on the 0th round"
|
||||
sendMessage = "You can't hit before you see your cards"
|
||||
elif hand["hit"]:
|
||||
logMessage = "They've already hit this round"
|
||||
log_message = "They've already hit this round"
|
||||
sendMessage = "You've already hit this round"
|
||||
elif hand["standing"]:
|
||||
logMessage = "They're already standing"
|
||||
log_message = "They're already standing"
|
||||
sendMessage = "You can't hit when you're standing"
|
||||
elif len(hand["hand"]) != 2:
|
||||
logMessage = "They tried to double after round 1"
|
||||
log_message = "They tried to double after round 1"
|
||||
sendMessage = "You can only double on the first round"
|
||||
elif self.bot.money.checkBalance(user) < hand["bet"]:
|
||||
logMessage = "They tried to double without being in the game"
|
||||
log_message = "They tried to double without being in the game"
|
||||
sendMessage = "You can't double when you're not in the game"
|
||||
else:
|
||||
bet = hand["bet"]
|
||||
@ -759,16 +759,16 @@ class Blackjack():
|
||||
game = blackjackGames.find_one({"_id": channel})
|
||||
roundDone = self._isRoundDone(game)
|
||||
|
||||
sendMessage = self.bot.longStrings["Blackjack double"]
|
||||
userName = self.bot.databaseFuncs.getName(user)
|
||||
sendMessage = self.bot.long_strings["Blackjack double"]
|
||||
userName = self.bot.database_funcs.getName(user)
|
||||
sendMessage = sendMessage.format(bet, userName)
|
||||
logMessage = "They succeeded"
|
||||
log_message = "They succeeded"
|
||||
else:
|
||||
logMessage = "They tried to double without being in the game"
|
||||
log_message = "They tried to double without being in the game"
|
||||
sendMessage = "You can't double when you're not in the game"
|
||||
|
||||
await ctx.send(sendMessage)
|
||||
self.bot.log(logMessage)
|
||||
self.bot.log(log_message)
|
||||
|
||||
if roundDone:
|
||||
gameID = game["gameID"]
|
||||
@ -801,16 +801,16 @@ class Blackjack():
|
||||
|
||||
if hand is None:
|
||||
sendMessage = "You need to specify which hand"
|
||||
logMessage = "They didn't specify a hand"
|
||||
log_message = "They didn't specify a hand"
|
||||
elif game["round"] <= 0:
|
||||
sendMessage = "You can't stand before you see your cards"
|
||||
logMessage = "They tried to stand on round 0"
|
||||
log_message = "They tried to stand on round 0"
|
||||
elif hand["hit"]:
|
||||
sendMessage = "You've already hit this round"
|
||||
logMessage = "They'd already hit this round"
|
||||
log_message = "They'd already hit this round"
|
||||
elif hand["standing"]:
|
||||
sendMessage = "You're already standing"
|
||||
logMessage = "They're already standing"
|
||||
log_message = "They're already standing"
|
||||
else:
|
||||
hand["standing"] = True
|
||||
|
||||
@ -829,14 +829,14 @@ class Blackjack():
|
||||
roundDone = self._isRoundDone(game)
|
||||
|
||||
sendMessage = f"{ctx.author.display_name} is standing"
|
||||
logMessage = "They succeeded"
|
||||
log_message = "They succeeded"
|
||||
|
||||
else:
|
||||
logMessage = "They tried to stand without being in the game"
|
||||
log_message = "They tried to stand without being in the game"
|
||||
sendMessage = "You have to enter the game before you can stand"
|
||||
|
||||
await ctx.send(sendMessage)
|
||||
self.bot.log(logMessage)
|
||||
self.bot.log(log_message)
|
||||
|
||||
if roundDone:
|
||||
gameID = game["gameID"]
|
||||
@ -887,33 +887,33 @@ class Blackjack():
|
||||
otherHand = 4
|
||||
|
||||
if handNumberError:
|
||||
logMessage = "They didn't specify a hand"
|
||||
log_message = "They didn't specify a hand"
|
||||
sendMessage = "You have to specify the hand you're hitting with"
|
||||
elif game["round"] == 0:
|
||||
logMessage = "They tried to split on round 0"
|
||||
log_message = "They tried to split on round 0"
|
||||
sendMessage = "You can't split before you see your cards"
|
||||
elif game["user hands"][user]["split"] > 3:
|
||||
logMessage = "They tried to split more than three times"
|
||||
log_message = "They tried to split more than three times"
|
||||
sendMessage = "You can only split 3 times"
|
||||
elif hand["hit"]:
|
||||
logMessage = "They've already hit"
|
||||
log_message = "They've already hit"
|
||||
sendMessage = "You've already hit or split this hand."
|
||||
elif hand["standing"]:
|
||||
logMessage = "They're already standing"
|
||||
log_message = "They're already standing"
|
||||
sendMessage = "You're already standing"
|
||||
elif len(hand["hand"]) != 2:
|
||||
logMessage = "They tried to split after the first round"
|
||||
log_message = "They tried to split after the first round"
|
||||
sendMessage = "You can only split on the first round"
|
||||
else:
|
||||
firstCard = self._calcHandValue([hand["hand"][0]])
|
||||
secondCard = self._calcHandValue([hand["hand"][1]])
|
||||
if firstCard != secondCard:
|
||||
logMessage = "They tried to split two different cards"
|
||||
sendMessage = self.bot.longStrings["Blackjack different cards"]
|
||||
log_message = "They tried to split two different cards"
|
||||
sendMessage = self.bot.long_strings["Blackjack different cards"]
|
||||
else:
|
||||
bet = hand["bet"]
|
||||
if self.bot.money.checkBalance(user) < bet:
|
||||
logMessage = "They didn't have enough GwendoBucks"
|
||||
log_message = "They didn't have enough GwendoBucks"
|
||||
sendMessage = "You don't have enough GwendoBucks"
|
||||
else:
|
||||
self.bot.money.addMoney(user, -1 * bet)
|
||||
@ -972,13 +972,13 @@ class Blackjack():
|
||||
game = blackjackGames.find_one({"_id": channel})
|
||||
roundDone = self._isRoundDone(game)
|
||||
|
||||
sendMessage = self.bot.longStrings["Blackjack split"]
|
||||
userName = self.bot.databaseFuncs.getName(user)
|
||||
sendMessage = self.bot.long_strings["Blackjack split"]
|
||||
userName = self.bot.database_funcs.getName(user)
|
||||
sendMessage = sendMessage.format(userName)
|
||||
logMessage = "They succeeded"
|
||||
log_message = "They succeeded"
|
||||
|
||||
await ctx.send(sendMessage)
|
||||
self.bot.log(logMessage)
|
||||
self.bot.log(log_message)
|
||||
|
||||
if roundDone:
|
||||
gameID = game["gameID"]
|
||||
@ -1002,28 +1002,28 @@ class Blackjack():
|
||||
user = f"#{ctx.author.id}"
|
||||
collection = self.bot.database["blackjack games"]
|
||||
game = collection.find_one({"_id": channel})
|
||||
userName = self.bot.databaseFuncs.getName(user)
|
||||
userName = self.bot.database_funcs.getName(user)
|
||||
|
||||
self.bot.log(f"{userName} is trying to join the Blackjack game")
|
||||
|
||||
if game is None:
|
||||
sendMessage = "There is no game going on in this channel"
|
||||
logMessage = sendMessage
|
||||
log_message = sendMessage
|
||||
elif user in game["user hands"]:
|
||||
sendMessage = "You're already in the game!"
|
||||
logMessage = "They're already in the game"
|
||||
log_message = "They're already in the game"
|
||||
elif len(game["user hands"]) >= 5:
|
||||
sendMessage = "There can't be more than 5 players in a game"
|
||||
logMessage = "There were already 5 players in the game"
|
||||
log_message = "There were already 5 players in the game"
|
||||
elif game["round"] != 0:
|
||||
sendMessage = "The table is no longer taking bets"
|
||||
logMessage = "They tried to join after the game begun"
|
||||
log_message = "They tried to join after the game begun"
|
||||
elif bet < 0:
|
||||
sendMessage = "You can't bet a negative amount"
|
||||
logMessage = "They tried to bet a negative amount"
|
||||
log_message = "They tried to bet a negative amount"
|
||||
elif self.bot.money.checkBalance(user) < bet:
|
||||
sendMessage = "You don't have enough GwendoBucks"
|
||||
logMessage = "They didn't have enough GwendoBucks"
|
||||
log_message = "They didn't have enough GwendoBucks"
|
||||
else:
|
||||
self.bot.money.addMoney(user, -1 * bet)
|
||||
playerHand = [self._drawCard(channel) for _ in range(2)]
|
||||
@ -1048,9 +1048,9 @@ class Blackjack():
|
||||
enterGameText = "entered the game with a bet of"
|
||||
betText = f"{bet} GwendoBucks"
|
||||
sendMessage = f"{userName} {enterGameText} {betText}"
|
||||
logMessage = sendMessage
|
||||
log_message = sendMessage
|
||||
|
||||
self.bot.log(logMessage)
|
||||
self.bot.log(log_message)
|
||||
await ctx.send(sendMessage)
|
||||
|
||||
async def start(self, ctx: discord_slash.context.SlashContext):
|
||||
@ -1109,7 +1109,7 @@ class Blackjack():
|
||||
gameStarted = True
|
||||
|
||||
if gameStarted:
|
||||
sendMessage = self.bot.longStrings["Blackjack started"]
|
||||
sendMessage = self.bot.long_strings["Blackjack started"]
|
||||
await ctx.channel.send(sendMessage)
|
||||
|
||||
tableImagesPath = "resources/games/blackjackTables/"
|
||||
@ -1117,7 +1117,7 @@ class Blackjack():
|
||||
|
||||
oldImage = await ctx.channel.send(file=discord.File(filePath))
|
||||
|
||||
with open("resources/games/oldImages/blackjack"+channel, "w") as f:
|
||||
with open("resources/games/old_images/blackjack"+channel, "w") as f:
|
||||
f.write(str(oldImage.id))
|
||||
|
||||
await asyncio.sleep(30)
|
||||
@ -1142,7 +1142,7 @@ class Blackjack():
|
||||
new_message = self._blackjackFinish(channel)
|
||||
await ctx.channel.send(new_message)
|
||||
else:
|
||||
sendMessage = self.bot.longStrings["Blackjack going on"]
|
||||
sendMessage = self.bot.long_strings["Blackjack going on"]
|
||||
await ctx.channel.send(sendMessage)
|
||||
self.bot.log("There was already a game going on")
|
||||
|
||||
@ -1267,7 +1267,7 @@ class DrawBlackjack():
|
||||
|
||||
for x in range(len(hands)):
|
||||
key, value = list(hands.items())[x]
|
||||
key = self.bot.databaseFuncs.getName(key)
|
||||
key = self.bot.database_funcs.getName(key)
|
||||
handParams = [
|
||||
value["hand"],
|
||||
False,
|
||||
|
@ -73,8 +73,8 @@ class ConnectFour():
|
||||
canStart = True
|
||||
|
||||
if game is not None:
|
||||
sendMessage = self.bot.longStrings["Connect 4 going on"]
|
||||
logMessage = "There was already a game going on"
|
||||
sendMessage = self.bot.long_strings["Connect 4 going on"]
|
||||
log_message = "There was already a game going on"
|
||||
canStart = False
|
||||
elif type(opponent) == int:
|
||||
# Opponent is Gwendolyn
|
||||
@ -84,7 +84,7 @@ class ConnectFour():
|
||||
opponent = f"#{self.bot.user.id}"
|
||||
else:
|
||||
sendMessage = "Difficulty doesn't exist"
|
||||
logMessage = "They challenged a difficulty that doesn't exist"
|
||||
log_message = "They challenged a difficulty that doesn't exist"
|
||||
canStart = False
|
||||
elif type(opponent) == discord.User:
|
||||
if opponent.bot:
|
||||
@ -96,7 +96,7 @@ class ConnectFour():
|
||||
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
|
||||
@ -106,7 +106,7 @@ class ConnectFour():
|
||||
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
|
||||
|
||||
if canStart:
|
||||
@ -133,15 +133,15 @@ class ConnectFour():
|
||||
gwendoTurn = (players[0] == f"#{self.bot.user.id}")
|
||||
startedGame = True
|
||||
|
||||
opponentName = self.bot.databaseFuncs.getName(opponent)
|
||||
turnName = self.bot.databaseFuncs.getName(players[0])
|
||||
opponentName = self.bot.database_funcs.getName(opponent)
|
||||
turnName = self.bot.database_funcs.getName(players[0])
|
||||
|
||||
startedText = f"Started game against {opponentName}{diffText}."
|
||||
turnText = f"It's {turnName}'s turn"
|
||||
sendMessage = f"{startedText} {turnText}"
|
||||
logMessage = "They started a game"
|
||||
log_message = "They started a game"
|
||||
|
||||
self.bot.log(logMessage)
|
||||
self.bot.log(log_message)
|
||||
await ctx.send(sendMessage)
|
||||
|
||||
# Sets the whole game in motion
|
||||
@ -150,13 +150,13 @@ class ConnectFour():
|
||||
filePath = f"{boardsPath}board{ctx.channel_id}.png"
|
||||
oldImage = await ctx.channel.send(file=discord.File(filePath))
|
||||
|
||||
oldImagesPath = "resources/games/oldImages/"
|
||||
oldImagePath = f"{oldImagesPath}connectFour{ctx.channel_id}"
|
||||
old_imagesPath = "resources/games/old_images/"
|
||||
oldImagePath = f"{old_imagesPath}connect_four{ctx.channel_id}"
|
||||
with open(oldImagePath, "w") as f:
|
||||
f.write(str(oldImage.id))
|
||||
|
||||
if gwendoTurn:
|
||||
await self._connectFourAI(ctx)
|
||||
await self._connect_fourAI(ctx)
|
||||
else:
|
||||
for reaction in self.REACTIONS:
|
||||
await oldImage.add_reaction(reaction)
|
||||
@ -183,19 +183,19 @@ class ConnectFour():
|
||||
connect4Games = self.bot.database["connect 4 games"]
|
||||
game = connect4Games.find_one({"_id": channel})
|
||||
playerNumber = game["players"].index(user)+1
|
||||
userName = self.bot.databaseFuncs.getName(user)
|
||||
userName = self.bot.database_funcs.getName(user)
|
||||
placedPiece = False
|
||||
|
||||
if game is None:
|
||||
sendMessage = "There's no game in this channel"
|
||||
logMessage = "There was no game in the channel"
|
||||
log_message = "There was no game in the channel"
|
||||
else:
|
||||
board = game["board"]
|
||||
board = self._placeOnBoard(board, playerNumber, column)
|
||||
|
||||
if board is None:
|
||||
sendMessage = "There isn't any room in that column"
|
||||
logMessage = "There wasn't any room in the column"
|
||||
log_message = "There wasn't any room in the column"
|
||||
else:
|
||||
updater = {"$set": {"board": board}}
|
||||
connect4Games.update_one({"_id": channel}, updater)
|
||||
@ -217,7 +217,7 @@ class ConnectFour():
|
||||
|
||||
sendMessage = "{} placed a piece in column {} and won. "
|
||||
sendMessage = sendMessage.format(userName, column+1)
|
||||
logMessage = f"{userName} won"
|
||||
log_message = f"{userName} won"
|
||||
winAmount = int(game["difficulty"])**2+5
|
||||
if game["players"][won-1] != f"#{self.bot.user.id}":
|
||||
sendMessage += "Adding {} GwendoBucks to their account"
|
||||
@ -225,27 +225,27 @@ class ConnectFour():
|
||||
elif 0 not in board[0]:
|
||||
gameWon = True
|
||||
sendMessage = "It's a draw!"
|
||||
logMessage = "The game ended in a draw"
|
||||
log_message = "The game ended in a draw"
|
||||
else:
|
||||
gameWon = False
|
||||
otherUserId = game["players"][turn]
|
||||
otherUserName = self.bot.databaseFuncs.getName(otherUserId)
|
||||
sendMessage = self.bot.longStrings["Connect 4 placed"]
|
||||
otherUserName = self.bot.database_funcs.getName(otherUserId)
|
||||
sendMessage = self.bot.long_strings["Connect 4 placed"]
|
||||
formatParams = [userName, column+1, otherUserName]
|
||||
sendMessage = sendMessage.format(*formatParams)
|
||||
logMessage = "They placed the piece"
|
||||
log_message = "They placed the piece"
|
||||
|
||||
gwendoTurn = (game["players"][turn] == f"#{self.bot.user.id}")
|
||||
|
||||
placedPiece = True
|
||||
|
||||
await ctx.channel.send(sendMessage)
|
||||
self.bot.log(logMessage)
|
||||
self.bot.log(log_message)
|
||||
|
||||
if placedPiece:
|
||||
self.draw.drawImage(channel)
|
||||
|
||||
oldImagePath = f"resources/games/oldImages/connectFour{channel}"
|
||||
oldImagePath = f"resources/games/old_images/connect_four{channel}"
|
||||
with open(oldImagePath, "r") as f:
|
||||
oldImage = await ctx.channel.fetch_message(int(f.read()))
|
||||
|
||||
@ -263,7 +263,7 @@ class ConnectFour():
|
||||
with open(oldImagePath, "w") as f:
|
||||
f.write(str(oldImage.id))
|
||||
if gwendoTurn:
|
||||
await self._connectFourAI(ctx)
|
||||
await self._connect_fourAI(ctx)
|
||||
else:
|
||||
for reaction in self.REACTIONS:
|
||||
await oldImage.add_reaction(reaction)
|
||||
@ -285,7 +285,7 @@ class ConnectFour():
|
||||
loserIndex = game["players"].index(f"#{ctx.author.id}")
|
||||
winnerIndex = (loserIndex+1) % 2
|
||||
winnerID = game["players"][winnerIndex]
|
||||
winnerName = self.bot.databaseFuncs.getName(winnerID)
|
||||
winnerName = self.bot.database_funcs.getName(winnerID)
|
||||
|
||||
sendMessage = f"{ctx.author.display_name} surrenders."
|
||||
sendMessage += f" This means {winnerName} is the winner."
|
||||
@ -295,7 +295,7 @@ class ConnectFour():
|
||||
sendMessage += f" Adding {reward} to their account"
|
||||
|
||||
await ctx.send(sendMessage)
|
||||
oldImagePath = f"resources/games/oldImages/connectFour{channel}"
|
||||
oldImagePath = f"resources/games/old_images/connect_four{channel}"
|
||||
with open(oldImagePath, "r") as f:
|
||||
oldImage = await ctx.channel.fetch_message(int(f.read()))
|
||||
|
||||
@ -353,7 +353,7 @@ class ConnectFour():
|
||||
reward = difficulty**2 + 5
|
||||
self.bot.money.addMoney(game["players"][winner-1], reward)
|
||||
|
||||
self.bot.databaseFuncs.deleteGame("connect 4 games", channel)
|
||||
self.bot.database_funcs.deleteGame("connect 4 games", channel)
|
||||
|
||||
def _isWon(self, board: dict):
|
||||
won = 0
|
||||
@ -429,7 +429,7 @@ class ConnectFour():
|
||||
|
||||
return won, winDirection, winCoordinates
|
||||
|
||||
async def _connectFourAI(self, ctx: SlashContext):
|
||||
async def _connect_fourAI(self, ctx: SlashContext):
|
||||
def outOfRange(possibleScores: list):
|
||||
allowedRange = max(possibleScores)*(1-0.1)
|
||||
moreThanOne = len(possibleScores) != 1
|
||||
@ -1023,12 +1023,12 @@ class DrawConnectFour():
|
||||
if game["players"][0] == "Gwendolyn":
|
||||
player1 = "Gwendolyn"
|
||||
else:
|
||||
player1 = self.bot.databaseFuncs.getName(game["players"][0])
|
||||
player1 = self.bot.database_funcs.getName(game["players"][0])
|
||||
|
||||
if game["players"][1] == "Gwendolyn":
|
||||
player2 = "Gwendolyn"
|
||||
else:
|
||||
player2 = self.bot.databaseFuncs.getName(game["players"][1])
|
||||
player2 = self.bot.database_funcs.getName(game["players"][1])
|
||||
|
||||
exampleHeight = self.HEIGHT - self.BORDER
|
||||
exampleHeight += (self.BOTTOMBORDER+self.BORDER)//2 - self.TEXTSIZE//2
|
@ -11,7 +11,7 @@ Has a container for game functions.
|
||||
from .invest import Invest
|
||||
from .trivia import Trivia
|
||||
from .blackjack import Blackjack
|
||||
from .connectFour import ConnectFour
|
||||
from .connect_four import ConnectFour
|
||||
from .hangman import Hangman
|
||||
from .hex import HexGame
|
||||
|
||||
@ -28,7 +28,7 @@ class Games():
|
||||
Contains investment functions.
|
||||
blackjack
|
||||
Contains blackjack functions.
|
||||
connectFour
|
||||
connect_four
|
||||
Contains connect four functions.
|
||||
hangman
|
||||
Contains hangman functions.
|
||||
@ -43,6 +43,6 @@ class Games():
|
||||
self.invest = Invest(bot)
|
||||
self.trivia = Trivia(bot)
|
||||
self.blackjack = Blackjack(bot)
|
||||
self.connectFour = ConnectFour(bot)
|
||||
self.connect_four = ConnectFour(bot)
|
||||
self.hangman = Hangman(bot)
|
||||
self.hex = HexGame(bot)
|
@ -72,7 +72,7 @@ class Hangman():
|
||||
channel = str(ctx.channel_id)
|
||||
user = f"#{ctx.author.id}"
|
||||
game = self.__bot.database["hangman games"].find_one({"_id": channel})
|
||||
userName = self.__bot.databaseFuncs.getName(user)
|
||||
userName = self.__bot.database_funcs.getName(user)
|
||||
startedGame = False
|
||||
|
||||
if game is None:
|
||||
@ -99,14 +99,14 @@ class Hangman():
|
||||
|
||||
self.__draw.drawImage(channel)
|
||||
|
||||
logMessage = "Game started"
|
||||
log_message = "Game started"
|
||||
sendMessage = f"{userName} started game of hangman."
|
||||
startedGame = True
|
||||
else:
|
||||
logMessage = "There was already a game going on"
|
||||
sendMessage = self.__bot.longStrings["Hangman going on"]
|
||||
log_message = "There was already a game going on"
|
||||
sendMessage = self.__bot.long_strings["Hangman going on"]
|
||||
|
||||
self.__bot.log(logMessage)
|
||||
self.__bot.log(log_message)
|
||||
await ctx.send(sendMessage)
|
||||
|
||||
if startedGame:
|
||||
@ -122,7 +122,7 @@ class Hangman():
|
||||
|
||||
oldMessages = f"{newImage.id}\n{blankMessage.id}"
|
||||
|
||||
with open(f"resources/games/oldImages/hangman{channel}", "w") as f:
|
||||
with open(f"resources/games/old_images/hangman{channel}", "w") as f:
|
||||
f.write(oldMessages)
|
||||
|
||||
for message, letters in reactionMessages.items():
|
||||
@ -149,7 +149,7 @@ class Hangman():
|
||||
else:
|
||||
self.__bot.database["hangman games"].delete_one({"_id": channel})
|
||||
|
||||
with open(f"resources/games/oldImages/hangman{channel}", "r") as f:
|
||||
with open(f"resources/games/old_images/hangman{channel}", "r") as f:
|
||||
messages = f.read().splitlines()
|
||||
|
||||
for message in messages:
|
||||
@ -216,17 +216,17 @@ class Hangman():
|
||||
|
||||
if game["misses"] == 6:
|
||||
hangmanGames.delete_one({"_id": channel})
|
||||
sendMessage += self.__bot.longStrings["Hangman lost game"]
|
||||
sendMessage += self.__bot.long_strings["Hangman lost game"]
|
||||
remainingLetters = []
|
||||
elif all(game["guessed"]):
|
||||
hangmanGames.delete_one({"_id": channel})
|
||||
self.__bot.money.addMoney(user, 15)
|
||||
sendMessage += self.__bot.longStrings["Hangman guessed word"]
|
||||
sendMessage += self.__bot.long_strings["Hangman guessed word"]
|
||||
remainingLetters = []
|
||||
|
||||
await message.channel.send(sendMessage)
|
||||
|
||||
with open(f"resources/games/oldImages/hangman{channel}", "r") as f:
|
||||
with open(f"resources/games/old_images/hangman{channel}", "r") as f:
|
||||
oldMessageIDs = f.read().splitlines()
|
||||
|
||||
for oldID in oldMessageIDs:
|
||||
@ -254,7 +254,7 @@ class Hangman():
|
||||
else:
|
||||
oldMessages = str(newImage.id)
|
||||
|
||||
oldImagePath = f"resources/games/oldImages/hangman{channel}"
|
||||
oldImagePath = f"resources/games/old_images/hangman{channel}"
|
||||
with open(oldImagePath, "w") as f:
|
||||
f.write(oldMessages)
|
||||
|
||||
|
@ -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
|
||||
|
@ -42,7 +42,7 @@ class Invest():
|
||||
price: int
|
||||
The price of the stock.
|
||||
"""
|
||||
res = self.bot.finnhubClient.quote(symbol.upper())
|
||||
res = self.bot.finnhub_client.quote(symbol.upper())
|
||||
if res == {}:
|
||||
return 0
|
||||
else:
|
||||
@ -65,7 +65,7 @@ class Invest():
|
||||
investmentsDatabase = self.bot.database["investments"]
|
||||
userInvestments = investmentsDatabase.find_one({"_id": user})
|
||||
|
||||
userName = self.bot.databaseFuncs.getName(user)
|
||||
userName = self.bot.database_funcs.getName(user)
|
||||
|
||||
if userInvestments in [None, {}]:
|
||||
return f"{userName} does not have a stock portfolio."
|
||||
@ -162,7 +162,7 @@ class Invest():
|
||||
}
|
||||
investmentsDatabase.insert_one(newUser)
|
||||
|
||||
userName = self.bot.databaseFuncs.getName(user)
|
||||
userName = self.bot.database_funcs.getName(user)
|
||||
sendMessage = "{} bought {} GwendoBucks worth of {} stock"
|
||||
sendMessage = sendMessage.format(userName, buyAmount, stock)
|
||||
return sendMessage
|
||||
@ -219,7 +219,7 @@ class Invest():
|
||||
updater = {"$unset": {f"investments.{stock}": ""}}
|
||||
investmentsDatabase.update_one({"_id": user}, updater)
|
||||
|
||||
userName = self.bot.databaseFuncs.getName(user)
|
||||
userName = self.bot.database_funcs.getName(user)
|
||||
sendMessage = "{} sold {} GwendoBucks worth of {} stock"
|
||||
return sendMessage.format(userName, sellAmount, stock)
|
||||
else:
|
||||
@ -252,7 +252,7 @@ class Invest():
|
||||
response = response.format(commands[0].upper())
|
||||
else:
|
||||
price = f"{price:,}".replace(",", ".")
|
||||
response = self.bot.longStrings["Stock value"]
|
||||
response = self.bot.long_strings["Stock value"]
|
||||
response = response.format(commands[1].upper(), price)
|
||||
|
||||
elif parameters.startswith("buy"):
|
||||
@ -260,14 +260,14 @@ class Invest():
|
||||
if len(commands) == 3:
|
||||
response = self.buyStock(user, commands[1], int(commands[2]))
|
||||
else:
|
||||
response = self.bot.longStrings["Stock parameters"]
|
||||
response = self.bot.long_strings["Stock parameters"]
|
||||
|
||||
elif parameters.startswith("sell"):
|
||||
commands = parameters.split(" ")
|
||||
if len(commands) == 3:
|
||||
response = self.sellStock(user, commands[1], int(commands[2]))
|
||||
else:
|
||||
response = self.bot.longStrings["Stock parameters"]
|
||||
response = self.bot.long_strings["Stock parameters"]
|
||||
|
||||
else:
|
||||
response = "Incorrect parameters"
|
||||
@ -280,7 +280,7 @@ class Invest():
|
||||
"description": text,
|
||||
"colour": 0x00FF00
|
||||
}
|
||||
em = discord.Embed(*embedParams)
|
||||
em = discord.Embed(**embedParams)
|
||||
await ctx.send(embed=em)
|
||||
else:
|
||||
await ctx.send(response)
|
||||
|
@ -98,7 +98,7 @@ class Money():
|
||||
else:
|
||||
newUser = {
|
||||
"_id": user,
|
||||
"user name": self.bot.databaseFuncs.getName(user),
|
||||
"user name": self.bot.database_funcs.getName(user),
|
||||
"money": amount
|
||||
}
|
||||
self.database["users"].insert_one(newUser)
|
||||
@ -120,7 +120,7 @@ class Money():
|
||||
"""
|
||||
await self.bot.defer(ctx)
|
||||
username = user.display_name
|
||||
if self.bot.databaseFuncs.getID(username) is None:
|
||||
if self.bot.database_funcs.getID(username) is None:
|
||||
async for member in ctx.guild.fetch_members(limit=None):
|
||||
if member.display_name.lower() == username.lower():
|
||||
username = member.display_name
|
||||
@ -134,7 +134,7 @@ class Money():
|
||||
|
||||
userid = f"#{ctx.author.id}"
|
||||
userData = self.database["users"].find_one({"_id": userid})
|
||||
targetUser = self.bot.databaseFuncs.getID(username)
|
||||
targetUser = self.bot.database_funcs.getID(username)
|
||||
|
||||
if amount <= 0:
|
||||
self.bot.log("They tried to steal")
|
||||
|
@ -91,9 +91,9 @@ class Trivia():
|
||||
|
||||
return question, answers, correctAnswer
|
||||
else:
|
||||
logMessage = "There was already a trivia question for that channel"
|
||||
self.bot.log(logMessage)
|
||||
return self.bot.longStrings["Trivia going on"], "", ""
|
||||
log_message = "There was already a trivia question for that channel"
|
||||
self.bot.log(log_message)
|
||||
return self.bot.long_strings["Trivia going on"], "", ""
|
||||
|
||||
def triviaAnswer(self, user: str, channel: str, command: str):
|
||||
"""
|
||||
@ -182,10 +182,10 @@ class Trivia():
|
||||
self.triviaCountPoints(channelId)
|
||||
|
||||
deleteGameParams = ["trivia questions", channelId]
|
||||
self.bot.databaseFuncs.deleteGame(*deleteGameParams)
|
||||
self.bot.database_funcs.deleteGame(*deleteGameParams)
|
||||
|
||||
self.bot.log("Time's up for the trivia question", channelId)
|
||||
sendMessage = self.bot.longStrings["Trivia time up"]
|
||||
sendMessage = self.bot.long_strings["Trivia time up"]
|
||||
formatParams = [chr(correctAnswer), options[correctAnswer-97]]
|
||||
sendMessage = sendMessage.format(*formatParams)
|
||||
await ctx.send(sendMessage)
|
||||
|
Reference in New Issue
Block a user