2023-10-16 10:40:49 +00:00
|
|
|
from module.base.timer import Timer
|
2023-10-16 04:24:52 +00:00
|
|
|
from module.logger import logger
|
2023-11-06 14:30:43 +00:00
|
|
|
from tasks.base.assets.assets_base_page import MENU_CHECK
|
2023-10-16 04:24:52 +00:00
|
|
|
from tasks.base.page import page_menu
|
|
|
|
from tasks.base.ui import UI
|
2023-10-16 10:40:49 +00:00
|
|
|
from tasks.freebies.assets.assets_freebies_support_reward import (
|
|
|
|
CAN_GET_REWARD,
|
|
|
|
IN_PROFILE,
|
|
|
|
MENU_TO_PROFILE,
|
|
|
|
PROFILE
|
|
|
|
)
|
|
|
|
|
2023-10-16 04:24:52 +00:00
|
|
|
|
|
|
|
class SupportReward(UI):
|
2023-10-16 10:40:49 +00:00
|
|
|
|
2023-10-16 04:24:52 +00:00
|
|
|
def run(self):
|
|
|
|
"""
|
|
|
|
Run get support reward task
|
|
|
|
"""
|
2023-10-16 10:40:49 +00:00
|
|
|
logger.hr('Support reward', level=1)
|
2023-10-16 04:24:52 +00:00
|
|
|
self.ui_ensure(page_menu)
|
2023-10-16 10:40:49 +00:00
|
|
|
|
2023-10-16 04:24:52 +00:00
|
|
|
self._goto_profile()
|
|
|
|
self._get_reward()
|
|
|
|
self._goto_menu()
|
2023-10-16 10:40:49 +00:00
|
|
|
|
2023-10-16 04:24:52 +00:00
|
|
|
def _goto_profile(self):
|
|
|
|
"""
|
|
|
|
Pages:
|
|
|
|
in: MENU
|
|
|
|
out: PROFILE
|
|
|
|
"""
|
|
|
|
skip_first_screenshot = False
|
|
|
|
logger.info('Going to profile')
|
|
|
|
while 1:
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
2023-10-16 10:40:49 +00:00
|
|
|
|
2023-10-16 04:24:52 +00:00
|
|
|
if self.appear(IN_PROFILE):
|
|
|
|
logger.info('Successfully in profile')
|
|
|
|
return True
|
2023-10-16 10:40:49 +00:00
|
|
|
|
2023-10-16 04:24:52 +00:00
|
|
|
if self.appear_then_click(MENU_TO_PROFILE):
|
|
|
|
continue
|
2023-10-16 10:40:49 +00:00
|
|
|
|
2023-10-16 04:24:52 +00:00
|
|
|
if self.appear_then_click(PROFILE):
|
|
|
|
continue
|
2023-10-16 10:40:49 +00:00
|
|
|
|
|
|
|
def _get_reward(self, skip_first_screenshot=True):
|
2023-10-16 04:24:52 +00:00
|
|
|
"""
|
|
|
|
Pages:
|
|
|
|
in: PROFILE
|
2023-11-06 14:30:43 +00:00
|
|
|
out: reward_appear()
|
2023-10-16 04:24:52 +00:00
|
|
|
"""
|
|
|
|
logger.info('Getting reward')
|
2023-10-16 10:40:49 +00:00
|
|
|
claimed = False
|
|
|
|
empty = Timer(0.3, count=1).start()
|
|
|
|
timeout = Timer(5).start()
|
2023-10-16 04:24:52 +00:00
|
|
|
while 1:
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
2023-10-16 10:40:49 +00:00
|
|
|
|
|
|
|
if not claimed and empty.reached():
|
|
|
|
logger.info('No reward')
|
|
|
|
break
|
2023-11-06 14:30:43 +00:00
|
|
|
if self.reward_appear():
|
2023-10-16 10:40:49 +00:00
|
|
|
logger.info('Got reward')
|
|
|
|
break
|
|
|
|
if timeout.reached():
|
|
|
|
logger.warning('Get support reward timeout')
|
|
|
|
break
|
|
|
|
|
|
|
|
if self.appear_then_click(CAN_GET_REWARD, similarity=0.70, interval=2):
|
|
|
|
claimed = True
|
|
|
|
timeout.reset()
|
2023-10-16 04:24:52 +00:00
|
|
|
continue
|
2023-10-16 10:40:49 +00:00
|
|
|
|
2023-10-16 04:24:52 +00:00
|
|
|
def _goto_menu(self):
|
|
|
|
"""
|
|
|
|
Pages:
|
2023-11-06 14:30:43 +00:00
|
|
|
in: PROFILE or reward_appear
|
2023-10-16 04:24:52 +00:00
|
|
|
out: MENU
|
|
|
|
"""
|
|
|
|
skip_first_screenshot = False
|
|
|
|
logger.info('Going to menu')
|
|
|
|
while 1:
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
2023-10-16 10:40:49 +00:00
|
|
|
|
2023-10-16 04:24:52 +00:00
|
|
|
if self.appear(MENU_CHECK):
|
|
|
|
return True
|
2023-10-16 10:40:49 +00:00
|
|
|
|
2023-11-06 14:30:43 +00:00
|
|
|
if self.handle_ui_close(IN_PROFILE, interval=2):
|
2023-10-16 04:24:52 +00:00
|
|
|
continue
|
2023-10-16 10:40:49 +00:00
|
|
|
if self.handle_reward(click_button=CAN_GET_REWARD):
|
|
|
|
# # Avoid clicking on some other buttons
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
2023-10-16 04:24:52 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
self = SupportReward('src')
|
|
|
|
self.device.screenshot()
|
2023-10-16 10:40:49 +00:00
|
|
|
self.run()
|