🧹 Cleaning up cogs

This commit is contained in:
NikolajDanger
2021-03-31 16:53:37 +02:00
parent 92fe7913f7
commit aff29a8d91
10 changed files with 166 additions and 126 deletions

View File

@ -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")