Skip to content

Commit

Permalink
1.1.0 - fix #41
Browse files Browse the repository at this point in the history
  • Loading branch information
lgc2333 committed Feb 16, 2024
1 parent 8951abe commit 9c1cf67
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,28 @@

_✨ 运行状态图片版 for NoneBot2 ✨_

<img src="https://img.shields.io/badge/python-3.9+-blue.svg" alt="python">
<a href="https://pdm.fming.dev">
<img src="https://img.shields.io/badge/pdm-managed-blueviolet" alt="pdm-managed">
</a>
<a href="https://wakatime.com/badge/user/b61b0f9a-f40b-4c82-bc51-0a75c67bfccf/project/bfec6993-aa9e-42fb-9f3e-53a5d4739373">
<img src="https://wakatime.com/badge/user/b61b0f9a-f40b-4c82-bc51-0a75c67bfccf/project/bfec6993-aa9e-42fb-9f3e-53a5d4739373.svg" alt="wakatime">
</a>

<br />

<a href="https://pydantic.dev">
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/lgc-NB2Dev/readme/main/template/pyd-v1-or-v2.json" alt="Pydantic Version 1 Or 2" >
</a>
<a href="./LICENSE">
<img src="https://img.shields.io/github/license/lgc2333/nonebot-plugin-picstatus.svg" alt="license">
</a>
<a href="https://pypi.python.org/pypi/nonebot-plugin-picstatus">
<img src="https://img.shields.io/pypi/v/nonebot-plugin-picstatus.svg" alt="pypi">
</a>
<img src="https://img.shields.io/badge/python-3.9+-blue.svg" alt="python">
<a href="https://pypi.python.org/pypi/nonebot-plugin-picstatus">
<img src="https://img.shields.io/pypi/dm/nonebot-plugin-picstatus" alt="pypi download">
</a>
<a href="https://wakatime.com/badge/user/b61b0f9a-f40b-4c82-bc51-0a75c67bfccf/project/bfec6993-aa9e-42fb-9f3e-53a5d4739373">
<img src="https://wakatime.com/badge/user/b61b0f9a-f40b-4c82-bc51-0a75c67bfccf/project/bfec6993-aa9e-42fb-9f3e-53a5d4739373.svg" alt="wakatime">
</a>

</div>

Expand Down Expand Up @@ -158,6 +167,10 @@ Telegram:[@lgc2333](https://t.me/lgc2333)

## 📝 更新日志

### 1.1.0

- 支持 Pydantic V2

### 1.0.3

- 修复了当有读取数据出错的分区时图片无法正常渲染的 Bug
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_picstatus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
if config.ps_only_su:
usage += "\n注意:仅SuperUser可以使用此指令"

__version__ = "1.0.3.post1"
__version__ = "1.1.0"
__plugin_meta__ = PluginMetadata(
name="PicStatus",
description="以图片形式显示当前设备的运行状态",
Expand Down
13 changes: 9 additions & 4 deletions nonebot_plugin_picstatus/components/header.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import asyncio
from contextlib import suppress
from dataclasses import dataclass
from datetime import datetime
from typing import Dict, List, Optional, Tuple

import psutil
from nonebot import get_bots, logger
from nonebot.adapters import Bot as BaseBot, Event as BaseEvent
from nonebot.matcher import current_bot
from nonebot.matcher import current_bot, current_event
from nonebot.message import event_preprocessor
from nonebot_plugin_userinfo import UserInfo, get_user_info
from playwright.async_api import Request, Route
Expand Down Expand Up @@ -109,13 +110,12 @@ async def get_header_data() -> HeaderData:
format_timedelta(now_time - nonebot_run_time) if nonebot_run_time else "未知"
)
booted = format_timedelta(
now_time - datetime.fromtimestamp(psutil.boot_time()), # noqa: DTZ006
now_time - datetime.fromtimestamp(psutil.boot_time()).astimezone(),
)
return HeaderData(bots=bots, nb_run=nb_run, booted=booted)


@event_preprocessor
async def _(bot: BaseBot, event: BaseEvent):
async def cache_bot_info(bot: BaseBot, event: BaseEvent):
if bot.self_id in bot_info_cache:
return
try:
Expand All @@ -127,6 +127,9 @@ async def _(bot: BaseBot, event: BaseEvent):
bot_info_cache[bot.self_id] = info


event_preprocessor(cache_bot_info)


@router(f"{ROUTE_URL}/api/bot_avatar/*")
async def _(route: Route, request: Request):
url = URL(request.url)
Expand Down Expand Up @@ -159,6 +162,8 @@ async def _(route: Route, request: Request):

@register_component
async def header():
with suppress(Exception):
await cache_bot_info(current_bot.get(), current_event.get())
return await ENVIRONMENT.get_template("header.html.jinja").render_async(
data=await get_header_data(),
)
2 changes: 1 addition & 1 deletion nonebot_plugin_picstatus/components/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def test_one(site: TestSiteCfg) -> NetworkConnectionType:
follow_redirects=True,
) as client:
start = time.time()
resp = await client.get(site.url)
resp = await client.get(str(site.url))
delay = (time.time() - start) * 1000

except Exception as e:
Expand Down
13 changes: 9 additions & 4 deletions nonebot_plugin_picstatus/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from pathlib import Path
from typing import List, Literal, Optional, Set

from nonebot import get_driver
from nonebot import get_plugin_config
from nonebot.compat import type_validate_python
from pydantic import AnyHttpUrl, BaseModel

RES_PATH = Path(__file__).parent / "res"
Expand Down Expand Up @@ -80,8 +81,12 @@ class Cfg(BaseModel):
ps_sort_nets: bool = True
# connection_test
ps_test_sites: List[TestSiteCfg] = [
TestSiteCfg.parse_obj({"name": "百度", "url": "https://www.baidu.com/"}),
TestSiteCfg.parse_obj(
type_validate_python(
TestSiteCfg,
{"name": "百度", "url": "https://www.baidu.com/"},
),
type_validate_python(
TestSiteCfg,
{"name": "Google", "url": "https://www.google.com/", "use_proxy": True},
),
]
Expand All @@ -98,4 +103,4 @@ class Cfg(BaseModel):
# endregion components


config: Cfg = Cfg.parse_obj(get_driver().config.dict())
config: Cfg = get_plugin_config(Cfg)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "A NoneBot2 plugin generates a picture which shows the status of c
authors = [{ name = "student_2333", email = "[email protected]" }]
dependencies = [
"nonebot2>=2.2.0",
"nonebot-plugin-alconna>=0.34.1",
"nonebot-plugin-alconna>=0.37.0",
"nonebot-plugin-userinfo>=0.1.3",
"nonebot-plugin-htmlrender>=0.2.3",
"psutil>=5.9.2",
Expand Down

0 comments on commit 9c1cf67

Please sign in to comment.