Esempio n. 1
0
def run(message):
    '''
        Run

        Run the custom plugin specific code. A returned
        string is the message that will be sent back
        to the user.

        --
        @param  message:dict    The message sent by the user

        @return str
    '''

    # Get the message contents
    text = message['text']

    # Remove a mention. This could be the case
    # if the bot was mentioned in a chat room
    if text.startswith('@'):
        text = text.split(' ', 1)[1].strip()

    # Some bots will accept commands that started
    # with a '/'
    if text.startswith('/'):
        text = text.replace('/', '', 1).strip()

    # Remove the trigger command
    for command in commands():
        text = ignore_case_replace(command, '', text).strip()

    return text
Esempio n. 2
0
def run (message):
    '''
        Run

        Run the custom plugin specific code. A returned
        string is the message that will be sent back
        to the user.

        --
        @param  message:dict    The message sent by the user

        @return str
    '''

    # Get the message contents
    text = message['text']

    # Remove a mention. This could be the case
    # if the bot was mentioned in a chat room
    if text.startswith('@'):
        text = text.split(' ', 1)[1].strip()

    # Some bots will accept commands that started
    # with a '/'
    if text.startswith('/'):
        text = text.replace('/', '', 1).strip()

    # Remove the trigger command
    for command in commands():
        text = ignore_case_replace(command, '', text).strip()

    return text
Esempio n. 3
0
def run (message):
    '''
        Run

        Run the custom plugin specific code. A returned
        string is the message that will be sent back
        to the user.

        --
        @param  message:dict    The message sent by the user

        @return str
    '''

    # Get the message contents
    text = message['text']

    # Remove a mention. This could be the case
    # if the bot was mentioned in a chat room
    if text.startswith('@'):
        text = text.split(' ', 1)[1].strip()

    # Some bots will accept commands that started
    # with a '/'
    if text.startswith('/'):
        text = text.replace('/', '', 1).strip()

    # Try and determine what was the trigger command
    # for this plugin.
    action = text.split(' ')[0].strip()

    # Hopefully we never get here, but just in case.
    if action not in commands():
        return 'Sorry, I don\'t know what to do with: {command}'.format(
            command = action
        )

    # Remove the trigger command
    for command in commands():
        text = ignore_case_replace(command, '', text).strip()

    # Map actions to function and () them
    do_action = {
        'learn': _learn,
        'forget': _forget,
        'show': _show
    }
    response = do_action[action](text)

    return response
Esempio n. 4
0
def run(message):
    '''
        Run

        Run the custom plugin specific code. A returned
        string is the message that will be sent back
        to the user.

        --
        @param  message:dict    The message sent by the user

        @return str
    '''

    # Get the message contents
    text = message['text']

    # Remove a mention. This could be the case
    # if the bot was mentioned in a chat room
    if text.startswith('@'):
        text = text.split(' ', 1)[1].strip()

    # Some bots will accept commands that started
    # with a '/'
    if text.startswith('/'):
        text = text.replace('/', '', 1).strip()

    # Try and determine what was the trigger command
    # for this plugin.
    action = text.split(' ')[0].strip()

    # Hopefully we never get here, but just in case.
    if action not in commands():
        return 'Sorry, I don\'t know what to do with: {command}'.format(
            command=action)

    # Remove the trigger command
    for command in commands():
        text = ignore_case_replace(command, '', text).strip()

    if text == 'help':
        return _show_help()

    if text in ['neutral', 'explicit', 'chuck', 'all']:
        return pyjokes.get_joke(language='en', category=text)

    # Default to a neutral joke
    return pyjokes.get_joke(language='en', category='all')
Esempio n. 5
0
def run (message):
    '''
        Run

        Run the custom plugin specific code. A returned
        string is the message that will be sent back
        to the user.

        --
        @param  message:dict    The message sent by the user

        @return str
    '''

    # Get the message contents
    text = message['text']

    # Remove a mention. This could be the case
    # if the bot was mentioned in a chat room
    if text.startswith('@'):
        text = text.split(' ', 1)[1].strip()

    # Some bots will accept commands that started
    # with a '/'
    if text.startswith('/'):
        text = text.replace('/', '', 1).strip()

    # Try and determine what was the trigger command
    # for this plugin.
    action = text.split(' ')[0].strip()

    # Hopefully we never get here, but just in case.
    if action not in commands():
        return 'Sorry, I don\'t know what to do with: {command}'.format(
            command = action)

    # Remove the trigger command
    for command in commands():
        text = ignore_case_replace(command, '', text).strip()

    if text == 'help':
        return _show_help()

    if text in ['neutral', 'explicit', 'chuck', 'all']:
        return pyjokes.get_joke(language = 'en', category = text)

    # Default to a neutral joke
    return pyjokes.get_joke(language = 'en', category = 'all')
Esempio n. 6
0
def run(message):
    '''
        Run

        Run the custom plugin specific code. A returned
        string is the message that will be sent back
        to the user.

        --
        @param  message:dict    The message sent by the user

        @return str
    '''

    # Get the message contents
    text = message['text']

    # Remove a mention. This could be the case
    # if the bot was mentioned in a chat room
    if text.startswith('@'):
        text = text.split(' ', 1)[1].strip()

    # Some bots will accept commands that started
    # with a '/'
    if text.startswith('/'):
        text = text.replace('/', '', 1).strip()

    # Try and determine what was the trigger command
    # for this plugin.
    action = text.split(' ')[0].strip()

    # Hopefully we never get here, but just in case.
    if action not in commands():
        return 'Sorry, I don\'t know what to do with: {command}'.format(
            command=action)

    # Remove the trigger command
    for command in commands():
        text = ignore_case_replace(command, '', text).strip()

    # Map actions to function and () them
    do_action = {'learn': _learn, 'forget': _forget, 'show': _show}
    response = do_action[action](text)

    return response
Esempio n. 7
0
def run (message):
    '''
        Run

        Run the custom plugin specific code. A returned
        string is the message that will be sent back
        to the user.

        --
        @param  message:dict    The message sent by the user

        @return str
    '''

    # Get the message contents
    text = message['text']

    # Remove a mention. This could be the case
    # if the bot was mentioned in a chat room
    if text.startswith('@'):
        text = text.split(' ', 1)[1].strip()

    # Some bots will accept commands that started
    # with a '/'
    if text.startswith('/'):
        text = text.replace('/', '', 1).strip()

    # Remove the trigger command
    for command in commands():
        text = ignore_case_replace(command, '', text).strip()

    possible_images = _ask_google(text)

    if possible_images['failed']:
        return {
            'location': static_values.data_dir + '/no_image.png',
            'caption': 'Image retreival failed. See logs for details.'
        }

    location_and_caption = _save_image(
        random.choice(possible_images['urls']))

    return location_and_caption
Esempio n. 8
0
def run(message):
    '''
        Run

        Run the custom plugin specific code. A returned
        string is the message that will be sent back
        to the user.

        --
        @param  message:dict    The message sent by the user

        @return str
    '''

    if not _client_id_set():
        return ('Imgur Client-ID not set. Get one at '
                'https://api.imgur.com/oauth2/addclient')

    # Get the message contents
    text = message['text']

    # Remove a mention. This could be the case
    # if the bot was mentioned in a chat room
    if text.startswith('@'):
        text = text.split(' ', 1)[1].strip()

    # Some bots will accept commands that started
    # with a '/'
    if text.startswith('/'):
        text = text.replace('/', '', 1).strip()

    # Remove the trigger command
    for command in commands():
        text = ignore_case_replace(command, '', text).strip()

    if text == 'credits':
        response = _get_credits()
    else:
        response = _get_random_image(text)

    return response
Esempio n. 9
0
def run (message):
    '''
        Run

        Run the custom plugin specific code. A returned
        string is the message that will be sent back
        to the user.

        --
        @param  message:dict    The message sent by the user

        @return str
    '''

    # Get the text
    text = message['text']

    # Remove the trigger command
    for command in commands():
        text = ignore_case_replace(command, '', text).strip()

    # Call Urban Dictionary API for a definition
    # if the user supplied term
    try:

        logger.debug('Asking Urban Dictionary what is {term}'.format(
            term = text))

        # The actual lookup request
        response = requests.get(
            api.format(
                term = text.encode('utf-8')))

    except Exception, e:

        logger.error('Urban Dictionay lookup failed with: {error}'.format(
            error = str(e)))

        return 'Sorry, Urban Dictionary lookup failed'
Esempio n. 10
0
def run(message):
    '''
        Run

        Run the custom plugin specific code. A returned
        string is the message that will be sent back
        to the user.

        --
        @param  message:dict    The message sent by the user

        @return str
    '''

    # Get the text
    text = message['text']

    # Remove the trigger command
    for command in commands():
        text = ignore_case_replace(command, '', text).strip()

    # Call Urban Dictionary API for a definition
    # if the user supplied term
    try:

        logger.debug(
            'Asking Urban Dictionary what is {term}'.format(term=text))

        # The actual lookup request
        response = requests.get(api.format(term=text.encode('utf-8')))

    except Exception, e:

        logger.error(
            'Urban Dictionay lookup failed with: {error}'.format(error=str(e)))

        return 'Sorry, Urban Dictionary lookup failed'
Esempio n. 11
0
def run(message):
    '''
        Run

        Run the custom plugin specific code. A returned
        string is the message that will be sent back
        to the user.

        --
        @param  message:dict    The message sent by the user

        @return str
    '''

    # Get the message contents
    text = message['text']

    # Remove a mention. This could be the case
    # if the bot was mentioned in a chat room
    if text.startswith('@'):
        text = text.split(' ', 1)[1].strip()

    # Some bots will accept commands that started
    # with a '/'
    if text.startswith('/'):
        text = text.replace('/', '', 1).strip()

    # Try and determine what was the trigger command
    # for this plugin.
    action = text.split(' ')[0].strip()

    # Hopefully we never get here, but just in case.
    if action not in commands():
        return 'Sorry, I don\'t know what to do with: {command}'.format(
            command=action)

    # Remove the trigger command
    for command in commands():
        text = ignore_case_replace(command, '', text).strip()

    # Now, parse the reminder line
    parts = _extract_parts(text)

    # If there was an error with the message, show it
    if parts['error']:
        error_message = 'Reminder not set. Error was: {e}.\n\n{help}'.format(
            e=parts['error_message'], help=_show_help(None))

        return error_message

    # Handle a few control commands that should show
    # stop or display help for this plugin
    if parts['action'] in ['show', 'stop', 'help']:
        handle_action = {
            'show': _show_all_reminders,
            'stop': _stop_reminder,
            'help': _show_help,
        }

        # Handle and return the returned message
        return handle_action[parts['action']](message)

    # Fake a small case-like statement for the once or
    # every message types
    handle_recurrence_types = {
        'once': _set_once_reminder,
        'every': _set_recurring_reminder
    }

    # Run the appropriate set function
    handle_recurrence_types[parts['recurrence']](parts, message)

    # Respond with the fact that the reminder is set.
    response = 'Reminder set for: {t} with message: {m}'.format(
        t=parts['parsed_time'], m=parts['message'])

    return response
Esempio n. 12
0
def run (message):
    '''
        Run

        Run the custom plugin specific code. A returned
        string is the message that will be sent back
        to the user.

        --
        @param  message:dict    The message sent by the user

        @return str
    '''

    # Get the message contents
    text = message['text']

    # Remove a mention. This could be the case
    # if the bot was mentioned in a chat room
    if text.startswith('@'):
        text = text.split(' ', 1)[1].strip()

    # Some bots will accept commands that started
    # with a '/'
    if text.startswith('/'):
        text = text.replace('/', '', 1).strip()

    # Try and determine what was the trigger command
    # for this plugin.
    action = text.split(' ')[0].strip()

    # Hopefully we never get here, but just in case.
    if action not in commands():
        return 'Sorry, I don\'t know what to do with: {command}'.format(
            command = action
        )

    # Remove the trigger command
    for command in commands():
        text = ignore_case_replace(command, '', text).strip()

    # Now, parse the reminder line
    parts = _extract_parts(text)

    # If there was an error with the message, show it
    if parts['error']:
        error_message = 'Reminder not set. Error was: {e}.\n\n{help}'.format(
            e = parts['error_message'],
            help = _show_help(None)
        )

        return error_message

    # Handle a few control commands that should show
    # stop or display help for this plugin
    if parts['action'] in ['show', 'stop', 'help']:
        handle_action = {
            'show': _show_all_reminders,
            'stop': _stop_reminder,
            'help': _show_help,
        }

        # Handle and return the returned message
        return handle_action[parts['action']](message)

    # Fake a small case-like statement for the once or
    # every message types
    handle_recurrence_types = {
        'once': _set_once_reminder,
        'every': _set_recurring_reminder
    }

    # Run the appropriate set function
    handle_recurrence_types[parts['recurrence']](parts, message)

    # Respond with the fact that the reminder is set.
    response = 'Reminder set for: {t} with message: {m}'.format(
        t = parts['parsed_time'],
        m = parts['message']
    )

    return response