Genesis commit
This commit is contained in:
commit
a2a2bcb206
6 changed files with 4167 additions and 0 deletions
62
test.py
Normal file
62
test.py
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
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())
|
||||
Loading…
Add table
Add a link
Reference in a new issue