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'

    # Ensure the response was OK from an HTTP perspective
    if not response.status_code == requests.codes.ok:
        return 'Failed to ask Urban Dictionary what {term} means'.format(
            term = text)

    # Try and parse the response json
    try:
        response_data = json.loads(response.text.strip())

    except __HOLE__, e:

        logger.error('Parsing response Json failed with: {err}'.format(err = str(e)))

        # Wait a little for the dust to settle and
        # retry the update call
        return 'Failed to parse the Urban Dictionary response'

    # Try and parse a JSON response from the API
    try:

        # check that we actually got something
        if response_data['result_type'] == 'no_results':
            return 'The lookup returned no results.'

    except Exception, e:

        logger.error('Failed to extract definition and example with error: {error}'.format(
            error = str(e)))

        return 'Unable to parse response. See logs for more details.'

    # Get the actual definitions
    try:

        definition = response_data['list'][0]['definition']
        example = response_data['list'][0]['example']
        author = response_data['list'][0]['author']
        permalink = response_data['list'][0]['permalink']
        tags = ', '.join(response_data['tags'])

    except Exception, e:

        logger.error('Failed to extract definition and example with error: {error}'.format(
            error = str(e)))

        return 'Unable to parse response. See logs for more details.'

    # Construct the final response message
    final_definition = u'\'{term}\' is defined by \'{author}\' as:\n\n* Definition: {definition}\n* Example: {' \
                       u'example}\n\nTags: {tags}\n\nSee: {permalink}'.format(
        term = text,
        author = author,
        definition = definition,
        example = example,
        tags = tags,
        permalink = permalink)

    return final_definition
dataset/ETHPy150Open leonjza/hogar/hogar/Plugins/UrbanDictionary/main.py/run