From 69e16f39278f79c8fb99137c0efb3db0d05a37a3 Mon Sep 17 00:00:00 2001 From: eya46 <644310932@qq.com> Date: Sun, 28 Jan 2024 20:29:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8yarl.URL=E6=9B=BF=E4=BB=A3pat?= =?UTF-8?q?hlib?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 61 ++++++++++++++++++++++++----------- nonebot_plugin_enatfrp/api.py | 12 +++---- pyproject.toml | 2 +- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index dfbcccf..f43ec5e 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,11 @@
# NoneBot Plugin eNatFrp -SakuraFrp管理插件 +# SakuraFrp管理插件 ![License](https://img.shields.io/github/license/eya46/nonebot_plugin_enatfrp) ![Python](https://img.shields.io/badge/python-3.8+-blue.svg) -![NoneBot](https://img.shields.io/badge/nonebot-2.0.1+-blueviolet) +![NoneBot](https://img.shields.io/badge/nonebot-2.1.0+-red.svg)
## 安装方式 @@ -38,28 +38,51 @@ SakuraFrp管理插件 - 我的信息│用户信息 - 公告 `` - 授权 ` ` - -计算机列表 +- 计算机列表 ## 配置项 ### 非必要配置项 -- `natfrp_api`: natfrp api地址 -- `natfrp_token`: natfrp api token -- `natfrp_at`: 是否at -- `natfrp_reply`: 是否回复 -- `natfrp_use_start`: 是否使用nb配置的command_start -- `natfrp_use_sep`: 是否使用nb配置的command_sep - -- `natfrp_cmd_help`: `frp帮助` -- `natfrp_cmd_powerOn`: `开机` -- `natfrp_cmd_tunnels`: `隧道状态` -- `natfrp_cmd_trafficHistory`: `流量` `流量历史` -- `natfrp_cmd_trafficPlans`: `流量包` `流量套餐` -- `natfrp_cmd_userInfo`: `我的信息` `用户信息` -- `natfrp_cmd_announcement`: `公告` -- `natfrp_cmd_auth`: `授权` -- `natfrp_cmd_showPCs`: `计算机列表` +```dotenv +# str +# natfrp api地址 +natfrp_api= +# natfrp api token +natfrp_token= + +# bool +# 是否at +natfrp_at= +# 是否回复 +natfrp_reply= +# 是否使用nb配置的command_start +natfrp_use_start= +# 是否使用nb配置的command_sep + +# 以下是命令文本 List[str] +natfrp_use_sep= +# frp帮助 +natfrp_cmd_help= +# 开机 +natfrp_cmd_powerOn= +# 隧道状态 +natfrp_cmd_tunnels= +# 流量 流量历史 +natfrp_cmd_trafficHistory= +# 流量包 流量套餐 +natfrp_cmd_trafficPlans= +# 我的信息 用户信息 +natfrp_cmd_userInfo= +# 公告 +natfrp_cmd_announcement= +# 授权 +natfrp_cmd_auth= +# 计算机列表 +natfrp_cmd_showPCs= +``` + + ## 依赖项 diff --git a/nonebot_plugin_enatfrp/api.py b/nonebot_plugin_enatfrp/api.py index 623498f..e2cd686 100644 --- a/nonebot_plugin_enatfrp/api.py +++ b/nonebot_plugin_enatfrp/api.py @@ -1,6 +1,6 @@ -from pathlib import PurePosixPath from typing import TYPE_CHECKING, Protocol, Any, Literal, Dict -from urllib.parse import urlparse, urlunparse + +from yarl import URL from .tools import request @@ -12,18 +12,14 @@ async def __call__(self, **data: Any) -> Any: class API: def __init__(self, api: str, token: str): - self.api = api + self.api = URL(api) self.headers = {"Authorization": f"Bearer {token}"} - def get_api(self, path: str) -> str: - u = urlparse(self.api) - return urlunparse(u._replace(path=(PurePosixPath(u.path) / path).as_posix())) # type:ignore - async def call_api( self, path: str, method: Literal["GET", "PUT", "POST", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"], **data: Any ) -> Any: - return await request(method, self.get_api(path), self.headers, **data) + return await request(method, str(self.api / path), self.headers, **data) async def system_bulletin(self) -> list: """ diff --git a/pyproject.toml b/pyproject.toml index c00ddb5..f7d12e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nonebot-plugin-enatfrp" -version = "0.1.5" +version = "0.1.6" description = "SakuraFrp管理插件" authors = ["eya46 <61458340+eya46@users.noreply.github.com>"] license = "MIT"