diff --git a/assets/gui/css/alas.css b/assets/gui/css/alas.css index d907940..3f25c87 100644 --- a/assets/gui/css/alas.css +++ b/assets/gui/css/alas.css @@ -377,6 +377,7 @@ pre.rich-traceback-code { #pywebio-scope-scheduler-bar, #pywebio-scope-log-bar, #pywebio-scope-log, +#pywebio-scope-daemon-log-bar, #pywebio-scope-daemon-overview #pywebio-scope-groups { font-weight: 500; margin: 0.3125rem; diff --git a/assets/gui/css/dark-alas.css b/assets/gui/css/dark-alas.css index c2d76e7..62fc2e2 100644 --- a/assets/gui/css/dark-alas.css +++ b/assets/gui/css/dark-alas.css @@ -133,12 +133,13 @@ pre.rich-traceback-code { color: #c9d1d9; } -#pywebio-scope-scheduler-bar, -#pywebio-scope-log-bar, -#pywebio-scope-log, #pywebio-scope-running, #pywebio-scope-pending, #pywebio-scope-waiting, +#pywebio-scope-scheduler-bar, +#pywebio-scope-log-bar, +#pywebio-scope-log, +#pywebio-scope-daemon-log-bar, #pywebio-scope-daemon-overview #pywebio-scope-groups { background-color: #2f3136; border: 1px solid #21262d; diff --git a/assets/gui/css/light-alas.css b/assets/gui/css/light-alas.css index 171d565..6a8be72 100644 --- a/assets/gui/css/light-alas.css +++ b/assets/gui/css/light-alas.css @@ -133,12 +133,13 @@ pre.rich-traceback-code { border: 1px solid lightgrey; } -#pywebio-scope-scheduler-bar, -#pywebio-scope-log-bar, -#pywebio-scope-log, #pywebio-scope-running, #pywebio-scope-pending, #pywebio-scope-waiting, +#pywebio-scope-scheduler-bar, +#pywebio-scope-log-bar, +#pywebio-scope-log, +#pywebio-scope-daemon-log-bar, #pywebio-scope-daemon-overview #pywebio-scope-groups { background-color: white; border: 1px solid lightgrey; diff --git a/config/template.json b/config/template.json index 294d80c..cbe76d9 100644 --- a/config/template.json +++ b/config/template.json @@ -250,11 +250,8 @@ } }, "Momotalk": { - "Scheduler": { - "Enable": false, - "NextRun": "2020-01-01 00:00:00", - "Command": "Momotalk", - "ServerUpdate": "04:00" + "Momotalk": { + "Enable": true } } } \ No newline at end of file diff --git a/module/config/argument/args.json b/module/config/argument/args.json index 4a288bf..1a877b8 100644 --- a/module/config/argument/args.json +++ b/module/config/argument/args.json @@ -1062,28 +1062,10 @@ } }, "Momotalk": { - "Scheduler": { + "Momotalk": { "Enable": { "type": "checkbox", - "value": false, - "option": [ - true, - false - ] - }, - "NextRun": { - "type": "datetime", - "value": "2020-01-01 00:00:00", - "validate": "datetime" - }, - "Command": { - "type": "input", - "value": "Momotalk", - "display": "hide" - }, - "ServerUpdate": { - "type": "input", - "value": "04:00", + "value": true, "display": "hide" } } diff --git a/module/config/argument/argument.yaml b/module/config/argument/argument.yaml index fb2e4aa..f61662d 100644 --- a/module/config/argument/argument.yaml +++ b/module/config/argument/argument.yaml @@ -267,3 +267,10 @@ ItemStorage: stored: StoredTacticalChallengeTicket order: 6 color: "#7ac8e5" + +# ==================== Momotalk ==================== + +Momotalk: + Enable: + value: true + display: hide \ No newline at end of file diff --git a/module/config/argument/menu.json b/module/config/argument/menu.json index 9f562ec..b871831 100644 --- a/module/config/argument/menu.json +++ b/module/config/argument/menu.json @@ -33,7 +33,13 @@ "tasks": [ "Circle", "Task", - "Mail", + "Mail" + ] + }, + "Tool": { + "menu": "collapse", + "page": "tool", + "tasks": [ "Momotalk" ] } diff --git a/module/config/argument/task.yaml b/module/config/argument/task.yaml index acf129b..8f9e611 100644 --- a/module/config/argument/task.yaml +++ b/module/config/argument/task.yaml @@ -80,5 +80,12 @@ Reward: - Scheduler Mail: - Scheduler + +# ==================== Tool ==================== + +Tool: + menu: 'collapse' + page: 'tool' + tasks: Momotalk: - - Scheduler \ No newline at end of file + - Momotalk \ No newline at end of file diff --git a/module/config/config_generated.py b/module/config/config_generated.py index b0eba21..82c0495 100644 --- a/module/config/config_generated.py +++ b/module/config/config_generated.py @@ -166,3 +166,6 @@ class GeneratedConfig: ItemStorage_BountyTicket = {} ItemStorage_ScrimmageTicket = {} ItemStorage_TacticalChallengeTicket = {} + + # Group `Momotalk` + Momotalk_Enable = True diff --git a/module/config/i18n/en-US.json b/module/config/i18n/en-US.json index 72b1aa8..cf8f3ce 100644 --- a/module/config/i18n/en-US.json +++ b/module/config/i18n/en-US.json @@ -15,6 +15,10 @@ "Reward": { "name": "Reward", "help": "" + }, + "Tool": { + "name": "Tools", + "help": "" } }, "Task": { @@ -849,6 +853,16 @@ "help": "" } }, + "Momotalk": { + "_info": { + "name": "Momotalk", + "help": "Tools need to stop the scheduler and then run independently" + }, + "Enable": { + "name": "", + "help": "" + } + }, "Gui": { "Aside": { "Install": "Install", diff --git a/module/config/i18n/zh-CN.json b/module/config/i18n/zh-CN.json index 65206a2..76ce3a1 100644 --- a/module/config/i18n/zh-CN.json +++ b/module/config/i18n/zh-CN.json @@ -15,6 +15,10 @@ "Reward": { "name": "收菜", "help": "" + }, + "Tool": { + "name": "工具", + "help": "" } }, "Task": { @@ -849,6 +853,16 @@ "help": "" } }, + "Momotalk": { + "_info": { + "name": "Momotalk", + "help": "工具需要停止调度器再单独运行" + }, + "Enable": { + "name": "", + "help": "" + } + }, "Gui": { "Aside": { "Install": "安装", diff --git a/module/webui/app.py b/module/webui/app.py index f23f26d..e85aca1 100644 --- a/module/webui/app.py +++ b/module/webui/app.py @@ -611,7 +611,7 @@ class AlasGUI(Frame): [ put_scope("scheduler-bar"), put_scope("groups"), - put_scope("log-bar"), + put_scope("daemon-log-bar"), put_scope("log", [put_html("")]), ], ) @@ -625,7 +625,7 @@ class AlasGUI(Frame): [ put_scope( "_daemon_upper", - [put_scope("scheduler-bar"), put_scope("log-bar")], + [put_scope("scheduler-bar"), put_scope("daemon-log-bar")], ), put_scope("groups"), put_scope("log", [put_html("")]), @@ -654,16 +654,17 @@ class AlasGUI(Frame): scope="scheduler_btn", ) - with use_scope("log-bar"): - put_text(t("Gui.Overview.Log")).style( - "font-size: 1.25rem; margin: auto .5rem auto;" - ) - put_scope( - "log-bar-btns", - [ - put_scope("log_scroll_btn"), - ], - ) + with use_scope("daemon-log-bar"): + with use_scope("log-title"): + put_text(t("Gui.Overview.Log")).style( + "font-size: 1.25rem; margin: auto .5rem auto;" + ) + put_scope( + "log-bar-btns", + [ + put_scope("log_scroll_btn"), + ], + ) switch_log_scroll = BinarySwitchButton( label_on=t("Gui.Button.ScrollON"), diff --git a/module/webui/process_manager.py b/module/webui/process_manager.py index 60b2d1a..338505b 100644 --- a/module/webui/process_manager.py +++ b/module/webui/process_manager.py @@ -6,11 +6,12 @@ from multiprocessing import Process from typing import Dict, List, Union from filelock import FileLock +from rich.console import Console, ConsoleRenderable + from module.config.utils import filepath_config from module.logger import logger, set_file_logger, set_func_logger from module.webui.fake import get_config_mod, mod_instance from module.webui.setting import State -from rich.console import Console, ConsoleRenderable class ProcessManager: @@ -147,6 +148,10 @@ class ProcessManager: if e is not None: AzurLaneAutoScript.stop_event = e ArisuAutoSweeper(config_name=config_name).loop() + elif func == "Momotalk": + from tasks.momotalk.momotalk import MomoTalk + + MomoTalk(config=config_name, task="Momotalk").run() else: logger.critical(f"No function matched: {func}") logger.info(f"[{config_name}] exited. Reason: Finish\n") diff --git a/tasks/momotalk/ui.py b/tasks/momotalk/ui.py index 907115f..708f009 100644 --- a/tasks/momotalk/ui.py +++ b/tasks/momotalk/ui.py @@ -1,9 +1,7 @@ -import cv2 import numpy as np -from module.base.base import ModuleBase from module.base.timer import Timer -from module.base.utils import point_in_area, area_size +from module.base.utils import area_size from module.logger import logger from module.ui.switch import Switch from tasks.base.page import page_main, page_momo_talk @@ -24,23 +22,19 @@ SWITCH_SORT.add_state("descending", SORT_DESCENDING) """Required for template matching as reply and story button can be found in different locations""" -REPLY_TEMPLATE = REPLY.matched_button.image -STORY_TEMPLATE = STORY.matched_button.image -CHATTING_TEMPLATE = CHATTING.matched_button.image +REPLY_TEMPLATE = REPLY +STORY_TEMPLATE = STORY +CHATTING_TEMPLATE = CHATTING class MomoTalkUI(UI): - def __init__(self, config, device): - super().__init__(config, device) - self.swipe_vector_range = (0.65, 0.85) - self.list = CHAT_AREA - self.click_coords = self.device.click_methods.get(self.config.Emulator_ControlMethod, self.device.click_adb) + swipe_vector_range = (0.65, 0.85) + list = CHAT_AREA - def swipe_page(self, direction: str, main: ModuleBase, vector_range=None, reverse=False): + def swipe_page(self, direction: str, vector_range=None, reverse=False): """ Args: direction: up, down - main: vector_range (tuple[float, float]): reverse (bool): """ @@ -58,7 +52,7 @@ class MomoTalkUI(UI): if reverse: vector = (-vector[0], -vector[1]) - main.device.swipe_vector(vector, self.list.button) + self.device.swipe_vector(vector, self.list.button) def select_then_disappear(self, dest_enter: ButtonWrapper, dest_check: ButtonWrapper): timer = Timer(5, 10).start() @@ -83,24 +77,19 @@ class MomoTalkUI(UI): return True - def click_all(self, template, x_add=0, y_add=0): + def click_all(self, template: ButtonWrapper, offset: tuple[int, int] = (0, 0)) -> bool: """ Find the all the locations of the template adding an offset if specified and click them. If after filter, no coords then swipe. """ - image = self.device.screenshot() - result = cv2.matchTemplate(image, template, cv2.TM_CCOEFF_NORMED) - threshold = 0.8 - locations = np.where(result >= threshold) - seen = set() - for pt in zip(*locations[::-1]): - center_pt = (int(pt[0] + template.shape[1] / 2 + x_add), int(pt[1] + template.shape[0] / 2 + y_add)) - seen.add(center_pt) + template.load_search(self.list.area) + template.matched_button._button_offset = offset + seen = template.match_multi_template(self.device.image, similarity=0.8) if seen: - if y_add != 0: - seen = filter(lambda x: point_in_area(x, CHAT_AREA.area), seen) - [self.click_coords(coords[0], coords[1]) for coords in seen] - self.swipe_page("down", self) + if any(offset): + for button in seen: + self.device.click(button) + self.swipe_page("down") return True return False @@ -157,10 +146,10 @@ class MomoTalkUI(UI): return True elif self.click_all(CHATTING_TEMPLATE): timer.reset() - elif self.click_all(REPLY_TEMPLATE, y_add=62): + elif self.click_all(REPLY_TEMPLATE, offset=(0, 62)): logger.info("Clicked on reply") timer.reset() - elif self.click_all(STORY_TEMPLATE, y_add=62): + elif self.click_all(STORY_TEMPLATE, offset=(0, 62)): logger.info("Clicked on story") timer.reset() elif timer.reached():