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 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)))
async def dice(self, ctx, *args): """ Command to roll a dice, optionally for Didier Dinks. :param ctx: Discord Context :param args: bet & wager """ args = list(args) result = random.randint(1, 6) # No choice made & no wager if len(args) == 0: self.updateStats("dice", result) return await ctx.send(":game_die: **{}**!".format(result)) # Check for invalid args if len(args) == 1 or not args[0].isdigit() or not 0 < int(args[0]) < 7: return await ctx.send("Controleer je argumenten.") args[1] = abbreviated(args[1]) valid = checks.isValidAmount(ctx, args[1]) # Invalid amount if not valid[0]: return await ctx.send(valid[1]) await self.gamble(ctx, args[0], str(result), valid[1], 6, ":game_die: ") self.updateStats("dice", result)
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 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 coinflip(self, ctx, *args): """ Command to flip a coin, optionally for Didier Dinks. :param ctx: Discord Context :param args: bet & wager """ args = list(args) choices = ["Kop", "Munt"] result = random.choice(choices) # No choice made & no wager if len(args) == 0: await ctx.send("**{}**!".format(result)) self.updateStats("cf", "h" if result == "Kop" else "t") return # Check for invalid args if len(args) == 1 or args[0][0].lower() not in "kmht": return await ctx.send("Controleer je argumenten.") args[1] = abbreviated(args[1]) valid = checks.isValidAmount(ctx, args[1]) # Invalid amount if not valid[0]: return await ctx.send(valid[1]) # Allow full words, abbreviations, and English alternatives args[0] = "k" if args[0][0].lower() == "k" or args[0][0].lower( ) == "h" else "m" won = await self.gamble(ctx, args[0], result, valid[1], 2) if won: s = stats.getOrAddUser(ctx.author.id) stats.update(ctx.author.id, "cf_wins", int(s[8]) + 1) stats.update(ctx.author.id, "cf_profit", float(s[9]) + float(valid[1])) self.updateStats("cf", "h" if result == "Kop" else "t")