: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))

View File

@ -1,7 +1,7 @@
import discord, codecs, string
from discord.ext import commands
from funcs import logThis, stopServer, helloFunc, roll_dice, imageFunc, nameGen, tavernGen, movieFunc, cap, findWikiPage
from funcs import logThis, helloFunc, roll_dice, imageFunc, nameGen, tavernGen, movieFunc, cap, findWikiPage
class MiscCog(commands.Cog):
@ -40,7 +40,7 @@ class MiscCog(commands.Cog):
if "#"+str(ctx.message.author.id) in ["#266269899859427329", "#380732645602230272"]:
await ctx.send("Pulling git repo and restarting...")
stopServer()
self.client.funcs.stopServer()
await self.client.logout()
else:

View File

@ -1,6 +1,6 @@
from discord.ext import commands
from funcs import logThis, fiarReactionTest, monopolyReactionTest, emojiToCommand, fiar, runMonopoly, hangmanReactionTest, runHangman
from funcs import logThis, emojiToCommand
class ReactionCog(commands.Cog):
def __init__(self, client):
@ -14,17 +14,17 @@ class ReactionCog(commands.Cog):
channel = message.channel
logThis(user.display_name+" reacted to a message",str(channel.id))
try:
fourInARowTheirTurn, piece = fiarReactionTest(channel,message,"#"+str(user.id))
fourInARowTheirTurn, piece = self.client.funcs.fiarReactionTest(channel,message,"#"+str(user.id))
except:
fourInARowTheirTurn = False
if fourInARowTheirTurn:
place = emojiToCommand(reaction.emoji)
await fiar(channel," place "+str(piece)+" "+str(place),user.id)
elif monopolyReactionTest(channel,message):
await runMonopoly(channel,"roll","#"+str(user.id))
elif hangmanReactionTest(channel,message):
await self.client.gameLoops.fiar(channel," place "+str(piece)+" "+str(place),user.id)
elif self.client.funcs.monopolyReactionTest(channel,message):
await self.client.gameLoops.runMonopoly(channel,"roll","#"+str(user.id))
elif self.client.funcs.hangmanReactionTest(channel,message):
guess = chr(ord(reaction.emoji)-127397)
await runHangman(channel,"#"+str(user.id),command="guess "+guess)
await self.client.gameLoops.runHangman(channel,"#"+str(user.id),command="guess "+guess)
def setup(client):
client.add_cog(ReactionCog(client))

View File

@ -1,7 +1,7 @@
import discord, string
from discord.ext import commands
from funcs import parseRoll, parseDestiny, critRoll, parseChar, cap
from funcs import cap
class SwCog(commands.Cog):
@ -13,7 +13,7 @@ class SwCog(commands.Cog):
@commands.command()
async def swroll(self, ctx, *, content):
command = cap(content)
newMessage = parseRoll("#"+str(ctx.message.author.id),command)
newMessage = self.client.swroll.parseRoll("#"+str(ctx.message.author.id),command)
messageList = newMessage.split("\n")
for messageItem in messageList:
await ctx.send(messageItem)
@ -21,7 +21,7 @@ class SwCog(commands.Cog):
# Controls destiny points
@commands.command()
async def swd(self, ctx, *, content):
newMessage = parseDestiny("#"+str(ctx.message.author.id),content)
newMessage = self.client.swdestiny.parseDestiny("#"+str(ctx.message.author.id),content)
messageList = newMessage.split("\n")
for messageItem in messageList:
await ctx.send(messageItem)
@ -29,7 +29,7 @@ class SwCog(commands.Cog):
# Rolls for critical injuries
@commands.command()
async def swcrit(self, ctx, arg : int = 0):
newMessage = critRoll(int(arg))
newMessage = self.client.swroll.critRoll(int(arg))
messageList = newMessage.split("\n")
for messageItem in messageList:
@ -40,7 +40,7 @@ class SwCog(commands.Cog):
@commands.command(aliases=["sw"])
async def swchar(self, ctx, *, content = ""):
command = string.capwords(content.replace("+","+ ").replace("-","- ").replace(",",", "))
title, desc = parseChar("#"+str(ctx.message.author.id),command)
title, desc = self.client.swchar.parseChar("#"+str(ctx.message.author.id),command)
if title != "":
em1 = discord.Embed(title = title, description = desc, colour=0xDEADBF)
await ctx.send(embed = em1)