Exemplo n.º 1
0
async def ban(ctx, member: discord.Member, *, reason=None):
    """
    Taur bans a user using a member received by parameters 
    and a reason. Call this command using this syntax:

        t/ban @member reason
    """

    # send a private message to the user
    d = '''
Taur banned you from a server.

Reason: {0}

If you have any problem, please contact the mods of the server.
    '''.format(reason)
    #try to send the message
    try:
        msg = ModerationEmbed(d)
        await msg.send(member) # send the message to the member using msg.send()

    except: # this will error if the user has blocked the bot or has server dms disabled so discord can't send them a message.
        print('Could not send a private message to {}.'.format(member))

    else:
        print(decorators.sended_to(member))

    # ban the user
    await member.ban(reason=reason)
    # inform the chat
    msg = ModerationEmbed('{} has been banned by Taur because of the following reason: {}'.format(member, reason))
    await msg.send(ctx)
    print(decorators.responded_to('t/ban'))
Exemplo n.º 2
0
async def kick(ctx, member: discord.Member, *, reason=None):
    """
    Using this command Taur kicks a member from the server using
    the member.kick method. Call this command using this syntax:

        t/kick @member reason
    """
    d = '''
Taur kicked you from a server

Reason: {0}

If you have any problem, please contact the mods of the server.
    '''.format(reason)
    #try to send the message
    try:
        msg = ModerationEmbed(d)
        await msg.send(member) # send the message to the member using msg.send()

    except: # this will error if the user has blocked the bot or has server dms disabled so discord can't send them a message.
        print('Could not send a private message to {}.'.format(member))

    else:
        print(decorators.sended_to(member))

    #k ick the member
    await member.kick()
    # inform the public chat
    msg = ModerationEmbed('{} has been kicked by Taur because of the following reason: {}'.format(member, reason))
    await msg.send(ctx)
    print(decorators.responded_to('t/kick'))
Exemplo n.º 3
0
async def vote(ctx, *, message):
    """
    This command uses a message (p:message:str) passed by parameters to then 
    let all users up-vote or down-vote it. This command can be just called if 
    the person who calls it is a member of the staff.
    """
    # create the emojis variables
    embed = discord.Embed(title="Let's Vote!", description="**{}**\n".format(message), color=discord.Color.blue())
    embed.add_field(name='Vote below', value="Reply with <:upvote:452583845305384981> to vote **Yes**\n \nReact with <:downvote:452583859532333067> to vote **No**")
    # create the message using a msg variable
    msg = await ctx.send("@everyone", embed=embed)
    decorators.add_reactions(msg, ('👍', '👎'))
    print(decorators.responded_to('t/vote'))
Exemplo n.º 4
0
async def purge(ctx, amount=5):
    """
    Taur uses this command to delete messages from the server
    using the ctx.purge method
    """
    try:
        # delete the messages 
        await ctx.channel.purge(limit=amount) # also deletes your own message
        await ctx.send(f"**Taur has deleted {amount} message{'s' if amount > 1 else ''}**") # check if the message is 1, to send "message" instead of "messages"
    except discord.ext.commands.errors.ExpectedClosingQuoteError:
        await ctx.send('Expecting quotes to end the amount argument.')
    except TypeError as e:
        await ctx.send('Invalid type conversion to :int') 
    except:
        await ctx.send('Sorry, but you do not have permissions to use this command.')
    finally:
        print(decorators.responded_to('t/purge'))
Exemplo n.º 5
0
async def on_message(message):

    """
    This discord event will read all the new messages in the discord
    server, so if the user wants to use a command but the command does not need
    permisions or parameters; it will be implemented in this event
    """

    # check if the bot is the author of the message
    if message.author == bot.user:
        return

    with open('dic/bad_words.txt') as f:
        bad_words = [line.rstrip() for line in f]
        # moderation of the message
        message_content = message.content.lower()
        for word in message_content.split():
            # check for mod
               if word in bad_words and message.author != bot.user:
                # delete the message 
                await message.delete()
                print(decorators.deleted(message, word))
                # include the message
                await message.channel.send('Be carefull {}, your message includes the word "{}". Please avoid that word.'.format(message.author.name, word))
                # create the embed message to send to the user (private)
                d = '''
Taur found the word {} in your message. 
This word is included in our [list of prohibited words.]() so Taur has deleted your message
Be careful and avoid these words as you could be banned from the server.

Message:
```{}```
                '''.format(word, message.content)
                # create the embed message using the discord.Embed() class
                e = ModerationEmbed(d)
                await message.author.send(e.get()) # send the embed message
                print(decorators.responded_to(message.author.name))


    if message.content.startswith('t/info'):
        # send information about the bot
        info_embed=discord.Embed(title="Taur | Information",
            description=open('doc/description.txt').read() + '\n\nTaur is active in: {0} servers'.format(len(bot.guilds)),
            color=0x087d1b)
        info_embed.set_author(name="Taur",
            url="https://github.com/PabloCorbCon/Taur")
        info_embed.set_image(url='https://github.com/PabloCorbCon/Taur/blob/master/branding/logo.png?raw=true')
        info_embed.set_footer(text="By Pablo Corbalán | Twitter: @pablocorbcon - GitHub: @PabloCorbCon")

        print(decorators.responded_to('t/info'))
        await message.channel.send(embed=info_embed)


    elif message.content.startswith('t/commands'):
        # create the embed message
        commands_embed=discord.Embed(title="Taur | Commands",
            description='**All the commands start with the prefix "t/**".\n' + load.load_help_commands('dic/commands.json', True) + "\n\n",
            color=0x087d1b)
        commands_embed.set_author(name="Taur",
            url="https://github.com/PabloCorbCon/Taur")
        commands_embed.set_footer(text="By Pablo Corbalán | Twitter: @pablocorbcon - GitHub: @PabloCorbCon")

        print(decorators.responded_to('t/commands'))
        await message.channel.send(embed=commands_embed)


    elif message.content.startswith('t/invite'):
        #create the bot link
        link = 'https://discord.com/api/oauth2/authorize?client_id=745535486784831509&permissions=8&scope=bot' # link to invite the link
        print(decorators.responded_to('t/invite'))
        await message.channel.send("You can **invite Taur using this link: **{}".format(link))


    elif message.content.startswith('t/support'):
        #create the bot's server link
        link = 'https://discord.gg/rEZYpkX'
        print(decorators.responded_to('t/support'))
        await message.channel.send('Taur has his own discord server where you can get suppport:\n\n{}'.format(link))


    elif message.content.startswith('t/ping'):
        await message.channel.send('Pong! {}'.format(round(bot.latency, 2)))
        print(decorators.responded_to('t/ping'))

    elif message.content.startswith('t/chat'):
        channel = message.channel
        # chat with the user using the ./chat/ group
        await channel.send('Remember you can exit the chat using STOP. Now, type something to start.')
        print(decorators.responded_to('t/chat'))
        # create a function to check messages
        def check(m):
            return m.channel == channel and m.author != bot.user
        # create an infinitive loop
        while True:
            return 0 #provisional
            # wait for the next message
            msg = await bot.wait_for('message', check=check)
            # create the sentence
            sentence = chat_mod.answer(msg.content)
            # check if the user wants to exit
            if sentence == 'See you later!':
                break
            print(sentence)
            try:
                await channel.send(sentence)
            except discord.errors.HTTPException as e:
                print('Could not respond to the message: {} with the following sentence: {}.ERROR:{}'.format(msg.content, sentence, e))
            else:
                print('Taur responded to the message: {} with the following sentence: {}.'.format(msg.content, sentence))


    elif message.content.startswith('t/members'):
        # get the list of members
        list_of_members = ''
        for member in message.guild.members:
            list_of_members += ' {0} |'.format(member.name)
        # create the embed message
        members_embed=discord.Embed(title="Taur | Members",
            description='{}'.format(list_of_members),
            color=0x087d1b)
        members_embed.set_author(name="Taur",
            url="https://github.com/PabloCorbCon/Taur")
        members_embed.set_footer(text="By Pablo Corbalán | Twitter: @pablocorbcon - GitHub: @PabloCorbCon")

        # send the message
        await message.channel.send('Members of the server: ', embed=members_embed)  


    elif message.content.startswith('t/joke'):
        # the bot tells a joke, so we have to open the jokes file using the load.load_jokes() function
        joke_index = random.randint(1, 150) # we select a random joke from the jokes file
        # get an specific joke and then tell it
        joke = load.load_jokes('dic/jokes.txt', joke_index, True)
        await message.channel.send(joke)
        print(decorators.responded_to('t/joke'))

    await bot.process_commands(message)
Exemplo n.º 6
0
async def mute(ctx, mute_time: int, member: discord.Member = None, *, reason=None):
    if not member:
        return # return if the command is something like "t/mute"
    # select the role using the utils.get role
    role = discord.utils.get(ctx.guild.roles, name="muted")
    # add the role to the member
    try:
        await member.add_roles(role)

    except AttributeError as e:
        await ctx.send(f"I can't mute {member.mention} because the muted role is not configurated in this server.")

    else:
         # send a private message to the user
        d = '''
        Taur muted {0} you from the server

        Reason:
        {1}

        If you have any problem, please contact the mods of the server.
        '''.format(member, reason)
        #try to send the message
        try:
            msg = embed=ModerationEmbed(d)
            await msg.send(member)

        except: # this will error if the user has blocked the bot or has server dms disabled so discord can't send them a message.
            print('Could not send a private message to {}.'.format(member))

        else:
            print(decorators.sended_to(member))
        # inform the chat that the user has been muted
        msg = ModerationEmbed('{0} has been muted from this server {1} second{2}.\n\nReason:\n{3}'.format(member, mute_time, 's' if mute_time > 1 else '', reason))
        await msg.send(ctx)
        # sleep the time the discord member has been muted using thee asyncio module
        await asyncio.sleep(mute_time) 
        print(decorators.responded_to('t/mute'))

        try:
            await member.remove_roles(role)

        except AttributeError as e:
            await ctx.send(f"I can't  unmute {member.mention} because the muted role is not configurated in this server.")

        else:
            # send a private message to the user
            d = '''
            Taur unmuted you from a server! Please remember you to read and respect the rules.

            If you have any problem, please contact the mods of the server.
            '''
            #try to send the message
            try:
                msg = ModerationEmbed(d)
                await msg.send(member)

            except: # this will error if the user has blocked the bot or has server dms disabled so discord can't send them a message.
                print('Could not send a private message to {}.'.format(member))

            else:
                print(decorators.sended_to(member))
            # sleep the time the discord member has been muted using thee asyncio module
            await asyncio.sleep(mute_time) 
            msg = ModerationEmbed('{0} has been unmuted from this server, please, remember to red the rules...'.format(member))
            await msg.send(ctx )
            print(decorators.responded_to('t/mute'))
            print(decorators.sended_to(str(member.mention)))