mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-04 02:26:11 +08:00
55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
from abc import ABC
|
|
from typing import Literal
|
|
|
|
from httpx import AsyncClient
|
|
|
|
from ..types import Target
|
|
from .http import http_client
|
|
|
|
|
|
class ClientManager(ABC):
|
|
async def get_client(self, target: Target | None) -> AsyncClient: ...
|
|
|
|
async def get_client_for_static(self) -> AsyncClient: ...
|
|
|
|
async def get_query_name_client(self) -> AsyncClient: ...
|
|
|
|
async def refresh_client(self): ...
|
|
|
|
|
|
class DefaultClientManager(ClientManager):
|
|
async def get_client(self, target: Target | None) -> AsyncClient:
|
|
return http_client()
|
|
|
|
async def get_client_for_static(self) -> AsyncClient:
|
|
return http_client()
|
|
|
|
async def get_query_name_client(self) -> AsyncClient:
|
|
return http_client()
|
|
|
|
|
|
class SchedulerConfig:
|
|
schedule_type: Literal["date", "interval", "cron"]
|
|
schedule_setting: dict
|
|
name: str
|
|
client_mgr: type[ClientManager] = DefaultClientManager
|
|
require_browser: bool = False
|
|
|
|
def __str__(self):
|
|
return f"[{self.name}]-{self.name}-{self.schedule_setting}"
|
|
|
|
def __init__(self):
|
|
self.default_http_client = http_client()
|
|
|
|
|
|
def scheduler(schedule_type: Literal["date", "interval", "cron"], schedule_setting: dict) -> type[SchedulerConfig]:
|
|
return type(
|
|
"AnonymousScheduleConfig",
|
|
(SchedulerConfig,),
|
|
{
|
|
"schedule_type": schedule_type,
|
|
"schedule_setting": schedule_setting,
|
|
"client_mgr": ClientManager,
|
|
},
|
|
)
|