feat: add mail claim automation
This commit is contained in:
1 parent
56e79dcd26
commit
b44bb70b26
5 files changed
+47
No files matched your search
@@ -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'
|
||||
Reference in new issue
Block a user