Plugin setup
Drop one small Python file into each bot's Plugins/ folder. Each push includes the character, inventory, pets, party and recent events.
Your ingest token
Loading…Keep this private. Anyone with this token can push data to your account.
phPanel.py
# phPanel.py
# Pushes a snapshot of this character to your phBot Panel by Yurel every 10s.
# Also receives remote commands (start / stop / trace / clear_trace) in the push response.
# Drop this file into the phBot "Plugins/" folder and restart the bot.
from phBot import *
import json
import threading
try:
import urllib.request as _ureq
except ImportError:
import urllib2 as _ureq # type: ignore
URL = "/api/public/ingest"
TOKEN = "YOUR_TOKEN_HERE"
INTERVAL = 10 # seconds
_events = []
_lock = threading.Lock()
_pending_commands = []
_pending_lock = threading.Lock()
def _queue(event_type, payload=None):
with _lock:
_events.append({"type": event_type, "payload": payload or {}})
def _safe(fn_name, *args):
fn = globals().get(fn_name)
if not callable(fn):
return None
try:
return fn(*args)
except Exception:
return None
def _clean(value):
if isinstance(value, float):
if value != value or value == float("inf") or value == float("-inf"):
return None
return value
if isinstance(value, dict):
return {k: _clean(v) for k, v in value.items()}
if isinstance(value, (list, tuple)):
return [_clean(v) for v in value]
return value
def _schedule_command(cmd):
with _pending_lock:
_pending_commands.append(cmd or {})
def _exec_command(cmd):
name = (cmd or {}).get("command")
params = (cmd or {}).get("params") or {}
try:
if name == "start":
r = _safe("start_bot")
try: log("[Panel] start_bot() -> %s" % r)
except Exception: pass
_queue("cmd_start", {"result": r})
elif name == "stop":
r = _safe("stop_bot")
try: log("[Panel] stop_bot() -> %s" % r)
except Exception: pass
_queue("cmd_stop", {"result": r})
elif name == "trace":
target = params.get("name") or params.get("target") or ""
if target:
r = _safe("start_trace", target)
try: log("[Panel] start_trace(%s) -> %s" % (target, r))
except Exception: pass
_queue("cmd_trace", {"target": target, "result": r})
elif name == "clear_trace":
r = _safe("stop_trace")
try: log("[Panel] stop_trace() -> %s" % r)
except Exception: pass
_queue("cmd_clear_trace", {"result": r})
else:
try: log("[Panel] unknown command: %s" % name)
except Exception: pass
except Exception as e:
try: log("[Panel] command %s failed: %s" % (name, e))
except Exception: pass
def _push():
try:
global _events
with _lock:
evts = list(_events)
_events = []
body = _clean({
"token": TOKEN,
"character": _safe("get_character_data") or {},
"inventory": _safe("get_inventory") or {},
"pets": _safe("get_pets") or {},
"party": _safe("get_party") or {},
"training": _safe("get_training_area"),
"events": evts,
})
data = json.dumps(body).encode("utf-8")
req = _ureq.Request(URL, data=data, headers={
"Content-Type": "application/json",
"Accept": "application/json, text/plain, */*",
"User-Agent": "phPanel/1.3",
})
resp = _ureq.urlopen(req, timeout=8).read()
try:
parsed = json.loads(resp.decode("utf-8"))
for cmd in (parsed.get("commands") or []):
try: log("[Panel] queued remote command: %s" % ((cmd or {}).get("command") or "?"))
except Exception: pass
_schedule_command(cmd)
except Exception:
pass
except Exception as e:
try: log("[Panel] push failed: %s" % e)
except Exception: pass
threading.Timer(INTERVAL, _push).start()
def connected(): _queue("connected")
def disconnected(): _queue("disconnected")
def loading_state(state): _queue("loading_state", {"state": state})
def event_loop():
queued = []
with _pending_lock:
if _pending_commands:
queued = list(_pending_commands)
del _pending_commands[:]
for cmd in queued:
_exec_command(cmd)
_push()
try: log("[Panel] Panel By Yurel loaded")
except Exception: pass
Install steps
- 1. Copy
phPanel.pyinto phBot'sPlugins/folder (next tophBot.exe). - 2. Start the bot. The plugin pushes a snapshot every 30 seconds, plus an event whenever the bot connects, disconnects, dies, or levels up.
- 3. Open the Characters tab — your character appears within a minute.
- 4. Egy közös
Plugins/mappa elég — minden phBot példány külön tölti be a plugint, és a saját karakterét pusholja ugyanazzal a tokennel.
Endpoint
/api/public/ingest