diff --git a/nonebot_plugin_fortnite/shop.py b/nonebot_plugin_fortnite/shop.py index 86ec5fa..7184806 100644 --- a/nonebot_plugin_fortnite/shop.py +++ b/nonebot_plugin_fortnite/shop.py @@ -40,15 +40,22 @@ async def screenshot_shop_img() -> Path: # page.on('requestfailed', lambda request: logger.warning(f'Request failed: {request.url}')) await page.add_style_tag(content='* { transition: none !important; animation: none !important; }') await page.goto(url) - # 模拟滚动到页面底部 - for _ in range(10): - await page.evaluate("""() => { - window.scrollBy(0, document.body.scrollHeight); - }""") - await asyncio.sleep(2) # 等待2秒以加载内容 - - await page.wait_for_load_state('networkidle', timeout=100000) - # await page.wait_for_load_state('load') # 等待页面加载完毕 + + async def wait_for_load(): + await page.wait_for_load_state('networkidle', timeout=60000) + + async def scroll_page(): + for _ in range(20): + await page.evaluate("""() => { + window.scrollBy(0, document.body.scrollHeight / 20); + }""") + await asyncio.sleep(1) # 等待1秒以加载内容 + + await asyncio.gather( + wait_for_load(), + scroll_page() + ) + await page.screenshot(path=shop_file, full_page=True) return shop_file finally: diff --git a/nonebot_plugin_fortnite/stats.py b/nonebot_plugin_fortnite/stats.py index 10386a0..9dc6991 100644 --- a/nonebot_plugin_fortnite/stats.py +++ b/nonebot_plugin_fortnite/stats.py @@ -48,13 +48,13 @@ async def get_level(name: str, time_window: str) -> int: time_window = TimeWindow.LIFETIME if time_window.startswith("生涯") else TimeWindow.SEASON stats = await get_stats(name, time_window) bp = stats.battle_pass - return f'等级: {bp.level} 下一级进度: {bp.progress}%' + return f'{stats.user.name}: Lv{bp.level} | {bp.progress}% to Lv{bp.level + 1}' @exception_handler() async def get_stats_image(name: str, time_window: str) -> Path: time_window = TimeWindow.LIFETIME if time_window.startswith("生涯") else TimeWindow.SEASON stats = await get_stats(name, time_window, StatsImageType.ALL) - return await get_stats_img_by_url(stats.image.url, name) + return await get_stats_img_by_url(stats.image.url, stats.user.name) font_path: Path | None = None diff --git a/pyproject.toml b/pyproject.toml index 9eb8e5c..4ec4479 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nonebot-plugin-fortnite" -version = "0.1.1" +version = "0.1.2" description = "堡垒之夜插件" authors = ["fllesser "] readme = "README.md" @@ -12,7 +12,6 @@ keywords = ["nonebot", "nonebot2"] [tool.poetry.dependencies] python = "^3.10" httpx = "^0.27.2" -fortnite-api = "^3.2.1" pillow = "^10.4.0" playwright = "^1.4.9.1" nonebot2 = "^2.4.0" @@ -20,6 +19,7 @@ nonebot-plugin-uninfo = "^0.6.5" nonebot-plugin-alconna = "^0.54.2" nonebot-plugin-localstore = "^0.7.3" nonebot-plugin-apscheduler = "^0.5.0" +fortnite-api = {version = "^3.2.1", extras = ["speed"]} [tool.poetry.group.test.dependencies] nb-cli = "^1.4.2"