Skip to content

Commit

Permalink
🐛 fix status plugin generic subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Dec 1, 2023
1 parent 4b8ae6e commit 374c0bc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/plugins/nonebot_plugin_status/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@Author : yanyongyu
@Date : 2020-09-18 00:00:13
@LastEditors : yanyongyu
@LastEditTime : 2023-10-08 13:40:21
@LastEditTime : 2023-12-01 10:41:28
@Description : Status plugin
@GitHub : https://github.com/yanyongyu
"""
Expand All @@ -11,7 +11,7 @@

import inspect
import contextlib
from typing import Any
from typing import Any, Dict

from jinja2 import Environment
from nonebot import get_driver
Expand Down Expand Up @@ -85,7 +85,7 @@
)


async def _solve_required_vars() -> dict[str, Any]:
async def _solve_required_vars() -> Dict[str, Any]:
"""Solve required variables for template rendering."""
return (
{
Expand All @@ -112,7 +112,7 @@ async def server_status(matcher: Matcher):
await matcher.send(message=await render_template())


from . import common as common
from . import common as common # noqa: E402

with contextlib.suppress(ImportError):
import nonebot.adapters.onebot.v11 # noqa: F401
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/nonebot_plugin_status/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import asyncio
from datetime import datetime
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING, Dict, List, Optional

import psutil
from nonebot.adapters import Bot
Expand All @@ -26,7 +26,7 @@

# bot status
_nonebot_run_time: datetime
_bot_connect_time: dict[str, datetime] = {}
_bot_connect_time: Dict[str, datetime] = {}


@driver.on_startup
Expand All @@ -53,7 +53,7 @@ def get_nonebot_run_time() -> datetime:
raise RuntimeError("NoneBot not running!") from None


def get_bot_connect_time() -> dict[str, datetime]:
def get_bot_connect_time() -> Dict[str, datetime]:
"""Get the time when the bot connected to the server."""
return _bot_connect_time

Expand All @@ -65,7 +65,7 @@ async def get_cpu_status() -> float:
return psutil.cpu_percent()


async def per_cpu_status() -> list[float]:
async def per_cpu_status() -> List[float]:
"""Get the CPU usage status of each core."""
psutil.cpu_percent(percpu=True)
await asyncio.sleep(0.5)
Expand All @@ -89,7 +89,7 @@ def _get_disk_usage(path: str) -> Optional["sdiskusage"]:
logger.warning(f"Could not get disk usage for {path}: {e!r}")


def get_disk_usage() -> dict[str, "sdiskusage"]:
def get_disk_usage() -> Dict[str, "sdiskusage"]:
"""Get the disk usage status."""
disk_parts = psutil.disk_partitions()
return {
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/nonebot_plugin_status/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ nonebot-adapter-onebot = { version = "^2.0.0-beta.1", optional = true }
[tool.poetry.extras]
onebot = ["nonebot-adapter-onebot"]

[tool.ruff]
line-length = 88
target-version = "py38"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

0 comments on commit 374c0bc

Please sign in to comment.