示例#1
0
    async def delete_tree(self, ctx, *, input_tree_name):
        """Delete tree of input_tree_name."""

        user = find_or_insert_user(ctx.author.id)

        tree_index = find_tree_index(user, input_tree_name)

        if tree_index == None:
            await ctx.send(embed=error_embed(
                ctx.author,
                f"You do not have a tree with the name {input_tree_name}."))
            return

        # get parts and move to inventory
        tree_name_output = user["trees"][tree_index]["name"]

        # iterate over tree to return parts to inventory
        inventory_parts = []
        for key, value in user["trees"][tree_index].items():
            if key == "name" or key == "background_color":
                continue

            part_for_inventory = value
            part_for_inventory["type"] = key
            inventory_parts.append(part_for_inventory)

        # add old part to inventory
        user["inventory"].extend(inventory_parts)

        # delete tree
        user["trees"].pop(tree_index)
        user_col.update_one({"user_id": ctx.author.id}, {"$set": user})

        await ctx.send(
            embed=info_embed(ctx.author, f"Deleted tree {tree_name_output}."))
示例#2
0
    async def delete_inventory_part(self, ctx, input_inventory_num: int):
        """Delete a part from the inventory."""

        user = find_or_insert_user(ctx.author.id)

        inventory_num = input_inventory_num - 1

        # check for proper inventory number
        if input_inventory_num <= 0:
            await ctx.send(embed=error_embed(
                ctx.author, "Inventory numbers must be over 0."))
            return

        elif len(user["inventory"]) - 1 < inventory_num:
            await ctx.send(embed=error_embed(
                ctx.author,
                f"Your inventory only goes up to {len(user['inventory'])}, but #{input_inventory_num} was entered."
            ))
            return

        user["inventory"].pop(inventory_num)
        user_col.update_one({"user_id": ctx.author.id}, {"$set": user})

        await ctx.send(embed=info_embed(
            ctx.author, f"Part at #{input_inventory_num} has been removed."))
    async def get_ping(self, ctx):
        """Send bot's latency."""

        await ctx.send(embed=info_embed(
            ctx.author, f"Pong: {self.bot.latency * 1000: .2f}ms.",
            "https://media1.tenor.com/images/a3ca17636f365c6b0a0d11fc6a1240b5/tenor.gif"
        ))
示例#4
0
    async def buy_part_with_username(self,
                                     ctx,
                                     part_name,
                                     member: discord.User = None):
        """Buy a part from a player's shop with their username."""

        user = find_or_insert_user(ctx.author.id)

        if len(user["inventory"]) >= 100:
            await ctx.send(embed=error_embed(
                ctx.author,
                "You have reached the limit of 100 parts in your inventory."))
            return

        if member == None:
            member = ctx.author

        seller = user_col.find_one({"user_id": member.id})

        if seller == None:
            await ctx.send(
                embed=error_embed(ctx.author, f"{member} has no parts listed.")
            )
            return

        # get correct spelling of list in seller
        all_parts = seller["parts"]
        part_to_buy = None

        for part in all_parts:
            if part["name"].lower() == part_name.lower():
                part_to_buy = part

        if part_to_buy == None:
            await ctx.send(embed=error_embed(
                ctx.author,
                f"{member} does not have a part named {part_name}."))
            return

        if part_to_buy["price"] > user["balance"]:
            await ctx.send(embed=error_embed(
                ctx.author,
                f"You only have ${user['balance']}, but {part_to_buy['name']} costs ${part_to_buy['price']}."
            ))
            return

        # give part and remove money from user
        part_to_buy["creator"] = str(member)
        user["inventory"].append(part_to_buy)
        user["balance"] -= part_to_buy["price"]
        user_col.update_one({"user_id": ctx.author.id}, {"$set": user})

        # give money to seller
        seller_tree_account = user_col.find_one({"user_id": member.id})
        seller_tree_account["balance"] += part_to_buy["price"]
        user_col.update_one({"user_id": member.id},
                            {"$set": seller_tree_account})

        await ctx.send(embed=info_embed(
            ctx.author, f"You bought {member}'s {part_to_buy['name']}."))
示例#5
0
    async def daily_reward(self, ctx):
        """Get a random amount of money every 24 hours."""

        user = find_or_insert_user(ctx.author.id)
        
        reward = randint(50, 100)
        user["balance"] += reward

        user_col.update_one({"user_id" : ctx.author.id}, {"$set" : user})

        await ctx.send(embed=info_embed(ctx.author, f"Added ${reward} to your balance! Your new balance is ${user['balance']}."))
示例#6
0
    async def clear_inventory(self, ctx):
        """Deletes all of the parts in the inventory."""

        user = find_or_insert_user(ctx.author.id)

        user["inventory"].clear()
        user_col.update_one({"user_id": ctx.author.id},
                            {"$set": {
                                "inventory": []
                            }})

        await ctx.send(embed=info_embed(ctx.author, "Cleared your inventory."))
示例#7
0
    async def check_balance(self, ctx, member : discord.User = None):
        """Check a player's balance."""

        if member == None:
            member = ctx.author

        user = find_user(member.id)
        
        if user == None:
            await ctx.send(embed=error_embed(ctx.author, f"{member} does not have a balance yet."))
            return
        
        await ctx.send(embed=info_embed(ctx.author, f"{member} has ${user['balance']}."))
示例#8
0
    async def delete_part_listing(self, ctx, part_name):
        """Delete a listing from the player's shop."""

        user = find_or_insert_user(ctx.author.id)

        part_for_removal = None
        for i, part in enumerate(user["parts"]):
            if part["name"].lower() == part_name.lower():
                part_for_removal = part["name"]
                break

        if part_for_removal == None:
            await ctx.send(embed=error_embed(
                ctx.author, f"Part {part_name} was not found."))
            return

        user["parts"].pop(i)
        user_col.update_one({"user_id": ctx.author.id}, {"$set": user})

        await ctx.send(
            embed=info_embed(ctx.author, f"Unlisted part {part_for_removal}."))