✨ Fully converted to slash commands
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import asyncio
|
||||
import discord
|
||||
|
||||
from funcs import logThis
|
||||
|
||||
class GameLoops():
|
||||
def __init__(self,bot):
|
||||
self.bot = bot
|
||||
@@ -16,7 +14,7 @@ class GameLoops():
|
||||
|
||||
for message in messages:
|
||||
oldMessage = await channel.fetch_message(int(message))
|
||||
logThis("Deleting old message")
|
||||
self.bot.log("Deleting old message", level = 10)
|
||||
await oldMessage.delete()
|
||||
except:
|
||||
oldMessage = ""
|
||||
@@ -31,22 +29,22 @@ class GameLoops():
|
||||
if channelId is None:
|
||||
channelId = str(ctx.channel_id)
|
||||
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = self.bot.connectFour.parseconnectFour(command,channelId, user)
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = self.bot.games.connectFour.parseconnectFour(command,channelId, user)
|
||||
|
||||
if hasattr(ctx, "send"):
|
||||
await ctx.send(response)
|
||||
else:
|
||||
await ctx.channel.send(response)
|
||||
logThis(response,channelId)
|
||||
self.bot.log(response, channelId, level = 10)
|
||||
if showImage:
|
||||
if deleteImage:
|
||||
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:
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = await self.bot.connectFour.connectFourAI(channelId)
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = await self.bot.games.connectFour.connectFourAI(channelId)
|
||||
await ctx.channel.send(response)
|
||||
logThis(response,channelId)
|
||||
self.bot.log(response,channelId, level = 10)
|
||||
if showImage:
|
||||
if deleteImage:
|
||||
await oldImage.delete()
|
||||
@@ -60,7 +58,7 @@ class GameLoops():
|
||||
await oldImage.add_reaction(reaction)
|
||||
|
||||
except:
|
||||
logThis("Image deleted before I could react to all of them")
|
||||
self.bot.log("Image deleted before I could react to all of them", level = 10)
|
||||
|
||||
else:
|
||||
with open("resources/games/oldImages/connectFour"+channelId, "w") as f:
|
||||
@@ -70,7 +68,7 @@ class GameLoops():
|
||||
for reaction in reactions:
|
||||
await oldImage.add_reaction(reaction)
|
||||
except:
|
||||
logThis("Image deleted before I could react to all of them")
|
||||
self.bot.log("Image deleted before I could react to all of them", level = 10)
|
||||
|
||||
if gameDone:
|
||||
game = self.bot.database["connect 4 games"].find_one({"_id":channelId})
|
||||
@@ -81,7 +79,7 @@ class GameLoops():
|
||||
|
||||
await oldImage.delete()
|
||||
except:
|
||||
logThis("The old image was already deleted")
|
||||
self.bot.log("The old image was already deleted")
|
||||
|
||||
winner = game["winner"]
|
||||
difficulty = int(game["difficulty"])
|
||||
@@ -90,19 +88,19 @@ class GameLoops():
|
||||
if game["players"][winner-1].lower() != "gwendolyn":
|
||||
self.bot.money.addMoney(game["players"][winner-1].lower(),reward)
|
||||
|
||||
self.bot.funcs.deleteGame("connect 4 games",channelId)
|
||||
self.bot.databaseFuncs.deleteGame("connect 4 games",channelId)
|
||||
|
||||
async def runHangman(self,channel,user,command = "start", ctx = None):
|
||||
try:
|
||||
response, showImage, deleteImage, remainingLetters = self.bot.hangman.parseHangman(str(channel.id),user,command)
|
||||
response, showImage, deleteImage, remainingLetters = self.bot.games.hangman.parseHangman(str(channel.id),user,command)
|
||||
except:
|
||||
logThis("Error parsing command (error code 1701)")
|
||||
self.bot.log("Error parsing command (error code 1701)")
|
||||
if response != "":
|
||||
if ctx is None:
|
||||
await channel.send(response)
|
||||
else:
|
||||
await ctx.send(response)
|
||||
logThis(response,str(channel.id))
|
||||
self.bot.log(response,str(channel.id), level = 10)
|
||||
if showImage:
|
||||
if deleteImage:
|
||||
await self.deleteMessage("hangman"+str(channel.id),channel)
|
||||
@@ -127,34 +125,34 @@ class GameLoops():
|
||||
emoji = chr(ord(letter)+127397)
|
||||
await message.add_reaction(emoji)
|
||||
except:
|
||||
logThis("Image deleted before adding all reactions")
|
||||
self.bot.log("Image deleted before adding all reactions", level = 10)
|
||||
|
||||
# Runs Hex
|
||||
async def runHex(self,ctx,command,user):
|
||||
channelId = ctx.channel_id
|
||||
try:
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = self.bot.hex.parseHex(command,str(channelId),user)
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = self.bot.games.hex.parseHex(command,str(channelId),user)
|
||||
except:
|
||||
logThis("Error parsing command (error code 1510)")
|
||||
self.bot.log("Error parsing command (error code 1510)")
|
||||
|
||||
await ctx.send(response)
|
||||
|
||||
logThis(response,str(channelId))
|
||||
self.bot.log(response,str(channelId), level = 10)
|
||||
if showImage:
|
||||
if deleteImage:
|
||||
try:
|
||||
oldImage = await self.deleteMessage("hex"+str(channelId),ctx.channel)
|
||||
except:
|
||||
logThis("Error deleting old image (error code 1501)")
|
||||
self.bot.log("Error deleting old image (error code 1501)")
|
||||
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(channelId))
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = self.bot.games.hex.hexAI(str(channelId))
|
||||
except:
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = "An AI error ocurred",False,False,False,False
|
||||
logThis("AI error (error code 1520)")
|
||||
self.bot.log("AI error (error code 1520)")
|
||||
await ctx.channel.send(response)
|
||||
logThis(response,str(channelId))
|
||||
self.bot.log(response,str(channelId), level = 10)
|
||||
if showImage:
|
||||
if deleteImage:
|
||||
await oldImage.delete()
|
||||
@@ -171,4 +169,4 @@ class GameLoops():
|
||||
winnings = game["difficulty"]*10
|
||||
self.bot.money.addMoney(game["players"][winner-1].lower(),winnings)
|
||||
|
||||
self.bot.funcs.deleteGame("hex games",str(channelId))
|
||||
self.bot.databaseFuncs.deleteGame("hex games",str(channelId))
|
||||
|
||||
Reference in New Issue
Block a user