mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-09 18:27:56 +08:00
♻️ rename scheduler_config -> site
This commit is contained in:
@@ -1,37 +1,37 @@
|
||||
from nonebot.log import logger
|
||||
|
||||
from ..utils import Site
|
||||
from ..config import config
|
||||
from .scheduler import Scheduler
|
||||
from ..utils import SchedulerConfig
|
||||
from ..config.db_model import Target
|
||||
from ..types import Target as T_Target
|
||||
from ..platform import platform_manager
|
||||
from ..plugin_config import plugin_config
|
||||
|
||||
scheduler_dict: dict[type[SchedulerConfig], Scheduler] = {}
|
||||
scheduler_dict: dict[type[Site], Scheduler] = {}
|
||||
|
||||
|
||||
async def init_scheduler():
|
||||
_schedule_class_dict: dict[type[SchedulerConfig], list[Target]] = {}
|
||||
_schedule_class_platform_dict: dict[type[SchedulerConfig], list[str]] = {}
|
||||
_schedule_class_dict: dict[type[Site], list[Target]] = {}
|
||||
_schedule_class_platform_dict: dict[type[Site], list[str]] = {}
|
||||
for platform in platform_manager.values():
|
||||
scheduler_config = platform.scheduler
|
||||
if not hasattr(scheduler_config, "name") or not scheduler_config.name:
|
||||
scheduler_config.name = f"AnonymousScheduleConfig[{platform.platform_name}]"
|
||||
site = platform.site
|
||||
if not hasattr(site, "name") or not site.name:
|
||||
site.name = f"AnonymousScheduleConfig[{platform.platform_name}]"
|
||||
|
||||
platform_name = platform.platform_name
|
||||
targets = await config.get_platform_target(platform_name)
|
||||
if scheduler_config not in _schedule_class_dict:
|
||||
_schedule_class_dict[scheduler_config] = list(targets)
|
||||
if site not in _schedule_class_dict:
|
||||
_schedule_class_dict[site] = list(targets)
|
||||
else:
|
||||
_schedule_class_dict[scheduler_config].extend(targets)
|
||||
if scheduler_config not in _schedule_class_platform_dict:
|
||||
_schedule_class_platform_dict[scheduler_config] = [platform_name]
|
||||
_schedule_class_dict[site].extend(targets)
|
||||
if site not in _schedule_class_platform_dict:
|
||||
_schedule_class_platform_dict[site] = [platform_name]
|
||||
else:
|
||||
_schedule_class_platform_dict[scheduler_config].append(platform_name)
|
||||
for scheduler_config, target_list in _schedule_class_dict.items():
|
||||
if not plugin_config.bison_use_browser and scheduler_config.require_browser:
|
||||
logger.warning(f"{scheduler_config.name} requires browser, it will not schedule.")
|
||||
_schedule_class_platform_dict[site].append(platform_name)
|
||||
for site, target_list in _schedule_class_dict.items():
|
||||
if not plugin_config.bison_use_browser and site.require_browser:
|
||||
logger.warning(f"{site.name} requires browser, it will not schedule.")
|
||||
continue
|
||||
|
||||
schedulable_args = []
|
||||
@@ -39,19 +39,19 @@ async def init_scheduler():
|
||||
schedulable_args.append(
|
||||
(target.platform_name, T_Target(target.target), platform_manager[target.platform_name].use_batch)
|
||||
)
|
||||
platform_name_list = _schedule_class_platform_dict[scheduler_config]
|
||||
scheduler_dict[scheduler_config] = Scheduler(scheduler_config, schedulable_args, platform_name_list)
|
||||
platform_name_list = _schedule_class_platform_dict[site]
|
||||
scheduler_dict[site] = Scheduler(site, schedulable_args, platform_name_list)
|
||||
config.register_add_target_hook(handle_insert_new_target)
|
||||
config.register_delete_target_hook(handle_delete_target)
|
||||
|
||||
|
||||
async def handle_insert_new_target(platform_name: str, target: T_Target):
|
||||
platform = platform_manager[platform_name]
|
||||
scheduler_obj = scheduler_dict[platform.scheduler]
|
||||
scheduler_obj = scheduler_dict[platform.site]
|
||||
scheduler_obj.insert_new_schedulable(platform_name, target)
|
||||
|
||||
|
||||
async def handle_delete_target(platform_name: str, target: T_Target):
|
||||
platform = platform_manager[platform_name]
|
||||
scheduler_obj = scheduler_dict[platform.scheduler]
|
||||
scheduler_obj = scheduler_dict[platform.site]
|
||||
scheduler_obj.delete_schedulable(platform_name, target)
|
||||
|
||||
@@ -5,13 +5,13 @@ from nonebot.log import logger
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot_plugin_saa.utils.exceptions import NoBotFound
|
||||
|
||||
from nonebot_bison.utils.scheduler_config import ClientManager
|
||||
from nonebot_bison.utils import ClientManager
|
||||
|
||||
from ..config import config
|
||||
from ..send import send_msgs
|
||||
from ..types import Target, SubUnit
|
||||
from ..platform import platform_manager
|
||||
from ..utils import ProcessContext, SchedulerConfig
|
||||
from ..utils import Site, ProcessContext
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -30,7 +30,7 @@ class Scheduler:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
scheduler_config: type[SchedulerConfig],
|
||||
scheduler_config: type[Site],
|
||||
schedulables: list[tuple[str, Target, bool]], # [(platform_name, target, use_batch)]
|
||||
platform_name_list: list[str],
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user