88 lines
3.2 KiB
Python
88 lines
3.2 KiB
Python
"""
|
|
PalaceRoom
|
|
|
|
A Room that represents a topic in the memory palace.
|
|
Memory objects spawned here embody concepts retrieved from mempalace.
|
|
Its description auto-populates from a palace search on the memory topic.
|
|
"""
|
|
|
|
import json
|
|
import subprocess
|
|
from evennia.objects.objects import DefaultRoom
|
|
from .objects import ObjectParent
|
|
|
|
PALACE_SCRIPT = "/root/wizards/bezalel/evennia/palace_search.py"
|
|
|
|
|
|
class PalaceRoom(ObjectParent, DefaultRoom):
|
|
"""
|
|
A room in the mind palace. Its db.memory_topic describes what
|
|
kind of memories are stored here. The description is populated
|
|
from a live MemPalace search.
|
|
"""
|
|
|
|
def at_object_creation(self):
|
|
super().at_object_creation()
|
|
self.db.memory_topic = ""
|
|
self.db.wing = "bezalel"
|
|
self.db.desc = (
|
|
f"This is the |c{self.key}|n room of your mind palace.\n"
|
|
"Memories and concepts drift here like motes of light.\n"
|
|
"Use |wpalace/search <query>|n or |wrecall <topic>|n to summon memories."
|
|
)
|
|
|
|
def _search_palace(self, query, wing=None, room=None, n=3):
|
|
"""Call the helper script and return parsed results."""
|
|
cmd = ["/root/wizards/bezalel/hermes/venv/bin/python", PALACE_SCRIPT, query]
|
|
cmd.append(wing or "none")
|
|
cmd.append(room or "none")
|
|
cmd.append(str(n))
|
|
try:
|
|
result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
|
|
data = json.loads(result.stdout)
|
|
return data.get("results", [])
|
|
except Exception:
|
|
return []
|
|
|
|
def update_description(self):
|
|
"""Refresh the room description from a palace search on its topic."""
|
|
topic = self.db.memory_topic or self.key.split(":")[-1] if ":" in self.key else self.key
|
|
wing = self.db.wing or "bezalel"
|
|
results = self._search_palace(topic, wing=wing, n=3)
|
|
|
|
header = (
|
|
f"=|c {topic.upper()} |n="
|
|
)
|
|
desc_lines = [
|
|
header,
|
|
f"You stand in the |c{topic}|n room of the |y{wing}|n wing.",
|
|
"Memories drift here like motes of light.",
|
|
"",
|
|
]
|
|
|
|
if results:
|
|
desc_lines.append("|gNearby memories:|n")
|
|
for i, r in enumerate(results, 1):
|
|
content = r.get("content", "")[:200]
|
|
source = r.get("source", "unknown")
|
|
room_name = r.get("room", "unknown")
|
|
desc_lines.append(f" |m[{i}]|n |c{room_name}|n — {content}... |x({source})|n")
|
|
else:
|
|
desc_lines.append("|xThe palace is quiet here. No memories resonate with this topic yet.|n")
|
|
|
|
desc_lines.append("")
|
|
desc_lines.append("Use |wrecall <query>|n to search deeper, or |wpalace/search <query>|n.")
|
|
self.db.desc = "\n".join(desc_lines)
|
|
|
|
def at_object_receive(self, moved_obj, source_location, **kwargs):
|
|
"""Refresh description when someone enters."""
|
|
if moved_obj.has_account:
|
|
self.update_description()
|
|
super().at_object_receive(moved_obj, source_location, **kwargs)
|
|
|
|
def return_appearance(self, looker):
|
|
text = super().return_appearance(looker)
|
|
if self.db.memory_topic:
|
|
text += f"\n|xTopic: {self.db.memory_topic}|n"
|
|
return text
|