Exemplo n.º 1
0
def get_user_state(user: User) -> Optional[State]:
    user_id = user.get_id()
    state_record = DatastoreClient().get_client().collection(
        USERS_STATES).document(user_id).get().to_dict()
    print(f'user_id: {user_id}, state_record: {state_record}')
    state = None
    if state_record:
        state = State(**state_record)
    print(f'parsed_state: {state}')
    return state
Exemplo n.º 2
0
def update_user_state(user: User, new_state: QuestStateType) -> bool:
    try:
        user_id = user.get_id()
        state_ref = DatastoreClient().get_client().collection(
            USERS_STATES).document(user_id)
        state_ref.update({u'state_type': new_state.name})
        return True
    except Exception as e:
        print(f'Update of state failed for user {user} to state: {new_state}. '
              f'Exception: {e}')
        return False
Exemplo n.º 3
0
def save_user_state(user: User, state: State):
    user_id = user.get_id()
    DatastoreClient().get_client().collection(USERS_STATES).document(
        user_id).set(asdict(state))