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 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 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 bail(self, ctx): """ Command to bail yourself out of prison. :param ctx: Discord Context """ user = prison.getUser(ctx.author.id) if len(user) == 0: return await ctx.send("Je zit niet in de gevangenis, **{}**.".format(ctx.author.display_name)) user = user[0] # Check if user can afford this valid = checks.isValidAmount(ctx, math.floor(user[1])) if not valid[0]: return await ctx.send(valid[1]) dinks = currency.dinks(ctx.author.id) prison.remove(ctx.author.id) currency.update(ctx.author.id, "dinks", float(dinks) - float(user[1])) await ctx.send("**{}** heeft zichzelf vrijgekocht!".format(ctx.author.display_name)) # Update the user's stats s = stats.getOrAddUser(ctx.author.id) stats.update(ctx.author.id, "bails", int(s[10]) + 1) # Increase the bail in the stats file with open("files/stats.json", "r") as fp: s = json.load(fp) s["rob"]["bail_paid"] += float(user[1]) with open("files/stats.json", "w") as fp: json.dump(s, fp)
async def give(self, ctx, person: discord.Member, amount: Abbreviated): """ Command that gives your Didier Dinks to another user. :param ctx: Discord Context :param person: user to give the Didier Dinks to :param amount: the amount of Didier Dinks to give """ # Invalid amount if amount is None: return # Disable DM abuse if ctx.guild is None: return await ctx.send("Muttn") valid = checks.isValidAmount(ctx, amount) if not valid[0]: return await ctx.send(valid[1]) amount = float(valid[1]) currency.update(ctx.author.id, "dinks", float(currency.dinks(ctx.author.id)) - amount) currency.update(person.id, "dinks", float(currency.dinks(person.id)) + amount) rep = getRep(math.floor(amount), Numbers.t.value) await ctx.send( "**{}** heeft **{}** zowaar **{}** Didier Dink{} geschonken!". format(ctx.author.display_name, person.display_name, rep, checks.pluralS(amount)))
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)))
def buy(ctx, userid, itemid, amount): connection = utils.connect() cursor = connection.cursor() dinks = currency.dinks(userid) cursor.execute("SELECT * FROM store WHERE itemid = %s", (int(itemid),)) result = cursor.fetchall() if not result: return False, "Er is geen item met dit id." # Not an empty list, no IndexError. result = result[0] cursor.execute("SELECT amount FROM inventory WHERE userid = %s AND itemid = %s", (int(userid), int(itemid),)) inv = cursor.fetchall() # Check if user already owns this limit = result[3] if limit is not None \ and inv \ and inv[0][0] + amount > limit: return False, "Je kan dit item maar {} keer kopen.".format(limit) isValid = checks.isValidAmount(ctx, result[2] * amount) if not isValid[0]: return isValid currency.update(userid, "dinks", dinks - (result[2] * amount)) addItem(userid, itemid, amount, inv) return True, {"id": result[0], "name": result[1], "price": result[2] * amount}
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 slots(self, ctx, wager: Abbreviated = None): """ Command to play slot machines. :param ctx: Discord Context :param wager: the amount of Didier Dinks to bet with """ valid = checks.isValidAmount(ctx, wager) # Invalid amount if not valid[0]: return await ctx.send(valid[1]) ratios = dinks.getRatios() def randomKey(): return random.choice(list(ratios.keys())) def generateResults(): return [randomKey(), randomKey(), randomKey()] # Generate the result result = generateResults() textFormatted = "{}\n{}\n:yellow_square:{}:yellow_square:\n:arrow_right:{}:arrow_left::part_alternation_mark:\n" \ ":yellow_square:{}:yellow_square: :red_circle:\n{}\n{}".format( dinks.slotsHeader, dinks.slotsEmptyRow, "".join(generateResults()), "".join(result), "".join(generateResults()), dinks.slotsEmptyRow, dinks.slotsFooter) await ctx.send(textFormatted) # Everything different -> no profit if len(set(result)) == 3: await ctx.send( "Je hebt je inzet (**{:,}** Didier Dinks) verloren, **{}**.". format(math.floor(float(valid[1])), ctx.author.display_name)) currency.update( ctx.author.id, "dinks", float(currency.dinks(ctx.author.id)) - math.floor(float(valid[1]))) return # Calculate the profit multiplier multiplier = 1.0 for symbol in set(result): multiplier *= ratios[symbol][result.count(symbol) - 1] await ctx.send( ":moneybag: Je wint **{:,}** Didier Dinks, **{}**! :moneybag:". format(round(float(valid[1]) * multiplier, 2), ctx.author.display_name)) currency.update( ctx.author.id, "dinks", float(currency.dinks(ctx.author.id)) + (float(valid[1]) * multiplier) - math.floor(float(valid[1])))
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))
async def award(self, ctx, user: discord.User, amount: Abbreviated): """ Command that awards a user a certain amount of Didier Dinks. :param ctx: Discord Context :param user: the user to give the Didier Dinks to :param amount: the amount of Didier Dinks to award [user] """ # No amount was passed if amount is None: return # Update the db currency.update(user.id, "dinks", float(currency.dinks(user.id)) + float(amount)) # Gets the abbreviated representation of the amount rep = getRep(amount, Numbers.t.value) await ctx.send("**{}** heeft **{}** zowaar **{}** Didier Dink{} beloond!" .format(ctx.author.display_name, self.utilsCog.getDisplayName(ctx, user.id), rep, checks.pluralS(amount)))
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 sell(self, ctx, itemid, amount: Abbreviated = 1): if amount is None: return try: itemid = int(itemid) except ValueError: return await ctx.send("Dit is geen geldig id.") inv = store.inventory(ctx.author.id) if not inv or not any(int(item[0]) == itemid for item in inv): return await ctx.send("Je hebt geen item met dit id.") item_tuple = None for item in inv: if item[0] == itemid: item_tuple = item break if str(amount).lower() == "all": amount = int(item_tuple[2]) if int(item_tuple[2]) < amount: return await ctx.send("Je hebt niet zoveel {}s.".format( item_tuple[1])) store.sell(int(ctx.author.id), itemid, int(amount), int(item_tuple[2])) price = int(store.getItemPrice(itemid)[0]) returnValue = round(0.8 * (price * amount)) currency.update(ctx.author.id, "dinks", currency.dinks(ctx.author.id) + returnValue) await ctx.send( "**{}** heeft **{} {}{}** verkocht voor **{}** Didier Dinks!". format(ctx.author.display_name, amount, item_tuple[1], "s" if amount != 1 else "", getRep(returnValue, Numbers.t.value)))
async def gamble(self, ctx, bet, result, wager, factor, pre="", post=""): """ Function for gambling because it's the same thing every time. :param ctx: Discord Context :param bet: the option the user bet on :param result: randomly generated result :param wager: size of the bet of the user :param factor: the factor by which the person's wager is amplified :param pre: any string that might have to be pre-pended to the output string :param post: any string that might have to be appended to the output string :return: a boolean indicating whether or not the user has won """ # Code no longer first removes your bet to then add profit, # resulting in triple coinflip profit (@Clement). # Subtract one off of the factor to compensate for the initial wager factor -= 1 answer = "**{}**! ".format(result) won = False # Check if won if result[0].lower() == bet[0].lower(): won = True answer += "Je wint **{:,}** Didier Dink{}" currency.update( ctx.author.id, "dinks", float(currency.dinks(ctx.author.id)) + (float(wager) * factor)) else: answer += "Je hebt je inzet (**{:,}** Didier Dink{}) verloren" currency.update( ctx.author.id, "dinks", float(currency.dinks(ctx.author.id)) - float(wager)) self.loseDinks(round(float(wager))) # If won -> multiple dinkS, if lost, it's possible that the user only bet on 1 dinK await ctx.send(pre + answer.format( round(float(wager) * factor if won else float(wager)), checks.pluralS(float(wager) * factor if won else float(wager))) + ", **{}**!".format(ctx.author.display_name)) return won
async def bankInterest(self): """ Task that gives daily interest """ # Don't do it multiple times a day if bot dc's, ... with open("files/lastTasks.json", "r") as fp: lastTasks = json.load(fp) if int(self.getCurrentHour()) == 0 and int(time.time()) - int( lastTasks["interest"]) > 10000: users = currency.getAllRows() bitcoinPrice = self.getCurrentBitcoinPrice() for user in users: # People in prison don't get interest if len(prison.getUser(int(user[0]))) != 0: continue if float(user[3]) != 0.0: currency.update(user[0], "investeddays", int(user[4]) + 1) profit = ((float(user[3]) + float(user[5])) * (1 + (float(user[2]) * 0.01))) - float(user[3]) # Can't exceed 1 quadrillion # Check BC as well so they can't put everything into BC to cheat the system if float(user[1]) + float(user[3]) + float( user[5]) + profit + (float( user[8]) * bitcoinPrice) > Numbers.q.value: # In case adding profit would exceed 1q, only add the difference profit = Numbers.q.value - float(user[1]) - float( user[3]) - float( user[5]) - (float(user[8]) * bitcoinPrice) # Don't reduce the current profit if Dinks were gained some other way (rob, bc, ...) if profit > 0: currency.update(user[0], "profit", float(user[5]) + profit) await self.client.get_user(int(user[0])).send( "Je hebt de invest-limiet van 1Q Didier Dinks bereikt.\nIndien je nog meer Didier Dinks wil sparen, kan je 1q Didier Dinks omruilen voor een Platinum Dink in de shop." ) else: currency.update(user[0], "profit", float(user[5]) + profit) lastTasks["interest"] = int(round(time.time())) with open("files/lastTasks.json", "w") as fp: json.dump(lastTasks, fp)
async def rob(self, ctx, target: discord.User): """ Command to rob another user. :param ctx: Discord Context :param target: the target victim to be robbed :return: """ canRob, caller, target = await self.canRob(ctx, target) if not canRob: return threshold = 50 + round(int(target[6]) * 0.7) rg = random.randint(0 + int(caller[7]), 100) stat = stats.getOrAddUser(ctx.author.id) # Rob succeeded if rg > threshold: capacity = float(calcCapacity(caller[7])) remaining = capacity # Try robbing out of invest first, then Dinks pouch amount = capacity if float(target[3]) >= capacity else float( target[3]) remaining -= amount currency.update(target[0], "investedamount", float(target[3]) - amount) # Rob out of Dinks pouch if amount != capacity and not float(target[1]) < 1: if float(target[1]) >= remaining: amount += remaining currency.update(target[0], "dinks", float(target[1]) - remaining) else: amount += float(target[1]) currency.update(target[0], "dinks", 0.0) # Update db currency.update(caller[0], "dinks", float(caller[1]) + amount) await ctx.send( "**{}** heeft **{:,}** Didier Dink{} gestolen van **{}**!". format(ctx.author.display_name, math.floor(amount), checks.pluralS(math.floor(amount)), self.utilsCog.getDisplayName(ctx, target[0]))) stats.update(ctx.author.id, "robs_success", int(stat[2]) + 1) stats.update(ctx.author.id, "robs_total", float(stat[4]) + amount) else: # Rob failed # Calculate what happens fate = random.randint(1, 10) # Leave Dinks behind instead of robbing if fate < 8: punishment = float(calcCapacity(caller[7])) / 2 prisoned = round(float(caller[1])) < round(punishment) # Doesn't have enough Dinks -> prison if prisoned: diff = round(punishment - float(caller[1])) punishment = round(float(caller[1])) days = 1 + round(int(caller[7]) // 10) prison.imprison(caller[0], diff, days, round(round(diff) // days)) # Update db currency.update(target[0], "dinks", float(target[1]) + punishment) currency.update(caller[0], "dinks", float(caller[1]) - punishment) await ctx.send( "**{}** was zo vriendelijk om **{}** zowaar **{:,}** Didier Dink{} te geven!" .format(ctx.author.display_name, self.utilsCog.getDisplayName(ctx, target[0]), math.floor(punishment), checks.pluralS(math.floor(punishment)))) # Can't put this in the previous if- because the value of Punishment changes if prisoned: await ctx.send( "Je bent naar de gevangenis verplaatst omdat je niet genoeg Didier Dinks had." ) elif fate == 9: # Prison totalSum = round(calcCapacity(caller[7])) days = 1 + (int(caller[7]) // 10) prison.imprison(caller[0], totalSum, days, totalSum / days) await ctx.send( "**{}** niet stelen, **{}** niet stelen!\nJe bent naar de gevangenis verplaatst." .format(ctx.author.display_name, ctx.author.display_name)) else: # Escape await ctx.send( "Je poging is mislukt, maar je kon nog net op tijd vluchten, **{}**." "\nAllez, 't is goed voor ene keer e, deugeniet.".format( ctx.author.display_name)) stats.update(ctx.author.id, "robs_failed", int(stat[3]) + 1)