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 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 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 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 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
def isValidAmount(ctx, amount): if not amount: return [False, "Geef een geldig bedrag op."] dinks = float(currency.dinks(ctx.author.id)) if str(amount).lower() == "all": if dinks > 0: return [True, dinks] else: return [False, "Je hebt niet genoeg Didier Dinks om dit te doen."] # Check if it's a number <= 0 or text != all if (all(char.isalpha() for char in str(amount)) and str(amount).lower() != "all") or \ (all(char.isdigit() for char in str(abs(int(amount)))) and int(amount) <= 0): return [False, "Geef een geldig bedrag op."] if int(amount) > dinks: return [False, "Je hebt niet genoeg Didier Dinks om dit te doen."] return [True, amount]
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)))