🧹 Cleaning up cogs
This commit is contained in:
@ -170,7 +170,6 @@ class Blackjack():
|
||||
|
||||
return hand, allStanding, preAllStanding
|
||||
|
||||
|
||||
# When players try to hit
|
||||
def blackjackHit(self,channel,user,handNumber = 0):
|
||||
game = self.bot.database["blackjack games"].find_one({"_id":channel})
|
||||
@ -224,7 +223,6 @@ class Blackjack():
|
||||
self.bot.log(user+" tried to hit without being in the game")
|
||||
return "You have to enter the game before you can hit"
|
||||
|
||||
|
||||
# When players try to double down
|
||||
def blackjackDouble(self,channel,user,handNumber = 0):
|
||||
game = self.bot.database["blackjack games"].find_one({"_id":channel})
|
||||
@ -562,7 +560,6 @@ class Blackjack():
|
||||
|
||||
return finalWinnings
|
||||
|
||||
|
||||
def calcWinnings(self,hand, dealerValue, topLevel, dealerBlackjack, dealerBusted):
|
||||
self.bot.log("Calculating winnings")
|
||||
reason = ""
|
||||
@ -703,7 +700,7 @@ class Blackjack():
|
||||
else:
|
||||
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
|
||||
blackjackMinCards = 50
|
||||
blackjackDecks = 4
|
||||
|
@ -1,3 +1,5 @@
|
||||
import discord
|
||||
|
||||
class Invest():
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
@ -103,35 +105,48 @@ class Invest():
|
||||
else:
|
||||
return "no"
|
||||
|
||||
def parseInvest(self, content: str, user : str):
|
||||
if content.startswith("check"):
|
||||
commands = content.split(" ")
|
||||
async def parseInvest(self, ctx, parameters):
|
||||
try:
|
||||
await ctx.defer()
|
||||
except:
|
||||
self.bot.log("Defer failed")
|
||||
user = f"#{ctx.author.id}"
|
||||
|
||||
if parameters.startswith("check"):
|
||||
commands = parameters.split(" ")
|
||||
if len(commands) == 1:
|
||||
return self.getPortfolio(user)
|
||||
response = self.getPortfolio(user)
|
||||
else:
|
||||
price = self.getPrice(commands[1])
|
||||
if price == 0:
|
||||
return f"{commands[1].upper()} is not traded on the american market."
|
||||
response = f"{commands[1].upper()} is not traded on the american market."
|
||||
else:
|
||||
price = f"{price:,}".replace(",",".")
|
||||
return f"The current {commands[1].upper()} stock is valued at **{price}** GwendoBucks"
|
||||
response = f"The current {commands[1].upper()} stock is valued at **{price}** GwendoBucks"
|
||||
|
||||
elif content.startswith("buy"):
|
||||
commands = content.split(" ")
|
||||
elif parameters.startswith("buy"):
|
||||
commands = parameters.split(" ")
|
||||
if len(commands) == 3:
|
||||
#try:
|
||||
return self.buyStock(user,commands[1],int(commands[2]))
|
||||
#except:
|
||||
# return "The command must be given as \"/invest buy [stock] [amount of GwendoBucks to purchase with]\""
|
||||
response = self.buyStock(user,commands[1],int(commands[2]))
|
||||
else:
|
||||
return "You must give both a stock name and an amount of gwendobucks you wish to spend."
|
||||
response = "You must give both a stock name and an amount of gwendobucks you wish to spend."
|
||||
|
||||
elif content.startswith("sell"):
|
||||
commands = content.split(" ")
|
||||
elif parameters.startswith("sell"):
|
||||
commands = parameters.split(" ")
|
||||
if len(commands) == 3:
|
||||
try:
|
||||
return self.sellStock(user,commands[1],int(commands[2]))
|
||||
response = self.sellStock(user,commands[1],int(commands[2]))
|
||||
except:
|
||||
return "The command must be given as \"/invest sell [stock] [amount of GwendoBucks to sell stocks for]\""
|
||||
response = "The command must be given as \"/invest sell [stock] [amount of GwendoBucks to sell stocks for]\""
|
||||
else:
|
||||
return "You must give both a stock name and an amount of GwendoBucks you wish to sell stocks for."
|
||||
response = "You must give both a stock name and an amount of GwendoBucks you wish to sell stocks for."
|
||||
|
||||
else:
|
||||
response = "Incorrect parameters"
|
||||
|
||||
if response.startswith("**"):
|
||||
responses = response.split("\n")
|
||||
em = discord.Embed(title=responses[0],description="\n".join(responses[1:]),colour=0x00FF00)
|
||||
await ctx.send(embed=em)
|
||||
else:
|
||||
await ctx.send(response)
|
||||
|
@ -14,6 +14,15 @@ class Money():
|
||||
return userData["money"]
|
||||
else: return 0
|
||||
|
||||
async def sendBalance(self, ctx):
|
||||
await ctx.defer()
|
||||
response = self.checkBalance("#"+str(ctx.author.id))
|
||||
if response == 1:
|
||||
new_message = ctx.author.display_name + " has " + str(response) + " GwendoBuck"
|
||||
else:
|
||||
new_message = ctx.author.display_name + " has " + str(response) + " GwendoBucks"
|
||||
await ctx.send(new_message)
|
||||
|
||||
# Adds money to the account of a user
|
||||
def addMoney(self,user,amount):
|
||||
self.bot.log("adding "+str(amount)+" to "+user+"'s account")
|
||||
@ -26,26 +35,39 @@ class Money():
|
||||
self.database["users"].insert_one({"_id":user,"user name":self.bot.databaseFuncs.getName(user),"money":amount})
|
||||
|
||||
# Transfers money from one user to another
|
||||
def giveMoney(self,user,targetUser,amount):
|
||||
userData = self.database["users"].find_one({"_id":user})
|
||||
targetUser = self.bot.databaseFuncs.getID(targetUser)
|
||||
async def giveMoney(self, ctx, user, amount):
|
||||
try:
|
||||
await ctx.defer()
|
||||
except:
|
||||
self.bot.log("Defer failed")
|
||||
username = user.display_name
|
||||
if self.bot.databaseFuncs.getID(username) == None:
|
||||
async for member in ctx.guild.fetch_members(limit=None):
|
||||
if member.display_name.lower() == username.lower():
|
||||
username = member.display_name
|
||||
userID = "#" + str(member.id)
|
||||
newUser = {"_id":userID,"user name":username,"money":0}
|
||||
self.bot.database["users"].insert_one(newUser)
|
||||
|
||||
userData = self.database["users"].find_one({"_id":f"#{ctx.author.id}"})
|
||||
targetUser = self.bot.databaseFuncs.getID(username)
|
||||
|
||||
if amount > 0:
|
||||
if targetUser != None:
|
||||
if userData != None:
|
||||
if userData["money"] >= amount:
|
||||
self.addMoney(user,-1 * amount)
|
||||
self.addMoney(f"#{ctx.author.id}",-1 * amount)
|
||||
self.addMoney(targetUser,amount)
|
||||
return "Transferred "+str(amount)+" GwendoBucks to "+self.bot.databaseFuncs.getName(targetUser)
|
||||
await ctx.send(f"Transferred {amount} GwendoBucks to {username}")
|
||||
else:
|
||||
self.bot.log("They didn't have enough GwendoBucks (error code 1223b)")
|
||||
return "You don't have that many GwendoBucks (error code 1223b)"
|
||||
self.bot.log("They didn't have enough GwendoBucks")
|
||||
await ctx.send("You don't have that many GwendoBucks")
|
||||
else:
|
||||
self.bot.log("They didn't have enough GwendoBucks (error code 1223a)")
|
||||
return "You don't have that many GwendoBucks (error code 1223a)"
|
||||
self.bot.log("They didn't have enough GwendoBucks")
|
||||
await ctx.send("You don't have that many GwendoBuck")
|
||||
else:
|
||||
self.bot.log("They weren't in the system")
|
||||
return "The target doesn't exist"
|
||||
await ctx.send("The target doesn't exist")
|
||||
else:
|
||||
self.bot.log("They tried to steal")
|
||||
return "Yeah, no. You can't do that"
|
||||
await ctx.send("Yeah, no. You can't do that")
|
||||
|
@ -1,6 +1,7 @@
|
||||
import json
|
||||
import urllib
|
||||
import random
|
||||
import asyncio
|
||||
|
||||
class Trivia():
|
||||
def __init__(self, bot):
|
||||
@ -83,3 +84,38 @@ class Trivia():
|
||||
self.bot.log("Couldn't find the question (error code 1102)")
|
||||
|
||||
return None
|
||||
|
||||
async def triviaParse(self, ctx, answer):
|
||||
try:
|
||||
await ctx.defer()
|
||||
except:
|
||||
self.bot.log("defer failed")
|
||||
if answer == "":
|
||||
question, options, correctAnswer = self.triviaStart(str(ctx.channel_id))
|
||||
if options != "":
|
||||
results = "**"+question+"**\n"
|
||||
for x, option in enumerate(options):
|
||||
results += chr(x+97) + ") "+option+"\n"
|
||||
|
||||
await ctx.send(results)
|
||||
|
||||
await asyncio.sleep(60)
|
||||
|
||||
self.triviaCountPoints(str(ctx.channel_id))
|
||||
|
||||
self.bot.databaseFuncs.deleteGame("trivia questions",str(ctx.channel_id))
|
||||
|
||||
self.bot.log("Time's up for the trivia question",str(ctx.channel_id))
|
||||
await ctx.send("Time's up The answer was \""+chr(correctAnswer)+") "+options[correctAnswer-97]+"\". Anyone who answered that has gotten 1 GwendoBuck")
|
||||
else:
|
||||
await ctx.send(question, hidden=True)
|
||||
|
||||
elif answer in ["a","b","c","d"]:
|
||||
response = self.triviaAnswer("#"+str(ctx.author.id), str(ctx.channel_id), answer)
|
||||
if response.startswith("Locked in "):
|
||||
await ctx.send(f"{ctx.author.display_name} answered {answer})")
|
||||
else:
|
||||
await ctx.send(response)
|
||||
else:
|
||||
self.bot.log("I didn't understand that (error code 1101)",str(ctx.channel_id))
|
||||
await ctx.send("I didn't understand that (error code 1101)")
|
||||
|
Reference in New Issue
Block a user