(self, user_id, new_data, merge=True)
| 22 | self.load() |
| 23 | |
| 24 | def update_user_profile(self, user_id, new_data, merge=True): |
| 25 | if merge and user_id in self.user_profiles and self.user_profiles[user_id].get("data"): # Check if data exists |
| 26 | current_data = self.user_profiles[user_id]["data"] |
| 27 | if isinstance(current_data, str) and isinstance(new_data, str): |
| 28 | updated_data = f"{current_data}\n\n--- Updated on {get_timestamp()} ---\n{new_data}" |
| 29 | else: # Fallback to overwrite if types are not strings or for more complex merge |
| 30 | updated_data = new_data |
| 31 | else: |
| 32 | # If merge=False or no existing data, replace with new data |
| 33 | updated_data = new_data |
| 34 | |
| 35 | self.user_profiles[user_id] = { |
| 36 | "data": updated_data, |
| 37 | "last_updated": get_timestamp() |
| 38 | } |
| 39 | print(f"LongTermMemory: Updated user profile for {user_id} (merge={merge}).") |
| 40 | self.save() |
| 41 | |
| 42 | def get_raw_user_profile(self, user_id): |
| 43 | return self.user_profiles.get(user_id, {}).get("data", "None") # Return "None" string if not found |
no test coverage detected