mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-06 20:06:12 +08:00
add version check for arknights
This commit is contained in:
parent
7b6226a833
commit
4f3325d988
@ -1,4 +1,6 @@
|
|||||||
from .platform import Platform
|
from collections import defaultdict
|
||||||
|
|
||||||
|
from .platform import Platform, NoTargetGroup
|
||||||
from pkgutil import iter_modules
|
from pkgutil import iter_modules
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
@ -11,7 +13,17 @@ for (_, module_name, _) in iter_modules([_package_dir]):
|
|||||||
async def check_sub_target(target_type, target):
|
async def check_sub_target(target_type, target):
|
||||||
return await platform_manager[target_type].get_target_name(target)
|
return await platform_manager[target_type].get_target_name(target)
|
||||||
|
|
||||||
platform_manager: dict[str, Platform] = {
|
_platform_list = defaultdict(list)
|
||||||
obj.platform_name: obj() for obj in \
|
for platform in Platform.registory:
|
||||||
filter(lambda platform: platform.enabled, Platform.registory)
|
if not platform.enabled:
|
||||||
}
|
continue
|
||||||
|
_platform_list[platform.platform_name].append(platform)
|
||||||
|
|
||||||
|
platform_manager: dict[str, Platform] = dict()
|
||||||
|
for name, platform_list in _platform_list.items():
|
||||||
|
if len(platform_list) == 1:
|
||||||
|
platform_manager[name] = platform_list[0]()
|
||||||
|
else:
|
||||||
|
platform_manager[name] = NoTargetGroup(platform_list)
|
||||||
|
|
||||||
|
print(platform_manager)
|
||||||
|
@ -3,9 +3,9 @@ import httpx
|
|||||||
import json
|
import json
|
||||||
from bs4 import BeautifulSoup as bs
|
from bs4 import BeautifulSoup as bs
|
||||||
|
|
||||||
from ..types import RawPost, Target
|
from ..types import Category, RawPost, Target
|
||||||
|
|
||||||
from .platform import NewMessage, NoTargetMixin, CategoryNotSupport
|
from .platform import NewMessage, NoTargetMixin, CategoryNotSupport, StatusChange
|
||||||
|
|
||||||
from ..utils import Render
|
from ..utils import Render
|
||||||
from ..post import Post
|
from ..post import Post
|
||||||
@ -13,9 +13,9 @@ from ..post import Post
|
|||||||
|
|
||||||
class Arknights(NewMessage, NoTargetMixin):
|
class Arknights(NewMessage, NoTargetMixin):
|
||||||
|
|
||||||
categories = {}
|
categories = {1: '游戏公告'}
|
||||||
platform_name = 'arknights'
|
platform_name = 'arknights'
|
||||||
name = '明日方舟游戏内公告'
|
name = '明日方舟游戏信息'
|
||||||
enable_tag = False
|
enable_tag = False
|
||||||
enabled = True
|
enabled = True
|
||||||
is_common = False
|
is_common = False
|
||||||
@ -23,7 +23,7 @@ class Arknights(NewMessage, NoTargetMixin):
|
|||||||
schedule_kw = {'seconds': 30}
|
schedule_kw = {'seconds': 30}
|
||||||
|
|
||||||
async def get_target_name(self, _: Target) -> str:
|
async def get_target_name(self, _: Target) -> str:
|
||||||
return '明日方舟游戏内公告'
|
return '明日方舟游戏信息'
|
||||||
|
|
||||||
async def get_sub_list(self, _) -> list[RawPost]:
|
async def get_sub_list(self, _) -> list[RawPost]:
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
@ -36,6 +36,9 @@ class Arknights(NewMessage, NoTargetMixin):
|
|||||||
def get_date(self, _: RawPost) -> None:
|
def get_date(self, _: RawPost) -> None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_category(self, _) -> Category:
|
||||||
|
return Category(1)
|
||||||
|
|
||||||
async def parse(self, raw_post: RawPost) -> Post:
|
async def parse(self, raw_post: RawPost) -> Post:
|
||||||
announce_url = raw_post['webUrl']
|
announce_url = raw_post['webUrl']
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
@ -53,3 +56,43 @@ class Arknights(NewMessage, NoTargetMixin):
|
|||||||
else:
|
else:
|
||||||
raise CategoryNotSupport()
|
raise CategoryNotSupport()
|
||||||
return Post('arknights', text='', url='', target_name="明日方舟游戏内公告", pics=pics, compress=True, override_use_pic=False)
|
return Post('arknights', text='', url='', target_name="明日方舟游戏内公告", pics=pics, compress=True, override_use_pic=False)
|
||||||
|
|
||||||
|
class AkVersion(NoTargetMixin, StatusChange):
|
||||||
|
|
||||||
|
categories = {2: '更新信息'}
|
||||||
|
platform_name = 'arknights'
|
||||||
|
name = '明日方舟游戏信息'
|
||||||
|
enable_tag = False
|
||||||
|
enabled = True
|
||||||
|
is_common = False
|
||||||
|
schedule_type = 'interval'
|
||||||
|
schedule_kw = {'seconds': 30}
|
||||||
|
|
||||||
|
async def get_target_name(self, _: Target) -> str:
|
||||||
|
return '明日方舟游戏信息'
|
||||||
|
|
||||||
|
async def get_status(self, _):
|
||||||
|
async with httpx.AsyncClient() as client:
|
||||||
|
res_ver = await client.get('https://ak-conf.hypergryph.com/config/prod/official/IOS/version')
|
||||||
|
res_preanounce = await client.get('https://ak-conf.hypergryph.com/config/prod/announce_meta/IOS/preannouncement.meta.json')
|
||||||
|
res = res_ver.json()
|
||||||
|
res.update(res_preanounce.json())
|
||||||
|
return res
|
||||||
|
|
||||||
|
async def compare_status(self, _, old_status, new_status):
|
||||||
|
res = []
|
||||||
|
if old_status.get('preAnnounceType') == 2 and new_status.get('preAnnounceType') == 0:
|
||||||
|
res.append(Post('arknights', text='开始维护!', target_name='明日方舟更新信息'))
|
||||||
|
elif old_status.get('preAnnounceType') == 0 and new_status.get('preAnnounceType') == 2:
|
||||||
|
res.append(Post('arknights', text='维护结束!冲!', target_name='明日方舟更新信息'))
|
||||||
|
if old_status.get('clientVersion') != new_status.get('clientVersion'):
|
||||||
|
res.append(Post('arknights', text='游戏本体更新(大更新)', target_name='明日方舟更新信息'))
|
||||||
|
if old_status.get('resVersion') != new_status.get('resVersion'):
|
||||||
|
res.append(Post('arknights', text='游戏资源更新(小更新)', target_name='明日方舟更新信息'))
|
||||||
|
return res
|
||||||
|
|
||||||
|
def get_category(self, _):
|
||||||
|
return Category(2)
|
||||||
|
|
||||||
|
async def parse(self, raw_post):
|
||||||
|
return raw_post
|
||||||
|
@ -280,7 +280,7 @@ class StatusChange(
|
|||||||
...
|
...
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def compare_status(self, target: Target, old_status, new_status) -> Optional[RawPost]:
|
def compare_status(self, target: Target, old_status, new_status) -> list[RawPost]:
|
||||||
...
|
...
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
@ -294,7 +294,7 @@ class StatusChange(
|
|||||||
if old_status := self.get_stored_data(target):
|
if old_status := self.get_stored_data(target):
|
||||||
diff = self.compare_status(target, old_status, new_status)
|
diff = self.compare_status(target, old_status, new_status)
|
||||||
if diff:
|
if diff:
|
||||||
res = await self.dispatch_user_post(target, [diff], users)
|
res = await self.dispatch_user_post(target, diff, users)
|
||||||
self.set_stored_data(target, new_status)
|
self.set_stored_data(target, new_status)
|
||||||
return res
|
return res
|
||||||
except httpx.RequestError as err:
|
except httpx.RequestError as err:
|
||||||
@ -337,6 +337,9 @@ class NoTargetGroup(
|
|||||||
self.is_common = platform_list[0].is_common
|
self.is_common = platform_list[0].is_common
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return '[' + ' '.join(map(lambda x: x.name, self.platform_list)) + ']'
|
||||||
|
|
||||||
async def get_target_name(self, _):
|
async def get_target_name(self, _):
|
||||||
return await self.platform_list[0].get_target_name(_)
|
return await self.platform_list[0].get_target_name(_)
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ class Post:
|
|||||||
|
|
||||||
target_type: str
|
target_type: str
|
||||||
text: str
|
text: str
|
||||||
url: Optional[str]
|
url: Optional[str] = None
|
||||||
target_name: Optional[str] = None
|
target_name: Optional[str] = None
|
||||||
compress: bool = False
|
compress: bool = False
|
||||||
override_use_pic: Optional[bool] = None
|
override_use_pic: Optional[bool] = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user