Пример #1
0
    async def deposit(self, ctx, amount):
        if amount.lower() == "all":
            bal = functs.get_balance(ctx.author.id)

            if bal == 0:
                await ctx.send("You don't have any credits on hand.")
                return

            functs.update_balance(ctx.author.id, -bal)
            functs.update_bank_balance(ctx.author.id, bal)

            await ctx.send(
                f"Successfully deposited **{bal}** credits to the bank.")
            return

        messages = {
            "NotAFloat":
            "The amount you deposit must be a number.",
            "MoreThanTwoDecimals":
            "You can only deposit credits up to the second decimal place.",
            "LessThanOrEqualToZero":
            "You can only deposit an amount over 0.\nUse `_withdraw [amount]` to take credits from the bank."
        }
        if await functs.invalid_credit_amount(ctx, amount, messages):
            return

        bal = functs.get_balance(ctx.author.id)
        amount = float(amount)
        if amount > bal:
            await ctx.send(
                f"You don't have that many credits on hand. You only have {bal} credits."
            )
            return

        functs.update_balance(ctx.author.id, -amount)
        functs.update_bank_balance(ctx.author.id, amount)

        await ctx.send(
            f"Successfully deposited **{amount}** credits to the bank.")
Пример #2
0
    async def balance(self, ctx, member: discord.Member = None):
        if member == None:
            member = ctx.author

        hand_bal = functs.get_balance(member.id)
        bank_bal = functs.get_bank_balance(member.id)

        embed = discord.Embed(title=f"{member.display_name}'s Balance",
                              description=f'Net worth: {hand_bal + bank_bal}',
                              color=0x5b5f90)
        embed.add_field(name="**Hand Balance**",
                        value=str(hand_bal),
                        inline=False)
        embed.add_field(name="**Bank Balance**",
                        value=str(bank_bal),
                        inline=False)
        await ctx.send(embed=embed)
Пример #3
0
    async def give(self, ctx, member: discord.Member, amount):
        messages = {
            "NotAFloat": "The amount you give must be a number.",
            "MoreThanTwoDecimals":
            "The amount you give can only go up to the second decimal place.",
            "LessThanOrEqualToZero": "You can only give an amount over 0."
        }
        if await functs.invalid_credit_amount(ctx, amount, messages):
            return

        bal = functs.get_balance(ctx.author.id)
        amount = float(amount)
        if amount > bal:
            await ctx.send(
                f"You don't have that many credits in your hand. You only have {bal} credits."
            )
            return

        functs.update_balance(ctx.author.id, -amount)
        functs.update_balance(member.id, amount)

        await ctx.send(
            f"{ctx.author.mention} gave {member.mention} **{amount}** credits!"
        )
Пример #4
0
    async def anagram(self, ctx, bet=None):
        if bet != None:
            messages = {
                "NotAFloat": "Your bet must be a number.",
                "MoreThanTwoDecimals":
                "Your bet cannot go past 2 decimal places.",
                "LessThanOrEqualToZero": "Your bet must be over 0 credits."
            }
            if await functs.invalid_credit_amount(ctx, bet, messages):
                return

            bal = functs.get_balance(ctx.author.id)
            bet = float(bet)
            if bet > bal:
                await ctx.send(
                    f"You don't have that many credits! You have {bal} credits on hand."
                )
                return

        if f"hm_{ctx.author.id}" in globals():
            await ctx.send(
                "You're already playing hangman! Finish the game or wait 5 minutes for that game to automatically end."
            )
            return

        exec(f"global hm_{ctx.author.id}; hm_{ctx.author.id} = None")

        if bet != None:
            functs.update_balance(ctx.author.id, -bet)

        definition = None
        while definition in [None, "ang="]:
            rand_num = random.randint(0, 209785)
            word = Words[rand_num:rand_num + 60]
            word = word[word.find("\n") + 1:]
            word = word[:word.find("\n")]

            data = requests.get(
                f"https://www.merriam-webster.com/dictionary/{word}").text

            definition = data[data.find("\"description\" content=\"") + 23:]
            definition = definition[:definition.find("\"")]

        word = word.lower()

        scrambled = list(word)
        random.shuffle(scrambled)
        title = f"Anagram | {ctx.author.display_name}"
        footer = "Say +cat to guess the word cat."
        lives_message = ["❤"] * 3
        won_game_msg = f"You won {bet} credits!" if bet != None else "You won!"
        lost_game_msg = f"You lost {bet} credits." if bet != None else "You lost."

        embed = discord.Embed(
            title=title,
            description="Let's play anagram! Try to unscramble this word.",
            color=0x23272a)
        embed.add_field(name="**Anagram**",
                        value="".join(scrambled),
                        inline=False)
        embed.add_field(name="**Lives**",
                        value=" ".join(lives_message),
                        inline=False)
        embed.set_footer(
            text=footer,
            icon_url=
            'https://cdn2.iconfinder.com/data/icons/app-types-in-grey/512/info_512pxGREY.png'
        )
        await ctx.send(embed=embed)

        def check(message):
            return message.content.startswith(
                "+") and message.author == ctx.author and len(
                    message.content.strip()) > 1

        while True:
            try:
                guess = await Bot.wait_for("message", timeout=300, check=check)

            except:
                exec(f"del hm_{ctx.author.id}", globals())

                await ctx.send(
                    f"5 minute timer: {ctx.author.mention}'s game has ended.")
                return

            content = guess.content[1:].strip().lower()

            if content == word:
                embed = discord.Embed(title=title,
                                      description=won_game_msg,
                                      color=0x00ff00)
                embed.add_field(name="**Word**", value=word, inline=False)
                embed.add_field(name="**Definition**",
                                value=definition,
                                inline=False)
                embed.add_field(name="**Lives**",
                                value=" ".join(lives_message),
                                inline=False)
                await ctx.send(embed=embed)

                if bet != None:
                    await functs.update_balance(ctx.author.id, bet * 2)

                exec(f"del hm_{ctx.author.id}", globals())
                return

            else:
                lives_message[-lives_message.count('❌') - 1] = '❌'

                if lives_message.count('❤') == 0:
                    embed = discord.Embed(title=title,
                                          description=lost_game_msg,
                                          color=0xff0000)
                    embed.add_field(name="**Word**", value=word, inline=False)
                    embed.add_field(name="**Definition**",
                                    value=definition,
                                    inline=False)
                    embed.add_field(name="**Lives**",
                                    value=" ".join(lives_message),
                                    inline=False)
                    await ctx.send(embed=embed)

                    exec(f"del hm_{ctx.author.id}", globals())
                    return

                embed = discord.Embed(
                    title=title,
                    description=f"Oops! Letter `{content}` is not in the word.",
                    color=0xff0000)
                embed.add_field(name="**Word**", value=word, inline=False)
                embed.add_field(name="**Lives**",
                                value=" ".join(lives_message),
                                inline=False)
                embed.set_footer(
                    text=footer,
                    icon_url=
                    'https://cdn2.iconfinder.com/data/icons/app-types-in-grey/512/info_512pxGREY.png'
                )
                await ctx.send(embed=embed)