feat: add sweep and task reward automation
This commit is contained in:
1 parent
8479cf4981
commit
44d9a617d1
21 files changed
+516
-8
No files matched your search
@@ -0,0 +1,86 @@
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from automation.engine import Matcher, Region, load_flow
|
||||
from automation.tasks import TaskRunner
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
class TaskDesktop:
|
||||
def __init__(self, images):
|
||||
self.images = images
|
||||
self.index = 0
|
||||
self.clicks = []
|
||||
|
||||
def screenshot(self):
|
||||
return self.images[min(self.index, len(self.images) - 1)]
|
||||
|
||||
def click(self, point, region, size, hold=0.2):
|
||||
self.clicks.append((point, hold))
|
||||
self.index += 1
|
||||
|
||||
|
||||
class TaskTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.flow = load_flow(ROOT / 'workflows/task_claim.json')
|
||||
self.matcher = Matcher(ROOT / 'assets')
|
||||
self.region = Region(0, 0, 562, 1002)
|
||||
|
||||
def image(self, state, claim=False, dot=None):
|
||||
image = Image.new('RGB', (562, 1002), (42, 58, 73))
|
||||
if state in self.flow['states']:
|
||||
for spec in self.flow['states'][state]:
|
||||
template = Image.open(ROOT / 'assets' / spec['template']).convert('RGB')
|
||||
x, y, _, _ = spec['search']
|
||||
image.paste(template, (x + 5, y + 5))
|
||||
if claim:
|
||||
spec = self.flow['claim_button']
|
||||
template = Image.open(ROOT / 'assets' / spec['template']).convert('RGB')
|
||||
x, y, _, _ = spec['search']
|
||||
image.paste(template, (x + 5, y + 5))
|
||||
if dot == 'home':
|
||||
spec = self.flow['task_dot'][0]
|
||||
elif dot:
|
||||
spec = self.flow['tab_dots'][dot]
|
||||
else:
|
||||
spec = None
|
||||
if spec:
|
||||
template = Image.open(ROOT / 'assets' / spec['template']).convert('RGB')
|
||||
x, y, _, _ = spec['search']
|
||||
image.paste(template, (x + 5, y + 5))
|
||||
return image
|
||||
|
||||
def runner(self, images):
|
||||
desktop = TaskDesktop(images)
|
||||
return desktop, TaskRunner(desktop, self.matcher, self.flow,
|
||||
lambda _: self.region, log=lambda _: None, timeout=0.8)
|
||||
|
||||
def test_claims_current_and_dotted_other_panel(self):
|
||||
images = [
|
||||
self.image('home', dot='home'),
|
||||
self.image('daily', claim=True),
|
||||
self.image('reward'),
|
||||
self.image('daily', dot='weekly'),
|
||||
self.image('weekly', claim=True),
|
||||
self.image('reward'),
|
||||
self.image('weekly'),
|
||||
self.image('home'),
|
||||
]
|
||||
desktop, runner = self.runner(images)
|
||||
self.assertEqual(runner.run(), 'claimed')
|
||||
self.assertEqual(len(desktop.clicks), 7)
|
||||
self.assertEqual(desktop.clicks[0][0], self.flow['clicks']['open_tasks'])
|
||||
self.assertEqual(desktop.clicks[3][0], self.flow['clicks']['open_weekly'])
|
||||
self.assertEqual(desktop.clicks[-1][0], self.flow['clicks']['close'])
|
||||
|
||||
def test_without_home_dot_does_not_open_tasks(self):
|
||||
desktop, runner = self.runner([self.image('home')])
|
||||
self.assertEqual(runner.run(), 'no_task_dot')
|
||||
self.assertEqual(desktop.clicks, [])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user