♻️ rename scheduler_config -> site

This commit is contained in:
felinae98
2024-06-02 22:36:02 +08:00
parent 2fc11a9653
commit 5bd8b21f19
27 changed files with 135 additions and 169 deletions
+6 -6
View File
@@ -8,9 +8,9 @@ from pydantic import Field, BaseModel
from nonebot.compat import type_validate_python
from ..post import Post
from ..utils import Site
from ..types import Target, RawPost, Category
from .platform import NewMessage, StatusChange
from ..utils.scheduler_config import SchedulerConfig
class ArkResponseBase(BaseModel):
@@ -52,7 +52,7 @@ class ArkBulletinResponse(ArkResponseBase):
data: BulletinData
class ArknightsSchedConf(SchedulerConfig):
class ArknightsSite(Site):
name = "arknights"
schedule_type = "interval"
schedule_setting = {"seconds": 30}
@@ -65,7 +65,7 @@ class Arknights(NewMessage):
enable_tag = False
enabled = True
is_common = False
scheduler = ArknightsSchedConf
site = ArknightsSite
has_target = False
default_theme = "arknights"
@@ -127,7 +127,7 @@ class AkVersion(StatusChange):
enable_tag = False
enabled = True
is_common = False
scheduler = ArknightsSchedConf
site = ArknightsSite
has_target = False
default_theme = "brief"
@@ -172,7 +172,7 @@ class MonsterSiren(NewMessage):
enable_tag = False
enabled = True
is_common = False
scheduler = ArknightsSchedConf
site = ArknightsSite
has_target = False
@classmethod
@@ -220,7 +220,7 @@ class TerraHistoricusComic(NewMessage):
enable_tag = False
enabled = True
is_common = False
scheduler = ArknightsSchedConf
site = ArknightsSite
has_target = False
default_theme = "brief"
+9 -11
View File
@@ -11,12 +11,10 @@ from nonebot.log import logger
from pydantic import Field, BaseModel
from nonebot.compat import PYDANTIC_V2, ConfigDict, type_validate_json, type_validate_python
from nonebot_bison.compat import model_rebuild
from nonebot_bison.utils.scheduler_config import ClientManager
from ..post import Post
from ..compat import model_rebuild
from ..types import Tag, Target, RawPost, ApiError, Category
from ..utils import SchedulerConfig, http_client, text_similarity
from ..utils import Site, ClientManager, http_client, text_similarity
from .platform import NewMessage, StatusChange, CategoryNotSupport, CategoryNotRecognize
TBaseModel = TypeVar("TBaseModel", bound=type[BaseModel])
@@ -133,18 +131,18 @@ class BilibiliClient(ClientManager):
return self._client
class BilibiliSchedConf(SchedulerConfig):
class BilibiliSite(Site):
name = "bilibili.com"
schedule_type = "interval"
schedule_setting = {"seconds": 10}
client_man = BilibiliClient
client_mgr = BilibiliClient
class BililiveSchedConf(SchedulerConfig):
class BililiveSchedConf(Site):
name = "live.bilibili.com"
schedule_type = "interval"
schedule_setting = {"seconds": 3}
client_man = BilibiliClient
client_mgr = BilibiliClient
class Bilibili(NewMessage):
@@ -160,7 +158,7 @@ class Bilibili(NewMessage):
enable_tag = True
enabled = True
is_common = True
scheduler = BilibiliSchedConf
site = BilibiliSite
name = "B站"
has_target = True
parse_target_promot = "请输入用户主页的链接"
@@ -333,7 +331,7 @@ class Bilibililive(StatusChange):
enable_tag = False
enabled = True
is_common = True
scheduler = BililiveSchedConf
site = BililiveSchedConf
name = "Bilibili直播"
has_target = True
use_batch = True
@@ -483,7 +481,7 @@ class BilibiliBangumi(StatusChange):
enable_tag = False
enabled = True
is_common = True
scheduler = BilibiliSchedConf
site = BilibiliSite
name = "Bilibili剧集"
has_target = True
parse_target_promot = "请输入剧集主页"
+2 -2
View File
@@ -3,8 +3,8 @@ from typing import Any
from httpx import AsyncClient
from ..post import Post
from ..utils import scheduler
from .platform import NewMessage
from ..utils import anonymous_site
from ..types import Target, RawPost
@@ -16,7 +16,7 @@ class FF14(NewMessage):
enabled = True
is_common = False
scheduler_class = "ff14"
scheduler = scheduler("interval", {"seconds": 60})
site = anonymous_site("interval", {"seconds": 60})
has_target = False
@classmethod
+4 -4
View File
@@ -4,12 +4,12 @@ from typing import Any
from httpx import AsyncClient
from ..post import Post
from ..utils import Site
from .platform import NewMessage
from ..utils import SchedulerConfig
from ..types import Target, RawPost, ApiError
class NcmSchedConf(SchedulerConfig):
class NcmSite(Site):
name = "music.163.com"
schedule_type = "interval"
schedule_setting = {"minutes": 1}
@@ -21,7 +21,7 @@ class NcmArtist(NewMessage):
enable_tag = False
enabled = True
is_common = True
scheduler = NcmSchedConf
site = NcmSite
name = "网易云-歌手"
has_target = True
parse_target_promot = "请输入歌手主页(包含数字ID)的链接"
@@ -78,7 +78,7 @@ class NcmRadio(NewMessage):
enable_tag = False
enabled = True
is_common = False
scheduler = NcmSchedConf
site = NcmSite
name = "网易云-电台"
has_target = True
parse_target_promot = "请输入主播电台主页(包含数字ID)的链接"
+5 -5
View File
@@ -14,8 +14,8 @@ from nonebot.log import logger
from nonebot_plugin_saa import PlatformTarget
from ..post import Post
from ..utils import Site, ProcessContext
from ..plugin_config import plugin_config
from ..utils import ProcessContext, SchedulerConfig
from ..types import Tag, Target, RawPost, SubUnit, Category
@@ -81,7 +81,7 @@ class PlatformABCMeta(PlatformMeta, ABC): ...
class Platform(metaclass=PlatformABCMeta, base=True):
scheduler: type[SchedulerConfig]
site: type[Site]
ctx: ProcessContext
is_common: bool
enabled: bool
@@ -444,7 +444,7 @@ def make_no_target_group(platform_list: list[type[Platform]]) -> type[Platform]:
name = DUMMY_STR
categories_keys = set()
categories = {}
scheduler = platform_list[0].scheduler
site = platform_list[0].site
for platform in platform_list:
if platform.has_target:
@@ -458,7 +458,7 @@ def make_no_target_group(platform_list: list[type[Platform]]) -> type[Platform]:
raise RuntimeError(f"Platform categories for {platform_name} duplicate")
categories_keys |= platform_category_key_set
categories.update(platform.categories)
if platform.scheduler != scheduler:
if platform.site != site:
raise RuntimeError(f"Platform scheduler for {platform_name} not fit")
def __init__(self: "NoTargetGroup", ctx: ProcessContext):
@@ -490,7 +490,7 @@ def make_no_target_group(platform_list: list[type[Platform]]) -> type[Platform]:
"platform_name": platform_list[0].platform_name,
"name": name,
"categories": categories,
"scheduler": scheduler,
"site": site,
"is_common": platform_list[0].is_common,
"enabled": True,
"has_target": False,
+3 -3
View File
@@ -9,10 +9,10 @@ from bs4 import BeautifulSoup as bs
from ..post import Post
from .platform import NewMessage
from ..types import Target, RawPost
from ..utils import SchedulerConfig, text_similarity
from ..utils import Site, text_similarity
class RssSchedConf(SchedulerConfig):
class RssSite(Site):
name = "rss"
schedule_type = "interval"
schedule_setting = {"seconds": 30}
@@ -25,7 +25,7 @@ class Rss(NewMessage):
name = "Rss"
enabled = True
is_common = True
scheduler = RssSchedConf
site = RssSite
has_target = True
@classmethod
+3 -3
View File
@@ -12,7 +12,7 @@ from bs4 import BeautifulSoup as bs
from ..post import Post
from .platform import NewMessage
from ..utils import SchedulerConfig, http_client
from ..utils import Site, http_client
from ..types import Tag, Target, RawPost, ApiError, Category
_HEADER = {
@@ -35,7 +35,7 @@ _HEADER = {
}
class WeiboSchedConf(SchedulerConfig):
class WeiboSite(Site):
name = "weibo.com"
schedule_type = "interval"
schedule_setting = {"seconds": 3}
@@ -53,7 +53,7 @@ class Weibo(NewMessage):
name = "新浪微博"
enabled = True
is_common = True
scheduler = WeiboSchedConf
site = WeiboSite
has_target = True
parse_target_promot = "请输入用户主页(包含数字UID)的链接"