def process_chat_real(session, message): curr_exchange, data = get_session(session) # guarantees data to be a dict if curr_exchange is None: curr_exchange = 'start' set_session(session, 'start', data) exch_type = exchange_type(curr_exchange) try: return EXCHANGE_TYPES_NEXT[exch_type](session, message) except KeyError: pass mapping = keywords(curr_exchange) new_exchange = default_func(curr_exchange) cleaned_words = clean(message).lower().split() if '?' in message: cleaned_words.append('question') for mess_word in cleaned_words: if mess_word in mapping: new_exchange = mapping[mess_word] break if new_exchange: set_session(session, new_exchange, data) return get_prompt(session, new_exchange, data) return None
def tangent_exchange(session_id, message): """Determine whether we're queued or not.""" curr_exchange, data = get_session(session_id) if data.get('queued', False): return None # stay right where we are new_exchange = default_func(curr_exchange) if new_exchange is None: return None set_session(session_id, new_exchange, data) return process_chat.get_prompt(session_id, new_exchange, data)
def manual_update_key(): body = request.get_json() session_id = body.get('session') key = body.get('key') value = body.get('value') if None in (session_id, key, value): return 'Session, key and value must be provided!', 400 exchange, data = get_session(session_id) data[key] = value set_session(session_id, exchange, data) return ''
def step_in(): session_id = request.values.get('session') if session_id: exch, data = get_session(session_id) all_exchanges = tuple(exchange_translation.all_exchanges()) return render_template('stepin.html', session_id=session_id, exchange=exch, session_data=data, all_exchanges=all_exchanges) return redirect(url_for('sessions'))
def manual_delete_key(): body = request.get_json() session_id = body.get('session') key = body.get('key') if session_id is None or key is None: return 'Session and key must be provided!', 400 exchange, data = get_session(session_id) try: del data[key] except KeyError: pass set_session(session_id, exchange, data) return ''
def manual_set_exchange(): body = request.get_json() session_id = body.get('session') new_exch = body.get('exchange') remove_queue = body.get('de_queue', False) send_prompt = body.get('send_prompt', False) if session_id is None or new_exch is None: return 'Session and exchange must be provided!', 400 _, data = get_session(session_id) if remove_queue: data['queued'] = False if send_prompt: prompt = get_prompt(session_id, new_exch, data) send_message_wrapper(session_id, prompt) set_session(session_id, new_exch, data) return ''
def mark_queued(session_id, status): exchange, data = get_session(session_id) data['queued'] = status set_session(session_id, exchange, data)
def need_autofollow(session): curr_exchange, _ = get_session(session) exch_type = exchange_type(curr_exchange) return EXCHANGE_TYPES_AUTOFOLLOW.get(exch_type, False)