mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-06 03:46:10 +08:00
add ncm
This commit is contained in:
parent
9c7b3a49bc
commit
8e61e27127
@ -45,9 +45,9 @@ class NcmArtist(TargetMixin, NewMessage):
|
|||||||
def get_date(self, post: RawPost) -> int:
|
def get_date(self, post: RawPost) -> int:
|
||||||
return post['publishTime'] // 1000
|
return post['publishTime'] // 1000
|
||||||
|
|
||||||
def parse(self, raw_post: RawPost) -> Post:
|
async def parse(self, raw_post: RawPost) -> Post:
|
||||||
text = '新专辑发布:{}'.format(raw_post.name)
|
text = '新专辑发布:{}'.format(raw_post['name'])
|
||||||
target_name = raw_post.artist.name
|
target_name = raw_post['artist']['name']
|
||||||
pics = [raw_post['picUrl']]
|
pics = [raw_post['picUrl']]
|
||||||
url = "https://music.163.com/#/album?id={}".format(raw_post['id'])
|
url = "https://music.163.com/#/album?id={}".format(raw_post['id'])
|
||||||
return Post('ncm-artist', text=text, url=url, pics=pics, target_name=target_name)
|
return Post('ncm-artist', text=text, url=url, pics=pics, target_name=target_name)
|
||||||
|
@ -114,9 +114,9 @@ class MessageProcessMixin(PlatformNameMixin, CategoryMixin, ParsePostMixin, abst
|
|||||||
self.parse_cache[post_id] = await self.parse(raw_post)
|
self.parse_cache[post_id] = await self.parse(raw_post)
|
||||||
break
|
break
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
retry_times -= 1
|
||||||
if not retry_times:
|
if not retry_times:
|
||||||
raise err
|
raise err
|
||||||
retry_times -= 1
|
|
||||||
return self.parse_cache[post_id]
|
return self.parse_cache[post_id]
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
@ -21,7 +21,7 @@ class Post:
|
|||||||
compress: bool = False
|
compress: bool = False
|
||||||
override_use_pic: Optional[bool] = None
|
override_use_pic: Optional[bool] = None
|
||||||
pics: list[Union[str,bytes]] = field(default_factory=list)
|
pics: list[Union[str,bytes]] = field(default_factory=list)
|
||||||
extra_msg = list[Message]
|
extra_msg: list[Message] = field(default_factory=list)
|
||||||
|
|
||||||
_message: Optional[list] = None
|
_message: Optional[list] = None
|
||||||
|
|
||||||
@ -125,8 +125,8 @@ class Post:
|
|||||||
# msgs.append(Message("[CQ:image,file={url}]".format(url=pic)))
|
# msgs.append(Message("[CQ:image,file={url}]".format(url=pic)))
|
||||||
msgs.append(MessageSegment.image(pic))
|
msgs.append(MessageSegment.image(pic))
|
||||||
if self.compress:
|
if self.compress:
|
||||||
msgs = Message([msgs])
|
msgs = [Message([msgs])]
|
||||||
msgs += self.extra_msg
|
msgs.extend(self.extra_msg)
|
||||||
self._message = msgs
|
self._message = msgs
|
||||||
return self._message
|
return self._message
|
||||||
|
|
||||||
|
1
tests/platforms/ncm_siren.json
Normal file
1
tests/platforms/ncm_siren.json
Normal file
File diff suppressed because one or more lines are too long
49
tests/platforms/test_ncm_artist.py
Normal file
49
tests/platforms/test_ncm_artist.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
from .utils import get_json
|
||||||
|
import pytest
|
||||||
|
import respx
|
||||||
|
import typing
|
||||||
|
import time
|
||||||
|
from httpx import Response
|
||||||
|
|
||||||
|
if typing.TYPE_CHECKING:
|
||||||
|
import sys
|
||||||
|
sys.path.append('./src/plugins')
|
||||||
|
import nonebot_hk_reporter
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def ncm_artist(plugin_module: 'nonebot_hk_reporter'):
|
||||||
|
return plugin_module.platform.platform_manager['ncm-artist']
|
||||||
|
|
||||||
|
@pytest.fixture(scope='module')
|
||||||
|
def ncm_artist_raw():
|
||||||
|
return get_json('ncm_siren.json')
|
||||||
|
|
||||||
|
@pytest.fixture(scope='module')
|
||||||
|
def ncm_artist_0(ncm_artist_raw):
|
||||||
|
return {
|
||||||
|
**ncm_artist_raw,
|
||||||
|
'hotAlbums': ncm_artist_raw['hotAlbums'][1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
@pytest.fixture(scope='module')
|
||||||
|
def ncm_artist_1(ncm_artist_raw: dict):
|
||||||
|
res = ncm_artist_raw.copy()
|
||||||
|
res['hotAlbums'] = ncm_artist_raw['hotAlbums'][:]
|
||||||
|
res['hotAlbums'][0]['publishTime'] = int(time.time() * 1000)
|
||||||
|
return res
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@respx.mock
|
||||||
|
async def test_fetch_new(ncm_artist, ncm_artist_0, ncm_artist_1, dummy_user_subinfo):
|
||||||
|
ncm_router = respx.get("https://music.163.com/api/artist/albums/32540734")
|
||||||
|
ncm_router.mock(return_value=Response(200, json=ncm_artist_0))
|
||||||
|
target = '32540734'
|
||||||
|
res = await ncm_artist.fetch_new_post(target, [dummy_user_subinfo])
|
||||||
|
assert(ncm_router.called)
|
||||||
|
assert(len(res) == 0)
|
||||||
|
ncm_router.mock(return_value=Response(200, json=ncm_artist_1))
|
||||||
|
res2 = await ncm_artist.fetch_new_post(target, [dummy_user_subinfo])
|
||||||
|
post = res2[0][1][0]
|
||||||
|
assert(post.target_type == 'ncm-artist')
|
||||||
|
assert(post.text == '新专辑发布:Y1K')
|
||||||
|
assert(post.url == 'https://music.163.com/#/album?id=131074504')
|
@ -27,6 +27,7 @@ async def test_9_merge(plugin_module: 'nonebot_hk_reporter'):
|
|||||||
post = plugin_module.post.Post('', '', '', pics=merge_source_9)
|
post = plugin_module.post.Post('', '', '', pics=merge_source_9)
|
||||||
await post._pic_merge()
|
await post._pic_merge()
|
||||||
assert len(post.pics) == 5
|
assert len(post.pics) == 5
|
||||||
|
await post.generate_messages()
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_6_merge(plugin_module):
|
async def test_6_merge(plugin_module):
|
||||||
|
@ -18,4 +18,3 @@ VuePress 由两部分组成:第一部分是一个极简静态网站生成器
|
|||||||
|
|
||||||
每一个由 VuePress 生成的页面都带有预渲染好的 HTML,也因此具有非常好的加载性能和搜索引擎优化(SEO)。同时,一旦页面被加载,Vue 将接管这些静态内容,并将其转换成一个完整的单页应用(SPA),其他的页面则会只在用户浏览到的时候才按需加载。
|
每一个由 VuePress 生成的页面都带有预渲染好的 HTML,也因此具有非常好的加载性能和搜索引擎优化(SEO)。同时,一旦页面被加载,Vue 将接管这些静态内容,并将其转换成一个完整的单页应用(SPA),其他的页面则会只在用户浏览到的时候才按需加载。
|
||||||
''')
|
''')
|
||||||
print(res)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user