예제 #1
0
    async def gamble(self, ctx, amount=None):
        user_tokens = int(dbfunctions.get_user(ctx.author).tokens)

        # Require user input
        if not amount: raise Exception("No user input")

        # If input is not an int, determine amount
        if not services.is_int(amount):
            if amount == "half":
                amount = math.floor(user_tokens / 2)
            elif amount in ["max", "all", "gamba"]:
                amount = user_tokens
            elif "%" in amount:
                amount = str(amount).replace("%", "")
                if not services.is_int(amount):
                    raise Exception("Bad user input")
                amount = math.floor(user_tokens / 100 * int(amount))
            else:
                raise Exception("Bad user input")
        amount = int(amount)
        if 0 >= amount or amount > user_tokens:
            raise Exception("Faulty token amount")

        # Do the gamble and format user feedback
        roll = services.attempt_chance(1, 100, 49)
        result = "won" if roll[0] else "lost"
        if not roll[0]: amount = amount * -1
        result_text = f"{ctx.author.display_name} {result} {abs(amount)} tokens and now has {user_tokens + amount}."

        # Update tokens and send user feedback
        dbfunctions.update_user_tokens(ctx.guild, ctx.author, amount)
        await services.send_simple_embed(ctx, self.client.user, result_text)
예제 #2
0
    async def gamble(self, ctx, amount=None):
        # Require user input
        if not amount:
            await services.send_simple_embed(
                ctx, ctx.author,
                f"{ctx.author.mention}, you did not specify an amount!")
            await services.failed_command_react(ctx.message)
            return

        user_tokens = int(dbfunctions.get_user(ctx.author).tokens)

        # Parse amount
        amount = services.parse_amount(amount, user_tokens)

        # Return any errors occurred while parsing
        if isinstance(amount, Exception):
            await services.send_simple_embed(
                ctx, ctx.author, f"{ctx.author.mention}, {str(amount)}")
            await services.failed_command_react(ctx.message)
            return

        # Do the gamble and format user feedback
        roll = services.attempt_chance(1, 100, 49)
        result = "won" if roll[0] else "lost"
        if not roll[0]: amount = amount * -1
        result_text = f"{ctx.author.mention} {result} {abs(amount)} tokens and now has {user_tokens + amount}."

        # Update tokens and send user feedback
        dbfunctions.update_user_tokens(ctx.guild, ctx.author, amount)
        await services.send_simple_embed(ctx, self.client.user, result_text)
예제 #3
0
    async def userinfo(self, ctx, *, user=None):
        # wait UIdrawer.request_ui_card()
        # await ctx.send(file=discord.File('support/uicard.png'))

        # Fetch relevant user and accompanying roles
        user = Search.search_user(ctx, user)
        roles = [role for role in user.roles]
        # Slice @@everyone out of the list
        roles = roles[1:]
        # Get user position in guild history (the Xth user to join the guild... that's still in the guild)
        position = sorted(ctx.guild.members,
                          key=lambda x: x.joined_at).index(user) + 1
        ordinal = get_ordinal(position)

        # Create embed
        embed = discord.Embed(colour=user.color,
                              timestamp=ctx.message.created_at,
                              title="*Questions?*",
                              url=cfg.embed_url)
        # Set embed fields and values
        embed.set_author(name=f"{user}")
        embed.set_thumbnail(url=user.avatar_url)
        embed.set_footer(text=cfg.embed_footer,
                         icon_url=self.client.user.avatar_url)

        embed.add_field(
            name="-",
            value="**ID:** " + str(user.id) + "\n"
            "**Created at:** " +
            user.created_at.strftime("%a, %#d %B %Y, %I:%M %p UTC") + "\n"
            "**Joined at:** " +
            user.joined_at.strftime("%a, %#d %B %Y, %I:%M %p UTC") + "\n"
            f"**{ordinal} member of {ctx.guild}.**",
            inline=False)

        # Make sure roles are listed correctly, even if empty
        if roles:
            embed.add_field(name=f"Roles ({len(roles)}):",
                            value=" ".join([role.mention for role in roles]),
                            inline=False)
            embed.add_field(name="Top role:",
                            value=user.top_role.mention,
                            inline=True)
        else:
            embed.add_field(name="Roles (0):", value="None")
            embed.add_field(name="Top role:", value="None", inline=True)
        embed.add_field(name="Bot?", value=user.bot, inline=True)

        if not user.bot:
            dbuser = dbfunctions.get_user(user)
            embed.add_field(
                name="User involvement",
                value=":e_mail: Messages sent: " + str(dbuser.messages_sent) +
                " :speaking_head: Activity: " + str(dbuser.activity_points),
                inline=False)
            embed.add_field(name="User stats",
                            value=":angel: Karma: " + str(dbuser.karma) +
                            " :moneybag: Tokens: " + str(dbuser.tokens),
                            inline=False)
        await ctx.send(embed=embed)
예제 #4
0
    async def roll(self, ctx, amount=None):
        # Require user input
        if not amount:
            await services.send_simple_embed(
                ctx, ctx.author,
                f"{ctx.author.mention}, you did not specify an amount!")
            await services.failed_command_react(ctx.message)
            return

        user_tokens = int(dbfunctions.get_user(ctx.author).tokens)

        # Parse amount
        amount = services.parse_amount(amount, user_tokens)

        # Return any errors occurred while parsing
        if isinstance(amount, Exception):
            await services.send_simple_embed(
                ctx, ctx.author, f"{ctx.author.mention}, {str(amount)}")
            await services.failed_command_react(ctx.message)
            return

        user_roll = random.randint(1, 6)
        bot_roll = random.randint(1, 6)

        embed = discord.Embed()

        if user_roll == bot_roll:
            embed = discord.Embed(
                colour=discord.Color.from_rgb(243, 188, 64),
                title="\\🎲 Die Roll - Tie!",
                description=
                f"{ctx.author.mention} rolled the die and tied with {self.client.user.mention}!\nNo one lost any tokens!"
            )

        elif user_roll < bot_roll:
            embed = discord.Embed(
                colour=discord.Color.from_rgb(241, 85, 74),
                title="\\🎲 Die Roll - Lost!",
                description=
                f"{ctx.author.mention} rolled the die and lost {abs(amount)} tokens to {self.client.user.mention}!"
            )
            dbfunctions.update_user_tokens(ctx.guild, ctx.author, amount * -1)

        elif user_roll > bot_roll:
            embed = discord.Embed(
                colour=discord.Color.from_rgb(73, 230, 103),
                title="\\🎲 Die Roll - Won!",
                description=
                f"{ctx.author.mention} rolled the die against {self.client.user.mention} and won {abs(amount)} tokens!"
            )
            dbfunctions.update_user_tokens(ctx.guild, ctx.author, amount)

        embed.add_field(name=f"{ctx.author.name}'s roll",
                        value=f"``{user_roll}``")
        embed.add_field(name=f"{self.client.user.name}'s roll",
                        value=f"``{bot_roll}``")

        await ctx.send(embed=embed)
예제 #5
0
파일: services.py 프로젝트: zionxiv/Anvil
async def set_user_auto_roles(user, guild):
    # Auto role and user data
    roles_raw = dbfunctions.retrieve_roles(guild.id)
    auto_roles = get_roles_by_id(guild, roles_raw)

    user_data = dbfunctions.get_user(user)
    user_messages, user_points, user_karma, user_tokens = user_data.messages_sent, \
                                                          user_data.activity_points, user_data.karma, user_data.tokens
    # Role lists
    all_auto_roles = []
    current_roles = user.roles
    allowed_roles = []
    not_allowed_roles = []

    # Check which auto_roles apply to the current user
    for role in auto_roles:
        all_auto_roles.append(role.role)
        if user_messages >= role.message_req and user_points >= role.point_req and user_karma >= role.karma_req \
                and user_tokens >= role.token_req:
            allowed_roles.append(role.role)

    # Remove auto roles the user shouldn't have from current_roles
    for role in current_roles.copy():
        if role in all_auto_roles and role not in allowed_roles:
            not_allowed_roles.append(role)
        if role not in allowed_roles:
            current_roles.remove(role)

    # Set up roles to actually add
    for role in allowed_roles.copy():
        if role in current_roles:
            allowed_roles.remove(role)

    # Actually add/remove roles here
    # Add roles first. Might break if missing required perms!
    if bool(allowed_roles):
        try:
            await user.add_roles(*allowed_roles,
                                 reason="Automatic role update")
            logger.log(logger.INFO, f"added auto roles to {user}", guild)
        except Exception as e:
            logger.log(logger.ERROR,
                       f"couldn't add an auto role to {user} due to: {e}.",
                       guild)
    # Removed roles. Might break if missing required perms!
    if bool(not_allowed_roles):
        try:
            await user.remove_roles(*not_allowed_roles,
                                    reason="Automatic role update")
            logger.log(logger.INFO, f"removed auto from roles {user}", guild)
        except Exception as e:
            logger.log(
                logger.ERROR,
                f"couldn't remove an auto role from {user} due to: {e}.",
                guild)
예제 #6
0
    async def give(self, ctx, receiver=None, amount=None):
        # Require user input
        if not amount:
            await services.send_simple_embed(
                ctx, ctx.author,
                f"{ctx.author.mention}, you did not specify an amount!")
            await services.failed_command_react(ctx.message)
            return

        sender_tokens = int(dbfunctions.get_user(ctx.author).tokens)

        # Parse amount
        amount = services.parse_amount(amount, sender_tokens)

        # Return any errors occurred while parsing
        if isinstance(amount, Exception):
            await services.send_simple_embed(
                ctx, ctx.author, f"{ctx.author.mention}, {str(amount)}")
            await services.failed_command_react(ctx.message)
            return

        # Get receiver
        receiver_user = Search.search_user(ctx, receiver)

        # Safety checks
        if receiver_user is None:
            await services.send_simple_embed(
                ctx, ctx.author,
                f"I couldn't find any user from: ``{str(receiver)}``")
            await services.failed_command_react(ctx.message)
            return
        elif receiver_user.id is ctx.author.id:
            await services.send_simple_embed(
                ctx, ctx.author,
                f"{ctx.author.mention}, you can't give tokens to yourself, smh!"
            )
            await services.failed_command_react(ctx.message)
            return
        elif receiver_user.bot:
            await services.send_simple_embed(
                ctx, ctx.author,
                f"You can't give tokens to a bot, smh {ctx.author.mention}!")
            await services.failed_command_react(ctx.message)
            return

        # Update tokens
        dbfunctions.update_user_tokens(ctx.guild, ctx.author, amount * -1)
        dbfunctions.update_user_tokens(ctx.guild, receiver_user, amount)

        # Send success message
        await services.send_simple_embed(
            ctx, self.client.user,
            f"{ctx.author.mention} gave {receiver_user.mention} {abs(amount)} tokens."
        )
예제 #7
0
    async def messages(self, ctx, user=None):
        user = Search.search_user(ctx, user)
        if user is None or user.bot:
            user = ctx.author

        dbuser = dbfunctions.get_user(user)
        embed = discord.Embed(colour=user.color,
                              url=cfg.embed_url)
        # Set embed fields and values
        embed.set_author(name=f"{user}", icon_url=f"{user.avatar_url}")
        embed.description = f":speaking_head: Messages: {dbuser.messages_sent}"
        await ctx.send(embed=embed)
예제 #8
0
    async def tokens(self, ctx, user=None):
        user = Search.search_user(ctx, user)
        if user is None or user.bot:
            user = ctx.author

        dbuser = dbfunctions.get_user(user)
        embed = discord.Embed(colour=user.color,
                              url=cfg.embed_url)
        # Set embed fields and values
        embed.set_author(name=f"{user}", icon_url=f"{user.avatar_url}")
        embed.description = f":moneybag: Tokens: {dbuser.tokens}"
        await ctx.send(embed=embed)
예제 #9
0
    async def bet(self, ctx, face: int, amount=None):
        # Require user input
        if not face:
            await services.send_simple_embed(
                ctx, ctx.author,
                f"{ctx.author.mention}, you did not specify a die face!")
            await services.failed_command_react(ctx.message)
            return
        elif face < 1 or face > 6:
            await services.send_simple_embed(
                ctx, ctx.author,
                f"{ctx.author.mention}, a die only has 6 faces!")
            await services.failed_command_react(ctx.message)
            return

        if not amount:
            await services.send_simple_embed(
                ctx, ctx.author,
                f"{ctx.author.mention}, you did not specify an amount!")
            await services.failed_command_react(ctx.message)
            return

        user_tokens = int(dbfunctions.get_user(ctx.author).tokens)

        # Parse amount
        amount = services.parse_amount(amount, user_tokens)

        # Return any errors occurred while parsing
        if isinstance(amount, Exception):
            await services.send_simple_embed(
                ctx, ctx.author, f"{ctx.author.mention}, {str(amount)}")
            await services.failed_command_react(ctx.message)
            return

        if (amount < 20):
            await services.send_simple_embed(
                ctx, ctx.author,
                f"{ctx.author.mention}, you must bet at least 20 tokens!")
            await services.failed_command_react(ctx.message)
            return

        die_roll = random.randint(1, 6)

        embed = discord.Embed()

        if die_roll == face:
            random_multi = random.randint(500, 575)
            winnings = math.floor(amount / 100 * int(random_multi))

            dbfunctions.update_user_tokens(ctx.guild, ctx.author, winnings)

            embed = discord.Embed(
                colour=discord.Color.from_rgb(73, 230, 103),
                title="\\🎲 Bet - Won!",
                description=
                f"{ctx.author.mention} bet on ``{face}`` and won ``{winnings}`` tokens with a random multiplier of ``{abs(random_multi)}%``!"
            )
        else:
            dbfunctions.update_user_tokens(ctx.guild, ctx.author, amount * -1)

            embed = discord.Embed(
                colour=discord.Color.from_rgb(241, 85, 74),
                title="\\🎲 Bet - Lost!",
                description=
                f"{ctx.author.mention} bet on ``{face}`` and lost ``{amount}`` tokens!"
            )

        embed.add_field(name="Die roll", value=f"``{die_roll}``")

        await ctx.send(embed=embed)