49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
"""账号自动学习任务的立即开始与停止。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from euniv.study_window import window_open
|
|
|
|
|
|
class StudyControlError(ValueError):
|
|
"""任务控制参数不符合要求。"""
|
|
|
|
|
|
def start_now(account) -> None:
|
|
account.study_paused = False
|
|
account.study_ignore_window = True
|
|
|
|
|
|
def stop_now(account) -> None:
|
|
account.study_paused = True
|
|
account.study_ignore_window = False
|
|
|
|
|
|
def is_paused(account) -> bool:
|
|
return bool(getattr(account, "study_paused", False))
|
|
|
|
|
|
def ignores_window(account) -> bool:
|
|
return bool(getattr(account, "study_ignore_window", False))
|
|
|
|
|
|
def eligible(account) -> bool:
|
|
if is_paused(account):
|
|
return False
|
|
if ignores_window(account):
|
|
return True
|
|
return window_open(account)
|
|
|
|
|
|
def view_of(account) -> dict:
|
|
paused = is_paused(account)
|
|
ignore = ignores_window(account)
|
|
opened = window_open(account)
|
|
started = (not paused) and (ignore or opened)
|
|
return {
|
|
"paused": paused,
|
|
"ignore_window": ignore,
|
|
"window_open": opened,
|
|
"started": started,
|
|
}
|