feat: add mail claim automation

This commit is contained in:
admin committed 2026-10-04 23:16:31 +08:00
1 parent 56e79dcd26
commit b44bb70b26
5 files changed
+47

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

+32
View File
@@ -0,0 +1,32 @@
"""首页邮件红点触发的一键领取流程。"""
import time
from .engine import WorkflowError
class MailRunner:
def __init__(self, desktop, matcher, flow, region_provider, log=print, timeout=12):
self.desktop, self.matcher, self.flow = desktop, matcher, flow
self.region_provider, self.log, self.timeout = region_provider, log, timeout
def wait(self, *names):
end=time.monotonic()+self.timeout; previous=None; stable=0
while time.monotonic()<end:
shot=self.desktop.screenshot(); region=self.region_provider(shot); frame=self.matcher.frame(shot,region)
found=next((n for n in names if self.matcher.matches(frame,self.flow['states'][n])),None)
stable=stable+1 if found and found==previous else (1 if found else 0); previous=found
if stable>=2:return found,shot,region,frame
time.sleep(.25)
raise WorkflowError('未识别到预期页面 '+ '/'.join(names)+',已停止。')
def action(self,name,obs):
_,shot,region,_=obs
if self.region_provider(shot)!=region: raise WorkflowError('识别后游戏窗口移动,已停止,请重新运行。')
self.desktop.click(self.flow['clicks'][name],region,shot.size,hold=.8); self.log('已执行:'+name)
def run(self,dry_run=False):
home=self.wait('home')
if dry_run:self.log('首页识别通过。计划:邮件红点 → 一键领取 → 返回首页。未点击。');return 'preview'
if not self.matcher.matches(home[3],self.flow['mail_dot']): self.log('邮件按钮没有红点,本次不进入。');return 'no_dot'
self.action('open_mail',home); page=self.wait('mail')
self.action('claim',page); reward=self.wait('reward'); self.action('dismiss_reward',reward)
self.action('close',self.wait('mail')); self.wait('home'); self.log('已确认返回首页。');return 'claimed'
+14
View File
@@ -0,0 +1,14 @@
import argparse, sys, time
from pathlib import Path
from automation.engine import Matcher,load_flow
from automation.mail import MailRunner
from automation.offers import MacGameDesktop
ROOT=Path(__file__).resolve().parent
def main():
p=argparse.ArgumentParser(description='首页邮件:有红点时一键领取并返回首页');p.add_argument('--dry-run',action='store_true');a=p.parse_args()
if sys.platform!='darwin':return 2
try:
d=MacGameDesktop();d.activate();print('3 秒后开始;请保持游戏在前台。',flush=True);time.sleep(3)
MailRunner(d,Matcher(ROOT/'assets'),load_flow(ROOT/'workflows/mail_claim.json'),d.region_for).run(a.dry_run);return 0
except Exception as e:print('流程停止:'+str(e),file=sys.stderr);return 1
if __name__=='__main__':raise SystemExit(main())
+1
View File
@@ -0,0 +1 @@
{"name":"收取邮件","states":{"home":[{"template":"home.png","search":[150,730,410,865]}],"mail":[{"template":"mail_title.png","search":[130,80,440,200]},{"template":"mail_claim.png","search":[270,730,520,870]}],"reward":[{"template":"sword_gift_reward.png","search":[120,180,440,390],"threshold":0.8},{"template":"sword_gift_dismiss.png","search":[145,600,420,730]}]},"mail_dot":[{"template":"tasks_home_dot.png","search":[505,310,562,390]}],"clicks":{"open_mail":[0.93,0.35],"claim":[0.70,0.80],"dismiss_reward":[0.50,0.67],"close":[0.93,0.14]}}