Compare commits
3 Commits
mimo/code/
...
fix/1509-t
| Author | SHA1 | Date | |
|---|---|---|---|
| 2016a7e076 | |||
| 3f7277d920 | |||
|
|
ec2ed3c62f |
@@ -29,7 +29,7 @@ from typing import Any, Callable, Optional
|
|||||||
|
|
||||||
import websockets
|
import websockets
|
||||||
|
|
||||||
from bannerlord_trace import BannerlordTraceLogger
|
from nexus.bannerlord_trace import BannerlordTraceLogger
|
||||||
|
|
||||||
# ═══════════════════════════════════════════════════════════════════════════
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
# CONFIGURATION
|
# CONFIGURATION
|
||||||
|
|||||||
@@ -304,6 +304,43 @@ async def inject_event(event_type: str, ws_url: str, **kwargs):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def clean_lines(text: str) -> str:
|
||||||
|
"""Remove ANSI codes and collapse whitespace from log text."""
|
||||||
|
import re
|
||||||
|
text = strip_ansi(text)
|
||||||
|
text = re.sub(r'\s+', ' ', text).strip()
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_event(event: dict) -> dict:
|
||||||
|
"""Normalize an Evennia event dict to standard format."""
|
||||||
|
return {
|
||||||
|
"type": event.get("type", "unknown"),
|
||||||
|
"actor": event.get("actor", event.get("name", "")),
|
||||||
|
"room": event.get("room", event.get("location", "")),
|
||||||
|
"message": event.get("message", event.get("text", "")),
|
||||||
|
"timestamp": event.get("timestamp", ""),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def parse_room_output(text: str) -> dict:
|
||||||
|
"""Parse Evennia room output into structured data."""
|
||||||
|
import re
|
||||||
|
lines = text.strip().split("\n")
|
||||||
|
result = {"name": "", "description": "", "exits": [], "objects": []}
|
||||||
|
if lines:
|
||||||
|
result["name"] = strip_ansi(lines[0]).strip()
|
||||||
|
if len(lines) > 1:
|
||||||
|
result["description"] = strip_ansi(lines[1]).strip()
|
||||||
|
for line in lines[2:]:
|
||||||
|
line = strip_ansi(line).strip()
|
||||||
|
if line.startswith("Exits:"):
|
||||||
|
result["exits"] = [e.strip() for e in line[6:].split(",") if e.strip()]
|
||||||
|
elif line.startswith("You see:"):
|
||||||
|
result["objects"] = [o.strip() for o in line[8:].split(",") if o.strip()]
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="Evennia -> Nexus WebSocket Bridge")
|
parser = argparse.ArgumentParser(description="Evennia -> Nexus WebSocket Bridge")
|
||||||
sub = parser.add_subparsers(dest="mode")
|
sub = parser.add_subparsers(dest="mode")
|
||||||
|
|||||||
Reference in New Issue
Block a user