mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-07 13:23:50 +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>
40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
"""A send-only adapter: POSTs each game chat message as JSON to any URL (a Slack/Mattermost-style incoming webhook,
|
|
an automation tool, your own service). It shows how little an adapter needs.
|
|
|
|
Body: {"text": "[Nimbus Station] Bob: hi", "sender": "Bob", "message": "hi", "channel": "zone", "zone_id": 1200,
|
|
"zone_name": "Nimbus Station", "instance_id": 2, "id": 42}
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import json
|
|
import logging
|
|
import urllib.request
|
|
|
|
from ..core import GameMessage, plain_line
|
|
from .base import Adapter
|
|
|
|
log = logging.getLogger("chat_bridge.webhook")
|
|
|
|
|
|
def webhook_body(msg: GameMessage, skipped: int = 0) -> dict:
|
|
body = {"text": plain_line(msg), "sender": msg.sender_name, "message": msg.message, "channel": msg.channel,
|
|
"zone_id": msg.zone_id, "zone_name": msg.zone_name, "instance_id": msg.instance_id, "id": msg.id}
|
|
if skipped:
|
|
body["skipped"] = skipped
|
|
return body
|
|
|
|
|
|
class WebhookAdapter(Adapter):
|
|
name = "webhook"
|
|
default_label = "Webhook"
|
|
|
|
def _post(self, body: dict) -> None:
|
|
req = urllib.request.Request(self.config["url"], data=json.dumps(body).encode(), method="POST",
|
|
headers={"Content-Type": "application/json", **self.config.get("headers", {})})
|
|
with urllib.request.urlopen(req, timeout=15) as resp:
|
|
resp.read()
|
|
|
|
async def send(self, msg: GameMessage, skipped: int = 0) -> None:
|
|
await asyncio.to_thread(self._post, webhook_body(msg, skipped))
|