🧹 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

@ -1,4 +1,4 @@
import os, finnhub, platform, asyncio import os, finnhub, platform, asyncio, discord
from discord.ext import commands from discord.ext import commands
from discord_slash import SlashCommand from discord_slash import SlashCommand
@ -26,9 +26,12 @@ class Gwendolyn(commands.Bot):
self.money = Money(self) self.money = Money(self)
self.databaseFuncs = databaseFuncs(self) self.databaseFuncs = databaseFuncs(self)
super().__init__(command_prefix=" ", case_insensitive=True) intents = discord.Intents.default()
intents.members = True
def log(self, messages, channel : str = "", level : int = 20): super().__init__(command_prefix=" ", case_insensitive=True, intents = intents)
def log(self, messages, channel : str = "", level : int = 10):
logThis(messages, channel, level) logThis(messages, channel, level)

View File

@ -8,14 +8,14 @@ class EventCog(commands.Cog):
# Sets the game and logs when the bot logs in # Sets the game and logs when the bot logs in
@commands.Cog.listener() @commands.Cog.listener()
async def on_ready(self): async def on_ready(self):
self.bot.log("Logged in as "+self.bot.user.name+", "+str(self.bot.user.id)) self.bot.log("Logged in as "+self.bot.user.name+", "+str(self.bot.user.id), level = 20)
game = discord.Game("Use /help for commands") game = discord.Game("Use /help for commands")
await self.bot.change_presence(activity=game) await self.bot.change_presence(activity=game)
# Logs when user sends a command # Logs when user sends a command
@commands.Cog.listener() @commands.Cog.listener()
async def on_slash_command(self, ctx): async def on_slash_command(self, ctx):
self.bot.log(f"{ctx.author.display_name} ran /{ctx.name}") self.bot.log(f"{ctx.author.display_name} ran /{ctx.name}", str(ctx.channel_id), level = 20)
# Logs if a command experiences an error # Logs if a command experiences an error
@commands.Cog.listener() @commands.Cog.listener()

View File

@ -25,11 +25,9 @@ class GamesCog(commands.Cog):
# Gives another user an amount of GwendoBucks # Gives another user an amount of GwendoBucks
@cog_ext.cog_slash(**params["give"]) @cog_ext.cog_slash(**params["give"])
async def give(self, ctx, parameters): async def give(self, ctx, user, amount):
await ctx.defer() await ctx.defer()
commands = parameters.split(" ") username = user.display_name
amount = int(commands[-1])
username = " ".join(commands[:-1])
if self.bot.databaseFuncs.getID(username) == None: if self.bot.databaseFuncs.getID(username) == None:
async for member in ctx.guild.fetch_members(limit=None): async for member in ctx.guild.fetch_members(limit=None):
if member.display_name.lower() == username.lower(): if member.display_name.lower() == username.lower():

View File

@ -12,7 +12,7 @@ class ReactionCog(commands.Cog):
if user.bot == False: if user.bot == False:
message = reaction.message message = reaction.message
channel = message.channel channel = message.channel
self.bot.log(f"{user.display_name} reacted to a message",str(channel.id), level = 10) self.bot.log(f"{user.display_name} reacted to a message",str(channel.id))
try: try:
connectFourTheirTurn, piece = self.bot.databaseFuncs.connectFourReactionTest(channel,message,"#"+str(user.id)) connectFourTheirTurn, piece = self.bot.databaseFuncs.connectFourReactionTest(channel,message,"#"+str(user.id))
except: except:

View File

@ -35,7 +35,7 @@ class Blackjack():
# Calculates the value of a blackjack hand # Calculates the value of a blackjack hand
def calcHandValue(self, hand : list): def calcHandValue(self, hand : list):
self.bot.log("Calculating hand value", level = 10) self.bot.log("Calculating hand value")
values = [] values = []
values.append(0) values.append(0)
@ -58,13 +58,13 @@ class Blackjack():
if value <= 21: if value <= 21:
handValue = value 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 return handValue
# Draws a card from the deck # Draws a card from the deck
def drawCard(self, channel): 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] drawnCard = self.bot.database["blackjack cards"].find_one({"_id":channel})["cards"][0]
self.bot.database["blackjack cards"].update_one({"_id":channel},{"$pop":{"cards":-1}}) 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 # Goes to the next round and calculates some stuff
def blackjackContinue(self, channel): 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}) game = self.bot.database["blackjack games"].find_one({"_id":channel})
done = False done = False
@ -116,7 +116,7 @@ class Blackjack():
game = self.bot.database["blackjack games"].find_one({"_id":channel}) 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"]: for user in game["user hands"]:
try: try:
newUser, allStanding, preAllStanding = self.testIfStanding(game["user hands"][user],allStanding,preAllStanding,True) newUser, allStanding, preAllStanding = self.testIfStanding(game["user hands"][user],allStanding,preAllStanding,True)
@ -141,10 +141,10 @@ class Blackjack():
return "", True, done return "", True, done
else: else:
if game["round"] == 1: 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: else:
firstRoundMessage = "" 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): def testIfStanding(self, hand,allStanding,preAllStanding,topLevel):
if hand["hit"] == False: if hand["hit"] == False:
@ -430,7 +430,7 @@ class Blackjack():
roundDone = self.isRoundDone(self.bot.database["blackjack games"].find_one({"_id":channel})) 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: else:
self.bot.log(user+" doesn't have enough GwendoBucks") self.bot.log(user+" doesn't have enough GwendoBucks")
return "You don'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): def calcWinnings(self,hand, dealerValue, topLevel, dealerBlackjack, dealerBusted):
self.bot.log("Calculating winnings", level = 10) self.bot.log("Calculating winnings")
reason = "" reason = ""
bet = hand["bet"] bet = hand["bet"]
winnings = -1 * bet winnings = -1 * bet
@ -659,14 +659,14 @@ class Blackjack():
# Loop of blackjack game rounds # Loop of blackjack game rounds
async def blackjackLoop(self,channel,gameRound,gameID): 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: with open("resources/games/oldImages/blackjack"+str(channel.id), "r") as f:
oldImage = await channel.fetch_message(int(f.read())) oldImage = await channel.fetch_message(int(f.read()))
new_message, allStanding, gamedone = self.blackjackContinue(str(channel.id)) new_message, allStanding, gamedone = self.blackjackContinue(str(channel.id))
if new_message != "": 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) await channel.send(new_message)
if gamedone == False: if gamedone == False:
await oldImage.delete() await oldImage.delete()
@ -699,9 +699,9 @@ class Blackjack():
self.bot.log("Something fucked up (error code 1310)") self.bot.log("Something fucked up (error code 1310)")
await channel.send(new_message) await channel.send(new_message)
else: 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: 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): async def parseBlackjack(self,content, ctx):
# Blackjack shuffle variables # Blackjack shuffle variables
@ -726,7 +726,7 @@ class Blackjack():
new_message = self.blackjackStart(str(channel)) new_message = self.blackjackStart(str(channel))
if new_message == "started": 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) await ctx.channel.send(new_message)
oldImage = await ctx.channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(channel)+".png")) 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 # Loop of game rounds
if gamedone == False: 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) await self.blackjackLoop(ctx.channel,1,gameID)
else: else:
new_message = self.blackjackFinish(str(channel)) new_message = self.blackjackFinish(str(channel))

View File

@ -9,7 +9,7 @@ class DrawBlackjack():
self.bot = bot self.bot = bot
def drawImage(self,channel): 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}) game = self.bot.database["blackjack games"].find_one({"_id":channel})
fnt = ImageFont.truetype('resources/fonts/futura-bold.ttf', 50) 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)+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) 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") table.save("resources/games/blackjackTables/blackjackTable"+channel+".png")
return return
def drawHand(self, hand, dealer, busted, blackjack): 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) fnt = ImageFont.truetype('resources/fonts/futura-bold.ttf', 200)
fnt2 = ImageFont.truetype('resources/fonts/futura-bold.ttf', 120) fnt2 = ImageFont.truetype('resources/fonts/futura-bold.ttf', 120)
length = len(hand) length = len(hand)

View File

@ -88,7 +88,7 @@ class connectFour():
turn = (game["turn"]+1)%2 turn = (game["turn"]+1)%2
self.bot.database["connect 4 games"].update_one({"_id":channel},{"$set":{"turn":turn}}) 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) won, winDirection, winCoordinates = self.isWon(board)
if won != 0: if won != 0:
@ -112,7 +112,7 @@ class connectFour():
gwendoTurn = False gwendoTurn = False
if game["players"][turn] == "Gwendolyn": 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 gwendoTurn = True
self.draw.drawImage(channel) self.draw.drawImage(channel)
@ -141,10 +141,10 @@ class connectFour():
def parseconnectFour(self, command, channel, user): def parseconnectFour(self, command, channel, user):
commands = command.split() commands = command.split()
if command == "" or command == " ": 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": elif commands[0] == "start":
# Starting a game # 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") commands.append("3")
return self.connectFourStart(channel,user,commands[1]) # commands[1] is the opponent return self.connectFourStart(channel,user,commands[1]) # commands[1] is the opponent
@ -165,7 +165,7 @@ class connectFour():
if user == game["players"][turn]: if user == game["players"][turn]:
piece = turn + 1 piece = turn + 1
else: 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 return "It's not your turn!", False, False, False, False
column = int(commands[1])-1 column = int(commands[1])-1
else: else:
@ -173,7 +173,7 @@ class connectFour():
piece = int(commands[1]) piece = int(commands[1])
return self.placePiece(channel, piece, column) return self.placePiece(channel, piece, column)
else: 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 # Checks if someone has won the game and returns the winner
def isWon(self, board): def isWon(self, board):
@ -235,7 +235,7 @@ class connectFour():
# Plays as the AI # Plays as the AI
async def connectFourAI(self, channel): 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}) game = self.bot.database["connect 4 games"].find_one({"_id":channel})
board = game["board"] board = game["board"]
@ -248,7 +248,7 @@ class connectFour():
testBoard = self.placeOnBoard(testBoard,player,column) testBoard = self.placeOnBoard(testBoard,player,column)
if testBoard != None: if testBoard != None:
scores[column] = await self.minimax(testBoard,difficulty,player%2+1,player,-math.inf,math.inf,False) 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() possibleScores = scores.copy()

View File

@ -8,7 +8,7 @@ class drawConnectFour():
# Draws the whole thing # Draws the whole thing
def drawImage(self, channel): 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}) game = self.bot.database["connect 4 games"].find_one({"_id":channel})
board = game["board"] board = game["board"]

View File

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

View File

@ -18,7 +18,7 @@ class Hangman():
while "-" in word or "." in word: while "-" in word or "." in word:
with urllib.request.urlopen(apiUrl+apiKey) as p: with urllib.request.urlopen(apiUrl+apiKey) as p:
word = list(json.load(p)[0]["word"].upper()) 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) guessed = [False] * len(word)
gameID = datetime.datetime.now().strftime('%Y%m%d%H%M%S') 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} 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 return background
def drawImage(self,channel): 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}) game = self.bot.database["hangman games"].find_one({"_id":channel})
random.seed(game["game ID"]) random.seed(game["game ID"])

View File

@ -22,13 +22,13 @@ class HexGame():
commands = command.lower().split() commands = command.lower().split()
game = self.bot.database["hex games"].find_one({"_id":channel}) game = self.bot.database["hex games"].find_one({"_id":channel})
if command == "" or command == " ": 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": elif commands[0] == "start":
# Starting a game # 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") 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 return self.hexStart(channel,user,commands[1]) # commands[1] is the opponent
# If using a command with no game, return error # If using a command with no game, return error
@ -47,7 +47,7 @@ class HexGame():
try: try:
return self.placeHex(channel,commands[1], user) return self.placeHex(channel,commands[1], user)
except: 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 # Undo
elif commands[0] == "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 return "You can only swap as the second player after the very first move.", False, False, False, False
else: 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 # Starts the game
def hexStart(self, channel, user, opponent): def hexStart(self, channel, user, opponent):
@ -142,7 +142,7 @@ class HexGame():
if player == turn: if player == turn:
board = game["board"] 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 # Places on board
board = self.placeOnHexBoard(board,player,position) board = self.placeOnHexBoard(board,player,position)
@ -153,7 +153,7 @@ class HexGame():
self.bot.database["hex games"].update_one({"_id":channel},{"$set":{"turn":turn}}) self.bot.database["hex games"].update_one({"_id":channel},{"$set":{"turn":turn}})
# Checking for a win # Checking for a win
self.bot.log("Checking for win", level = 10) self.bot.log("Checking for win")
winner = self.evaluateBoard(game["board"])[1] winner = self.evaluateBoard(game["board"])[1]
if winner == 0: # Continue with the game. if winner == 0: # Continue with the game.
@ -174,7 +174,7 @@ class HexGame():
# Is it now Gwendolyn's turn? # Is it now Gwendolyn's turn?
gwendoTurn = False gwendoTurn = False
if game["players"][turn-1] == "Gwendolyn": 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 gwendoTurn = True
# Update the board # Update the board
@ -226,7 +226,7 @@ class HexGame():
turn = game["turn"] turn = game["turn"]
# You can only undo after your turn, which is the opponent's 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 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() lastMove = game["gameHistory"].pop()
game["board"][lastMove[0]][lastMove[1]] = 0 game["board"][lastMove[0]][lastMove[1]] = 0
@ -251,7 +251,7 @@ class HexGame():
# Plays as the AI # Plays as the AI
def hexAI(self, channel): 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}) game = self.bot.database["hex games"].find_one({"_id":channel})
board = game["board"] board = game["board"]
@ -293,7 +293,7 @@ class HexGame():
chosenMove = (i // BOARDWIDTH , i % BOARDWIDTH) chosenMove = (i // BOARDWIDTH , i % BOARDWIDTH)
""" """
placement = "abcdefghijk"[chosenMove[1]]+str(chosenMove[0]+1) 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") 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. 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 break
else: 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: if scores[player] == 0:
winner = player winner = player
break # We don't need to check the other player's score, if player1 won. break # We don't need to check the other player's score, if player1 won.

View File

@ -122,7 +122,7 @@ class Invest():
#try: #try:
return self.buyStock(user,commands[1],int(commands[2])) return self.buyStock(user,commands[1],int(commands[2]))
#except: #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: else:
return "You must give both a stock name and an amount of gwendobucks you wish to spend." return "You must give both a stock name and an amount of gwendobucks you wish to spend."
@ -132,6 +132,6 @@ class Invest():
try: try:
return self.sellStock(user,commands[1],int(commands[2])) return self.sellStock(user,commands[1],int(commands[2]))
except: 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: else:
return "You must give both a stock name and an amount of GwendoBucks you wish to sell stocks for." 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 # Returns the account balance for a user
def checkBalance(self, 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}) userData = self.database["users"].find_one({"_id":user})
@ -16,7 +16,7 @@ class Money():
# Adds money to the account of a user # Adds money to the account of a user
def addMoney(self,user,amount): 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}) userData = self.database["users"].find_one({"_id":user})

View File

@ -135,5 +135,5 @@ class LookupFuncs():
else: else:
self.bot.log("I don't know that spell (error code 501)") 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)" 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) return(spell_output)

View File

@ -40,7 +40,7 @@ class BedreNetflix():
messageText += "Error" messageText += "Error"
imdbIds.append(movie.movieID) 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) em = discord.Embed(title=messageTitle,description=messageText,colour=0x00FF00)
@ -116,7 +116,7 @@ class BedreNetflix():
messageText += "Error" messageText += "Error"
imdbNames.append(show["title"]) 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) em = discord.Embed(title=messageTitle,description=messageText,colour=0x00FF00)
@ -380,5 +380,5 @@ class BedreNetflix():
else: else:
await ctx.send(messageText) await ctx.send(messageText)
else: 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] movie = searchResult[0]
imdbClient.update(movie) imdbClient.update(movie)
self.bot.log("Successfully ran !movie") self.bot.log("Successfully ran /movie")
title = movie["title"] title = movie["title"]
plot = movie['plot'][0].split("::")[0] 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)" return "Couldn't find that data. Are you sure you spelled it correctly? (error code 944)"
else: else:
self.bot.log(user+" doesn't have a character (error code 943)") 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): 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"] 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") self.bot.log("Converted skill to dice")
else: else:
self.bot.log("Okay, no they don't i guess (error code 912)") 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"]: elif string.capwords(commands[0]) in ["Ranged","Piloting"]:
self.bot.log("They fucked up writing the name of a ranged or piloting skill") self.bot.log("They fucked up writing the name of a ranged or piloting skill")

View File

@ -108,5 +108,5 @@ Things you should know about the logging:
### Logging rules ### Logging rules
1. Never call the `logThis()` function from `/utils/utilFuncs/`. Always call `bot.log`. 1. Never call the `logThis()` function from `/utils/utilFuncs/`. Always call `bot.log`.
1. There should be at most 3 `INFO` level logs while executing a single command. This includes the log created in the `on_command()` function in `Gwendolyn.py`, so your code for a command can at most make 2 logs of level `INFO`. `DEBUG` level logs should be used for all other logging. 1. The `on_slash_command()` and `on_ready()` events are the only times log should be called at level 20.`DEBUG` level logs should be used for all other logging.
1. Always provide the channel id if available. Although you shouldn't pass the channel id to a function purely to use it in logs. 1. Always provide the channel id if available. Although you shouldn't pass the channel id to a function purely to use it in logs.

View File

@ -1 +1 @@
Du kan søge efter en film ved at skrive `!addmovie [søgning]`. Gwendolyn vil derefter vise dig resultater baseret på din søgning. Du kan derfra reagere på Gwendolyns besked for at downloade en specifik film. Du kan søge efter en film ved at skrive `/addmovie [søgning]`. Gwendolyn vil derefter vise dig resultater baseret på din søgning. Du kan derfra reagere på Gwendolyns besked for at downloade en specifik film.

View File

@ -1 +1 @@
Du kan søge efter et show ved at skrive `!addshow [søgning]`. Gwendolyn vil derefter vise dig resultater baseret på din søgning. Du kan derfra reagere på Gwendolyns besked for at downloade et specifikt show. Du kan søge efter et show ved at skrive `/addshow [søgning]`. Gwendolyn vil derefter vise dig resultater baseret på din søgning. Du kan derfra reagere på Gwendolyns besked for at downloade et specifikt show.

View File

@ -1 +1 @@
Kommandoen `!blackjack` starter et spil blackjack. `!blackjack bet [beløb]` lader dig vædde en mængde af dine GwendoBucks. Du bruger `!blackjack hit`, `!blackjack stand`, `!blackjack split` og `!blackjack double` i løbet af spillet. Kommandoen `/blackjack` starter et spil blackjack. `/blackjack bet [beløb]` lader dig vædde en mængde af dine GwendoBucks. Du bruger `/blackjack hit`, `/blackjack stand`, `/blackjack split` og `/blackjack double` i løbet af spillet.

View File

@ -1 +1 @@
Brug `!connectFour start` til at starte et spil imod Gwendolyn. Brug `!connectFour start [modstander]` for at spille imod en anden person. Du kan også bruge `!connectFour start [1-5]`, hvor tallet er sværhedsgraden af Gwendolyn du gerne vil spille imod. Brug `/connectFour start` til at starte et spil imod Gwendolyn. Brug `/connectFour start [modstander]` for at spille imod en anden person. Du kan også bruge `/connectFour start [1-5]`, hvor tallet er sværhedsgraden af Gwendolyn du gerne vil spille imod.

View File

@ -1 +1 @@
Du kan give GwendoBucks til andre med `!give [modtager] [antal]`, hvor [modtager] er den der skal modtage GwendoBucks og [antal] er hvor mange GwendoBucks du giver dem. Du kan give GwendoBucks til andre med `/give [modtager] [antal]`, hvor [modtager] er den der skal modtage GwendoBucks og [antal] er hvor mange GwendoBucks du giver dem.

View File

@ -1 +1 @@
Brug `!hangman` til at starte et spil hangman. Brug derefter reaktionerne til at gætte bogstaver. Du har 6 gæt. Brug `/hangman` til at starte et spil hangman. Brug derefter reaktionerne til at gætte bogstaver. Du har 6 gæt.

View File

@ -1 +1 @@
Hvis du bruger kommandoen `!hello`, sender Gwendolyn en venlig hilsen. Hvis du bruger kommandoen `/hello`, sender Gwendolyn en venlig hilsen.

View File

@ -1 +1 @@
Brug `!hex start` til at starte et spil imod Gwendolyn. Brug "!hex start [modstander]" for at spille imod en anden person. Brug `/hex start` til at starte et spil imod Gwendolyn. Brug "/hex start [modstander]" for at spille imod en anden person.

View File

@ -1,3 +1,3 @@
`!invest` vil vise dig hvilke aktier du har. `!invest check [symbol]` viser dig en akties nuværende pris, hvor [symbol] er forkortelsen for firmaet. GwendoBucks er lig med 1 amerikans cent. `/invest` vil vise dig hvilke aktier du har. `/invest check [symbol]` viser dig en akties nuværende pris, hvor [symbol] er forkortelsen for firmaet. GwendoBucks er lig med 1 amerikans cent.
`!invest buy [symbol] [pris]` lader dig købe aktier. [pris] er mængden af GwendoBucks du bruger på at købe. Du kan købe for færre GwendoBucks end en enkelt akties pris, men ikke for mindre end 100 GwendoBucks. `/invest buy [symbol] [pris]` lader dig købe aktier. [pris] er mængden af GwendoBucks du bruger på at købe. Du kan købe for færre GwendoBucks end en enkelt akties pris, men ikke for mindre end 100 GwendoBucks.
`!invest buy [symbol] [pris]` lader dig sælge dine aktier. Du kan godt sælge for mindre end 100 GwendoBucks. `/invest buy [symbol] [pris]` lader dig sælge dine aktier. Du kan godt sælge for mindre end 100 GwendoBucks.

View File

@ -1,2 +1,2 @@
Søg efter et monster i D&D med `!monster [monster]`, hvor [monster] er navnet på det monster du søger efter. Søg efter et monster i D&D med `/monster [monster]`, hvor [monster] er navnet på det monster du søger efter.
Hvis Gwendolyn ikke kan finde det, er det ofte fordi du har skrevet navnet forkert. Hvis Gwendolyn ikke kan finde det, er det ofte fordi du har skrevet navnet forkert.

View File

@ -1,2 +1,2 @@
Søg efter en spell i D&D med `!spell [spell]`, hvor [spell] er navnet på den spell du søger efter. Søg efter en spell i D&D med `/spell [spell]`, hvor [spell] er navnet på den spell du søger efter.
Hvis Gwendolyn ikke kan finde den, er det ofte fordi du har skrevet navnet forkert. Hvis Gwendolyn ikke kan finde den, er det ofte fordi du har skrevet navnet forkert.

View File

@ -1 +1 @@
Du kan bruge kommandoer som `!starWarsCharacter name Jared` eller `!starWarsCharacter skills astrogation 3` til at ændre din karakters info. Kommandoen `!starWarsCharacter` vil give dig et character sheet for din karakter. Du kan bruge kommandoer som `/starWarsCharacter name Jared` eller `/starWarsCharacter skills astrogation 3` til at ændre din karakters info. Kommandoen `/starWarsCharacter` vil give dig et character sheet for din karakter.

View File

@ -1 +1 @@
Lader dig rulle Star Wars terninger. Du kan skrive tal der repræsenterer antallet af hver terning i rækkefølgen: ability, proficiency, difficulty, challenge, boost, setback og force. Du behøver ikke skrive et tal til alle terningerne. Du kan også skrive forbogstavet for terningen du vil rulle før antallet, såsom "!starWarsRoll f2", der ruller 2 force terninger. Lader dig rulle Star Wars terninger. Du kan skrive tal der repræsenterer antallet af hver terning i rækkefølgen: ability, proficiency, difficulty, challenge, boost, setback og force. Du behøver ikke skrive et tal til alle terningerne. Du kan også skrive forbogstavet for terningen du vil rulle før antallet, såsom "/starWarsRoll f2", der ruller 2 force terninger.

View File

@ -1,4 +1,4 @@
Lader dig spille et spil trivia. `!trivia` starter spillet. Lader dig spille et spil trivia. `/trivia` starter spillet.
Hvert spil trivia varer i 1 minut, og der kan kun være et enkelt spil i hver kanal ad gangen. Hvert spil trivia varer i 1 minut, og der kan kun være et enkelt spil i hver kanal ad gangen.
`!trivia [svar]` lader dig svare på det nuværende spørgsmål, hvor [svar] er a, b, c eller d. `/trivia [svar]` lader dig svare på det nuværende spørgsmål, hvor [svar] er a, b, c eller d.
Hvis du svarer rigtigt får du 1 GwendoBuck. Hvis du svarer rigtigt får du 1 GwendoBuck.

View File

@ -1,24 +1,24 @@
`!hello` - En venlig hilsen. `/hello` - En venlig hilsen.
`!roll` - Rul terninger i xdy format. `/roll` - Rul terninger i xdy format.
`!spell` - Slå en besværgelse op. `/spell` - Slå en besværgelse op.
`!monster` - Slå et monster op. `/monster` - Slå et monster op.
`!image` - Finder et tilfældigt billede fra internettet. `/image` - Finder et tilfældigt billede fra internettet.
`!movie` - Giver titlen på en tilfældig film fra Bedre Netflix `/movie` - Giver titlen på en tilfældig film fra Bedre Netflix
`!name` - Genererer et tilfældigt navn. `/name` - Genererer et tilfældigt navn.
`!tavern` - Genererer en tilfældig tavern. `/tavern` - Genererer en tilfældig tavern.
`!give` - Lader dig give GwendoBucks til andre. `/give` - Lader dig give GwendoBucks til andre.
`!starWarsCharacter` - Lader dig lave en Star Wars karakter. `/starWarsCharacter` - Lader dig lave en Star Wars karakter.
`!starWarsRoll` - Lader dig rulle Star Wars terninger. `/starWarsRoll` - Lader dig rulle Star Wars terninger.
`!balance` - Viser dig hvor mange GwendoBucks du har. `/balance` - Viser dig hvor mange GwendoBucks du har.
`!invest` - Lader dig investere dine GwendoBucks i aktiemarkedet. `/invest` - Lader dig investere dine GwendoBucks i aktiemarkedet.
`!blackjack` - Lader dig spille et spil blackjack. `/blackjack` - Lader dig spille et spil blackjack.
`!trivia` - Lader dig spille et spil trivia, hvor du kan tjene GwendoBucks. `/trivia` - Lader dig spille et spil trivia, hvor du kan tjene GwendoBucks.
`!connectFour` - Lader dig spille et spil fire på stribe. `/connectFour` - Lader dig spille et spil fire på stribe.
`!hex` - Lader dig spille et spil Hex. `/hex` - Lader dig spille et spil Hex.
`!hangman` - Lader dig spille et spil hangman. `/hangman` - Lader dig spille et spil hangman.
`!wolf` - Lader dig slå ting op på Wolfram Alpha. `/wolf` - Lader dig slå ting op på Wolfram Alpha.
`!addmovie` - Lader dig tilføje film til Bedre Netflix. `/addmovie` - Lader dig tilføje film til Bedre Netflix.
`!addshow` - Lader dig tilføje tv shows til Bedre Netflix. `/addshow` - Lader dig tilføje tv shows til Bedre Netflix.
`!downloading` - Viser dig hvor langt de torrents der er ved at downloade er kommet. `/downloading` - Viser dig hvor langt de torrents der er ved at downloade er kommet.
`!thank` - Lader dig takke Gwendolyn. `/thank` - Lader dig takke Gwendolyn.
Du kan få ekstra information om kommandoerne med "!help [kommando]". Du kan få ekstra information om kommandoerne med "/help [kommando]".

View File

@ -146,9 +146,15 @@
"description" : "Give GwendoBucks to another user", "description" : "Give GwendoBucks to another user",
"options" : [ "options" : [
{ {
"name" : "parameters", "name" : "user",
"description" : "The user and amount of GwendoBucks you're sending", "description" : "The user you're sending GwendoBucks to",
"type" : 3, "type" : 6,
"required" : "true"
},
{
"name" : "amount",
"description" : "The number of GwendoBucks you're sending",
"type" : 4,
"required" : "true" "required" : "true"
} }
] ]

View File

@ -90,7 +90,7 @@ class databaseFuncs():
oldImage = int(f.read()) oldImage = int(f.read())
if message.id == oldImage: if message.id == oldImage:
self.bot.log("They reacted to the connectFour game", level = 10) self.bot.log("They reacted to the connectFour game")
turn = game["turn"] turn = game["turn"]
if user == game["players"][turn]: if user == game["players"][turn]:
return True, turn+1 return True, turn+1
@ -111,7 +111,7 @@ class databaseFuncs():
for oldMessage in oldMessages: for oldMessage in oldMessages:
oldMessageID = int(oldMessage) oldMessageID = int(oldMessage)
if message.id == oldMessageID: if message.id == oldMessageID:
self.bot.log("They reacted to the hangman game", level = 10) self.bot.log("They reacted to the hangman game")
gameMessage = True gameMessage = True
return gameMessage return gameMessage