59 lines
1.8 KiB
Python

"""Mailbox daily task. Ported from baas-reference module/mail.py's color-probe pattern."""
# (500, 10) sits on the mailbox panel's plain header background; the home
# screen shows character art there instead, so this tells open vs not-open.
HEADER_PROBE = (500, 10)
HEADER_OPEN_MIN_CHANNEL = 200
# "Claim all" renders as flat grey (153,153,153) when there is nothing to claim.
CLAIM_ALL_PROBE = (1710, 1128)
CLAIM_ALL_DISABLED_RGB = (153, 153, 153)
CLAIM_ALL_DISABLED_TOLERANCE = 12
OPEN_RETRIES = 3
def _is_open(driver):
r, g, b = driver.color_at(*HEADER_PROBE)
return r > HEADER_OPEN_MIN_CHANNEL and g > HEADER_OPEN_MIN_CHANNEL and b > HEADER_OPEN_MIN_CHANNEL
def _claim_all_disabled(driver):
r, g, b = driver.color_at(*CLAIM_ALL_PROBE)
tr, tg, tb = CLAIM_ALL_DISABLED_RGB
return (
abs(r - tr) <= CLAIM_ALL_DISABLED_TOLERANCE
and abs(g - tg) <= CLAIM_ALL_DISABLED_TOLERANCE
and abs(b - tb) <= CLAIM_ALL_DISABLED_TOLERANCE
)
def run(driver, config):
driver.focus_game()
opened = False
for attempt in range(1, OPEN_RETRIES + 1):
driver.click(*config.MAILBOX_ICON)
driver.wait(1.5)
if _is_open(driver):
opened = True
break
print(f"[mailbox] panel not detected after click (attempt {attempt}/{OPEN_RETRIES})")
if not opened:
print("[mailbox] could not confirm mailbox is open, aborting without pressing further keys")
return
if _claim_all_disabled(driver):
print("[mailbox] nothing to claim")
else:
print("[mailbox] claiming all")
driver.click(*config.CLAIM_ALL)
driver.wait(1)
driver.keypress("Return")
driver.wait(1)
driver.keypress("Escape")
driver.wait(1)
print("[mailbox] Done.")