mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-14 11:19:26 +08:00
add: migrate detect others' login
This commit is contained in:
37
alas.py
37
alas.py
@@ -591,6 +591,7 @@ from module.scheduler_watcher import *
|
||||
from datetime import datetime, timedelta
|
||||
from module.counter import MaxCounter
|
||||
from typing import Dict
|
||||
from module.device.my_assets import my_OTHERS_LOGIN_CONFIRM
|
||||
|
||||
|
||||
class FailedTaskCounter:
|
||||
@@ -745,6 +746,40 @@ class AzurLaneAutoScript(AzurLaneAutoScript):
|
||||
)
|
||||
exit(1)
|
||||
|
||||
def delay_all_tasks(self):
|
||||
target = datetime.now() + timedelta(minutes=self.config.others_login.interval)
|
||||
|
||||
self.config.task_delay(target=target, task=self.config.task.command)
|
||||
|
||||
for i in self.config.pending_task:
|
||||
self.config.task_delay(target=target, task=i.command)
|
||||
|
||||
for i in self.config.waiting_task:
|
||||
if i.next_run < target:
|
||||
self.config.task_delay(target=target, task=i.command)
|
||||
|
||||
def handle_OthersLogin(self, e) -> bool:
|
||||
logger.warning("Detected others' login")
|
||||
self.delay_all_tasks()
|
||||
|
||||
method = self.config.Optimization_WhenTaskQueueEmpty
|
||||
if method == "goto_main":
|
||||
self.config.Optimization_WhenTaskQueueEmpty = "stay_there"
|
||||
logger.warning("You should never goto main when you need to delay tasks as others login, change to stay there instead.")
|
||||
self.device.click(my_OTHERS_LOGIN_CONFIRM)
|
||||
|
||||
if method == "stay_there":
|
||||
self.device.click(my_OTHERS_LOGIN_CONFIRM)
|
||||
if self.config.others_login.need_notify:
|
||||
handle_notify(
|
||||
self.config.Error_OnePushConfig,
|
||||
title=f"Alas <{self.config_name}>: account's owner logs in",
|
||||
content=f"Delay some tasks to {datetime.now() + timedelta(minutes=self.config.others_login.interval, seconds=-1)}",
|
||||
)
|
||||
self.config.save()
|
||||
self.config.update()
|
||||
return True
|
||||
|
||||
def run(self, command, skip_first_screenshot=False):
|
||||
try:
|
||||
if not skip_first_screenshot:
|
||||
@@ -767,6 +802,8 @@ class AzurLaneAutoScript(AzurLaneAutoScript):
|
||||
return self.handle_ScriptError(e)
|
||||
except RequestHumanTakeover as e:
|
||||
return self.handle_RequestHumanTakeover(e)
|
||||
except OthersLogin as e:
|
||||
return self.handle_OthersLogin(e)
|
||||
except Exception as e:
|
||||
return self.handle_Exception(e)
|
||||
|
||||
|
||||
BIN
assets/cn/device/my_OTHERS_LOGIN_CONFIRM.png
Normal file
BIN
assets/cn/device/my_OTHERS_LOGIN_CONFIRM.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.5 KiB |
BIN
assets/cn/device/my_OTHERS_LOGIN_NOTIFY.png
Normal file
BIN
assets/cn/device/my_OTHERS_LOGIN_NOTIFY.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.2 KiB |
@@ -155,6 +155,11 @@
|
||||
"MaxRetryTimes": 5,
|
||||
"Notify": false
|
||||
},
|
||||
"OthersLogin": {
|
||||
"Enable": false,
|
||||
"Interval": 180,
|
||||
"Notify": true
|
||||
},
|
||||
"Storage": {
|
||||
"Storage": {}
|
||||
}
|
||||
|
||||
@@ -665,6 +665,20 @@
|
||||
"value": false
|
||||
}
|
||||
},
|
||||
"OthersLogin": {
|
||||
"Enable": {
|
||||
"type": "checkbox",
|
||||
"value": false
|
||||
},
|
||||
"Interval": {
|
||||
"type": "input",
|
||||
"value": 180
|
||||
},
|
||||
"Notify": {
|
||||
"type": "checkbox",
|
||||
"value": true
|
||||
}
|
||||
},
|
||||
"Storage": {
|
||||
"Storage": {
|
||||
"type": "storage",
|
||||
|
||||
@@ -975,3 +975,10 @@ GuildCoin:
|
||||
value: ^AAAAAA
|
||||
display: hide
|
||||
Record: 2020-01-01 00:00:00
|
||||
|
||||
# ==================== OthersLogin ====================
|
||||
|
||||
OthersLogin:
|
||||
Enable: false
|
||||
Interval: 180
|
||||
Notify: true
|
||||
@@ -24,6 +24,7 @@ Alas:
|
||||
- SchedulerWatcher
|
||||
- GameRestart
|
||||
- InstanceRestart
|
||||
- OthersLogin
|
||||
|
||||
# ==================== Cheat ====================
|
||||
|
||||
|
||||
@@ -795,6 +795,15 @@ class MultiSetWrapper:
|
||||
from module.config.full_config import AzurLaneFullConfig
|
||||
from module.scheduler_watcher import AzurLaneSchedulerWatcher
|
||||
from module.log_res.log_res import LogRes
|
||||
from cached_property import cached_property
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
class OthersLoginSetting:
|
||||
enabled: bool
|
||||
interval: int
|
||||
need_notify: bool
|
||||
|
||||
|
||||
class AzurLaneConfig(AzurLaneConfig):
|
||||
@@ -812,3 +821,12 @@ class AzurLaneConfig(AzurLaneConfig):
|
||||
@property
|
||||
def log_res(self):
|
||||
return LogRes(self)
|
||||
|
||||
@cached_property
|
||||
def others_login(self):
|
||||
full_config = self.full_config
|
||||
return OthersLoginSetting(
|
||||
enabled=full_config.Restart_OthersLogin_Enable,
|
||||
interval=full_config.Restart_OthersLogin_Interval,
|
||||
need_notify=full_config.Restart_OthersLogin_Notify,
|
||||
)
|
||||
|
||||
@@ -618,5 +618,10 @@ class GeneratedConfig:
|
||||
GuildCoin_Color = '^AAAAAA'
|
||||
GuildCoin_Record = datetime.datetime(2020, 1, 1, 0, 0)
|
||||
|
||||
# Group `OthersLogin`
|
||||
OthersLogin_Enable = False
|
||||
OthersLogin_Interval = 180
|
||||
OthersLogin_Notify = True
|
||||
|
||||
# Group `Storage`
|
||||
Storage_Storage = {}
|
||||
|
||||
@@ -107,6 +107,9 @@ class FullGeneratedConfig:
|
||||
Restart_InstanceRestart_Enable = None
|
||||
Restart_InstanceRestart_MaxRetryTimes = None
|
||||
Restart_InstanceRestart_Notify = None
|
||||
Restart_OthersLogin_Enable = None
|
||||
Restart_OthersLogin_Interval = None
|
||||
Restart_OthersLogin_Notify = None
|
||||
Restart_Storage_Storage = None
|
||||
|
||||
# Task `PowerLimit`
|
||||
|
||||
@@ -3382,6 +3382,24 @@
|
||||
"help": "GuildCoin.Record.help"
|
||||
}
|
||||
},
|
||||
"OthersLogin": {
|
||||
"_info": {
|
||||
"name": "OthersLogin._info.name",
|
||||
"help": "OthersLogin._info.help"
|
||||
},
|
||||
"Enable": {
|
||||
"name": "OthersLogin.Enable.name",
|
||||
"help": "OthersLogin.Enable.help"
|
||||
},
|
||||
"Interval": {
|
||||
"name": "OthersLogin.Interval.name",
|
||||
"help": "OthersLogin.Interval.help"
|
||||
},
|
||||
"Notify": {
|
||||
"name": "OthersLogin.Notify.name",
|
||||
"help": "OthersLogin.Notify.help"
|
||||
}
|
||||
},
|
||||
"Storage": {
|
||||
"_info": {
|
||||
"name": "Task status",
|
||||
|
||||
@@ -3382,6 +3382,24 @@
|
||||
"help": "GuildCoin.Record.help"
|
||||
}
|
||||
},
|
||||
"OthersLogin": {
|
||||
"_info": {
|
||||
"name": "OthersLogin._info.name",
|
||||
"help": "OthersLogin._info.help"
|
||||
},
|
||||
"Enable": {
|
||||
"name": "OthersLogin.Enable.name",
|
||||
"help": "OthersLogin.Enable.help"
|
||||
},
|
||||
"Interval": {
|
||||
"name": "OthersLogin.Interval.name",
|
||||
"help": "OthersLogin.Interval.help"
|
||||
},
|
||||
"Notify": {
|
||||
"name": "OthersLogin.Notify.name",
|
||||
"help": "OthersLogin.Notify.help"
|
||||
}
|
||||
},
|
||||
"Storage": {
|
||||
"_info": {
|
||||
"name": "Storage._info.name",
|
||||
|
||||
@@ -3382,6 +3382,24 @@
|
||||
"help": "GuildCoin.Record.help"
|
||||
}
|
||||
},
|
||||
"OthersLogin": {
|
||||
"_info": {
|
||||
"name": "顶号检测",
|
||||
"help": "修改以下的配置后要重新启动Alas实例"
|
||||
},
|
||||
"Enable": {
|
||||
"name": "启用",
|
||||
"help": ""
|
||||
},
|
||||
"Interval": {
|
||||
"name": "顶号后将任务推迟 X 分钟",
|
||||
"help": ""
|
||||
},
|
||||
"Notify": {
|
||||
"name": "通知",
|
||||
"help": ""
|
||||
}
|
||||
},
|
||||
"Storage": {
|
||||
"_info": {
|
||||
"name": "任务状态",
|
||||
|
||||
@@ -3382,6 +3382,24 @@
|
||||
"help": "GuildCoin.Record.help"
|
||||
}
|
||||
},
|
||||
"OthersLogin": {
|
||||
"_info": {
|
||||
"name": "OthersLogin._info.name",
|
||||
"help": "OthersLogin._info.help"
|
||||
},
|
||||
"Enable": {
|
||||
"name": "OthersLogin.Enable.name",
|
||||
"help": "OthersLogin.Enable.help"
|
||||
},
|
||||
"Interval": {
|
||||
"name": "OthersLogin.Interval.name",
|
||||
"help": "OthersLogin.Interval.help"
|
||||
},
|
||||
"Notify": {
|
||||
"name": "OthersLogin.Notify.name",
|
||||
"help": "OthersLogin.Notify.help"
|
||||
}
|
||||
},
|
||||
"Storage": {
|
||||
"_info": {
|
||||
"name": "任務狀態",
|
||||
|
||||
@@ -333,3 +333,27 @@ class Device(Screenshot, Control, AppControl):
|
||||
super().app_stop()
|
||||
self.stuck_record_clear()
|
||||
self.click_record_clear()
|
||||
|
||||
|
||||
from module.device.my_assets import *
|
||||
from module.ocr.ocr import Ocr
|
||||
from module.exception import OthersLogin
|
||||
|
||||
OthersLoginNotifyOcr = Ocr(buttons=my_OTHERS_LOGIN_NOTIFY, lang="cnocr")
|
||||
OTHERS_LOGIN_NOTIFY_SERVER = {
|
||||
"cn": "登录",
|
||||
"jp": "蜴所"
|
||||
}
|
||||
|
||||
|
||||
class Device(Device):
|
||||
def screenshot(self):
|
||||
img = super().screenshot()
|
||||
|
||||
if self.config.others_login.enabled:
|
||||
if my_OTHERS_LOGIN_CONFIRM.appear_on(img):
|
||||
if self.config.SERVER in OTHERS_LOGIN_NOTIFY_SERVER.keys():
|
||||
if OthersLoginNotifyOcr.ocr(img) == OTHERS_LOGIN_NOTIFY_SERVER[self.config.SERVER]:
|
||||
raise OthersLogin
|
||||
|
||||
return img
|
||||
|
||||
8
module/device/my_assets.py
Normal file
8
module/device/my_assets.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from module.base.button import Button
|
||||
from module.base.template import Template
|
||||
|
||||
# This file was automatically generated by dev_tools/button_extract.py.
|
||||
# Don't modify it manually.
|
||||
|
||||
my_OTHERS_LOGIN_CONFIRM = Button(area={'cn': (561, 488, 721, 534), 'en': (561, 488, 721, 534), 'jp': (561, 488, 721, 534), 'tw': (561, 488, 721, 534)}, color={'cn': (100, 147, 205), 'en': (100, 147, 205), 'jp': (100, 147, 205), 'tw': (100, 147, 205)}, button={'cn': (561, 488, 721, 534), 'en': (561, 488, 721, 534), 'jp': (561, 488, 721, 534), 'tw': (561, 488, 721, 534)}, file={'cn': './assets/cn/device/my_OTHERS_LOGIN_CONFIRM.png', 'en': './assets/cn/device/my_OTHERS_LOGIN_CONFIRM.png', 'jp': './assets/cn/device/my_OTHERS_LOGIN_CONFIRM.png', 'tw': './assets/cn/device/my_OTHERS_LOGIN_CONFIRM.png'})
|
||||
my_OTHERS_LOGIN_NOTIFY = Button(area={'cn': (664, 330, 712, 360), 'en': (664, 330, 712, 360), 'jp': (664, 330, 712, 360), 'tw': (664, 330, 712, 360)}, color={'cn': (144, 149, 160), 'en': (144, 149, 160), 'jp': (144, 149, 160), 'tw': (144, 149, 160)}, button={'cn': (664, 330, 712, 360), 'en': (664, 330, 712, 360), 'jp': (664, 330, 712, 360), 'tw': (664, 330, 712, 360)}, file={'cn': './assets/cn/device/my_OTHERS_LOGIN_NOTIFY.png', 'en': './assets/cn/device/my_OTHERS_LOGIN_NOTIFY.png', 'jp': './assets/cn/device/my_OTHERS_LOGIN_NOTIFY.png', 'tw': './assets/cn/device/my_OTHERS_LOGIN_NOTIFY.png'})
|
||||
@@ -61,3 +61,7 @@ class RequestHumanTakeover(Exception):
|
||||
# Request human takeover
|
||||
# Alas is unable to handle such error, probably because of wrong settings.
|
||||
pass
|
||||
|
||||
|
||||
class OthersLogin(Exception):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user