Example #1
0
    async def on_call(self, ctx, args, **flags):
        value = flags.pop('value', None)

        if value:
            if flags:
                return '{error} value flag conflict with all other flags'

            if not value.isdigit():
                return '{error} value is not integer'

            permissions = Permissions(permissions=int(value))
        else:
            permissions = None

        channel_flag = flags.pop('channel', None)
        if channel_flag is None:
            channel = ctx.channel
        else:
            channel = await find_channel(channel_flag, ctx.guild)
            if channel is None:
                return '{warning} Channel not found'

        only_true  = flags.pop('t', False)
        only_false = flags.pop('f', False)
        use_global = flags.pop('global', False)

        if only_true and only_false:
            return '{error} t and f flags conflict'

        if permissions is not None:
            target = value
        elif len(args) == 1:
            if use_global:
                permissions = ctx.author.guild_permissions
            else:
                permissions = channel.permissions_for(ctx.author)
            target = str(ctx.author)
        else:
            role = await find_role(args[1:], ctx.guild)
            if role is not None:
                permissions = role.permissions
                target = str(role)

                if use_global:
                    if permissions.administrator:
                        permissions = Permissions.all()
                elif permissions.administrator:
                    if isinstance(channel, VoiceChannel):
                        permissions = Permissions(
                            Permissions.all().value & ~Permissions.text().value)
                    elif isinstance(channel, TextChannel):
                        permissions = Permissions(
                            Permissions.all().value & ~Permissions.voice().value)
                    else:
                        permissions = Permissions(
                            Permissions.all().value
                            & ~Permissions.text().value
                            & ~Permissions.voice().value
                        )
                else:
                    for k, v in channel.overwrites_for(role):
                        if v is not None:
                            setattr(permissions, k, v)
            else:
                member = await find_user(args[1:], ctx.message, strict_guild=True)
                if member is None:
                    return '{warning} Role or member not found'

                if use_global:
                    permissions = member.guild_permissions
                else:
                    permissions = channel.permissions_for(member)
                target = str(member)

        if only_true:
            p = [(k, v) for k, v in permissions if v]
        elif only_false:
            p = [(k, v) for k, v in permissions if not v]
        else:
            p = permissions

        return f'Permissions of **{target}** in **{channel.mention if not use_global else ctx.guild}**```\n' + '\n'.join(f'{PERM_THERE if v else PERM_MISSING} | {k}' for k, v in p) + '```'
Example #2
0
async def on_message(message):
    global messages
    messages += 1

    # Logging the text messages to analyse output
    print(message.author, ":", message.content, "\n")

    # Server ID
    id = client.get_guild(586102837465972746)

    # When someone send a message, this status will pop up
    await client.change_presence(activity=discord.Game(name="Beta"))

    warnMessage = f"This word could offend other people {message.author}. So please **stop** using it. " \
        f"\n\n*This action was performed by the Anton Bot, to delete inappropriate messages." \
        f"\nFor questions please contact the developer of this Bot.\n\nDiscord: Smartskull#4305.*"

    # Lists all commands
    if message.content == "/help":
        await message.channel.send(f"Hello {message.author.mention}! Here you see all the available commands for Anton"
                                   "\n\n ```You have to type / before you can use the commands.\n\n\n"
                                   "Standard commands:\n------------------\n\n"
                                   "> help                          [Lists all commands for Anton]\n\n"
                                   "> rules                         [Sends you an private message with all the "
                                   "server rules]\n\n"
                                   "> stats                         [Statistics of the server]\n\n"
                                   "> tou                           [Terms of use. What does Anton collect?]\n\n\n"
                                   "Fast server managing[Beta]:\n---------------------------\n\n"
                                   "> add-role [rolename]           [Adding a special role to your server]\n\n"
                                   "> su                            [Creating the <Super user> role]\n\n"
                                   "> sh                            [This is the <Stream host> role.]\n\n"
                                   "> chEdit                        [Creating the <Channel editor> role]\n\n"
                                   "> txtEdit                       [Creating the <Text editor> role]\n\n\n"
                                   "Social media:\n-------------\n\n"
                                   "> tw                            [Opens Twitter in your browser]\n\n"
                                   "> in                            [Opens the instagram page in your browser]\n\n"
                                   "> fb                            [Opens Facebook in your browser]\n\n"
                                   "> git                           [Opens Github in your browser]\n\n"
                                   "> login                         [type </login {tw/in/fb/git}>]```")

    # An private message that includes all the server rules
    elif message.content == "/rules":
        await message.author.send(f"Hi {message.author.mention}. This are the standard server rules. Standard means "
                                  f"*most common and widely used*."
                                  f"\nIf you break any of this rules, you get kicked or banned from the server\n\n"
                                  f"> Don`t spread hate, racism or anything else that could hurt someone. "
                                  f"Spread love:heart:\n\n> In political discussions, please be as kind as possible. "
                                  f"*Attack ideas, not people*.\n\n"
                                  f"> Racism is ***S T R I C T L Y  F O R B I D D E N*** and you will get banned when "
                                  f"caught posting this kind of content.\n\n"
                                  f"> If you are able to manipulate the Discord server, changing permissions or "
                                  f"anything else that could threaten the server, please contact the server owner.\n\n"
                                  f"*Privacy makes free*. That is the reason why i **do not** collect personal data. "
                                  f"Also, you can see the code from *Anton Bot* on Github\n\nGithub repository:"
                                  f"https://github.com/Smartskull/Anton")

    # When the user sends "/stats" he will receive the most important server information.
    elif message.content == "/stats":
        await message.channel.send(f"Information about the *{id.name}* server:\n\n"
                                   f"```Name of server:            {id.name}\n\n"  # Display the server name
                                   f"Server owner:              {discord.Guild.owner.__get__(id)}\n\n"
                                   f"User on this server:       {id.member_count}\n\n"  # Count the users
                                   # When was the server created? [discord.Guild.created_at]
                                   f"Server created:            {discord.Guild.created_at.__get__(id)}\n\n"
                                   f"{message.author.name} joined on:       {discord.Member.joined_at}```")

    # Displays the "Terms of use".
    elif message.content == "/tou":
        await message.delete()
        await message.channel.send(f"Good to see you {message.author}! *What does Anton collect?*\n\n"
                                   f"   Anton **does not** collect or analyse text massages, voice calls or images "
                                   f"send trough the user.\n\n"
                                   f"   Anton **doesn't** collect time relevant data. That means he is not able to say "
                                   f" *how long*  someone is online or when the user joined\n\n"
                                   f"   Anton **does** count messages. This is relevant so the server owner knows "
                                   f"how many messages were send in one hour/day/month.\n\n"
                                   f"   Yes, Anton can automatically kick you. "
                                   f"Not because he collects messages. Anton has an "
                                   f"integrated swearing list. He just reacts if one word of this list was used.\n\n"
                                   f"If you have any questions or are not sure about the TOU, please contact me."
                                   f"\n\nMy Discord: Smartskull#4305\n\nThe Github of Anton: "
                                   f"https://github.com/Smartskull/Anton")

    # If a Owner wants to have some user information, he can use the </user "usrName"> command
    elif '/user' in message.content:
        # Checks if the message.author has the correct role
        if discord.utils.get(message.author.roles, name='Staff roles'):
            print('The user {} executed the /user command'.format(message.author))
            await message.delete()

            # This is a collection of random qoutes the message author gets when executing the command
            answerList = ['*The quieter you become the more you are able to hear* - Rumi',
                          'Arguing that you dont care about the right to privacy because you have nothing to hide '
                          'is no different than saying you dont care about free speech because you have nothing to say.*'
                          ' - Edward Snowden', '`import antigravity`',
                          '*With great power comes great responsibility* - Uncle Ben']

            usrID = message.mentions[0].id  # The id of the mentioned user
            usrName = message.mentions[0].name  # The name of the mentioned user
            usrRole = message.mentions[0].top_role  # The role of the mentioned user
            usrAvat = message.mentions[0].avatar_url  # The avatar of the mentioned user
            usrStat = message.mentions[0].status  # The status of the mentioned user
            usrJoinDate = \
                message.mentions[0].joined_at.strftime('%d.%m.%Y, um %H:%M Uhr')  # The joind date of the mentioned user
            usrCreatedAt = message.mentions[0].created_at.strftime('%d.%m.%Y, um %H:%M Uhr')

            # Creating the Embed (discord.Embed)
            usrInfo = discord.Embed(

                # The standard Embed settings:
                title='User Info von: {}'.format(usrName),
                description='',  # The description. At the moment it is empty
                color=discord.Color.blue()  # The title of the Embed

            )

            # Other design settings for the embed:
            usrInfo.add_field(name='ID', value=usrID)  # Accessing the the mentioned user`s id
            usrInfo.add_field(name='Role:', value=usrRole)  # The role of the mentioned user
            usrInfo.add_field(name='Join Date:', value=usrJoinDate)  # Displaying the join date of the mentioned user
            usrInfo.add_field(name='Account created:', value=usrCreatedAt)  # The role of the mentioned user
            usrInfo.add_field(name='Status', value=usrStat)  # The current status of the mentioned user
            usrInfo.set_image(url='{}'.format(usrAvat))  # The thumbnail. Its DC profile picture
            usrInfo.set_thumbnail(url=
                                  'https://cdn.discordapp.com/avatars/464905046962864128/'
                                  '189292578a56174bf37e672599c7d7be.webp?size=1024')  # The thumbnail. Target/Author?
            usrInfo.set_footer(text='Command executed from: {}'
                               .format(message.author))  # The footer shows the message author

            # Sending the embed to the message author
            await message.author.send(embed=usrInfo)

            # To hide the actual message
            await message.channel.send(random.choice(answerList))

        # The 'Permissions Denied' message if someone without the right permissions execute the command
        else:
            print('The user {} failed to execute the /user command'.format(message.author))
            await message.channel.send('ERROR[:01] ***Permission Denied***.'
                                       '\n\nYou dont have the permission to use this command!')

    # The most powerful role of all. The "Super user" role(inspired by the linux command "sudo su")
    elif message.content == "/add-role su":
        await discord.Guild.create_role(id, reason=f"Created the ""super user"" role in the {id.name} server",
                                        name="Super user", permissions=discord.Permissions.all())
        # If the role was created, this "success message" will show up
        await message.channel.send(f"Success {message.author.name}! The ***Super user*** role was created.\n\n"
                                   f"*Role created at {datetime.datetime.now()}.\n\n "
                                   f"This role is **very** powerful. Never forget: "
                                   f"*With great power, comes great responsibility*")

    elif message.content == "/add-role sh":
        await discord.Guild.create_role(id, reason="Created the ""Stream host"" role in the {id.name} server",
                                        name="sHost", permissions=discord.Permissions.administrator)

    # If there is an way to make this easier.. please tell me. It`s a pain to add new roles.

    # Creating the "Channel editor" role.
    elif message.content == "/add-role chEdit":
        await discord.Guild.create_role(id, reason=f"Created the ""Channel editor"" role in the {id.name} server",
                                        name="chEdit", permissions=Permissions.all_channel())
        # If the role was created, this "success message" will show up
        await message.channel.send(f"Success {message.author}! The ***Channel editor*** role was created."
                                   f"\n\n*Role created at "
                                   f"{datetime.datetime.now()}.*")

    # Creating the "Text editor" role.
    elif message.content == "/add-role txtEdit":
        await discord.Guild.create_role(id, reason=f"Created the ""Text editor"" role in the {id.name} server",
                                        name="txtEdit", permissions=Permissions.text())
        # If the role was created, this "success message" will show up
        await message.channel.send(f"Success {message.author}! The ***Text editor*** role was created."
                                   f"\n\n*Role created at "
                                   f"{datetime.datetime.now()}.*")