mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-08 13:53:45 +00:00
The NexusDashboard-parity dashboard (dDashboardServer) and everything built on it on the experimental branch: accounts, characters, properties and moderation tools, permissions shared with in-game slash commands, economy reports, World 3D and property 3D views with client scenery, scheduled events (features, vanity changes, live events, announcements, restarts), vanity files and events, the CDClient browser, the message inspector with saved captures, chat filter tools, community challenges, live ops, the AI moderator helper, and the server-side changes they need. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
"""The smallest adapter: game chat is printed, and each line typed on stdin is posted in the game.
|
|
|
|
Lines are `Name: message`, or just `message` (sent as the configured default name). Useful for trying the bridge
|
|
and as a template for new adapters.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import sys
|
|
|
|
from ..core import GameMessage, RemoteMessage, plain_line
|
|
from .base import Adapter, Deliver
|
|
|
|
|
|
def parse_line(line: str, default_name: str) -> RemoteMessage | None:
|
|
line = line.strip()
|
|
if not line:
|
|
return None
|
|
name, sep, text = line.partition(": ")
|
|
if sep and 0 < len(name) <= 32 and text.strip():
|
|
return RemoteMessage(author=name, text=text)
|
|
return RemoteMessage(author=default_name, text=line)
|
|
|
|
|
|
class ConsoleAdapter(Adapter):
|
|
name = "console"
|
|
default_label = "Console"
|
|
|
|
async def run(self, deliver: Deliver) -> None:
|
|
if not self.config.get("read_stdin", True):
|
|
return
|
|
default_name = self.config.get("name", "Console")
|
|
while True:
|
|
line = await asyncio.to_thread(sys.stdin.readline)
|
|
if not line: # end of input
|
|
return
|
|
msg = parse_line(line, default_name)
|
|
if msg:
|
|
await deliver(msg)
|
|
|
|
async def send(self, msg: GameMessage, skipped: int = 0) -> None:
|
|
if skipped:
|
|
print(f"({skipped} message(s) skipped: rate limit)", flush=True)
|
|
print(plain_line(msg), flush=True)
|