Even more converting to slash commands

This commit is contained in:
NikolajDanger
2021-03-29 17:01:01 +02:00
parent 232f97d0c8
commit e8c7fb95e5
22 changed files with 487 additions and 191 deletions

View File

@ -23,36 +23,36 @@ class GameLoops():
return oldMessage
# Runs Four in a Row
async def fiar(self, channel,command,user):
try:
response, showImage, deleteImage, gameDone, gwendoTurn = self.bot.fourInARow.parseFourInARow(command,str(channel.id),user)
except:
logThis("Error parsing command (error code 1410)")
# Runs connect four
async def connectFour(self, ctx, command, user = None, channelId = None):
if user is None:
user = "#"+str(ctx.author.id)
await channel.send(response)
logThis(response,str(channel.id))
if channelId is None:
channelId = str(ctx.channel_id)
response, showImage, deleteImage, gameDone, gwendoTurn = self.bot.connectFour.parseconnectFour(command,channelId, user)
if hasattr(ctx, "send"):
await ctx.send(response)
else:
await ctx.channel.send(response)
logThis(response,channelId)
if showImage:
if deleteImage:
try:
oldImage = await self.deleteMessage("fourInARow"+str(channel.id),channel)
except:
logThis("Error deleting message (error code 1401)")
oldImage = await channel.send(file = discord.File("resources/games/4InARowBoards/board"+str(channel.id)+".png"))
oldImage = await self.deleteMessage("connectFour"+channelId,ctx.channel)
oldImage = await ctx.channel.send(file = discord.File("resources/games/connect4Boards/board"+channelId+".png"))
if gameDone == False:
if gwendoTurn:
try:
response, showImage, deleteImage, gameDone, gwendoTurn = await self.bot.fourInARow.fourInARowAI(str(channel.id))
except:
logThis("AI error (error code 1420)")
await channel.send(response)
logThis(response,str(channel.id))
response, showImage, deleteImage, gameDone, gwendoTurn = await self.bot.connectFour.connectFourAI(channelId)
await ctx.channel.send(response)
logThis(response,channelId)
if showImage:
if deleteImage:
await oldImage.delete()
oldImage = await channel.send(file = discord.File("resources/games/4InARowBoards/board"+str(channel.id)+".png"))
oldImage = await ctx.channel.send(file = discord.File("resources/games/connect4Boards/board"+channelId+".png"))
if gameDone == False:
with open("resources/games/oldImages/fourInARow"+str(channel.id), "w") as f:
with open("resources/games/oldImages/connectFour"+channelId, "w") as f:
f.write(str(oldImage.id))
try:
reactions = ["1","2","3","4","5","6","7"]
@ -63,7 +63,7 @@ class GameLoops():
logThis("Image deleted before I could react to all of them")
else:
with open("resources/games/oldImages/fourInARow"+str(channel.id), "w") as f:
with open("resources/games/oldImages/connectFour"+channelId, "w") as f:
f.write(str(oldImage.id))
try:
reactions = ["1","2","3","4","5","6","7"]
@ -73,10 +73,10 @@ class GameLoops():
logThis("Image deleted before I could react to all of them")
if gameDone:
game = self.bot.database["4 in a row games"].find_one({"_id":str(channel.id)})
game = self.bot.database["connect 4 games"].find_one({"_id":channelId})
try:
with open("resources/games/oldImages/fourInARow"+str(channel.id), "r") as f:
with open("resources/games/oldImages/connectFour"+channelId, "r") as f:
oldImage = await channel.fetch_message(int(f.read()))
await oldImage.delete()
@ -90,15 +90,18 @@ class GameLoops():
if game["players"][winner-1].lower() != "gwendolyn":
self.bot.money.addMoney(game["players"][winner-1].lower(),reward)
self.bot.funcs.deleteGame("4 in a row games",str(channel.id))
self.bot.funcs.deleteGame("connect 4 games",channelId)
async def runHangman(self,channel,user,command = "start"):
async def runHangman(self,channel,user,command = "start", ctx = None):
try:
response, showImage, deleteImage, remainingLetters = self.bot.hangman.parseHangman(str(channel.id),user,command)
except:
logThis("Error parsing command (error code 1701)")
if response != "":
await channel.send(response)
if ctx is None:
await channel.send(response)
else:
await ctx.send(response)
logThis(response,str(channel.id))
if showImage:
if deleteImage:
@ -127,44 +130,45 @@ class GameLoops():
logThis("Image deleted before adding all reactions")
# Runs Hex
async def runHex(self,channel,command,user):
async def runHex(self,ctx,command,user):
channelId = ctx.channel_id
try:
response, showImage, deleteImage, gameDone, gwendoTurn = self.bot.hex.parseHex(command,str(channel.id),user)
response, showImage, deleteImage, gameDone, gwendoTurn = self.bot.hex.parseHex(command,str(channelId),user)
except:
logThis("Error parsing command (error code 1510)")
await channel.send(response)
await ctx.send(response)
logThis(response,str(channel.id))
logThis(response,str(channelId))
if showImage:
if deleteImage:
try:
oldImage = await self.deleteMessage("hex"+str(channel.id),channel)
oldImage = await self.deleteMessage("hex"+str(channelId),ctx.channel)
except:
logThis("Error deleting old image (error code 1501)")
oldImage = await channel.send(file = discord.File("resources/games/hexBoards/board"+str(channel.id)+".png"))
oldImage = await ctx.channel.send(file = discord.File("resources/games/hexBoards/board"+str(channelId)+".png"))
if gwendoTurn and not gameDone:
try:
response, showImage, deleteImage, gameDone, gwendoTurn = self.bot.hex.hexAI(str(channel.id))
response, showImage, deleteImage, gameDone, gwendoTurn = self.bot.hex.hexAI(str(channelId))
except:
response, showImage, deleteImage, gameDone, gwendoTurn = "An AI error occured",False,False,False,False
response, showImage, deleteImage, gameDone, gwendoTurn = "An AI error ocurred",False,False,False,False
logThis("AI error (error code 1520)")
await channel.send(response)
logThis(response,str(channel.id))
await ctx.channel.send(response)
logThis(response,str(channelId))
if showImage:
if deleteImage:
await oldImage.delete()
oldImage = await channel.send(file = discord.File("resources/games/hexBoards/board"+str(channel.id)+".png"))
oldImage = await ctx.channel.send(file = discord.File("resources/games/hexBoards/board"+str(channelId)+".png"))
if not gameDone:
with open("resources/games/oldImages/hex"+str(channel.id), "w") as f:
with open("resources/games/oldImages/hex"+str(channelId), "w") as f:
f.write(str(oldImage.id))
if gameDone:
game = self.bot.database["hex games"].find_one({"_id":str(channel.id)})
game = self.bot.database["hex games"].find_one({"_id":str(channelId)})
winner = game["winner"]
if winner != 0 and game["players"][0] != game["players"][1]: # player1 != player2
winnings = game["difficulty"]*10
self.bot.money.addMoney(game["players"][winner-1].lower(),winnings)
self.bot.funcs.deleteGame("hex games",str(channel.id))
self.bot.funcs.deleteGame("hex games",str(channelId))