async def defense(self, ctx): """ Command that upgrades the user's bank defense, increasing chance of failed robs by others. :param ctx: Discord Context """ response = currency.getOrAddUser(ctx.author.id) defense = int(response[6]) defenseLevelPrice = math.floor( math.pow(1.4, defense) * 365) if defense < 38 else 5 * calcCapacity(defense - 6) # Check if user has enough Didier Dinks to do this if float(response[1]) >= defenseLevelPrice: currency.update(ctx.author.id, "dinks", float(response[1]) - defenseLevelPrice) currency.update(ctx.author.id, "defense", int(response[6]) + 1) await ctx.send( "**{}** heeft de security van zijn bank geüpgradet naar level **{}**!" .format(ctx.author.display_name, int(response[6]) + 1)) else: await ctx.send( "Je hebt niet genoeg Didier Dinks om dit te doen, **{}**.". format(ctx.author.display_name))
async def invest(self, ctx, *amount: Abbreviated): """ Command that invests Didier Dinks into the user's bank. :param ctx: Discord Context :param amount: the amount of Didier Dinks to invest """ # Tuples don't support assignment amount = list(amount) if len(amount) != 1: await ctx.send("Geef een geldig bedrag op.") elif not checks.isValidAmount(ctx, amount[0])[0]: await ctx.send(checks.isValidAmount(ctx, amount[0])[1]) else: user = currency.getOrAddUser(ctx.author.id) if str(amount[0]).lower() == "all": amount[0] = user[1] amount[0] = float(amount[0]) currency.update(ctx.author.id, "investedamount", float(user[3]) + amount[0]) currency.update(ctx.author.id, "dinks", float(user[1]) - amount[0]) await ctx.send( "**{}** heeft **{:,}** Didier Dink{} geïnvesteerd!".format( ctx.author.display_name, math.floor(amount[0]), checks.pluralS(amount[0])))
async def stats(self, ctx): """ Command that shows the user's bank stats. :param ctx: Discord Context """ response = currency.getOrAddUser(ctx.author.id) # Calculate the prices to level stats up defense = int(response[6]) defenseLevelPrice = math.floor( math.pow(1.4, defense) * 365) if defense < 38 else 5 * calcCapacity(defense - 6) offense = int(response[7]) capacity = calcCapacity(offense) offenseLevelPrice = math.floor(math.pow(1.5, offense) * 369) if offense < 32 else 5 * capacity embed = discord.Embed(colour=discord.Colour.blue()) embed.set_author(name="Bank van {}".format(ctx.author.display_name)) embed.add_field(name="Offense:", value=str(offense), inline=True) embed.add_field(name="Prijs voor volgend level:", value="{:,}".format(int(offenseLevelPrice)), inline=True) embed.add_field(name="Capaciteit:", value="{:,}".format(int(capacity)), inline=True) embed.add_field(name="Security:", value=str(defense), inline=True) embed.add_field(name="Prijs voor volgend level:", value="{:,}".format(int(defenseLevelPrice)), inline=True) await ctx.send(embed=embed)
async def offense(self, ctx): """ Command that upgrades the user's bank offense, increasing capacity & rob chances. :param ctx: Discord Context """ response = currency.getOrAddUser(ctx.author.id) offense = int(response[7]) capacity = calcCapacity(offense) offenseLevelPrice = math.floor(math.pow(1.5, offense) * 369) if offense < 32 else 5 * capacity # Check if user has enough Didier Dinks to do this if float(response[1]) >= offenseLevelPrice: currency.update(ctx.author.id, "dinks", float(response[1]) - offenseLevelPrice) currency.update(ctx.author.id, "offense", int(response[7]) + 1) await ctx.send( "**{}** heeft de offense van zijn bank geüpgradet naar level **{}**!" .format(ctx.author.display_name, int(response[7]) + 1)) else: await ctx.send( "Je hebt niet genoeg Didier Dinks om dit te doen, **{}**.". format(ctx.author.display_name))
async def bank(self, ctx): """ Command that shows the user's Didier Bank. :param ctx: Discord Context """ # 0 1 2 3 4 5 6 7 8 9 10 # ID dinks level investedamount investeddays profit defense offense bc nightly streak response = currency.getOrAddUser(ctx.author.id) # Calculate the cost to level your bank interestLevelPrice = round(math.pow(1.28, int(response[2])) * 300) ratio = round(float(1 * (1 + (int(response[2]) * 0.01))), 4) # Calculate the amount of levels the user can purchase counter = 0 sumPrice = float(math.pow(1.28, int(response[2])) * 300) while float(response[1]) + float(response[3]) + float(response[5]) > sumPrice: counter += 1 sumPrice += round(float(math.pow(1.28, int(response[2]) + counter) * 300), 4) maxLevels = "" if counter == 0 else " (+{})".format(str(counter)) embed = discord.Embed(colour=discord.Colour.blue()) embed.set_author(name="Bank van {}".format(ctx.author.display_name)) embed.set_thumbnail(url=str(ctx.author.avatar_url)) embed.add_field(name="Level:", value=str(response[2]) + maxLevels, inline=True) embed.add_field(name="Ratio:", value=str(ratio), inline=True) embed.add_field(name="Prijs voor volgend level:", value="{:,}".format(interestLevelPrice), inline=False) embed.add_field(name="Momenteel geïnvesteerd:", value="{:,}".format(math.floor(float(response[3]))), inline=False) embed.add_field(name="Aantal dagen geïnvesteerd:", value=str(response[4]), inline=True) embed.add_field(name="Huidige winst na claim:", value="{:,}".format(math.floor(response[5])), inline=False) await ctx.send(embed=embed)
async def buy(self, ctx, amount: Abbreviated): """ Command to buy Bitcoins. :param ctx: Discord Context :param amount: the amount of Bitcoins the user wants to buy """ resp = checks.isValidAmount(ctx, amount) # Not a valid amount: send the appropriate error message if not resp[0]: return await ctx.send(resp[1]) if amount == "all": amount = resp[1] # Calculate the amount of Bitcoins the user can buy with [amount] of Didier Dinks price = self.getPrice() purchased = round(float(amount) / price, 8) # Update the db currency.update(ctx.author.id, "dinks", float(currency.dinks(ctx.author.id)) - float(amount)) currency.update( ctx.author.id, "bitcoins", float(currency.getOrAddUser(ctx.author.id)[8]) + float(purchased)) await ctx.send( "**{}** heeft **{:,}** Bitcoin{} gekocht voor **{:,}** Didier Dink{}!" .format(ctx.author.display_name, purchased, checks.pluralS(purchased), round(float(amount)), checks.pluralS(amount)))
async def bc(self, ctx): """ Command that shows your Bitcoin bank. :param ctx: Discord Context """ price = self.getPrice() bc = float(currency.getOrAddUser(ctx.author.id)[8]) currentTime = timeFormatters.dateTimeNow() currentTimeFormatted = currentTime.strftime('%m/%d/%Y om %H:%M:%S') # Create the embed embed = discord.Embed(colour=discord.Colour.gold()) embed.set_author( name="Bitcoin Bank van {}".format(ctx.author.display_name)) embed.add_field(name="Aantal Bitcoins:", value="{:,}".format(round(bc, 8)), inline=False) embed.add_field(name="Huidige waarde:", value="{:,} Didier Dink{}".format( round(bc * price, 8), checks.pluralS(bc * price)), inline=False) embed.set_footer(text="Huidige Bitcoin prijs: €{:,} ({})".format( price, str(currentTimeFormatted))) # Add the Bitcoin icon to the embed file = discord.File("files/images/bitcoin.png", filename="icon.png") embed.set_thumbnail(url="attachment://icon.png") await ctx.send(embed=embed, file=file)
async def canRob(self, ctx, target): """ Function that performs checks to see if a user can rob another user. In case the rob is not possible, it already sends an error message to show this. Returns the database dictionaries corresponding to these two users as they are needed in this function anyways, so it prevents an unnecessary database call in the rob command. :param ctx: Discord Context :param target: the target victim to be robbed :return: success: boolean, user1 ("Caller"): tuple, user2 ("Target"): tuple """ # Can't rob in DM's if str(ctx.channel.type) == "private": await ctx.send("Dat doe je niet, {}.".format( ctx.author.display_name)) return False, None, None # Can't rob bots if str(ctx.author.id) in constants.botIDs: await ctx.send("Nee.") # Can't rob in prison if len(prison.getUser(ctx.author.id)) != 0: await ctx.send( "Je kan niemand bestelen als je in de gevangenis zit.") return False, None, None # Check the database for these users user1 = currency.getOrAddUser(ctx.author.id) user2 = currency.getOrAddUser(target.id) # Can't rob without Didier Dinks if float(user1[1]) < 1.0: await ctx.send("Mensen zonder Didier Dinks kunnen niet stelen.") return False, None, None # Target has no Didier Dinks to rob if float(user2[1]) < 1.0 and float(user2[3]) < 1.0: await ctx.send("Deze persoon heeft geen Didier Dinks om te stelen." ) return False, None, None # Passed all tests return True, user1, user2
async def claim(self, ctx, *args): """ Command that claims profit out of the user's Didier Bank. :param ctx: :param args: :return: """ user = currency.getOrAddUser(ctx.author.id) args = list(args) claimAll = False if len(args) == 0: args.append("all") if args[0] == "all": args[0] = float(user[5]) claimAll = True if not claimAll: args[0] = abbreviated(str(args[0])) if args[0] is None: return await ctx.send("Dit is geen geldig bedrag.") try: # Checks if it can be parsed to int _ = int(args[0]) args[0] = float(args[0]) # Can't claim more than you have (or negative amounts) if args[0] < 0 or args[0] > float(user[5]): raise ValueError currency.update(ctx.author.id, "profit", float(user[5]) - args[0]) currency.update(ctx.author.id, "dinks", float(user[1]) + args[0]) s = stats.getOrAddUser(ctx.author.id) stats.update(ctx.author.id, "profit", float(s[7]) + args[0]) # If you claim everything, you get your invest back as well & your days reset if claimAll: currency.update( ctx.author.id, "dinks", float(user[1]) + float(user[3]) + float(user[5])) currency.update(ctx.author.id, "investedamount", 0.0) currency.update(ctx.author.id, "investeddays", 0) await ctx.send( "**{}** heeft **{:,}** Didier Dink{} geclaimt!".format( ctx.author.display_name, math.floor(args[0] + float(user[3])), checks.pluralS(math.floor(args[0] + float(user[3]))))) else: await ctx.send( "**{}** heeft **{:,}** Didier Dink{} geclaimt!".format( ctx.author.display_name, math.floor(args[0]), checks.pluralS(math.floor(args[0])))) except ValueError: await ctx.send("Geef een geldig bedrag op.")
async def sell(self, ctx, amount: Abbreviated): """ Command to sell Bitcoins. :param ctx: Discord Context :param amount: the amount of Bitcoins the user wants to sell """ if amount == "all": amount = float(currency.getOrAddUser(ctx.author.id)[8]) try: amount = float(amount) if amount <= 0: raise ValueError bc = float(currency.getOrAddUser(ctx.author.id)[8]) if bc == 0.0: # User has no Bitcoins await ctx.send("Je hebt geen Bitcoins, **{}**".format( ctx.author.display_name)) elif amount > bc: # User is trying to sell more Bitcoins that he has await ctx.send( "Je hebt niet genoeg Bitcoins om dit te doen, **{}**". format(ctx.author.display_name)) else: price = self.getPrice() dinks = float(currency.dinks(ctx.author.id)) currency.update(ctx.author.id, "bitcoins", bc - amount) currency.update(ctx.author.id, "dinks", dinks + (price * amount)) await ctx.send( "**{}** heeft **{:,}** Bitcoin{} verkocht voor **{:,}** Didier Dink{}!" .format(ctx.author.display_name, round(amount, 8), checks.pluralS(amount), round((price * amount), 8), checks.pluralS(price * amount))) except ValueError: # Can't be parsed to float -> random string OR smaller than 0 await ctx.send("Geef een geldig bedrag op.")
async def level(self, ctx): """ Command that upgrades the user's bank level, increasing interest. :param ctx: Discord Context """ response = currency.getOrAddUser(ctx.author.id) interestLevelPrice = float(math.pow(1.28, int(response[2])) * 300) # Check if user has enough Didier Dinks to do this if float(response[1]) >= interestLevelPrice: currency.update(ctx.author.id, "dinks", float(response[1]) - interestLevelPrice) currency.update(ctx.author.id, "banklevel", int(response[2]) + 1) await ctx.send("**{}** heeft zijn bank geüpgradet naar level **{}**!" .format(ctx.author.display_name, str(int(response[2]) + 1))) else: await ctx.send("Je hebt niet genoeg Didier Dinks om dit te doen, **{}**." .format(ctx.author.display_name))