Esempio n. 1
0
    async def inventory(self, ctx, user: discord.Member = None):
        if user is None:
            user = ctx.author

        Data.check_user_entry(user)

        Data.c.execute(
            "SELECT inventory FROM users WHERE id = :user_id",
            {"user_id": user.id},
        )
        inventory = json.loads(Data.c.fetchone()[0])

        inventory_embed = discord.Embed(
            title=f"{user.display_name}'s Inventory", color=self.theme_color)

        for item in inventory:
            item_name = item["name"]
            item_desc = item["description"]
            item_quantity = item["quantity"]
            inventory_embed.add_field(
                name=item_name,
                value=f"Quantity: {item_quantity}\n{item_desc}",
                inline=False,
            )

        await ctx.send(embed=inventory_embed)
Esempio n. 2
0
    async def balance(self, ctx, user: discord.User = None):
        if user is None:
            user = ctx.author

        Data.check_user_entry(user)

        Data.c.execute(
            "SELECT wallet, bank, bank_capacity FROM users WHERE id = :user_id",
            {"user_id": user.id},
        )
        data = Data.c.fetchone()
        wallet = data[0]
        bank = data[1]
        bank_capacity = data[2]

        embed = discord.Embed(
            title=f"{user.display_name}'s Bean Balance", color=self.theme_color
        )
        embed.add_field(name="Wallet", value=f"{wallet} beans")
        embed.add_field(name="Bank", value=f"{bank}/{bank_capacity} beans")

        await ctx.send(
            "You can get beans for free if you vote for me on Top.gg. Do `b.vote` for more info...",
            embed=embed,
        )
Esempio n. 3
0
    async def on_dbl_vote(self, data):
        if data["type"] == "upvote":
            user = self.bot.get_user(int(data["user"]))
            Data.check_user_entry(user)
            print(f"{user} has upvoted the bot on Top.gg")
            try:
                await user.send(
                    f"Thank you for voting for me on Top.gg. You have gotten {self.vote_reward} beans as a gift!"
                )
            except discord.errors.Forbidden:
                print(f"Couldn't send a message to {user}")

            Data.c.execute(
                "SELECT wallet FROM users WHERE id = :user_id",
                {"user_id": user.id},
            )
            wallet = Data.c.fetchone()[0]

            Data.c.execute(
                "UPDATE users SET wallet = :new_amount WHERE id = :user_id",
                {
                    "new_amount": wallet + self.vote_reward,
                    "user_id": user.id
                },
            )
            Data.conn.commit()
Esempio n. 4
0
    async def work(self, ctx):
        Data.check_user_entry(ctx.author)

        Data.c.execute(
            "SELECT wallet, job_id, job_streak, last_work_date FROM users WHERE id = :user_id",
            {"user_id": ctx.author.id},
        )
        data = Data.c.fetchone()

        current_balance = data[0]
        job_id = data[1]
        current_streak = data[2]
        last_work_date = datetime.strptime(data[3], "%Y-%m-%d %H:%M")
        today = datetime.now()

        if job_id == 0:
            await ctx.send("You're unemployed bro. Get a job...")
            return

        salary = self.jobs_data[job_id]["salary"]
        new_streak = current_streak + 1

        time_diff = today - last_work_date

        if time_diff.days > 2:
            new_streak = 1
            await ctx.send(
                "You didn't show up to work yesterday. Your work streak has been reset!"
            )

        elif time_diff.days < 1:
            time_left = 24 - time_diff.total_seconds() / 3600

            if time_left > 1:
                await ctx.send(
                    f"You've done enough work for today, try again in {int(time_left)} hours..."
                )
            else:
                time_left = time_left * 60
                await ctx.send(
                    f"You've done enough work for today, try again in {int(time_left)} minutes..."
                )

            return

        Data.c.execute(
            "UPDATE users SET wallet = :new_amount, job_streak = :new_streak, last_work_date = :new_lwd WHERE id = :user_id",
            {
                "new_amount": current_balance + salary,
                "new_streak": new_streak,
                "new_lwd": today.strftime("%Y-%m-%d %H:%M"),
                "user_id": ctx.author.id,
            },
        )

        Data.conn.commit()
        await ctx.send(
            f"You finished a day's worth of work and feel satisfied! You earned **{salary} beans** and you're on a **{new_streak} day** streak!"
        )
Esempio n. 5
0
    async def pay(self, ctx, user: discord.User, amount: int):
        if ctx.author.id == user.id:
            await ctx.send("You can't do that to yourself, smh...")
            return

        if amount == 0:
            await ctx.send(
                "Why are you using this command if you aren't giving them beans?"
            )
            return
        elif amount < 1:
            await ctx.send(
                "You can't trick me into taking away their money fool!"
            )
            return

        Data.check_user_entry(ctx.author)
        Data.check_user_entry(user)

        # Get current wallet balances
        Data.c.execute(
            "SELECT wallet FROM users WHERE id = :user_id",
            {"user_id": ctx.author.id},
        )
        current_balance = Data.c.fetchone()[0]

        Data.c.execute(
            "SELECT wallet FROM users WHERE id = :user_id",
            {"user_id": user.id},
        )
        current_receiver_balance = Data.c.fetchone()[0]

        # Ensure user has enough to pay
        if amount > current_balance:
            amount_needed = amount - current_balance
            await ctx.send(
                f"You don't have enough beans for that. You need {amount_needed} more beans."
            )
            return

        # Update balances
        Data.c.execute(
            "UPDATE users SET wallet = :new_amount WHERE id = :user_id",
            {"new_amount": current_balance - amount, "user_id": ctx.author.id},
        )
        Data.c.execute(
            "UPDATE users SET wallet = :new_amount WHERE id = :user_id",
            {
                "new_amount": current_receiver_balance + amount,
                "user_id": user.id,
            },
        )

        Data.conn.commit()

        await ctx.send(f"You paid **{amount} beans** to {user.display_name}.")
Esempio n. 6
0
    async def gamble(self, ctx, amount: int):
        Data.check_user_entry(ctx.author)

        Data.c.execute(
            "SELECT wallet FROM users WHERE id = :user_id",
            {"user_id": ctx.author.id},
        )
        wallet = Data.c.fetchone()[0]

        if amount > wallet:
            amount_needed = amount - wallet
            await ctx.send(
                f"You don't have enough beans for that. You need {amount_needed} more beans."
            )
            return

        player_roll = random.randint(1, 6)
        dealer_roll = random.randint(1, 6)

        if player_roll > dealer_roll:
            amount_won = math.ceil((player_roll - dealer_roll) / 6 * amount)
        elif player_roll < dealer_roll:
            amount_won = -amount
        else:
            amount_won = 0

        Data.c.execute(
            "UPDATE users SET wallet = :new_wallet WHERE id = :user_id",
            {
                "new_wallet": wallet + amount_won,
                "user_id": ctx.author.id
            },
        )
        Data.conn.commit()

        gamble_embed = discord.Embed(title="Gambling Results")

        gamble_embed.add_field(name="You rolled", value=str(player_roll))
        gamble_embed.add_field(name="Dealer rolled", value=str(dealer_roll))

        if player_roll > dealer_roll:
            gamble_embed.color = discord.Color.green()
            gamble_embed.set_footer(text=f"You won {amount_won} beans!")
        elif player_roll < dealer_roll:
            gamble_embed.color = discord.Color.red()
            gamble_embed.set_footer(text=f"You lost {abs(amount_won)} beans!")
        else:
            gamble_embed.color = discord.Color.gold()
            gamble_embed.set_footer(text="You won nothing!")

        await ctx.send(embed=gamble_embed)
Esempio n. 7
0
    async def withdraw(self, ctx, amount):
        Data.check_user_entry(ctx.author)

        # Get current wallet and banks balances
        Data.c.execute(
            "SELECT wallet, bank FROM users WHERE id = :user_id",
            {"user_id": ctx.author.id},
        )
        data = Data.c.fetchone()
        wallet_amount = data[0]
        bank_amount = data[1]

        if str(amount) == "all" or str(amount) == "max":
            amount = bank_amount
        else:
            amount = int(amount)

            if amount == 0:
                await ctx.send(
                    "Why are you using this command if you aren't withdrawing anything?"
                )
                return
            elif amount < 1:
                await ctx.send(
                    "There's a command for depositing as well, you know..."
                )
                return

            # Ensure user has enough to deposit
            if amount > bank_amount:
                await ctx.send("You don't have that many beans in your bank.")
                return

        # Update balances
        Data.c.execute(
            "UPDATE users SET wallet = :new_wallet_amount, bank = :new_bank_amount WHERE id = :user_id",
            {
                "new_wallet_amount": wallet_amount + amount,
                "new_bank_amount": bank_amount - amount,
                "user_id": ctx.author.id,
            },
        )

        Data.conn.commit()
        await ctx.send(f"You withdrew **{amount} beans** from your bank.")
Esempio n. 8
0
    async def takejob(self, ctx, *, job_name: str):
        Data.check_user_entry(ctx.author)

        jn = None
        js = None
        jr = None

        # Get current work streak
        Data.c.execute(
            "SELECT job_streak FROM users WHERE id = :user_id",
            {"user_id": ctx.author.id},
        )
        current_streak = Data.c.fetchone()[0]

        for (job_id, job) in enumerate(self.jobs_data):
            if job["name"].lower() == job_name.lower():
                jn = job["name"]
                js = job["salary"]
                jr = job["streak_requirement"]

                if current_streak < jr:
                    await ctx.send(
                        f"You need a **{jr} day** streak to get this job! You're currently on a **{current_streak} day** streak."
                    )
                    return

                # Set user's job_id to specified job
                Data.c.execute(
                    "UPDATE users SET job_id = :job_id WHERE id = :user_id",
                    {
                        "job_id": job_id,
                        "user_id": ctx.author.id
                    },
                )
                Data.conn.commit()
                break

        if jn is None or js is None or jr is None:
            return

        embed = discord.Embed(title=f"You have become a {jn}!",
                              color=self.theme_color)
        embed.add_field(name="You will earn", value=f"{js} beans per day")

        await ctx.send(embed=embed)
Esempio n. 9
0
    async def powerups(self, ctx):
        Data.check_user_entry(ctx.author)

        Data.c.execute(
            "SELECT powerups FROM users WHERE id = :user_id",
            {"user_id": ctx.author.id},
        )
        powerups = json.loads(Data.c.fetchone()[0])
        powerups_embed = discord.Embed(
            title=f"{ctx.author.display_name}'s Active Powerups",
            color=self.theme_color,
        )

        for powerup in powerups:
            powerup_name = " ".join(powerup.split("_")).title()
            powerups_embed.add_field(name=powerup_name,
                                     value=powerups[powerup])

        await ctx.send(embed=powerups_embed)
Esempio n. 10
0
    async def myjob(self, ctx):
        Data.check_user_entry(ctx.author)

        # Get the user's job_id
        Data.c.execute(
            "SELECT job_id FROM users WHERE id = :user_id",
            {"user_id": ctx.author.id},
        )
        job_id = Data.c.fetchone()[0]

        if job_id == 0:
            await ctx.send("You're unemployed bro. Get a job...")
            return

        current_job = self.jobs_data[job_id]

        job_name = current_job["name"]
        job_salary = current_job["salary"]

        embed = discord.Embed(title=f"You are a {job_name}.",
                              color=self.theme_color)
        embed.add_field(name="You earn", value=f"{job_salary} beans per day")

        await ctx.send(embed=embed)
Esempio n. 11
0
    async def fight(self, ctx, user: discord.User):
        if ctx.author.id == user.id:
            await ctx.send("You can't do that to yourself, smh...")
            return

        if ctx.author in self.currently_fighting:
            await ctx.send("You are already fighting someone at the moment...")
            return

        elif user in self.currently_fighting:
            await ctx.send(
                f"**{user.display_name}** is already fighting someone at the moment..."
            )
            return

        p1_health = 100
        p2_health = 100
        p1_name = ctx.author.display_name
        p2_name = user.display_name

        self.currently_fighting.append(ctx.author)
        self.currently_fighting.append(user)

        Data.check_user_entry(ctx.author)
        Data.check_user_entry(user)

        # Load player powerups
        Data.c.execute(
            "SELECT powerups FROM users WHERE id = :user_id",
            {"user_id": ctx.author.id},
        )
        p1_powerups = json.loads(Data.c.fetchone()[0])
        Data.c.execute(
            "SELECT powerups FROM users WHERE id = :user_id",
            {"user_id": user.id},
        )
        p2_powerups = json.loads(Data.c.fetchone()[0])

        def check_p1(message):
            return (message.author == ctx.author
                    and message.channel == ctx.channel)

        def check_p2(message):
            return message.author == user and message.channel == ctx.channel

        async def end():
            self.currently_fighting.remove(ctx.author)
            self.currently_fighting.remove(user)

            if p1_health != 100 and p2_health != 100:
                if len(p1_powerups) > 0:
                    Data.c.execute(
                        "UPDATE users SET powerups = :new_powerups WHERE id = :user_id",
                        {
                            "new_powerups": "{}",
                            "user_id": ctx.author.id
                        },
                    )
                    Data.conn.commit()
                    await ctx.send(
                        f"{ctx.author.mention}, you have used up your active powerups."
                    )

                if len(p2_powerups) > 0:
                    Data.c.execute(
                        "UPDATE users SET powerups = :new_powerups WHERE id = :user_id",
                        {
                            "new_powerups": "{}",
                            "user_id": user.id
                        },
                    )
                    Data.conn.commit()
                    await ctx.send(
                        f"{user.mention}, you have used up your active powerups."
                    )

        await ctx.send(
            f"{ctx.author.mention} wants to fight {user.mention}. Let's see how this goes..."
        )

        while True:
            # Player 2 turn
            p2_resp_valid = False

            try:
                while not p2_resp_valid:
                    await ctx.send(
                        f"{user.mention}, it's your turn! What will you do?\n`punch`, `defend`, `end`"
                    )

                    p2_response = (await self.bot.wait_for("message",
                                                           check=check_p2,
                                                           timeout=30)).content

                    if p2_response == "punch":
                        damage = random.randint(10, 45)

                        try:
                            damage += p2_powerups["damage_increase"]
                        except KeyError:
                            pass

                        p1_health -= damage
                        p2_resp_valid = True

                        await ctx.send(
                            f"**{p2_name}** bazooka punched **{p1_name}** and did **{damage}** damage! wHoOaA..."
                        )

                    elif p2_response == "defend":
                        heal = random.randint(5, 30)
                        p2_health += heal
                        p2_resp_valid = True

                        await ctx.send(
                            f"**{p2_name}** defended and regained **{heal}** health! Proteccshun..."
                        )

                    elif p2_response == "end":
                        await ctx.send(
                            f"**{p2_name}** chickened out, spam noob in the chat!"
                        )
                        await end()
                        return

                    else:
                        await ctx.send("Invalid response!")

            except asyncio.TimeoutError:
                await ctx.send(
                    f"**{p2_name}** didn't respond in time what a noob...")
                await end()
                return

            if p1_health <= 0:
                await ctx.send(f"Wow **{p1_name}** just died. Git gud noooob!")
                await end()
                return
            else:
                await ctx.send(
                    f"**{p1_name}** is now left with **{p1_health}** health.")

            # Player 1 turn
            p1_resp_valid = False

            try:
                while not p1_resp_valid:
                    await ctx.send(
                        f"{ctx.author.mention}, it's your turn! What will you do?\n`punch`, `defend`, `end`"
                    )

                    p1_response = (await self.bot.wait_for("message",
                                                           check=check_p1,
                                                           timeout=30)).content

                    if p1_response == "punch":
                        damage = random.randint(10, 45)

                        try:
                            damage += p1_powerups["damage_increase"]
                        except KeyError:
                            pass

                        p2_health -= damage
                        p1_resp_valid = True

                        await ctx.send(
                            f"**{p1_name}** bazooka punched **{p2_name}** and did **{damage}** damage! wHoOaA..."
                        )

                    elif p1_response == "defend":
                        heal = random.randint(5, 30)
                        p1_health += heal
                        p1_resp_valid = True

                        await ctx.send(
                            f"**{p1_name}** defended and regained **{heal}** health! Proteccshun..."
                        )

                    elif p1_response == "end":
                        await ctx.send(
                            f"**{p1_name}** chickened out, spam noob in the chat!"
                        )
                        await end()
                        return

                    else:
                        await ctx.send("Invalid response!")

            except asyncio.TimeoutError:
                await ctx.send(
                    f"**{p1_name}** didn't respond in time what a noob...")
                await end()
                return

            if p2_health <= 0:
                await ctx.send(f"Wow **{p2_name}** just died. Git gud noooob!")
                await end()
                return
            else:
                await ctx.send(
                    f"**{p2_name}** is now left with **{p2_health}** health.")
Esempio n. 12
0
    async def rob(self, ctx, victim: discord.Member):
        if ctx.author.id == victim.id:
            await ctx.send("You can't do that to yourself, smh...")
            return

        Data.check_user_entry(ctx.author)
        Data.check_user_entry(victim)

        Data.c.execute(
            "SELECT wallet FROM users WHERE id = :user_id",
            {"user_id": ctx.author.id},
        )
        robber_wallet = Data.c.fetchone()[0]

        Data.c.execute(
            "SELECT wallet FROM users WHERE id = :user_id",
            {"user_id": victim.id},
        )
        victim_wallet = Data.c.fetchone()[0]

        if robber_wallet < 150:
            amount_needed = 150 - robber_wallet
            await ctx.send(
                f"You need at least 150 beans for that. You need {amount_needed} more beans..."
            )
            return

        if victim.status != discord.Status.offline:
            success_rate = 35
        else:
            success_rate = 70

        chance = random.randint(0, 100)

        if chance < success_rate:
            amount_stolen = random.randint(0, victim_wallet)
            await ctx.send(
                f"OMG! You stole **{amount_stolen} beans** from **{victim.display_name}**..."
            )
        else:
            amount_stolen = random.randint(-150, -70)
            await ctx.send(
                f"You got caught stealing from **{victim.display_name}** and had to pay them **{abs(amount_stolen)} beans**"
            )

        Data.c.execute(
            "UPDATE users SET wallet = :new_wallet WHERE id = :user_id",
            {
                "new_wallet": robber_wallet + amount_stolen,
                "user_id": ctx.author.id,
            },
        )
        Data.c.execute(
            "UPDATE users SET wallet = :new_wallet WHERE id = :user_id",
            {
                "new_wallet": victim_wallet - amount_stolen,
                "user_id": victim.id,
            },
        )

        Data.conn.commit()
Esempio n. 13
0
    async def deposit(self, ctx, amount):
        Data.check_user_entry(ctx.author)

        # Get current wallet and banks balances
        Data.c.execute(
            "SELECT wallet, bank, bank_capacity FROM users WHERE id = :user_id",
            {"user_id": ctx.author.id},
        )
        data = Data.c.fetchone()
        wallet_amount = data[0]
        bank_amount = data[1]
        bank_capacity = data[2]

        if str(amount) == "all" or str(amount) == "max":
            amount = wallet_amount

            if bank_amount + amount > bank_capacity:
                amount = bank_capacity - bank_amount

        else:
            amount = int(amount)

            if amount == 0:
                await ctx.send(
                    "Why are you using this command if you aren't depositing anything?"
                )
                return
            elif amount < 1:
                await ctx.send(
                    "There's a command for withdrawing as well, you know..."
                )
                return

            # Ensure user has enough to deposit
            if amount > wallet_amount:
                amount_needed = amount - wallet_amount
                await ctx.send(
                    f"You don't have enough beans for that. You need {amount_needed} more beans."
                )
                return

            if bank_amount + amount > bank_capacity:
                await ctx.send(
                    "You don't have enough space in your bank for that."
                )
                return

            # Ensure user doesn't go over the capacity

        # Update balances
        Data.c.execute(
            "UPDATE users SET wallet = :new_wallet_amount, bank = :new_bank_amount WHERE id = :user_id",
            {
                "new_wallet_amount": wallet_amount - amount,
                "new_bank_amount": bank_amount + amount,
                "user_id": ctx.author.id,
            },
        )

        Data.conn.commit()
        await ctx.send(f"You deposited **{amount} beans** to your bank.")
Esempio n. 14
0
    async def buy(self, ctx, quantity: int, *, item_name):
        Data.check_user_entry(ctx.author)

        Data.c.execute(
            "SELECT wallet, inventory FROM users WHERE id = :user_id",
            {"user_id": ctx.author.id},
        )
        data = Data.c.fetchone()
        wallet_amount = data[0]
        inventory = json.loads(data[1])

        item_info = None

        for item in self.shop_data:
            if item["name"].lower() == item_name.lower():
                item_info = item
                break

        if item_info is None:
            return

        item_n = item_info["name"]
        total_price = item_info["price"] * quantity

        if total_price > wallet_amount:
            amount_needed = total_price - wallet_amount
            await ctx.send(
                f"You don't have enough beans for that. You need {amount_needed} more beans."
            )
            return

        # Find out if the item being bought is a duplicate
        item_duplicate = False
        duplicate_index = None
        for (i, item) in enumerate(inventory):
            if item["name"] == item_n:
                item_duplicate = True
                duplicate_index = i
                break

        if item_duplicate:
            inventory[duplicate_index]["quantity"] += quantity
        else:
            inventory_entry = {
                "name": item_n,
                "description": item_info["description"],
                "quantity": quantity,
                "function_id": item_info["function_id"],
                "function_vars": item_info["function_vars"],
            }
            inventory.append(inventory_entry)

        Data.c.execute(
            "UPDATE users SET inventory = :new_json WHERE id = :user_id",
            {
                "new_json": json.dumps(inventory),
                "user_id": ctx.author.id
            },
        )

        Data.c.execute(
            "UPDATE users SET wallet = :new_amount WHERE id = :user_id",
            {
                "new_amount": wallet_amount - total_price,
                "user_id": ctx.author.id,
            },
        )

        Data.conn.commit()

        if quantity > 1:
            await ctx.send(
                f"You bought **{quantity} {item_n}s** for **{total_price} beans**!"
            )
        else:
            await ctx.send(
                f"You bought **{item_n}** for **{total_price} beans**!")
Esempio n. 15
0
    async def use(self, ctx, *, item_name):
        Data.check_user_entry(ctx.author)

        Data.c.execute(
            "SELECT bank_capacity, inventory FROM users WHERE id = :user_id",
            {"user_id": ctx.author.id},
        )
        data = Data.c.fetchone()
        bank_capacity = data[0]
        inventory = json.loads(data[1])

        # Find the desired item in inventory
        inv_index = None
        for (i, item) in enumerate(inventory):
            if item["name"].lower() == item_name.lower():
                inv_index = i
                break

        if inv_index is None:
            return

        # Remove that item from inventory
        item_info = inventory[inv_index]

        if item_info["quantity"] > 1:
            item_info["quantity"] -= 1
        else:
            inventory.pop(inv_index)

        # Perform the item's action
        f_id = item_info["function_id"]

        if f_id is not None:
            f_vars = item_info["function_vars"]

            if f_id == 0:  # Bank Storage Coupon
                bank_capacity += f_vars["bank_capacity_increase"]
                Data.c.execute(
                    "UPDATE users SET bank_capacity = :new_capacity WHERE id = :user_id",
                    {
                        "new_capacity": bank_capacity,
                        "user_id": ctx.author.id
                    },
                )

            elif f_id == 1:  # Sugar Coated Bean
                Data.c.execute(
                    "SELECT powerups FROM users WHERE id = :user_id",
                    {"user_id": ctx.author.id},
                )
                current_powerups = json.loads(Data.c.fetchone()[0])

                if "damage_increase" in current_powerups:
                    await ctx.send(f"This powerup is already active!")
                    return

                current_powerups["damage_increase"] = f_vars["damage_increase"]

                Data.c.execute(
                    "UPDATE users SET powerups = :new_powerups WHERE id = :user_id",
                    {
                        "new_powerups": json.dumps(current_powerups),
                        "user_id": ctx.author.id,
                    },
                )

        # Write inventory changes to DB
        Data.c.execute(
            "UPDATE users SET inventory = :new_inventory WHERE id = :user_id",
            {
                "new_inventory": json.dumps(inventory),
                "user_id": ctx.author.id
            },
        )
        Data.conn.commit()

        item_n = item_info["name"]

        if self.is_vowel(item_n[0]):
            await ctx.send(f"You used an **{item_n}**!")
        else:
            await ctx.send(f"You used a **{item_n}**!")