sos-bot/actions/find.py
bachko 3309a47e10 Initial commit: SoS bot framework
- 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
2026-07-09 13:52:31 +00:00

24 lines
764 B
Python

"""Action: find — find a template and return its position (sets ctx['_last_pos'])."""
import os
class Action:
name = "find"
def run(self, ctx, params):
template = params["template"]
confidence = params.get("confidence", 0.8)
region = params.get("region")
tmpl_dir = ctx.get("_templates_dir",
os.path.join(os.path.dirname(__file__), "..", "templates"))
tpl_path = os.path.join(tmpl_dir, template)
pos = ctx["vision"].find_template(tpl_path, confidence, region)
ctx["_last_pos"] = pos
if pos is None:
ctx["log"].info("find(%s) → not found", template)
else:
ctx["log"].info("find(%s) → %s", template, pos)
return pos