- ADB client (connect, tap, swipe, screencap, app control) - Vision module (in-memory screenshot + OpenCV template matching) - Action loader (auto-discovers .py files in actions/) - Engine (screenshot → detect → act loop with YAML playbook) - 12 built-in actions: tap, click, wait, swipe, find, find_and_click, wait_until, click_seq, keyevent, app, log - Example custom action template - Debug screenshot tool for template creation - Detailed plan.md with 20 actions across 9 phases - Sample playbook with 10 steps
88 lines
2.2 KiB
Python
88 lines
2.2 KiB
Python
"""
|
|
State of Survival Bot — Main Entry Point
|
|
Usage:
|
|
python main.py # default playbook & port
|
|
python main.py --playbook my_play.yaml
|
|
python main.py --port 5556
|
|
python main.py --host 192.168.1.100
|
|
"""
|
|
import argparse
|
|
import logging
|
|
import signal
|
|
import sys
|
|
import os
|
|
|
|
# Ensure the project root is on sys.path
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from core.engine import Engine
|
|
|
|
|
|
def setup_logging(verbose: bool = False):
|
|
level = logging.DEBUG if verbose else logging.INFO
|
|
fmt = "%(asctime)s [%(levelname)-5s] %(message)s"
|
|
datefmt = "%H:%M:%S"
|
|
logging.basicConfig(level=level, format=fmt, datefmt=datefmt)
|
|
# Keep OpenCV chatter quiet
|
|
logging.getLogger("cv2").setLevel(logging.WARNING)
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description="State of Survival Bot — ADB + OpenCV automation",
|
|
)
|
|
parser.add_argument(
|
|
"--playbook",
|
|
default=os.path.join(os.path.dirname(__file__), "playbook", "default.yaml"),
|
|
help="Path to playbook YAML (default: playbook/default.yaml)",
|
|
)
|
|
parser.add_argument(
|
|
"--host",
|
|
default="127.0.0.1",
|
|
help="ADB host (default: 127.0.0.1)",
|
|
)
|
|
parser.add_argument(
|
|
"--port",
|
|
type=int,
|
|
default=5555,
|
|
help="ADB port (default: 5555)",
|
|
)
|
|
parser.add_argument(
|
|
"-v", "--verbose",
|
|
action="store_true",
|
|
help="Verbose debug logging",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
setup_logging(args.verbose)
|
|
logger = logging.getLogger("sos")
|
|
|
|
engine = Engine(args.playbook)
|
|
engine.playbook_path = args.playbook
|
|
engine.adb_host = args.host
|
|
engine.adb_port = args.port
|
|
|
|
# Handle Ctrl+C gracefully
|
|
def sigint_handler(sig, frame):
|
|
logger.info("Received SIGINT — shutting down...")
|
|
engine.stop()
|
|
signal.signal(signal.SIGINT, sigint_handler)
|
|
|
|
try:
|
|
engine.start()
|
|
except KeyboardInterrupt:
|
|
engine.stop()
|
|
except Exception as e:
|
|
logger.error("Fatal: %s", e)
|
|
sys.exit(1)
|
|
finally:
|
|
try:
|
|
engine.adb.disconnect()
|
|
except Exception:
|
|
pass
|
|
logger.info("Bot shut down")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|