async def give(self, ctx, who: discord.User, what: int, collection="default"): if who == ctx.author: await ctx.send("You cannot give a number to yourself.") return from_acc = econ.get_account(ctx.author.id) to_acc = econ.get_account(who.id) if not collection in from_acc.number_collection.keys(): await ctx.send(f"Collection '{collection}' does not exist.") return if not what in from_acc.number_collection[collection]: await ctx.send( f"Number '{what}' is not in collection '{collection}'.") return from_acc.remove_number(collection, what) to_acc.add_number("default", what) econ.save_bank() await ctx.send( f"You have transfered '{what}' from your collection '{collection}' to {who.name}." )
async def newcollection(self, ctx, name): acc = econ.get_account(ctx.author.id) if name in acc.number_collection.keys(): await ctx.send("You already have a collection with this name.") return acc.create_collection(name) await ctx.send("Collection created.") econ.save_bank()
async def delcollection(self, ctx, collection): acc = econ.get_account(ctx.author.id) if not collection in acc.number_collection.keys(): await ctx.send("That collection does not exist.") return acc.remove_collection(collection) await ctx.send(f"Collection '{collection}' has been removed. \ Its numbers are now in your default collection.") econ.save_bank()
async def unbet(self, ctx): acc = econ.get_account(ctx.author.id) if acc.bet() == 0: await ctx.send("No current bet.") return refund = round(acc.bet() / 2, 2) acc.transact(refund) acc.bet_value = 0 await ctx.send( f"You rescind your bet. You are refunded {refund} {CURRENCY}.") econ.save_bank()
async def recycle(self, ctx, number: int, collection="default"): acc = econ.get_account(ctx.author.id) if not collection in acc.number_collection.keys(): await ctx.send("That collection does not exist.") return if not number in acc.number_collection[collection]: await ctx.send("That number is not in your collection.") return acc.remove_number(collection, number) acc.transact(0.05) await ctx.send( f"You recycled {number}. You earned 0.05 {CURRENCY} for recycling." ) econ.save_bank()
async def sell(self, ctx, number: int, collection="default"): acc = econ.get_account(ctx.author.id) if not collection in acc.number_collection.keys(): await ctx.send("That collection does not exist.") return if not number in acc.number_collection[collection]: await ctx.send("That number is not in your collection.") return if len(str(number)) < 5: await ctx.send("You can only sell numbers with >= 5 digits.") return acc.remove_number(collection, number) value = min(round(10 + (number / 10**5), 2), 50) acc.transact(value) await ctx.send(f"You sold {number} for {value} {CURRENCY}.") econ.save_bank()
async def movenumber(self, ctx, number: int, destination, source="default"): acc = econ.get_account(ctx.author.id) if not (source in acc.number_collection.keys() and \ destination in acc.number_collection.keys()): await ctx.send("Invalid source or destination.") return if not number in acc.number_collection[source]: await ctx.send(f"Number {number} is not in source.") return acc.remove_number(source, number) acc.add_number(destination, number) await ctx.send("Number moved.") econ.save_bank()
async def buyseeds(self, ctx, amount=1): if not 'seed_price' in save.state.keys(): save.save_state('seed_price', 50) if amount < 1: await ctx.send("Invalid amount.") return seed_price = save.state['seed_price'] cost = amount * seed_price acc = econ.get_account(ctx.author.id) if cost > acc.balance: await ctx.send( f"Insufficient funds to purchase seeds for {cost} {CURRENCY}.") return acc.transact(-cost) acc.seed_count += amount await ctx.send(f"Purchased seeds for {cost} {CURRENCY}.") econ.save_bank()
async def pay(self, ctx, who: discord.User, what: float): if who == ctx.author: await ctx.send("You cannot pay yourself.") return if what <= 0: await ctx.send("Invalid amount.") return what = round(what, 2) from_acc = econ.get_account(ctx.author.id) to_acc = econ.get_account(who.id) if from_acc.balance < what: await ctx.send("Insufficient funds.") return from_acc.transact(-what) to_acc.transact(what) econ.save_bank() await ctx.send(f"You have transfered {what} {CURRENCY} to {who.name}.")
async def random(self, ctx, seed=""): '''Gives a random number. Keeps track of high score.''' acc = econ.get_account(ctx.author.id) if len(seed) > 0: if acc.seeds() > 0: acc.seed_count -= 1 random.seed(seed) await ctx.send("You have seeded the random number generator.") else: await ctx.send( "You do not have any seeds with which to seed random generator." ) return value = '' choices = [True, True] while random.choice(choices): value += str(random.randint(0, 9)) choices.append(False) value = int(value) if 'rand_highscore_user' in save.state.keys(): highscore_user = save.state['rand_highscore_user'] highscore_value = save.state['rand_highscore_value'] else: highscore_user = str(ctx.author) highscore_value = 0 acc.add_number("default", value) if value > highscore_value: embed = discord.Embed(color=discord.Color.blurple(), title='Congratulations!! :partying_face:', description='You beat the high score!') embed.add_field(name='Old high score:', value=f'{highscore_user} got {highscore_value}') embed.add_field(name='New high score:', value=f'{str(ctx.author)} got {value}') save.save_state('rand_highscore_user', str(ctx.author)) save.save_state('rand_highscore_value', value) if acc.bet() != 0: acc.transact(acc.bet() * 1.5) if not 'seed_price' in save.state.keys(): seed_price = 50 else: seed_price = save.state['seed_price'] seed_price += acc.bet() seed_price /= 2 seed_price = max(10, seed_price - 25) seed_price = round(seed_price, 2) print(seed_price) save.save_state('seed_price', seed_price) acc.bet_value = 0 await ctx.send("You won the bet!") else: embed = discord.Embed(color=discord.Color.lighter_grey(), title='Value:', description=str(value)) embed.set_footer(text='You did not beat the high score.') embed.add_field(name='Current high score:', value=f'{highscore_user} got {highscore_value}') if acc.bet() != 0: acc.transact(-(acc.bet() * 2)) acc.bet_value = 0 await ctx.send("You lost the bet.") await ctx.send(embed=embed) if value % 16 == 0 and value != 0: if len(seed) == 0: acc.seed_count += 1 await ctx.send( "You generated a multiple of 16! You earned one seed.") else: await ctx.send( "You generated a multiple of 16. " + "However, since you seeded this outcome, you did not earn a seed." ) econ.save_bank()