base_task.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from time import sleep, time
  5. import random
  6. from datetime import datetime, timedelta
  7. from module.atom.animate import RuleAnimate
  8. from module.atom.click import RuleClick
  9. from module.atom.gif import RuleGif
  10. from module.atom.image import RuleImage
  11. from module.atom.list import RuleList
  12. from module.atom.long_click import RuleLongClick
  13. from module.atom.ocr import RuleOcr
  14. from module.atom.swipe import RuleSwipe
  15. from module.base.timer import Timer
  16. from module.config.config import Config
  17. from module.device.device import Device
  18. from module.exception import ScriptError
  19. from module.logger import logger
  20. from module.ocr.base_ocr import OcrMode
  21. from tasks.Component.Costume.costume_base import CostumeBase
  22. from tasks.Component.config_base import Time
  23. from tasks.GlobalGame.assets import GlobalGameAssets
  24. from tasks.GlobalGame.config_emergency import FriendInvitation
  25. from typing import Union
  26. class BaseTask(GlobalGameAssets, CostumeBase):
  27. config: Config = None
  28. device: Device = None
  29. folder: str
  30. name: str
  31. stage: str
  32. limit_time: timedelta = None # 限制运行的时间,是软时间,不是硬时间
  33. limit_count: int = None # 限制运行的次数
  34. current_count: int = None # 当前运行的次数
  35. def __init__(self, config: Config, device: Device) -> None:
  36. """
  37. :rtype: object
  38. """
  39. self.config = config
  40. self.device = device
  41. self.interval_timer = {} # 这个是用来记录每个匹配的运行间隔的,用于控制运行频率
  42. self.animates = {} # 保存缓存
  43. self.start_time = datetime.now() # 启动的时间
  44. self.check_costume(self.config.global_game.costume_config)
  45. # self.friend_timer = None # 这个是用来记录勾协的时间的
  46. # if self.config.global_game.emergency.invitation_detect_interval:
  47. # self.interval_time = self.config.global_game.emergency.invitation_detect_interval
  48. # self.friend_timer = Timer(self.interval_time)
  49. # self.friend_timer.start()
  50. # 战斗次数相关
  51. self.current_count = 0 # 战斗次数
  52. def _burst(self) -> bool:
  53. """
  54. 游戏界面突发异常检测
  55. :return: 没有出现返回False, 其他True
  56. """
  57. image = self.device.image
  58. appear_invitation = self.appear(self.I_G_ACCEPT)
  59. if not appear_invitation:
  60. return False
  61. logger.info('Invitation appearing')
  62. invite_type = self.config.global_game.emergency.friend_invitation
  63. detect_record = self.device.detect_record
  64. match invite_type:
  65. case FriendInvitation.ACCEPT:
  66. logger.info(f"Accept friend invitation")
  67. click_button = self.I_G_ACCEPT
  68. case FriendInvitation.REJECT:
  69. logger.info(f"Reject friend invitation")
  70. click_button = self.I_G_REJECT
  71. case FriendInvitation.ONLY_JADE:
  72. # 勾协
  73. logger.info(f"Only accept jade invitation")
  74. if self.appear(self.I_G_JADE):
  75. click_button = self.I_G_ACCEPT
  76. else:
  77. click_button = self.I_G_IGNORE
  78. case FriendInvitation.JADE_AND_FOOD:
  79. # 如果是接受勾协和粮协
  80. logger.info(f"Accept jade and food invitation")
  81. if self.appear(self.I_G_JADE) or self.appear(self.I_G_CAT_FOOD) or self.appear(self.I_G_DOG_FOOD):
  82. click_button = self.I_G_ACCEPT
  83. else:
  84. click_button = self.I_G_IGNORE
  85. case FriendInvitation.IGNORE:
  86. # 如果是忽略
  87. logger.info(f"Ignore friend invitation")
  88. click_button = self.I_G_IGNORE
  89. case _:
  90. raise ScriptError(f'Unknown friend invitation type: {invite_type}')
  91. if not click_button:
  92. raise ScriptError(f'Unknown click button type: {invite_type}')
  93. while 1:
  94. self.device.screenshot()
  95. if not self.appear(target=click_button):
  96. logger.info('Deal with invitation done')
  97. break
  98. if self.appear_then_click(click_button, interval=0.8):
  99. continue
  100. # 有的时候长战斗 点击后会取消战斗状态
  101. self.device.detect_record = detect_record
  102. # 如果接受邀请则立即执行悬赏任务
  103. if click_button == self.I_G_ACCEPT:
  104. self.set_next_run(task='WantedQuests', target=datetime.now().replace(microsecond=0))
  105. return True
  106. def screenshot(self):
  107. """
  108. 截图 引入中间函数的目的是 为了解决如协作的这类突发的事件
  109. :return:
  110. """
  111. self.device.screenshot()
  112. # 判断勾协
  113. self._burst()
  114. # # 判断网络异常
  115. # if self.appear(self.I_NETWORK_ABNORMAL):
  116. # logger.warning(f"Network abnormal")
  117. # raise GameStuckError
  118. #
  119. # # 判断网络错误
  120. # if self.appear(self.I_NETWORK_ERROR):
  121. # logger.warning(f"Network error")
  122. # raise GameStuckError
  123. return self.device.image
  124. def maybe_screenshot(self, soft_skip: bool = False):
  125. """
  126. 可能截图
  127. :param soft_skip: True跳过截图(但保证设备一定有图才跳过,否则依然截图)
  128. :return:
  129. """
  130. if not soft_skip or not self.exist_image():
  131. return self.screenshot()
  132. return self.device.image
  133. def exist_image(self) -> bool:
  134. """
  135. 判断当前设备是否有图片
  136. :return: 有返回True,没有返回False
  137. """
  138. return hasattr(self.device, 'image') and self.device.image is not None
  139. def appear(self,
  140. target: RuleImage | RuleGif | RuleOcr,
  141. interval: float = None,
  142. threshold: float = None):
  143. """
  144. :param target: 匹配的目标可以是RuleImage, 也可以是RuleOcr
  145. :param interval:
  146. :param threshold:
  147. :return:
  148. """
  149. if interval:
  150. if target.name in self.interval_timer:
  151. if self.interval_timer[target.name].limit != interval:
  152. self.interval_timer[target.name] = Timer(interval)
  153. else:
  154. self.interval_timer[target.name] = Timer(interval)
  155. if not self.interval_timer[target.name].reached():
  156. return False
  157. if isinstance(target, RuleOcr):
  158. appear = self.ocr_appear(target, interval)
  159. else:
  160. appear = target.match(self.device.image, threshold=threshold)
  161. if appear and interval:
  162. self.interval_timer[target.name].reset()
  163. return appear
  164. def appear_then_click(self,
  165. target: RuleImage | RuleGif,
  166. action: Union[RuleClick, RuleLongClick] = None,
  167. interval: float = None,
  168. threshold: float = None,
  169. duration: float = None):
  170. """
  171. 出现了就点击,默认点击图片的位置,如果添加了click参数,就点击click的位置
  172. :param duration: 如果是长按,可以手动指定duration,不指定默认.单位是ms!!!!
  173. :param action: 可以是RuleClick, 也可以是RuleLongClick
  174. :param target: 可以是RuleImage后续支持RuleOcr
  175. :param interval:
  176. :param threshold:
  177. :return: True or False
  178. """
  179. if not isinstance(target, RuleImage) and not isinstance(target, RuleGif):
  180. return False
  181. appear = self.appear(target, interval=interval, threshold=threshold)
  182. if appear and not action:
  183. x, y = target.coord()
  184. self.device.click(x, y, control_name=target.name)
  185. elif appear and action:
  186. x, y = action.coord()
  187. if isinstance(action, RuleLongClick):
  188. if duration is None:
  189. self.device.long_click(x, y, duration=action.duration / 1000, control_name=target.name)
  190. else:
  191. self.device.long_click(x, y, duration=duration / 1000, control_name=target.name)
  192. elif isinstance(action, RuleClick):
  193. self.device.click(x, y, control_name=target.name)
  194. return appear
  195. def wait_until_appear(self,
  196. target: RuleImage | RuleOcr,
  197. skip_first_screenshot=False,
  198. wait_time: int = None) -> bool:
  199. """
  200. 等待直到出现目标
  201. :param wait_time: 等待时间,单位秒
  202. :param target:
  203. :param skip_first_screenshot:
  204. :return:
  205. """
  206. wait_timer = None
  207. if wait_time:
  208. wait_timer = Timer(wait_time)
  209. wait_timer.start()
  210. while 1:
  211. if skip_first_screenshot:
  212. skip_first_screenshot = False
  213. else:
  214. self.screenshot()
  215. if wait_timer and wait_timer.reached():
  216. logger.warning(f"Wait until appear {target.name} timeout")
  217. return False
  218. if isinstance(target, RuleImage) and self.appear(target):
  219. return True
  220. if isinstance(target, RuleOcr) and self.ocr_appear(target):
  221. return True
  222. def wait_until_appear_then_click(self,
  223. target: RuleImage,
  224. action: Union[RuleClick, RuleLongClick] = None,
  225. wait_time: int = None) -> bool:
  226. """
  227. 等待直到出现目标,然后点击
  228. :param wait_time:
  229. :param action:
  230. :param target:
  231. :return:
  232. """
  233. if not self.wait_until_appear(target, wait_time):
  234. return False
  235. click_x, click_y = target.coord()
  236. if action is None:
  237. self.device.click(click_x, click_y, control_name=target.name)
  238. elif isinstance(action, RuleLongClick):
  239. self.device.long_click(click_x, click_y, duration=action.duration / 1000, control_name=target.name)
  240. elif isinstance(action, RuleClick):
  241. self.device.click(click_x, click_y, control_name=target.name)
  242. return True
  243. def wait_until_disappear(self, target: RuleImage) -> None:
  244. while 1:
  245. self.screenshot()
  246. if not self.appear(target):
  247. break
  248. def wait_until_stable(self,
  249. target: RuleImage,
  250. timer=Timer(0.3, count=1),
  251. timeout=Timer(5, count=10),
  252. skip_first_screenshot=True):
  253. """
  254. 等待目标稳定,即连续多次匹配成功
  255. :param target:
  256. :param timer:
  257. :param timeout:
  258. :param skip_first_screenshot:
  259. :return:
  260. """
  261. target._match_init = False
  262. timeout.reset()
  263. while 1:
  264. if skip_first_screenshot:
  265. skip_first_screenshot = False
  266. else:
  267. self.screenshot()
  268. if target._match_init:
  269. if target.match(self.device.image):
  270. if timer.reached():
  271. break
  272. else:
  273. # button.load_color(self.device.image)
  274. timer.reset()
  275. else:
  276. # target.load_color(self.device.image)
  277. target._match_init = True
  278. if timeout.reached():
  279. logger.warning(f'Wait_until_stable({target}) timeout')
  280. break
  281. def wait_animate_stable(self, rule: RuleAnimate, interval: float = None, timeout: float = None):
  282. """
  283. 不同与上面的wait_until_stable,这个将会匹配连续的两帧图片的特定区域
  284. @param rule:
  285. @param interval:
  286. @param timeout:
  287. @return:
  288. """
  289. if not isinstance(rule, RuleAnimate):
  290. rule = RuleAnimate(rule)
  291. timeout_timer = Timer(timeout).start() if timeout is not None else None
  292. while 1:
  293. self.screenshot()
  294. if interval:
  295. if rule.name in self.interval_timer:
  296. if self.interval_timer[rule.name].limit != interval:
  297. self.interval_timer[rule.name] = Timer(interval)
  298. else:
  299. self.interval_timer[rule.name] = Timer(interval)
  300. if not self.interval_timer[rule.name].reached():
  301. return False
  302. stable = rule.stable(self.device.image)
  303. if stable:
  304. if interval:
  305. self.interval_timer[rule.name].reset()
  306. break
  307. if timeout_timer and timeout_timer.reached():
  308. logger.info(f'Wait_animate_stable({rule}) timeout')
  309. break
  310. def swipe(self, swipe: RuleSwipe, interval: float = None) -> None:
  311. """
  312. :param interval:
  313. :param swipe:
  314. :return:
  315. """
  316. if not isinstance(swipe, RuleSwipe):
  317. return
  318. if interval:
  319. if swipe.name in self.interval_timer:
  320. # 如果传入的限制时间不一样,则替换限制新的传入的时间
  321. if self.interval_timer[swipe.name].limit != interval:
  322. self.interval_timer[swipe.name] = Timer(interval)
  323. else:
  324. # 如果没有限制时间,则创建限制时间
  325. self.interval_timer[swipe.name] = Timer(interval)
  326. # 如果时间还没到达,则不执行
  327. if not self.interval_timer[swipe.name].reached():
  328. return
  329. x1, y1, x2, y2 = swipe.coord()
  330. self.device.swipe(p1=(x1, y1), p2=(x2, y2), control_name=swipe.name)
  331. # 执行后,如果有限制时间,则重置限制时间
  332. if interval:
  333. # logger.info(f'Swipe {swipe.name}')
  334. self.interval_timer[swipe.name].reset()
  335. def click(self, click: Union[RuleClick, RuleLongClick] = None, interval: float = None) -> bool:
  336. """
  337. 点击或者长按
  338. :param interval:
  339. :param click:
  340. :return: 返回值不是click是否成功,而是interval是否设置以及是否到时间
  341. """
  342. if not click:
  343. return False
  344. if interval:
  345. if click.name in self.interval_timer:
  346. # 如果传入的限制时间不一样,则替换限制新的传入的时间
  347. if self.interval_timer[click.name].limit != interval:
  348. self.interval_timer[click.name] = Timer(interval)
  349. else:
  350. # 如果没有限制时间,则创建限制时间
  351. self.interval_timer[click.name] = Timer(interval)
  352. # 如果时间还没到达,则不执行
  353. if not self.interval_timer[click.name].reached():
  354. return False
  355. x, y = click.coord()
  356. if isinstance(click, RuleLongClick):
  357. self.device.long_click(x=x, y=y, duration=click.duration / 1000, control_name=click.name)
  358. elif isinstance(click, RuleClick) or isinstance(click, RuleImage) or isinstance(click, RuleOcr):
  359. self.device.click(x=x, y=y, control_name=click.name)
  360. # 执行后,如果有限制时间,则重置限制时间
  361. if interval:
  362. self.interval_timer[click.name].reset()
  363. return True
  364. return False
  365. def ocr_appear(self, target: RuleOcr, interval: float = None) -> bool:
  366. """
  367. ocr识别目标
  368. :param interval:
  369. :param target:
  370. :return: 如果target有keyword或者是keyword存在,返回是True,否则返回False
  371. 但是没有指定keyword,返回的是匹配到的值,具体取决于target的mode
  372. """
  373. if not isinstance(target, RuleOcr):
  374. return None
  375. if interval:
  376. if target.name in self.interval_timer:
  377. # 如果传入的限制时间不一样,则替换限制新的传入的时间
  378. if self.interval_timer[target.name].limit != interval:
  379. self.interval_timer[target.name] = Timer(interval)
  380. else:
  381. # 如果没有限制时间,则创建限制时间
  382. self.interval_timer[target.name] = Timer(interval)
  383. # 如果时间还没到达,则不执行
  384. if not self.interval_timer[target.name].reached():
  385. return None
  386. result = target.ocr(self.device.image)
  387. appear = False
  388. if not target.keyword or target.keyword == '':
  389. appear = False
  390. match target.mode:
  391. case OcrMode.FULL: # 全匹配
  392. appear = result != (0, 0, 0, 0)
  393. case OcrMode.SINGLE:
  394. appear = result == target.keyword
  395. case OcrMode.DIGIT:
  396. appear = result == int(target.keyword)
  397. case OcrMode.DIGITCOUNTER:
  398. appear = result == target.ocr_str_digit_counter(target.keyword)
  399. case OcrMode.DURATION:
  400. appear = result == target.parse_time(target.keyword)
  401. if interval and appear:
  402. self.interval_timer[target.name].reset()
  403. return appear
  404. def ocr_appear_click(self,
  405. target: RuleOcr,
  406. action: Union[RuleClick, RuleLongClick] = None,
  407. interval: float = None,
  408. duration: float = None) -> bool:
  409. """
  410. ocr识别目标,如果目标存在,则触发动作
  411. :param target:
  412. :param action:
  413. :param interval:
  414. :param duration:
  415. :return:
  416. """
  417. appear = self.ocr_appear(target, interval)
  418. if not appear:
  419. return False
  420. if action:
  421. x, y = action.coord()
  422. self.click(action, interval)
  423. else:
  424. x, y = target.coord()
  425. self.device.click(x=x, y=y, control_name=target.name)
  426. return True
  427. def list_find(self, target: RuleList, name: str | list[str], max_swipe: int = 10) -> bool | tuple:
  428. """
  429. 会一致在列表寻找目标,找到了就退出。
  430. 如果是图片列表会一直往下找
  431. 如果是纯文字的,会自动识别自己的位置,根据位置选择向前还是向后翻
  432. :param max_swipe: 最大滑动次数
  433. :param target:
  434. :param name:
  435. :return:
  436. """
  437. swipe_down = False
  438. swipe_distance_ratio = None
  439. result = None
  440. if not target:
  441. return False
  442. appear = False
  443. for _ in range(max_swipe):
  444. self.screenshot()
  445. if target.is_image:
  446. result = target.image_appear(self.device.image, name=name)
  447. swipe_down = True
  448. elif target.is_ocr:
  449. result = target.ocr_appear(self.device.image, name=name)
  450. swipe_down = result is not None and isinstance(result, int) and result > 0
  451. swipe_distance_ratio = 1
  452. # 结果是坐标证明找到了, 非坐标都是没找到
  453. if result is not None and isinstance(result, tuple):
  454. appear = True
  455. break
  456. if swipe_distance_ratio:
  457. x1, y1, x2, y2 = target.swipe_pos(number=swipe_distance_ratio, after=swipe_down)
  458. else:
  459. x1, y1, x2, y2 = target.swipe_pos(after=swipe_down)
  460. self.device.swipe(p1=(x1, y1), p2=(x2, y2))
  461. sleep(random.uniform(0.8, 1.3)) # 等待滑动完成, 待优化
  462. if appear:
  463. return result
  464. return False
  465. def list_appear_click(self, target: RuleList, interval: float = None, max_swipe: int = 10) -> bool:
  466. if interval:
  467. if target.name in self.interval_timer:
  468. # 如果传入的限制时间不一样,则替换限制新的传入的时间
  469. if self.interval_timer[target.name].limit != interval:
  470. self.interval_timer[target.name] = Timer(interval)
  471. else:
  472. # 如果没有限制时间,则创建限制时间
  473. self.interval_timer[target.name] = Timer(interval)
  474. # 如果时间还没到达,则不执行
  475. if not self.interval_timer[target.name].reached():
  476. return False
  477. appear = self.list_find(target, name=target.array[0], max_swipe=max_swipe)
  478. if isinstance(appear, tuple) and interval:
  479. x, y = appear
  480. self.device.click(x, y)
  481. self.interval_timer[target.name].reset()
  482. return True
  483. return False
  484. def set_next_run(self, task: str, finish: bool = False,
  485. success: bool = None, server: bool = True, target: datetime = None) -> None:
  486. """
  487. 设置下次运行时间 当然这个也是可以重写的
  488. :param target: 可以自定义的下次运行时间
  489. :param server: True
  490. :param success: 判断是成功的还是失败的时间间隔
  491. :param task: 任务名称,大驼峰的
  492. :param finish: 是完成任务后的时间为基准还是开始任务的时间为基准
  493. :return:
  494. """
  495. if finish:
  496. start_time = datetime.now().replace(microsecond=0)
  497. else:
  498. start_time = self.start_time
  499. self.config.task_delay(task, start_time=start_time, success=success, server=server, target=target)
  500. def custom_next_run(self, task: str, custom_time: Time = None, time_delta: float = 1) -> None:
  501. """
  502. 设置下次自定义运行时间
  503. :param task: 任务名称,大驼峰的
  504. :param custom_time: 可以自定义的下次运行时间
  505. :param time_delta: 下次运行日期为几天后,默认为第二天
  506. :return:
  507. """
  508. target_time = (datetime.now() + timedelta(days=time_delta)).replace(hour=custom_time.hour,
  509. minute=custom_time.minute,
  510. second=custom_time.second)
  511. self.set_next_run(task, target=target_time)
  512. # ---------------------------------------------------------------------------------------------------------------
  513. #
  514. # ---------------------------------------------------------------------------------------------------------------
  515. def ui_reward_appear_click(self, screenshot=False) -> bool:
  516. """
  517. 如果出现 ‘获得奖励’ 就点击
  518. :return:
  519. """
  520. if screenshot:
  521. self.screenshot()
  522. return self.appear_then_click(self.I_UI_REWARD, action=self.C_UI_REWARD, interval=0.4, threshold=0.6)
  523. def ui_get_reward(self, click_image: RuleImage or RuleOcr or RuleClick, click_interval: float = 1):
  524. """
  525. 传进来一个点击图片 或是 一个ocr, 会点击这个图片,然后等待‘获得奖励’,
  526. 最后当获得奖励消失后 退出
  527. :param click_interval:
  528. :param click_image:
  529. :return:
  530. """
  531. _timer = Timer(10)
  532. _timer.start()
  533. while 1:
  534. self.screenshot()
  535. if self.ui_reward_appear_click():
  536. sleep(0.5)
  537. while 1:
  538. self.screenshot()
  539. # 等待动画结束
  540. if not self.appear(self.I_UI_REWARD, threshold=0.6):
  541. logger.info('Get reward success')
  542. break
  543. # 一直点击
  544. if self.ui_reward_appear_click():
  545. continue
  546. break
  547. if _timer.reached():
  548. logger.warning('Get reward timeout')
  549. break
  550. if isinstance(click_image, RuleImage):
  551. if self.appear_then_click(click_image, interval=click_interval):
  552. continue
  553. elif isinstance(click_image, RuleOcr):
  554. if self.ocr_appear_click(click_image, interval=click_interval):
  555. continue
  556. elif isinstance(click_image, RuleClick):
  557. if self.click(click_image, interval=click_interval):
  558. continue
  559. return True
  560. def ui_click(self, click, stop, interval=1):
  561. """
  562. 循环的一个操作,直到出现stop
  563. :param click:
  564. :param stop:
  565. :parm interval
  566. :return:
  567. """
  568. while 1:
  569. self.screenshot()
  570. if self.appear(stop):
  571. break
  572. if isinstance(click, RuleImage) and self.appear_then_click(click, interval=interval):
  573. continue
  574. if isinstance(click, RuleClick) and self.click(click, interval=interval):
  575. continue
  576. elif isinstance(click, RuleOcr) and self.ocr_appear_click(click, interval=interval):
  577. continue
  578. def ui_click_until_disappear(self, click, interval: float = 1):
  579. """
  580. 点击一个按钮直到消失
  581. :param interval:
  582. :param click:
  583. :return:
  584. """
  585. while 1:
  586. self.screenshot()
  587. if not self.appear(click):
  588. break
  589. elif self.appear_then_click(click, interval=interval):
  590. continue
  591. def ui_click_until_smt_disappear(self, click, stop, interval: float = 1):
  592. """
  593. 点击一个按钮/区域/文字直到stop消失
  594. """
  595. while 1:
  596. self.screenshot()
  597. if not self.appear(stop):
  598. break
  599. if isinstance(click, RuleImage) or isinstance(click, RuleGif):
  600. self.appear_then_click(click, interval=interval)
  601. continue
  602. if isinstance(click, RuleClick):
  603. self.click(click, interval)
  604. continue
  605. if isinstance(click, RuleOcr):
  606. self.click(click)
  607. continue
  608. def push_notify(self, content='', title=None, level=3):
  609. logger.info(f'Push notify: {content}')
  610. def save_image(self, task_name=None, content=None, wait_time=2, image_type=False, push_flag=False, level=3):
  611. logger.info(f'Save image: {task_name}')