'Nicknaming process'

def _nickname_pokemon(self, pokemon):

    instance_id = pokemon.unique_id
    if (not instance_id):
        self.emit_event(u'api_error', formatted=u'Failed    to    get    pokemon    name,    will    not    rename.')
        return False
    old_nickname = pokemon.nickname
    try:
        new_nickname = self._generate_new_nickname(pokemon, self.template)
    except KeyError as bad_key:
        self.emit_event(u'config_error', formatted=u'Unable    to    nickname    {}    due    to    bad    template    ({})'.format(old_nickname, bad_key))
        return False
    if (pokemon.nickname_raw == new_nickname):
        return False
    request = self.bot.api.create_request()
    request.nickname_pokemon(pokemon_id=instance_id, nickname=new_nickname)
    response = request.call()
    sleep(1.2)
    try:
        result = reduce(dict.__getitem__, [u'responses', u'NICKNAME_POKEMON'], response)[u'result']
    except KeyError:
        self.emit_event(u'api_error', formatted=u'Attempt    to    nickname    received    bad    response    from    server.')
        return True
    if (result == 0):
        self.emit_event(u'unset_pokemon_nickname', formatted=u'Pokemon    {}    nickname    unset.'.format(old_nickname), data={u'old_name': old_nickname})
        pokemon.update_nickname(new_nickname)
    elif (result == 1):
        self.emit_event(u'rename_pokemon', formatted=u'*{}    Renamed*    to    *{}*'.format(old_nickname, new_nickname), data={u'old_name': old_nickname, u'current_name': new_nickname})
        pokemon.update_nickname(new_nickname)
    elif (result == 2):
        self.emit_event(u'pokemon_nickname_invalid', formatted=u'Nickname    {}    is    invalid'.format(new_nickname), data={u'nickname': new_nickname})
    else:
        self.emit_event(u'api_error', formatted=u'Attempt    to    nickname    received    unexpected    result    from    server    ({}).'.format(result))
    return True
