:spakles: Database and OOP

This commit is contained in:
NikolajDanger
2020-08-13 16:31:28 +02:00
parent f431c079d1
commit 4127e537a1
31 changed files with 3674 additions and 3731 deletions

View File

@@ -1,7 +1,7 @@
import discord, asyncio
from discord.ext import commands
from funcs import logThis, triviaAnswer, triviaCountPoints, triviaStart, deleteGame, checkBalance, giveMoney, parseBlackjack, parseInvest, fiar, runMonopoly, runHex, runHangman
from funcs import logThis
class GamesCog(commands.Cog):
@@ -12,7 +12,7 @@ class GamesCog(commands.Cog):
# Checks user balance
@commands.command(aliases = ["b"])
async def balance(self, ctx):
response = checkBalance("#"+str(ctx.message.author.id))
response = self.client.money.checkBalance("#"+str(ctx.message.author.id))
if response == 1:
new_message = ctx.message.author.display_name + " has " + str(response) + " GwendoBuck"
else:
@@ -25,7 +25,7 @@ class GamesCog(commands.Cog):
commands = content.split(" ")
if len(commands) == 2:
amount = int(commands[1])
response = giveMoney("#"+str(ctx.message.author.id),commands[0],amount)
response = self.client.money.giveMoney("#"+str(ctx.message.author.id),commands[0],amount)
await ctx.send(response)
else:
logThis("I didn't understand that (error code 1222)",str(ctx.message.channel.id))
@@ -34,7 +34,7 @@ class GamesCog(commands.Cog):
# Invest GwendoBucks in the stock market
@commands.command(aliases=["i"])
async def invest(self, ctx, *, content = "check"):
response = parseInvest(content,"#"+str(ctx.message.author.id),self.client.finnhubClient)
response = self.client.invest.parseInvest(content,"#"+str(ctx.message.author.id))
if response.startswith("**"):
responses = response.split("\n")
em = discord.Embed(title=responses[0],description="\n".join(responses[1:]),colour=0x00FF00)
@@ -46,7 +46,7 @@ class GamesCog(commands.Cog):
@commands.command()
async def trivia(self, ctx, *, content = ""):
if content == "":
question, answers, correctAnswer = triviaStart(str(ctx.message.channel.id))
question, answers, correctAnswer = self.client.trivia.triviaStart(str(ctx.message.channel.id))
if answers != "":
results = "**"+question+"**\n"
for x, answer in enumerate(answers):
@@ -56,9 +56,9 @@ class GamesCog(commands.Cog):
await asyncio.sleep(60)
triviaCountPoints(str(ctx.message.channel.id))
self.client.trivia.triviaCountPoints(str(ctx.message.channel.id))
deleteGame("trivia questions",str(ctx.message.channel.id))
self.client.funcs.deleteGame("trivia questions",str(ctx.message.channel.id))
logThis("Time's up for the trivia question",str(ctx.message.channel.id))
await ctx.send("Time's up The answer was \""+chr(correctAnswer)+") "+answers[correctAnswer-97]+"\". Anyone who answered that has gotten 1 GwendoBuck")
@@ -66,7 +66,7 @@ class GamesCog(commands.Cog):
await ctx.send(question)
elif content in ["a","b","c","d"]:
response = triviaAnswer("#"+str(ctx.message.author.id),str(ctx.message.channel.id),content)
response = self.client.trivia.triviaAnswer("#"+str(ctx.message.author.id),str(ctx.message.channel.id),content)
if response.startswith("Locked in "):
await ctx.message.add_reaction("👍")
else:
@@ -78,27 +78,27 @@ class GamesCog(commands.Cog):
# Runs a game of blackjack
@commands.command(aliases = ["bj"])
async def blackjack(self, ctx, *, content = ""):
await parseBlackjack(content,ctx)
await self.client.blackjack.parseBlackjack(content,ctx)
# Runs a game of Connect four
@commands.command(aliases = ["fiar","connect4","connectfour","4iar","4inarow"])
async def fourinarow(self, ctx, *, content = ""):
await fiar(ctx.message.channel,content,"#"+str(ctx.message.author.id))
# Runs a game of Hex
@commands.command(name="hex")
async def hexCommand(self, ctx, *, content = ""):
await runHex(ctx.message.channel,content,"#"+str(ctx.message.author.id))
await self.client.gameLoops.fiar(ctx.message.channel,content,"#"+str(ctx.message.author.id))
# Runs a game of Monopoly
@commands.command(aliases = ["m","mon","mono"])
async def monopoly(self, ctx, *, content = ""):
await runMonopoly(ctx.message.channel,content,"#"+str(ctx.message.author.id))
await self.client.gameLoops.runMonopoly(ctx.message.channel,content,"#"+str(ctx.message.author.id))
# Runs a game of Hangman
@commands.command(aliases = ["hm"])
async def hangman(self, ctx, *, content = "start"):
await runHangman(ctx.message.channel,"#"+str(ctx.message.author.id),self.client.credentials.wordnikKey,content)
await self.client.gameLoops.runHangman(ctx.message.channel,"#"+str(ctx.message.author.id),content)
# Runs a game of Hex
@commands.command(name="hex")
async def hexCommand(self, ctx, *, content = ""):
await self.client.gameLoops.runHex(ctx.message.channel,content,"#"+str(ctx.message.author.id))
def setup(client):
client.add_cog(GamesCog(client))