62 lines
1.6 KiB
Python
62 lines
1.6 KiB
Python
import asyncio
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
def load_env_file(path: Path) -> None:
|
|
if not path.exists():
|
|
return
|
|
for raw in path.read_text(encoding="utf-8").splitlines():
|
|
line = raw.strip()
|
|
if not line or line.startswith("#"):
|
|
continue
|
|
if "=" not in line:
|
|
continue
|
|
key, value = line.split("=", 1)
|
|
key = key.strip()
|
|
value = value.strip().strip('"').strip("'")
|
|
os.environ.setdefault(key, value)
|
|
|
|
|
|
async def main() -> None:
|
|
root = Path(__file__).resolve().parent
|
|
load_env_file(root / ".env")
|
|
|
|
sys.path.insert(0, str(root / "src"))
|
|
from src.main import Minecraft
|
|
|
|
host = os.environ.get("SERVER_HOST")
|
|
client_id = os.environ.get("PUFFERPANEL_CLIENT_ID")
|
|
client_secret = os.environ.get("PUFFERPANEL_CLIENT_SECRET")
|
|
if not host or not client_id or not client_secret:
|
|
raise RuntimeError(
|
|
"Missing SERVER_HOST / PUFFERPANEL_CLIENT_ID / PUFFERPANEL_CLIENT_SECRET"
|
|
)
|
|
|
|
mc = Minecraft(
|
|
host=host,
|
|
client_id=client_id,
|
|
client_secret=client_secret,
|
|
server_name="Retards Server",
|
|
poll_interval=0.5,
|
|
)
|
|
|
|
try:
|
|
await mc.command("say hi from test.py")
|
|
|
|
tail = [line async for line in mc.logs_tail(5)]
|
|
print("tail (last 5 lines):")
|
|
for line in tail:
|
|
print(line)
|
|
|
|
print("streaming next log line...")
|
|
async for line in mc.logs_stream():
|
|
print("stream:", line)
|
|
break
|
|
finally:
|
|
await mc.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|