🧹 Last bit of cleaning up before pushing

This commit is contained in:
NikolajDanger
2021-03-31 01:02:32 +02:00
parent b345720468
commit 6c1a1cf626
37 changed files with 125 additions and 118 deletions

View File

@ -35,7 +35,7 @@ class Blackjack():
# Calculates the value of a blackjack hand
def calcHandValue(self, hand : list):
self.bot.log("Calculating hand value", level = 10)
self.bot.log("Calculating hand value")
values = []
values.append(0)
@ -58,13 +58,13 @@ class Blackjack():
if value <= 21:
handValue = value
self.bot.log("Calculated "+str(hand)+" to be "+str(handValue), level = 10)
self.bot.log("Calculated "+str(hand)+" to be "+str(handValue))
return handValue
# Draws a card from the deck
def drawCard(self, channel):
self.bot.log("drawing a card", level = 10)
self.bot.log("drawing a card")
drawnCard = self.bot.database["blackjack cards"].find_one({"_id":channel})["cards"][0]
self.bot.database["blackjack cards"].update_one({"_id":channel},{"$pop":{"cards":-1}})
@ -97,7 +97,7 @@ class Blackjack():
# Goes to the next round and calculates some stuff
def blackjackContinue(self, channel):
self.bot.log("Continuing blackjack game", level = 10)
self.bot.log("Continuing blackjack game")
game = self.bot.database["blackjack games"].find_one({"_id":channel})
done = False
@ -116,7 +116,7 @@ class Blackjack():
game = self.bot.database["blackjack games"].find_one({"_id":channel})
self.bot.log("Testing if all are standing", level = 10)
self.bot.log("Testing if all are standing")
for user in game["user hands"]:
try:
newUser, allStanding, preAllStanding = self.testIfStanding(game["user hands"][user],allStanding,preAllStanding,True)
@ -141,10 +141,10 @@ class Blackjack():
return "", True, done
else:
if game["round"] == 1:
firstRoundMessage = ". You can also double down with \"!blackjack double\" or split with \"!blackjack split\""
firstRoundMessage = ". You can also double down with \"/blackjack double\" or split with \"/blackjack split\""
else:
firstRoundMessage = ""
return "You have 2 minutes to either hit or stand with \"!blackjack hit\" or \"!blackjack stand\""+firstRoundMessage+". It's assumed you're standing if you don't make a choice.", False, done
return "You have 2 minutes to either hit or stand with \"/blackjack hit\" or \"/blackjack stand\""+firstRoundMessage+". It's assumed you're standing if you don't make a choice.", False, done
def testIfStanding(self, hand,allStanding,preAllStanding,topLevel):
if hand["hit"] == False:
@ -430,7 +430,7 @@ class Blackjack():
roundDone = self.isRoundDone(self.bot.database["blackjack games"].find_one({"_id":channel}))
return "Splitting "+self.bot.databaseFuncs.getName(user)+"'s hand into 2. Adding their original bet to the second hand. You can use \"!Blackjack hit/stand/double 1\" and \"!Blackjack hit/stand/double 2\" to play the different hands.",str(roundDone)[0] + str(game["round"])
return "Splitting "+self.bot.databaseFuncs.getName(user)+"'s hand into 2. Adding their original bet to the second hand. You can use \"/blackjack hit/stand/double 1\" and \"/blackjack hit/stand/double 2\" to play the different hands.",str(roundDone)[0] + str(game["round"])
else:
self.bot.log(user+" doesn't have enough GwendoBucks")
return "You don't have enough GwendoBucks",""
@ -564,7 +564,7 @@ class Blackjack():
def calcWinnings(self,hand, dealerValue, topLevel, dealerBlackjack, dealerBusted):
self.bot.log("Calculating winnings", level = 10)
self.bot.log("Calculating winnings")
reason = ""
bet = hand["bet"]
winnings = -1 * bet
@ -659,14 +659,14 @@ class Blackjack():
# Loop of blackjack game rounds
async def blackjackLoop(self,channel,gameRound,gameID):
self.bot.log("Loop "+str(gameRound),str(channel.id), level = 10)
self.bot.log("Loop "+str(gameRound),str(channel.id))
with open("resources/games/oldImages/blackjack"+str(channel.id), "r") as f:
oldImage = await channel.fetch_message(int(f.read()))
new_message, allStanding, gamedone = self.blackjackContinue(str(channel.id))
if new_message != "":
self.bot.log(new_message,str(channel.id), level = 10)
self.bot.log(new_message,str(channel.id))
await channel.send(new_message)
if gamedone == False:
await oldImage.delete()
@ -699,9 +699,9 @@ class Blackjack():
self.bot.log("Something fucked up (error code 1310)")
await channel.send(new_message)
else:
self.bot.log("Ending loop on round "+str(gameRound),str(channel.id), level = 10)
self.bot.log("Ending loop on round "+str(gameRound),str(channel.id))
else:
self.bot.log("Ending loop on round "+str(gameRound),str(channel.id), level = 10)
self.bot.log("Ending loop on round "+str(gameRound),str(channel.id))
async def parseBlackjack(self,content, ctx):
# Blackjack shuffle variables
@ -726,7 +726,7 @@ class Blackjack():
new_message = self.blackjackStart(str(channel))
if new_message == "started":
new_message = "Blackjack game started. Use \"!blackjack bet [amount]\" to enter the game within the next 30 seconds."
new_message = "Blackjack game started. Use \"/blackjack bet [amount]\" to enter the game within the next 30 seconds."
await ctx.channel.send(new_message)
oldImage = await ctx.channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(channel)+".png"))
@ -746,7 +746,7 @@ class Blackjack():
# Loop of game rounds
if gamedone == False:
self.bot.log("!blackjack calling self.blackjackLoop()",str(channel))
self.bot.log("/blackjack calling self.blackjackLoop()",str(channel))
await self.blackjackLoop(ctx.channel,1,gameID)
else:
new_message = self.blackjackFinish(str(channel))

View File

@ -9,7 +9,7 @@ class DrawBlackjack():
self.bot = bot
def drawImage(self,channel):
self.bot.log("Drawing blackjack table",channel, level = 10)
self.bot.log("Drawing blackjack table",channel)
game = self.bot.database["blackjack games"].find_one({"_id":channel})
fnt = ImageFont.truetype('resources/fonts/futura-bold.ttf', 50)
@ -78,13 +78,13 @@ class DrawBlackjack():
textImage.text((32+(384*placement[x])+117-int(textWidth/2)+2,1020+2),key,fill=(0,0,0), font=fntSmol)
textImage.text((32+(384*placement[x])+117-int(textWidth/2),1015),key,fill=(255,255,255), font=fntSmol)
self.bot.log("Saving table image", level = 10)
self.bot.log("Saving table image")
table.save("resources/games/blackjackTables/blackjackTable"+channel+".png")
return
def drawHand(self, hand, dealer, busted, blackjack):
self.bot.log("Drawing hand "+str(hand)+", "+str(busted)+", "+str(blackjack), level = 10)
self.bot.log("Drawing hand "+str(hand)+", "+str(busted)+", "+str(blackjack))
fnt = ImageFont.truetype('resources/fonts/futura-bold.ttf', 200)
fnt2 = ImageFont.truetype('resources/fonts/futura-bold.ttf', 120)
length = len(hand)

View File

@ -88,7 +88,7 @@ class connectFour():
turn = (game["turn"]+1)%2
self.bot.database["connect 4 games"].update_one({"_id":channel},{"$set":{"turn":turn}})
self.bot.log("Checking for win", level = 10)
self.bot.log("Checking for win")
won, winDirection, winCoordinates = self.isWon(board)
if won != 0:
@ -112,7 +112,7 @@ class connectFour():
gwendoTurn = False
if game["players"][turn] == "Gwendolyn":
self.bot.log("It's Gwendolyn's turn", level = 10)
self.bot.log("It's Gwendolyn's turn")
gwendoTurn = True
self.draw.drawImage(channel)
@ -141,10 +141,10 @@ class connectFour():
def parseconnectFour(self, command, channel, user):
commands = command.split()
if command == "" or command == " ":
return "I didn't get that. Use \"!connectFour start [opponent]\" to start a game. To play against the computer, use difficulty 1 through 5 as the [opponent].", False, False, False, False
return "I didn't get that. Use \"/connectFour start [opponent]\" to start a game. To play against the computer, use difficulty 1 through 5 as the [opponent].", False, False, False, False
elif commands[0] == "start":
# Starting a game
if len(commands) == 1: # if the commands is "!connectFour start", the opponent is Gwendolyn
if len(commands) == 1: # if the commands is "/connectFour start", the opponent is Gwendolyn
commands.append("3")
return self.connectFourStart(channel,user,commands[1]) # commands[1] is the opponent
@ -165,7 +165,7 @@ class connectFour():
if user == game["players"][turn]:
piece = turn + 1
else:
self.bot.log("It wasn't their turn", level = 10)
self.bot.log("It wasn't their turn")
return "It's not your turn!", False, False, False, False
column = int(commands[1])-1
else:
@ -173,7 +173,7 @@ class connectFour():
piece = int(commands[1])
return self.placePiece(channel, piece, column)
else:
return "I didn't get that. Use \"!connectFour start [opponent]\" to start a game. To play against the computer, use difficulty 1 through 5 as the [opponent].", False, False, False, False
return "I didn't get that. Use \"/connectFour start [opponent]\" to start a game. To play against the computer, use difficulty 1 through 5 as the [opponent].", False, False, False, False
# Checks if someone has won the game and returns the winner
def isWon(self, board):
@ -235,7 +235,7 @@ class connectFour():
# Plays as the AI
async def connectFourAI(self, channel):
self.bot.log("Figuring out best move", level = 10)
self.bot.log("Figuring out best move")
game = self.bot.database["connect 4 games"].find_one({"_id":channel})
board = game["board"]
@ -248,7 +248,7 @@ class connectFour():
testBoard = self.placeOnBoard(testBoard,player,column)
if testBoard != None:
scores[column] = await self.minimax(testBoard,difficulty,player%2+1,player,-math.inf,math.inf,False)
self.bot.log("Best score for column "+str(column)+" is "+str(scores[column]), level = 10)
self.bot.log("Best score for column "+str(column)+" is "+str(scores[column]))
possibleScores = scores.copy()

View File

@ -8,7 +8,7 @@ class drawConnectFour():
# Draws the whole thing
def drawImage(self, channel):
self.bot.log("Drawing connect four board", level = 10)
self.bot.log("Drawing connect four board")
game = self.bot.database["connect 4 games"].find_one({"_id":channel})
board = game["board"]

View File

@ -14,7 +14,7 @@ class GameLoops():
for message in messages:
oldMessage = await channel.fetch_message(int(message))
self.bot.log("Deleting old message", level = 10)
self.bot.log("Deleting old message")
await oldMessage.delete()
except:
oldMessage = ""
@ -35,7 +35,7 @@ class GameLoops():
await ctx.send(response)
else:
await ctx.channel.send(response)
self.bot.log(response, channelId, level = 10)
self.bot.log(response, channelId)
if showImage:
if deleteImage:
oldImage = await self.deleteMessage("connectFour"+channelId,ctx.channel)
@ -44,7 +44,7 @@ class GameLoops():
if gwendoTurn:
response, showImage, deleteImage, gameDone, gwendoTurn = await self.bot.games.connectFour.connectFourAI(channelId)
await ctx.channel.send(response)
self.bot.log(response,channelId, level = 10)
self.bot.log(response,channelId)
if showImage:
if deleteImage:
await oldImage.delete()
@ -58,7 +58,7 @@ class GameLoops():
await oldImage.add_reaction(reaction)
except:
self.bot.log("Image deleted before I could react to all of them", level = 10)
self.bot.log("Image deleted before I could react to all of them")
else:
with open("resources/games/oldImages/connectFour"+channelId, "w") as f:
@ -68,7 +68,7 @@ class GameLoops():
for reaction in reactions:
await oldImage.add_reaction(reaction)
except:
self.bot.log("Image deleted before I could react to all of them", level = 10)
self.bot.log("Image deleted before I could react to all of them")
if gameDone:
game = self.bot.database["connect 4 games"].find_one({"_id":channelId})
@ -100,7 +100,7 @@ class GameLoops():
await channel.send(response)
else:
await ctx.send(response)
self.bot.log(response,str(channel.id), level = 10)
self.bot.log(response,str(channel.id))
if showImage:
if deleteImage:
await self.deleteMessage("hangman"+str(channel.id),channel)
@ -125,7 +125,7 @@ class GameLoops():
emoji = chr(ord(letter)+127397)
await message.add_reaction(emoji)
except:
self.bot.log("Image deleted before adding all reactions", level = 10)
self.bot.log("Image deleted before adding all reactions")
# Runs Hex
async def runHex(self,ctx,command,user):
@ -137,7 +137,7 @@ class GameLoops():
await ctx.send(response)
self.bot.log(response,str(channelId), level = 10)
self.bot.log(response,str(channelId))
if showImage:
if deleteImage:
try:
@ -152,7 +152,7 @@ class GameLoops():
response, showImage, deleteImage, gameDone, gwendoTurn = "An AI error ocurred",False,False,False,False
self.bot.log("AI error (error code 1520)")
await ctx.channel.send(response)
self.bot.log(response,str(channelId), level = 10)
self.bot.log(response,str(channelId))
if showImage:
if deleteImage:
await oldImage.delete()

View File

@ -18,7 +18,7 @@ class Hangman():
while "-" in word or "." in word:
with urllib.request.urlopen(apiUrl+apiKey) as p:
word = list(json.load(p)[0]["word"].upper())
self.bot.log("Found the word \""+"".join(word)+"\"", level = 10)
self.bot.log("Found the word \""+"".join(word)+"\"")
guessed = [False] * len(word)
gameID = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
newGame = {"_id":channel,"player" : user,"guessed letters" : [],"word" : word,"game ID" : gameID,"misses" : 0,"guessed" : guessed}

View File

@ -212,7 +212,7 @@ class DrawHangman():
return background
def drawImage(self,channel):
self.bot.log("Drawing hangman image", channel, level = 10)
self.bot.log("Drawing hangman image", channel)
game = self.bot.database["hangman games"].find_one({"_id":channel})
random.seed(game["game ID"])

View File

@ -22,13 +22,13 @@ class HexGame():
commands = command.lower().split()
game = self.bot.database["hex games"].find_one({"_id":channel})
if command == "" or command == " ":
return "I didn't get that. Use \"!hex start [opponent]\" to start a game.", False, False, False, False
return "I didn't get that. Use \"/hex start [opponent]\" to start a game.", False, False, False, False
elif commands[0] == "start":
# Starting a game
if len(commands) == 1: # if the commands is "!hex start", the opponent is Gwendolyn at difficulty 2
if len(commands) == 1: # if the commands is "/hex start", the opponent is Gwendolyn at difficulty 2
commands.append("2")
self.bot.log("Starting a hex game with hexStart(). "+str(user)+" challenged "+commands[1], level = 10)
self.bot.log("Starting a hex game with hexStart(). "+str(user)+" challenged "+commands[1])
return self.hexStart(channel,user,commands[1]) # commands[1] is the opponent
# If using a command with no game, return error
@ -47,7 +47,7 @@ class HexGame():
try:
return self.placeHex(channel,commands[1], user)
except:
return "I didn't get that. To place a piece use \"!hex place [position]\". A valid position is e.g. \"E2\".", False, False, False, False
return "I didn't get that. To place a piece use \"/hex place [position]\". A valid position is e.g. \"E2\".", False, False, False, False
# Undo
elif commands[0] == "undo":
@ -78,7 +78,7 @@ class HexGame():
return "You can only swap as the second player after the very first move.", False, False, False, False
else:
return "I didn't get that. Use \"!hex start [opponent]\" to start a game, \"!hex place [position]\" to place a piece, \"!hex undo\" to undo your last move or \"!hex stop\" to stop a current game.", False, False, False, False
return "I didn't get that. Use \"/hex start [opponent]\" to start a game, \"/hex place [position]\" to place a piece, \"/hex undo\" to undo your last move or \"/hex stop\" to stop a current game.", False, False, False, False
# Starts the game
def hexStart(self, channel, user, opponent):
@ -142,7 +142,7 @@ class HexGame():
if player == turn:
board = game["board"]
self.bot.log("Placing a piece on the board with placeHex()", level = 10)
self.bot.log("Placing a piece on the board with placeHex()")
# Places on board
board = self.placeOnHexBoard(board,player,position)
@ -153,7 +153,7 @@ class HexGame():
self.bot.database["hex games"].update_one({"_id":channel},{"$set":{"turn":turn}})
# Checking for a win
self.bot.log("Checking for win", level = 10)
self.bot.log("Checking for win")
winner = self.evaluateBoard(game["board"])[1]
if winner == 0: # Continue with the game.
@ -174,7 +174,7 @@ class HexGame():
# Is it now Gwendolyn's turn?
gwendoTurn = False
if game["players"][turn-1] == "Gwendolyn":
self.bot.log("It's Gwendolyn's turn", level = 10)
self.bot.log("It's Gwendolyn's turn")
gwendoTurn = True
# Update the board
@ -226,7 +226,7 @@ class HexGame():
turn = game["turn"]
# You can only undo after your turn, which is the opponent's turn.
if user == game["players"][(turn % 2)]: # If it's not your turn
self.bot.log("Undoing {}'s last move".format(self.bot.databaseFuncs.getName(user)), level = 10)
self.bot.log("Undoing {}'s last move".format(self.bot.databaseFuncs.getName(user)))
lastMove = game["gameHistory"].pop()
game["board"][lastMove[0]][lastMove[1]] = 0
@ -251,7 +251,7 @@ class HexGame():
# Plays as the AI
def hexAI(self, channel):
self.bot.log("Figuring out best move", level = 10)
self.bot.log("Figuring out best move")
game = self.bot.database["hex games"].find_one({"_id":channel})
board = game["board"]
@ -293,7 +293,7 @@ class HexGame():
chosenMove = (i // BOARDWIDTH , i % BOARDWIDTH)
"""
placement = "abcdefghijk"[chosenMove[1]]+str(chosenMove[0]+1)
self.bot.log("ChosenMove is {} at {}".format(chosenMove,placement), level = 10)
self.bot.log("ChosenMove is {} at {}".format(chosenMove,placement))
return self.placeHex(channel,placement, "Gwendolyn")
@ -327,7 +327,7 @@ class HexGame():
scores[player] = Distance[u] # A player's score is the shortest distance to goal. Which equals the number of remaining moves they need to win if unblocked by the opponent.
break
else:
self.bot.log("For some reason, no path to the goal was found. ", level = 10)
self.bot.log("For some reason, no path to the goal was found. ")
if scores[player] == 0:
winner = player
break # We don't need to check the other player's score, if player1 won.

View File

@ -122,7 +122,7 @@ class Invest():
#try:
return self.buyStock(user,commands[1],int(commands[2]))
#except:
# return "The command must be given as \"!invest buy [stock] [amount of GwendoBucks to purchase with]\""
# return "The command must be given as \"/invest buy [stock] [amount of GwendoBucks to purchase with]\""
else:
return "You must give both a stock name and an amount of gwendobucks you wish to spend."
@ -132,6 +132,6 @@ class Invest():
try:
return self.sellStock(user,commands[1],int(commands[2]))
except:
return "The command must be given as \"!invest sell [stock] [amount of GwendoBucks to sell stocks for]\""
return "The command must be given as \"/invest sell [stock] [amount of GwendoBucks to sell stocks for]\""
else:
return "You must give both a stock name and an amount of GwendoBucks you wish to sell stocks for."

View File

@ -6,7 +6,7 @@ class Money():
# Returns the account balance for a user
def checkBalance(self, user):
self.bot.log("checking "+user+"'s account balance", level = 10)
self.bot.log("checking "+user+"'s account balance")
userData = self.database["users"].find_one({"_id":user})
@ -16,7 +16,7 @@ class Money():
# Adds money to the account of a user
def addMoney(self,user,amount):
self.bot.log("adding "+str(amount)+" to "+user+"'s account", level = 10)
self.bot.log("adding "+str(amount)+" to "+user+"'s account")
userData = self.database["users"].find_one({"_id":user})

View File

@ -135,5 +135,5 @@ class LookupFuncs():
else:
self.bot.log("I don't know that spell (error code 501)")
spell_output = "I don't think that's a spell (error code 501)"
self.bot.log("Successfully ran !spell")
self.bot.log("Successfully ran /spell")
return(spell_output)

View File

@ -40,7 +40,7 @@ class BedreNetflix():
messageText += "Error"
imdbIds.append(movie.movieID)
self.bot.log("Returning a list of "+str(len(movies))+" possible movies: "+str(imdbIds), level = 10)
self.bot.log("Returning a list of "+str(len(movies))+" possible movies: "+str(imdbIds))
em = discord.Embed(title=messageTitle,description=messageText,colour=0x00FF00)
@ -116,7 +116,7 @@ class BedreNetflix():
messageText += "Error"
imdbNames.append(show["title"])
self.bot.log("Returning a list of "+str(len(shows))+" possible shows: "+str(imdbNames), level = 10)
self.bot.log("Returning a list of "+str(len(shows))+" possible shows: "+str(imdbNames))
em = discord.Embed(title=messageTitle,description=messageText,colour=0x00FF00)
@ -380,5 +380,5 @@ class BedreNetflix():
else:
await ctx.send(messageText)
else:
await ctx.send("Invalid or repeated parameters. Use '!help downloading' to see valid parameters.")
await ctx.send("Invalid or repeated parameters. Use '/help downloading' to see valid parameters.")

View File

@ -45,7 +45,7 @@ class Other():
movie = searchResult[0]
imdbClient.update(movie)
self.bot.log("Successfully ran !movie")
self.bot.log("Successfully ran /movie")
title = movie["title"]
plot = movie['plot'][0].split("::")[0]

View File

@ -450,7 +450,7 @@ class StarWarsChar():
return "Couldn't find that data. Are you sure you spelled it correctly? (error code 944)"
else:
self.bot.log(user+" doesn't have a character (error code 943)")
return "You don't have a character. You can make one with !starwarscharacter (error code 943)"
return "You don't have a character. You can make one with /starwarscharacter (error code 943)"
def replaceSpaces(self,cmd : str):
withSpaces = ["Specialization Trees","Wound Threshold","Strain Threshold","Defense - Ranged","Defense - Melee","Force Rating","Core Worlds","Outer Rim","Piloting - Planetary","Piloting - Space","Ranged - Heavy","Ranged - Light","Lightsaber Characteristic","Critical Injuries","Force Powers"]

View File

@ -328,7 +328,7 @@ class StarWarsRoll():
self.bot.log("Converted skill to dice")
else:
self.bot.log("Okay, no they don't i guess (error code 912)")
return "You don't have a user. You can make one with !starwarscharacter (error code 912)"
return "You don't have a user. You can make one with /starwarscharacter (error code 912)"
elif string.capwords(commands[0]) in ["Ranged","Piloting"]:
self.bot.log("They fucked up writing the name of a ranged or piloting skill")